📄 jsframelayout.java
字号:
/**
* Invalidates the layout,
* indicating that if the layout manager has cached information it should be discarded.
* @param target the container
*/
public void invalidateLayout(Container target) {
// TODO Auto-generated method stub
}
/**
* Determines the maximum size of the target container using this layout manager.
* This method is called when a container calls its getMaximumSize method.
* Most applications do not call this method directly.
* @param target the container
* @return the maximum dimensions for this layout
*/
public Dimension maximumLayoutSize(Container target) {
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
/**
* Lays out the container argument using this js frame layout.
* This method actually reshapes the components in the specify container
* in order to satisfy the constraints of this <code>JsFrameLayout</code> object.
* @param target the container
*/
public void layoutContainer(Container target) {
synchronized (target.getTreeLock()) {
Insets xIns = target.getInsets();
int top = xIns.top;
int bottom = target.getHeight() - xIns.bottom;
int left = xIns.left;
int right = target.getWidth() - xIns.right;
// north line
int northHeight = 0;
int leftTemp = left;
int rightTemp = right;
if (northwest != null) {
Dimension d = northwest.getPreferredSize();
northwest.setBounds(leftTemp, top, d.width, d.height);
leftTemp += d.width;
northHeight = Math.max(northHeight, d.height);
}
if (northeast != null) {
Dimension d = northeast.getPreferredSize();
northeast.setBounds(rightTemp - d.width, top, d.width, d.height);
rightTemp -= d.width;
northHeight = Math.max(northHeight, d.height);
}
if (north != null) {
Dimension d = north.getPreferredSize();
north.setBounds(leftTemp, top, rightTemp - leftTemp, d.height);
northHeight = Math.max(northHeight, d.height);
}
// south line
int southHeight = 0;
leftTemp = left;
rightTemp = right;
if (southwest != null) {
Dimension d = southwest.getPreferredSize();
southwest.setBounds(leftTemp, bottom - d.height, d.width, d.height);
leftTemp += d.width;
southHeight = Math.max(southHeight, d.height);
}
if (southeast != null) {
Dimension d = southeast.getPreferredSize();
southeast.setBounds(rightTemp - d.width, bottom - d.height, d.width, d.height);
rightTemp -= d.width;
southHeight = Math.max(southHeight, d.height);
}
if (south != null) {
Dimension d = south.getPreferredSize();
south.setBounds(leftTemp, bottom - d.height, rightTemp - leftTemp, d.height);
southHeight = Math.max(southHeight, d.height);
}
// center line
leftTemp = left;
rightTemp = right;
int topTemp = top + northHeight;
int bottomTemp = bottom - southHeight;
if (west != null) {
Dimension d = west.getPreferredSize();
west.setBounds(leftTemp, topTemp, d.width, bottomTemp - topTemp);
leftTemp += d.width;
}
if (east != null) {
Dimension d = east.getPreferredSize();
east.setBounds(rightTemp - d.width, topTemp, d.width, bottomTemp - topTemp);
rightTemp -= d.width;
}
if (title != null) {
Dimension d = title.getPreferredSize();
title.setBounds(leftTemp, topTemp, rightTemp - leftTemp, d.height);
topTemp += d.height + vgap;
}
if (titleLine != null) {
Dimension d = titleLine.getPreferredSize();
titleLine.setBounds(leftTemp, topTemp, rightTemp - leftTemp, d.height);
topTemp += d.height + vgap;
}
if (menu != null) {
Dimension d = menu.getPreferredSize();
menu.setBounds(leftTemp, topTemp, rightTemp - leftTemp, d.height);
topTemp += d.height + vgap;
}
if (state != null) {
Dimension d = state.getPreferredSize();
state.setBounds(leftTemp, bottomTemp - d.height, rightTemp - leftTemp, d.height);
bottomTemp -= d.height + vgap;
}
if (content != null) {
content.setBounds(leftTemp, topTemp, rightTemp - leftTemp, bottomTemp - topTemp);
}
}
}
/**
* Determines the minimum size of the target container using this layout manager.
* This method is called when a container calls its getMinimumSize method.
* Most applications do not call this method directly.
* @param target the container
* @return the minimum size of the layout
*/
public Dimension minimumLayoutSize(Container target) {
synchronized (target.getTreeLock()) {
// north line
Dimension northDmn = new Dimension(0, 0);
if (northwest != null) {
Dimension d = northwest.getMinimumSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
if (northeast != null) {
Dimension d = northeast.getMinimumSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
if (north != null) {
Dimension d = north.getMinimumSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
// center line
Dimension centerDmn = new Dimension(0, 0);
if (west != null) {
Dimension d = west.getMinimumSize();
centerDmn.width += d.width;
centerDmn.height = Math.max(centerDmn.height, d.height);
}
if (east != null) {
Dimension d = east.getMinimumSize();
centerDmn.width += d.width;
centerDmn.height = Math.max(centerDmn.height, d.height);
}
int centerWidth = 0;
int centerHeight = 0;
if (title != null) {
Dimension d = title.getMinimumSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeight += d.height + vgap;
}
if (titleLine != null) {
Dimension d = titleLine.getMinimumSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeight += d.height + vgap;
}
if (menu != null) {
Dimension d = menu.getMinimumSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeight += d.height + vgap;
}
if (content != null) {
Dimension d = content.getMinimumSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeight += d.height;
}
if (state != null) {
Dimension d = state.getMinimumSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeight += d.height + vgap;
}
centerDmn.width += centerWidth;
centerDmn.height = Math.max(centerDmn.height, centerHeight);
// south line
Dimension southDmn = new Dimension(0, 0);
if (southwest != null) {
Dimension d = southwest.getMinimumSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
if (southeast != null) {
Dimension d = southeast.getMinimumSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
if (south != null) {
Dimension d = south.getMinimumSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
//
Dimension containerDmn = new Dimension(0, 0);
containerDmn.width = Math.max(Math.max(northDmn.width, centerDmn.width), southDmn.width);
containerDmn.height = northDmn.height + centerDmn.height + vgap + southDmn.height;
Insets xIns = target.getInsets();
containerDmn.width += xIns.left + xIns.right;
containerDmn.height += xIns.top + xIns.bottom;
return containerDmn;
}
}
/**
* Determines the preferred size of the target container using this layout manager,
* based on the components in the container.
* This method is called when a container calls its getPreferredSize method.
* Most applications do not call this method directly.
* @param target the container
* @return the preferred size of the layout
*/
public Dimension preferredLayoutSize(Container target) {
synchronized (target.getTreeLock()) {
// north line
Dimension northDmn = new Dimension(0, 0);
if (northwest != null) {
Dimension d = northwest.getPreferredSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
if (northeast != null) {
Dimension d = northeast.getPreferredSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
if (north != null) {
Dimension d = north.getPreferredSize();
northDmn.width += d.width;
northDmn.height = Math.max(northDmn.height, d.height);
}
// center line
Dimension centerDmn = new Dimension(0, 0);
if (west != null) {
Dimension d = west.getPreferredSize();
centerDmn.width += d.width;
centerDmn.height = Math.max(centerDmn.height, d.height);
}
if (east != null) {
Dimension d = east.getPreferredSize();
centerDmn.width += d.width;
centerDmn.height = Math.max(centerDmn.height, d.height);
}
int centerWidth = 0;
int centerHeiht = 0;
if (title != null) {
Dimension d = title.getPreferredSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeiht += d.height + vgap;
}
if (titleLine != null) {
Dimension d = titleLine.getPreferredSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeiht += d.height + vgap;
}
if (menu != null) {
Dimension d = menu.getPreferredSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeiht += d.height + vgap;
}
if (content != null) {
Dimension d = content.getPreferredSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeiht += d.height;
}
if (state != null) {
Dimension d = state.getPreferredSize();
centerWidth = Math.max(centerWidth, d.width);
centerHeiht += d.height + vgap;
}
centerDmn.width += centerWidth;
centerDmn.height = Math.max(centerDmn.height, centerHeiht);
// south line
Dimension southDmn = new Dimension(0, 0);
if (southwest != null) {
Dimension d = southwest.getPreferredSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
if (southeast != null) {
Dimension d = southeast.getPreferredSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
if (south != null) {
Dimension d = south.getPreferredSize();
southDmn.width += d.width;
southDmn.height = Math.max(southDmn.height, d.height);
}
// container
Dimension containerDmn = new Dimension(0, 0);
containerDmn.width = Math.max(Math.max(northDmn.width, centerDmn.width), southDmn.width);
containerDmn.height = northDmn.height + centerDmn.height + vgap + southDmn.height;
Insets xIns = target.getInsets();
containerDmn.width += xIns.left + xIns.right;
containerDmn.height += xIns.top + xIns.bottom;
return containerDmn;
}
}
/**
* Removes the specify component from this layout.
* This method is called when a container calls its remove or removeAll methods.
* Most applications do not call this method directly.
* @param component the component to be removed from this layout
*/
public void removeLayoutComponent(Component component) {
synchronized (component.getTreeLock()) {
if (component == northwest) {
northwest = null;
}
else if (component == north) {
north = null;
}
else if (component == northeast) {
northeast = null;
}
else if (component == west) {
west = null;
}
else if (component == title) {
title = null;
}
else if (component == titleLine) {
titleLine = null;
}
else if (component == menu) {
menu = null;
}
else if (component == content) {
content = null;
}
else if (component == state) {
state = null;
}
else if (component == east) {
east = null;
}
else if (component == southwest) {
southwest = null;
}
else if (component == south) {
south = null;
}
else if (component == southeast) {
southeast = null;
}
}
}
/**
* Returns the constraints for the specify component.
* @param component the component
* @return the constraints associated with the given component
*/
public Object getConstraints(Component component) {
if (component == northwest) {
return NORTHWEST;
}
else if (component == north) {
return NORTH;
}
else if (component == northeast) {
return NORTHEAST;
}
else if (component == west) {
return WEST;
}
else if (component == title) {
return TITLE;
}
else if (component == titleLine) {
return TITLE_LINE;
}
else if (component == menu) {
return MENU;
}
else if (component == content) {
return CONTENT;
}
else if (component == state) {
return STATE;
}
else if (component == east) {
return EAST;
}
else if (component == southwest) {
return SOUTHWEST;
}
else if (component == south) {
return SOUTH;
}
else if (component == southeast) {
return SOUTHEAST;
}
else {
return null;
}
}
/**
* Returns the representation of this layout.
* @return the string specifying this layout
*/
public String toString() {
return getClass().getName() + "[vgap=" + vgap + "]";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -