36744
|
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.getContentPane().add(new SpinnerDemo());
|
|
62 |
frame.setPreferredSize(new Dimension(800, 600));
|
|
63 |
frame.pack();
|
|
64 |
frame.setLocationRelativeTo(null);
|
|
65 |
frame.setVisible(true);
|
|
66 |
}
|
|
67 |
|
|
68 |
public SpinnerDemo() {
|
|
69 |
setLayout(new BorderLayout());
|
|
70 |
|
|
71 |
// Create main components
|
|
72 |
PaletteChooser chooser
|
|
73 |
= new PaletteChooser(resourceManager);
|
|
74 |
final JMandelbrot mandelbrot
|
|
75 |
= new JMandelbrot(400, 400, chooser.getPalette(), resourceManager);
|
|
76 |
MandelbrotControl mandelbrotControl
|
|
77 |
= new MandelbrotControl(mandelbrot, resourceManager);
|
|
78 |
|
|
79 |
// Connect palette chooser and mandelbrot component
|
|
80 |
chooser.addPropertyChangeListener(PaletteChooser.PALETTE_PROPERTY_NAME,
|
|
81 |
(PropertyChangeEvent evt) -> {
|
|
82 |
mandelbrot.setPalette((Palette) evt.getNewValue());
|
|
83 |
mandelbrot.calculatePicture();
|
|
84 |
});
|
|
85 |
|
|
86 |
// Layout components
|
|
87 |
add(mandelbrot);
|
|
88 |
|
|
89 |
JPanel controlPanel = new JPanel();
|
|
90 |
controlPanel.setLayout(new BorderLayout());
|
|
91 |
controlPanel.add(chooser, BorderLayout.NORTH);
|
|
92 |
|
|
93 |
JPanel mandelbrotControlPanel = new JPanel();
|
|
94 |
mandelbrotControlPanel.setLayout(new BorderLayout());
|
|
95 |
mandelbrotControlPanel.add(mandelbrotControl, BorderLayout.NORTH);
|
|
96 |
controlPanel.add(mandelbrotControlPanel, BorderLayout.CENTER);
|
|
97 |
|
|
98 |
add(controlPanel, BorderLayout.EAST);
|
|
99 |
}
|
|
100 |
}
|