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.*;
035: import javax.swing.JInternalFrame.JDesktopIcon;
036:
037: import org.jvnet.lafwidget.LafWidgetSupport;
038: import org.jvnet.lafwidget.utils.LafConstants.PasswordStrength;
039: import org.jvnet.substance.color.ColorScheme;
040: import org.jvnet.substance.painter.decoration.DecorationAreaType;
041: import org.jvnet.substance.theme.SubstanceTheme;
042: import org.jvnet.substance.utils.*;
043:
044: /**
045: * Support for <a href="https://laf-widget.dev.java.net">laf-widget</a> layer.
046: * This class is <b>for internal use only</b>.
047: *
048: * @author Kirill Grouchnikov
049: */
050: public class SubstanceWidgetSupport extends LafWidgetSupport {
051:
052: /*
053: * (non-Javadoc)
054: *
055: * @see org.jvnet.lafwidget.LafWidgetSupport#getComponentForHover(javax.swing.JInternalFrame.JDesktopIcon)
056: */
057: @Override
058: public JComponent getComponentForHover(JDesktopIcon desktopIcon) {
059: SubstanceDesktopIconUI ui = (SubstanceDesktopIconUI) desktopIcon
060: .getUI();
061: return ui.getComponentForHover();
062: }
063:
064: /*
065: * (non-Javadoc)
066: *
067: * @see org.jvnet.lafwidget.LafWidgetSupport#toInstallMenuSearch(javax.swing.JMenuBar)
068: */
069: @Override
070: public boolean toInstallMenuSearch(JMenuBar menuBar) {
071: if (!SubstanceLookAndFeel.toShowExtraElements())
072: return false;
073: if (menuBar instanceof SubstanceTitlePane.SubstanceMenuBar)
074: return false;
075: return super .toInstallMenuSearch(menuBar);
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see org.jvnet.lafwidget.LafWidgetSupport#getSearchIcon(int,
082: * java.awt.ComponentOrientation)
083: */
084: @Override
085: public Icon getSearchIcon(int dimension,
086: ComponentOrientation componentOrientation) {
087: return SubstanceImageCreator.getSearchIcon(dimension,
088: SubstanceThemeUtilities.getTheme(null,
089: ComponentState.ACTIVE), componentOrientation
090: .isLeftToRight());
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see org.jvnet.lafwidget.LafWidgetSupport#getArrowIcon(int)
097: */
098: @Override
099: public Icon getArrowIcon(int orientation) {
100: return SubstanceImageCreator.getArrowIcon(SubstanceSizeUtils
101: .getControlFontSize(), orientation,
102: SubstanceThemeUtilities.getTheme(null,
103: ComponentState.ACTIVE));
104: }
105:
106: /*
107: * (non-Javadoc)
108: *
109: * @see org.jvnet.lafwidget.LafWidgetSupport#getNumberIcon(int)
110: */
111: @Override
112: public Icon getNumberIcon(int number) {
113: // SubstanceDecorationPainter decorationPainter = SubstanceLookAndFeel
114: // .getCurrentDecorationPainter();
115: // boolean isArc = decorationPainter instanceof ArcDecorationPainter;
116: SubstanceTheme theme = SubstanceLookAndFeel.getTheme()
117: .getDecorationTheme(DecorationAreaType.HEADER);
118: // if (!isArc)
119: // theme = theme.getActiveTheme();
120: // else
121: // theme = theme.getActiveTitlePaneTheme().negate();
122: return SubstanceImageCreator.getHexaMarker(number, theme);
123: }
124:
125: /*
126: * (non-Javadoc)
127: *
128: * @see org.jvnet.lafwidget.LafWidgetSupport#markButtonAsFlat(javax.swing.AbstractButton)
129: */
130: @Override
131: public void markButtonAsFlat(AbstractButton button) {
132: button.putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY,
133: Boolean.TRUE);
134: button.setOpaque(false);
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see org.jvnet.lafwidget.LafWidgetSupport#getRolloverTabIndex(javax.swing.JTabbedPane)
141: */
142: @Override
143: public int getRolloverTabIndex(JTabbedPane tabbedPane) {
144: SubstanceTabbedPaneUI ui = (SubstanceTabbedPaneUI) tabbedPane
145: .getUI();
146: return ui.getRolloverTabIndex();
147: }
148:
149: /*
150: * (non-Javadoc)
151: *
152: * @see org.jvnet.lafwidget.LafWidgetSupport#setTabAreaInsets(javax.swing.JTabbedPane,
153: * java.awt.Insets)
154: */
155: @Override
156: public void setTabAreaInsets(JTabbedPane tabbedPane,
157: Insets tabAreaInsets) {
158: SubstanceTabbedPaneUI ui = (SubstanceTabbedPaneUI) tabbedPane
159: .getUI();
160: ui.setTabAreaInsets(tabAreaInsets);
161: }
162:
163: /*
164: * (non-Javadoc)
165: *
166: * @see org.jvnet.lafwidget.LafWidgetSupport#getTabAreaInsets(javax.swing.JTabbedPane)
167: */
168: @Override
169: public Insets getTabAreaInsets(JTabbedPane tabbedPane) {
170: SubstanceTabbedPaneUI ui = (SubstanceTabbedPaneUI) tabbedPane
171: .getUI();
172: return ui.getTabAreaInsets();
173: }
174:
175: /*
176: * (non-Javadoc)
177: *
178: * @see org.jvnet.lafwidget.LafWidgetSupport#getTabRectangle(javax.swing.JTabbedPane,
179: * int)
180: */
181: @Override
182: public Rectangle getTabRectangle(JTabbedPane tabbedPane,
183: int tabIndex) {
184: SubstanceTabbedPaneUI ui = (SubstanceTabbedPaneUI) tabbedPane
185: .getUI();
186: return ui.getTabRectangle(tabIndex);
187: }
188:
189: /*
190: * (non-Javadoc)
191: *
192: * @see org.jvnet.lafwidget.LafWidgetSupport#paintPasswordStrengthMarker(java.awt.Graphics,
193: * int, int, int, int,
194: * org.jvnet.lafwidget.utils.LafConstants.PasswordStrength)
195: */
196: @Override
197: public void paintPasswordStrengthMarker(Graphics g, int x, int y,
198: int width, int height, PasswordStrength pStrength) {
199: Graphics2D g2 = (Graphics2D) g.create();
200:
201: ColorScheme colorScheme = null;
202:
203: if (pStrength == PasswordStrength.WEAK)
204: colorScheme = SubstanceTheme.ORANGE;
205: if (pStrength == PasswordStrength.MEDIUM)
206: colorScheme = SubstanceTheme.YELLOW;
207: if (pStrength == PasswordStrength.STRONG)
208: colorScheme = SubstanceTheme.GREEN;
209:
210: if (colorScheme != null) {
211: SubstanceImageCreator.paintRectangularBackground(g, x, y,
212: width, height, colorScheme, 0.5f, false);
213: }
214:
215: g2.dispose();
216: }
217:
218: /*
219: * (non-Javadoc)
220: *
221: * @see org.jvnet.lafwidget.LafWidgetSupport#hasLockIcon(java.awt.Component)
222: */
223: @Override
224: public boolean hasLockIcon(Component comp) {
225: if (!SubstanceLookAndFeel.toShowExtraElements())
226: return false;
227: if (comp instanceof JComponent) {
228: if (Boolean.TRUE
229: .equals(((JComponent) comp)
230: .getClientProperty(SubstanceLookAndFeel.NO_EXTRA_ELEMENTS)))
231: return false;
232: }
233: return super .hasLockIcon(comp);
234: }
235:
236: /*
237: * (non-Javadoc)
238: *
239: * @see org.jvnet.lafwidget.LafWidgetSupport#getLockIcon()
240: */
241: @Override
242: public Icon getLockIcon() {
243: return SubstanceImageCreator.makeTransparent(null,
244: SubstanceImageCreator
245: .getSmallLockIcon(SubstanceThemeUtilities
246: .getTheme(null, ComponentState.DEFAULT)
247: .getColorScheme()), 0.3);
248: }
249:
250: /*
251: * (non-Javadoc)
252: *
253: * @see org.jvnet.lafwidget.LafWidgetSupport#toInstallExtraElements(java.awt.Component)
254: */
255: @Override
256: public boolean toInstallExtraElements(Component comp) {
257: return SubstanceCoreUtilities.toShowExtraElements(comp);
258: }
259:
260: /*
261: * (non-Javadoc)
262: *
263: * @see org.jvnet.lafwidget.LafWidgetSupport#getLookupIconSize()
264: */
265: @Override
266: public int getLookupIconSize() {
267: int result = 2 + SubstanceSizeUtils.getControlFontSize();
268: if (result % 2 == 1)
269: result++;
270: return result;
271: }
272:
273: /*
274: * (non-Javadoc)
275: *
276: * @see org.jvnet.lafwidget.LafWidgetSupport#getLookupButtonSize()
277: */
278: @Override
279: public int getLookupButtonSize() {
280: return 4 + SubstanceSizeUtils.getControlFontSize();
281: }
282: }
|