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

📄 jsframeborderblockui.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.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.Area;
import java.awt.geom.QuadCurve2D;

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

/**
 * The UI delegate for <code>JsFrameBorderBlock</code>.
 * 
 * @see JsFrameBorderBlock
 * 
 * @version 1.0 01/05/09
 * @author Jason (MSN:www.jason0086.com@hotmail.com)
 */
public class JsFrameBorderBlockUI extends ComponentUI {
	
	/**
	 * The location, which should be one of the following:
	 * <code>NORTHWEST</code>, <code>NORTH</code>, <code>NORTHEAST</code>,
	 * The northeast portion of the layout of the <code>JsFrame</code>.
	 * <code>WEST</code>, <code>EAST</code>, <code>SOUTHWEST</code>,
	 * <code>SOUTH</code>, <code>SOUTHEAST</code>.
	 */
	private int locationInt = 0;
	
	/**
	 * The outside color.
	 */
	private Color outsideClr = null;
	
	/**
	 * The inside color.
	 */
	private Color insideClr = null;
	
	/**
	 * Constructs a js frame border block ui with the gradual changing color and the location.
	 * @param outsideColor the outside color
	 * @param insideColor the inside color
	 * @param location the location indicator for the corresponding <code>JsFrameBorderBlock</code>
	 */
	public JsFrameBorderBlockUI(Color outsideColor, Color insideColor, int location) {
		this.outsideClr = outsideColor;
		this.insideClr = insideColor;
		this.locationInt = location;
	}
	
	/**
	 * Change the icon and string associated with the look and feel.
	 */
	@SuppressWarnings("static-access")
	public void changeLookAndFeel() {
		MetalLookAndFeel lookMlaf = (MetalLookAndFeel) UIManager.getLookAndFeel();
		this.outsideClr = lookMlaf.getFocusColor();
		this.insideClr = lookMlaf.getMenuBackground();
	}
	
	@Override
	public void paint(Graphics gc, JComponent component) {
		Graphics2D xG2d = (Graphics2D) gc;
		GradientPaint xGp = null;
		if ((this.locationInt == JsFrameBorderBlock.NORTH) 
				|| (this.locationInt == JsFrameBorderBlock.WEST) 
				|| (this.locationInt == JsFrameBorderBlock.EAST) 
				|| (this.locationInt == JsFrameBorderBlock.SOUTH)) {
			if (this.locationInt == JsFrameBorderBlock.NORTH) {
				xGp = new GradientPaint(0, 
										0, 
										this.outsideClr, 
										0, 
										component.getHeight(), 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.WEST) {
				xGp = new GradientPaint(0, 
										0, 
										this.outsideClr, 
										component.getWidth(), 
										0, 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.EAST) {
				xGp = new GradientPaint(component.getWidth(), 
										0, 
										this.outsideClr, 
										0, 
										0, 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.SOUTH) {
				xGp = new GradientPaint(0, 
										component.getHeight(), 
										this.outsideClr, 
										0, 
										0, 
										this.insideClr, 
										false);
			}
			xG2d.setPaint(xGp);
			xG2d.fill(component.getVisibleRect());
		}
		else if ((this.locationInt == JsFrameBorderBlock.NORTHWEST) 
				|| (this.locationInt == JsFrameBorderBlock.NORTHEAST) 
				|| (this.locationInt == JsFrameBorderBlock.SOUTHWEST) 
				|| (this.locationInt == JsFrameBorderBlock.SOUTHEAST)) {
			double ratioDbl = component.getWidth() >> 3;
			int xInt = 0;
			int yInt = 0;
			int xTriangleArr[] = new int[3];
			int yTriangleArr[] = new int[3];
			Polygon xPly = null;
			Area xArea = new Area();
			double xSectorArr[] = new double[3];
			double ySectorArr[] = new double[3];
			QuadCurve2D.Double xDbl = new QuadCurve2D.Double();
			if (this.locationInt == JsFrameBorderBlock.NORTHWEST) {
				xInt = component.getWidth();
				yInt = component.getWidth();
				xTriangleArr[0] = 0;
				xTriangleArr[1] = xInt;
				xTriangleArr[2] = xInt;
				yTriangleArr[0] = xInt;
				yTriangleArr[1] = yInt;
				yTriangleArr[2] = 0;
				xSectorArr[0] = 0;
				xSectorArr[1] = ratioDbl;
				xSectorArr[2] = xInt;
				ySectorArr[0] = yInt;
				ySectorArr[1] = ratioDbl;
				ySectorArr[2] = 0;
				xGp = new GradientPaint((int) ratioDbl, 
										(int) ratioDbl, 
										this.outsideClr, 
										xInt, 
										yInt, 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.NORTHEAST) {
				xInt = 0;
				yInt = component.getHeight();
				xTriangleArr[0] = xInt;
				xTriangleArr[1] = xInt;
				xTriangleArr[2] = component.getWidth();
				yTriangleArr[0] = 0;
				yTriangleArr[1] = yInt;
				yTriangleArr[2] = yInt;
				xSectorArr[0] = component.getWidth();
				xSectorArr[1] = component.getWidth() - ratioDbl;
				xSectorArr[2] = xInt;
				ySectorArr[0] = yInt;
				ySectorArr[1] = ratioDbl;
				ySectorArr[2] = 0;
				xGp = new GradientPaint(component.getWidth() - (int) ratioDbl, 
										(int) ratioDbl, 
										this.outsideClr, 
										xInt, 
										yInt, 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.SOUTHWEST) {
				xInt = component.getWidth();
				yInt = 0;
				xTriangleArr[0] = xInt;
				xTriangleArr[1] = xInt;
				xTriangleArr[2] = 0;
				yTriangleArr[0] = component.getHeight();
				yTriangleArr[1] = yInt;
				yTriangleArr[2] = yInt;
				xSectorArr[0] = 0;
				xSectorArr[1] = ratioDbl;
				xSectorArr[2] = xInt;
				ySectorArr[0] = yInt;
				ySectorArr[1] = component.getHeight() - ratioDbl;
				ySectorArr[2] = component.getHeight();
				xGp = new GradientPaint((int) ratioDbl, 
										component.getHeight() - (int) ratioDbl, 
										this.outsideClr, 
										xInt, 
										yInt, 
										this.insideClr, 
										false);
			}
			else if (this.locationInt == JsFrameBorderBlock.SOUTHEAST) {
				xInt = 0;
				yInt = 0;
				xTriangleArr[0] = xInt;
				xTriangleArr[1] = xInt;
				xTriangleArr[2] = component.getWidth();
				yTriangleArr[0] = yInt;
				yTriangleArr[1] = component.getHeight();
				yTriangleArr[2] = yInt;
				xSectorArr[0] = xInt;
				xSectorArr[1] = component.getWidth() - ratioDbl;
				xSectorArr[2] = component.getWidth();
				ySectorArr[0] = component.getHeight();
				ySectorArr[1] = component.getHeight() - ratioDbl;
				ySectorArr[2] = yInt;
				xGp = new GradientPaint(component.getWidth() - (int) ratioDbl, 
										component.getHeight() - (int) ratioDbl, 
										this.outsideClr, 
										xInt, 
										yInt, 
										this.insideClr, 
										false);
			}
			// triangle
			xPly = new Polygon(xTriangleArr, yTriangleArr, xTriangleArr.length);
			xArea.add(new Area(xPly));
			// sector
			xDbl.setCurve(xSectorArr[0], ySectorArr[0], xSectorArr[1], ySectorArr[1], xSectorArr[2], ySectorArr[2]);
			// combine the triangle and the sector
			xArea.add(new Area(xDbl));
			xG2d.setPaint(xGp);
			xG2d.fill(xArea);
		}
		else {
			throw new IllegalArgumentException("Invalid direction.");
		}
	}

}

⌨️ 快捷键说明

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