Java Code Examples for javax.swing.JSlider#HORIZONTAL

The following examples show how to use javax.swing.JSlider#HORIZONTAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrackingGameBalls.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadGUI(){	
	setTitle("Video Sample - Tracking Game");
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 60, 30);
	sliderSensibility.setMinorTickSpacing(2);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	labelSlider = new JLabel("Sensibility");
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	buttonStart = new JButton("Start");
	buttonStart.addActionListener(new ButtonHandler());
	
	Container l_container = getContentPane();
	l_container.setLayout(new BorderLayout());
	l_container.add(videoPanel, BorderLayout.NORTH);
	l_container.add(panelSlider, BorderLayout.CENTER);
	l_container.add(buttonStart, BorderLayout.SOUTH);
	
	setSize(imageWidth+20,imageHeight+100);
	setVisible(true);
}
 
Example 2
Source File: TypesConfigFrame.java    From ontopia with Apache License 2.0 6 votes vote down vote up
private Box createWeightPanel(String title, int min, int max) {
  Box weightPanel = new Box(BoxLayout.X_AXIS);

  weightPanel.add(Box.createHorizontalStrut(10));
  weightPanel.add(new JLabel(title));
  weightPanel.add(Box.createHorizontalStrut(10));

  weight = new JSlider(JSlider.HORIZONTAL, min, max, 1);
  weight.addChangeListener(new ChangeListener() {

    @Override
    public void stateChanged(ChangeEvent e) {
      setWeight(((JSlider) e.getSource()).getValue());
    }
  });

  weightPanel.add(weight);
  weightPanel.add(Box.createHorizontalStrut(10));
  return weightPanel;
}
 
Example 3
Source File: ChromaKey.java    From marvinproject with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadGUI(){
	setTitle("Chroma Key Sample");
	
	panelBottom = new JPanel();
	
	ButtonHandler l_buttonHandler = new ButtonHandler();
	buttonCaptureBackground = new JButton("Capture Background");
	buttonStart = new JButton("Start");
	buttonStart.setEnabled(false);
	buttonCaptureBackground.addActionListener(l_buttonHandler);
	buttonStart.addActionListener(l_buttonHandler);
	
	sliderColorRange = new JSlider(JSlider.HORIZONTAL, 0, 50, 30);
	sliderColorRange.setMinorTickSpacing(1);
	sliderColorRange.setPaintTicks(true);
	sliderColorRange.addChangeListener(new SliderHandler());
	
	labelColorRange = new JLabel("Color Range");
	
	panelSlider = new JPanel();
	panelSlider.add(labelColorRange);
	panelSlider.add(sliderColorRange);
	
	panelBottom.add(buttonCaptureBackground);
	panelBottom.add(buttonStart);
	
	Container l_container = getContentPane();
	l_container.setLayout(new BorderLayout());
	l_container.add(videoPanel, BorderLayout.NORTH);
	l_container.add(panelSlider, BorderLayout.CENTER);
	l_container.add(panelBottom, BorderLayout.SOUTH);
	
	
	setSize(videoInterface.getImageWidth(),videoInterface.getImageHeight()+100);
	setVisible(true);
}
 
Example 4
Source File: MotifSliderUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}
 
Example 5
Source File: SeaGlassSynthPainterImpl.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Paints the background of the thumb of a slider.
 *
 * @param context     SynthContext identifying the <code>JComponent</code>
 *                    and <code>Region</code> to paint to
 * @param g           <code>Graphics</code> to paint to
 * @param x           X coordinate of the area to paint to
 * @param y           Y coordinate of the area to paint to
 * @param w           Width of the area to paint to
 * @param h           Height of the area to paint to
 * @param orientation One of <code>JSlider.HORIZONTAL</code> or <code>
 *                    JSlider.VERTICAL</code>
 */
public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) {
    if (context.getComponent().getClientProperty("Slider.paintThumbArrowShape") == Boolean.TRUE) {

        if (orientation == JSlider.HORIZONTAL) {
            orientation = JSlider.VERTICAL;
        } else {
            orientation = JSlider.HORIZONTAL;
        }

        paintBackground(context, g, x, y, w, h, orientation);
    } else {
        paintBackground(context, g, x, y, w, h, orientation);
    }
}
 
Example 6
Source File: LuckSliderUI.java    From littleluck with Apache License 2.0 5 votes vote down vote up
@Override
public void paintTrack(Graphics g)
{
    // 如果还未初始化图片资源,则先初始化。
    // The initialization of the resources required.
    initRes(slider.getOrientation());
    
    Rectangle trackBounds = trackRect;
    
    Graphics2D g2d = (Graphics2D) g;

    if (slider.getOrientation() == JSlider.HORIZONTAL)
    {
        // 垂直居中,偏下两个像素。
        // Vertical center, under two partial pixels.
        int cy = (trackBounds.height / 2) - 2;

        g.translate(trackBounds.x, trackBounds.y + cy);

        horizontalNp.drawNinePatch(g2d, 0, 0, trackBounds.width, size);

        horizontalHighlightNp.drawNinePatch(g2d, 0, 0, thumbRect.x - 2, size);

        g.translate(-trackBounds.x, -(trackBounds.y + cy));
    }
    else
    {
        // 水平居中偏右连个像素。
        // Horizontal center-right two pixels.
        int cx = (trackBounds.width / 2) - 2;

        g.translate(trackBounds.x + cx, trackBounds.y);

        verticalNp.drawNinePatch(g2d, 0, 0, size, trackBounds.height);

        verticalHighlightNp.drawNinePatch(g2d, 0, thumbRect.y, size, trackBounds.height - thumbRect.y);

        g.translate(-(trackBounds.x + cx), -trackBounds.y);
    }
}
 
Example 7
Source File: PercentageInputComponent.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Creates a new PercentageInputComponent.
 * 
 * @param param The PercentageParameter to be controlled.
 * @param enabled 
 * @param parameterPanel The ParameterPanel to which this component is to
 * 				 be placed.
 */
public PercentageInputComponent(
		PercentageParameter param, ParameterPanel parameterPanel) {
	super(parameterPanel);
	this.param = param;
	this.state = ParameterInputComponent.INPUT_IS_INITIALIZED;
	/**
	 * The eventual minimum and maximum values of the percentage parameter
	 * may be something between 0 and 100, but the slider will always show
	 * a scale from 0 to 100, even if some values would be illegal.
	 * The illegality is (hopefully) clearly indicated.
	 */
	int initValue = 0; 
	if (param.getIntegerValue() != null) {
	    initValue = param.getIntegerValue().intValue();
	}
	this.slider = new JSlider(JSlider.HORIZONTAL, 0, 100, initValue);
	slider.setMajorTickSpacing(50);
	slider.setMinorTickSpacing(10);
	slider.setPaintTicks(true);
	slider.setPaintLabels(false);
	slider.addChangeListener(this);
	slider.addFocusListener(this);
	// Normal width minus label width
	slider.setPreferredSize(new Dimension(ParameterInputComponent.PREFERED_WIDTH - 40, 40));
	
	this.numberLabel = new JLabel(
			param.getIntegerValue() + "%", SwingConstants.CENTER);
	numberLabel.setPreferredSize(new Dimension(40, 30));
	numberLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
	
	this.add(slider, BorderLayout.WEST);
	this.add(numberLabel, BorderLayout.EAST);
}
 
Example 8
Source File: MotifSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}
 
Example 9
Source File: ZoomSliderPanel.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private JSlider getControl() {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 50, 200, 100);
    slider.setMajorTickSpacing(50);
    slider.setMinorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.addChangeListener(this);
    return slider;        
}
 
Example 10
Source File: SimpleMotionDetection.java    From marvinproject with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadGUI(){
	setTitle("Simple Motion Detection");
	labelMotion = new JLabel("MOTION: NO");
	labelMotion.setOpaque(true);
	labelMotion.setHorizontalAlignment(SwingConstants.CENTER);
	
	labelMotion.setBackground(Color.red);
	labelMotion.setForeground(Color.white);
	
	labelSlider = new JLabel("Sensibility:");
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 13, 10);
	sliderSensibility.setMinorTickSpacing(1);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	panelCenter = new JPanel(new BorderLayout());
	panelCenter.add(videoPanel, BorderLayout.NORTH);
	panelCenter.add(labelMotion, BorderLayout.SOUTH);
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	Container l_container = getContentPane();
	l_container.add(videoPanel, BorderLayout.NORTH);
	l_container.add(labelMotion, BorderLayout.CENTER);
	l_container.add(panelSlider, BorderLayout.SOUTH);
	
	
	setSize(imageWidth,imageHeight+100);
	setVisible(true);
}
 
Example 11
Source File: SeaGlassSliderUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
protected void calculateTickRect() {
    if (slider.getOrientation() == JSlider.HORIZONTAL) {
        tickRect.x = trackRect.x;
        tickRect.y = trackRect.y + trackRect.height + 2 + getTickLength();
        tickRect.width = trackRect.width;
        tickRect.height = getTickLength();

        if (!slider.getPaintTicks()) {
            --tickRect.y;
            tickRect.height = 0;
        }
    } else {
        if (SeaGlassLookAndFeel.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;
        }
    }
}
 
Example 12
Source File: JavaMixer.java    From Spark with Apache License 2.0 5 votes vote down vote up
private JComponent createControlComponent(FloatControl control) {
    int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL;
    BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control);
    JSlider slider = new JSlider(model);
    slider.setOrientation(orientation);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setSize(10, 50);
    return slider;
}
 
Example 13
Source File: WaveformSliderUI.java    From pumpernickel with MIT License 5 votes vote down vote up
private void adjustValue(MouseEvent e) {
	float f;
	if (slider.getOrientation() == JSlider.HORIZONTAL) {
		f = (float) (e.getX() - trackRect.x) / (float) trackRect.width;
	} else {
		f = (float) (e.getY() - trackRect.y) / (float) trackRect.height;
	}
	int range = slider.getMaximum() - slider.getMinimum();
	int value = slider.getMinimum() + (int) (range * f);
	if (value < slider.getMinimum())
		value = slider.getMinimum();
	if (value > slider.getMaximum())
		value = slider.getMaximum();
	slider.setValue(value);
}
 
Example 14
Source File: MotifSliderUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void paintThumb(Graphics g)  {
    Rectangle knobBounds = thumbRect;

    int x = knobBounds.x;
    int y = knobBounds.y;
    int w = knobBounds.width;
    int h = knobBounds.height;

    if ( slider.isEnabled() ) {
        g.setColor(slider.getForeground());
    }
    else {
        // PENDING(jeff) - the thumb should be dithered when disabled
        g.setColor(slider.getForeground().darker());
    }

    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        g.translate(x, knobBounds.y-1);

        // fill
        g.fillRect(0, 1, w, h - 1);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 0, w - 1, 1);      // top
        drawVLine(g, 0, 1, h);          // left
        drawVLine(g, w / 2, 2, h - 1);  // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 0, w - 1, h);      // bottom
        drawVLine(g, w - 1, 1, h);      // right
        drawVLine(g, w / 2 - 1, 2, h);  // center

        g.translate(-x, -(knobBounds.y-1));
    }
    else {
        g.translate(knobBounds.x-1, 0);

        // fill
        g.fillRect(1, y, w - 1, h);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 1, w, y);             // top
        drawVLine(g, 1, y + 1, y + h - 1); // left
        drawHLine(g, 2, w - 1, y + h / 2); // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 2, w, y + h - 1);        // bottom
        drawVLine(g, w, y + h - 1, y);        // right
        drawHLine(g, 2, w - 1, y + h / 2 - 1);// center

        g.translate(-(knobBounds.x-1), 0);
    }
}
 
Example 15
Source File: MotifSliderUI.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void paintThumb(Graphics g)  {
    Rectangle knobBounds = thumbRect;

    int x = knobBounds.x;
    int y = knobBounds.y;
    int w = knobBounds.width;
    int h = knobBounds.height;

    if ( slider.isEnabled() ) {
        g.setColor(slider.getForeground());
    }
    else {
        // PENDING(jeff) - the thumb should be dithered when disabled
        g.setColor(slider.getForeground().darker());
    }

    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        g.translate(x, knobBounds.y-1);

        // fill
        g.fillRect(0, 1, w, h - 1);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 0, w - 1, 1);      // top
        drawVLine(g, 0, 1, h);          // left
        drawVLine(g, w / 2, 2, h - 1);  // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 0, w - 1, h);      // bottom
        drawVLine(g, w - 1, 1, h);      // right
        drawVLine(g, w / 2 - 1, 2, h);  // center

        g.translate(-x, -(knobBounds.y-1));
    }
    else {
        g.translate(knobBounds.x-1, 0);

        // fill
        g.fillRect(1, y, w - 1, h);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 1, w, y);             // top
        drawVLine(g, 1, y + 1, y + h - 1); // left
        drawHLine(g, 2, w - 1, y + h / 2); // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 2, w, y + h - 1);        // bottom
        drawVLine(g, w, y + h - 1, y);        // right
        drawHLine(g, 2, w - 1, y + h / 2 - 1);// center

        g.translate(-(knobBounds.x-1), 0);
    }
}
 
Example 16
Source File: MotifSliderUI.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void paintThumb(Graphics g)  {
    Rectangle knobBounds = thumbRect;

    int x = knobBounds.x;
    int y = knobBounds.y;
    int w = knobBounds.width;
    int h = knobBounds.height;

    if ( slider.isEnabled() ) {
        g.setColor(slider.getForeground());
    }
    else {
        // PENDING(jeff) - the thumb should be dithered when disabled
        g.setColor(slider.getForeground().darker());
    }

    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        g.translate(x, knobBounds.y-1);

        // fill
        g.fillRect(0, 1, w, h - 1);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 0, w - 1, 1);      // top
        drawVLine(g, 0, 1, h);          // left
        drawVLine(g, w / 2, 2, h - 1);  // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 0, w - 1, h);      // bottom
        drawVLine(g, w - 1, 1, h);      // right
        drawVLine(g, w / 2 - 1, 2, h);  // center

        g.translate(-x, -(knobBounds.y-1));
    }
    else {
        g.translate(knobBounds.x-1, 0);

        // fill
        g.fillRect(1, y, w - 1, h);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 1, w, y);             // top
        drawVLine(g, 1, y + 1, y + h - 1); // left
        drawHLine(g, 2, w - 1, y + h / 2); // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 2, w, y + h - 1);        // bottom
        drawVLine(g, w, y + h - 1, y);        // right
        drawHLine(g, 2, w - 1, y + h / 2 - 1);// center

        g.translate(-(knobBounds.x-1), 0);
    }
}
 
Example 17
Source File: RocPlot.java    From rtg-tools with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates a new swing plot.
 * @param precisionRecall true defaults to precision recall graph
 * @param interpolate if true, enable curve interpolation
 */
RocPlot(boolean precisionRecall, boolean interpolate) {
  mInterpolate = interpolate;
  mMainPanel = new JPanel();
  UIManager.put("FileChooser.readOnly", Boolean.TRUE);
  mFileChooser = new JFileChooser();
  final Action details = mFileChooser.getActionMap().get("viewTypeDetails");
  if (details != null) {
    details.actionPerformed(null);
  }
  mFileChooser.setMultiSelectionEnabled(true);
  mFileChooser.setFileFilter(new RocFileFilter());
  mZoomPP = new RocZoomPlotPanel();
  mZoomPP.setOriginIsMin(true);
  mZoomPP.setTextAntialiasing(true);
  mProgressBar = new JProgressBar(-1, -1);
  mProgressBar.setVisible(true);
  mProgressBar.setStringPainted(true);
  mProgressBar.setIndeterminate(true);
  mStatusLabel = new JLabel();
  mPopup = new JPopupMenu();
  mRocLinesPanel = new RocLinesPanel(this);
  mScrollPane = new JScrollPane(mRocLinesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  mScrollPane.setWheelScrollingEnabled(true);
  mLineWidthSlider = new JSlider(JSlider.HORIZONTAL, LINE_WIDTH_MIN, LINE_WIDTH_MAX, 1);
  mScoreCB = new JCheckBox("Show Scores");
  mScoreCB.setSelected(true);
  mSelectAllCB = new JCheckBox("Select / Deselect all");
  mTitleEntry = new JTextField("ROC");
  mTitleEntry.setMaximumSize(new Dimension(Integer.MAX_VALUE, mTitleEntry.getPreferredSize().height));
  mOpenButton = new JButton("Open...");
  mOpenButton.setToolTipText("Add a new curve from a file");
  mCommandButton = new JButton("Cmd...");
  mCommandButton.setToolTipText("Send the equivalent rocplot command-line to the terminal");
  final ImageIcon icon = createImageIcon("com/rtg/graph/resources/realtimegenomics_logo.png", "RTG Logo");
  mIconLabel = new JLabel(icon);
  mIconLabel.setBackground(new Color(16, 159, 205));
  mIconLabel.setForeground(Color.WHITE);
  mIconLabel.setOpaque(true);
  mIconLabel.setFont(new Font("Arial", Font.BOLD, 24));
  mIconLabel.setHorizontalAlignment(JLabel.LEFT);
  mIconLabel.setIconTextGap(50);
  if (icon != null) {
    mIconLabel.setMinimumSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
  }
  mGraphType = new JComboBox<>(new String[] {ROC_PLOT, PRECISION_SENSITIVITY});
  mGraphType.setSelectedItem(precisionRecall ? PRECISION_SENSITIVITY : ROC_PLOT);
  configureUI();
}
 
Example 18
Source File: MotifSliderUI.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public void paintThumb(Graphics g)  {
    Rectangle knobBounds = thumbRect;

    int x = knobBounds.x;
    int y = knobBounds.y;
    int w = knobBounds.width;
    int h = knobBounds.height;

    if ( slider.isEnabled() ) {
        g.setColor(slider.getForeground());
    }
    else {
        // PENDING(jeff) - the thumb should be dithered when disabled
        g.setColor(slider.getForeground().darker());
    }

    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        g.translate(x, knobBounds.y-1);

        // fill
        g.fillRect(0, 1, w, h - 1);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 0, w - 1, 1);      // top
        drawVLine(g, 0, 1, h);          // left
        drawVLine(g, w / 2, 2, h - 1);  // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 0, w - 1, h);      // bottom
        drawVLine(g, w - 1, 1, h);      // right
        drawVLine(g, w / 2 - 1, 2, h);  // center

        g.translate(-x, -(knobBounds.y-1));
    }
    else {
        g.translate(knobBounds.x-1, 0);

        // fill
        g.fillRect(1, y, w - 1, h);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 1, w, y);             // top
        drawVLine(g, 1, y + 1, y + h - 1); // left
        drawHLine(g, 2, w - 1, y + h / 2); // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 2, w, y + h - 1);        // bottom
        drawVLine(g, w, y + h - 1, y);        // right
        drawHLine(g, 2, w - 1, y + h / 2 - 1);// center

        g.translate(-(knobBounds.x-1), 0);
    }
}
 
Example 19
Source File: SeaGlassSliderUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
public void mouseDragged(MouseEvent e) {
    int thumbMiddle = 0;

    if (!slider.isEnabled()) {
        return;
    }

    currentMouseX = e.getX();
    currentMouseY = e.getY();

    if (!isDragging()) {
        return;
    }

    slider.setValueIsAdjusting(true);

    switch (slider.getOrientation()) {
    case JSlider.VERTICAL:
        int halfThumbHeight = thumbRect.height / 2;
        int thumbTop = e.getY() - offset;
        int trackTop = trackRect.y;
        int trackBottom = trackRect.y + trackRect.height - halfThumbHeight - trackBorder;
        int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent());

        if (drawInverted()) {
            trackBottom = vMax;
            trackTop = trackTop + halfThumbHeight;
        } else {
            trackTop = vMax;
        }
        thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
        thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);

        setThumbLocation(thumbRect.x, thumbTop);

        thumbMiddle = thumbTop + halfThumbHeight;
        slider.setValue(valueForYPosition(thumbMiddle));
        break;
    case JSlider.HORIZONTAL:
        int halfThumbWidth = thumbRect.width / 2;
        int thumbLeft = e.getX() - offset;
        int trackLeft = trackRect.x + halfThumbWidth + trackBorder;
        int trackRight = trackRect.x + trackRect.width - halfThumbWidth - trackBorder;
        int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent());

        if (drawInverted()) {
            trackLeft = hMax;
        } else {
            trackRight = hMax;
        }
        thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
        thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);

        setThumbLocation(thumbLeft, thumbRect.y);

        thumbMiddle = thumbLeft + halfThumbWidth;
        slider.setValue(valueForXPosition(thumbMiddle));
        break;
    default:
        return;
    }

    if (slider.getValueIsAdjusting()) {
        setThumbActive(true);
    }
}
 
Example 20
Source File: MotifSliderUI.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void paintThumb(Graphics g)  {
    Rectangle knobBounds = thumbRect;

    int x = knobBounds.x;
    int y = knobBounds.y;
    int w = knobBounds.width;
    int h = knobBounds.height;

    if ( slider.isEnabled() ) {
        g.setColor(slider.getForeground());
    }
    else {
        // PENDING(jeff) - the thumb should be dithered when disabled
        g.setColor(slider.getForeground().darker());
    }

    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        g.translate(x, knobBounds.y-1);

        // fill
        g.fillRect(0, 1, w, h - 1);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 0, w - 1, 1);      // top
        drawVLine(g, 0, 1, h);          // left
        drawVLine(g, w / 2, 2, h - 1);  // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 0, w - 1, h);      // bottom
        drawVLine(g, w - 1, 1, h);      // right
        drawVLine(g, w / 2 - 1, 2, h);  // center

        g.translate(-x, -(knobBounds.y-1));
    }
    else {
        g.translate(knobBounds.x-1, 0);

        // fill
        g.fillRect(1, y, w - 1, h);

        // highlight
        g.setColor(getHighlightColor());
        drawHLine(g, 1, w, y);             // top
        drawVLine(g, 1, y + 1, y + h - 1); // left
        drawHLine(g, 2, w - 1, y + h / 2); // center

        // shadow
        g.setColor(getShadowColor());
        drawHLine(g, 2, w, y + h - 1);        // bottom
        drawVLine(g, w, y + h - 1, y);        // right
        drawHLine(g, 2, w - 1, y + h / 2 - 1);// center

        g.translate(-(knobBounds.x-1), 0);
    }
}