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 | */
|
---|
19 | package org.nzdl.gsdl.SimpleGraphicalClient;
|
---|
20 |
|
---|
21 |
|
---|
22 | import javax.swing.*;
|
---|
23 | import javax.swing.border.*;
|
---|
24 | import java.awt.*;
|
---|
25 | import java.awt.event.*;
|
---|
26 | import java.util.*;
|
---|
27 | /**
|
---|
28 | * Class
|
---|
29 | *
|
---|
30 | * A class to
|
---|
31 | *
|
---|
32 | * @author Dave Nichols ([email protected])
|
---|
33 | * @author stuart yeates ([email protected])
|
---|
34 | * @version $Revision: 2144 $
|
---|
35 | * @see org.nzdl.gsdl.service.SimpleGraphicalClient.SimpleGraphicalClient
|
---|
36 | */
|
---|
37 |
|
---|
38 | public class CSFrame extends JFrame implements Observer, Constants
|
---|
39 |
|
---|
40 | {
|
---|
41 |
|
---|
42 | CSModel csModel;
|
---|
43 | SearchPanel searchPanel;
|
---|
44 | JPanel otherPanel;
|
---|
45 |
|
---|
46 |
|
---|
47 | // Constructor
|
---|
48 | public CSFrame(String title, CSModel newCSModel)
|
---|
49 | {
|
---|
50 | setTitle(title); // Set the window title
|
---|
51 |
|
---|
52 | csModel = newCSModel;
|
---|
53 | Container content = getContentPane();
|
---|
54 |
|
---|
55 | setJMenuBar(menuBar); // Add the menu bar to the window
|
---|
56 |
|
---|
57 | JMenu fileMenu = new JMenu("File"); // Create File menu
|
---|
58 | JMenu editMenu = new JMenu("Edit"); // Create Edit menu
|
---|
59 |
|
---|
60 | // File Menu
|
---|
61 |
|
---|
62 | //fileMenu.add( newSpaceAction = new FileAction("New Space", NEW_SPACE_ID)).setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK));;
|
---|
63 | //fileMenu.add( newGroupAction = new FileAction("New Group", NEW_GROUP_ID)).setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK));;
|
---|
64 | //fileMenu.add( newPersonAction = new FileAction("New Person", NEW_PERSON_ID)).setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK));
|
---|
65 | //fileMenu.addSeparator();
|
---|
66 | fileMenu.add( quitAction = new FileAction("Poll Server", POLL_ID)).setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK));;
|
---|
67 | fileMenu.add( quitAction = new FileAction("Quit", QUIT_ID)).setAccelerator(KeyStroke.getKeyStroke('Q', Event.CTRL_MASK));;
|
---|
68 |
|
---|
69 |
|
---|
70 | editMenu.add( infoAction = new EditAction("Info...", INFO_ID));
|
---|
71 | editMenu.add( editAction = new EditAction("Edit...", EDIT_ID));
|
---|
72 |
|
---|
73 | menuBar.add(fileMenu); // Add the file menu
|
---|
74 | // menuBar.add(editMenu); // Add the edit menu
|
---|
75 |
|
---|
76 |
|
---|
77 | searchPanel = new SearchPanel(csModel, this);
|
---|
78 | otherPanel = new JPanel();
|
---|
79 |
|
---|
80 | content.setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
|
---|
81 | content.add(searchPanel);
|
---|
82 |
|
---|
83 | //csModel.addObserver(this);
|
---|
84 | addWindowListener(new WindowHandler());
|
---|
85 | //jlist.addMouseListener( new MouseHandler(this));
|
---|
86 |
|
---|
87 | pack();
|
---|
88 | searchPanel.searchTextField.requestFocus();
|
---|
89 | } //end constructor
|
---|
90 |
|
---|
91 |
|
---|
92 | public void update(Observable observedThing, Object o )
|
---|
93 | {
|
---|
94 | System.out.println("Updating...");
|
---|
95 | //jlist.setListData( ((CSModel)observedThing).getModel() );
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 |
|
---|
100 | // action objects
|
---|
101 |
|
---|
102 | abstract class CSAction extends AbstractAction
|
---|
103 | {
|
---|
104 | int menuItemID;
|
---|
105 |
|
---|
106 | CSAction( String name, int newMenuItemID)
|
---|
107 | {
|
---|
108 | super(name);
|
---|
109 | menuItemID = newMenuItemID;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public abstract void actionPerformed(ActionEvent e);
|
---|
113 |
|
---|
114 | } //end CSAction
|
---|
115 |
|
---|
116 | class FileAction extends CSAction
|
---|
117 | {
|
---|
118 | FileAction(String name, int newMenuItemID)
|
---|
119 | {
|
---|
120 | super(name,newMenuItemID );
|
---|
121 | }
|
---|
122 |
|
---|
123 | public void actionPerformed(ActionEvent e)
|
---|
124 | {
|
---|
125 | switch (menuItemID) {
|
---|
126 | case NEW_PERSON_ID:
|
---|
127 | System.out.println("new person chosen from menu");
|
---|
128 | Frame f = new Frame();
|
---|
129 | //newPersonDialog = new NewPersonDialog(f, psModel);
|
---|
130 | break;
|
---|
131 | case NEW_SPACE_ID:
|
---|
132 | System.out.println("new space chosen from menu");
|
---|
133 | break;
|
---|
134 | case NEW_GROUP_ID:
|
---|
135 | System.out.println("new group chosen from menu");
|
---|
136 | break;
|
---|
137 | case POLL_ID:
|
---|
138 | System.out.println("poll chosen from menu");
|
---|
139 | break;
|
---|
140 | case QUIT_ID:
|
---|
141 | System.out.println("quit chosen from menu");
|
---|
142 | dispose(); // free resources
|
---|
143 | System.exit(0); // exit program
|
---|
144 | break;
|
---|
145 | default:
|
---|
146 | System.out.println("unimplemented option chosen from FileAction");
|
---|
147 | break;
|
---|
148 | } // end switch
|
---|
149 | }//end actionPerformed
|
---|
150 | } // end FileAction
|
---|
151 |
|
---|
152 | class EditAction extends CSAction
|
---|
153 | {
|
---|
154 | EditAction(String name, int newMenuItemID)
|
---|
155 | {
|
---|
156 | super(name,newMenuItemID );
|
---|
157 | }
|
---|
158 |
|
---|
159 | public void actionPerformed(ActionEvent e)
|
---|
160 | {
|
---|
161 | switch (menuItemID) {
|
---|
162 | case INFO_ID:
|
---|
163 | System.out.println("info Action chosen");
|
---|
164 | break;
|
---|
165 | case EDIT_ID:
|
---|
166 | System.out.println("edit Action chosen");
|
---|
167 | break;
|
---|
168 | default:
|
---|
169 | System.out.println("unimplemented option chosen from EditAction");
|
---|
170 | break;
|
---|
171 | } // end switch
|
---|
172 | } //end actionPerformed
|
---|
173 | } // end EditAction
|
---|
174 |
|
---|
175 |
|
---|
176 | class WindowHandler extends WindowAdapter
|
---|
177 | {
|
---|
178 |
|
---|
179 | public void windowOpened(WindowEvent e) {
|
---|
180 |
|
---|
181 | SwingUtilities.invokeLater(new Runnable() {
|
---|
182 | public void run() {
|
---|
183 | searchPanel.searchTextField.requestFocus();
|
---|
184 | searchPanel.searchTextField.setCaretPosition(
|
---|
185 | searchPanel.searchTextField.getText().length() );
|
---|
186 | searchPanel.searchTextField.selectAll();
|
---|
187 | }
|
---|
188 | });
|
---|
189 | } //end windowOpened
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 | public void windowClosing(WindowEvent e)
|
---|
194 | {
|
---|
195 | dispose(); // free resources
|
---|
196 | System.exit(0); // exit program
|
---|
197 | }
|
---|
198 | }// end WindowHandler
|
---|
199 |
|
---|
200 |
|
---|
201 | class MouseHandler extends MouseAdapter
|
---|
202 | {
|
---|
203 | private Frame frame;
|
---|
204 |
|
---|
205 | public MouseHandler( CSFrame f )
|
---|
206 | {
|
---|
207 | this.frame = f;
|
---|
208 | }
|
---|
209 |
|
---|
210 | public void mouseClicked(MouseEvent e) {
|
---|
211 | //System.out.println("mouse event" );
|
---|
212 | if (e.getClickCount() == 2) {
|
---|
213 | System.out.println("double click - mouse event" );
|
---|
214 | int index = jlist.locationToIndex(e.getPoint());
|
---|
215 | System.out.println("index is " + index );
|
---|
216 | //psObject = (PeopleSpaceObject) jlist.getModel().getElementAt(index);
|
---|
217 | } //end if
|
---|
218 | } //end mouseClicked
|
---|
219 |
|
---|
220 | public void mousePressed(MouseEvent e) {
|
---|
221 | maybeShowPopup(e);
|
---|
222 | }
|
---|
223 |
|
---|
224 | public void mouseReleased(MouseEvent e) {
|
---|
225 | maybeShowPopup(e);
|
---|
226 | }
|
---|
227 |
|
---|
228 | private void maybeShowPopup(MouseEvent e) {
|
---|
229 | if (e.isPopupTrigger()) {
|
---|
230 | contextPopup.show(e.getComponent(),
|
---|
231 | e.getX(), e.getY());
|
---|
232 | } //end if
|
---|
233 | } //end maybeShowPopup
|
---|
234 |
|
---|
235 | } //end class MouseHandler
|
---|
236 |
|
---|
237 | // private declarations
|
---|
238 | private JMenuBar menuBar = new JMenuBar(); // Window menu bar
|
---|
239 | private JMenuItem newSpaceItem, newGroupItem, newPersonItem, quitItem;
|
---|
240 |
|
---|
241 | private JList jlist, peopleList;
|
---|
242 | private JPopupMenu contextPopup;
|
---|
243 |
|
---|
244 | // FileActions
|
---|
245 | private FileAction newSpaceAction, newGroupAction, newPersonAction, quitAction;
|
---|
246 |
|
---|
247 | // EditActions
|
---|
248 |
|
---|
249 | private EditAction infoAction, editAction, weightsAction;
|
---|
250 |
|
---|
251 | //Dialog
|
---|
252 |
|
---|
253 | //private NewPersonDialog newPersonDialog;
|
---|
254 |
|
---|
255 | } //end CSFrame
|
---|