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

📄 basicborders.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	        } else {		    BasicGraphicsUtils.drawBezel(g, x, y, width, height, 					       false, b.isFocusPainted() && b.hasFocus(),                                                 shadow, darkShadow,                                                  highlight, lightHighlight);	        }	    } else {		        BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false,                                             shadow, darkShadow, highlight, lightHighlight);	    }        }              public Insets getBorderInsets(Component c)       {	    return getBorderInsets(c, new Insets(0,0,0,0));        }        public Insets getBorderInsets(Component c, Insets insets)       {            insets.top = insets.left = insets.bottom = insets.right = 2;	    return insets;        }    }    public static class MenuBarBorder extends AbstractBorder implements UIResource {        private Color shadow;        private Color highlight;        public MenuBarBorder(Color shadow, Color highlight) {            this.shadow = shadow;            this.highlight = highlight;        }	public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {	    BasicGraphicsUtils.drawGroove(g, 0, height-2, 					  width, height,                                          shadow, highlight);	}		public Insets getBorderInsets(Component c)       {	    return getBorderInsets(c, new Insets(0,0,0,0));	}        public Insets getBorderInsets(Component c, Insets insets)       {            insets.top = 0;	    insets.left = 0;	    insets.bottom = 2;	    insets.right = 0;	    return insets;        }    }    public static class MarginBorder extends AbstractBorder implements UIResource {        public Insets getBorderInsets(Component c)       {	    return getBorderInsets(c, new Insets(0,0,0,0));        }        public Insets getBorderInsets(Component c, Insets insets)       {            Insets margin = null;            //            // Ideally we'd have an interface defined for classes which            // support margins (to avoid this hackery), but we've            // decided against it for simplicity            //           if (c instanceof AbstractButton) {               AbstractButton b = (AbstractButton)c;               margin = b.getMargin();           } else if (c instanceof JToolBar) {               JToolBar t = (JToolBar)c;               margin = t.getMargin();           } else if (c instanceof JTextComponent) {               JTextComponent t = (JTextComponent)c;               margin = t.getMargin();           }	   insets.top = margin != null? margin.top : 0;	   insets.left = margin != null? margin.left : 0;	   insets.bottom = margin != null? margin.bottom : 0;	   insets.right = margin != null? margin.right : 0;	       	   return insets;        }    }    public static class FieldBorder extends AbstractBorder implements UIResource {        protected Color shadow;        protected Color darkShadow;        protected Color highlight;        protected Color lightHighlight;        public FieldBorder(Color shadow, Color darkShadow,                            Color highlight, Color lightHighlight) {            this.shadow = shadow;            this.highlight = highlight;            this.darkShadow = darkShadow;            this.lightHighlight = lightHighlight;        }        public void paintBorder(Component c, Graphics g, int x, int y,                             int width, int height) {            BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height,                                              shadow, darkShadow,                                               highlight, lightHighlight);        }        public Insets getBorderInsets(Component c) {	    return getBorderInsets(c, new Insets(0,0,0,0));	}	public Insets getBorderInsets(Component c, Insets insets) {            Insets margin = null;            if (c instanceof JTextComponent) {                margin = ((JTextComponent)c).getMargin();            }	    insets.top = margin != null? 2+margin.top : 2;	    insets.left = margin != null? 2+margin.left : 2;	    insets.bottom = margin != null? 2+margin.bottom : 2;	    insets.right = margin != null? 2+margin.right : 2;	       	    return insets;        }    }    /**     * Draws the border around the divider in a splitpane     * (when BasicSplitPaneUI is used). To get the appropriate effect, this     * needs to be used with a SplitPaneBorder.     */    static class SplitPaneDividerBorder implements Border, UIResource {        Color highlight;        Color shadow;        SplitPaneDividerBorder(Color highlight, Color shadow) {	    this.highlight = highlight;	    this.shadow = shadow;	}	public void paintBorder(Component c, Graphics g, int x, int y,				int width, int height) {	    Component          child;	    Rectangle          cBounds;	    JSplitPane         splitPane = ((BasicSplitPaneDivider)c).		                         getBasicSplitPaneUI().getSplitPane();	    Dimension          size = c.getSize();	    	    child = splitPane.getLeftComponent();	    // This is needed for the space between the divider and end of	    // splitpane.	    g.setColor(c.getBackground());	    g.drawRect(x, y, width - 1, height - 1);	    if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {		if(child != null) {		    g.setColor(highlight);		    g.drawLine(0, 0, 0, size.height);		}		child = splitPane.getRightComponent();		if(child != null) {		    g.setColor(shadow);		    g.drawLine(size.width - 1, 0, size.width - 1, size.height);		}	    } else {		if(child != null) {		    g.setColor(highlight);		    g.drawLine(0, 0, size.width, 0);		}		child = splitPane.getRightComponent();		if(child != null) {		    g.setColor(shadow);		    g.drawLine(0, size.height - 1, size.width,			       size.height - 1);		}	    }	}	public Insets getBorderInsets(Component c) {	    Insets insets = new Insets(0,0,0,0);	    if (c instanceof BasicSplitPaneDivider) {		BasicSplitPaneUI bspui = ((BasicSplitPaneDivider)c).		                         getBasicSplitPaneUI();		if (bspui != null) {		    JSplitPane splitPane = bspui.getSplitPane();		    if (splitPane != null) {			if (splitPane.getOrientation() ==			    JSplitPane.HORIZONTAL_SPLIT) {			    insets.top = insets.bottom = 0;			    insets.left = insets.right = 1;			    return insets;			}			// VERTICAL_SPLIT			insets.top = insets.bottom = 1;			insets.left = insets.right = 0;			return insets;		    }		}	    }	    insets.top = insets.bottom = insets.left = insets.right = 1;	    return insets;	}	public boolean isBorderOpaque() { return true; }    }    /**     * Draws the border around the splitpane. To work correctly you shoudl     * also install a border on the divider (property SplitPaneDivider.border).     */    public static class SplitPaneBorder implements Border, UIResource {        protected Color highlight;        protected Color shadow;        public SplitPaneBorder(Color highlight, Color shadow) {	    this.highlight = highlight;	    this.shadow = shadow;	}	public void paintBorder(Component c, Graphics g, int x, int y,				int width, int height) {	    // The only tricky part with this border is that the divider is	    // not positioned at the top (for horizontal) or left (for vert),	    // so this border draws to where the divider is:	    // -----------------	    // |xxxxxxx xxxxxxx|	    // |x     ---     x|	    // |x     |	|     x|	    // |x     |D|     x|	    // |x     | |     x|	    // |x     ---     x|	    // |xxxxxxx xxxxxxx|	    // -----------------	    // The above shows (rather excessively) what this looks like for	    // a horizontal orientation. This border then draws the x's, with	    // the SplitPaneDividerBorder drawing its own border.	    Component          child;	    Rectangle          cBounds;	    JSplitPane splitPane = (JSplitPane)c;	    	    child = splitPane.getLeftComponent();	    // This is needed for the space between the divider and end of	    // splitpane.	    g.setColor(c.getBackground());	    g.drawRect(x, y, width - 1, height - 1);	    if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {		if(child != null) {		    cBounds = child.getBounds();		    g.setColor(shadow);		    g.drawLine(0, 0, cBounds.width + 1, 0);		    g.drawLine(0, 1, 0, cBounds.height + 2);		    g.setColor(highlight);		    g.drawLine(1, cBounds.height + 1, cBounds.width + 1,			       cBounds.height + 1);		}		child = splitPane.getRightComponent();		if(child != null) {		    cBounds = child.getBounds();		    int             maxX = cBounds.x + cBounds.width;		    int             maxY = cBounds.y + cBounds.height;		    		    g.setColor(shadow);		    g.drawLine(cBounds.x - 1, 0, maxX, 0);		    g.drawLine(cBounds.x - 1, maxY, cBounds.x, maxY);		    g.setColor(highlight);		    g.drawLine(cBounds.x, maxY, maxX, maxY);		    g.drawLine(maxX, 0, maxX, maxY + 1);		}	    } else {		if(child != null) {		    cBounds = child.getBounds();		    g.setColor(shadow);		    g.drawLine(0, 0, cBounds.width + 1, 0);		    g.drawLine(0, 1, 0, cBounds.height);		    g.setColor(highlight);		    g.drawLine(1 + cBounds.width, 0, 1 + cBounds.width,			       cBounds.height + 1);		    g.drawLine(0, cBounds.height + 1, 0, cBounds.height + 1);		}		child = splitPane.getRightComponent();		if(child != null) {		    cBounds = child.getBounds();		    int             maxX = cBounds.x + cBounds.width;		    int             maxY = cBounds.y + cBounds.height;		    		    g.setColor(shadow);		    g.drawLine(0, cBounds.y - 1, 0, maxY);		    g.drawLine(maxX, cBounds.y - 1, maxX, cBounds.y - 1);		    g.drawLine(0, cBounds.y - 1, cBounds.width, cBounds.y - 1);		    g.setColor(highlight);		    g.drawLine(0, maxY, cBounds.width + 1, maxY);		    g.drawLine(maxX, cBounds.y, maxX, maxY);		}	    }	}	public Insets getBorderInsets(Component c) {	    return new Insets(1, 1, 1, 1);	}	public boolean isBorderOpaque() { return true; }    }    }

⌨️ 快捷键说明

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