package com.rle.monitor; /* * RLE Surface Crack Detector Graphing Software * * Copyright (C) 2002 RLE Technologies * For more information visit http://www.rletech.com/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /** * @author Andy Goth * @author Eric Peterson * @author Matt Lane * @version 0.1 */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; /** Slider with stop values and block incrementing. */ public class MySlider extends JSlider { private int blockIncrement; private int stopMin; private int stopMax; private static final EventListenerList nullListenerList = new EventListenerList(); public MySlider() { this(HORIZONTAL, 0, 100, 50); } public MySlider(int orientation) { this(orientation, 0, 100, 50); } public MySlider(int min, int max) { this(HORIZONTAL, min, max, (min + max) / 2); } public MySlider(int min, int max, int value) { this(HORIZONTAL, min, max, value); } public MySlider(int orientation, int min, int max, int value) { super(orientation, min, max, value); ComponentUI ui; ui = MySliderUI.createUI(this); ui.installUI(this); setUI(ui); blockIncrement = (getMaximum() - getMinimum()) / 8; stopMin = getMinimum(); stopMax = getMaximum(); setExtent(0); } public MySlider(BoundedRangeModel brm) { this(HORIZONTAL); setModel(brm); } /** Returns the amount by which the track adjusts the slider. */ public int getBlockIncrement(int dir) {return blockIncrement;} /** Sets the amount by which the track adjusts the slider. */ public void setBlockIncrement(int inc) { if (inc < 1) throw new IllegalArgumentException("Out of bounds"); blockIncrement = inc; } public void setValue(int v) { if (v < stopMin) super.setValue(stopMin); else if (v > stopMax) super.setValue(stopMax); else super.setValue(v); } /** Sets the slider's value without sending event notifications. */ public void setValueQuiet(int v) { EventListenerList listenerList = this.listenerList; this.listenerList = nullListenerList; if (v < stopMin) super.setValue(stopMin); else if (v > stopMax) super.setValue(stopMax); else super.setValue(v); this.listenerList = listenerList; } /** Returns the minimum value the slider can be set to. */ public int getStopMin() {return stopMin;} /** Sets the minimum value the slider can be set to. */ public void setStopMin(int m) { if (m < getMinimum()) throw new IllegalArgumentException("Out of bounds"); stopMin = m; if (getValue() < m) setValue(m); repaint(); } /** Returns the maximum value the slider can be set to. */ public int getStopMax() {return stopMax;} /** Sets the maximum value the slider can be set to. */ public void setStopMax(int m) { if (m > getMaximum()) throw new IllegalArgumentException("Out of bounds"); stopMax = m; if (getValue() > m) setValue(m); repaint(); } }