KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SPopupMenu


1 /*
2  * $Id: SPopupMenu.java,v 1.11 2005/05/18 16:06:16 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 org.wings;
15
16 import org.wings.plaf.PopupMenuCG;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 /**
22  * @author hengels
23  * @version $Revision: 1.11 $
24  */

25 public class SPopupMenu
26         extends SComponent {
27     protected final List JavaDoc menuItems = new ArrayList JavaDoc();
28     private double widthScaleFactor = 0.7f;
29
30     /**
31      * Add a menu item to this menu.
32      */

33     public void add(SMenuItem menuItem) {
34         menuItems.add(menuItem);
35         menuItem.setParentMenu(this);
36     }
37
38     /**
39      * Add a menu item to this menu.
40      */

41     public void add(SComponent menuItem) {
42         menuItems.add(menuItem);
43         menuItem.setParentFrame(getParentFrame());
44     }
45
46     public void setParentFrame(SFrame f) {
47         super.setParentFrame(f);
48         for (int i = 0; i < menuItems.size(); i++) {
49             ((SComponent) menuItems.get(i)).setParentFrame(f);
50         }
51     }
52
53     /**
54      * Add a menu item to this menu.
55      */

56     public void add(String JavaDoc menuitem) {
57         this.add(new SMenuItem(menuitem));
58     }
59
60     public SComponent getMenuComponent(int pos) {
61         return (SComponent) menuItems.get(pos);
62     }
63
64     /**
65      * Return the number of items on the menu, including separators.
66      */

67     public int getMenuComponentCount() {
68         return menuItems.size();
69     }
70
71     /**
72      * Remove all {@link SMenuItem} from this menu.
73      */

74     public void removeAll() {
75         while (menuItems.size() > 0) {
76             remove(0);
77         }
78     }
79
80     /**
81      * Removes the menu item at specified index from the menu.
82      */

83     public void remove(int pos) {
84         remove(getMenuComponent(pos));
85     }
86
87     /**
88      * removes a specific menu item component.
89      */

90     public void remove(SComponent comp) {
91         menuItems.remove(comp);
92         comp.setParentFrame(null);
93     }
94
95     public void setCG(PopupMenuCG cg) {
96         super.setCG(cg);
97     }
98
99     /**
100      * Returns the scale factor for the width of the Menu components.
101      * The length of the children texts is multiplied by this factor and set as
102      * width (in em) for the children.
103      *
104      * @return Returns the widthScaleFactor.
105      */

106     public double getWidthScaleFactor() {
107         return widthScaleFactor;
108     }
109     /**
110      * Sets the scale factor for the width of the Menu components.
111      * The length of the children texts is multiplied by this factor and set as
112      * width (in em) for the children.
113      *
114      * Default value is 0.8.
115      *
116      * @param widthScaleFactor The widthScaleFactor to set.
117      */

118     public void setWidthScaleFactor(double widthScaleFactor) {
119         this.widthScaleFactor = widthScaleFactor;
120     }
121 }
122
Popular Tags