javax.swing.JButton#getClientProperty ( )源码实例Demo

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

源代码1 项目: pumpernickel   文件: DialogFooter.java
/**
 * Finds a certain type of button, if it is available.
 * 
 * @param buttonType
 *            of the options in this class (such as YES_OPTION or
 *            CANCEL_OPTION)
 * @return the button that maps to that option, or null if no such button
 *         was found.
 */
public JButton getButton(int buttonType) {
	for (int a = 0; a < getComponentCount(); a++) {
		if (getComponent(a) instanceof JButton) {
			JButton button = (JButton) getComponent(a);
			Object value = button.getClientProperty(PROPERTY_OPTION);
			int intValue = -1;
			if (value instanceof Number)
				intValue = ((Number) value).intValue();
			if (intValue == buttonType)
				return button;
		}
	}
	return null;
}
 
源代码2 项目: the-one   文件: NodeChooser.java
/**
 * Action listener method for buttons and node set chooser
 */
public void actionPerformed(ActionEvent e) {
	if (e.getSource() instanceof JButton) {
		JButton source = (JButton)e.getSource();
		DTNHost host = (DTNHost)source.getClientProperty(HOST_KEY);
		gui.setFocus(host);
	}
	else if (e.getSource() == this.groupChooser) {
		setNodes(groupChooser.getSelectedIndex() * MAX_NODE_COUNT);
	}
	else if (e.getSource() == this.refreshTimer) {
		updateShownNodes();
	}
}
 
源代码3 项目: the-one   文件: EventLogPanel.java
/**
 * Action listener for log entry (host & message) buttons
 */
public void actionPerformed(ActionEvent e) {
	JButton source = (JButton)e.getSource();

	if (source.getClientProperty(HOST_PROP) != null) {
		// button was a host button -> focus it on GUI
		gui.setFocus((DTNHost)source.getClientProperty(HOST_PROP));
	}
	else if (source.getClientProperty(MSG_PROP) != null) {
		// was a message button -> show information about the message
		Message m = (Message)source.getClientProperty(MSG_PROP);
		gui.getInfoPanel().showInfo(m);
	}
}
 
源代码4 项目: pumpernickel   文件: CollapsibleContainer.java
protected LayoutBlueprint(boolean initialPermitLocked) {
	super(ANIMATION_DURATION, 1F);
	this.initialPermitLocked = initialPermitLocked;
	Insets insets = getInsets();
	int height = getHeight() - insets.top - insets.bottom;

	int remainingHeight = height;

	float totalVerticalWeight = 0;
	Map<JComponent, Number> verticalWeightMap = new HashMap<JComponent, Number>();

	for (int a = 0; a < sections.size(); a++) {
		Section section = sections.get(a);
		JPanel body = section.getBody();
		JButton header = getHeader(section);

		Boolean collapsed = (Boolean) header
				.getClientProperty(COLLAPSED);
		if (collapsed == null)
			collapsed = Boolean.FALSE;
		if (!header.isVisible())
			collapsed = true;

		components.add(header);
		components.add(body);

		if (header.isVisible())
			visibleComponents.add(header);
		if ((!collapsed))
			visibleComponents.add(body);

		Number n = (Number) section.getProperty(VERTICAL_WEIGHT);
		if (n == null)
			n = 0;
		if (visibleComponents.contains(body)) {
			totalVerticalWeight += n.floatValue();
			if (n.floatValue() != 0)
				verticalWeightMap.put(body, n);
		}

		if (visibleComponents.contains(header)) {
			Dimension headerSize = header.getPreferredSize();
			heightMap.put(header, headerSize.height);
			remainingHeight -= headerSize.height;
		} else {
			heightMap.put(header, 0);
		}
		originalHeightMap.put(header, header.getHeight());

		if (visibleComponents.contains(body) && n.floatValue() == 0) {
			Dimension bodySize = body.getPreferredSize();
			heightMap.put(body, bodySize.height);
			remainingHeight -= bodySize.height;
		} else {
			heightMap.put(body, 0);
		}
		originalHeightMap.put(body, body.getHeight());
	}

	if (remainingHeight > 0 && totalVerticalWeight > 0) {
		// divide the remaining height based on the vertical weight
		int designatedHeight = 0;
		JComponent lastC = null;
		for (JComponent jc : verticalWeightMap.keySet()) {
			Number weight = verticalWeightMap.get(jc);
			int i = (int) (weight.floatValue() / totalVerticalWeight * remainingHeight);
			heightMap.put(jc, heightMap.get(jc) + i);
			designatedHeight += i;
			lastC = jc;
		}

		// due to rounding error, we may have a few extra pixels:
		int remainingPixels = remainingHeight - designatedHeight;
		// tack them on to someone. anyone.
		heightMap.put(lastC, heightMap.get(lastC) + remainingPixels);
	}
}