`
DemoGilbete
  • 浏览: 5380 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

bevelborder.java

阅读更多
001 /**
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017 /***
018 * @author Alexander T. Simbirtsev
019 */
020 package javax.swing.border;
021
022 import java.awt.Color;
023 import java.awt.Component;
024 import java.awt.Graphics;
025 import java.awt.Insets;
026
027 import org.apache.harmony.x.swing.internal.nls.Messages;
028
029
030 public class BevelBorder extends AbstractBorder {
031
032     public static final int RAISED = 0;
033     public static final int LOWERED = 1;
034
035     private static final int INSETS_SIZE = 2;
036
037     protected int bevelType;
038
039     protected Color highlightOuter;
040     protected Color highlightInner;
041     protected Color shadowInner;
042     protected Color shadowOuter;
043
044     public BevelBorder(final int bevelType) {
045         this.bevelType = bevelType;
046     }
047
048     public BevelBorder(final int bevelType, final Color highlightOuterColor, final Color highlightInnerColor, final Color shadowOuterColor, final Color shadowInnerColor) {
049         this(bevelType);
050
051         if (highlightOuterColor == null || highlightInnerColor == null ||
052                 shadowOuterColor == null || shadowInnerColor == null) {
053             throw new NullPointerException(Messages.getString("swing.68")); //$NON-NLS-1$
054         }
055         highlightOuter = highlightOuterColor;
056         highlightInner = highlightInnerColor;
057         shadowOuter = shadowOuterColor;
058         shadowInner = shadowInnerColor;
059     }
060
061     public BevelBorder(final int bevelType, final Color highlight, final Color shadow) {
062         this(bevelType, highlight, highlight, shadow, shadow);
063     }
064
065     int getInsetSize() {
066         return INSETS_SIZE;
067     }
068
069     public Insets getBorderInsets(final Component c, final Insets insets) {
070         int insetSize = getInsetSize();
071
072         insets.left = insetSize;
073         insets.top = insetSize;
074         insets.bottom = insetSize;
075         insets.right = insetSize;
076
077         return insets;
078     }
079
080     public Insets getBorderInsets(final Component c) {
081         int insetSize = getInsetSize();
082         return new Insets(insetSize, insetSize, insetSize, insetSize);
083     }
084
085     protected void paintRaisedBevel(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
086         Color oldColor = g.getColor();
087         Color color = getShadowOuterColor(c);
088         g.setColor(color);
089         g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
090         g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
091
092         color = getShadowInnerColor(c);
093         g.setColor(color);
094         g.drawLine(x + 1, y + height - 2, x + width - 2, y + height - 2);
095         g.drawLine(x + width - 2, y + 1, x + width - 2, y + height - 2);
096
097         color = getHighlightOuterColor(c);
098         g.setColor(color);
099         g.drawLine(x + 1, y, x + width - 2, y);
100         g.drawLine(x, y + 1, x, y + height - 2);
101
102         color = getHighlightInnerColor(c);
103         g.setColor(color);
104         g.drawLine(x + 2, y + 1, x + width - 3, y + 1);
105         g.drawLine(x + 1, y + 2, x + 1, y + height - 3);
106         g.setColor(oldColor);
107     }
108
109     protected void paintLoweredBevel(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
110         Color oldColor = g.getColor();
111         Color color = getShadowInnerColor(c);
112         g.setColor(color);
113         g.drawLine(x, y, x + width - 1, y);
114         g.drawLine(x, y, x, y + height - 1);
115
116         color = getShadowOuterColor(c);
117         g.setColor(color);
118         g.drawLine(x + 1, y + 1, x + width - 2, y + 1);
119         g.drawLine(x + 1, y + 1, x + 1, y + height - 2);
120
121         color = getHighlightOuterColor(c);
122         g.setColor(color);
123         g.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
124         g.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 2);
125
126         color = getHighlightInnerColor(c);
127         g.setColor(color);
128         g.drawLine(x + 2, y + height - 2, x + width - 2, y + height - 2);
129         g.drawLine(x + width - 2, y + 2, x + width - 2, y + height - 3);
130         g.setColor(oldColor);
131     }
132
133     public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
134         if (bevelType == BevelBorder.LOWERED) {
135             paintLoweredBevel(c, g, x, y, width, height);
136         } else if (bevelType == BevelBorder.RAISED){
137             paintRaisedBevel(c, g, x, y, width, height);
138         }
139     }
140
141     public Color getShadowOuterColor(final Component c) {
142         return (shadowOuter != null) ? shadowOuter : c.getBackground().darker().darker();
143     }
144
145     public Color getShadowInnerColor(final Component c) {
146         return (shadowInner != null) ? shadowInner : c.getBackground().darker();
147     }
148
149     public Color getHighlightOuterColor(final Component c) {
150         return (highlightOuter != null) ? highlightOuter : c.getBackground().brighter().brighter();
151     }
152
153     public Color getHighlightInnerColor(final Component c) {
154         return (highlightInner != null) ? highlightInner : c.getBackground().brighter();
155     }
156
157     public Color getShadowOuterColor() {
158         return shadowOuter;
159     }
160
161     public Color getShadowInnerColor() {
162         return shadowInner;
163     }
164
165     public Color getHighlightOuterColor() {
166         return highlightOuter;
167     }
168
169     public Color getHighlightInnerColor() {
170         return highlightInner;
171     }
172
173     public boolean isBorderOpaque() {
174         return true;
175     }
176
177     public int getBevelType() {
178         return bevelType;
179     }
180
181 }
分享到:
评论

相关推荐

    咖啡机 界面

    import javax.swing.BorderFactory; import javax.swing.JPanel;... cabinetView.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); } public JPanel getView(){ return cabinetView; } }

    java编写的类似文本编辑器的代码

    import javax.swing.border.BevelBorder; import javax.swing.event.*; import javax.swing.filechooser.FileFilter; import javax.swing.text.BadLocationException; import javax.swing.tree....

    Java Swing自定义标签边界.rar

    Java基于要SWing技术自定义标签的边界效果,通过javax.swing.border.Border 接口,进行自定义边界类OwnBorder。可以实现空边界(EmptyBorder)、斜切边界(BevelBorder)、蚀刻边界(EtchedBorder)、线条边界...

    Java自定义标签的边界效果

    本例将实现如空边界(EmptyBorder)、斜切边界(BevelBorder)、蚀刻边界(EtchedBorder)、线条边界(LineBorder)、带标题的边界(TitledBorder)和复合边界(CompoundBorder)等边界效果。 运行环境:Java/...

    图书管理系统数据库源代码.doc

    //设置是否可以移动工具栏 toolBar.setBorder(new BevelBorder(BevelBorder。RAIZED)); //设置边框 //图书信息添加按钮 JButton bookAddButton=new JButton(MenuActions.BOOK_ADD); ImageIcon icon=new ...

Global site tag (gtag.js) - Google Analytics