Debian Codegraph @

substance-swingx/src/main/java/org/pushingpixels/substance/swingx/SubstanceStatusBarUI.java

raw symbols SCIP
1 /*
2 * Copyright 2005-2010 Kirill Grouchnikov, based on work by
3 * Sun Microsystems, Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 package org.pushingpixels.substance.swingx;
20
21 import java.awt.*;
22 import java.awt.image.BufferedImage;
23
24 import javax.swing.*;
25 import javax.swing.plaf.ComponentUI;
26
27 import org.jdesktop.swingx.JXStatusBar;
28 import org.jdesktop.swingx.plaf.basic.BasicStatusBarUI;
29 import org.pushingpixels.substance.api.*;
30 import org.pushingpixels.substance.internal.painter.DecorationPainterUtils;
31 import org.pushingpixels.substance.internal.painter.SeparatorPainterUtils;
32 import org.pushingpixels.substance.internal.utils.*;
33
34 /**
35 * Substance-consistent UI delegate for {@link JXStatusBar}.
36 *
37 * @author Kirill Grouchnikov
38 */
39 public class SubstanceStatusBarUI extends BasicStatusBarUI {
40 /**
41 * Background delegate.
42 */
43 private SubstanceSwingxFillBackgroundDelegate bgDelegate;
44
45 public static ComponentUI createUI(JComponent comp) {
46 SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp);
47 return new SubstanceStatusBarUI();
48 }
49
50 /**
51 * Creates a new UI delegate.
52 */
53 public SubstanceStatusBarUI() {
54 super();
55 this.bgDelegate = new SubstanceSwingxFillBackgroundDelegate();
56 }
57
58 /*
59 * (non-Javadoc)
60 *
61 * @see
62 * org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#installDefaults(org.jdesktop
63 * .swingx.JXStatusBar)
64 */
65 @Override
66 protected void installDefaults(JXStatusBar sb) {
67 super.installDefaults(sb);
68 SubstanceLookAndFeel.setDecorationType(sb, DecorationAreaType.FOOTER);
69 }
70
71 /*
72 * (non-Javadoc)
73 *
74 * @see
75 * org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#uninstallDefaults(org
76 * .jdesktop.swingx.JXStatusBar)
77 */
78 @Override
79 protected void uninstallDefaults(JXStatusBar sb) {
80 DecorationPainterUtils.clearDecorationType(sb);
81 super.uninstallDefaults(sb);
82 }
83
84 @Override
85 protected void paintBackground(Graphics2D g, JXStatusBar bar) {
86 this.bgDelegate.paint(bar, g, true);
87
88 JRootPane rootPane = SwingUtilities.getRootPane(bar);
89 Window window = SwingUtilities.getWindowAncestor(bar);
90 boolean isResizable = false;
91 if (window instanceof JFrame) {
92 JFrame frame = (JFrame) window;
93 isResizable = frame.isResizable()
94 && (frame.getExtendedState() != JFrame.MAXIMIZED_BOTH);
95 }
96 if (window instanceof JDialog) {
97 isResizable = ((JDialog) window).isResizable();
98 }
99 boolean hasResizeGrip = SubstanceCoreUtilities
100 .toShowExtraWidgets(rootPane)
101 && isResizable;
102 if (hasResizeGrip) {
103 int dim = bar.getHeight() * 2 / 3;
104 SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
105 .getColorScheme(bar, ColorSchemeAssociationKind.SEPARATOR,
106 ComponentState.ENABLED);
107 BufferedImage resizeImage = SubstanceImageCreator
108 .getResizeGripImage(bar, scheme, dim, false);
109 g.drawImage(resizeImage, bar.getWidth() - dim, bar.getHeight()
110 - dim, null);
111 }
112 }
113
114 /*
115 * (non-Javadoc)
116 *
117 * @see
118 * org.jdesktop.swingx.plaf.basic.BasicStatusBarUI#paintSeparator(java.awt
119 * .Graphics2D, org.jdesktop.swingx.JXStatusBar, int, int, int, int)
120 */
121 @Override
122 protected void paintSeparator(Graphics2D g, JXStatusBar bar, int x, int y,
123 int w, int h) {
124 g.translate(x, y);
125 SeparatorPainterUtils.paintSeparator(bar, g, w, h, JSlider.VERTICAL,
126 true, 4);
127 g.translate(-x, -y);
128 }
129
130 @Override
131 protected int getSeparatorWidth() {
132 return SubstanceSizeUtils.getAdjustedSize(SubstanceSizeUtils
133 .getComponentFontSize(this.statusBar), super
134 .getSeparatorWidth(), 2, 1, false);
135 }
136
137 @Override
138 protected Insets getSeparatorInsets(Insets insets) {
139 Insets result = super.getSeparatorInsets(insets);
140 int totalSeparatorWidth = this.getSeparatorWidth();
141 int componentFontSize = SubstanceSizeUtils
142 .getComponentFontSize(this.statusBar);
143 int lineSeparatorWidth = (int) (2 * SubstanceSizeUtils
144 .getBorderStrokeWidth(componentFontSize));
145 int widthLeft = (totalSeparatorWidth - lineSeparatorWidth - result.left - result.right);
146 if (widthLeft > 0) {
147 result.left += widthLeft / 2;
148 result.right += widthLeft / 2;
149 }
150 result.top = SubstanceSizeUtils.getAdjustedSize(componentFontSize,
151 result.top, 4, 1, false);
152 result.bottom = SubstanceSizeUtils.getAdjustedSize(componentFontSize,
153 result.bottom, 4, 1, false);
154 return result;
155 }
156 }