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: TabHighlightBorder.java,v 1.19 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.border;
024:
025: import net.infonode.gui.GraphicsUtil;
026: import net.infonode.gui.colorprovider.ColorProvider;
027: import net.infonode.gui.colorprovider.ColorProviderUtil;
028: import net.infonode.gui.colorprovider.UIManagerColorProvider;
029: import net.infonode.tabbedpanel.Tab;
030: import net.infonode.tabbedpanel.TabbedPanel;
031: import net.infonode.tabbedpanel.TabbedPanelProperties;
032: import net.infonode.tabbedpanel.TabbedUtils;
033: import net.infonode.util.Direction;
034:
035: import javax.swing.border.Border;
036: import java.awt.*;
037: import java.io.Serializable;
038:
039: /**
040: * TabHighlightBorder draws a 1 pixel wide highlight on the top and left side of the
041: * tab. It will not draw highlight on the side towards a TabbedPanel's content area
042: * if the border is constructed with open border.
043: *
044: * @author $Author: jesper $
045: * @version $Revision: 1.19 $
046: * @see Tab
047: * @see TabbedPanel
048: * @see TabbedPanelProperties
049: */
050: public class TabHighlightBorder implements Border, Serializable {
051: private static final long serialVersionUID = 1;
052:
053: private ColorProvider color;
054: private boolean openBorder;
055:
056: /**
057: * Constructs a TabHighlightBorder that acts as an empty border, i.e. no highlight
058: * is drawn but it will report the same insets as if the highlight was drawn
059: */
060: public TabHighlightBorder() {
061: this ((Color) null, false);
062: }
063:
064: /**
065: * Constructs a TabHighlightBorder with the given color as highlight color
066: *
067: * @param color the highlight color
068: * @param openBorder when true, no highlighting is drawn on the side towards a
069: * TabbedPanel's content area, otherwise false
070: */
071: public TabHighlightBorder(Color color, boolean openBorder) {
072: this (ColorProviderUtil.getColorProvider(color,
073: UIManagerColorProvider.TABBED_PANE_HIGHLIGHT),
074: openBorder);
075: }
076:
077: /**
078: * Constructs a TabHighlightBorder with the given color as highlight color
079: *
080: * @param colorProvider the highlight color provider
081: * @param openBorder when true, no highlighting is drawn on the side towards a
082: * TabbedPanel's content area, otherwise false
083: */
084: public TabHighlightBorder(ColorProvider colorProvider,
085: boolean openBorder) {
086: this .color = colorProvider;
087: this .openBorder = openBorder;
088: }
089:
090: public void paintBorder(Component c, Graphics g, int x, int y,
091: int width, int height) {
092: TabbedPanel tabbedPanel = TabbedUtils.getParentTabbedPanel(c);
093:
094: if (tabbedPanel != null) {
095: Direction d = tabbedPanel.getProperties()
096: .getTabAreaOrientation();
097: g.setColor(color.getColor(c));
098:
099: if (d == Direction.UP) {
100: GraphicsUtil.drawOptimizedLine(g, x + 1, y, x + width
101: - 2, y);
102: GraphicsUtil.drawOptimizedLine(g, x, y, x, y + height
103: - (openBorder ? 1 : 2));
104: } else if (d == Direction.LEFT) {
105: GraphicsUtil.drawOptimizedLine(g, x + 1, y, x + width
106: - (openBorder ? 1 : 2), y);
107: GraphicsUtil.drawOptimizedLine(g, x, y, x, y + height
108: - 2);
109: } else if (d == Direction.DOWN) {
110: if (!openBorder)
111: GraphicsUtil.drawOptimizedLine(g, x + 1, y, x
112: + width - 2, y);
113: GraphicsUtil.drawOptimizedLine(g, x, y, x, y + height
114: - 2);
115: } else {
116: if (openBorder)
117: GraphicsUtil.drawOptimizedLine(g, x, y, x + width
118: - 2, y);
119: else {
120: GraphicsUtil.drawOptimizedLine(g, x + 1, y, x
121: + width - 2, y);
122: GraphicsUtil.drawOptimizedLine(g, x, y, x, y
123: + height - 2);
124: }
125: }
126: }
127: }
128:
129: public Insets getBorderInsets(Component c) {
130: return new Insets(1, 1, 0, 0);
131: }
132:
133: public boolean isBorderOpaque() {
134: return false;
135: }
136: }
|