|
1 /* |
|
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package com.sun.swingset3.demos.spinner; |
|
24 |
|
25 import javax.swing.*; |
|
26 import java.awt.*; |
|
27 import java.beans.PropertyChangeEvent; |
|
28 |
|
29 import com.sun.swingset3.DemoProperties; |
|
30 import com.sun.swingset3.demos.ResourceManager; |
|
31 |
|
32 /** |
|
33 * Demonstrates JSpinner and SwingWorker |
|
34 * |
|
35 * @author Mikhail Lapshin |
|
36 */ |
|
37 @DemoProperties( |
|
38 value = "Spinner Demo", |
|
39 category = "Controls", |
|
40 description = "Demonstrates JSpinner and SwingWorker", |
|
41 sourceFiles = { |
|
42 "com/sun/swingset3/demos/spinner/SpinnerDemo.java", |
|
43 "com/sun/swingset3/demos/spinner/JMandelbrot.java", |
|
44 "com/sun/swingset3/demos/spinner/JPaletteShower.java", |
|
45 "com/sun/swingset3/demos/spinner/JSpinnerPanel.java", |
|
46 "com/sun/swingset3/demos/spinner/MandelbrotControl.java", |
|
47 "com/sun/swingset3/demos/spinner/Palette.java", |
|
48 "com/sun/swingset3/demos/spinner/PaletteChooser.java", |
|
49 "com/sun/swingset3/demos/ResourceManager.java", |
|
50 "com/sun/swingset3/demos/spinner/resources/SpinnerDemo.properties", |
|
51 "com/sun/swingset3/demos/spinner/resources/images/SpinnerDemo.gif" |
|
52 } |
|
53 ) |
|
54 public class SpinnerDemo extends JPanel { |
|
55 |
|
56 private final ResourceManager resourceManager = new ResourceManager(getClass()); |
|
57 public static final String DEMO_TITLE = SpinnerDemo.class.getAnnotation(DemoProperties.class).value(); |
|
58 |
|
59 public static void main(String[] args) { |
|
60 JFrame frame = new JFrame(DEMO_TITLE); |
|
61 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
62 frame.getContentPane().add(new SpinnerDemo()); |
|
63 frame.setPreferredSize(new Dimension(800, 600)); |
|
64 frame.pack(); |
|
65 frame.setLocationRelativeTo(null); |
|
66 frame.setVisible(true); |
|
67 } |
|
68 |
|
69 public SpinnerDemo() { |
|
70 setLayout(new BorderLayout()); |
|
71 |
|
72 // Create main components |
|
73 PaletteChooser chooser |
|
74 = new PaletteChooser(resourceManager); |
|
75 final JMandelbrot mandelbrot |
|
76 = new JMandelbrot(400, 400, chooser.getPalette(), resourceManager); |
|
77 MandelbrotControl mandelbrotControl |
|
78 = new MandelbrotControl(mandelbrot, resourceManager); |
|
79 |
|
80 // Connect palette chooser and mandelbrot component |
|
81 chooser.addPropertyChangeListener(PaletteChooser.PALETTE_PROPERTY_NAME, |
|
82 (PropertyChangeEvent evt) -> { |
|
83 mandelbrot.setPalette((Palette) evt.getNewValue()); |
|
84 mandelbrot.calculatePicture(); |
|
85 }); |
|
86 |
|
87 // Layout components |
|
88 add(mandelbrot); |
|
89 |
|
90 JPanel controlPanel = new JPanel(); |
|
91 controlPanel.setLayout(new BorderLayout()); |
|
92 controlPanel.add(chooser, BorderLayout.NORTH); |
|
93 |
|
94 JPanel mandelbrotControlPanel = new JPanel(); |
|
95 mandelbrotControlPanel.setLayout(new BorderLayout()); |
|
96 mandelbrotControlPanel.add(mandelbrotControl, BorderLayout.NORTH); |
|
97 controlPanel.add(mandelbrotControlPanel, BorderLayout.CENTER); |
|
98 |
|
99 add(controlPanel, BorderLayout.EAST); |
|
100 } |
|
101 } |