putClientProperty ( )源码实例Demo

javax.swing.JSlider#putClientProperty ( )源码实例Demo

下面列出了javax.swing.JSlider#putClientProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pumpernickel   文件: AngleSliderUI.java
/** 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;
}
 
源代码2 项目: pumpernickel   文件: PaddingInfo.java
/**
 * 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();
}
 
源代码3 项目: pumpernickel   文件: PaddingInfo.java
/**
 * 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));
		}
	}
}
 
源代码4 项目: pumpernickel   文件: AngleSliderUI.java
@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);
}
 
源代码5 项目: jbox2d   文件: TestbedSidePanel.java
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;
    }
  }
}