Source Code Cross Referenced for SMenuBar.java in  » Swing-Library » Swinglets » com » javelin » swinglets » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » Swinglets » com.javelin.swinglets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Javelin Software, All rights reserved.
003:         */
004:
005:        package com.javelin.swinglets;
006:
007:        /**
008:         * A SMenuBar is a menu bar for adding SMenu's to.
009:         * 
010:         * @author Robin Sharp
011:         */
012:
013:        import java.awt.*;
014:        import java.awt.event.*;
015:        import java.io.*;
016:        import java.util.*;
017:
018:        import com.javelin.swinglets.event.*;
019:
020:        public class SMenuBar extends SContainer {
021:            /**
022:             * Construct a SMenuBar.
023:             */
024:            public SMenuBar() {
025:            }
026:
027:            /**
028:             * Returns the name of the L&F class that renders this component.
029:             */
030:            public Class getUIClass() {
031:                return SMenuBar.class;
032:            }
033:
034:            /**
035:             * Get the top level ancestor. 
036:             */
037:            public SContainer getTopLevelAncestor() {
038:                return frame;
039:            }
040:
041:            /**
042:             * Get the SFrame.
043:             */
044:            public SFrame getFrame() {
045:                return frame;
046:            }
047:
048:            /**
049:             * Set the SFrame to which this SMenu Belongs.
050:             */
051:            public SMenuBar setFrame(SFrame frame) {
052:                if (this .frame == frame)
053:                    return this ;
054:
055:                //Remove the menubar on the old frame
056:                if (this .frame != null) {
057:                    this .frame.setMenuBar(null);
058:                }
059:
060:                this .frame = frame;
061:
062:                //Add the menubar to the new frame
063:                if (frame != null) {
064:                    frame.setMenuBar(this );
065:                }
066:
067:                return this ;
068:            }
069:
070:            /**
071:             * Get the placement of the menus.
072:             */
073:            public int getMenuPlacement() {
074:                return menuPlacement;
075:            }
076:
077:            /**
078:             * Sets the placement of menus. <br>
079:             * One of SConstants.TOP, SConstants.BOTTOM, SConstants.LEFT, or SConstants.RIGHT.
080:             */
081:            public SMenuBar setMenuPlacement(int menuPlacement) {
082:                this .menuPlacement = menuPlacement;
083:                return this ;
084:            }
085:
086:            /**
087:             * Appends the specified SMenuItem to the end of the menu bar.
088:             */
089:            public SMenuItem add(SMenuItem c) {
090:                super .add(c);
091:                return c;
092:            }
093:
094:            /**
095:             * Gets the SMenuItem at the specified position in the menu bar.
096:             */
097:            public SMenuItem getMenuItem(int index) {
098:                SComponent c = getComponent(index);
099:
100:                if (c instanceof  SMenuItem)
101:                    return (SMenuItem) c;
102:
103:                return null;
104:            }
105:
106:            /**
107:             * Returns the number of items in the menu bar.
108:             */
109:            public int getMenuCount() {
110:                return getComponentCount();
111:            }
112:
113:            /**
114:             * Returns the index of the specified component.
115:             */
116:            public int getComponentIndex(SComponent c) {
117:                int count = this .getComponentCount();
118:                SComponent[] component = this .getComponents();
119:                for (int index = 0; index < count; index++) {
120:                    SComponent comp = component[index];
121:                    if (comp == c) {
122:                        return index;
123:                    }
124:                }
125:                return -1;
126:            }
127:
128:            /**
129:             * Sets the currently selected component.
130:             */
131:            public SMenuBar setSelected(SComponent component) {
132:                if (component == null) {
133:                    selectedIndex = -1;
134:                } else {
135:                    selectedIndex = getComponentIndex(component);
136:                }
137:
138:                return this ;
139:            }
140:
141:            /**
142:             * Returns true if the MenuBar currently has a component selected
143:             */
144:            public boolean isSelected() {
145:                return selectedIndex >= 0;
146:            }
147:
148:            /**
149:             * Get the selected index
150:             */
151:            public int getSelectedIndex() {
152:                return selectedIndex;
153:            }
154:
155:            /**
156:             * Drill down to find the selected SMenu, or null.
157:             */
158:            public SMenu getSelectedMenu() {
159:                return getSelectedMenu((SMenu) getMenuItem(getSelectedIndex()));
160:            }
161:
162:            /**
163:             * Drill down to find the selected SMenu, or null.
164:             */
165:            protected SMenu getSelectedMenu(SMenu menu) {
166:                if (menu.isSelected()) {
167:                    SMenuItem subMenu = menu.getItem(menu.getSelectedIndex());
168:                    if (subMenu != null && subMenu instanceof  SMenu) {
169:                        return getSelectedMenu((SMenu) subMenu);
170:                    }
171:
172:                    return null;
173:                } else {
174:                    return menu;
175:                }
176:            }
177:
178:            /** 
179:             * Returns true if the Menubar's border should be painted.
180:             */
181:            public boolean isBorderPainted() {
182:                return borderPainted;
183:            }
184:
185:            /**
186:             * Sets whether the border should be painted.
187:             */
188:            public SMenuBar setBorderPainted(boolean borderPainted) {
189:                this .borderPainted = borderPainted;
190:                return this ;
191:            }
192:
193:            /** 
194:             * Processes events occurring on this component.
195:             */
196:            protected void processEvent(AWTEvent event) {
197:                if (event instanceof  FormEvent) {
198:                    processFormEvent((FormEvent) event);
199:                }
200:            }
201:
202:            /**
203:             * Process the FormEvent to compute which menu item has been 
204:             * selected. 
205:             * <p>
206:             * If this is branch node the display the children, by updating 
207:             * the selected item value.
208:             * <p>
209:             * If this is a leaf node then notify the node that it has 
210:             * been selected through an action event.
211:             */
212:            protected void processFormEvent(FormEvent event) {
213:                //System.out.println( "SMenuBar.processFormEvent\n" + event );
214:
215:                //Reset the selected index, unless otherwise stated.
216:                selectedIndex = -1;
217:
218:                //System.out.println( event );
219:                for (Enumeration names = event.getParameterNames(); names
220:                        .hasMoreElements();) {
221:                    String name = (String) names.nextElement();
222:                    if (Character.isDigit(name.charAt(0))) {
223:                        int index = name.indexOf('.');
224:                        int menuIndex = -1;
225:                        if (index >= 0) {
226:                            menuIndex = Integer.parseInt(name.substring(0,
227:                                    index));
228:                        } else {
229:                            menuIndex = Integer.parseInt(name);
230:                        }
231:
232:                        //Check to see if the selected index was a menu or a menuItem
233:                        //If it was a menu item then fire an action event and reset the 
234:                        //selected index
235:                        SMenuItem menuItem = getMenuItem(menuIndex);
236:                        if (menuItem != null) {
237:                            if (menuItem instanceof  SMenu) {
238:                                selectedIndex = menuIndex;
239:                            } else if (menuItem instanceof  SMenuItem) {
240:                                menuItem.dispatchEvent(new ActionEvent(
241:                                        menuItem, ActionEvent.ACTION_PERFORMED,
242:                                        null));
243:                            }
244:                        }
245:                    }
246:                }
247:            }
248:
249:            /**
250:             * Paint this component in the header.
251:             */
252:            public void paintHeaderx(Object out) {
253:                getUI().updateHeader(out, this );
254:            }
255:
256:            /**
257:             * Paint this component.
258:             */
259:            public void paintx(Object out) {
260:                getUI().update(out, this );
261:            }
262:
263:            // PRIVATE //////////////////////////////////////////////////////////
264:
265:            protected SFrame frame;
266:
267:            protected int menuPlacement = SConstants.TOP;
268:            protected boolean borderPainted;
269:            protected int selectedIndex = -1;
270:
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.