metalsliderui.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 469 行 · 第 1/2 页
JAVA
469 行
g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1); g.setColor(UIManager.getColor("Slider.altTrackColor")); g.drawLine(x + 1, trackY + 2, x + w - 3, trackY + 2); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(x + 1, trackY + 3, x + w - 3, trackY + 3); g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); g.drawLine(x + 1, trackY + 4, x + w - 3, trackY + 4); } } else if (filledSlider) { 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.getControlShadow()); g.fillRect(x + 1, trackY + 1, w - 3, getTrackWidth() - 3); if (slider.isEnabled()) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1); g.drawLine(x + 1, trackY + 1, x + 1, trackY + getTrackWidth() - 3); } } } else { int trackX = trackRect.x + (trackRect.width - getTrackWidth()) / 2; int trackY = trackRect.y; int trackW = getTrackWidth(); int trackH = trackRect.height - 1; 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 necessary. if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) { if (slider.isEnabled()) { int yPos = yPositionForValue(slider.getValue()); int y = (slider.getInverted() ? trackY : yPos); int h = (slider.getInverted() ? yPos - trackY : trackY + trackH - yPos); g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3); g.setColor(UIManager.getColor("Slider.altTrackColor")); g.drawLine(trackX + 2, y + 1, trackX + 2, y + h - 3); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(trackX + 3, y + 1, trackX + 3, y + h - 3); g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); g.drawLine(trackX + 4, y + 1, trackX + 4, y + h - 3); } } else if (filledSlider) { int yPos = yPositionForValue(slider.getValue()); int y = (slider.getInverted() ? trackY : yPos); int h = (slider.getInverted() ? yPos - trackY : trackY + trackH - yPos); g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(trackX + 1, y + 1, getTrackWidth() - 3, h - 3); if (slider.isEnabled()) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(trackX + 1, y + 1, trackX + trackW - 3, y + 1); g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3); } } } } /** * Draws the focus rectangle for the slider. The Metal look and feel * indicates that the {@link JSlider} has the focus by changing the color of * the thumb control - this is handled elsewhere and so this method is empty * (it overrides the method in the {@link BasicSliderUI} class to prevent * a default focus highlight from being drawn). * * @param g the graphics device. */ public void paintFocus(Graphics g) { // do nothing as focus is shown by different color on thumb control } /** * Returns the size of the thumb icon. * * @return The size of the thumb icon. */ protected Dimension getThumbSize() { if (slider.getOrientation() == JSlider.HORIZONTAL) return new Dimension(horizThumbIcon.getIconWidth(), horizThumbIcon.getIconHeight()); else return new Dimension(vertThumbIcon.getIconWidth(), vertThumbIcon.getIconHeight()); } /** * Returns the length of the major tick marks. * * @return The length of the major tick marks. */ public int getTickLength() { return tickLength + TICK_BUFFER; } /** * Returns the track width. * * @return The track width. */ protected int getTrackWidth() { return trackWidth; } /** * Returns the track length. * * @return The track length. */ protected int getTrackLength() { return (slider.getOrientation() == JSlider.HORIZONTAL ? tickRect.width : tickRect.height); } /** * Returns the thumb overhang. * * @return The thumb overhang. */ protected int getThumbOverhang() { // FIXME: for what might this method be used? return 0; } protected void scrollDueToClickInTrack(int dir) { // FIXME: for what might this method be overridden? super.scrollDueToClickInTrack(dir); } /** * Paints the minor ticks for a slider with a horizontal orientation. * * @param g the graphics device. * @param tickBounds the tick bounds. * @param x the x value for the tick. */ protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) { // Note the incoming 'g' has a translation in place to get us to the // start of the tick rect already... if (slider.isEnabled()) g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength / 2); } /** * Paints the major ticks for a slider with a horizontal orientation. * * @param g the graphics device. * @param tickBounds the tick bounds. * @param x the x value for the tick. */ protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) { // Note the incoming 'g' has a translation in place to get us to the // start of the tick rect already... if (slider.isEnabled()) g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength); } /** * Paints the minor ticks for a slider with a vertical orientation. * * @param g the graphics device. * @param tickBounds the tick bounds. * @param y the y value for the tick. */ protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) { // Note the incoming 'g' has a translation in place to get us to the // start of the tick rect already... if (slider.isEnabled()) g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength / 2, y); } /** * Paints the major ticks for a slider with a vertical orientation. * * @param g the graphics device. * @param tickBounds the tick bounds. * @param y the y value for the tick. */ protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) { // Note the incoming 'g' has a translation in place to get us to the // start of the tick rect already... if (slider.isEnabled()) g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength, y); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?