📄 aqualayoutstyle.java
字号:
break;
case SwingConstants.EAST :
result -= visualMargin1.right + visualMargin2.left;
break;
case SwingConstants.WEST :
result -= visualMargin1.left + visualMargin2.right;
default :
break;
}
}
// Aqua does not support negative gaps, because all its components are
// opaque
return Math.max(0, result);
}
private Insets getPreferredGap(JComponent component, int type, int sizeStyle) {
Map gapMap;
switch (type) {
case INDENT :
gapMap = INDENT_GAPS;
break;
case RELATED :
gapMap = RELATED_GAPS;
break;
case UNRELATED :
default :
gapMap = UNRELATED_GAPS;
break;
}
String uid = component.getUIClassID();
String style = null;
// == is ok here as Strings from Swing get interned, if for some reason
// need .equals then must deal with null.
if (uid == "ButtonUI" || uid =="ToggleButtonUI") {
style = (String) component.getClientProperty("JButton.buttonType");
} else if (uid =="ProgressBarUI") {
style = (((JProgressBar) component).getOrientation() ==
JProgressBar.HORIZONTAL) ? "horizontal" : "vertical";
} else if (uid == "SliderUI") {
style = (((JSlider) component).getOrientation()
== JProgressBar.HORIZONTAL) ? "horizontal" : "vertical";
} else if (uid == "TabbedPaneUI") {
switch (((JTabbedPane) component).getTabPlacement()) {
case JTabbedPane.TOP :
style = "top";
break;
case JTabbedPane.LEFT :
style = "left";
break;
case JTabbedPane.BOTTOM :
style = "bottom";
break;
case JTabbedPane.RIGHT :
style = "right";
break;
}
} else if (uid == "ComboBoxUI") {
style = ((JComboBox) component).isEditable() ? "editable" : "uneditable";
}
return getInsets(gapMap, uid, style, sizeStyle);
}
/**
* 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) {
int result;
int sizeStyle = Math.min(getSizeStyle(component), getSizeStyle(parent));
// Compute gap
Insets gap = getContainerGap(parent, sizeStyle);
switch (position) {
case SwingConstants.NORTH :
result = gap.top;
break;
case SwingConstants.SOUTH :
result = gap.bottom;
break;
case SwingConstants.EAST :
result = gap.right;
break;
case SwingConstants.WEST :
default :
result = gap.left;
break;
}
// Compensate for visual margin
Insets visualMargin = getVisualMargin(component);
switch (position) {
case SwingConstants.NORTH :
result -= visualMargin.top;
break;
case SwingConstants.SOUTH :
result -= visualMargin.bottom;
// Radio buttons in Quaqua are 1 pixel too high, in order
// to align their baselines with other components, when no
// baseline aware layout manager is used.
if (component instanceof JRadioButton) {
result--;
}
break;
case SwingConstants.EAST :
result -= visualMargin.left;
break;
case SwingConstants.WEST :
result -= visualMargin.right;
default :
break;
}
// Aqua does not support negative gaps, because all its components are
// opaque
return Math.max(0, result);
}
private Insets getContainerGap(Container container, int sizeStyle) {
String uid;
if (container instanceof JComponent) {
uid = ((JComponent) container).getUIClassID();
} else if (container instanceof Dialog) {
uid = "Dialog";
} else if (container instanceof Frame) {
uid = "Frame";
} else if (container instanceof java.applet.Applet) {
uid = "Applet";
} else if (container instanceof Panel) {
uid = "Panel";
} else {
uid = "default";
}
// FIXME insert style code here for JInternalFrame with palette style
return getInsets(CONTAINER_GAPS, uid, null, sizeStyle);
}
private Insets getInsets(Map gapMap, String uid, String style,
int sizeStyle) {
if (uid == null) {
uid = "default";
}
ComponentInsets componentInsets = (ComponentInsets)gapMap.get(uid);
if (componentInsets == null) {
componentInsets = (ComponentInsets)gapMap.get("default");
if (componentInsets == null) {
return EMPTY_INSETS;
}
} else if (style != null) {
ComponentInsets subInsets = componentInsets.getSubinsets(style);
if (subInsets != null) {
componentInsets = subInsets;
}
}
return componentInsets.getInsets(sizeStyle);
}
private Insets getVisualMargin(JComponent component) {
String uid = component.getUIClassID();
String style = null;
if (uid == "ButtonUI" || uid == "ToggleButtonUI") {
style = (String) component.getClientProperty("JButton.buttonType");
} else if (uid == "ProgressBarUI") {
style = (((JProgressBar) component).getOrientation()
== JProgressBar.HORIZONTAL) ? "horizontal" :
"vertical";
} else if (uid == "SliderUI") {
style = (((JSlider) component).getOrientation() ==
JProgressBar.HORIZONTAL) ? "horizontal"
: "vertical";
} else if (uid == "TabbedPaneUI") {
switch (((JTabbedPane) component).getTabPlacement()) {
case JTabbedPane.TOP :
style = "top";
break;
case JTabbedPane.LEFT :
style = "left";
break;
case JTabbedPane.BOTTOM :
style = "bottom";
break;
case JTabbedPane.RIGHT :
style = "right";
break;
}
}
Insets gap = getInsets(VISUAL_MARGINS, uid, style, 0);
// Take into account different positions of the button icon
if (uid == "RadioButtonUI" || uid == "CheckBoxUI") {
switch (((AbstractButton) component).getHorizontalTextPosition()) {
case SwingConstants.RIGHT :
gap = new Insets(gap.top, gap.right, gap.bottom, gap.left);
break;
case SwingConstants.CENTER :
gap = new Insets(gap.top, gap.right, gap.bottom, gap.right);
break;
/*
case SwingConstants.LEFT :
break;
*/
default:
gap = new Insets(gap.top, gap.left, gap.bottom, gap.right);
}
if (component.getBorder() instanceof EmptyBorder) {
gap.left -= 2;
gap.right -= 2;
gap.top -= 2;
gap.bottom -= 2;
}
}
return gap;
}
/**
* Returns the size style of a specified component.
*
* @return REGULAR, SMALL or MINI.
*/
private int getSizeStyle(Component c) {
// Aqua components have a different style depending on the
// font size used.
// 13 Point = Regular
// 11 Point = Small
// 9 Point = Mini
if (c == null) {
return REGULAR;
}
Font font = c.getFont();
if (font == null) {
return REGULAR;
}
int fontSize = font.getSize();
return (fontSize >= 13) ? REGULAR : ((fontSize > 9) ? SMALL : MINI);
}
/**
* ComponentInsets is used to manage the Insets for a specific Component
* type. Each ComponentInsets may also have children (sub) ComponentInsets.
* Subinsets are used to represent different styles a component may have.
* For example, a Button may not a set of insets, as well as insets when
* it has a style of metal.
*/
private static class ComponentInsets {
// Map<String,ComponentInsets>
private Map children;
private Insets[] insets;
public ComponentInsets() {
}
public ComponentInsets(Insets[] insets) {
this.insets = insets;
}
public void setInsets(Insets[] insets) {
this.insets = insets;
}
public Insets[] getInsets() {
return insets;
}
public Insets getInsets(int size) {
if (insets == null) {
return EMPTY_INSETS;
}
return insets[size];
}
void addSubinsets(String subkey, ComponentInsets subinsets) {
if (children == null) {
children = new HashMap(5);
}
children.put(subkey, subinsets);
}
ComponentInsets getSubinsets(String subkey) {
return (children == null) ? null :
(ComponentInsets)children.get(subkey);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -