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: * @version $Revision$
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: import java.security.InvalidParameterException;
027:
028: import org.apache.harmony.x.swing.internal.nls.Messages;
029:
030: public class EtchedBorder extends AbstractBorder {
031:
032: public static final int RAISED = 0;
033: public static final int LOWERED = 1;
034:
035: protected int etchType = LOWERED;;
036: protected Color highlight;
037: protected Color shadow;
038:
039: private static final int INSETS_SIZE = 2;
040: private static final String INCORRECT_BORDER_TYPE_EXCEPTION_TEXT = Messages
041: .getString("swing.1D"); //$NON-NLS-1$
042:
043: public EtchedBorder() {
044: }
045:
046: public EtchedBorder(final Color highlightColor,
047: final Color shadowColor) {
048: highlight = highlightColor;
049: shadow = shadowColor;
050: }
051:
052: public EtchedBorder(final int etchType, final Color highlightColor,
053: final Color shadowColor) {
054: if (etchType != RAISED && etchType != LOWERED) {
055: throw new InvalidParameterException(
056: INCORRECT_BORDER_TYPE_EXCEPTION_TEXT);
057: }
058: this .etchType = etchType;
059: highlight = highlightColor;
060: shadow = shadowColor;
061: }
062:
063: public EtchedBorder(final int etchType) {
064: if (etchType != RAISED && etchType != LOWERED) {
065: throw new InvalidParameterException(
066: INCORRECT_BORDER_TYPE_EXCEPTION_TEXT);
067: }
068: this .etchType = etchType;
069: }
070:
071: public Insets getBorderInsets(final Component c, final Insets insets) {
072: insets.left = INSETS_SIZE;
073: insets.top = INSETS_SIZE;
074: insets.bottom = INSETS_SIZE;
075: insets.right = INSETS_SIZE;
076:
077: return insets;
078: }
079:
080: public Insets getBorderInsets(final Component c) {
081: return new Insets(INSETS_SIZE, INSETS_SIZE, INSETS_SIZE,
082: INSETS_SIZE);
083: }
084:
085: public void paintBorder(final Component c, final Graphics g,
086: final int x, final int y, final int width, final int height) {
087: Color oldColor = g.getColor();
088: Color color = (etchType == EtchedBorder.RAISED) ? getShadowColor(c)
089: : getHighlightColor(c);
090: g.setColor(color);
091: g.drawRect(x, y, width - 1, height - 1);
092: g.drawRect(x + 1, y + 1, width - 3, height - 3);
093: color = (etchType == EtchedBorder.RAISED) ? getHighlightColor(c)
094: : getShadowColor(c);
095: g.setColor(color);
096: g.drawRect(x, y, width - 2, height - 2);
097: g.setColor(oldColor);
098: }
099:
100: public Color getShadowColor(final Component c) {
101: return (shadow != null) ? shadow : c.getBackground().darker();
102: }
103:
104: public Color getHighlightColor(final Component c) {
105: return (highlight != null) ? highlight : c.getBackground()
106: .brighter();
107: }
108:
109: public Color getShadowColor() {
110: return shadow;
111: }
112:
113: public Color getHighlightColor() {
114: return highlight;
115: }
116:
117: public boolean isBorderOpaque() {
118: return true;
119: }
120:
121: public int getEtchType() {
122: return etchType;
123: }
124:
125: }
|