查看本类的 API文档即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright (C) 2015 Jack Jiang(cngeeker.com) The BeautyEye Project. 
3    * All rights reserved.
4    * Project URL:https://github.com/JackJiang2011/beautyeye
5    * Version 3.6
6    * 
7    * Jack Jiang PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
8    * 
9    * SplitPaneDividerBorder.java at 2015-2-1 20:25:41, original version by Jack Jiang.
10   * You can contact author with jb2011@163.com.
11   */
12  package org.jb2011.lnf.beautyeye.ch17_split;
13  
14  import java.awt.Component;
15  import java.awt.Graphics;
16  import java.awt.Insets;
17  
18  import javax.swing.JSplitPane;
19  import javax.swing.border.Border;
20  import javax.swing.plaf.UIResource;
21  import javax.swing.plaf.basic.BasicSplitPaneDivider;
22  import javax.swing.plaf.basic.BasicSplitPaneUI;
23  
24  // TODO: Auto-generated Javadoc
25  /**
26   * 分隔条的border实现类.
27   * <p>
28   * Draws the border around the divider in a splitpane. To get the appropriate effect, this
29   * needs to be used with a SplitPaneBorder.
30   * 
31   * @author Jack Jiang(jb2011@163.com)
32   */
33  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 一些说明 Start
34  //本类参考自jdk1.6_u18的javax.swing.plaf.basic.BasicBorders
35  //	.SplitPaneDividerBorder的源码,主要修改了UI填充实现部分
36  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 一些说明 END
37  public class SplitPaneDividerBorder implements Border, UIResource
38  {
39  //	javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder
40  //	private Color highlight;
41  //	private Color shadow;
42  
43  //	public SplitPaneDividerBorder(Color highlight, Color shadow)
44  //	{
45  //		this.highlight = highlight;
46  //		this.shadow = shadow;
47  //	}
48  
49  	/* (non-Javadoc)
50   * @see javax.swing.border.Border#paintBorder(java.awt.Component, java.awt.Graphics, int, int, int, int)
51   */
52  public void paintBorder(Component c, Graphics g, int x, int y, int width,
53  			int height)
54  	{
55  		//在目前的视觉效果下不需要这个border的绘制哦
56  //		Graphics2D g2d = (Graphics2D) g;
57  //		Component child;
58  //		Rectangle cBounds;
59  //		JSplitPane splitPane = ((BasicSplitPaneDivider) c).getBasicSplitPaneUI().getSplitPane();
60  //		Dimension size = c.getSize();
61  //
62  //		child = splitPane.getLeftComponent();
63  //		// This is needed for the space between the divider and end of
64  //		// splitpane.
65  //		g.setColor(c.getBackground());
66  //		g.drawRect(x, y, width - 1, height - 1);
67  //		
68  //		if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
69  //		{
70  ////			if (child != null)
71  ////			{
72  ////				g.setColor(shadow);//highlight);
73  ////				g.drawLine(0, 0, 0, size.height);
74  ////			}
75  ////			child = splitPane.getRightComponent();
76  ////			if (child != null)
77  ////			{
78  ////				g.setColor(shadow);
79  ////				g.drawLine(size.width - 1, 0, size.width - 1, size.height);
80  ////			}
81  //		}
82  //		else
83  //		{
84  ////			if (child != null)
85  ////			{
86  ////				g.setColor(shadow);//highlight);
87  ////				g.drawLine(0, 0, size.width, 0);
88  ////			}
89  ////			child = splitPane.getRightComponent();
90  ////			if (child != null)
91  ////			{
92  ////				g.setColor(shadow);
93  ////			    g.drawLine(0, size.height - 1, size.width,size.height - 1);
94  ////
95  ////			}
96  //		}
97  	}
98  
99  	/* (non-Javadoc)
100 	 * @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
101 	 */
102 	public Insets getBorderInsets(Component c)
103 	{
104 		Insets insets = new Insets(0, 0, 0, 0);
105 		if (c instanceof BasicSplitPaneDivider)
106 		{
107 			BasicSplitPaneUI bspui = ((BasicSplitPaneDivider) c)
108 					.getBasicSplitPaneUI();
109 
110 			if (bspui != null)
111 			{
112 				JSplitPane splitPane = bspui.getSplitPane();
113 
114 				if (splitPane != null)
115 				{
116 					if (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
117 					{
118 						insets.top = insets.bottom = 0;
119 						insets.left = insets.right = 1;
120 						return insets;
121 					}
122 					// VERTICAL_SPLIT
123 					insets.top = insets.bottom = 1;
124 					insets.left = insets.right = 0;
125 					return insets;
126 				}
127 			}
128 		}
129 		insets.top = insets.bottom = insets.left = insets.right = 1;
130 		return insets;
131 	}
132 
133 	/* (non-Javadoc)
134 	 * @see javax.swing.border.Border#isBorderOpaque()
135 	 */
136 	public boolean isBorderOpaque()
137 	{
138 		return true;
139 	}
140 }