Changeset 26 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java


Ignore:
Timestamp:
07/29/2017 02:22:14 PM (9 years ago)
Author:
jdalbey
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/drawers/RangeSliderDemo.java

    r25 r26  
     1package scriptbuilder.gui.drawers; 
    12 
    23import java.awt.BorderLayout; 
     
    1415import javax.swing.event.ChangeEvent; 
    1516import javax.swing.event.ChangeListener; 
     17 
    1618/* 
    1719The MIT License 
     
    3638OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
    3739THE SOFTWARE. 
    38 */ 
     40 */ 
    3941 
    4042/** 
    4143 * Demo application panel to display a range slider. 
    4244 */ 
    43 public class RangeSliderDemo extends JPanel { 
     45public class RangeSliderDemo extends JPanel 
     46{ 
    4447 
    4548    private JLabel rangeSliderLabel1 = new JLabel(); 
     
    4952    private RangeSlider rangeSlider = new RangeSlider(); 
    5053 
    51     public RangeSliderDemo() { 
     54    public RangeSliderDemo() 
     55    { 
    5256        setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); 
    5357        setLayout(new GridBagLayout()); 
    54          
     58 
    5559        rangeSliderLabel1.setText("Lower value:"); 
    5660        rangeSliderLabel2.setText("Upper value:"); 
    5761        rangeSliderValue1.setHorizontalAlignment(JLabel.LEFT); 
    5862        rangeSliderValue2.setHorizontalAlignment(JLabel.LEFT); 
    59          
     63 
    6064        rangeSlider.setPreferredSize(new Dimension(240, rangeSlider.getPreferredSize().height)); 
    6165        rangeSlider.setMinimum(0); 
    6266        rangeSlider.setMaximum(10); 
    63          
     67 
    6468        // Add listener to update display. 
    65         rangeSlider.addChangeListener(new ChangeListener() { 
    66             public void stateChanged(ChangeEvent e) { 
     69        rangeSlider.addChangeListener(new ChangeListener() 
     70        { 
     71            public void stateChanged(ChangeEvent e) 
     72            { 
    6773                RangeSlider slider = (RangeSlider) e.getSource(); 
    6874                rangeSliderValue1.setText(String.valueOf(slider.getValue())); 
     
    7278 
    7379        add(rangeSliderLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 
    74             GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 
     80                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 
    7581        add(rangeSliderValue1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 
    76             GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 0), 0, 0)); 
     82                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 0), 0, 0)); 
    7783        add(rangeSliderLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 
    78             GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 
     84                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 3, 3), 0, 0)); 
    7985        add(rangeSliderValue2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 
    80             GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 6, 0), 0, 0)); 
    81         add(rangeSlider      , new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0, 
    82             GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 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)); 
    8389    } 
    84      
    85     public void display() { 
     90 
     91    public void display() 
     92    { 
    8693        // Initialize values. 
    8794        rangeSlider.setValue(3); 
    8895        rangeSlider.setUpperValue(7); 
    89          
     96 
    9097        // Initialize value display. 
    9198        rangeSliderValue1.setText(String.valueOf(rangeSlider.getValue())); 
    9299        rangeSliderValue2.setText(String.valueOf(rangeSlider.getUpperValue())); 
    93          
     100 
    94101        // Create window frame. 
    95102        JFrame frame = new JFrame(); 
     
    97104        frame.setResizable(false); 
    98105        frame.setTitle("Range Slider Demo"); 
    99          
     106 
    100107        // Set window content and validate. 
    101108        frame.getContentPane().setLayout(new BorderLayout()); 
    102109        frame.getContentPane().add(this, BorderLayout.CENTER); 
    103110        frame.pack(); 
    104          
     111 
    105112        // Set window location and display. 
    106113        frame.setLocationRelativeTo(null); 
    107114        frame.setVisible(true); 
    108115    } 
    109      
     116 
    110117    /** 
    111118     * Main application method. 
     119     * 
    112120     * @param args String[] 
    113121     */ 
    114     public static void main(String[] args) { 
    115         try { 
     122    public static void main(String[] args) 
     123    { 
     124        try 
     125        { 
    116126            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    117         } catch (Exception ex) { 
     127        } 
     128        catch (Exception ex) 
     129        { 
    118130            ex.printStackTrace(); 
    119131        } 
    120132 
    121         SwingUtilities.invokeLater(new Runnable() { 
    122             public void run() { 
     133        SwingUtilities.invokeLater(new Runnable() 
     134        { 
     135            public void run() 
     136            { 
    123137                new RangeSliderDemo().display(); 
    124138            } 
Note: See TracChangeset for help on using the changeset viewer.