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:
027: public class LineBorder extends AbstractBorder {
028:
029: protected int thickness = 1;
030: protected Color lineColor;
031: protected boolean roundedCorners;
032:
033: public LineBorder(final Color color, final int thickness,
034: final boolean roundedCorners) {
035: lineColor = color;
036: this .thickness = thickness;
037: this .roundedCorners = roundedCorners;
038: }
039:
040: public LineBorder(final Color color, final int thickness) {
041: lineColor = color;
042: this .thickness = thickness;
043: }
044:
045: public LineBorder(final Color color) {
046: lineColor = color;
047: }
048:
049: public Insets getBorderInsets(final Component component,
050: final Insets insets) {
051: if (insets != null) {
052: insets.top = thickness;
053: insets.left = thickness;
054: insets.right = thickness;
055: insets.bottom = thickness;
056:
057: return insets;
058: }
059:
060: return getBorderInsets(component);
061: }
062:
063: public Insets getBorderInsets(final Component component) {
064: return new Insets(thickness, thickness, thickness, thickness);
065: }
066:
067: public void paintBorder(final Component c, final Graphics g,
068: final int x, final int y, final int width, final int height) {
069: Color oldColor = g.getColor();
070: g.setColor(lineColor);
071: if (!roundedCorners) {
072: for (int i = 0; i < thickness; i++) {
073: g.drawRect(x + i, y + i, width - 1 - 2 * i, height - 1
074: - 2 * i);
075: }
076: } else {
077: for (int i = 0; i < thickness; i++) {
078: g.drawRoundRect(x + i, y + i, width - 1 - 2 * i, height
079: - 1 - 2 * i, thickness, thickness);
080: }
081: }
082: g.setColor(oldColor);
083: }
084:
085: public Color getLineColor() {
086: return lineColor;
087: }
088:
089: public boolean isBorderOpaque() {
090: return !roundedCorners;
091: }
092:
093: public boolean getRoundedCorners() {
094: return roundedCorners;
095: }
096:
097: public int getThickness() {
098: return thickness;
099: }
100:
101: public static Border createGrayLineBorder() {
102: return new LineBorder(Color.gray);
103: }
104:
105: public static Border createBlackLineBorder() {
106: return new LineBorder(Color.black);
107: }
108:
109: }
|