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

The following examples show how to use javax.swing.JSlider#putClientProperty() . 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: AngleSliderUI.java    From pumpernickel with MIT License 6 votes vote down vote up
/** Return the Data object associated with a slider. */
protected Data getData(JSlider slider) {
	Data data = (Data) slider.getClientProperty(DATA_KEY);
	if (data == null) {
		data = new Data();
		slider.putClientProperty(DATA_KEY, data);
	}

	Dimension size = new Dimension(slider.getWidth(), slider.getHeight());
	if (!Objects.equals(size, data.lastSize)) {
		data.lastSize = size;
		calculateGeometry(slider);
	}

	return data;
}
 
Example 2
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 3
Source File: PaddingInfo.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Should be called shortly after <code>prep()</code>.
 */
private static void restore(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		Boolean b = (Boolean) jc.getClientProperty(USED_TO_BE_OPAQUE);
		if (b != null && b.booleanValue()) {
			jc.setOpaque(true);
		}
		jc.putClientProperty(USED_TO_BE_OPAQUE, null);

		Dimension d = (Dimension) jc.getClientProperty(SIZE);
		if (d != null) {
			jc.setSize(d);
			jc.putClientProperty(SIZE, null);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = (ChangeListener[]) s
				.getClientProperty(CHANGE_LISTENERS);
		Integer i = (Integer) s.getClientProperty(SLIDER_VALUE);
		if (i != null)
			s.setValue(i.intValue());
		if (listeners != null) {
			for (int a = 0; a < listeners.length; a++) {
				s.addChangeListener(listeners[a]);
			}
		}
		s.putClientProperty(SLIDER_VALUE, null);
		s.putClientProperty(CHANGE_LISTENERS, null);
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			restore(c2.getComponent(a));
		}
	}
}
 
Example 4
Source File: AngleSliderUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	JSlider slider = (JSlider) c;
	slider.addFocusListener(focusListener);
	slider.addMouseListener(mouseListener);
	slider.addMouseMotionListener(mouseListener);
	RepaintChangeListener rcl = new RepaintChangeListener(c);
	slider.getModel().addChangeListener(rcl);
	slider.putClientProperty(REPAINT_CHANGE_LISTENER_KEY, rcl);
	slider.addKeyListener(keyListener);
	slider.setFocusable(true);
	slider.setRequestFocusEnabled(true);
	calculateGeometry((JSlider) c);
}
 
Example 5
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addSettings(JPanel argPanel, TestbedSettings argSettings, SettingType argIgnore) {
  for (TestbedSetting setting : argSettings.getSettings()) {
    if (setting.settingsType == argIgnore) {
      continue;
    }
    switch (setting.constraintType) {
      case RANGE:
        JLabel text = new JLabel(setting.name + ": " + setting.value);
        JSlider slider = new JSlider(setting.min, setting.max, setting.value);
        slider.setMaximumSize(new Dimension(200, 20));
        slider.addChangeListener(this);
        slider.setName(setting.name);
        slider.putClientProperty(SETTING_TAG, setting);
        slider.putClientProperty(LABEL_TAG, text);
        argPanel.add(text);
        argPanel.add(slider);
        break;
      case BOOLEAN:
        JCheckBox checkbox = new JCheckBox(setting.name);
        checkbox.setSelected(setting.enabled);
        checkbox.addChangeListener(this);
        checkbox.putClientProperty(SETTING_TAG, setting);
        argPanel.add(checkbox);
        break;
    }
  }
}