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

« back to all changes in this revision

Viewing changes to substance-swingx/src/main/java/org/pushingpixels/substance/swingx/SubstanceSwingxPlugin.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 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.Color;
 
22
import java.awt.Component;
 
23
import java.awt.Font;
 
24
import java.awt.Graphics2D;
 
25
import java.awt.Rectangle;
 
26
 
 
27
import javax.swing.JComponent;
 
28
import javax.swing.SwingConstants;
 
29
import javax.swing.UIDefaults;
 
30
import javax.swing.plaf.ColorUIResource;
 
31
import javax.swing.plaf.FontUIResource;
 
32
import javax.swing.plaf.IconUIResource;
 
33
 
 
34
import org.jdesktop.swingx.JXDatePicker;
 
35
import org.jdesktop.swingx.JXErrorPane;
 
36
import org.jdesktop.swingx.JXHeader;
 
37
import org.jdesktop.swingx.JXHyperlink;
 
38
import org.jdesktop.swingx.JXLoginPane;
 
39
import org.jdesktop.swingx.JXMonthView;
 
40
import org.jdesktop.swingx.JXStatusBar;
 
41
import org.jdesktop.swingx.JXTaskPane;
 
42
import org.jdesktop.swingx.JXTaskPaneContainer;
 
43
import org.jdesktop.swingx.JXTipOfTheDay;
 
44
import org.jdesktop.swingx.JXTitledPanel;
 
45
import org.jdesktop.swingx.painter.Painter;
 
46
import org.jdesktop.swingx.plaf.PainterUIResource;
 
47
import org.pushingpixels.lafplugin.LafComponentPlugin;
 
48
import org.pushingpixels.substance.api.ColorSchemeAssociationKind;
 
49
import org.pushingpixels.substance.api.ComponentState;
 
50
import org.pushingpixels.substance.api.DecorationAreaType;
 
51
import org.pushingpixels.substance.api.SubstanceColorScheme;
 
52
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
 
53
import org.pushingpixels.substance.api.SubstanceSkin;
 
54
import org.pushingpixels.substance.api.fonts.FontSet;
 
55
import org.pushingpixels.substance.internal.painter.BackgroundPaintingUtils;
 
56
import org.pushingpixels.substance.internal.painter.DecorationPainterUtils;
 
57
import org.pushingpixels.substance.internal.utils.SubstanceColorUtilities;
 
58
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
 
59
import org.pushingpixels.substance.internal.utils.SubstanceImageCreator;
 
60
import org.pushingpixels.substance.internal.utils.SubstanceSizeUtils;
 
61
import org.pushingpixels.substance.internal.utils.border.SubstanceBorder;
 
62
 
 
63
/**
 
64
 * Substance plugin for <a href="https://swingx.dev.java.net">SwingX</a>
 
65
 * components.
 
66
 * 
 
67
 * @author Kirill Grouchnikov
 
68
 */
 
69
public class SubstanceSwingxPlugin implements LafComponentPlugin {
 
70
 
 
71
        /**
 
72
         * Creates a plugin instance.
 
73
         */
 
74
        public SubstanceSwingxPlugin() {
 
75
        }
 
76
 
 
77
        public Object[] getDefaults(Object mSkin) {
 
78
                SubstanceSkin skin = (SubstanceSkin) mSkin;
 
79
                final SubstanceColorScheme mainActiveScheme = skin
 
80
                                .getActiveColorScheme(DecorationAreaType.NONE);
 
81
                SubstanceColorScheme mainEnabledScheme = skin
 
82
                                .getEnabledColorScheme(DecorationAreaType.NONE);
 
83
                SubstanceColorScheme mainDisabledScheme = skin
 
84
                                .getDisabledColorScheme(DecorationAreaType.NONE);
 
85
                Color foregroundColor = SubstanceColorUtilities
 
86
                                .getForegroundColor(mainEnabledScheme);
 
87
                Color backgroundColor = new ColorUIResource(mainActiveScheme
 
88
                                .getBackgroundFillColor());
 
89
                Color disabledForegroundColor = SubstanceColorUtilities
 
90
                                .getForegroundColor(mainDisabledScheme);
 
91
 
 
92
                SubstanceColorScheme highlightColorScheme = skin.getColorScheme(
 
93
                                (Component) null, ColorSchemeAssociationKind.HIGHLIGHT,
 
94
                                ComponentState.SELECTED);
 
95
                if (highlightColorScheme == null) {
 
96
                        highlightColorScheme = skin.getColorScheme(null,
 
97
                                        ComponentState.ROLLOVER_SELECTED);
 
98
                }
 
99
 
 
100
                Color selectionBackgroundColor = new ColorUIResource(
 
101
                                highlightColorScheme.getSelectionBackgroundColor());
 
102
 
 
103
                Color selectionForegroundColor = new ColorUIResource(
 
104
                                highlightColorScheme.getSelectionForegroundColor());
 
105
 
 
106
                FontSet fontSet = SubstanceLookAndFeel.getFontPolicy().getFontSet(
 
107
                                "Substance", null);
 
108
 
 
109
                Font controlFont = fontSet.getControlFont();
 
110
 
 
111
                Painter titlePanelPainter = new Painter() {
 
112
                        public void paint(Graphics2D g, Object jxTitledPanel, int width,
 
113
                                        int height) {
 
114
                                JComponent titledPanel = (JComponent) jxTitledPanel;
 
115
                                Graphics2D g2d = (Graphics2D) g.create();
 
116
                                // g2d.translate(10, 10);
 
117
                                DecorationAreaType decorationType = SubstanceLookAndFeel
 
118
                                                .getDecorationType(titledPanel);
 
119
                                if ((decorationType != null)
 
120
                                                && (SubstanceCoreUtilities.getSkin(titledPanel)
 
121
                                                                .isRegisteredAsDecorationArea(decorationType))) {
 
122
                                        DecorationPainterUtils.paintDecorationBackground(g2d,
 
123
                                                        titledPanel, false);
 
124
                                } else {
 
125
                                        BackgroundPaintingUtils.fillAndWatermark(g2d, titledPanel,
 
126
                                                        SubstanceCoreUtilities.getSkin(titledPanel)
 
127
                                                                        .getBackgroundColorScheme(decorationType)
 
128
                                                                        .getBackgroundFillColor(), new Rectangle(0,
 
129
                                                                        0, titledPanel.getWidth(), titledPanel
 
130
                                                                                        .getHeight()));
 
131
                                }
 
132
                                g2d.dispose();
 
133
                        }
 
134
                };
 
135
 
 
136
                SubstanceColorScheme headerDecorationTheme = skin
 
137
                                .getEnabledColorScheme(DecorationAreaType.HEADER);
 
138
                Color titlePaneForeground = new ColorUIResource(SubstanceColorUtilities
 
139
                                .getForegroundColor(headerDecorationTheme));
 
140
 
 
141
                Object[] defaults = new Object[] {
 
142
 
 
143
                                JXDatePicker.uiClassID,
 
144
                                "org.pushingpixels.substance.swingx.SubstanceDatePickerUI",
 
145
 
 
146
                                JXMonthView.uiClassID,
 
147
                                "org.pushingpixels.substance.swingx.SubstanceMonthViewUI",
 
148
 
 
149
                                JXTaskPaneContainer.uiClassID,
 
150
                                "org.pushingpixels.substance.swingx.SubstanceTaskPaneContainerUI",
 
151
 
 
152
                                JXTaskPane.uiClassID,
 
153
                                "org.pushingpixels.substance.swingx.SubstanceTaskPaneUI",
 
154
 
 
155
                                JXStatusBar.uiClassID,
 
156
                                "org.pushingpixels.substance.swingx.SubstanceStatusBarUI",
 
157
 
 
158
                                JXHeader.uiClassID,
 
159
                                "org.pushingpixels.substance.swingx.SubstanceHeaderUI",
 
160
 
 
161
                                JXLoginPane.uiClassID,
 
162
                                "org.pushingpixels.substance.swingx.SubstanceLoginPaneUI",
 
163
 
 
164
                                JXTipOfTheDay.uiClassID,
 
165
                                "org.pushingpixels.substance.swingx.SubstanceTipOfTheDayUI",
 
166
 
 
167
                                JXTitledPanel.uiClassID,
 
168
                                "org.pushingpixels.substance.swingx.SubstanceTitledPanelUI",
 
169
 
 
170
                                JXErrorPane.uiClassID,
 
171
                                "org.pushingpixels.substance.swingx.SubstanceErrorPaneUI",
 
172
 
 
173
                                JXHyperlink.uiClassID,
 
174
                                "org.pushingpixels.substance.swingx.SubstanceHyperlinkUI",
 
175
 
 
176
                                "PanelUI",
 
177
                                "org.pushingpixels.substance.swingx.SubstancePanelUI",
 
178
 
 
179
                                "TableUI",
 
180
                                "org.pushingpixels.substance.swingx.SubstanceTableUI",
 
181
 
 
182
                                "ColumnHeaderRenderer.upIcon",
 
183
                                new UIDefaults.LazyValue() {
 
184
                                        @Override
 
185
                                        public Object createValue(UIDefaults table) {
 
186
                                                return new IconUIResource(SubstanceImageCreator
 
187
                                                                .getArrowIcon(SubstanceSizeUtils
 
188
                                                                                .getControlFontSize(),
 
189
                                                                                SwingConstants.NORTH, mainActiveScheme));
 
190
                                        }
 
191
                                },
 
192
 
 
193
                                "ColumnHeaderRenderer.downIcon",
 
194
                                new UIDefaults.LazyValue() {
 
195
                                        @Override
 
196
                                        public Object createValue(UIDefaults table) {
 
197
                                                return new IconUIResource(SubstanceImageCreator
 
198
                                                                .getArrowIcon(SubstanceSizeUtils
 
199
                                                                                .getControlFontSize(),
 
200
                                                                                SwingConstants.SOUTH, mainActiveScheme));
 
201
                                        }
 
202
                                },
 
203
 
 
204
                                "JXDatePicker.arrowIcon",
 
205
                                new UIDefaults.LazyValue() {
 
206
                                        @Override
 
207
                                        public Object createValue(UIDefaults table) {
 
208
                                                return new IconUIResource(SubstanceImageCreator
 
209
                                                                .getArrowIcon(SubstanceSizeUtils
 
210
                                                                                .getControlFontSize(),
 
211
                                                                                SwingConstants.SOUTH, mainActiveScheme));
 
212
                                        }
 
213
                                },
 
214
 
 
215
                                "JXLoginPane.bannerFont",
 
216
                                new FontUIResource(controlFont.deriveFont(3.0f * controlFont
 
217
                                                .getSize())),
 
218
 
 
219
                                "JXLoginPane.bannerForeground",
 
220
                                new ColorUIResource(SubstanceColorUtilities
 
221
                                                .getNegativeColor(foregroundColor)),
 
222
 
 
223
                                "JXLoginPane.bannerLightBackground",
 
224
                                new ColorUIResource(
 
225
                                                mainActiveScheme.isDark() ? mainActiveScheme
 
226
                                                                .getUltraLightColor() : mainActiveScheme
 
227
                                                                .getLightColor()),
 
228
 
 
229
                                "JXLoginPane.bannerDarkBackground",
 
230
                                new ColorUIResource(
 
231
                                                mainActiveScheme.isDark() ? mainActiveScheme
 
232
                                                                .getLightColor() : mainActiveScheme
 
233
                                                                .getMidColor()),
 
234
 
 
235
                                "JXMonthView.background",
 
236
                                backgroundColor,
 
237
 
 
238
                                "JXMonthView.foreground",
 
239
                                foregroundColor,
 
240
 
 
241
                                "JXMonthView.monthStringBackground",
 
242
                                backgroundColor,
 
243
 
 
244
                                "JXMonthView.monthStringForeground",
 
245
                                foregroundColor,
 
246
 
 
247
                                "JXMonthView.daysOfTheWeekForeground",
 
248
                                foregroundColor,
 
249
 
 
250
                                "JXMonthView.weekOfTheYearForeground",
 
251
                                foregroundColor,
 
252
 
 
253
                                "JXMonthView.unselectableDayForeground",
 
254
                                new ColorUIResource(Color.RED),
 
255
 
 
256
                                "JXMonthView.selectedBackground",
 
257
                                selectionBackgroundColor,
 
258
 
 
259
                                "JXMonthView.selectedForeground",
 
260
                                selectionForegroundColor,
 
261
 
 
262
                                "JXMonthView.flaggedDayForeground",
 
263
                                new ColorUIResource(Color.RED),
 
264
 
 
265
                                "JXMonthView.leadingDayForeground",
 
266
                                disabledForegroundColor,
 
267
 
 
268
                                "JXMonthView.trailingDayForeground",
 
269
                                disabledForegroundColor,
 
270
 
 
271
                                "TaskPane.titleForeground",
 
272
                                foregroundColor,
 
273
 
 
274
                                "TaskPane.titleOver",
 
275
                                foregroundColor,
 
276
 
 
277
                                "TaskPane.specialTitleForeground",
 
278
                                foregroundColor,
 
279
 
 
280
                                "TaskPane.specialTitleOver",
 
281
                                foregroundColor,
 
282
 
 
283
                                "TaskPaneContainer.background",
 
284
                                backgroundColor,
 
285
                                // new ColorUIResource(new SubstanceComplexTheme("dummy",
 
286
                                // activeTitleTheme.getKind(), null, activeTitleTheme,
 
287
                                // null, null).getBackgroundColor()),
 
288
 
 
289
                                "TaskPaneContainer.backgroundPainter",
 
290
                                null,
 
291
 
 
292
                                "TaskPane.background",
 
293
                                backgroundColor,
 
294
 
 
295
                                "TaskPane.foreground",
 
296
                                foregroundColor,
 
297
 
 
298
                                "TaskPane.font",
 
299
                                new FontUIResource(controlFont.deriveFont(Font.BOLD)),
 
300
 
 
301
                                "TipOfTheDay.background",
 
302
                                backgroundColor.darker(),
 
303
 
 
304
                                "TipOfTheDay.foreground",
 
305
                                foregroundColor,
 
306
 
 
307
                                "TipOfTheDay.font",
 
308
                                new FontUIResource(controlFont),
 
309
 
 
310
                                "TipOfTheDay.tipFont",
 
311
                                new FontUIResource(controlFont.deriveFont(4.0f + controlFont
 
312
                                                .getSize())),
 
313
 
 
314
                                "TipOfTheDay.border", new SubstanceBorder(),
 
315
 
 
316
                                "TitledBorder.font", new FontUIResource(controlFont),
 
317
 
 
318
                                "TitledBorder.titleColor", foregroundColor,
 
319
 
 
320
                                "JXTitledPanel.titleForeground", titlePaneForeground,
 
321
 
 
322
                                "JXTitledPanel.titleFont",
 
323
                                new FontUIResource(controlFont.deriveFont(Font.BOLD)),
 
324
 
 
325
                                "JXTitledPanel.titlePainter",
 
326
                                new PainterUIResource(titlePanelPainter),
 
327
 
 
328
                                "JXHeader.titleForeground", titlePaneForeground,
 
329
 
 
330
                                "JXHeader.descriptionForeground", titlePaneForeground, };
 
331
 
 
332
                return defaults;
 
333
        }
 
334
 
 
335
        public void initialize() {
 
336
        }
 
337
 
 
338
        public void uninitialize() {
 
339
        }
 
340
}