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

📄 basicsliderui.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                trackBuffer = Math.max( highLabel.getBounds().width, lowLabel.getBounds().width ) / 2;                trackBuffer = Math.max( trackBuffer, thumbRect.width / 2 );            }            else {                trackBuffer = Math.max( highLabel.getBounds().height, lowLabel.getBounds().height ) / 2;                trackBuffer = Math.max( trackBuffer, thumbRect.height / 2 );            }        }        else {            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {                trackBuffer = thumbRect.width / 2;            }            else {                trackBuffer = thumbRect.height / 2;            }        }    }      protected void calculateTrackRect() {	int centerSpacing = 0; // used to center sliders added using BorderLayout.CENTER (bug 4275631)        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {	    centerSpacing = thumbRect.height;	    if ( slider.getPaintTicks() ) centerSpacing += getTickLength();	    if ( slider.getPaintLabels() ) centerSpacing += getHeightOfTallestLabel();	    trackRect.x = contentRect.x + trackBuffer;	    trackRect.y = contentRect.y + (contentRect.height - centerSpacing - 1)/2;	    trackRect.width = contentRect.width - (trackBuffer * 2);	    trackRect.height = thumbRect.height;	}	else {	    centerSpacing = thumbRect.width;	    if (BasicGraphicsUtils.isLeftToRight(slider)) {		if ( slider.getPaintTicks() ) centerSpacing += getTickLength();	    	if ( slider.getPaintLabels() ) centerSpacing += getWidthOfWidestLabel();	    } else {	        if ( slider.getPaintTicks() ) centerSpacing -= getTickLength();	    	if ( slider.getPaintLabels() ) centerSpacing -= getWidthOfWidestLabel();	    }	    trackRect.x = contentRect.x + (contentRect.width - centerSpacing - 1)/2;	    trackRect.y = contentRect.y + trackBuffer;	    trackRect.width = thumbRect.width;	    trackRect.height = contentRect.height - (trackBuffer * 2);	}    }    /**     * Gets the height of the tick area for horizontal sliders and the width of the     * tick area for vertical sliders.  BasicSliderUI uses the returned value to     * determine the tick area rectangle.  If you want to give your ticks some room,     * make this larger than you need and paint your ticks away from the sides in paintTicks().     */    protected int getTickLength() {        return 8;    }    protected void calculateTickRect() {	if ( slider.getOrientation() == JSlider.HORIZONTAL ) {	    tickRect.x = trackRect.x;	    tickRect.y = trackRect.y + trackRect.height;	    tickRect.width = trackRect.width;	    tickRect.height = getTickLength();	    	    if ( !slider.getPaintTicks() ) {	        --tickRect.y;		tickRect.height = 0;	    }	}	else {	    if(BasicGraphicsUtils.isLeftToRight(slider)) {	        tickRect.x = trackRect.x + trackRect.width;		tickRect.width = getTickLength();	    }	    else {	        tickRect.width = getTickLength();	        tickRect.x = trackRect.x - tickRect.width;	    }	    tickRect.y = trackRect.y;	    tickRect.height = trackRect.height;	    if ( !slider.getPaintTicks() ) {	        --tickRect.x;		tickRect.width = 0;	    }	}    }    protected void calculateLabelRect() {        if ( slider.getPaintLabels() ) {	    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {	        labelRect.x = tickRect.x - trackBuffer;		labelRect.y = tickRect.y + tickRect.height;		labelRect.width = tickRect.width + (trackBuffer * 2);                labelRect.height = getHeightOfTallestLabel();            }            else {	        if(BasicGraphicsUtils.isLeftToRight(slider)) {		    labelRect.x = tickRect.x + tickRect.width;		    labelRect.width = getWidthOfWidestLabel();		}		else {		    labelRect.width = getWidthOfWidestLabel();		    labelRect.x = tickRect.x - labelRect.width;		}		labelRect.y = tickRect.y - trackBuffer;		labelRect.height = tickRect.height + (trackBuffer * 2);            }        }        else {            if ( slider.getOrientation() == JSlider.HORIZONTAL ) {	        labelRect.x = tickRect.x;		labelRect.y = tickRect.y + tickRect.height;		labelRect.width = tickRect.width;		labelRect.height = 0;            }            else {	        if(BasicGraphicsUtils.isLeftToRight(slider)) {		    labelRect.x = tickRect.x + tickRect.width;		}		else {		    labelRect.x = tickRect.x;		}		labelRect.y = tickRect.y;		labelRect.width = 0;		labelRect.height = tickRect.height;            }        }    }    protected Dimension getThumbSize() {        Dimension size = new Dimension();        if ( slider.getOrientation() == JSlider.VERTICAL ) {	    size.width = 20;	    size.height = 11;	}	else {	    size.width = 11;	    size.height = 20;	}	return size;    }    public class PropertyChangeHandler implements PropertyChangeListener {        // NOTE: This class exists only for backward compatability. All        // its functionality has been moved into Handler. If you need to add        // new functionality add it to the Handler, but make sure this              // class calls into the Handler.        public void propertyChange( PropertyChangeEvent e ) {            getHandler().propertyChange(e);        }    }    protected int getWidthOfWidestLabel() {        Dictionary dictionary = slider.getLabelTable();        int widest = 0;        if ( dictionary != null ) {            Enumeration keys = dictionary.keys();            while ( keys.hasMoreElements() ) {                Component label = (Component)dictionary.get( keys.nextElement() );                widest = Math.max( label.getPreferredSize().width, widest );            }        }        return widest;    }    protected int getHeightOfTallestLabel() {        Dictionary dictionary = slider.getLabelTable();        int tallest = 0;        if ( dictionary != null ) {            Enumeration keys = dictionary.keys();            while ( keys.hasMoreElements() ) {                Component label = (Component)dictionary.get( keys.nextElement() );                tallest = Math.max( label.getPreferredSize().height, tallest );            }        }        return tallest;    }    protected int getWidthOfHighValueLabel() {        Component label = getHighestValueLabel();        int width = 0;        if ( label != null ) {            width = label.getPreferredSize().width;        }        return width;    }    protected int getWidthOfLowValueLabel() {        Component label = getLowestValueLabel();        int width = 0;        if ( label != null ) {            width = label.getPreferredSize().width;        }        return width;    }    protected int getHeightOfHighValueLabel() {        Component label = getHighestValueLabel();        int height = 0;        if ( label != null ) {            height = label.getPreferredSize().height;        }        return height;    }    protected int getHeightOfLowValueLabel() {        Component label = getLowestValueLabel();        int height = 0;        if ( label != null ) {            height = label.getPreferredSize().height;        }        return height;    }    protected boolean drawInverted() {        if (slider.getOrientation()==JSlider.HORIZONTAL) {	    if(BasicGraphicsUtils.isLeftToRight(slider)) {	        return slider.getInverted();	    } else {	        return !slider.getInverted();	    }	} else {	    return slider.getInverted();	}    }    /**     * Returns the label that corresponds to the highest slider value in the label table.     * @see JSlider#setLabelTable     */    protected Component getLowestValueLabel() {        Dictionary dictionary = slider.getLabelTable();        Component label = null;        if ( dictionary != null ) {            Enumeration keys = dictionary.keys();            if ( keys.hasMoreElements() ) {                int lowestValue = ((Integer)keys.nextElement()).intValue();                while ( keys.hasMoreElements() ) {                    int value = ((Integer)keys.nextElement()).intValue();                    lowestValue = Math.min( value, lowestValue );                }                label = (Component)dictionary.get( new Integer( lowestValue ) );            }        }        return label;    }    /**     * Returns the label that corresponds to the lowest slider value in the label table.     * @see JSlider#setLabelTable     */    protected Component getHighestValueLabel() {        Dictionary dictionary = slider.getLabelTable();        Component label = null;        if ( dictionary != null ) {            Enumeration keys = dictionary.keys();            if ( keys.hasMoreElements() ) {                int highestValue = ((Integer)keys.nextElement()).intValue();                while ( keys.hasMoreElements() ) {                    int value = ((Integer)keys.nextElement()).intValue();                    highestValue = Math.max( value, highestValue );                }                label = (Component)dictionary.get( new Integer( highestValue ) );            }        }        return label;    }    public void paint( Graphics g, JComponent c )   {        recalculateIfInsetsChanged();	recalculateIfOrientationChanged();	Rectangle clip = g.getClipBounds();	if ( !clip.intersects(trackRect) && slider.getPaintTrack())	    calculateGeometry();	if ( slider.getPaintTrack() && clip.intersects( trackRect ) ) {	    paintTrack( g );	}        if ( slider.getPaintTicks() && clip.intersects( tickRect ) ) {            paintTicks( g );        }        if ( slider.getPaintLabels() && clip.intersects( labelRect ) ) {            paintLabels( g );        }	if ( slider.hasFocus() && clip.intersects( focusRect ) ) {	    paintFocus( g );      	}	if ( clip.intersects( thumbRect ) ) {	    paintThumb( g );	}    }    protected void recalculateIfInsetsChanged() {        Insets newInsets = slider.getInsets();        if ( !newInsets.equals( insetCache ) ) {	    insetCache = newInsets;	    calculateGeometry();	}    }    protected void recalculateIfOrientationChanged() {        boolean ltr = BasicGraphicsUtils.isLeftToRight(slider);        if ( ltr!=leftToRightCache ) {	    leftToRightCache = ltr;	    calculateGeometry();	}    }    public void paintFocus(Graphics g)  {        	g.setColor( getFocusColor() );	BasicGraphicsUtils.drawDashedRect( g, focusRect.x, focusRect.y,					   focusRect.width, focusRect.height );    }    public void paintTrack(Graphics g)  {                int cx, cy, cw, ch;        int pad;        Rectangle trackBounds = trackRect;        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {            pad = trackBuffer;            cx = pad;            cy = (trackBounds.height / 2) - 2;            cw = trackBounds.width;            g.translate(trackBounds.x, trackBounds.y + cy);            g.setColor(getShadowColor());            g.drawLine(0, 0, cw - 1, 0);            g.drawLine(0, 1, 0, 2);            g.setColor(getHighlightColor());            g.drawLine(0, 3, cw, 3);            g.drawLine(cw, 0, cw, 3);            g.setColor(Color.black);            g.drawLine(1, 1, cw-2, 1);            g.translate(-trackBounds.x, -(trackBounds.y + cy));        }        else {            pad = trackBuffer;            cx = (trackBounds.width / 2) - 2;            cy = pad;            ch = trackBounds.height;            g.translate(trackBounds.x + cx, trackBounds.y);            g.setColor(getShadowColor());            g.drawLine(0, 0, 0, ch - 1);            g.drawLine(1, 0, 2, 0);            g.setColor(getHighlightColor());            g.drawLine(3, 0, 3, ch);            g.drawLine(0, ch, 3, ch);            g.setColor(Color.black);            g.drawLine(1, 1, 1, ch-2);            g.translate(-(trackBounds.x + cx), -trackBounds.y);        }    }    public void paintTicks(Graphics g)  {                Rectangle tickBounds = tickRect;        int i;        int maj, min, max;        int w = tickBounds.width;        int h = tickBounds.height;        int centerEffect, tickHeight;        g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black));        maj = slider.getMajorTickSpacing();        min = slider.getMinorTickSpacing();        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {           g.translate( 0, tickBounds.y);            int value = slider.getMinimum();            int xPos = 0;            if ( slider.getMinorTickSpacing() > 0 ) {                while ( value <= slider.getMaximum() ) {                    xPos = xPositionForValue( value );                    paintMinorTickForHorizSlider( g, tickBounds, xPos );                    value += slider.getMinorTickSpacing();                }            }            if ( slider.getMajorTickSpacing() > 0 ) {                value = slider.getMinimum();                while ( value <= slider.getMaximum() ) {                    xPos = xPositionForValue( value );                    paintMajorTickForHorizSlider( g, tickBounds, xPos );                    value += slider.getMajorTickSpacing();                }            }            g.translate( 0, -tickBounds.y);        }        else {           g.translate(tickBounds.x, 0);            int value = slider.getMinimum();            int yPos = 0;            if ( slider.getMinorTickSpacing() > 0 ) {	        int offset = 0;	        if(!BasicGraphicsUtils.isLeftToRight(slider)) {		    offset = tickBounds.width - tickBounds.width / 2;		    g.translate(offset, 0);		}                while ( value <= slider.getMaximum() ) {                    yPos = yPositionForValue( value );                    paintMinorTickForVertSlider( g, tickBounds, yPos );                    value += slider.getMinorTickSpacing();                }		if(!BasicGraphicsUtils.isLeftToRight(slider)) {		    g.translate(-offset, 0);		}            }            if ( slider.getMajorTickSpacing() > 0 ) {                value = slider.getMinimum();	        if(!BasicGraphicsUtils.isLeftToRight(slider)) {		    g.translate(2, 0);		}

⌨️ 快捷键说明

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