2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.substance.internal.utils.border;
34
import javax.swing.JToolBar;
35
import javax.swing.SwingConstants;
36
import javax.swing.border.AbstractBorder;
37
import javax.swing.plaf.UIResource;
39
import org.pushingpixels.substance.api.*;
40
import org.pushingpixels.substance.internal.utils.*;
45
* @author Kirill Grouchnikov
47
public class SubstanceToolBarBorder extends AbstractBorder implements
52
* @see javax.swing.border.Border#paintBorder(java.awt.Component,
53
* java.awt.Graphics, int, int, int, int)
56
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
57
// failsafe for LAF change
58
if (!SubstanceLookAndFeel.isCurrentLookAndFeel())
61
Graphics2D graphics = (Graphics2D) g;
62
graphics.translate(x, y);
64
if (((JToolBar) c).isFloatable()) {
65
SubstanceColorScheme scheme = SubstanceColorSchemeUtilities
66
.getColorScheme(c, ColorSchemeAssociationKind.SEPARATOR,
67
ComponentState.ENABLED);
68
int dragBumpsWidth = (int) (0.75 * SubstanceSizeUtils
69
.getToolBarDragInset(SubstanceSizeUtils
70
.getComponentFontSize(c)));
71
if (((JToolBar) c).getOrientation() == SwingConstants.HORIZONTAL) {
72
// fix for defect 3 on NB module
73
int height = c.getHeight() - 4;
75
if (c.getComponentOrientation().isLeftToRight()) {
76
graphics.drawImage(SubstanceImageCreator.getDragImage(
77
c, scheme, dragBumpsWidth, height, 2), 2, 1,
80
graphics.drawImage(SubstanceImageCreator.getDragImage(
81
c, scheme, dragBumpsWidth, height, 2), c
83
- dragBumpsWidth - 2, 1, null);
88
// fix for defect 3 on NB module
89
int width = c.getWidth() - 4;
91
graphics.drawImage(SubstanceImageCreator.getDragImage(c,
92
scheme, width, dragBumpsWidth, 2), 2, 2, null);
97
graphics.translate(-x, -y);
103
* @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
106
public Insets getBorderInsets(Component c) {
107
return this.getBorderInsets(c, new Insets(0, 0, 0, 0));
114
* javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component,
118
public Insets getBorderInsets(Component c, Insets newInsets) {
119
Insets defaultInsets = SubstanceSizeUtils
120
.getToolBarInsets(SubstanceSizeUtils.getComponentFontSize(c));
121
newInsets.set(defaultInsets.top, defaultInsets.left,
122
defaultInsets.bottom, defaultInsets.right);
124
JToolBar toolbar = (JToolBar) c;
125
if (toolbar.isFloatable()) {
126
int dragInset = SubstanceSizeUtils
127
.getToolBarDragInset(SubstanceSizeUtils
128
.getComponentFontSize(c));
129
if (toolbar.getOrientation() == SwingConstants.HORIZONTAL) {
130
if (toolbar.getComponentOrientation().isLeftToRight()) {
131
newInsets.left = dragInset;
133
newInsets.right = dragInset;
136
newInsets.top = dragInset;
140
Insets margin = toolbar.getMargin();
142
if (margin != null) {
143
newInsets.left += margin.left;
144
newInsets.top += margin.top;
145
newInsets.right += margin.right;
146
newInsets.bottom += margin.bottom;