Source Code Cross Referenced for WindowMenuUtil.java in  » Swing-Library » InfoNode-Docking-Windows » net » infonode » docking » util » 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 » InfoNode Docking Windows » net.infonode.docking.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2004 NNL Technology AB
003:         * Visit www.infonode.net for information about InfoNode(R) 
004:         * products and how to contact NNL Technology AB.
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
019:         * MA 02111-1307, USA.
020:         */
021:
022:        // $Id: WindowMenuUtil.java,v 1.27 2007/01/28 21:25:10 jesper Exp $
023:        package net.infonode.docking.util;
024:
025:        import net.infonode.docking.*;
026:        import net.infonode.docking.action.*;
027:        import net.infonode.docking.internalutil.InternalDockingUtil;
028:        import net.infonode.gui.icon.button.ArrowIcon;
029:        import net.infonode.gui.menu.MenuUtil;
030:        import net.infonode.tabbedpanel.TabbedPanelProperties;
031:        import net.infonode.tabbedpanel.titledtab.TitledTabProperties;
032:        import net.infonode.util.Direction;
033:
034:        import javax.swing.*;
035:        import java.awt.event.ActionEvent;
036:        import java.awt.event.ActionListener;
037:
038:        /**
039:         * Class containing utility methods for creating window popup menues.
040:         *
041:         * @author $Author: jesper $
042:         * @version $Revision: 1.27 $
043:         */
044:        public final class WindowMenuUtil {
045:            private WindowMenuUtil() {
046:            }
047:
048:            private static final Icon[] ARROW_ICONS = new Icon[4];
049:
050:            static {
051:                final Direction[] directions = Direction.getDirections();
052:
053:                for (int i = 0; i < directions.length; i++)
054:                    ARROW_ICONS[i] = new ArrowIcon(
055:                            InternalDockingUtil.DEFAULT_BUTTON_ICON_SIZE + 1,
056:                            directions[i]);
057:            }
058:
059:            private static AbstractTabWindow getTabWindowFor(
060:                    DockingWindow window) {
061:                return (AbstractTabWindow) (window instanceof  AbstractTabWindow ? window
062:                        : window.getWindowParent() != null
063:                                && window.getWindowParent() instanceof  AbstractTabWindow ? window
064:                                .getWindowParent()
065:                                : null);
066:            }
067:
068:            private static JMenu getMoveToMenuItems(final DockingWindow window) {
069:                JMenu moveToMenu = new JMenu("Move to Window Bar");
070:
071:                if (window.isMinimizable()) {
072:                    final RootWindow root = window.getRootWindow();
073:                    final Direction[] directions = Direction.getDirections();
074:
075:                    for (int i = 0; i < 4; i++) {
076:                        final Direction dir = directions[i];
077:
078:                        if (!DockingUtil.isAncestor(root.getWindowBar(dir),
079:                                window)
080:                                && root.getWindowBar(dir).isEnabled()) {
081:                            moveToMenu
082:                                    .add(
083:                                            new JMenuItem(dir.getName(),
084:                                                    ARROW_ICONS[i]))
085:                                    .addActionListener(new ActionListener() {
086:                                        public void actionPerformed(
087:                                                ActionEvent e) {
088:                                            root.getWindowBar(dir).addTab(
089:                                                    window);
090:                                        }
091:                                    });
092:                        }
093:                    }
094:                }
095:
096:                return moveToMenu;
097:            }
098:
099:            private static void addWindowMenuItems(JPopupMenu menu,
100:                    DockingWindow window) {
101:                menu.add(UndockWithAbortWindowAction.INSTANCE.getAction(window)
102:                        .toSwingAction());
103:                menu.add(DockWithAbortWindowAction.INSTANCE.getAction(window)
104:                        .toSwingAction());
105:                menu.add(RestoreWithAbortWindowAction.INSTANCE
106:                        .getAction(window).toSwingAction());
107:                menu.add(MinimizeWithAbortWindowAction.INSTANCE.getAction(
108:                        window).toSwingAction());
109:
110:                if (window instanceof  TabWindow)
111:                    menu.add(MaximizeWithAbortWindowAction.INSTANCE.getAction(
112:                            window).toSwingAction());
113:
114:                menu.add(CloseWithAbortWindowAction.INSTANCE.getAction(window)
115:                        .toSwingAction());
116:
117:                if (window.getWindowParent() instanceof  AbstractTabWindow)
118:                    menu.add(CloseOthersWindowAction.INSTANCE.getAction(window)
119:                            .toSwingAction());
120:
121:                JMenu moveToMenu = getMoveToMenuItems(window);
122:
123:                if (moveToMenu.getItemCount() > 0) {
124:                    menu.add(moveToMenu);
125:                }
126:            }
127:
128:            private static void addNewViewMenuItems(JPopupMenu menu,
129:                    final DockingWindow window, ViewFactoryManager viewManager) {
130:                ViewFactory[] viewFactories = viewManager.getViewFactories();
131:
132:                if (viewFactories.length == 0)
133:                    return;
134:
135:                JMenu viewsPopup = new JMenu("Show View");
136:
137:                for (int i = 0; i < viewFactories.length; i++) {
138:                    final ViewFactory vf = viewFactories[i];
139:
140:                    viewsPopup.add(new JMenuItem(vf.getTitle(), vf.getIcon()))
141:                            .addActionListener(new ActionListener() {
142:                                public void actionPerformed(ActionEvent e) {
143:                                    View view = vf.createView();
144:
145:                                    if (view.getRootWindow() == window
146:                                            .getRootWindow())
147:                                        return;
148:
149:                                    view.restore();
150:
151:                                    if (view.getRootWindow() == window
152:                                            .getRootWindow())
153:                                        return;
154:
155:                                    if (window instanceof  RootWindow)
156:                                        ((RootWindow) window).setWindow(view);
157:                                    else {
158:                                        AbstractTabWindow tabWindow = getTabWindowFor(window);
159:
160:                                        if (tabWindow != null)
161:                                            tabWindow.addTab(view);
162:                                    }
163:                                }
164:                            });
165:                }
166:
167:                menu.add(viewsPopup);
168:            }
169:
170:            private static void addTabOrientationMenuItems(JPopupMenu menu,
171:                    DockingWindow window) {
172:                final AbstractTabWindow tabWindow = getTabWindowFor(window);
173:
174:                if (tabWindow == null || tabWindow instanceof  WindowBar)
175:                    return;
176:
177:                JMenu orientationMenu = new JMenu("Tab Orientation");
178:                TabbedPanelProperties properties = tabWindow
179:                        .getTabWindowProperties().getTabbedPanelProperties();
180:                final Direction[] directions = Direction.getDirections();
181:
182:                for (int i = 0; i < directions.length; i++) {
183:                    final Direction dir = directions[i];
184:                    JMenuItem item = orientationMenu.add(new JMenuItem(dir
185:                            .getName(), ARROW_ICONS[i]));
186:                    item.setEnabled(dir != properties.getTabAreaOrientation());
187:                    item.addActionListener(new ActionListener() {
188:                        public void actionPerformed(ActionEvent e) {
189:                            tabWindow.getTabWindowProperties()
190:                                    .getTabbedPanelProperties()
191:                                    .setTabAreaOrientation(dir);
192:                        }
193:                    });
194:                }
195:
196:                menu.add(orientationMenu);
197:            }
198:
199:            private static void addTabDirectionMenuItems(JPopupMenu menu,
200:                    DockingWindow window) {
201:                final AbstractTabWindow tabWindow = getTabWindowFor(window);
202:
203:                if (tabWindow == null)
204:                    return;
205:
206:                JMenu directionMenu = new JMenu("Tab Direction");
207:                TitledTabProperties properties = TitledTabProperties
208:                        .getDefaultProperties();
209:                properties.addSuperObject(tabWindow.getTabWindowProperties()
210:                        .getTabProperties().getTitledTabProperties());
211:                final Direction[] directions = Direction.getDirections();
212:
213:                for (int i = 0; i < directions.length; i++) {
214:                    final Direction dir = directions[i];
215:
216:                    if (dir != Direction.LEFT) {
217:                        JMenuItem item = directionMenu.add(new JMenuItem(dir
218:                                .getName(), ARROW_ICONS[i]));
219:                        item.setEnabled(dir != properties.getNormalProperties()
220:                                .getDirection());
221:                        item.addActionListener(new ActionListener() {
222:                            public void actionPerformed(ActionEvent e) {
223:                                tabWindow.getTabWindowProperties()
224:                                        .getTabProperties()
225:                                        .getTitledTabProperties()
226:                                        .getNormalProperties()
227:                                        .setDirection(dir);
228:                            }
229:                        });
230:                    }
231:                }
232:
233:                menu.add(directionMenu);
234:            }
235:
236:            private static void addSplitWindowMenuItems(JPopupMenu menu,
237:                    final DockingWindow window) {
238:                if (window instanceof  SplitWindow) {
239:                    JMenu splitMenu = new JMenu("Split Window");
240:
241:                    splitMenu.add("25%").addActionListener(
242:                            new ActionListener() {
243:                                public void actionPerformed(ActionEvent e) {
244:                                    ((SplitWindow) window)
245:                                            .setDividerLocation(0.25f);
246:                                }
247:                            });
248:
249:                    splitMenu.add("50%").addActionListener(
250:                            new ActionListener() {
251:                                public void actionPerformed(ActionEvent e) {
252:                                    ((SplitWindow) window)
253:                                            .setDividerLocation(0.5f);
254:                                }
255:                            });
256:
257:                    splitMenu.add("75%").addActionListener(
258:                            new ActionListener() {
259:                                public void actionPerformed(ActionEvent e) {
260:                                    ((SplitWindow) window)
261:                                            .setDividerLocation(0.75f);
262:                                }
263:                            });
264:
265:                    splitMenu.addSeparator();
266:
267:                    splitMenu.add("Flip Orientation").addActionListener(
268:                            new ActionListener() {
269:                                public void actionPerformed(ActionEvent e) {
270:                                    ((SplitWindow) window)
271:                                            .setHorizontal(!((SplitWindow) window)
272:                                                    .isHorizontal());
273:                                }
274:                            });
275:
276:                    splitMenu.add("Mirror").addActionListener(
277:                            new ActionListener() {
278:                                public void actionPerformed(ActionEvent e) {
279:                                    SplitWindow sw = (SplitWindow) window;
280:                                    sw.setWindows(window.getChildWindow(1),
281:                                            window.getChildWindow(0));
282:                                    sw.setDividerLocation(1 - sw
283:                                            .getDividerLocation());
284:                                }
285:                            });
286:
287:                    menu.add(splitMenu);
288:                }
289:            }
290:
291:            /**
292:             * Creates a factory which creates a popup menu containing common window actions.
293:             *
294:             * @param viewFactoryManager used for creating a list of views that the user can show
295:             * @param addTabItems        add items for changing tab direction and orientation
296:             * @return the window popup menu factory
297:             */
298:            public static WindowPopupMenuFactory createWindowMenuFactory(
299:                    ViewFactoryManager viewFactoryManager, boolean addTabItems) {
300:                return createWindowMenuFactory(viewFactoryManager, addTabItems,
301:                        true);
302:            }
303:
304:            /**
305:             * Creates a factory which creates a popup menu containing common window actions.
306:             *
307:             * @param viewFactoryManager  used for creating a list of views that the user can show
308:             * @param addTabItems         add items for changing tab direction and orientation
309:             * @param addSplitWindowItems add items for {@link SplitWindow}'s
310:             * @return the window popup menu factory
311:             * @since IDW 1.2.0
312:             */
313:            public static WindowPopupMenuFactory createWindowMenuFactory(
314:                    final ViewFactoryManager viewFactoryManager,
315:                    final boolean addTabItems, final boolean addSplitWindowItems) {
316:                return new WindowPopupMenuFactory() {
317:                    public JPopupMenu createPopupMenu(DockingWindow window) {
318:                        JPopupMenu menu = new JPopupMenu(window.getTitle());
319:
320:                        if (!(window instanceof  RootWindow)) {
321:                            if (!(window instanceof  WindowBar)) {
322:                                addWindowMenuItems(menu, window);
323:                                menu.addSeparator();
324:                            }
325:
326:                            if (addTabItems) {
327:                                addTabOrientationMenuItems(menu, window);
328:                                addTabDirectionMenuItems(menu, window);
329:                                menu.addSeparator();
330:                            }
331:
332:                            if (addSplitWindowItems) {
333:                                addSplitWindowMenuItems(menu, window);
334:                                menu.addSeparator();
335:                            }
336:                        }
337:
338:                        addNewViewMenuItems(menu, window, viewFactoryManager);
339:                        MenuUtil.optimizeSeparators(menu);
340:                        MenuUtil.align(menu);
341:                        return menu;
342:                    }
343:                };
344:            }
345:
346:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.