KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > PopupExample


1 /*
2  * $Id: PopupExample.java,v 1.7 2005/04/26 12:03:31 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.awt.event.ActionListener JavaDoc;
18
19 import org.wings.*;
20
21 /**
22  * @author <a HREF="mailto:hengels@mercatis.de">Holger Engels</a>
23  * @version $Revision: 1.7 $
24  */

25 public class PopupExample extends WingSetPane {
26
27     private SLabel selection;
28
29     private final ActionListener JavaDoc menuItemListener = new ActionListener JavaDoc() {
30         public void actionPerformed(ActionEvent JavaDoc e) {
31             selection.setText(((SMenuItem) e.getSource()).getText());
32         }
33     };
34
35     public SComponent createExample() {
36
37         SPopupMenu menu = new SPopupMenu();
38         menu.add(createMenuItem("Cut"));
39         menu.add(createMenuItem("Copy"));
40         menu.add(createMenuItem("Paste"));
41
42         SMenu subMenu = new SMenu("Help");
43         subMenu.add(createMenuItem("About"));
44         subMenu.add(createMenuItem("Topics"));
45         menu.add(subMenu);
46         
47         SPopupMenu menu2 = new SPopupMenu();
48         menu2.add(createMenuItem("Open"));
49         menu2.add(createMenuItem("Save"));
50         menu2.add(createMenuItem("Close"));
51
52         SLabel testLabel = new SLabel("This label has a context menu.");
53         testLabel.setComponentPopupMenu(menu);
54         SLabel testLabel2 = new SLabel("This label has the same context menu.");
55         testLabel2.setComponentPopupMenu(menu);
56         SLabel testLabel3 = new SLabel("This label has another context menu.");
57         testLabel3.setComponentPopupMenu(menu2);
58         SLabel selectionLabel = new SLabel("Selected Menu: ");
59         selection = new SLabel("none");
60
61         SPanel all = new SPanel();
62         all.add(testLabel);
63         all.add(testLabel2);
64         all.add(testLabel3);
65         all.add(selectionLabel);
66         all.add(selection);
67         return all;
68     }
69
70     private SMenuItem createMenuItem(String JavaDoc string) {
71         SMenuItem result = new SMenuItem(string);
72         result.addActionListener(menuItemListener);
73         return result;
74     }
75 }
76
Popular Tags