⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bslayerdialog.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.plugins.maps.editor;

/*
 * BSLayerDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 18 December 2002, 11:17
 */

import java.awt.*;
import javax.swing.*;
import java.beans.*; // Property change stuff
//import java.util.*;

//import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.core.*;

/**
 * <code>BSLayerDialog</code> allows entering parameters for map layer.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */

public class BSLayerDialog extends JDialog {
    private JOptionPane optionPane;
    public int priority;
    public int offsetX;
    public int offsetY;
    public float scale;
    public boolean confirmed = false;
    
    /** Constructor */
    BSLayerDialog(Frame _parent, int _offsetX, int _offsetY, float _scale, 
                  int minPriority, int maxPriority, int defaultPriority) {
                      
        super(_parent, "Set layer", true);
        
        final Frame parent = _parent;
        
        final JTextField offsetXTextField = new JTextField(Integer.toString(_offsetX));
        final JTextField offsetYTextField = new JTextField(Integer.toString(_offsetY));
        final JTextField scaleTextField = new JTextField(Float.toString(_scale));
        
        final JComboBox priorityComboBox = new JComboBox();
        for (int i=minPriority; i<=maxPriority; i++)
            priorityComboBox.addItem(new Integer(i));
        priorityComboBox.setSelectedItem(new Integer(defaultPriority));
            
        Object[] fields = {"X offset: ", offsetXTextField,
                           "Y offset: ", offsetYTextField,
                           "Scale: ", scaleTextField,
                           "Priority: ", priorityComboBox};
        
        final String okButton = "OK";
        final String cancelButton = "Cancel";
        Object[] options = {okButton, cancelButton};

        optionPane = new JOptionPane(fields, 
                                     JOptionPane.PLAIN_MESSAGE,
                                     JOptionPane.OK_CANCEL_OPTION,
                                     null,
                                     options,
                                     options[0]);
        setContentPane(optionPane);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        pack();
        setLocationRelativeTo(parent);
        
        // handles actions
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();
			
                if (isVisible() 
                    && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
                      prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if (value.equals(okButton)) {
                        priority = ((Integer) priorityComboBox.getSelectedItem()).intValue();
                        try {
                            offsetX = Integer.parseInt(offsetXTextField.getText());
                            offsetY = Integer.parseInt(offsetYTextField.getText());
                        } catch (NumberFormatException e2) {
                            JOptionPane.showMessageDialog(parent, "Offsets must be integer numbers", 
                                                          "Error",  JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                        try {
                            scale = Float.parseFloat(scaleTextField.getText());
                        } catch (NumberFormatException e3) {
                            JOptionPane.showMessageDialog(parent, "Scale must be a float number", 
                                                          "Error",  JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                        confirmed = true;
                        setVisible(false);
                    }
                    else if (value.equals(cancelButton)) {
                        confirmed = false;
                        setVisible(false);
                    }
                }
            }
        });
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -