⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsframeborder.java

📁 Java自定义窗体JsFrame。简介见:http://jason0086.spaces.live.com/Blog/cns!A797D0C5C0C13C92!518.entry
💻 JAVA
字号:
package com.hfkj.jsframe.border;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;

import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;

import com.hfkj.jsframe.component.JsComponent;
import com.hfkj.jsframe.frame.JsFrameLayout;
import com.hfkj.jsframe.layout.JsLayoutManager;

/**
 * The <code>JsFrameBorder</code> class is for the integration of the operations
 * on the eight border blocks indicated by the following constraints in the <code>JsFrame</code>:
 * <p>
 * <ul>
 * <li><code>NORTHWEST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The northwest portion of the layout for the <code>JsFrame</code>.
 * <li><code>NORTH</code>(defined in <code>JsFrameBorderBlock</code>):
 * the north portion of the layout for the <code>JsFrame</code>.
 * <li><code>NORTHEAST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The northeast portion of the layout for the <code>JsFrame</code>.
 * <li><code>WEST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The west portion of the layout for the <code>JsFrame</code>.
 * <li><code>EAST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The east portion of the layout for the <code>JsFrame</code>.
 * <li><code>SOUTHWEST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The southwest portion of the layout for the <code>JsFrame</code>.
 * <li><code>SOUTH</code>(defined in <code>JsFrameBorderBlock</code>):
 * The south portion of the layout for the <code>JsFrame</code>.
 * <li><code>SOUTHEAST</code>(defined in <code>JsFrameBorderBlock</code>):
 * The southeast portion of the layout for the <code>JsFrame</code>.
 * </ul>
 * <p>
 * If you just want to operate some of the above border blocks, you should first get it 
 * from the layout of the <code>JsFrame</code> by doing the following:
 * <pre>
 * JsFrameLayout layout = (JsFrameLayout) jsframe.getLayout();
 * Component component = layout.getLayoutComponent(JsFrameLayout.NORTHWEST);
 * </pre>
 * or doing the following:
 * <pre>
 * JsFrameLayout layout = (JsFrameLayout) jsframe.getLayout();
 * JsComponent jscomponent = (JsComponent) layout.getLayoutComponent(JsFrameLayout.NORTHWEST);
 * </pre>
 * 
 * @see JsFrameBorderBlock
 * @see com.hfkj.jsframe.frame.JsFrame
 * @see com.hfkj.jsframe.component.JsComponent
 * 
 * @version 1.0 01/05/09
 * @author Jason (MSN:www.jason0086.com@hotmail.com)
 */
public class JsFrameBorder {
	
	/**
	 * The root frame.
	 */
	protected Frame rootFrm = null;
	
	/**
	 * The preferred width.
	 */
	private int preferredWidthInt = 10;
	
	/**
	 * Constructs a js frame border for the frame specified by the given frame.
	 * @param rootFrame the frame which is the host of this <code>JsFrameBorder</code>
	 */
	@SuppressWarnings("static-access")
	public JsFrameBorder(Frame rootFrame) {
		this.rootFrm = rootFrame;
		this.setupBorder();
		MetalLookAndFeel lookMlaf = (MetalLookAndFeel) UIManager.getLookAndFeel();
    	this.setColor(lookMlaf.getFocusColor(), lookMlaf.getMenuBackground());
    	this.setPreferredWidth(this.preferredWidthInt);
    	this.setResizable(true);
	}
	
	/**
	 * Change the icon and string associated with the look and feel.
	 */
	@SuppressWarnings("static-access")
	public void changeLookAndFeel() {
		MetalLookAndFeel lookMlaf = (MetalLookAndFeel) UIManager.getLookAndFeel();
    	this.setColor(lookMlaf.getFocusColor(), lookMlaf.getMenuBackground());
	}
	
	/**
	 * Returns the mask shape.
	 * @return the mask shape
	 */
	public Shape getMaskShape() {
		int widthInt = 0;
		int heightInt = 0;
		if (this.rootFrm.getExtendedState() == Frame.MAXIMIZED_BOTH) {
			widthInt = this.rootFrm.getMaximizedBounds().width;
			heightInt = this.rootFrm.getMaximizedBounds().height;
		}
		else {
			widthInt = this.rootFrm.getWidth();
			heightInt = this.rootFrm.getHeight();
		}
		return new RoundRectangle2D.Float(0, 
											0, 
											widthInt, 
											heightInt, 
											this.preferredWidthInt + (this.preferredWidthInt >> 1), 
											this.preferredWidthInt + (this.preferredWidthInt >> 1));
	}

	/**
	 * Sets the color for the border.
	 * @param outsideColor the outside color
	 * @param insideColor the inside color
	 */
    public void setColor(Color outsideColor, Color insideColor) {
    	JsLayoutManager xJlm = (JsLayoutManager) this.rootFrm.getLayout();
    	// set the UI for northwest portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.NORTHWEST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.NORTHWEST)
	    	);
    	// set the UI for north portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.NORTH)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.NORTH)
	    	);
    	// set the UI for northeast portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.NORTHEAST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.NORTHEAST)
	    	);
    	// set the UI for west portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.WEST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.WEST)
	    	);
    	// set the UI for east portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.EAST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.EAST)
	    	);
    	// set the UI for southwest portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.SOUTHWEST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.SOUTHWEST)
	    	);
    	// set the UI for south portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.SOUTH)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.SOUTH)
	    	);
    	// set the UI for southeast portion of this frame
    	((JsComponent) xJlm.getLayoutComponent(JsFrameLayout.SOUTHEAST)).setUI(
	    		new JsFrameBorderBlockUI(outsideColor, insideColor, JsFrameBorderBlock.SOUTHEAST)
	    	);
    }

	/**
	 * Sets the preferred width for the border.
	 * @param width the preferred width for the border
	 */
    public void setPreferredWidth(int width) {
    	JsLayoutManager xJlm = (JsLayoutManager) this.rootFrm.getLayout();
    	xJlm.getLayoutComponent(JsFrameLayout.NORTHWEST).setPreferredSize(new Dimension(width, width));
    	xJlm.getLayoutComponent(JsFrameLayout.NORTH).setPreferredSize(new Dimension(0, width));
    	xJlm.getLayoutComponent(JsFrameLayout.NORTHEAST).setPreferredSize(new Dimension(width, width));
    	xJlm.getLayoutComponent(JsFrameLayout.WEST).setPreferredSize(new Dimension(width, 0));
    	xJlm.getLayoutComponent(JsFrameLayout.EAST).setPreferredSize(new Dimension(width, 0));
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTHWEST).setPreferredSize(new Dimension(width, width));
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTH).setPreferredSize(new Dimension(0, width));
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTHEAST).setPreferredSize(new Dimension(width, width));
    }
    
    /**
     * Sets the resizabled state of the border.
     * @param resizabled the resizabled state of the border
     */
    public void setResizable(boolean resizabled) {
    	JsLayoutManager xJlm = (JsLayoutManager) this.rootFrm.getLayout();
    	xJlm.getLayoutComponent(JsFrameLayout.NORTHWEST).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.NORTH).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.NORTHEAST).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.WEST).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.EAST).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTHWEST).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTH).setEnabled(resizabled);
    	xJlm.getLayoutComponent(JsFrameLayout.SOUTHEAST).setEnabled(resizabled);
    }
    
    private void setupBorder() {
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.NORTHWEST, this.rootFrm), JsFrameLayout.NORTHWEST);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.NORTH, this.rootFrm), JsFrameLayout.NORTH);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.NORTHEAST, this.rootFrm), JsFrameLayout.NORTHEAST);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.WEST, this.rootFrm), JsFrameLayout.WEST);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.EAST, this.rootFrm), JsFrameLayout.EAST);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.SOUTHWEST, this.rootFrm), JsFrameLayout.SOUTHWEST);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.SOUTH, this.rootFrm), JsFrameLayout.SOUTH);
    	this.rootFrm.add(new JsFrameBorderBlock(JsFrameBorderBlock.SOUTHEAST, this.rootFrm), JsFrameLayout.SOUTHEAST);
    }
	

}

⌨️ 快捷键说明

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