001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.ideaplugin.frames;
020:
021: import org.apache.ideaplugin.bean.ParameterObj;
022:
023: import javax.swing.*;
024: import java.awt.*;
025: import java.awt.event.ActionListener;
026: import java.awt.event.ActionEvent;
027:
028: public class ParameterDialog extends JDialog {
029: private static ParameterDialog dialog;
030: private static ParameterObj para = new ParameterObj("", "");
031: private JTextField txtName;
032: private JTextField txtValue;
033:
034: public static void initialize(Component comp, String title) {
035: Frame frame = JOptionPane.getFrameForComponent(comp);
036: dialog = new ParameterDialog(frame, title);
037: dialog.setResizable(false);
038: dialog.setSize(250, 150);
039: }
040:
041: public static ParameterObj showDialog(String title) {
042: if (dialog != null) {
043: dialog.setTitle(title);
044: dialog.setVisible(true);
045: }
046: return para;
047: }
048:
049: private ParameterDialog(Frame frame, String title) {
050: super (frame, title, true);
051:
052: //buttons
053: final JButton cancelButton = new JButton("Cancel");
054: final JButton setButton = new JButton(" OK ");
055: cancelButton.addActionListener(new ActionListener() {
056: public void actionPerformed(ActionEvent e) {
057: ParameterDialog.dialog.setVisible(false);
058: }
059: });
060: setButton.addActionListener(new ActionListener() {
061: public void actionPerformed(ActionEvent e) {
062: ParameterDialog.para.setName(txtName.getText());
063: ParameterDialog.para.setValue(txtValue.getText());
064: ParameterDialog.dialog.setVisible(false);
065: }
066: });
067: getRootPane().setDefaultButton(setButton);
068: getRootPane().setDefaultButton(cancelButton);
069: //main part of the dialog
070:
071: txtName = new JTextField();
072: txtValue = new JTextField();
073:
074: JPanel listPane = new JPanel();
075: listPane
076: .setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
077: listPane.add(Box.createRigidArea(new Dimension(10, 0)));
078: listPane.add(new JLabel("Name:"));
079: listPane.add(txtName);
080: listPane.add(new JLabel("Value:"));
081: listPane.add(txtValue);
082: listPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
083: 10));
084:
085: //Lay out the buttons from left to right.
086: JPanel buttonPane = new JPanel();
087: buttonPane
088: .setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
089: buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
090: 10));
091: buttonPane.add(Box.createHorizontalGlue());
092: buttonPane.add(cancelButton);
093: buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
094: buttonPane.add(setButton);
095:
096: //Put everything together, using the content pane's BorderLayout.
097: Container contentPane = getContentPane();
098: contentPane.add(listPane, BorderLayout.CENTER);
099: contentPane.add(buttonPane, BorderLayout.SOUTH);
100:
101: pack();
102: }
103:
104: }
|