KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > dialogs > ADialog


1 /*
2  * DialogRange.java of project jchart2d
3  * Copyright 2006 (C) Achim Westermann, created on 09:31:15.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.gui.chart.dialogs;
24
25 import info.monitorenter.gui.chart.layout.controls.RangeChooserPanel;
26
27 import java.awt.Component JavaDoc;
28 import java.awt.Container JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.HeadlessException JavaDoc;
31 import java.awt.Window JavaDoc;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.awt.event.ComponentAdapter JavaDoc;
35 import java.awt.event.ComponentEvent JavaDoc;
36 import java.awt.event.WindowAdapter JavaDoc;
37 import java.awt.event.WindowEvent JavaDoc;
38
39 import javax.swing.Box JavaDoc;
40 import javax.swing.BoxLayout JavaDoc;
41 import javax.swing.JButton JavaDoc;
42 import javax.swing.JComponent JavaDoc;
43 import javax.swing.JDialog JavaDoc;
44 import javax.swing.JOptionPane JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46
47
48 /**
49  * A dialog for choosing a range.
50  * <p>
51  *
52  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
53  *
54  *
55  * @version $Revision: 1.2 $
56  */

57 public abstract class ADialog extends JDialog JavaDoc {
58
59   /** The ui controls and model to interact with. */
60   private JComponent JavaDoc m_chooserPanel;
61
62   /**
63    * Creates a range-chooser dialog.
64    * <p>
65    *
66    * @param component
67    * the parent <code>Component</code> for the dialog.
68    *
69    * @param title
70    * the String containing the dialog's title.
71    *
72    * @param modal
73    * if true this will be a modal dialog (blocking actions on component
74    * until closed.
75    *
76    * @param chooserPane
77    * the UI control for choosing the range.
78    */

79   public ADialog(final Component JavaDoc component, final String JavaDoc title, final boolean modal,
80       final RangeChooserPanel chooserPane) {
81     super(JOptionPane.getFrameForComponent(component), title, modal);
82     this.m_chooserPanel = chooserPane;
83
84     Container JavaDoc contentPane = this.getContentPane();
85     contentPane.setLayout(new BoxLayout JavaDoc(contentPane, BoxLayout.Y_AXIS));
86     contentPane.add(this.m_chooserPanel);
87
88     // Window listeners:
89
this.addWindowListener(new WindowAdapter JavaDoc() {
90       public void windowClosing(final WindowEvent JavaDoc e) {
91         Window JavaDoc w = e.getWindow();
92         w.setVisible(false);
93       }
94     });
95     this.addComponentListener(new ComponentAdapter JavaDoc() {
96       public void componentHidden(final ComponentEvent JavaDoc e) {
97         Window JavaDoc w = (Window JavaDoc) e.getComponent();
98         w.dispose();
99       }
100     });
101
102     // Chancel / OK Buttons.
103
JPanel JavaDoc okChancelPanel = new JPanel JavaDoc();
104     okChancelPanel.setLayout(new BoxLayout JavaDoc(okChancelPanel, BoxLayout.X_AXIS));
105     okChancelPanel.add(Box.createHorizontalGlue());
106     JButton JavaDoc ok = new JButton JavaDoc("OK");
107     ok.addActionListener(new ActionListener JavaDoc() {
108       public void actionPerformed(final ActionEvent JavaDoc e) {
109         setVisible(false);
110       }
111     });
112     okChancelPanel.add(ok);
113     okChancelPanel.add(Box.createHorizontalGlue());
114     JButton JavaDoc chancel = new JButton JavaDoc("Chancel");
115     chancel.addActionListener(new ActionListener JavaDoc() {
116       public void actionPerformed(final ActionEvent JavaDoc e) {
117         setVisible(false);
118       }
119     });
120     okChancelPanel.add(chancel);
121     okChancelPanel.add(Box.createHorizontalGlue());
122     // add ok / chancel to ui:
123
contentPane.add(okChancelPanel);
124     this.setSize(new Dimension JavaDoc(300, 200));
125   }
126
127   /**
128    * Shows a modal dialog and blocks until the dialog is hidden. If the user
129    * presses the "OK" button, then this method hides/disposes the dialog and
130    * returns the selected color. If the user presses the "Cancel" button or
131    * closes the dialog without pressing "OK", then this method hides/disposes
132    * the dialog and returns <code>null</code>.
133    * <p>
134    *
135    *
136    * @return the selected range or <code>null</code> if the user opted out.
137    *
138    * @exception HeadlessException
139    * if GraphicsEnvironment.isHeadless() returns true.
140    * @see java.awt.GraphicsEnvironment#isHeadless
141    */

142   public JComponent JavaDoc showDialog() throws HeadlessException JavaDoc {
143     // blocks until user brings dialog down...
144
this.setVisible(true);
145     return this.m_chooserPanel;
146   }
147
148 }
149
Popular Tags