metalsliderui.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 469 行 · 第 1/2 页
JAVA
469 行
/* MetalSliderUI.java Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.plaf.metal;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Rectangle;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.Icon;import javax.swing.JComponent;import javax.swing.JSlider;import javax.swing.UIManager;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.basic.BasicGraphicsUtils;import javax.swing.plaf.basic.BasicSliderUI;/** * A UI delegate for the {@link JSlider} component. */public class MetalSliderUI extends BasicSliderUI{ /** * A property change handler that updates the rendered component in response * to specific property change events. This custom handler is used to * intercept the "JSlider.isFilled" property, which is only recognised by * the {@link MetalLookAndFeel}. */ protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { /** * Creates a new listener. */ protected MetalPropertyListener() { // Nothing to do here. } /** * Handles property change events. Events with the name "JSlider.isFilled" * are handled here, and other events are passed to the superclass. * * @param e the property change event. */ public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName().equals(SLIDER_FILL)) { Boolean b = (Boolean) e.getNewValue(); if (b == null) filledSlider = false; else filledSlider = b.booleanValue(); } else super.propertyChange(e); } } /** The thumb color (unused, because an icon is used to draw the thumb). */ protected static Color thumbColor; /** * The highlight color used for drawing the track rect when the slider is * enabled. */ protected static Color highlightColor; /** * The shadow color used for drawing the track rect when the slider is * enabled. */ protected static Color darkShadowColor; /** The track width. */ protected static int trackWidth = UIManager.getInt("Slider.trackWidth"); /** The length of the major tick marks. */ protected static int tickLength = UIManager.getInt("Slider.majorTickLength"); /** The icon used for the thumb control of horizontally oriented sliders. */ protected static Icon horizThumbIcon = UIManager.getIcon( "Slider.horizontalThumbIcon"); /** The icon used for the thumb control of vertically oriented sliders. */ protected static Icon vertThumbIcon = UIManager.getIcon( "Slider.verticalThumbIcon"); /** The gap between the track and the tick marks. */ protected final int TICK_BUFFER = 4; /** A key to look up the filledSlider setting in the {@link UIManager}. */ protected final String SLIDER_FILL = "JSlider.isFilled"; /** * A flag that controls whether or not the track is filled up to the value * of the slider. */ protected boolean filledSlider; /** * Constructs a new instance. */ public MetalSliderUI() { super(null); filledSlider = UIManager.getBoolean(SLIDER_FILL); darkShadowColor = MetalLookAndFeel.getControlDarkShadow(); highlightColor = MetalLookAndFeel.getControlHighlight(); } /** * Returns a new instance of <code>MetalSliderUI</code>. * * @param component the component (ignored). * * @return A new instance of <code>MetalSliderUI</code>. */ public static ComponentUI createUI(JComponent component) { return new MetalSliderUI(); } /** * Installs the default for this UI delegate in the supplied component. * * @param c the component. */ public void installUI(JComponent c) { super.installUI(c); Boolean b = (Boolean) c.getClientProperty(SLIDER_FILL); if (b != null) filledSlider = b.booleanValue(); } /** * Creates a property change listener for the slider. * * @param slider the slider. * * @return A new instance of {@link MetalPropertyListener}. */ protected PropertyChangeListener createPropertyChangeListener(JSlider slider) { return new MetalPropertyListener(); } /** * Paints the thumb icon for the slider. * * @param g the graphics device. */ public void paintThumb(Graphics g) { if (slider.getOrientation() == JSlider.HORIZONTAL) horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); else vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); } /** * Paints the track along which the thumb control moves. * * @param g the graphics device. */ public void paintTrack(Graphics g) { Color shadowColor = MetalLookAndFeel.getControlShadow(); if (slider.getOrientation() == JSlider.HORIZONTAL) { int trackX = trackRect.x; int trackY = trackRect.y + (trackRect.height - getTrackWidth()) / 2; int trackW = trackRect.width - 1; int trackH = getTrackWidth(); // draw border if (slider.isEnabled()) BasicGraphicsUtils.drawEtchedRect(g, trackX, trackY, trackW, trackH, darkShadowColor, shadowColor, darkShadowColor, highlightColor); else { g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(trackX, trackY, trackW - 2, trackH - 2); } // fill track (if required) if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) { if (slider.isEnabled()) { int xPos = xPositionForValue(slider.getValue()); int x = (slider.getInverted() ? xPos : trackRect.x); int w = (slider.getInverted() ? trackX + trackW - xPos : xPos - trackRect.x); g.setColor(MetalLookAndFeel.getWhite());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?