Warning: Can't use blame annotator:
svn blame failed on trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java @ 26

Revision 26, 5.0 KB checked in by jdalbey, 9 years ago (diff)

RangeSliderUI.java: Added popup menu (with stubs for actions)

RevLine 
1package scriptbuilder.gui.drawers;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.GridBagConstraints;
6import java.awt.GridBagLayout;
7import java.awt.Insets;
8
9import javax.swing.BorderFactory;
10import javax.swing.JFrame;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.SwingUtilities;
14import javax.swing.UIManager;
15import javax.swing.event.ChangeEvent;
16import javax.swing.event.ChangeListener;
17
18/*
19The MIT License
20
21Copyright (c) 2010 Ernest Yu. All rights reserved.
22
23Permission is hereby granted, free of charge, to any person obtaining a copy
24of this software and associated documentation files (the "Software"), to deal
25in the Software without restriction, including without limitation the rights
26to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27copies of the Software, and to permit persons to whom the Software is
28furnished to do so, subject to the following conditions:
29
30The above copyright notice and this permission notice shall be included in
31all copies or substantial portions of the Software.
32
33THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39THE SOFTWARE.
40 */
41
42/**
43 * Demo application panel to display a range slider.
44 */
45public class RangeSliderDemo extends JPanel
46{
47
48    private JLabel rangeSliderLabel1 = new JLabel();
49    private JLabel rangeSliderValue1 = new JLabel();
50    private JLabel rangeSliderLabel2 = new JLabel();
51    private JLabel rangeSliderValue2 = new JLabel();
52    private RangeSlider rangeSlider = new RangeSlider();
53
54    public RangeSliderDemo()
55    {
56        setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
57        setLayout(new GridBagLayout());
58
59        rangeSliderLabel1.setText("Lower value:");
60        rangeSliderLabel2.setText("Upper value:");
61        rangeSliderValue1.setHorizontalAlignment(JLabel.LEFT);
62        rangeSliderValue2.setHorizontalAlignment(JLabel.LEFT);
63
64        rangeSlider.setPreferredSize(new Dimension(240, rangeSlider.getPreferredSize().height));
65        rangeSlider.setMinimum(0);
66        rangeSlider.setMaximum(10);
67
68        // Add listener to update display.
69        rangeSlider.addChangeListener(new ChangeListener()
70        {
71            public void stateChanged(ChangeEvent e)
72            {
73                RangeSlider slider = (RangeSlider) e.getSource();
74                rangeSliderValue1.setText(String.valueOf(slider.getValue()));
75                rangeSliderValue2.setText(String.valueOf(slider.getUpperValue()));
76            }
77        });
78
79        add(rangeSliderLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
80                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0));
81        add(rangeSliderValue1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
82                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 0), 0, 0));
83        add(rangeSliderLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
84                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0));
85        add(rangeSliderValue2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
86                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 6, 0), 0, 0));
87        add(rangeSlider, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,
88                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
89    }
90
91    public void display()
92    {
93        // Initialize values.
94        rangeSlider.setValue(3);
95        rangeSlider.setUpperValue(7);
96
97        // Initialize value display.
98        rangeSliderValue1.setText(String.valueOf(rangeSlider.getValue()));
99        rangeSliderValue2.setText(String.valueOf(rangeSlider.getUpperValue()));
100
101        // Create window frame.
102        JFrame frame = new JFrame();
103        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
104        frame.setResizable(false);
105        frame.setTitle("Range Slider Demo");
106
107        // Set window content and validate.
108        frame.getContentPane().setLayout(new BorderLayout());
109        frame.getContentPane().add(this, BorderLayout.CENTER);
110        frame.pack();
111
112        // Set window location and display.
113        frame.setLocationRelativeTo(null);
114        frame.setVisible(true);
115    }
116
117    /**
118     * Main application method.
119     *
120     * @param args String[]
121     */
122    public static void main(String[] args)
123    {
124        try
125        {
126            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
127        }
128        catch (Exception ex)
129        {
130            ex.printStackTrace();
131        }
132
133        SwingUtilities.invokeLater(new Runnable()
134        {
135            public void run()
136            {
137                new RangeSliderDemo().display();
138            }
139        });
140    }
141}
Note: See TracBrowser for help on using the repository browser.