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

Quick Search    Search Deep

Source code: org/mitre/cvw/AVToolFrame.java


1   /*
2    * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3    * All rights reserved.
4    * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5    */
6   
7   package org.mitre.cvw;
8   
9   import javax.swing.*;
10  import java.awt.*;
11  import java.awt.event.*;
12  import java.util.StringTokenizer;
13  
14  /**
15   * This is a simple window with some instructions it is used to 
16   * get the desired size and location from the user for the audio and
17   * video tools.  This is because we can't get the 
18   * dimensions of the actual audio/video tool, have the user save the location 
19   * and size of a dummy window and then use those dimensions for the actual
20   * audio/video tool.
21   * @version 1.0
22   * @author Deb Ercolini
23   */
24  public class AVToolFrame extends CVWFrame {
25    // declare variables
26    JFrame parent;
27    //protected TextView panel;
28    protected JTextArea panel;
29    protected GridBagLayout gridbag = new GridBagLayout();
30    protected Font bold;
31    protected JButton okButton;
32    protected JButton cancelButton;
33    protected JButton helpButton;
34    protected JLabel microText;
35    protected String microTextString;
36    String toolType = new String();
37    CVWPreferences cvwPref;
38    String avText;
39  
40    Container contentPane;
41  
42  /**
43   * Constructor
44   *
45   * @param par the parent window
46   * @param title the type of window this is i.e. Audio or Video
47   * @param prefs the CVWPreferences to change.
48   */
49    AVToolFrame(CVWFrame par, String title, CVWPreferences prefs) {
50      super(title + " Tool Location");
51      toolType = title;
52      cvwPref = prefs;
53  
54      setBackground(Color.lightGray);
55      parent = par;
56      contentPane = getContentPane();
57  
58      contentPane.setLayout(gridbag);
59  
60      // set font for default button
61      bold = new Font("Helvetica", Font.BOLD, 12);
62  
63      Font big = new Font("Helvetica", Font.BOLD, 18);
64      avText = "To set preferred location and size of the " + 
65        toolType + " Conferencing Tool, move and resize " +
66        "this window to your liking.";
67      
68      panel = new JTextArea(avText, 10, 100);
69      panel.setLineWrap(true);
70      panel.setWrapStyleWord(true);
71      panel.setFont(big);
72      panel.setEditable(false);
73      panel.setBackground(Color.lightGray);
74  
75      // srj 3/2/99 1.1
76      this.addWindowListener(new WindowAdapter() {
77        public void windowClosing(WindowEvent e) {
78    cancel();
79        }
80      });
81  
82      this.addKeyListener(new KeyAdapter() {
83        public void keyReleased(KeyEvent e) {
84    Component target = e.getComponent();
85    if (target == helpButton) 
86      okButton.requestFocus();
87        }
88      });
89  
90      // create the buttons
91      okButton = new JButton("Save");
92      okButton.setFont(bold);
93      okButton.addActionListener(new ActionListener() {
94        public void actionPerformed(ActionEvent e) {
95    ok();
96        }
97      });
98  
99      cancelButton = new JButton("Cancel");
100     cancelButton.addActionListener(new ActionListener() {
101       public void actionPerformed(ActionEvent e) {
102   cancel();
103       }
104     });
105 
106     helpButton = new JButton("Default");
107     helpButton.addActionListener(new ActionListener() {
108       public void actionPerformed(ActionEvent e) {
109   defaultSize();
110       }
111     });
112 
113     // create microtext 
114     microTextString = new String("                                                                                            ");
115     microText = new JLabel(microTextString);
116     microText.setForeground(Color.red);
117 
118     JPanel btnPanel = new JPanel();
119     btnPanel.setLayout(new GridLayout(1,0,5,5));
120     btnPanel.add(okButton);
121     btnPanel.add(cancelButton);
122     btnPanel.add(helpButton);
123 
124     constrain(contentPane, panel, 0,0,5,5, 
125     GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1.0, 1.0, 
126     10, 5, 5, 5, 0, 0);
127     constrain(contentPane, microText, 0,GridBagConstraints.RELATIVE,4,1, 
128     GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1.0, 0.0, 
129     5, 5, 5, 0, 0, 0);
130     constrain(contentPane, btnPanel, 4,GridBagConstraints.RELATIVE,1,1, 
131     GridBagConstraints.NONE, GridBagConstraints.EAST, 0.0, 0.0, 
132     0, 5, 5, 5, 0, 0);
133   }
134 
135 /**
136  * Returns the preferred size as specified in the CVWPreferences.
137  * @return the preferred size as specified in the CVWPreferences
138  * @see CVWPreferences#getAVSize;
139  */
140   public Dimension getPreferredSize() {
141     Rectangle size = cvwPref.getAVSize(toolType);
142     return new Dimension(size.width, size.height);
143   }
144   
145 
146 /**
147  * If the window is not already showing, set its size to the one specified in 
148  * CVWPreferences.
149  * @param b whether to show or hide the window
150  */
151     public void setVisible(boolean b) {
152       if (b && !isShowing()) {
153         Rectangle size = cvwPref.getAVSize(toolType);
154         setBounds(size.x, size.y, size.width, size.height);
155        }
156       super.setVisible(b);
157     }
158 
159 /**
160  * Saves the current size and location of this window to the CVWPreferences and
161  * then closes.
162  * @see CVWPreferences#setAVSize;
163  */
164   public void ok() {
165       if(CVWCoordinator.DEBUG) System.err.println("OKAY "+ getBounds());
166      cvwPref.setAVSize(toolType, getBounds());
167      destroy();
168   }
169 
170 /**
171  * Closes the window but first resets its size to the size when first opened.
172  */
173   public void cancel() {
174       if(CVWCoordinator.DEBUG) System.err.println("CANCEL!");
175       Rectangle size = cvwPref.getAVSize(toolType);
176       setBounds(size.x, size.y, size.width, size.height);
177       destroy();
178   }
179 
180 /**
181  * Resets this window to the default size as defined by CVWPreferences.
182  * @see CVWPreferences#getDefaultSize;
183  */
184   public void defaultSize() {
185     Rectangle r = CVWPreferences.getDefaultSize(toolType);
186     if(CVWCoordinator.DEBUG) System.err.println("x="+r.x+",y="+r.y+",width="+r.width+",height="+r.height);
187     setBounds(r.x, r.y, r.width, r.height);
188     doLayout();
189     panel.doLayout();
190   }
191 
192 /**
193  * Closes the window.
194  * @return 
195  */
196   public boolean destroy() {
197     this.setVisible(false);
198     this.dispose();
199     return true;
200   }
201 
202 }
203 
204