⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lwslider.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 *     Caption: Zaval Light-Weight Visual Components Library
 *     $Revision: 2.79 $
 *     $Date: 2003/08/22 11:24:16 $
 *
 *     @author:     Andrei Vishnevsky
 *     @version:    3.50
 *
 * Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java
 * alternative to humble AWT-based and SWING-based GUI interfaces for
 * wide ranges of platforms, including J2SE, PersonalJava and J2ME.
 *
 * Designed as light-weight but, alternatively to Swing, built separately
 * from AWT (not on top of the java.awt library like Swing), the LwVCL is
 * the good alternative to highly performant, memory-efficient, flexible
 * GUI solution for embedded, stand-alone and applet applications.
 *
 * For more info on this product read Zaval Light-Weight Visual Components Library Tutorial
 * (It comes within this package).
 * The latest product version is always available from the product's homepage:
 * http://www.zaval.org/products/lwvcl/
 * and from the SourceForge:
 * http://sourceforge.net/projects/zaval0003/
 *
 * Contacts:
 *   Support : support@zaval.org
 *   Change Requests : change-request@zaval.org
 *   Feedback : feedback@zaval.org
 *   Other : info@zaval.org
 *
 * Copyright (C) 2001-2003  Zaval Creative Engineering Group (http://www.zaval.org)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * (version 2) as published by the Free Software Foundation.
 *
 * 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.
 *
 */
package org.zaval.lw;import java.awt.*;import java.awt.event.*;import org.zaval.lw.event.*;import org.zaval.util.*;/** * This is slider component that can be used to select a value from the * specified integer interval. The minimum, maximum, intervals sizes and other properties * are specified by <code>setValues</code> method. The table below explains the * properties meaning in more detail: * <table border="1"> *    <tr> *      <td align="center">Property</td> *      <td align="center">Description</td> *    </tr> *    <tr> *      <td align="center" valign="center"> *           max *      </td> *      <td> *           This is maximum possible value of the slider interval. Use <code>getMax</code> *           method to get the property value. It is impossible to set a slider value that is *           greater than the maximum. *      </td> *    </tr> *    <tr> *      <td align="center" valign="center"> *           min *      </td> *      <td> *           This is minimum possible value of the slider interval. Use <code>getMin</code> *           method to get the property value. It is impossible to set a slider value that is *           less than the minimum. *      </td> *    </tr> *    <tr> *      <td align="center" valign="center"> *          roughStep *      </td> *      <td> *           This property defines a rough step that is used to change current slider value for *           none-interval slider model. The step is used (to change the slider value) when the *           left mouse button has been pressed. *      </td> *    </tr> *    <tr> *      <td align="center" valign="center"> *          exactStep *      </td> *      <td> *           This property defines an exact step that is used to change current slider value for *           none-interval slider model. The step is used (to change the slider value) when *           appropriate key has been pressed or mouse drag event has been performed. *      </td> *    </tr> *    <tr> *      <td align="center" valign="center"> *          interval[] *      </td> *      <td> *          This property defines slider intervals sizes. The intervals are used to *          navigate through the slider component for interval model. The painting *          process uses the intervals to render scale and the scale titles. *      </td> *    </tr> *    <tr> *      <td align="center" valign="center"> *          isIntervalModel *      </td> *      <td> *          This property defines navigation model. There are two possible models: *          <ul> *            <li> *              None-interval model (if the property is false). In this case the slider *              changes its value using the defined steps properties (roughStep and *              exactStep steps). *            </li> *            <li> *              Interval model (if the property is true). In this case the slider *              changes its value using the interval sizes as the step. *            </li> *          </ul> *      </td> *    </tr> * </table> * <br> * The basic components features are described below: * <ul> *  <li> *     It is possible to customize the slider bundle and gauge views by *     <code>setView</code> method. The component uses "sl.hbundle" *     (horizontal slider), "sl.vbundle" (vertical slider) and "sl.gauge" (gauge view) *     static views as the default. *  </li> *  <li> *     The scale and titles rendering can be disabled or enabled by the *     <code>showScale</code> and <code>showTitle</code> methods. *  </li> *  <li> *     To render titles the component uses views that are provided by LwViewProvider. *     Use <code>setViewProvider</code> method to customize the titles views. *  </li> *  <li> *     Use <code>setOrientation</code> method to define the slider orientation. *  </li> *  <li> *     To listen whenever the slider value has been changed use action events listener. *  </li> * </ul> */public class LwSliderextends LwCanvasimplements LwKeyListener, LwMouseListener, LwMouseMotionListener,           LwViewProvider{ /**  * The bundle view id.  */  public static final int BUNDLE_VIEW  = 0; /**  * The gauge view id.  */  public static final int GAUGE_VIEW   = 1;  private int             max, min, value, roughStep, exactStep;  private int             netSize = 3, gap = 3, orient, scaleStep, psW, psH;  private int[]           intervals, pl;  private LwView[]        views = new LwView[2];  private LwActionSupport support;  private Color           scaleColor = LwToolkit.darkBlue;  private LwViewProvider  provider;  private LwTextRender    render = new LwTextRender(""); /**  * Constructs a slider. The slider will use horizontal orientation.  */  public LwSlider() {    this (LwToolkit.HORIZONTAL);  } /**  * Constructs a slider with the specified orientation. Use LwToolkit.HORIZONTAL or  * LwToolkit.VERTICAL constant as the orientation property value.  * @param <code>o</code> the specified orientation.  */  public LwSlider(int o)  {    provider = this;    setOrientation(o);    setView (GAUGE_VIEW, LwManager.getView("sl.gauge"));    setValues (0, 20, new int[] { 0, 5, 10 }, 2, 1);    render = new LwTextRender("");    render.setFont (LwToolkit.BFONT);    render.setForeground (scaleColor);    setScaleStep(1);    showScale (true);    showTitle (true);  }  public /*C#override*/ boolean canHaveFocus() {    return true;  } /**  * Gets the scale gap. The gap defines distance between the bundle element and the scale  * element.  * @return a gap.  */  public int getScaleGap (){    return gap;  } /**  * Sets the specified scale gap. The gap defines distance between the bundle element  * and the scale element.  * @param <code>g</code> the specified scale gap.  */  public void setScaleGap (int g)  {    if (g != gap) {      gap = g;      vrp();    }  } /**  * Gets the scale color.  * @return a scale color.  */  public Color getScaleColor () {    return scaleColor;  } /**  * Sets the scale color.  * @param <code>c</code> the scale color.  */  public void setScaleColor (Color c)  {    if (!c.equals(scaleColor)) {      scaleColor = c;      repaint();    }  } /**  * Sets the scale step.  * @param <code>s</code> the scale step.  */  public void setScaleStep (int s)  {    if (s != scaleStep)    {      scaleStep = s;      repaint();    }  } /**  * Sets the scale element visibility.  * @param <code>b</code> the scale element visibility.  */  public void showScale (boolean b)  {    if (MathBox.checkBit(bits, SHOW_SCALE) != b) {      bits = MathBox.getBits(bits, SHOW_SCALE, b);      vrp();    }  } /**  * Tests if the slider value will be changed according to the mouse cursor location by  * mouse presssed event.  * @return <code>true</code> if the slider value is changed by mouse pressed event  * according to the mouse cursor location.  */  public boolean isJumpOnPress () {    return MathBox.checkBit(bits, JUMP_ONPRESS);  } /**  * Sets if the slider value should be changed according to the mouse cursor location by  * mouse presssed event.  * @param <code>b</code> use <code>true</code> as the argument value to allow the slider  * value changing by mouse pressed event according to the mouse cursor location.  */  public void jumpOnPress (boolean b) {    bits = MathBox.getBits(bits, JUMP_ONPRESS, b);  } /**  * Sets the slider title visibility.  * @param <code>b</code> the slider title visibility.  */  public void showTitle (boolean b)  {    if (MathBox.checkBit(bits, SHOW_TITLE) != b) {      bits = MathBox.getBits(bits, SHOW_TITLE, b);      vrp();    }  } /**  * Sets the specified titles views provider. The provider defines views for the slider  * titles that are used to render the titles.  * @param <code>p</code> the specified titles views provider.  */  public void setViewProvider(LwViewProvider p)  {    if (p != provider)    {      provider = p;      vrp();    }  }  public LwView getView(Drawable d, Object o) {    render.getTextModel().setText(o!=null?o.toString():"");    return render;  } /**  * Sets the specified slider orientation. It is possible to use LwToolkit.HORIZONTAL or  * LwToolkit.VERTICAL as the orientation value. Draw attention that the method restores  * appropriate bundle view.  * @param <code>o</code> the specified slider orientation.  */  public void setOrientation(int o)  {    if (o != LwToolkit.HORIZONTAL && o != LwToolkit.VERTICAL)      throw new IllegalArgumentException();    if (o != orient)    {      orient = o;      setView (BUNDLE_VIEW, o == LwToolkit.HORIZONTAL?LwManager.getView("sl.hbundle")                                                     :LwManager.getView("sl.vbundle"));    }  } /**  * Gets the slider orientation.  * @return a slider orientation.  */  public int getOrientation() {    return orient;  } /**  * Gets the view of the specified slider element.  * @param <code>id</code> the specified slider element id.  * @return a view that is used to render the slider element.  */  public LwView getView (int id) {    return views[id];  } /**  * Sets the view for the specified slider element. There are two elements views can be  * specified by the method: BUNDLE_VIEW and GAUGE_VIEW.  * @param <code>id</code> the specified slider element id.  * @param <code>v</code> the specified view.  */  public void setView (int id, LwView v)  {    if (v != views[id])    {      views[id] = v;      vrp();    }  } /**  * Tests if the interval model is used to navigate through the slider.  * The interval model defines that navigation possible only between slider intervals.  * @return <code>true</code> if the interval model is used; otherwise <code>false</code>.  */  public boolean isIntervalModel() {    return MathBox.checkBit(bits, INTERVAL_MODEL_BIT);  } /**  * Sets the specified navigation model.  * @param <code>b</code> specified navigation model. Use <code>true</code> to set interval  * model; otherwise <code>false</code>.  */  public void useIntervalModel(boolean b) {    if (b != isIntervalModel())      bits = MathBox.getBits (bits, INTERVAL_MODEL_BIT, b);  } /**  * Gets the current slider value.  * @return a current slider value.  */  public int getValue() {    return value;  } /**  * Sets the specified slider value. The value should be less than maximal and greater than  * minimal possible properties.  * @param <code>v</code> the specified slider value.  */  public void setValue(int v)  {    if (v < min || v > max) throw new IllegalArgumentException();    int prev = value;    if (value != v)    {      value = v;      if (support != null) support.perform(new LwActionEvent(this, new Integer(prev)));      repaint();    }  } /**  * Gets the maximal possible value.  * @return a maximal possible value.  */  public int getMax () {    return max;  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -