| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class SubstanceStatusBarUI extends BasicStatusBarUI { |
| 40 |
|
| 41 |
|
| 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 |
|
| 52 |
|
| 53 |
public SubstanceStatusBarUI() { |
| 54 |
super(); |
| 55 |
this.bgDelegate = new SubstanceSwingxFillBackgroundDelegate(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
@Override |
| 66 |
protected void installDefaults(JXStatusBar sb) { |
| 67 |
super.installDefaults(sb); |
| 68 |
SubstanceLookAndFeel.setDecorationType(sb, DecorationAreaType.FOOTER); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 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 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 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 |
} |