Java Code Examples for javax.swing.JButton#getClientProperty()

The following examples show how to use javax.swing.JButton#getClientProperty() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: pumpernickel   File: DialogFooter.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
/**
 * 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();
	}
}
 
Example 3
/**
 * 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);
	}
}
 
Example 4
Source Project: pumpernickel   File: CollapsibleContainer.java    License: MIT License 4 votes vote down vote up
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);
	}
}