Source Code Cross Referenced for ScrollDemo.java in  » Swing-Library » substance-look-feel » test » 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 
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;
031:
032:        import java.awt.*;
033:        import java.awt.event.ActionEvent;
034:        import java.awt.event.ActionListener;
035:        import java.awt.image.BufferedImage;
036:        import java.util.HashMap;
037:        import java.util.Map;
038:
039:        import javax.swing.*;
040:        import javax.swing.event.ChangeEvent;
041:        import javax.swing.event.ChangeListener;
042:
043:        import org.jvnet.lafwidget.LafWidget;
044:        import org.jvnet.lafwidget.LafWidgetUtilities2;
045:        import org.jvnet.lafwidget.layout.TransitionLayout;
046:        import org.jvnet.lafwidget.preview.DefaultPreviewPainter;
047:        import org.jvnet.substance.SubstanceLookAndFeel;
048:        import org.jvnet.substance.grip.DragBumpsGripPainter;
049:        import org.jvnet.substance.painter.AlphaControlBackgroundComposite;
050:        import org.jvnet.substance.utils.SubstanceCoreUtilities;
051:        import org.jvnet.substance.utils.SubstanceConstants.ScrollPaneButtonPolicyKind;
052:
053:        public class ScrollDemo extends JFrame {
054:            public class ScrollPanel extends JPanel {
055:                private JScrollPane sp;
056:
057:                private JPanel panel;
058:
059:                private Map<String, BufferedImage> shots;
060:
061:                public ScrollPanel() {
062:                    this .shots = new HashMap<String, BufferedImage>();
063:
064:                    this .panel = new JPanel() {
065:                        @Override
066:                        protected void paintComponent(Graphics g) {
067:                            Graphics2D graphics = (Graphics2D) g.create();
068:                            graphics.setComposite(TransitionLayout
069:                                    .getAlphaComposite(panel));
070:
071:                            BufferedImage shot = getShot(this .getWidth(), this 
072:                                    .getHeight());
073:                            graphics.drawImage(shot, 0, 0, null);
074:                            graphics.dispose();
075:                        }
076:                    };
077:                    // this.panel.putClientProperty(LafWidget.COMPONENT_PREVIEW_PAINTER,
078:                    // new DefaultPreviewPainter());
079:                    this .panel.setPreferredSize(new Dimension(1200, 800));
080:                    this .panel.setSize(this .getPreferredSize());
081:                    this .panel.setMinimumSize(this .getPreferredSize());
082:                    this .sp = new JScrollPane(this .panel,
083:                            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
084:                            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
085:                    this .sp
086:                            .putClientProperty(
087:                                    SubstanceLookAndFeel.OVERLAY_PROPERTY,
088:                                    Boolean.TRUE);
089:                    this .sp.putClientProperty(
090:                            SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
091:                            Boolean.TRUE);
092:                    this .sp.putClientProperty(
093:                            SubstanceLookAndFeel.GRIP_PAINTER,
094:                            new DragBumpsGripPainter());
095:                    this .sp.putClientProperty(
096:                            LafWidget.COMPONENT_PREVIEW_PAINTER,
097:                            new DefaultPreviewPainter());
098:                    // this.sp.putClientProperty(
099:                    // SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY, Boolean.FALSE);
100:                    this .setLayout(new BorderLayout());
101:                    this .add(this .sp, BorderLayout.CENTER);
102:
103:                    JPanel controlsSliders = new JPanel(new GridLayout(2, 1));
104:
105:                    final JSlider sliderInactive = new JSlider(0, 100, 50);
106:                    sliderInactive.setMajorTickSpacing(20);
107:                    sliderInactive.setMinorTickSpacing(5);
108:                    sliderInactive.setPaintLabels(true);
109:                    sliderInactive.setPaintTicks(true);
110:                    sliderInactive.setSnapToTicks(true);
111:
112:                    final JSlider sliderActive = new JSlider(0, 100, 80);
113:                    sliderActive.setMajorTickSpacing(20);
114:                    sliderActive.setMinorTickSpacing(5);
115:                    sliderActive.setPaintLabels(true);
116:                    sliderActive.setPaintTicks(true);
117:                    sliderActive.setSnapToTicks(true);
118:
119:                    sliderInactive.addChangeListener(new ChangeListener() {
120:                        public void stateChanged(ChangeEvent e) {
121:                            int valInactive = sliderInactive.getValue();
122:                            int valActive = sliderActive.getValue();
123:                            sp.putClientProperty(
124:                                    SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
125:                                    new AlphaControlBackgroundComposite(
126:                                            valInactive / 100.0f,
127:                                            valActive / 100.0f));
128:                            sp.repaint();
129:                        }
130:                    });
131:                    sliderActive.addChangeListener(new ChangeListener() {
132:                        public void stateChanged(ChangeEvent e) {
133:                            int valInactive = sliderInactive.getValue();
134:                            int valActive = sliderActive.getValue();
135:                            sp.putClientProperty(
136:                                    SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
137:                                    new AlphaControlBackgroundComposite(
138:                                            valInactive / 100.0f,
139:                                            valActive / 100.0f));
140:                            sp.repaint();
141:                        }
142:                    });
143:                    int valInactive = sliderInactive.getValue();
144:                    int valActive = sliderActive.getValue();
145:                    sp.putClientProperty(
146:                            SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
147:                            new AlphaControlBackgroundComposite(
148:                                    valInactive / 100.0f, valActive / 100.0f));
149:
150:                    controlsSliders.add(sliderActive);
151:                    controlsSliders.add(sliderInactive);
152:                    this .add(controlsSliders, BorderLayout.SOUTH);
153:
154:                    JPanel controls = new JPanel();
155:                    controls.setLayout(new FlowLayout(FlowLayout.CENTER));
156:                    final JCheckBox isEnabled = new JCheckBox("enabled");
157:                    isEnabled.setSelected(true);
158:                    isEnabled.addActionListener(new ActionListener() {
159:                        public void actionPerformed(ActionEvent e) {
160:                            boolean toEnable = isEnabled.isSelected();
161:                            sp.setEnabled(toEnable);
162:                            updateEnabledState(sp, toEnable);
163:                            Check.out("Scroll pane is " + toEnable);
164:                        }
165:                    });
166:                    // controls.add(isEnabled);
167:
168:                    final JCheckBox hasCustomPreview = new JCheckBox("preview");
169:                    hasCustomPreview.setSelected(LafWidgetUtilities2
170:                            .getComponentPreviewPainter(sp) != null);
171:                    hasCustomPreview.addActionListener(new ActionListener() {
172:                        public void actionPerformed(ActionEvent e) {
173:                            sp
174:                                    .putClientProperty(
175:                                            LafWidget.COMPONENT_PREVIEW_PAINTER,
176:                                            hasCustomPreview.isSelected() ? new DefaultPreviewPainter()
177:                                                    : null);
178:                            sp.repaint();
179:                        }
180:                    });
181:                    controls.add(hasCustomPreview);
182:
183:                    final JComboBox buttonPolicyCombo = new JComboBox(
184:                            new Object[] { ScrollPaneButtonPolicyKind.NONE,
185:                                    ScrollPaneButtonPolicyKind.OPPOSITE,
186:                                    ScrollPaneButtonPolicyKind.ADJACENT,
187:                                    ScrollPaneButtonPolicyKind.MULTIPLE,
188:                                    ScrollPaneButtonPolicyKind.MULTIPLE_BOTH });
189:                    buttonPolicyCombo
190:                            .setSelectedItem(ScrollPaneButtonPolicyKind.OPPOSITE);
191:                    buttonPolicyCombo.addActionListener(new ActionListener() {
192:                        public void actionPerformed(ActionEvent e) {
193:                            ScrollPaneButtonPolicyKind buttonPolicy = (ScrollPaneButtonPolicyKind) buttonPolicyCombo
194:                                    .getSelectedItem();
195:                            sp
196:                                    .putClientProperty(
197:                                            SubstanceLookAndFeel.SCROLL_PANE_BUTTONS_POLICY,
198:                                            buttonPolicy);
199:                            sp.repaint();
200:                        }
201:                    });
202:                    // controls.add(new JLabel("buttons"));
203:                    controls.add(buttonPolicyCombo);
204:
205:                    final JCheckBox isNever = new JCheckBox("never");
206:                    isNever.addActionListener(new ActionListener() {
207:                        public void actionPerformed(ActionEvent e) {
208:                            sp
209:                                    .putClientProperty(
210:                                            SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY,
211:                                            isNever.isSelected() ? Boolean.TRUE
212:                                                    : null);
213:                            sp.repaint();
214:                        }
215:                    });
216:                    controls.add(isNever);
217:
218:                    final JCheckBox isFlat = new JCheckBox("flat");
219:                    isFlat.addActionListener(new ActionListener() {
220:                        public void actionPerformed(ActionEvent e) {
221:                            sp
222:                                    .putClientProperty(
223:                                            SubstanceLookAndFeel.FLAT_PROPERTY,
224:                                            isFlat.isSelected() ? Boolean.TRUE
225:                                                    : null);
226:                            sp.repaint();
227:                        }
228:                    });
229:                    controls.add(isFlat);
230:
231:                    final JCheckBox isActive = new JCheckBox("active");
232:                    isActive
233:                            .setSelected(Boolean.TRUE
234:                                    .equals(sp
235:                                            .getClientProperty(SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY)));
236:                    isActive.addActionListener(new ActionListener() {
237:                        public void actionPerformed(ActionEvent e) {
238:                            sp
239:                                    .putClientProperty(
240:                                            SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
241:                                            isActive.isSelected() ? Boolean.TRUE
242:                                                    : null);
243:                            sp.repaint();
244:                        }
245:                    });
246:                    controls.add(isActive);
247:
248:                    final JCheckBox isOverlay = new JCheckBox("overlay");
249:                    isOverlay
250:                            .setSelected(Boolean.TRUE
251:                                    .equals(sp
252:                                            .getClientProperty(SubstanceLookAndFeel.OVERLAY_PROPERTY)));
253:                    isOverlay.addActionListener(new ActionListener() {
254:                        public void actionPerformed(ActionEvent e) {
255:                            sp.putClientProperty(
256:                                    SubstanceLookAndFeel.OVERLAY_PROPERTY,
257:                                    isOverlay.isSelected() ? Boolean.TRUE
258:                                            : null);
259:                            sp.repaint();
260:                        }
261:                    });
262:                    controls.add(isOverlay);
263:
264:                    this .add(controls, BorderLayout.NORTH);
265:                }
266:
267:                private synchronized BufferedImage getShot(int width, int height) {
268:                    String key = width + ":" + height;
269:                    BufferedImage result = this .shots.get(key);
270:                    if (result == null) {
271:                        result = SubstanceCoreUtilities.getBlankImage(width,
272:                                height);
273:
274:                        Graphics2D graphics = result.createGraphics();
275:                        int cols = 1 + width / 10;
276:                        int rows = 1 + height / 10;
277:                        if (SubstanceCoreUtilities
278:                                .isThemeDark(SubstanceLookAndFeel.getTheme()))
279:                            graphics.setColor(Color.black);
280:                        else
281:                            graphics.setColor(Color.white);
282:                        graphics.fillRect(0, 0, width, height);
283:                        for (int i = 0; i < cols; i++) {
284:                            for (int j = 0; j < rows; j++) {
285:                                if (((i + j) % 2) == 0) {
286:                                    float val = (i + j) / 100.f;
287:                                    val -= Math.floor(val);
288:                                    boolean isDark = SubstanceCoreUtilities
289:                                            .isThemeDark(SubstanceLookAndFeel
290:                                                    .getTheme());
291:                                    float brightness = isDark ? 0.1f : 0.9f;
292:                                    float saturation = 0.2f;
293:                                    graphics.setColor(new Color(Color.HSBtoRGB(
294:                                            val, saturation, brightness)));
295:                                    graphics.fillRect(i * 10, j * 10, 10, 10);
296:                                }
297:                            }
298:                        }
299:
300:                        graphics.setColor(Color.gray);
301:                        graphics.setFont(new Font("Arial", Font.PLAIN, 11));
302:                        rows = 1 + height / 25;
303:                        for (int i = 0; i < rows; i++) {
304:                            for (int j = 0; j < width / 25; j++) {
305:                                graphics.drawString("" + (i + j), j * 25,
306:                                        25 * i);
307:                            }
308:                        }
309:
310:                        this .shots.put(key, result);
311:                    }
312:                    return result;
313:                }
314:            }
315:
316:            public ScrollDemo() {
317:                super ("Scroll overlay demo");
318:                this .setLayout(new BorderLayout());
319:                this .add(new ScrollPanel(), BorderLayout.CENTER);
320:                this .setSize(450, 400);
321:                this .setLocationRelativeTo(null);
322:                this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
323:            }
324:
325:            void updateEnabledState(Container c, boolean enabled) {
326:                for (int counter = c.getComponentCount() - 1; counter >= 0; counter--) {
327:                    Component child = c.getComponent(counter);
328:
329:                    child.setEnabled(enabled);
330:                    if (child instanceof  Container) {
331:                        updateEnabledState((Container) child, enabled);
332:                    }
333:                }
334:            }
335:
336:            public static void main(String[] args) throws Exception {
337:                // UIManager.setLookAndFeel(new SubstanceModerateLookAndFeel());
338:                UIManager.setLookAndFeel(new SubstanceLookAndFeel());
339:                SwingUtilities.invokeLater(new Runnable() {
340:                    public void run() {
341:                        new ScrollDemo().setVisible(true);
342:                    }
343:                });
344:            }
345:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.