KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ext > security > gui > SecurityGui


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.ext.security.gui;
32
33 import java.awt.*;
34 import java.awt.event.*;
35
36 import javax.swing.BorderFactory JavaDoc;
37 import javax.swing.ButtonGroup JavaDoc;
38 import javax.swing.ImageIcon JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JCheckBoxMenuItem JavaDoc;
41 import javax.swing.JComboBox JavaDoc;
42 import javax.swing.JFrame JavaDoc;
43 import javax.swing.JLabel JavaDoc;
44 import javax.swing.JMenu JavaDoc;
45 import javax.swing.JMenuBar JavaDoc;
46 import javax.swing.JMenuItem JavaDoc;
47 import javax.swing.JPanel JavaDoc;
48 import javax.swing.JRadioButtonMenuItem JavaDoc;
49 import javax.swing.JScrollPane JavaDoc;
50 import javax.swing.JSplitPane JavaDoc;
51 import javax.swing.JTable JavaDoc;
52 import javax.swing.JTextArea JavaDoc;
53 import javax.swing.JTextField JavaDoc;
54 import javax.swing.KeyStroke JavaDoc;
55
56
57 /*
58  * This class exists solely to show you what menus look like.
59  * It has no menu-related event handling.
60  */

61 public class SecurityGui extends JFrame JavaDoc {
62     JTextArea JavaDoc output;
63     JScrollPane JavaDoc scrollPane;
64     JTextField JavaDoc sender;
65     JComboBox JavaDoc senderFromAuth;
66     JComboBox JavaDoc senderFromInt;
67     JComboBox JavaDoc senderFromConf;
68     JComboBox JavaDoc senderToAuth;
69     JComboBox JavaDoc senderToInt;
70     JComboBox JavaDoc senderToConf;
71     JTextField JavaDoc receiver;
72     JComboBox JavaDoc receiverFromAuth;
73     JComboBox JavaDoc receiverFromInt;
74     JComboBox JavaDoc receiverFromConf;
75     JComboBox JavaDoc receiverToAuth;
76     JComboBox JavaDoc receiverToInt;
77     JComboBox JavaDoc receiverToConf;
78
79     public SecurityGui() {
80         JMenuBar JavaDoc menuBar;
81         JMenu JavaDoc menu;
82         JMenu JavaDoc submenu;
83         JMenuItem JavaDoc menuItem;
84         JCheckBoxMenuItem JavaDoc cbMenuItem;
85         JRadioButtonMenuItem JavaDoc rbMenuItem;
86
87         addWindowListener(new WindowAdapter() {
88                 public void windowClosing(WindowEvent e) {
89                     System.exit(0);
90                 }
91             });
92
93         //Suggest that the L&F (rather than the system)
94
//decorate all windows. This must be invoked before
95
//creating the JFrame. Native look and feels will
96
//ignore this hint.
97
setDefaultLookAndFeelDecorated(false);
98
99         //Add regular components to the window, using the default BorderLayout.
100
Container contentPane = getContentPane();
101         output = new JTextArea JavaDoc(5, 30);
102         output.setEditable(false);
103         scrollPane = new JScrollPane JavaDoc(output);
104         contentPane.add(scrollPane, BorderLayout.CENTER);
105
106         //Create the menu bar.
107
menuBar = new JMenuBar JavaDoc();
108         setJMenuBar(menuBar);
109
110         //Build the first menu.
111
menu = new JMenu JavaDoc("A Menu");
112         menu.setMnemonic(KeyEvent.VK_A);
113         menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
114         menuBar.add(menu);
115
116         //a group of JMenuItems
117
menuItem = new JMenuItem JavaDoc("A text-only menu item", KeyEvent.VK_T);
118
119         //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
120
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
121                 ActionEvent.ALT_MASK));
122         menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
123         menu.add(menuItem);
124
125         menuItem = new JMenuItem JavaDoc("Both text and icon",
126                 new ImageIcon JavaDoc("images/middle.gif"));
127         menuItem.setMnemonic(KeyEvent.VK_B);
128         menu.add(menuItem);
129
130         menuItem = new JMenuItem JavaDoc(new ImageIcon JavaDoc("images/middle.gif"));
131         menuItem.setMnemonic(KeyEvent.VK_D);
132         menu.add(menuItem);
133
134         //a group of radio button menu items
135
menu.addSeparator();
136
137         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
138
139         rbMenuItem = new JRadioButtonMenuItem JavaDoc("A radio button menu item");
140         rbMenuItem.setSelected(true);
141         rbMenuItem.setMnemonic(KeyEvent.VK_R);
142         group.add(rbMenuItem);
143         menu.add(rbMenuItem);
144
145         rbMenuItem = new JRadioButtonMenuItem JavaDoc("Another one");
146         rbMenuItem.setMnemonic(KeyEvent.VK_O);
147         group.add(rbMenuItem);
148         menu.add(rbMenuItem);
149
150         //a group of check box menu items
151
menu.addSeparator();
152         cbMenuItem = new JCheckBoxMenuItem JavaDoc("A check box menu item");
153         cbMenuItem.setMnemonic(KeyEvent.VK_C);
154         menu.add(cbMenuItem);
155
156         cbMenuItem = new JCheckBoxMenuItem JavaDoc("Another one");
157         cbMenuItem.setMnemonic(KeyEvent.VK_H);
158         menu.add(cbMenuItem);
159
160         //a submenu
161
menu.addSeparator();
162         submenu = new JMenu JavaDoc("A submenu");
163         submenu.setMnemonic(KeyEvent.VK_S);
164
165         menuItem = new JMenuItem JavaDoc("An item in the submenu");
166         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
167                 ActionEvent.ALT_MASK));
168         submenu.add(menuItem);
169
170         menuItem = new JMenuItem JavaDoc("Another item");
171         submenu.add(menuItem);
172         menu.add(submenu);
173
174         //Build second menu in the menu bar.
175
menu = new JMenu JavaDoc("Another Menu");
176         menu.setMnemonic(KeyEvent.VK_N);
177         menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
178         menuBar.add(menu);
179
180         // table
181
String JavaDoc[] columnNames = {
182             "First Name", "Last Name", "Sport", "# of Years", "Vegetarian"
183         };
184
185         Object JavaDoc[][] data = new Object JavaDoc[0][];
186         JTable JavaDoc table = new JTable JavaDoc(data, columnNames);
187         table.setPreferredScrollableViewportSize(new Dimension(500, 70));
188
189         //Container contentPane =
190
GridBagLayout editorLayout = new GridBagLayout();
191         GridBagConstraints c = new GridBagConstraints();
192         JPanel JavaDoc editorPanel = new JPanel JavaDoc();
193         editorPanel.setBorder(BorderFactory.createTitledBorder(
194                 "Move the Mouse to Move Duke"));
195         editorPanel.setLayout(editorLayout);
196
197         String JavaDoc[] attributesModeStrings = { "Required", "Optional", "Disallowed" };
198
199         // Create the combo box, select item at index 4.
200
// Indices start at 0, so 4 specifies the pig.
201
JLabel JavaDoc name = new JLabel JavaDoc("Target");
202         c.gridx = 0;
203         c.gridy = 0;
204         editorLayout.setConstraints(name, c);
205         editorPanel.add(name);
206
207         sender = new JTextField JavaDoc(10);
208         sender.setActionCommand("Target");
209         c.gridx = 1;
210         c.gridy = 0;
211         editorLayout.setConstraints(sender, c);
212         editorPanel.add(sender);
213
214         name = new JLabel JavaDoc("Authentication");
215         c.gridx = 0;
216         c.gridy = 5;
217         editorLayout.setConstraints(name, c);
218         editorPanel.add(name);
219
220         senderToAuth = new JComboBox JavaDoc(attributesModeStrings);
221         senderToAuth.setSelectedIndex(0);
222
223         //attributeModeList.addActionListener(this);
224
c.gridx = 1;
225         c.gridy = 5;
226         editorLayout.setConstraints(senderToAuth, c);
227         editorPanel.add(senderToAuth);
228
229         name = new JLabel JavaDoc("integrity");
230         c.gridx = 0;
231         c.gridy = 6;
232         editorLayout.setConstraints(name, c);
233         editorPanel.add(name);
234
235         senderFromInt = new JComboBox JavaDoc(attributesModeStrings);
236         senderFromInt.setSelectedIndex(0);
237         c.gridx = 1;
238         c.gridy = 6;
239         editorLayout.setConstraints(senderFromInt, c);
240         editorPanel.add(senderFromInt);
241
242         name = new JLabel JavaDoc("confidentiality");
243         c.gridx = 0;
244         c.gridy = 7;
245         editorLayout.setConstraints(name, c);
246         editorPanel.add(name);
247
248         senderFromConf = new JComboBox JavaDoc(attributesModeStrings);
249         senderFromConf.setSelectedIndex(0);
250         c.gridx = 1;
251         c.gridy = 7;
252         editorLayout.setConstraints(senderFromConf, c);
253         editorPanel.add(senderFromConf);
254
255         name = new JLabel JavaDoc(" >>>> ");
256         c.gridx = 2;
257         c.gridy = 5;
258         editorLayout.setConstraints(name, c);
259         editorPanel.add(name);
260
261         name = new JLabel JavaDoc("authentification");
262         c.gridx = 3;
263         c.gridy = 5;
264         editorLayout.setConstraints(name, c);
265         editorPanel.add(name);
266
267         receiverFromAuth = new JComboBox JavaDoc(attributesModeStrings);
268         receiverFromAuth.setSelectedIndex(0);
269         c.gridx = 4;
270         c.gridy = 5;
271         editorLayout.setConstraints(receiverFromAuth, c);
272         editorPanel.add(receiverFromAuth);
273         name = new JLabel JavaDoc("integrity");
274         c.gridx = 3;
275         c.gridy = 6;
276         editorLayout.setConstraints(name, c);
277         editorPanel.add(name);
278
279         receiverFromInt = new JComboBox JavaDoc(attributesModeStrings);
280         receiverFromInt.setSelectedIndex(0);
281         c.gridx = 4;
282         c.gridy = 6;
283         editorLayout.setConstraints(receiverFromInt, c);
284         editorPanel.add(receiverFromInt);
285
286         name = new JLabel JavaDoc("confidentiality");
287         c.gridx = 3;
288         c.gridy = 7;
289         editorLayout.setConstraints(name, c);
290         editorPanel.add(name);
291
292         receiverFromInt = new JComboBox JavaDoc(attributesModeStrings);
293         receiverFromInt.setSelectedIndex(0);
294         c.gridx = 4;
295         c.gridy = 7;
296         editorLayout.setConstraints(receiverFromInt, c);
297         editorPanel.add(receiverFromInt);
298
299         name = new JLabel JavaDoc("Authentication");
300         c.gridx = 0;
301         c.gridy = 1;
302         editorLayout.setConstraints(name, c);
303         editorPanel.add(name);
304
305         senderFromAuth = new JComboBox JavaDoc(attributesModeStrings);
306         senderFromAuth.setSelectedIndex(0);
307
308         //attributeModeList.addActionListener(this);
309
c.gridx = 1;
310         c.gridy = 1;
311         editorLayout.setConstraints(senderFromAuth, c);
312         editorPanel.add(senderFromAuth);
313
314         name = new JLabel JavaDoc("integrity");
315         c.gridx = 0;
316         c.gridy = 2;
317         editorLayout.setConstraints(name, c);
318         editorPanel.add(name);
319
320         senderFromInt = new JComboBox JavaDoc(attributesModeStrings);
321         senderFromInt.setSelectedIndex(0);
322         c.gridx = 1;
323         c.gridy = 2;
324         editorLayout.setConstraints(senderFromInt, c);
325         editorPanel.add(senderFromInt);
326
327         name = new JLabel JavaDoc("confidentiality");
328         c.gridx = 0;
329         c.gridy = 3;
330         editorLayout.setConstraints(name, c);
331         editorPanel.add(name);
332
333         senderFromConf = new JComboBox JavaDoc(attributesModeStrings);
334         senderFromConf.setSelectedIndex(0);
335         c.gridx = 1;
336         c.gridy = 3;
337         editorLayout.setConstraints(senderFromConf, c);
338         editorPanel.add(senderFromConf);
339
340         name = new JLabel JavaDoc(" <<<< ");
341         c.gridx = 2;
342         c.gridy = 2;
343         editorLayout.setConstraints(name, c);
344         editorPanel.add(name);
345
346         name = new JLabel JavaDoc("Target");
347         c.gridx = 3;
348         c.gridy = 0;
349         editorLayout.setConstraints(name, c);
350         editorPanel.add(name);
351
352         receiver = new JTextField JavaDoc(10);
353         receiver.setActionCommand("Target");
354         c.gridx = 4;
355         c.gridy = 0;
356         editorLayout.setConstraints(receiver, c);
357         editorPanel.add(receiver);
358
359         name = new JLabel JavaDoc("authentification");
360         c.gridx = 3;
361         c.gridy = 1;
362         editorLayout.setConstraints(name, c);
363         editorPanel.add(name);
364
365         receiverFromAuth = new JComboBox JavaDoc(attributesModeStrings);
366         receiverFromAuth.setSelectedIndex(0);
367         c.gridx = 4;
368         c.gridy = 1;
369         editorLayout.setConstraints(receiverFromAuth, c);
370         editorPanel.add(receiverFromAuth);
371         name = new JLabel JavaDoc("integrity");
372         c.gridx = 3;
373         c.gridy = 2;
374         editorLayout.setConstraints(name, c);
375         editorPanel.add(name);
376
377         receiverFromInt = new JComboBox JavaDoc(attributesModeStrings);
378         receiverFromInt.setSelectedIndex(0);
379         c.gridx = 4;
380         c.gridy = 2;
381         editorLayout.setConstraints(receiverFromInt, c);
382         editorPanel.add(receiverFromInt);
383
384         name = new JLabel JavaDoc("confidentiality");
385         c.gridx = 3;
386         c.gridy = 3;
387         editorLayout.setConstraints(name, c);
388         editorPanel.add(name);
389
390         receiverFromConf = new JComboBox JavaDoc(attributesModeStrings);
391         receiverFromConf.setSelectedIndex(0);
392         c.gridx = 4;
393         c.gridy = 3;
394         editorLayout.setConstraints(receiverFromConf, c);
395         editorPanel.add(receiverFromConf);
396
397         JButton JavaDoc button = new JButton JavaDoc("Add");
398         c.gridx = 5;
399         c.gridy = 4;
400         editorLayout.setConstraints(button, c);
401         editorPanel.add(button);
402
403         // editor Scroll Pane
404
JScrollPane JavaDoc editScrollPane = new JScrollPane JavaDoc(editorPanel);
405
406         // textField.addActionListener(this);
407
//Create the scroll pane and add the table to it.
408
JScrollPane JavaDoc tableScrollPane = new JScrollPane JavaDoc(table);
409
410         // Create a split pane with the two scroll panes in it.
411
JSplitPane JavaDoc splitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT,
412                 editScrollPane, tableScrollPane);
413         splitPane.setOneTouchExpandable(true);
414         splitPane.setDividerLocation(150);
415
416         // Add the scroll pane to this window.
417
getContentPane().add(splitPane, BorderLayout.CENTER);
418     }
419
420     public void actionPerformed(ActionEvent e) {
421     }
422
423     public static void main(String JavaDoc[] args) {
424         JFrame.setDefaultLookAndFeelDecorated(true);
425
426         SecurityGui window = new SecurityGui();
427
428         window.setTitle("MenuLookDemo");
429         window.setSize(450, 260);
430         window.setVisible(true);
431     }
432 }
433
Popular Tags