1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tools.flame; 18 19 import java.awt.BorderLayout; 20 import java.awt.Dimension; 21 22 import javax.swing.JPanel; 23 import javax.swing.JSpinner; 24 import javax.swing.SpinnerNumberModel; 25 import javax.swing.event.ChangeListener; 26 27 /** @author Inferno */ 28 public class Slider extends JPanel { 29 public JSpinner spinner; 30 Slider(float initialValue, final float min, final float max, float stepSize)31 public Slider (float initialValue, final float min, final float max, float stepSize) { 32 spinner = new JSpinner(new SpinnerNumberModel(initialValue, min, max, stepSize)); 33 setLayout(new BorderLayout()); 34 add(spinner); 35 } 36 setValue(float value)37 public void setValue (float value) { 38 spinner.setValue((double)value); 39 } 40 getValue()41 public float getValue () { 42 return ((Double)spinner.getValue()).floatValue(); 43 } 44 addChangeListener(ChangeListener listener)45 public void addChangeListener (ChangeListener listener) { 46 spinner.addChangeListener(listener); 47 } 48 getPreferredSize()49 public Dimension getPreferredSize () { 50 Dimension size = super.getPreferredSize(); 51 size.width = 75; 52 size.height = 26; 53 return size; 54 } 55 } 56