~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/utils/border/SubstanceToolBarBorder.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
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. 
 
13
 *     
 
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. 
 
17
 *     
 
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. 
 
29
 */
 
30
package org.pushingpixels.substance.internal.utils.border;
 
31
 
 
32
import java.awt.*;
 
33
 
 
34
import javax.swing.JToolBar;
 
35
import javax.swing.SwingConstants;
 
36
import javax.swing.border.AbstractBorder;
 
37
import javax.swing.plaf.UIResource;
 
38
 
 
39
import org.pushingpixels.substance.api.*;
 
40
import org.pushingpixels.substance.internal.utils.*;
 
41
 
 
42
/**
 
43
 * Border for toolbar.
 
44
 * 
 
45
 * @author Kirill Grouchnikov
 
46
 */
 
47
public class SubstanceToolBarBorder extends AbstractBorder implements
 
48
                UIResource {
 
49
        /*
 
50
         * (non-Javadoc)
 
51
         * 
 
52
         * @see javax.swing.border.Border#paintBorder(java.awt.Component,
 
53
         * java.awt.Graphics, int, int, int, int)
 
54
         */
 
55
        @Override
 
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())
 
59
                        return;
 
60
 
 
61
                Graphics2D graphics = (Graphics2D) g;
 
62
                graphics.translate(x, y);
 
63
 
 
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;
 
74
                                if (height > 0) {
 
75
                                        if (c.getComponentOrientation().isLeftToRight()) {
 
76
                                                graphics.drawImage(SubstanceImageCreator.getDragImage(
 
77
                                                                c, scheme, dragBumpsWidth, height, 2), 2, 1,
 
78
                                                                null);
 
79
                                        } else {
 
80
                                                graphics.drawImage(SubstanceImageCreator.getDragImage(
 
81
                                                                c, scheme, dragBumpsWidth, height, 2), c
 
82
                                                                .getBounds().width
 
83
                                                                - dragBumpsWidth - 2, 1, null);
 
84
                                        }
 
85
                                }
 
86
                        } else // vertical
 
87
                        {
 
88
                                // fix for defect 3 on NB module
 
89
                                int width = c.getWidth() - 4;
 
90
                                if (width > 0) {
 
91
                                        graphics.drawImage(SubstanceImageCreator.getDragImage(c,
 
92
                                                        scheme, width, dragBumpsWidth, 2), 2, 2, null);
 
93
                                }
 
94
                        }
 
95
                }
 
96
 
 
97
                graphics.translate(-x, -y);
 
98
        }
 
99
 
 
100
        /*
 
101
         * (non-Javadoc)
 
102
         * 
 
103
         * @see javax.swing.border.Border#getBorderInsets(java.awt.Component)
 
104
         */
 
105
        @Override
 
106
        public Insets getBorderInsets(Component c) {
 
107
                return this.getBorderInsets(c, new Insets(0, 0, 0, 0));
 
108
        }
 
109
 
 
110
        /*
 
111
         * (non-Javadoc)
 
112
         * 
 
113
         * @see
 
114
         * javax.swing.border.AbstractBorder#getBorderInsets(java.awt.Component,
 
115
         * java.awt.Insets)
 
116
         */
 
117
        @Override
 
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);
 
123
 
 
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;
 
132
                                } else {
 
133
                                        newInsets.right = dragInset;
 
134
                                }
 
135
                        } else {// vertical
 
136
                                newInsets.top = dragInset;
 
137
                        }
 
138
                }
 
139
 
 
140
                Insets margin = toolbar.getMargin();
 
141
 
 
142
                if (margin != null) {
 
143
                        newInsets.left += margin.left;
 
144
                        newInsets.top += margin.top;
 
145
                        newInsets.right += margin.right;
 
146
                        newInsets.bottom += margin.bottom;
 
147
                }
 
148
 
 
149
                return newInsets;
 
150
        }
 
151
}