Java Code Examples for javax.swing.JSlider#getValue()

The following examples show how to use javax.swing.JSlider#getValue() . 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: AqlViewer.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private <X, Y> void viewAlgebraHelper(JComponent top, Algebra<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> algebra,
		JPanel out, JCheckBox simp, JSlider sl, Map<Pair<Boolean, Integer>, JScrollPane> cache) {
	boolean b = simp.isSelected();
	int l = sl.getValue();
	Pair<Boolean, Integer> p = new Pair<>(b, l);
	JScrollPane jsp = cache.get(p);
	if (jsp == null) {
		jsp = makeList2(algebra, b, l);
		cache.put(p, jsp);
	}
	out.removeAll();
	out.add(jsp, BorderLayout.CENTER);
	out.add(top, BorderLayout.SOUTH);
	out.revalidate();
	out.repaint();
}
 
Example 2
Source File: MainFrame.java    From FCMFrame with Apache License 2.0 6 votes vote down vote up
public void stateChanged(ChangeEvent e) {
	JSlider s1 = (JSlider) e.getSource();
	String name = label.getText();
	if(!"".equals(name)) {
		name = name.substring(0, name.indexOf(":"));
	}
	if("分类数".equals(name)) {
		clusternum = s1.getValue();
	} else if("迭代次数".equals(name)) {
		iternum = s1.getValue();
	} else if("指数".equals(name)) {
		exponent = s1.getValue();
	} else if("程序执行速度".equals(name)) {
		speed = s1.getValue();
	} else {
		JOptionPane.showMessageDialog(null, "参数有误", "提醒", JOptionPane.ERROR_MESSAGE);
	}
	label.setText(name+":"+s1.getValue());
}
 
Example 3
Source File: ShowcaseDemo.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Add a popover labeling a slider.
 * 
 * @param suffix
 *            the text to append after the numeric value, such as "%" or
 *            " pixels".
 */
protected void addSliderPopover(JSlider slider, final String suffix) {
	JPopover p = new JPopover<JToolTip>(slider, new JToolTip(), false) {

		@Override
		protected void doRefreshPopup() {
			JSlider js = (JSlider) getOwner();
			int v = js.getValue();
			String newText;
			if (v == 1 && suffix.startsWith(" ") && suffix.endsWith("s")) {
				newText = v + suffix.substring(0, suffix.length() - 1);
			} else {
				newText = v + suffix;
			}
			getContents().setTipText(newText);

			// this is only because we have the JToolTipDemo so
			// colors might change:
			getContents().updateUI();
			getContents().setBorder(null);
		}
	};
	p.setTarget(new SliderThumbPopupTarget(slider));
}
 
Example 4
Source File: FilterPanel.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Listen for changes from the slider
 */
@Override
public void stateChanged(ChangeEvent e) {
	JSlider source = (JSlider)e.getSource();
    if (!source.getValueIsAdjusting()) {
    	
    	if (source == freqSlider) {
    		int freq = (int)source.getValue();
    		Config.filterFrequency = freq;
    		Config.save();
    	} else {
    		int len = (int)source.getValue();
    		Config.filterLength = len;
    		Config.save();
    	}
    }
}
 
Example 5
Source File: SliderTrackPainter.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @param g
 * @param c
 * @param width
 * @param height
 */
private void paintValueTrack(Graphics2D g, JComponent c, int width, int height) {
      JSlider slider = (JSlider) c;
      int orientation = slider.getOrientation();
      double trackLength = slider.getMaximum()-slider.getMinimum();
      double percentFilled = (slider.getValue()-slider.getMinimum()) / trackLength;
      if ( "LogarithmicJSlider".equals( c.getClass().getSimpleName() ) ) {
          percentFilled = (Math.log((slider.getValue()))-Math.log(slider.getMinimum())) / 
          ((double) Math.log(slider.getMaximum()) - (double) Math.log(slider.getMinimum()));
      }
      if (percentFilled > 0) {
          Shape s = getValueShape(c, width, height, orientation, percentFilled);
          g.setPaint(getValuePaint(s));
          g.fill(s);
      }
}
 
Example 6
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void stateChanged(ChangeEvent e) {
  JComponent component = (JComponent) e.getSource();
  TestbedSetting setting = (TestbedSetting) component.getClientProperty(SETTING_TAG);

  switch (setting.constraintType) {
    case BOOLEAN:
      JCheckBox box = (JCheckBox) e.getSource();
      setting.enabled = box.isSelected();
      break;
    case RANGE:
      JSlider slider = (JSlider) e.getSource();
      setting.value = slider.getValue();
      JLabel label = (JLabel) slider.getClientProperty(LABEL_TAG);
      label.setText(setting.name + ": " + setting.value);
      break;
  }
  model.getPanel().grabFocus();
}
 
Example 7
Source File: ViewUtils.java    From GIFKR with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static JPanel createLabelField(String preText, String postText, JSlider s) {
	JPanel p = new JPanel();

	JSpinner spin = new JSpinner(new SpinnerNumberModel(s.getValue(), s.getMinimum(), s.getMaximum(), 1));
	spin.addChangeListener(ce -> {s.setValue((Integer) spin.getValue());});
	p.add(new JLabel(preText));
	p.add(spin);
	p.add(new JLabel(postText));

	return p;
}
 
Example 8
Source File: PaddingInfo.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * This makes some visual changes to the component and its children. Shortly
 * after calling this method, the <code>restore()</code> method needs to be
 * called.
 */
private static void prep(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		if (jc.isOpaque()) {
			jc.setOpaque(false);
			jc.putClientProperty(USED_TO_BE_OPAQUE, Boolean.TRUE);
		}

		Dimension preferredSize = c.getPreferredSize();
		if (greaterThanOrEqualTo(jc.getSize(), preferredSize) == false) {
			jc.putClientProperty(SIZE, c.getSize());
			jc.setSize(preferredSize);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = s.getChangeListeners();
		int mid = (s.getMinimum() + s.getMaximum()) / 2;
		if (mid != s.getValue()) {
			s.putClientProperty(CHANGE_LISTENERS, listeners);
			for (int a = 0; a < listeners.length; a++) {
				s.removeChangeListener(listeners[a]);
			}
			s.putClientProperty(SLIDER_VALUE, new Integer(s.getValue()));
			s.setValue(mid);
		}
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			prep(c2.getComponent(a));
		}
	}
	if (c.isValid() == false)
		c.validate();
}
 
Example 9
Source File: SoundSettings.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
	JSlider source = (JSlider) e.getSource();
	int value = source.getValue();
	ClientSingletonRepository.getSound().changeVolume(Numeric.intToFloat(value, 100.0f));
	WtWindowManager.getInstance().setProperty(VOLUME_PROPERTY + "master", Integer.toString(value));
}
 
Example 10
Source File: SoundSettings.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
	JSlider source = (JSlider) e.getSource();
	int value = source.getValue();
	group.changeVolume(Numeric.intToFloat(value, 100f));
	WtWindowManager.getInstance().setProperty(VOLUME_PROPERTY + groupName, Integer.toString(value));
}
 
Example 11
Source File: TripoliSessionRawDataView.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
    JSlider source = (JSlider) e.getSource();
    if (!source.getValueIsAdjusting()) {
        int value = source.getValue();
        if (FRACTION_LAYOUT_VIEW_STYLE.equals(FractionLayoutViewStylesEnum.SESSION)) {
            sessionModelWidth = value;
            SAVED_SessionModelWidth = value;
        } else {
            dataModelWidth = value;
            if (tripoliSession.getFractionationTechnique().compareTo(FractionationTechniquesEnum.INTERCEPT) == 0) {
                if (FRACTION_LAYOUT_VIEW_STYLE.equals(FractionLayoutViewStylesEnum.OVERLAY)) {
                    SAVED_InterceptOverlayModelWidth = value;
                } else {
                    SAVED_InterceptNormalModelWidth = value;
                }
            } else if (FRACTION_LAYOUT_VIEW_STYLE.equals(FractionLayoutViewStylesEnum.OVERLAY)) {
                SAVED_DownholeOverlayModelWidth = value;
            } else {
                SAVED_DownholeNormalModelWidth = value;
            }
        }
        if (!isZoomSlidersIndependent()) {
            theOtherSlider.setValue(value);
        }
        ((AbstractRawDataView) sampleSessionDataView).refreshPanel(true, false);
        sessionAnalysisWorkflowManager.revalidateScrollPane();
    }
}
 
Example 12
Source File: SimulateControlPanel.java    From VanetSim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * An implemented <code>ChangeListener</code> for the zooming slider which performs the necessary actions.
 * 
 * @param e a <code>ChangeEvent</code>
 */	
public void stateChanged(ChangeEvent e) {		
	JSlider source = (JSlider)e.getSource();
	if (!source.getValueIsAdjusting()) {	// only perform action when mouse button is released!
		int value = source.getValue();
		double scale = Math.exp(value/50.0)/1000;
		if(dontReRenderZoom_) dontReRenderZoom_ = false;
		else{
			Renderer.getInstance().setMapZoom(scale);
			ReRenderManager.getInstance().doReRender();
		}
	}
}
 
Example 13
Source File: AngleSliderUI.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0.create();
	JSlider slider = (JSlider) c;
	if (slider.isOpaque()) {
		g.setColor(slider.getBackground());
		g.fillRect(0, 0, slider.getWidth(), slider.getHeight());
	}

	if (slider.isEnabled() == false) {
		g.setComposite(
				AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
	}

	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);

	// paint a circular shadow
	/*
	 * g.translate(2,2); g.setColor(new Color(0,0,0,20)); g.fill(new
	 * Ellipse2D
	 * .Double(dial.getX()-2,dial.getY()-2,dial.getWidth()+4,dial.getHeight
	 * ()+4)); g.setColor(new Color(0,0,0,40)); g.fill(new
	 * Ellipse2D.Double(dial
	 * .getX()-1,dial.getY()-1,dial.getWidth()+2,dial.getHeight()+2));
	 * g.setColor(new Color(0,0,0,80)); g.fill(new
	 * Ellipse2D.Double(dial.getX
	 * ()-0,dial.getY()-0,dial.getWidth()+0,dial.getHeight()+0));
	 * g.translate(-2,-2);
	 */

	Data data = getData(slider);
	if (slider.hasFocus()) {
		PlafPaintUtils.paintFocus(g, data.dial, 3);
	}

	// g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
	// RenderingHints.VALUE_ANTIALIAS_OFF);

	Shape oldClip = g.getClip();
	g.clip(data.dial);
	int d = data.mousePressed ? -50 : 0;
	for (int a = 0; a < 5; a++) {
		float f = (a) / 4f;
		g.setColor(tweenColor(new Color(150 + d, 150 + d, 150 + d),
				new Color(212 + d, 212 + d, 212 + d), f));
		g.translate(0, a);
		g.fill(data.dial);
		g.translate(0, -a);
	}
	g.setClip(oldClip);

	g.setColor(border);
	g.draw(data.dial);

	float angle = (float) (slider.getValue() - slider.getMinimum())
			/ (((float) (slider.getMaximum() - slider.getMinimum())));
	angle = angle * (float) (2 * Math.PI);

	float centerX = (float) data.dial.getCenterX();
	float centerY = (float) data.dial.getCenterY();
	float radius = (float) Math.min(centerX - data.dial.getX(),
			centerY - data.dial.getY()) - 6;
	float x = (float) (centerX + radius * Math.cos(angle));
	float y = (float) (centerY + radius * Math.sin(angle));
	Ellipse2D knob = new Ellipse2D.Float(x - 2, y - 2, 4, 4);
	if (slider.hasFocus()) {
		g.setColor(Color.gray);
		g.fill(knob);
		g.setColor(Color.darkGray);
		g.draw(knob);
	} else {
		g.setColor(new Color(180, 180, 180));
		g.fill(knob);
		g.setColor(border);
		g.draw(knob);
	}

	g.dispose();
}