Source Code Cross Referenced for DemoFrame.java in  » Swing-Library » jgoodies-looks » com » jgoodies » looks » demo » 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 » jgoodies looks » com.jgoodies.looks.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         * 
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer. 
009:         *     
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution. 
013:         *     
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of 
015:         *    its contributors may be used to endorse or promote products derived 
016:         *    from this software without specific prior written permission. 
017:         *     
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029:         */
030:
031:        package com.jgoodies.looks.demo;
032:
033:        import java.awt.BorderLayout;
034:        import java.awt.Component;
035:        import java.awt.Dimension;
036:        import java.awt.event.ActionEvent;
037:        import java.awt.event.ActionListener;
038:        import java.awt.event.KeyEvent;
039:        import java.net.URL;
040:
041:        import javax.swing.*;
042:        import javax.swing.border.EmptyBorder;
043:        import javax.swing.plaf.metal.DefaultMetalTheme;
044:        import javax.swing.plaf.metal.MetalLookAndFeel;
045:
046:        import com.jgoodies.looks.LookUtils;
047:        import com.jgoodies.looks.Options;
048:        import com.jgoodies.looks.plastic.PlasticLookAndFeel;
049:        import com.jgoodies.looks.windows.WindowsLookAndFeel;
050:
051:        /** 
052:         * Builds the main frame in the Simple Looks Demo. 
053:         * Demonstrates and tests different multi-platform issues by
054:         * showing a variety of Swing widgets in different configurations.<p>
055:         * 
056:         * This class provides a couple of protected methods that create
057:         * components or a builder. The full JGoodies Looks Demo overrides 
058:         * these methods to vend components or builders from the 
059:         * JGoodies UI framework that better handle different platforms.
060:         * 
061:         * @author Karsten Lentzsch
062:         * @version $Revision: 1.16 $
063:         */
064:        public class DemoFrame extends JFrame {
065:
066:            protected static final Dimension PREFERRED_SIZE = LookUtils.IS_LOW_RESOLUTION ? new Dimension(
067:                    650, 510)
068:                    : new Dimension(730, 560);
069:
070:            private static final String COPYRIGHT = "\u00a9 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.";
071:
072:            /** Describes optional settings of the JGoodies Looks. */
073:            private final Settings settings;
074:
075:            /**
076:             * Constructs a <code>DemoFrame</code>, configures the UI, 
077:             * and builds the content.
078:             */
079:            protected DemoFrame(Settings settings) {
080:                this .settings = settings;
081:                configureUI();
082:                build();
083:                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
084:            }
085:
086:            public static void main(String[] args) {
087:                Settings settings = createDefaultSettings();
088:                if (args.length > 0) {
089:                    String lafShortName = args[0];
090:                    String lafClassName;
091:                    if ("Windows".equalsIgnoreCase(lafShortName)) {
092:                        lafClassName = Options.JGOODIES_WINDOWS_NAME;
093:                    } else if ("Plastic".equalsIgnoreCase(lafShortName)) {
094:                        lafClassName = Options.PLASTIC_NAME;
095:                    } else if ("Plastic3D".equalsIgnoreCase(lafShortName)) {
096:                        lafClassName = Options.PLASTIC3D_NAME;
097:                    } else if ("PlasticXP".equalsIgnoreCase(lafShortName)) {
098:                        lafClassName = Options.PLASTICXP_NAME;
099:                    } else {
100:                        lafClassName = lafShortName;
101:                    }
102:                    System.out.println("L&f chosen: " + lafClassName);
103:                    settings.setSelectedLookAndFeel(lafClassName);
104:                }
105:                DemoFrame instance = new DemoFrame(settings);
106:                instance.setSize(PREFERRED_SIZE);
107:                instance.locateOnScreen(instance);
108:                instance.setVisible(true);
109:            }
110:
111:            private static Settings createDefaultSettings() {
112:                Settings settings = Settings.createDefault();
113:
114:                // Configure the settings here.
115:
116:                return settings;
117:            }
118:
119:            /**
120:             * Configures the user interface; requests Swing settings and 
121:             * JGoodies Looks options from the launcher.
122:             */
123:            private void configureUI() {
124:                // UIManager.put("ToolTip.hideAccelerator", Boolean.FALSE);
125:
126:                Options.setDefaultIconSize(new Dimension(18, 18));
127:
128:                Options.setUseNarrowButtons(settings.isUseNarrowButtons());
129:
130:                // Global options
131:                Options.setTabIconsEnabled(settings.isTabIconsEnabled());
132:                UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, settings
133:                        .isPopupDropShadowEnabled());
134:
135:                // Swing Settings
136:                LookAndFeel selectedLaf = settings.getSelectedLookAndFeel();
137:                if (selectedLaf instanceof  PlasticLookAndFeel) {
138:                    PlasticLookAndFeel.setPlasticTheme(settings
139:                            .getSelectedTheme());
140:                    PlasticLookAndFeel.setTabStyle(settings
141:                            .getPlasticTabStyle());
142:                    PlasticLookAndFeel
143:                            .setHighContrastFocusColorsEnabled(settings
144:                                    .isPlasticHighContrastFocusEnabled());
145:                } else if (selectedLaf.getClass() == MetalLookAndFeel.class) {
146:                    MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
147:                }
148:
149:                // Work around caching in MetalRadioButtonUI
150:                JRadioButton radio = new JRadioButton();
151:                radio.getUI().uninstallUI(radio);
152:                JCheckBox checkBox = new JCheckBox();
153:                checkBox.getUI().uninstallUI(checkBox);
154:
155:                try {
156:                    UIManager.setLookAndFeel(selectedLaf);
157:                } catch (Exception e) {
158:                    System.out.println("Can't change L&F: " + e);
159:                }
160:
161:            }
162:
163:            /**
164:             * Builds the <code>DemoFrame</code> using Options from the Launcher.
165:             */
166:            private void build() {
167:                setContentPane(buildContentPane());
168:                setTitle(getWindowTitle());
169:                setJMenuBar(createMenuBuilder()
170:                        .buildMenuBar(settings, createHelpActionListener(),
171:                                createAboutActionListener()));
172:                setIconImage(readImageIcon("eye_16x16.gif").getImage());
173:            }
174:
175:            /** 
176:             * Creates and returns a builder that builds the menu.
177:             * This method is overriden by the full JGoodies Looks Demo to use
178:             * a more sophisticated menu builder that uses the JGoodies
179:             * UI Framework.
180:             * 
181:             * @return the builder that builds the menu bar
182:             */
183:            protected MenuBarView createMenuBuilder() {
184:                return new MenuBarView();
185:            }
186:
187:            /**
188:             * Builds and answers the content.
189:             */
190:            private JComponent buildContentPane() {
191:                JPanel panel = new JPanel(new BorderLayout());
192:                panel.add(buildToolBar(), BorderLayout.NORTH);
193:                panel.add(buildMainPanel(), BorderLayout.CENTER);
194:                return panel;
195:            }
196:
197:            // Tool Bar *************************************************************
198:
199:            /**
200:             * Builds, configures and returns the toolbar. Requests
201:             * HeaderStyle, look-specific BorderStyles, and Plastic 3D Hint 
202:             * from Launcher.
203:             */
204:            private Component buildToolBar() {
205:                JToolBar toolBar = new JToolBar();
206:                toolBar.setFloatable(true);
207:                toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
208:                // Swing
209:                toolBar.putClientProperty(Options.HEADER_STYLE_KEY, settings
210:                        .getToolBarHeaderStyle());
211:                toolBar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY,
212:                        settings.getToolBarPlasticBorderStyle());
213:                toolBar.putClientProperty(WindowsLookAndFeel.BORDER_STYLE_KEY,
214:                        settings.getToolBarWindowsBorderStyle());
215:                toolBar.putClientProperty(PlasticLookAndFeel.IS_3D_KEY,
216:                        settings.getToolBar3DHint());
217:
218:                AbstractButton button;
219:
220:                toolBar.add(createToolBarButton("backward.gif", "Back"));
221:                button = createToolBarButton("forward.gif", "Next");
222:                button.setEnabled(false);
223:                toolBar.add(button);
224:                toolBar.add(createToolBarButton("home.gif", "Home"));
225:                toolBar.addSeparator();
226:
227:                ActionListener openAction = new OpenFileActionListener();
228:                button = createToolBarButton("open.gif", "Open", openAction,
229:                        KeyStroke.getKeyStroke(KeyEvent.VK_O,
230:                                KeyEvent.CTRL_DOWN_MASK));
231:                button.addActionListener(openAction);
232:                toolBar.add(button);
233:                toolBar.add(createToolBarButton("print.gif", "Print"));
234:                toolBar.add(createToolBarButton("refresh.gif", "Update"));
235:                toolBar.addSeparator();
236:
237:                ButtonGroup group = new ButtonGroup();
238:                button = createToolBarRadioButton("pie_mode.png", "Pie Chart");
239:                button.setSelectedIcon(readImageIcon("pie_mode_selected.gif"));
240:                group.add(button);
241:                button.setSelected(true);
242:                toolBar.add(button);
243:
244:                button = createToolBarRadioButton("bar_mode.png", "Bar Chart");
245:                button.setSelectedIcon(readImageIcon("bar_mode_selected.gif"));
246:                group.add(button);
247:                toolBar.add(button);
248:
249:                button = createToolBarRadioButton("table_mode.png", "Table");
250:                button
251:                        .setSelectedIcon(readImageIcon("table_mode_selected.gif"));
252:                group.add(button);
253:                toolBar.add(button);
254:                toolBar.addSeparator();
255:
256:                button = createToolBarButton("help.gif", "Open Help");
257:                button.addActionListener(createHelpActionListener());
258:                toolBar.add(button);
259:
260:                return toolBar;
261:            }
262:
263:            /**
264:             * Creates and returns a JButton configured for use in a JToolBar.<p>
265:             * 
266:             * This is a simplified method that is overriden by the Looks Demo.
267:             * The full code uses the JGoodies UI framework's ToolBarButton
268:             * that better handles platform differences.
269:             */
270:            protected AbstractButton createToolBarButton(String iconName,
271:                    String toolTipText) {
272:                JButton button = new JButton(readImageIcon(iconName));
273:                button.setToolTipText(toolTipText);
274:                button.setFocusable(false);
275:                return button;
276:            }
277:
278:            private AbstractButton createToolBarButton(String iconName,
279:                    String toolTipText, ActionListener action,
280:                    KeyStroke keyStroke) {
281:                AbstractButton button = createToolBarButton(iconName,
282:                        toolTipText);
283:                button.registerKeyboardAction(action, keyStroke,
284:                        JComponent.WHEN_IN_FOCUSED_WINDOW);
285:                return button;
286:            }
287:
288:            /**
289:             * Creates and returns a JToggleButton configured for use in a JToolBar.<p>
290:             * 
291:             * This is a simplified method that is overriden by the Looks Demo.
292:             * The full code uses the JGoodies UI framework's ToolBarButton
293:             * that better handles platform differences.
294:             */
295:            protected AbstractButton createToolBarRadioButton(String iconName,
296:                    String toolTipText) {
297:                JToggleButton button = new JToggleButton(
298:                        readImageIcon(iconName));
299:                button.setToolTipText(toolTipText);
300:                button.setFocusable(false);
301:                return button;
302:            }
303:
304:            // Tabbed Pane **********************************************************
305:
306:            /**
307:             * Builds and answers the tabbed pane.
308:             */
309:            private Component buildMainPanel() {
310:                JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
311:                //tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
312:
313:                addTabs(tabbedPane);
314:
315:                tabbedPane.setBorder(new EmptyBorder(10, 10, 10, 10));
316:                return tabbedPane;
317:            }
318:
319:            private void addTabs(JTabbedPane tabbedPane) {
320:                tabbedPane.addTab("State", new StateTab().build());
321:                tabbedPane.addTab("Align", new AlignmentTab().build());
322:                tabbedPane.addTab("Tab", new TabTestTab().build());
323:                tabbedPane.addTab("Split", new SplitTab().build());
324:                tabbedPane.addTab("Combo", new ComboBoxTab().build());
325:                tabbedPane.addTab("HTML", new HtmlTab().build());
326:                tabbedPane.addTab("Dialog", new DialogsTab().build(tabbedPane));
327:                tabbedPane.addTab("Desktop", new DesktopTab().build());
328:                tabbedPane.addTab("Narrow", new NarrowTab().build());
329:            }
330:
331:            protected String getWindowTitle() {
332:                return "Simple Looks Demo";
333:            }
334:
335:            // Helper Code **********************************************************************
336:
337:            /**
338:             * Looks up and returns an icon for the specified filename suffix.
339:             */
340:            protected static ImageIcon readImageIcon(String filename) {
341:                URL url = DemoFrame.class.getResource("resources/images/"
342:                        + filename);
343:                return new ImageIcon(url);
344:            }
345:
346:            /**
347:             * Locates the given component on the screen's center.
348:             */
349:            protected void locateOnScreen(Component component) {
350:                Dimension paneSize = component.getSize();
351:                Dimension screenSize = component.getToolkit().getScreenSize();
352:                component.setLocation((screenSize.width - paneSize.width) / 2,
353:                        (screenSize.height - paneSize.height) / 2);
354:            }
355:
356:            /**
357:             * Creates and answers an ActionListener that opens the help viewer.
358:             */
359:            protected ActionListener createHelpActionListener() {
360:                return null;
361:            }
362:
363:            /**
364:             * Creates and answers an ActionListener that opens the about dialog.
365:             */
366:            protected ActionListener createAboutActionListener() {
367:                return new AboutActionListener();
368:            }
369:
370:            private final class AboutActionListener implements  ActionListener {
371:                public void actionPerformed(ActionEvent e) {
372:                    JOptionPane.showMessageDialog(DemoFrame.this ,
373:                            "The simple Looks Demo Application\n\n" + COPYRIGHT
374:                                    + "\n\n");
375:                }
376:            }
377:
378:            private final class OpenFileActionListener implements 
379:                    ActionListener {
380:                public void actionPerformed(ActionEvent e) {
381:                    new JFileChooser().showOpenDialog(DemoFrame.this);
382:                }
383:            }
384:
385:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.