source: trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSFrame.java@ 2179

Last change on this file since 2179 was 2162, checked in by say1, 23 years ago

logging fixes. clearing objects in the GUI to ease garbage collection. menu item to force global garbage collections.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/*
2 * SimpleGraphicalClient.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.nzdl.gsdl.SimpleGraphicalClient;
20
21
22import javax.swing.JMenuItem;
23import javax.swing.JMenuBar;
24import javax.swing.JPanel;
25import javax.swing.JFrame;
26import javax.swing.JList;
27import javax.swing.JPopupMenu;
28import javax.swing.BoxLayout;
29import javax.swing.JMenu;
30import javax.swing.AbstractAction;
31import javax.swing.SwingUtilities;
32import javax.swing.KeyStroke;
33
34import java.awt.*;
35import java.awt.event.*;
36import java.util.Observer;
37import java.util.Observable;
38/**
39 * Class
40 *
41 * A class to
42 *
43 * @author Dave Nichols ([email protected])
44 * @author stuart yeates ([email protected])
45 * @version $Revision: 2162 $
46 * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient
47 */
48
49public class CSFrame extends JFrame implements Observer, Constants
50
51{
52
53CSModel csModel;
54SearchPanel searchPanel;
55JPanel otherPanel;
56
57
58 // Constructor
59 public CSFrame(String title, CSModel newCSModel)
60 {
61 setTitle(title); // Set the window title
62
63 csModel = newCSModel;
64 Container content = getContentPane();
65
66 setJMenuBar(menuBar); // Add the menu bar to the window
67
68 JMenu fileMenu = new JMenu("File"); // Create File menu
69 JMenu editMenu = new JMenu("Edit"); // Create Edit menu
70
71 // File Menu
72
73 //fileMenu.add( newSpaceAction = new FileAction("New Space", NEW_SPACE_ID)).setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK));;
74 //fileMenu.add( newGroupAction = new FileAction("New Group", NEW_GROUP_ID)).setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK));;
75 //fileMenu.add( newPersonAction = new FileAction("New Person", NEW_PERSON_ID)).setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK));
76 //fileMenu.addSeparator();
77 fileMenu.add( quitAction = new FileAction("Poll Server", POLL_ID)).setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK));;
78 fileMenu.add( quitAction = new FileAction("Collect Garbage", GARBAGE_ID)).setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK));;
79 fileMenu.add( quitAction = new FileAction("Quit", QUIT_ID)).setAccelerator(KeyStroke.getKeyStroke('Q', Event.CTRL_MASK));;
80
81
82 editMenu.add( infoAction = new EditAction("Info...", INFO_ID));
83 editMenu.add( editAction = new EditAction("Edit...", EDIT_ID));
84
85 menuBar.add(fileMenu); // Add the file menu
86 // menuBar.add(editMenu); // Add the edit menu
87
88
89 searchPanel = new SearchPanel(csModel, this);
90 otherPanel = new JPanel();
91
92 content.setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
93 content.add(searchPanel);
94
95 //csModel.addObserver(this);
96 addWindowListener(new WindowHandler());
97 //jlist.addMouseListener( new MouseHandler(this));
98
99 pack();
100 searchPanel.searchTextField.requestFocus();
101 } //end constructor
102
103
104public void update(Observable observedThing, Object o )
105 {
106 System.out.println("Updating...");
107 //jlist.setListData( ((CSModel)observedThing).getModel() );
108 }
109
110
111
112 // action objects
113
114 abstract class CSAction extends AbstractAction
115 {
116 int menuItemID;
117
118 CSAction( String name, int newMenuItemID)
119 {
120 super(name);
121 menuItemID = newMenuItemID;
122 }
123
124 public abstract void actionPerformed(ActionEvent e);
125
126 } //end CSAction
127
128 class FileAction extends CSAction
129 {
130 FileAction(String name, int newMenuItemID)
131 {
132 super(name,newMenuItemID );
133 }
134
135 public void actionPerformed(ActionEvent e)
136 {
137 switch (menuItemID) {
138 case NEW_PERSON_ID:
139 System.out.println("new person chosen from menu");
140 Frame f = new Frame();
141 //newPersonDialog = new NewPersonDialog(f, psModel);
142 break;
143 case NEW_SPACE_ID:
144 System.out.println("new space chosen from menu");
145 break;
146 case NEW_GROUP_ID:
147 System.out.println("new group chosen from menu");
148 break;
149 case GARBAGE_ID:
150 System.err.println("forcing gc...");
151 System.gc() ;
152 System.runFinalization();
153 System.err.println("forcing gc...");
154 System.gc() ;
155 System.runFinalization();
156 System.err.println("forced gc");
157 break;
158 case POLL_ID:
159 System.out.println("poll chosen from menu");
160 break;
161 case QUIT_ID:
162 System.out.println("quit chosen from menu");
163 dispose(); // free resources
164 System.exit(0); // exit program
165 break;
166 default:
167 System.out.println("unimplemented option chosen from FileAction");
168 break;
169 } // end switch
170 }//end actionPerformed
171 } // end FileAction
172
173 class EditAction extends CSAction
174 {
175 EditAction(String name, int newMenuItemID)
176 {
177 super(name,newMenuItemID );
178 }
179
180 public void actionPerformed(ActionEvent e)
181 {
182 switch (menuItemID) {
183 case INFO_ID:
184 System.out.println("info Action chosen");
185 break;
186 case EDIT_ID:
187 System.out.println("edit Action chosen");
188 break;
189 default:
190 System.out.println("unimplemented option chosen from EditAction");
191 break;
192 } // end switch
193 } //end actionPerformed
194 } // end EditAction
195
196
197class WindowHandler extends WindowAdapter
198{
199
200 public void windowOpened(WindowEvent e) {
201
202 SwingUtilities.invokeLater(new Runnable() {
203 public void run() {
204 searchPanel.searchTextField.requestFocus();
205 searchPanel.searchTextField.setCaretPosition(
206 searchPanel.searchTextField.getText().length() );
207 searchPanel.searchTextField.selectAll();
208 }
209 });
210 } //end windowOpened
211
212
213
214 public void windowClosing(WindowEvent e)
215 {
216 dispose(); // free resources
217 System.exit(0); // exit program
218 }
219}// end WindowHandler
220
221
222class MouseHandler extends MouseAdapter
223{
224private Frame frame;
225
226 public MouseHandler( CSFrame f )
227 {
228 this.frame = f;
229 }
230
231 public void mouseClicked(MouseEvent e) {
232 //System.out.println("mouse event" );
233 if (e.getClickCount() == 2) {
234 System.out.println("double click - mouse event" );
235 int index = jlist.locationToIndex(e.getPoint());
236 System.out.println("index is " + index );
237 //psObject = (PeopleSpaceObject) jlist.getModel().getElementAt(index);
238 } //end if
239 } //end mouseClicked
240
241 public void mousePressed(MouseEvent e) {
242 maybeShowPopup(e);
243 }
244
245 public void mouseReleased(MouseEvent e) {
246 maybeShowPopup(e);
247 }
248
249 private void maybeShowPopup(MouseEvent e) {
250 if (e.isPopupTrigger()) {
251 contextPopup.show(e.getComponent(),
252 e.getX(), e.getY());
253 } //end if
254 } //end maybeShowPopup
255
256 } //end class MouseHandler
257
258 // private declarations
259 private JMenuBar menuBar = new JMenuBar(); // Window menu bar
260 private JMenuItem newSpaceItem, newGroupItem, newPersonItem, quitItem;
261
262 private JList jlist, peopleList;
263 private JPopupMenu contextPopup;
264
265 // FileActions
266 private FileAction newSpaceAction, newGroupAction, newPersonAction, quitAction;
267
268 // EditActions
269
270 private EditAction infoAction, editAction, weightsAction;
271
272 //Dialog
273
274 //private NewPersonDialog newPersonDialog;
275
276} //end CSFrame
Note: See TracBrowser for help on using the repository browser.