Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/modama/tools/AbstractDialog.java


1   /**
2    * Created by IntelliJ IDEA.
3    * User: Administrator
4    * Date: Feb 3, 2003
5    * Time: 12:03:07 AM
6    * To change this template use Options | File Templates.
7    */
8   package org.modama.tools;
9   
10  import org.modama.framework.tools.Resources;
11  
12  import javax.swing.*;
13  import java.awt.*;
14  import java.awt.event.ActionListener;
15  import java.awt.event.ActionEvent;
16  import java.awt.event.WindowAdapter;
17  import java.awt.event.WindowEvent;
18  
19  /**
20   * a frame for creating dialogs<br>
21   * you have to implement the following functions:<br>
22   *  setupGUI       create, add and layout the components<br>
23   *  setupEvents    setup the events for the components<br>
24   *  updateGUI      set the values of the components (from the model)<br>
25   */
26  abstract public class AbstractDialog extends JDialog {
27  
28      protected JComponent north, center, south;
29  
30      protected JButton ok, cancel;
31      /**
32       * to know wether the dialog was finished by OK or not
33       */
34      protected boolean finishedok;
35  
36      public AbstractDialog() throws HeadlessException {
37      }
38  
39      public AbstractDialog( Frame owner, String title ) throws HeadlessException {
40          super(owner, title, true);
41          init();
42      }
43  
44      protected void init() {
45          addWindowListener( new WindowAdapter() {
46              public void windowClosing(WindowEvent e) {
47                  cancelClicked();
48              }
49          });
50  
51          Container pane = getContentPane();
52  
53          north = new JPanel( new FlowLayout() );
54          center = new JPanel();
55          center.setLayout( new ParameterLayout( center ) );
56          south = new JPanel( new FlowLayout() );
57  
58          ok = new JButton( Resources.getString("global.ok") );
59          cancel = new JButton( Resources.getString("global.cancel") );
60          ok.addActionListener( new ActionListener() {
61              public void actionPerformed(ActionEvent e) {
62                  okClicked();
63              }
64          });
65          cancel.addActionListener( new ActionListener() {
66              public void actionPerformed(ActionEvent e) {
67                  cancelClicked();
68              }
69          });
70          south.add( ok );
71          south.add( cancel );
72  
73          setupGUI();
74          setupEvents();
75  
76          pane.setLayout( new BorderLayout() );
77          pane.add( north, BorderLayout.NORTH );
78          pane.add( center, BorderLayout.CENTER );
79          pane.add( south, BorderLayout.SOUTH );
80  
81          pack();
82      }
83  
84      /**
85       *
86       * @return
87       */
88      public boolean showDialog()
89      {
90          finishedok = false;
91          updateGUI();
92          show();
93          return finishedok;
94      }
95  
96      /**
97       * is called in the constructor to build the gui
98       */
99      abstract protected void setupGUI();
100 
101     /**
102      * is called in the constructor to setup the events
103      */
104     protected void setupEvents(){}
105 
106     /**
107      * is called befor showing the dialog to set the actual values
108      */
109     abstract protected void updateGUI();
110 
111     /**
112      * can be overriden, should check the inputvalues, if they are ok, finishedok has to be set to true
113      */
114     protected void okClicked(){
115         finishedok = true;
116         setVisible( false );
117     }
118 
119     protected void cancelClicked()
120     {
121         setVisible( false );
122     }
123 
124     public boolean isFinishedByeOK() {
125         return finishedok;
126     }
127 }