001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: HighlightBorder.java,v 1.17 2005/12/04 13:46:03 jesper Exp $
023: package net.infonode.gui.border;
024:
025: import net.infonode.gui.GraphicsUtil;
026: import net.infonode.gui.InsetsUtil;
027: import net.infonode.gui.colorprovider.BackgroundPainterColorProvider;
028: import net.infonode.gui.colorprovider.ColorMultiplier;
029: import net.infonode.gui.colorprovider.ColorProvider;
030: import net.infonode.gui.colorprovider.ColorProviderUtil;
031: import net.infonode.util.Direction;
032:
033: import javax.swing.border.Border;
034: import java.awt.*;
035: import java.io.Serializable;
036:
037: /**
038: * @author $Author: jesper $
039: * @version $Revision: 1.17 $
040: */
041: public class HighlightBorder implements Border, Serializable {
042: private static final long serialVersionUID = 1;
043:
044: private static final Insets INSETS = new Insets(1, 1, 0, 0);
045: private boolean lowered;
046: private boolean pressed;
047: private ColorProvider colorProvider;
048:
049: public HighlightBorder() {
050: this (false);
051: }
052:
053: public HighlightBorder(boolean lowered) {
054: this (lowered, null);
055: }
056:
057: public HighlightBorder(boolean lowered, Color color) {
058: this (lowered, false, color);
059: }
060:
061: public HighlightBorder(boolean lowered, boolean pressed, Color color) {
062: this (lowered, pressed, ColorProviderUtil.getColorProvider(
063: color, new ColorMultiplier(
064: BackgroundPainterColorProvider.INSTANCE,
065: lowered ? 0.7 : 1.70)));
066: }
067:
068: public HighlightBorder(boolean lowered, boolean pressed,
069: ColorProvider colorProvider) {
070: this .lowered = lowered;
071: this .pressed = pressed;
072: this .colorProvider = colorProvider;
073: }
074:
075: public Insets getBorderInsets(Component c) {
076: return pressed ? InsetsUtil.rotate(Direction.LEFT, INSETS)
077: : INSETS;
078: }
079:
080: public boolean isBorderOpaque() {
081: return false;
082: }
083:
084: public void paintBorder(Component c, Graphics g, int x, int y,
085: int width, int height) {
086: g.setColor(colorProvider.getColor(c));
087:
088: if (pressed) {
089: GraphicsUtil.drawOptimizedLine(g, x + (lowered ? 0 : 1), y
090: + height - 1, x + width - 1, y + height - 1);
091: GraphicsUtil.drawOptimizedLine(g, x + width - 1, y
092: + (lowered ? 0 : 1), x + width - 1, y + height - 2);
093: } else {
094: GraphicsUtil.drawOptimizedLine(g, x, y, x + width
095: - (lowered ? 1 : 2), y);
096: GraphicsUtil.drawOptimizedLine(g, x, y, x, y + height
097: - (lowered ? 1 : 2));
098: }
099: }
100: }
|