jnborderlayout.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 224 行

JAVA
224
字号
/*
 * $Id: JNBorderLayout.java,v 1.2 2004/02/28 09:20:54 epr Exp $
 */
package org.jnode.wt.layouts;

import java.awt.Dimension;
import java.awt.Insets;


public class JNBorderLayout implements JNLayoutManager {
    public static String CENTER = "CENTER";
    public static String EAST = "EAST";
    public static String NORTH = "NORTH";
    public static String SOUTH = "SOUTH";
    public static String WEST = "WEST";

    private org.jnode.wt.components.JNComponent north;
    private org.jnode.wt.components.JNComponent west;
    private org.jnode.wt.components.JNComponent east;
    private org.jnode.wt.components.JNComponent south;
    private org.jnode.wt.components.JNComponent center;


    private int hgap;
    private int vgap;

    /**
     * JNBorderLayout constructor comment.
     */
    public JNBorderLayout() {
        super();
    }

    /**
     * addLayoutComponent method comment.
     */
    public void addLayoutComponent(String name, org.jnode.wt.components.JNComponent component) {
        if (CENTER.equals(name)) {
            center = component;
            return;
        }
        if (NORTH.equals(name)) {
            north = component;
            return;
        }
        if (SOUTH.equals(name)) {
            south = component;
            return;
        }
        if (EAST.equals(name)) {
            east = component;
            return;
        }
        if (WEST.equals(name))
            west = component;

    }

    public void layoutContainer(org.jnode.wt.components.JNSimpleContainer container) {
        Insets insets = container.getInsets();
        int top = insets.top;
        int bottom = container.getHeight() - insets.bottom;
        int left = insets.left;
        int right = container.getWidth() - insets.right;

        if (north != null) {
            Dimension d = north.getPreferredSize();
            north.setBounds(left, top, right - left, d.height);
            top += d.height + vgap;
        }
        if (south != null) {
            Dimension d = south.getPreferredSize();
            south.setBounds(left, bottom - d.height, right - left, d.height);
            bottom -= d.height + vgap;
        }
        if (east != null) {
            Dimension d = east.getPreferredSize();
            east.setBounds(right - d.width, top, d.width, bottom - top);
            right -= d.width + hgap;
        }
        if (west != null) {
            Dimension d = west.getPreferredSize();
            west.setBounds(left, top, d.width, bottom - top);
            left += d.width + hgap;
        }
        if (center != null) {
            center.setBounds(left, top, right - left, bottom - top);
        }
    }


    /*
    public void layoutContainer(org.jnode.wt.components.JNSimpleContainer container) {
        Insets insets = container.getInsets();
        int top = insets.top;
        int bottom = container.getHeight() - insets.bottom;
        int left = insets.left;
        int right = container.getWidth() - insets.right;

        if (north != null) {
            Dimension d = north.getSize();
            north.setBounds(left, top, right - left, d.height);
            top += d.height + vgap;
        }
        if (south != null) {
            Dimension d = south.getSize();
            south.setBounds(left, bottom - d.height, right - left, d.height);
            bottom -= d.height + vgap;
        }
        if (east != null) {
            Dimension d = east.getSize();
            east.setBounds(right - d.width, top, d.width, bottom - top);
            right -= d.width + hgap;
        }
        if (west != null) {
            Dimension d = west.getSize();
            west.setBounds(left, top, d.width, bottom - top);
            left += d.width + hgap;
        }
        if (center != null) {
            center.setBounds(left, top, right - left, bottom - top);
        }
    } */


    /**
     * minimumLayoutSize method comment.
     */
    public java.awt.Dimension minimumLayoutSize(org.jnode.wt.components.JNSimpleContainer parent) {
        return null;
    }

    public Dimension preferredLayoutSize(org.jnode.wt.components.JNSimpleContainer container) {
        Dimension dimension = new Dimension(0, 0);

        if (east != null && east.isVisible()) {
            Dimension dimension1 = east.getPreferredSize();
            dimension.width += dimension1.width + hgap;
            dimension.height = Math.max(dimension1.height, dimension.height);
        }
        if (west != null && west.isVisible()) {
            Dimension dimension2 = west.getPreferredSize();
            dimension.width += dimension2.width + hgap;
            dimension.height = Math.max(dimension2.height, dimension.height);
        }
        if (center != null && center.isVisible()) {
            Dimension dimension3 = center.getPreferredSize();
            dimension.width += dimension3.width;
            dimension.height = Math.max(dimension3.height, dimension.height);
        }
        if (north != null && north.isVisible()) {
            Dimension dimension4 = north.getPreferredSize();
            dimension.width = Math.max(dimension4.width, dimension.width);
            dimension.height += dimension4.height + vgap;
        }
        if (south != null && south.isVisible()) {
            Dimension dimension5 = south.getPreferredSize();
            dimension.width = Math.max(dimension5.width, dimension.width);
            dimension.height += dimension5.height + vgap;
        }
        Insets insets = container.getInsets();
        dimension.width += insets.left + insets.right;
        dimension.height += insets.top + insets.bottom;
        return dimension;
    }

    /*
    public Dimension preferredLayoutSize(org.jnode.wt.components.JNSimpleContainer container) {
        Dimension dimension = new Dimension(0, 0);

        if (east != null && east.isVisible()) {
            Dimension dimension1 = east.getSize();
            dimension.width += dimension1.width + hgap;
            dimension.height = Math.max(dimension1.height, dimension.height);
        }
        if (west != null && west.isVisible()) {
            Dimension dimension2 = west.getSize();
            dimension.width += dimension2.width + hgap;
            dimension.height = Math.max(dimension2.height, dimension.height);
        }
        if (center != null && center.isVisible()) {
            Dimension dimension3 = center.getSize();
            dimension.width += dimension3.width;
            dimension.height = Math.max(dimension3.height, dimension.height);
        }
        if (north != null && north.isVisible()) {
            Dimension dimension4 = north.getSize();
            dimension.width = Math.max(dimension4.width, dimension.width);
            dimension.height += dimension4.height + vgap;
        }
        if (south != null && south.isVisible()) {
            Dimension dimension5 = south.getSize();
            dimension.width = Math.max(dimension5.width, dimension.width);
            dimension.height += dimension5.height + vgap;
        }
        Insets insets = container.getInsets();
        dimension.width += insets.left + insets.right;
        dimension.height += insets.top + insets.bottom;
        return dimension;
    }
    */

    public void removeLayoutComponent(org.jnode.wt.components.JNComponent component) {
        if (component == center) {
            center = null;
            return;
        }
        if (component == north) {
            north = null;
            return;
        }
        if (component == south) {
            south = null;
            return;
        }
        if (component == east) {
            east = null;
            return;
        }
        if (component == west)
            west = null;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?