📄 layoutstyle.java
字号:
}
return 6;
}
return 6;
}
throw new IllegalArgumentException("Invalid type");
}
/**
* Returns the amount of space to position a component inside its
* parent.
*
* @param component the <code>Component</code> being positioned
* @param position the position <code>component</code> is being placed
* relative to its parent; one of
* <code>SwingConstants.NORTH</code>,
* <code>SwingConstants.SOUTH</code>,
* <code>SwingConstants.EAST</code> or
* <code>SwingConstants.WEST</code>
* @param parent the parent of <code>component</code>; this may differ
* from the actual parent and may be null
* @return the amount of space to place between the component and specified
* edge
* @throws IllegalArgumentException if <code>position</code> is not
* one of <code>SwingConstants.NORTH</code>,
* <code>SwingConstants.SOUTH</code>,
* <code>SwingConstants.EAST</code> or
* <code>SwingConstants.WEST</code>;
* or <code>component</code> is null
*/
public int getContainerGap(JComponent component, int position,
Container parent) {
if (position != SwingConstants.NORTH &&
position != SwingConstants.SOUTH &&
position != SwingConstants.WEST &&
position != SwingConstants.EAST) {
throw new IllegalArgumentException("Invalid position");
}
if (component == null) {
throw new IllegalArgumentException("Component must be non-null");
}
return 12;
}
/**
* Returns true if <code>component</code> should be treated as a dialog.
*/
boolean isDialog(JComponent component) {
// PENDING: tag the content pane to make this easier to check for
String name = component.getName();
return (name != null && name.endsWith(".contentPane"));
}
/**
* For some look and feels check boxs and radio buttons have an empty
* border around them. Look and feel guidelines generally don't include
* this space. Use this method to subtract this space from the specified
* components.
*
* @param source First component
* @param target Second component
* @param position Position doing layout along.
* @param offset Ideal offset, not including border/margin
* @return offset - border/margin around the component.
*/
int getCBRBPadding(JComponent source, JComponent target, int position,
int offset) {
offset -= getCBRBPadding(source, position);
if (offset > 0) {
offset -= getCBRBPadding(target, flipDirection(position));
}
if (offset < 0) {
return 0;
}
return offset;
}
/**
* For some look and feels check boxs and radio buttons have an empty
* border around them. Look and feel guidelines generally don't include
* this space. Use this method to subtract this space from the specified
* components.
*
* @param source Component
* @param position Position doing layout along.
* @param offset Ideal offset, not including border/margin
* @return offset - border/margin around the component.
*/
int getCBRBPadding(JComponent source, int position, int offset) {
offset -= getCBRBPadding(source, position);
return Math.max(offset, 0);
}
int flipDirection(int position) {
switch(position) {
case SwingConstants.NORTH:
return SwingConstants.SOUTH;
case SwingConstants.SOUTH:
return SwingConstants.NORTH;
case SwingConstants.EAST:
return SwingConstants.WEST;
case SwingConstants.WEST:
return SwingConstants.EAST;
}
assert false;
return 0;
}
private int getCBRBPadding(JComponent c, int position) {
if (c.getUIClassID() == "CheckBoxUI" ||
c.getUIClassID() == "RadioButtonUI") {
Border border = c.getBorder();
if (border instanceof UIResource) {
return getInset(c, position);
}
}
return 0;
}
private int getInset(JComponent c, int position) {
Insets insets = c.getInsets();
switch(position) {
case SwingConstants.NORTH:
return insets.top;
case SwingConstants.SOUTH:
return insets.bottom;
case SwingConstants.EAST:
return insets.right;
case SwingConstants.WEST:
return insets.left;
}
assert false;
return 0;
}
private boolean isLeftAligned(AbstractButton button, int position) {
if (position == SwingConstants.WEST) {
boolean ltr = button.getComponentOrientation().isLeftToRight();
int hAlign = button.getHorizontalAlignment();
return ((ltr && (hAlign == SwingConstants.LEFT ||
hAlign == SwingConstants.LEADING)) ||
(!ltr && (hAlign == SwingConstants.TRAILING)));
}
return false;
}
private boolean isRightAligned(AbstractButton button, int position) {
if (position == SwingConstants.EAST) {
boolean ltr = button.getComponentOrientation().isLeftToRight();
int hAlign = button.getHorizontalAlignment();
return ((ltr && (hAlign == SwingConstants.RIGHT ||
hAlign == SwingConstants.TRAILING)) ||
(!ltr && (hAlign == SwingConstants.LEADING)));
}
return false;
}
private Icon getIcon(AbstractButton button) {
Icon icon = button.getIcon();
if (icon != null) {
return icon;
}
String key = null;
if (button instanceof JCheckBox) {
key = "CheckBox.icon";
} else if (button instanceof JRadioButton) {
key = "RadioButton.icon";
}
if (key != null) {
Object oIcon = UIManager.get(key);
if (oIcon instanceof Icon) {
return (Icon)oIcon;
}
}
return null;
}
/**
* Returns the amount to indent the specified component if it's
* a JCheckBox or JRadioButton. If the component is not a JCheckBox or
* JRadioButton, 0 will be returned.
*/
int getButtonChildIndent(JComponent c, int position) {
if ((c instanceof JRadioButton) || (c instanceof JCheckBox)) {
AbstractButton button = (AbstractButton)c;
Insets insets = c.getInsets();
Icon icon = getIcon(button);
int gap = button.getIconTextGap();
if (isLeftAligned(button, position)) {
return insets.left + icon.getIconWidth() + gap;
} else if (isRightAligned(button, position)) {
return insets.right + icon.getIconWidth() + gap;
}
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -