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

📄 basicsliderui.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        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 biggest value that has an entry in the label table.     *     * @return biggest value that has an entry in the label table, or     *         null.     * @since 1.6     */    protected Integer getHighestValue() {        Dictionary dictionary = slider.getLabelTable();        if (dictionary != null) {            Enumeration keys = dictionary.keys();            int max = slider.getMinimum() - 1;            while (keys.hasMoreElements()) {                max = Math.max(max, ((Integer)keys.nextElement()).intValue());            }            if (max == slider.getMinimum() - 1) {                return null;            }            return max;        }        return null;    }    /**     * Returns the smallest value that has an entry in the label table.     *     * @return smallest value that has an entry in the label table, or     *         null.     * @since 1.6     */    protected Integer getLowestValue() {        Dictionary dictionary = slider.getLabelTable();        if (dictionary != null) {            Enumeration keys = dictionary.keys();            int min = slider.getMaximum() + 1;            while (keys.hasMoreElements()) {                min = Math.min(min, ((Integer)keys.nextElement()).intValue());            }            if (min == slider.getMaximum() + 1) {                return null;            }            return min;        }        return null;    }    /**     * Returns the label that corresponds to the highest slider value in the label table.     * @see JSlider#setLabelTable     */    protected Component getLowestValueLabel() {        Integer min = getLowestValue();        if (min != null) {            return (Component)slider.getLabelTable().get(min);        }        return null;    }    /**     * Returns the label that corresponds to the lowest slider value in the label table.     * @see JSlider#setLabelTable     */    protected Component getHighestValueLabel() {        Integer max = getHighestValue();        if (max != null) {            return (Component)slider.getLabelTable().get(max);        }        return null;    }    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)  {                Rectangle trackBounds = trackRect;        if ( slider.getOrientation() == JSlider.HORIZONTAL ) {            int cy = (trackBounds.height / 2) - 2;            int 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 {            int cx = (trackBounds.width / 2) - 2;            int 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);		}                while ( value <= slider.getMaximum() ) {                    yPos = yPositionForValue( value );                    paintMajorTickForVertSlider( g, tickBounds, yPos );                    value += slider.getMajorTickSpacing();                }	        if(!BasicGraphicsUtils.isLeftToRight(slider)) {		    g.translate(-2, 0);		}            }            g.translate(-tickBounds.x, 0);        }    }    protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {        g.drawLine( x, 0, x, tickBounds.height / 2 - 1 );    }    protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {        g.drawLine( x, 0, x, tickBounds.height - 2 );    }    protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {        g.drawLine( 0, y, tickBounds.width / 2 - 1, y );    }    protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {        g.drawLine( 0, y,  tickBounds.width - 2, y );    }    public void paintLabels( Graphics g ) {        Rectangle labelBounds = labelRect;        Dictionary dictionary = slider.getLabelTable();        if ( dictionary != null ) {            Enumeration keys = dictionary.keys();            int minValue = slider.getMinimum();            int maxValue = slider.getMaximum();	    boolean enabled = slider.isEnabled();            while ( keys.hasMoreElements() ) {                Integer key = (Integer)keys.nextElement();                int value = key.intValue();                if (value >= minValue && value <= maxValue) {                    Component label = (Component)dictionary.get( key );		    if (label instanceof JComponent) {			((JComponent)label).setEnabled(enabled);		    }                    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {                        g.translate( 0, labelBounds.y );                        paintHorizontalLabel( g, value, label );                        g.translate( 0, -labelBounds.y );                    }                    else {                        int offset = 0;                        if (!BasicGraphicsUtils.isLeftToRight(slider)) {                            offset = labelBounds.width -                                label.getPreferredSize().width;                        }                        g.translate( labelBounds.x + offset, 0 );                        paintVerticalLabel( g, value, label );                        g.translate( -labelBounds.x - offset, 0 );                    }                }            }        }    }    /**     * Called for every label in the label table.  Used to draw the labels for horizontal sliders.     * The graphics have been translated to labelRect.y already.     * @see JSlider#setLabelTable     */    protected void paintHorizontalLabel( Graphics g, int value, Component label ) {        int labelCenter = xPositionForValue( value );        int labelLeft = labelCenter - (label.getPreferredSize().width / 2);        g.translate( labelLeft, 0 );        label.paint( g );        g.translate( -labelLeft, 0 );    }    /**     * Called for every label in the label table.  Used to draw the labels for vertical sliders.     * The graphics have been translated to labelRect.x already.     * @see JSlider#setLabelTable     */    protected void paintVerticalLabel( Graphics g, int value, Component label ) {        int labelCenter = yPositionForValue( value );        int labelTop = labelCenter - (label.getPreferredSize().height / 2);        g.translate( 0, labelTop );        label.paint( g );        g.translate( 0, -labelTop );    }    public void paintThumb(Graphics g)  {                Rectangle knobBounds = thumbRect;        int w = knobBounds.width;        int h = knobBounds.height;              g.translate(knobBounds.x, knobBounds.y);        if ( slider.isEnabled() ) {            g.setColor(slider.getBackground());        }        else {

⌨️ 快捷键说明

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