Source Code Cross Referenced for CombosPanel.java in  » Swing-Library » substance-look-feel » test » check » 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 » substance look feel » test.check 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. 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 Substance Kirill Grouchnikov 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:        package test.check;
031:
032:        import java.awt.*;
033:        import java.awt.event.*;
034:        import java.io.IOException;
035:        import java.util.Map;
036:        import java.util.Vector;
037:
038:        import javax.imageio.ImageIO;
039:        import javax.swing.*;
040:
041:        import org.jvnet.lafwidget.LafWidget;
042:        import org.jvnet.lafwidget.combo.AutoCompletionMatcher;
043:        import org.jvnet.substance.*;
044:        import org.jvnet.substance.combo.ComboPopupPrototypeCallback;
045:        import org.jvnet.substance.combo.WidestComboPopupPrototype;
046:        import org.jvnet.substance.theme.SubstanceTheme;
047:        import org.jvnet.substance.theme.ThemeInfo;
048:
049:        import test.Check;
050:        import test.check.command.*;
051:
052:        import com.jgoodies.forms.builder.DefaultFormBuilder;
053:        import com.jgoodies.forms.layout.FormLayout;
054:
055:        /**
056:         * Test application panel for testing {@link JComboBox} component.
057:         * 
058:         * @author Kirill Grouchnikov
059:         */
060:        public class CombosPanel extends ControllablePanel {
061:            /**
062:             * Renderer for the combobox containing the theme list.
063:             * 
064:             * @author Kirill Grouchnikov
065:             */
066:            protected static class ThemeComboRenderer extends JLabel implements 
067:                    ListCellRenderer {
068:                /**
069:                 * The current theme.
070:                 */
071:                protected SubstanceTheme currTheme;
072:
073:                public Component getListCellRendererComponent(JList list,
074:                        Object value, int index, boolean isSelected,
075:                        boolean cellHasFocus) {
076:                    SubstanceTheme theme = (SubstanceTheme) value;
077:                    this .setBackground(theme.getColorScheme().getMidColor());
078:                    this .setForeground(theme.getColorScheme()
079:                            .getForegroundColor());
080:                    this .setText(theme.getDisplayName());
081:                    this .currTheme = theme;
082:                    return this ;
083:                }
084:
085:                @Override
086:                public void paint(Graphics g) {
087:                    int width = this .getWidth();
088:                    int height = this .getHeight();
089:                    SubstanceImageCreator.paintRectangularBackground(g, 0, 0,
090:                            width, height, this .currTheme.getColorScheme(),
091:                            0.0f, false);
092:                    super .paint(g);
093:                }
094:            }
095:
096:            /**
097:             * A configure command that allows editing the specified combobox.
098:             * 
099:             * @author Kirill Grouchnikov
100:             */
101:            public static class EditAllowCommand implements 
102:                    ConfigurationCommand<JComboBox> {
103:                /*
104:                 * (non-Javadoc)
105:                 * 
106:                 * @see test.check.ConfigurationCommand#invoke(java.lang.Object)
107:                 */
108:                public void configure(JComboBox combo) {
109:                    combo.setEditable(true);
110:                }
111:            }
112:
113:            /**
114:             * A configure command that disallows editing the specified combobox.
115:             * 
116:             * @author Kirill Grouchnikov
117:             */
118:            public static class EditDisallowCommand implements 
119:                    ConfigurationCommand<JComboBox> {
120:                /*
121:                 * (non-Javadoc)
122:                 * 
123:                 * @see test.check.ConfigurationCommand#invoke(java.lang.Object)
124:                 */
125:                public void configure(JComboBox combo) {
126:                    combo.setEditable(false);
127:                }
128:            }
129:
130:            /**
131:             * Applies the specified configuration command on all combobox children of
132:             * the specified component.
133:             * 
134:             * @param comp
135:             *            Component.
136:             * @param command
137:             *            Configuration command to apply.
138:             */
139:            public static void run(Component comp,
140:                    ConfigurationCommand<? super  JComboBox> command) {
141:                if (comp instanceof  JComboBox) {
142:                    command.configure((JComboBox) comp);
143:                    return;
144:                }
145:                if (comp instanceof  Container) {
146:                    Container cont = (Container) comp;
147:                    for (int i = 0; i < cont.getComponentCount(); i++) {
148:                        run(cont.getComponent(i), command);
149:                    }
150:                }
151:            }
152:
153:            /**
154:             * Text editor for a combobox that checks fix for defect 151.
155:             * 
156:             * @author Kirill Grouchnikov
157:             */
158:            private class ComboBoxTextEditor151 extends JTextField implements 
159:                    ComboBoxEditor {
160:                /**
161:                 * Document.
162:                 */
163:                javax.swing.text.Document doc;
164:
165:                /**
166:                 * Creates the text editor.
167:                 */
168:                public ComboBoxTextEditor151() {
169:                    super ();
170:                    doc = super .getDocument();
171:                }
172:
173:                /*
174:                 * (non-Javadoc)
175:                 * 
176:                 * @see javax.swing.ComboBoxEditor#getEditorComponent()
177:                 */
178:                public java.awt.Component getEditorComponent() {
179:                    return this ;
180:                }
181:
182:                /*
183:                 * (non-Javadoc)
184:                 * 
185:                 * @see javax.swing.ComboBoxEditor#setItem(java.lang.Object)
186:                 */
187:                public void setItem(Object anObject) {
188:                    if (anObject instanceof  EditableDocument151) {
189:                        super .setCaretPosition(0);
190:                        super .setDocument((javax.swing.text.Document) anObject);
191:                    } else {
192:                        super .setCaretPosition(0);
193:                        super .setDocument(doc);
194:                        super .setText(anObject.toString());
195:
196:                    }
197:
198:                }
199:
200:                /*
201:                 * (non-Javadoc)
202:                 * 
203:                 * @see javax.swing.ComboBoxEditor#getItem()
204:                 */
205:                public Object getItem() {
206:                    return super .getText();
207:                }
208:
209:                /*
210:                 * (non-Javadoc)
211:                 * 
212:                 * @see java.awt.Component#toString()
213:                 */
214:                @Override
215:                public String toString() {
216:                    return super .getText();
217:                }
218:            }
219:
220:            /**
221:             * The document for checking fix for defect 151.
222:             * 
223:             * @author Kirill Grouchnikov
224:             */
225:            private class EditableDocument151 extends
226:                    javax.swing.text.PlainDocument {
227:                /**
228:                 * Creates the document.
229:                 */
230:                public EditableDocument151() {
231:                    this .setText("Long text to show the bug");
232:                }
233:
234:                /*
235:                 * (non-Javadoc)
236:                 * 
237:                 * @see java.lang.Object#toString()
238:                 */
239:                @Override
240:                public String toString() {
241:                    try {
242:                        return super .getText(0, super .getLength());
243:                    } catch (javax.swing.text.BadLocationException ex) {
244:                        return "bad location";
245:                    }
246:                }
247:
248:                /**
249:                 * @param newText
250:                 */
251:                public void setText(String newText) {
252:                    try {
253:                        super .remove(0, super .getLength());
254:                        super .insertString(0, newText,
255:                                new javax.swing.text.SimpleAttributeSet());
256:
257:                    } catch (javax.swing.text.BadLocationException ex) {
258:                        ex.printStackTrace();
259:                    }
260:
261:                }
262:            }
263:
264:            /**
265:             * Returns the left panel with comboboxes.
266:             * 
267:             * @return The left panel with comboboxes.
268:             */
269:            private JPanel getLeftComboPanel() {
270:                FormLayout lm = new FormLayout(
271:                        "right:pref, 4dlu, fill:pref:grow", "");
272:                DefaultFormBuilder builder = new DefaultFormBuilder(lm,
273:                        new ScrollablePanel());
274:                builder.setDefaultDialogBorder();
275:
276:                builder.appendSeparator("Simple combos");
277:
278:                JComboBox comboRegular = new JComboBox(new Object[] { "entry1",
279:                        "entry2", "entry3", "entry4", "entry5", "entry6" });
280:                comboRegular.setToolTipText("This is my combo 1");
281:                comboRegular.setMaximumRowCount(4);
282:                builder.append("Regular", comboRegular);
283:
284:                JComboBox comboActive = new JComboBox(new Object[] { "entry1",
285:                        "entry2", "entry3", "entry4", "entry5", "entry6" });
286:                comboActive.setToolTipText("This combo is active");
287:                comboActive.setMaximumRowCount(4);
288:                comboActive.putClientProperty(
289:                        SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
290:                        Boolean.TRUE);
291:                builder.append("Active", comboActive);
292:
293:                JComboBox comboDisabled = new JComboBox(new Object[] {
294:                        "entry1", "entry2", "entry3" });
295:                comboDisabled.setEnabled(false);
296:                builder.append("Disabled", comboDisabled);
297:
298:                JComboBox comboColored = new JComboBox(new Object[] {
299:                        "entry31", "entry32", "entry33", "entry34", "entry35",
300:                        "entry36", "aaa", "abb", "abc" });
301:                comboColored.setName("Colored combo");
302:                comboColored.setBackground(new Color(255, 128, 128));
303:                comboColored.setForeground(new Color(0, 0, 128));
304:                builder.append("Pink background", comboColored);
305:
306:                JComboBox comboColors = new JComboBox(new Object[] {
307:                        new Color(255, 128, 128), new Color(128, 255, 128),
308:                        new Color(128, 128, 255), new Color(255, 255, 128),
309:                        new Color(255, 128, 255), new Color(128, 255, 255), });
310:                comboColors.setName("Colors combo");
311:                comboColors.setRenderer(new SubstanceDefaultListCellRenderer() {
312:                    public Component getListCellRendererComponent(JList list,
313:                            Object value, int index, boolean isSelected,
314:                            boolean cellHasFocus) {
315:                        JLabel comp = (JLabel) super 
316:                                .getListCellRendererComponent(list, value,
317:                                        index, isSelected, cellHasFocus);
318:                        Color color = (Color) value;
319:                        comp.setBackground(color);
320:                        comp.setText(color.getRed() + ":" + color.getGreen()
321:                                + ":" + color.getBlue());
322:                        return comp;
323:                    }
324:                });
325:                builder.append("Colors", comboColors);
326:
327:                JComboBox comboFlat = new JComboBox(new Object[] { "entry1",
328:                        "entry2", "entry3", "entry4", "entry5", "entry6" });
329:                comboFlat.putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY,
330:                        Boolean.TRUE);
331:                builder.append("Flat button", comboFlat);
332:
333:                JComboBox comboDefaultCoreRenderer = new JComboBox(
334:                        new Object[] { "entry1", "entry2", "entry3", "entry4",
335:                                "entry5", "entry6" });
336:                comboDefaultCoreRenderer
337:                        .setRenderer(new DefaultListCellRenderer());
338:                builder.append("Default core renderer",
339:                        comboDefaultCoreRenderer);
340:
341:                builder.appendSeparator("Auto-completion");
342:
343:                final JComboBox comboCompletionTest = new JComboBox(
344:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
345:                                "Sergi" });
346:                comboCompletionTest.setEditable(true);
347:                comboCompletionTest.addActionListener(new ActionListener() {
348:                    public void actionPerformed(ActionEvent e) {
349:                        Check.out("'" + comboCompletionTest.getSelectedItem()
350:                                + "' selected");
351:                    }
352:                });
353:                builder.append("Free w/ Object[]", comboCompletionTest);
354:
355:                final JComboBox comboCompletionTest2 = new JComboBox();
356:                comboCompletionTest2.setEditable(true);
357:                comboCompletionTest2.setModel(new DefaultComboBoxModel(
358:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
359:                                "Sergi" }));
360:                comboCompletionTest2.addActionListener(new ActionListener() {
361:                    public void actionPerformed(ActionEvent e) {
362:                        Check.out("'" + comboCompletionTest2.getSelectedItem()
363:                                + "' selected");
364:                    }
365:                });
366:                builder.append("Free w/ default", comboCompletionTest2);
367:
368:                final JComboBox comboCompletionModelOnlyTest = new JComboBox(
369:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
370:                                "Sergi" });
371:                comboCompletionModelOnlyTest.setEditable(true);
372:                comboCompletionModelOnlyTest
373:                        .addActionListener(new ActionListener() {
374:                            public void actionPerformed(ActionEvent e) {
375:                                Check.out("'"
376:                                        + comboCompletionModelOnlyTest
377:                                                .getSelectedItem()
378:                                        + "' selected");
379:                            }
380:                        });
381:                comboCompletionModelOnlyTest.putClientProperty(
382:                        LafWidget.COMBO_BOX_USE_MODEL_ONLY, Boolean.TRUE);
383:                builder.append("Model-based", comboCompletionModelOnlyTest);
384:
385:                final JComboBox comboCompletionModelOnlyTestNoLock = new JComboBox(
386:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
387:                                "Sergi" });
388:                comboCompletionModelOnlyTestNoLock.setEditable(true);
389:                comboCompletionModelOnlyTestNoLock
390:                        .addActionListener(new ActionListener() {
391:                            public void actionPerformed(ActionEvent e) {
392:                                Check.out("'"
393:                                        + comboCompletionModelOnlyTest
394:                                                .getSelectedItem()
395:                                        + "' selected");
396:                            }
397:                        });
398:                comboCompletionModelOnlyTestNoLock.putClientProperty(
399:                        LafWidget.COMBO_BOX_USE_MODEL_ONLY, Boolean.TRUE);
400:                comboCompletionModelOnlyTestNoLock.putClientProperty(
401:                        LafWidget.NO_LOCK_ICON, Boolean.TRUE);
402:                builder.append("Model-based no lock",
403:                        comboCompletionModelOnlyTestNoLock);
404:
405:                final JComboBox comboCompletionCaseSensitiveTest = new JComboBox(
406:                        new Object[] { "AJ", "Ester", "Jordi", "Jordina",
407:                                "Jorge", "sergi" });
408:                comboCompletionCaseSensitiveTest.setEditable(true);
409:                comboCompletionCaseSensitiveTest
410:                        .addActionListener(new ActionListener() {
411:                            public void actionPerformed(ActionEvent e) {
412:                                Check.out("'"
413:                                        + comboCompletionCaseSensitiveTest
414:                                                .getSelectedItem()
415:                                        + "' selected");
416:                            }
417:                        });
418:                try {
419:                    comboCompletionCaseSensitiveTest.putClientProperty(
420:                            LafWidget.COMBO_BOX_AUTOCOMPLETION_MATCHER,
421:                            new AutoCompletionMatcher() {
422:                                public Object getFirstMatching(
423:                                        ComboBoxModel model, String pattern) {
424:                                    Object selectedItem = model
425:                                            .getSelectedItem();
426:                                    // only search for a different item if the currently
427:                                    // selected does not match
428:                                    if ((selectedItem != null)
429:                                            && this .startsWith(selectedItem
430:                                                    .toString(), pattern)) {
431:                                        return selectedItem;
432:                                    } else {
433:                                        // iterate over all items
434:                                        for (int i = 0, n = model.getSize(); i < n; i++) {
435:                                            Object currentItem = model
436:                                                    .getElementAt(i);
437:                                            // current item starts with the pattern?
438:                                            if ((currentItem != null)
439:                                                    && this 
440:                                                            .startsWith(
441:                                                                    currentItem
442:                                                                            .toString(),
443:                                                                    pattern)) {
444:                                                return currentItem;
445:                                            }
446:                                        }
447:                                    }
448:                                    // no item starts with the pattern => return null
449:                                    return null;
450:                                }
451:
452:                                protected boolean startsWith(String str1,
453:                                        String str2) {
454:                                    return str1.startsWith(str2);
455:                                }
456:                            });
457:                } catch (NoClassDefFoundError cndfe) {
458:                }
459:                builder.append("Case sensitive",
460:                        comboCompletionCaseSensitiveTest);
461:
462:                final JComboBox comboNoAutoCompletion = new JComboBox(
463:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
464:                                "Sergi" });
465:                comboNoAutoCompletion.setEditable(true);
466:                comboNoAutoCompletion.addActionListener(new ActionListener() {
467:                    public void actionPerformed(ActionEvent e) {
468:                        Check.out("'" + comboNoAutoCompletion.getSelectedItem()
469:                                + "' selected");
470:                    }
471:                });
472:                comboNoAutoCompletion.putClientProperty(
473:                        LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE);
474:                builder.append("No completion", comboNoAutoCompletion);
475:
476:                final JComboBox comboCompletionColored = new JComboBox(
477:                        new Object[] { "Ester", "Jordi", "Jordina", "Jorge",
478:                                "Sergi" });
479:                comboCompletionColored.setEditable(true);
480:                comboCompletionColored.addActionListener(new ActionListener() {
481:                    public void actionPerformed(ActionEvent e) {
482:                        Check.out("'"
483:                                + comboCompletionColored.getSelectedItem()
484:                                + "' selected");
485:                    }
486:                });
487:                comboCompletionColored.setBackground(new Color(255, 128, 128));
488:                builder.append("Colored", comboCompletionColored);
489:
490:                builder.appendSeparator("Miscellaneous");
491:
492:                JComboBox colorCombo = new ColorComboBox();
493:                builder.append("Color chooser", colorCombo);
494:
495:                JComboBox comboHebrew = new JComboBox(new Object[] {
496:                        "\u05e8\u05d0\u05e9\u05d9 1",
497:                        "\u05e8\u05d0\u05e9\u05d9 2",
498:                        "\u05e8\u05d0\u05e9\u05d9 3",
499:                        "\u05e8\u05d0\u05e9\u05d9 4",
500:                        "\u05e8\u05d0\u05e9\u05d9 5",
501:                        "\u05e8\u05d0\u05e9\u05d9 6",
502:                        "\u05e8\u05d0\u05e9\u05d9 7",
503:                        "\u05e8\u05d0\u05e9\u05d9 8",
504:                        "\u05e8\u05d0\u05e9\u05d9 9" });
505:                comboHebrew.setToolTipText("RTL combo");
506:                comboHebrew
507:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
508:                comboHebrew.setMaximumRowCount(6);
509:                builder.append("RTL (Hebrew)", comboHebrew);
510:
511:                JComboBox comboHebrewCustomRenderer = new JComboBox(
512:                        new Object[] { "\u05e8\u05d0\u05e9\u05d9 1",
513:                                "\u05e8\u05d0\u05e9\u05d9 2",
514:                                "\u05e8\u05d0\u05e9\u05d9 3",
515:                                "\u05e8\u05d0\u05e9\u05d9 4",
516:                                "\u05e8\u05d0\u05e9\u05d9 5",
517:                                "\u05e8\u05d0\u05e9\u05d9 6",
518:                                "\u05e8\u05d0\u05e9\u05d9 7",
519:                                "\u05e8\u05d0\u05e9\u05d9 8",
520:                                "\u05e8\u05d0\u05e9\u05d9 9" });
521:                comboHebrewCustomRenderer.setToolTipText("RTL combo");
522:                comboHebrewCustomRenderer
523:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
524:                comboHebrewCustomRenderer.setMaximumRowCount(6);
525:                comboHebrewCustomRenderer
526:                        .setRenderer(new SubstanceDefaultComboBoxRenderer(
527:                                comboHebrewCustomRenderer) {
528:                            private static final long serialVersionUID = 2629717016682715818L;
529:
530:                            @Override
531:                            public Component getListCellRendererComponent(
532:                                    JList list, Object value, int index,
533:                                    boolean isSelected, boolean hasFocus) {
534:                                Component c = super 
535:                                        .getListCellRendererComponent(list,
536:                                                value, index, isSelected,
537:                                                hasFocus);
538:                                try {
539:                                    ((JLabel) c)
540:                                            .setIcon(new ImageIcon(
541:                                                    ImageIO
542:                                                            .read(getClass()
543:                                                                    .getResource(
544:                                                                            "/test/check/icons/flag_israel.png"))));
545:                                } catch (IOException e) {
546:                                    e.printStackTrace();
547:                                }
548:                                return c;
549:                            }
550:                        });
551:                builder.append("RTL (Hebrew) with icon",
552:                        comboHebrewCustomRenderer);
553:
554:                final JComboBox combo151 = new JComboBox();
555:                final ComboBoxTextEditor151 editor = new ComboBoxTextEditor151();
556:                combo151.setEditor(editor);
557:                combo151.addItem(new EditableDocument151());
558:                combo151.addItem("Default");
559:                combo151.addItem("No Sound");
560:
561:                combo151.addActionListener(new java.awt.event.ActionListener() {
562:                    public void actionPerformed(java.awt.event.ActionEvent e) {
563:                        editor.setCaretPosition(0);
564:                        if (combo151.getSelectedItem() instanceof  String) {
565:                            combo151.setEditable(false);
566:
567:                        } else {
568:                            combo151.setEditable(true);
569:
570:                        }
571:                        editor.setCaretPosition(0);
572:                    }
573:                });
574:                builder.append("Defect 151", combo151);
575:
576:                if (UIManager.getLookAndFeel() instanceof  SubstanceLookAndFeel) {
577:                    Vector<SubstanceTheme> themeVector = new Vector<SubstanceTheme>();
578:                    Map<String, ThemeInfo> allThemes = SubstanceLookAndFeel
579:                            .getAllThemes();
580:                    for (Map.Entry<String, ThemeInfo> themeEntry : allThemes
581:                            .entrySet()) {
582:                        themeVector.add(SubstanceTheme
583:                                .createInstance(themeEntry.getValue()));
584:                    }
585:                    JComboBox themeCombo = new JComboBox(themeVector);
586:                    themeCombo.addItemListener(new ItemListener() {
587:                        public void itemStateChanged(ItemEvent evt) {
588:                            // Get the affected item
589:                            final Object item = evt.getItem();
590:
591:                            if (evt.getStateChange() == ItemEvent.SELECTED) {
592:                                SwingUtilities.invokeLater(new Runnable() {
593:                                    public void run() {
594:                                        try {
595:                                            SubstanceLookAndFeel
596:                                                    .setCurrentTheme((SubstanceTheme) item);
597:                                            // UIManager
598:                                            // .setLookAndFeel(new
599:                                            // SubstanceLookAndFeel());
600:                                            for (Frame frame : Frame
601:                                                    .getFrames()) {
602:                                                SwingUtilities
603:                                                        .updateComponentTreeUI(frame);
604:                                            }
605:                                        } catch (Exception exc) {
606:                                        }
607:                                    };
608:                                });
609:                            }
610:                        }
611:                    });
612:                    themeCombo.setRenderer(new ThemeComboRenderer());
613:                    builder.append("Themes", themeCombo);
614:                }
615:
616:                return builder.getPanel();
617:            }
618:
619:            /**
620:             * Returns the right panel with comboboxes.
621:             * 
622:             * @return The right panel with comboboxes.
623:             */
624:            private JPanel getRightComboPanel() {
625:                FormLayout lm = new FormLayout(
626:                        "right:pref, 4dlu, left:pref:grow", "");
627:                DefaultFormBuilder builder = new DefaultFormBuilder(lm,
628:                        new ScrollablePanel());
629:                builder.setDefaultDialogBorder();
630:
631:                builder.appendSeparator("Popup flyout");
632:
633:                JComboBox comboFlyoutDefault = new JComboBox(new Object[] {
634:                        "entry1", "entry2", "entry3", "entry4", "entry5",
635:                        "entry6" });
636:                comboFlyoutDefault.setMaximumRowCount(4);
637:                builder.append("Default", comboFlyoutDefault);
638:
639:                JComboBox comboFlyoutNorth = new JComboBox(new Object[] {
640:                        "entry1", "entry2", "entry3", "entry4", "entry5",
641:                        "entry6" });
642:                comboFlyoutNorth.setMaximumRowCount(4);
643:                comboFlyoutNorth
644:                        .putClientProperty(
645:                                SubstanceLookAndFeel.COMBO_BOX_POPUP_FLYOUT_ORIENTATION,
646:                                SwingConstants.NORTH);
647:                builder.append("North", comboFlyoutNorth);
648:
649:                JComboBox comboFlyoutEast = new JComboBox(new Object[] {
650:                        "entry1", "entry2", "entry3", "entry4", "entry5",
651:                        "entry6" });
652:                comboFlyoutEast.setMaximumRowCount(4);
653:                comboFlyoutEast
654:                        .putClientProperty(
655:                                SubstanceLookAndFeel.COMBO_BOX_POPUP_FLYOUT_ORIENTATION,
656:                                SwingConstants.EAST);
657:                builder.append("East", comboFlyoutEast);
658:
659:                JComboBox comboFlyoutSouth = new JComboBox(new Object[] {
660:                        "entry1", "entry2", "entry3", "entry4", "entry5",
661:                        "entry6" });
662:                comboFlyoutSouth.setMaximumRowCount(4);
663:                comboFlyoutSouth
664:                        .putClientProperty(
665:                                SubstanceLookAndFeel.COMBO_BOX_POPUP_FLYOUT_ORIENTATION,
666:                                SwingConstants.SOUTH);
667:                builder.append("South", comboFlyoutSouth);
668:
669:                JComboBox comboFlyoutWest = new JComboBox(new Object[] {
670:                        "entry1", "entry2", "entry3", "entry4", "entry5",
671:                        "entry6" });
672:                comboFlyoutWest.setMaximumRowCount(4);
673:                comboFlyoutWest
674:                        .putClientProperty(
675:                                SubstanceLookAndFeel.COMBO_BOX_POPUP_FLYOUT_ORIENTATION,
676:                                SwingConstants.WEST);
677:                builder.append("West", comboFlyoutWest);
678:
679:                JComboBox comboFlyoutCenter = new JComboBox(new Object[] {
680:                        "entry1", "entry2", "entry3", "entry4", "entry5",
681:                        "entry6" });
682:                comboFlyoutCenter.setMaximumRowCount(4);
683:                comboFlyoutCenter
684:                        .putClientProperty(
685:                                SubstanceLookAndFeel.COMBO_BOX_POPUP_FLYOUT_ORIENTATION,
686:                                SwingConstants.CENTER);
687:                builder.append("Center", comboFlyoutCenter);
688:
689:                builder.appendSeparator("Popup prototype");
690:                JComboBox comboProto1 = new JComboBox(new Object[] { "aa",
691:                        "aaaaa", "aaaaaaaaaa", "this one is the one",
692:                        "abcdefghijklmnopqrstuvwxyz" });
693:                comboProto1.setPrototypeDisplayValue("aaaaa");
694:                comboProto1.putClientProperty(
695:                        SubstanceLookAndFeel.COMBO_POPUP_PROTOTYPE,
696:                        "this one is the one");
697:                builder.append("Hard-coded value", comboProto1);
698:
699:                JComboBox comboProto2 = new JComboBox(new Object[] { "aa",
700:                        "aaaaa", "aaaaaaaaaa", "another one (not it)",
701:                        "abcdefghijklmnopqrstuvwxyz" });
702:                comboProto2.setPrototypeDisplayValue("aaaaa");
703:                comboProto2.putClientProperty(
704:                        SubstanceLookAndFeel.COMBO_POPUP_PROTOTYPE,
705:                        new WidestComboPopupPrototype());
706:                builder.append("Widest core callback", comboProto2);
707:
708:                JComboBox comboProto3 = new JComboBox(new Object[] { "aa",
709:                        "aaaaa", "this is not", "this one is not it",
710:                        "this one is it that is for the popup" });
711:                comboProto3.setPrototypeDisplayValue("aaaaa");
712:                comboProto3.putClientProperty(
713:                        SubstanceLookAndFeel.COMBO_POPUP_PROTOTYPE,
714:                        new ComboPopupPrototypeCallback() {
715:                            public Object getPopupPrototypeDisplayValue(
716:                                    JComboBox jc) {
717:                                return jc.getModel().getElementAt(
718:                                        jc.getModel().getSize() - 1);
719:                            }
720:                        });
721:                builder.append("Custom callback", comboProto3);
722:
723:                builder.appendSeparator("Empty combos");
724:                JComboBox emptyModelCombo = new JComboBox(new String[] {});
725:                builder.append("Empty model", emptyModelCombo);
726:
727:                JComboBox emptyStringCombo = new JComboBox(new String[] { "" });
728:                builder.append("Empty string", emptyStringCombo);
729:
730:                JComboBox spaceCombo = new JComboBox(new String[] { " " });
731:                builder.append("Space string", spaceCombo);
732:
733:                JComboBox emptyEditableCombo = new JComboBox(new String[] {});
734:                emptyEditableCombo.setEditable(true);
735:                builder.append("Empty model + editable", emptyEditableCombo);
736:
737:                JComboBox emptyStringEditableCombo = new JComboBox(
738:                        new String[] { "" });
739:                emptyStringEditableCombo.setEditable(true);
740:                builder.append("Empty string + editable",
741:                        emptyStringEditableCombo);
742:
743:                JComboBox spaceEditableCombo = new JComboBox(
744:                        new String[] { " " });
745:                spaceEditableCombo.setEditable(true);
746:                builder.append("Space string + editable", spaceEditableCombo);
747:
748:                return builder.getPanel();
749:            }
750:
751:            /**
752:             * Creates the combobox panel.
753:             */
754:            public CombosPanel() {
755:                this .setLayout(new BorderLayout());
756:
757:                JPanel gridPanel = new ScrollablePanel();
758:                gridPanel.setLayout(new GridLayout(1, 2));
759:                gridPanel.add(getLeftComboPanel());
760:                gridPanel.add(getRightComboPanel());
761:                this .add(new JScrollPane(gridPanel,
762:                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
763:                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
764:                        BorderLayout.CENTER);
765:
766:                FormLayout lm = new FormLayout("fill:pref:grow", "");
767:                DefaultFormBuilder builder = new DefaultFormBuilder(lm,
768:                        new ScrollablePanel());
769:
770:                JButton checkEscape = new JButton("Check ESC key");
771:                checkEscape.addActionListener(new ActionListener() {
772:                    public void actionPerformed(ActionEvent e) {
773:                        final JDialog dialog = new JDialog();
774:                        dialog.setTitle("Press ESC key when combo is focused");
775:                        dialog.setLayout(new FlowLayout());
776:                        JComboBox sampleCombo = new JComboBox(new Object[] {
777:                                "Ester", "Jordi", "Jordina", "Jorge", "Sergi" });
778:                        sampleCombo.setEditable(true);
779:                        dialog.add(sampleCombo);
780:                        dialog.add(new JCheckBox("Sample checkbox"));
781:                        dialog.add(new JButton("Sample button"));
782:                        dialog
783:                                .setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
784:
785:                        JRootPane rootPane = dialog.getRootPane();
786:                        InputMap iMap = rootPane
787:                                .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
788:                        iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
789:                                "escape");
790:
791:                        ActionMap aMap = rootPane.getActionMap();
792:                        aMap.put("escape", new AbstractAction() {
793:                            public void actionPerformed(ActionEvent e) {
794:                                dialog.dispose();
795:                            }
796:                        });
797:                        dialog.pack();
798:                        Dimension d = Toolkit.getDefaultToolkit()
799:                                .getScreenSize();
800:                        // center the dialog in the physical screen
801:                        dialog.setLocation((d.width - dialog.getWidth()) / 2,
802:                                (d.height - dialog.getHeight()) / 2);
803:                        dialog.setVisible(true);
804:                    }
805:                });
806:
807:                JButton disableCombosButton = new JButton("Disable all");
808:                disableCombosButton.addActionListener(new ActionListener() {
809:                    public void actionPerformed(ActionEvent e) {
810:                        SwingUtilities.invokeLater(new Runnable() {
811:                            public void run() {
812:                                CombosPanel.run(CombosPanel.this ,
813:                                        new DisableCommand());
814:                            }
815:                        });
816:                    }
817:                });
818:                JButton enableCombosButton = new JButton("Enable all");
819:                enableCombosButton.addActionListener(new ActionListener() {
820:                    public void actionPerformed(ActionEvent e) {
821:                        SwingUtilities.invokeLater(new Runnable() {
822:                            public void run() {
823:                                CombosPanel.run(CombosPanel.this ,
824:                                        new EnableCommand());
825:                            }
826:                        });
827:                    }
828:                });
829:                JButton makeAllEditableButton = new JButton("Make all editable");
830:                makeAllEditableButton.addActionListener(new ActionListener() {
831:                    public void actionPerformed(ActionEvent e) {
832:                        SwingUtilities.invokeLater(new Runnable() {
833:                            public void run() {
834:                                CombosPanel.run(CombosPanel.this ,
835:                                        new EditAllowCommand());
836:                            }
837:                        });
838:                    }
839:                });
840:                JButton makeAllNonEditableButton = new JButton(
841:                        "Make all non-editable");
842:                makeAllNonEditableButton
843:                        .addActionListener(new ActionListener() {
844:                            public void actionPerformed(ActionEvent e) {
845:                                SwingUtilities.invokeLater(new Runnable() {
846:                                    public void run() {
847:                                        CombosPanel.run(CombosPanel.this ,
848:                                                new EditDisallowCommand());
849:                                    }
850:                                });
851:                            }
852:                        });
853:
854:                builder.append(disableCombosButton);
855:                builder.append(enableCombosButton);
856:                builder.append(makeAllNonEditableButton);
857:                builder.append(makeAllEditableButton);
858:                builder.append(checkEscape);
859:
860:                this.controlPanel = builder.getPanel();
861:            }
862:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.