001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance;
031:
032: import java.awt.*;
033:
034: import javax.swing.SwingUtilities;
035: import javax.swing.border.AbstractBorder;
036: import javax.swing.plaf.UIResource;
037:
038: import org.jvnet.substance.color.ColorScheme;
039: import org.jvnet.substance.theme.SubstanceComplexTheme;
040: import org.jvnet.substance.theme.SubstanceTheme;
041: import org.jvnet.substance.utils.ComponentState;
042: import org.jvnet.substance.utils.SubstanceThemeUtilities;
043:
044: /**
045: * Root pane and internal frame border in <b>Substance</b> look and feel. This
046: * class is <b>for internal use only</b>.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SubstancePaneBorder extends AbstractBorder implements
051: UIResource {
052: /**
053: * Default border thickness.
054: */
055: private static final int BORDER_THICKNESS = 4;
056:
057: /**
058: * Default insets.
059: */
060: private static final Insets INSETS = new Insets(
061: SubstancePaneBorder.BORDER_THICKNESS,
062: SubstancePaneBorder.BORDER_THICKNESS,
063: SubstancePaneBorder.BORDER_THICKNESS,
064: SubstancePaneBorder.BORDER_THICKNESS);
065:
066: /*
067: * (non-Javadoc)
068: *
069: * @see javax.swing.border.Border#paintBorder(java.awt.Component,
070: * java.awt.Graphics, int, int, int, int)
071: */
072: @Override
073: public void paintBorder(Component c, Graphics g, int x, int y,
074: int w, int h) {
075: Window window = SwingUtilities.getWindowAncestor(c);
076: boolean isSelected = (window == null) ? true : window
077: .isActive();
078:
079: // Active for selected window, default for inactive windows
080: ComponentState state = isSelected ? ComponentState.ACTIVE
081: : ComponentState.DEFAULT;
082: SubstanceTheme theme = SubstanceThemeUtilities.getTheme(c,
083: state);
084:
085: // special case for complex themes
086: if (isSelected
087: && (SubstanceLookAndFeel.getTheme() instanceof SubstanceComplexTheme)) {
088: theme = ((SubstanceComplexTheme) SubstanceLookAndFeel
089: .getTheme()).getActiveTitlePaneTheme();
090: }
091:
092: // if ((c != null) && SubstanceCoreUtilities.hasColorization(c)) {
093: // Color backgr = c.getBackground();
094: // if (!(backgr instanceof UIResource)) {
095: // double colorization = SubstanceCoreUtilities
096: // .getColorizationFactor(c);
097: // theme = SubstanceShiftTheme.getShiftedTheme(theme, backgr,
098: // colorization, null, 0.0);
099: // }
100: // }
101: ColorScheme colorScheme = theme.getColorScheme();
102:
103: Graphics2D graphics = (Graphics2D) g;
104:
105: // bottom and right in ultra dark
106: graphics.setColor(colorScheme.getUltraDarkColor());
107: graphics.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
108: graphics.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
109: // top and left
110: graphics.setColor(colorScheme.getDarkColor());
111: graphics.drawLine(x, y, x + w - 2, y);
112: graphics.drawLine(x, y, x, y + h - 2);
113: // bottom and right
114: graphics.setColor(colorScheme.getMidColor());
115: graphics.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
116: graphics.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2);
117: // top and left
118: graphics.setColor(colorScheme.getMidColor());
119: graphics.drawLine(x + 1, y + 1, x + w - 3, y + 1);
120: graphics.drawLine(x + 1, y + 1, x + 1, y + h - 3);
121: // inner
122: graphics.setColor(colorScheme.getLightColor());
123: graphics.drawRect(x + 2, y + 2, w - 5, h - 5);
124: graphics.drawRect(x + 3, y + 3, w - 7, h - 7);
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
131: */
132: @Override
133: public Insets getBorderInsets(Component c) {
134: return SubstancePaneBorder.INSETS;
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component,
141: * java.awt.Insets)
142: */
143: @Override
144: public Insets getBorderInsets(Component c, Insets newInsets) {
145: newInsets.top = SubstancePaneBorder.INSETS.top;
146: newInsets.left = SubstancePaneBorder.INSETS.left;
147: newInsets.bottom = SubstancePaneBorder.INSETS.bottom;
148: newInsets.right = SubstancePaneBorder.INSETS.right;
149: return newInsets;
150: }
151:
152: /*
153: * (non-Javadoc)
154: *
155: * @see javax.swing.border.Border#isBorderOpaque()
156: */
157: @Override
158: public boolean isBorderOpaque() {
159: return false;
160: }
161: }
|