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

Quick Search    Search Deep

Source code: com/cybertivity/powerjournal/framework/DialogView.java


1   /*
2    * Title:     Similated Intelligence
3    * Copyright: Copyright (c) 2001 Cybertivity
4    * Company:   <A HREF="http://www.cybertivity.com">Cybertivity</A>
5    * @author    <A HREF="mailto:chris.arrowood@cybertivity.com">Chris Arrowood</A>
6    * @version   $Id: DialogView.java,v 1.1.1.1 2001/11/24 03:51:34 arrowood Exp $
7    */
8   package com.cybertivity.powerjournal.framework;
9   import java.awt.Dimension;
10  
11  import java.awt.Toolkit;
12  import java.awt.event.ActionEvent;
13  import java.awt.event.ActionListener;
14  import java.awt.event.WindowAdapter;
15  import java.awt.event.WindowEvent;
16  import javax.swing.JDialog;
17  import javax.swing.JFrame;
18  
19  /**
20   *  Description of the Class
21   *
22   * @author     arrowood
23   * @created    July 17, 2001
24   */
25  public abstract class DialogView extends View {
26    protected JDialog content = null;
27    protected AllActionListener actionListener = null;
28  
29  
30    /**
31     *  Constructor for the DialogView object
32     */
33    public DialogView() {
34      this(null, true);
35    }
36  
37  
38    /**
39     *  Constructor for the DialogView object
40     *
41     * @param  parent  Parent of this dialog
42     * @param  modal   Should this be modal?
43     */
44    public DialogView(JFrame parent, boolean modal) {
45      content = new JDialog(parent, modal);
46      actionListener = new AllActionListener();
47  
48      WindowAdapter windowAdapter =
49        new WindowAdapter() {
50          public void windowClosing(WindowEvent event) {
51            fireEvent("cancel");
52          }
53        };
54  
55      content.addWindowListener(windowAdapter);
56    }
57  
58  
59    /**
60     *  Show or hide the dialog.
61     *
62     * @param  visible  true to show the dialog, false to hide it.
63     */
64  
65    public void setVisible(boolean visible) {
66      content.setVisible(visible);
67    }
68  
69  
70    /**
71     *  Return my content -- the JDialog instance.
72     *
73     * @return    The Content value
74     */
75  
76    public JDialog getContent() {
77      return content;
78    }
79  
80  
81    /**
82     *  Get the dialog's visible state.
83     *
84     * @return    true if the dialog is visible.
85     */
86  
87    public boolean isVisible() {
88      return content.isVisible();
89    }
90  
91  
92    /**
93     *  Destroy myself.
94     */
95  
96    public void closeDialog() {
97      content.setVisible(false);
98      cleanUp();
99      ((JDialog) content).dispose();
100   }
101 
102 
103   public void moveToCenter() {
104     /*
105      *  Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
106      *  int w = content.getSize().width;
107      *  int h = content.getSize().height;
108      *  int x = (dim.width-w)/2;
109      *  int y = (dim.height-h)/2;
110      *  content.setBounds(x, y, w, h);
111      */
112     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
113     int height = content.getSize().height;
114     int width = content.getSize().width;
115 
116     content.setLocation((screen.width - width) / 2, (screen.height - height) / 2);
117   }
118 
119 
120   /**
121    *  DialogView has one instance of this. It listens to all button and menu
122    *  action events and passes them to the controller.
123    *
124    * @author     arrowood
125    * @created    July 17, 2001
126    */
127 
128   private class AllActionListener implements ActionListener {
129     public void actionPerformed(ActionEvent event) {
130       fireEvent(event.getActionCommand());
131     }
132   }
133 
134 
135   /**
136    *  When the window dies, behave like the Cancel button was clicked.
137    *
138    * @author     arrowood
139    * @created    July 17, 2001
140    */
141 
142   private class DeadlyWindowListener extends WindowAdapter {
143     public void windowClosing(WindowEvent event) {
144       fireEvent("cancel");
145     }
146   }
147 }
148