~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/looks-2.2.2/src/core/com/jgoodies/looks/plastic/PlasticBorders.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2001-2009 JGoodies Karsten Lentzsch. 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 JGoodies Karsten Lentzsch 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
 
 
31
package com.jgoodies.looks.plastic;
 
32
 
 
33
import java.awt.Component;
 
34
import java.awt.Graphics;
 
35
import java.awt.Insets;
 
36
 
 
37
import javax.swing.*;
 
38
import javax.swing.border.AbstractBorder;
 
39
import javax.swing.border.Border;
 
40
import javax.swing.border.CompoundBorder;
 
41
import javax.swing.border.EmptyBorder;
 
42
import javax.swing.plaf.BorderUIResource;
 
43
import javax.swing.plaf.UIResource;
 
44
import javax.swing.plaf.basic.BasicBorders;
 
45
import javax.swing.plaf.metal.MetalBorders;
 
46
import javax.swing.text.JTextComponent;
 
47
 
 
48
 
 
49
/**
 
50
 * This class consists of a set of <code>Border</code>s used
 
51
 * by the JGoodies Plastic Look and Feel UI delegates.
 
52
 *
 
53
 * @author Karsten Lentzsch
 
54
 * @version $Revision: 1.2 $
 
55
 */
 
56
 
 
57
final class PlasticBorders {
 
58
 
 
59
    private PlasticBorders() {
 
60
        // Overrides default constructor; prevents instantiation.
 
61
    }
 
62
 
 
63
 
 
64
    // Accessing and Creating Borders ***************************************
 
65
 
 
66
    private static Border comboBoxEditorBorder;
 
67
    private static Border comboBoxArrowButtonBorder;
 
68
    private static Border etchedBorder;
 
69
    private static Border flush3DBorder;
 
70
    private static Border menuBarHeaderBorder;
 
71
    private static Border menuBorder;
 
72
    private static Border menuItemBorder;
 
73
    private static Border popupMenuBorder;
 
74
    private static Border noMarginPopupMenuBorder;
 
75
    private static Border rolloverButtonBorder;
 
76
    private static Border scrollPaneBorder;
 
77
    private static Border separatorBorder;
 
78
    private static Border textFieldBorder;
 
79
    private static Border thinLoweredBorder;
 
80
    private static Border thinRaisedBorder;
 
81
    private static Border toolBarHeaderBorder;
 
82
 
 
83
 
 
84
    /**
 
85
     * Returns a border instance for a <code>JButton</code>.
 
86
     *
 
87
     * @return the lazily created button border
 
88
     */
 
89
    static Border getButtonBorder(Insets buttonMargin) {
 
90
        return new BorderUIResource.CompoundBorderUIResource(
 
91
                                    new ButtonBorder(buttonMargin),
 
92
                                    new BasicBorders.MarginBorder());
 
93
    }
 
94
 
 
95
    /**
 
96
     * Returns a border for a <code>JComboBox</code>'s button.
 
97
     *
 
98
     * @return the lazily created combo box arrow button border
 
99
     */
 
100
    static Border getComboBoxArrowButtonBorder() {
 
101
        if (comboBoxArrowButtonBorder == null) {
 
102
            comboBoxArrowButtonBorder = new CompoundBorder(  // No UIResource
 
103
                    new ComboBoxArrowButtonBorder(),
 
104
                    new BasicBorders.MarginBorder());
 
105
        }
 
106
        return comboBoxArrowButtonBorder;
 
107
    }
 
108
 
 
109
    /**
 
110
     * Returns a border for a <code>JComboBox</code>'s editor.
 
111
     *
 
112
     * @return the lazily created combo box editor border
 
113
     */
 
114
    static Border getComboBoxEditorBorder() {
 
115
        if (comboBoxEditorBorder == null) {
 
116
            comboBoxEditorBorder = new CompoundBorder( // No UIResource
 
117
                            new ComboBoxEditorBorder(),
 
118
                            new BasicBorders.MarginBorder());
 
119
        }
 
120
        return comboBoxEditorBorder;
 
121
    }
 
122
 
 
123
    /**
 
124
     * Returns an etched border instance for <code>JMenuBar</code> or
 
125
     * <code>JToolBar</code>.
 
126
     *
 
127
     * @return the lazily created etched border
 
128
     */
 
129
    static Border getEtchedBorder() {
 
130
        if (etchedBorder == null) {
 
131
            etchedBorder = new BorderUIResource.CompoundBorderUIResource(
 
132
                                    new EtchedBorder(),
 
133
                                    new BasicBorders.MarginBorder());
 
134
        }
 
135
        return etchedBorder;
 
136
    }
 
137
 
 
138
    /**
 
139
     * Returns a flushed 3D border.
 
140
     *
 
141
     * @return the lazily created flushed 3D border
 
142
     */
 
143
    static Border getFlush3DBorder() {
 
144
        if (flush3DBorder == null) {
 
145
            flush3DBorder = new Flush3DBorder();
 
146
        }
 
147
        return flush3DBorder;
 
148
    }
 
149
 
 
150
    /**
 
151
     * Returns a border for a <code>JInternalFrame</code>.
 
152
     *
 
153
     * @return an internal frame border
 
154
     */
 
155
    static Border getInternalFrameBorder() {
 
156
        return new InternalFrameBorder();
 
157
    }
 
158
 
 
159
    /**
 
160
     * Returns a special border for a <code>JMenuBar</code> that
 
161
     * is used in a header just above a <code>JToolBar</code>.
 
162
     *
 
163
     * @return the lazily created menu bar header border
 
164
     */
 
165
    static Border getMenuBarHeaderBorder() {
 
166
        if (menuBarHeaderBorder == null) {
 
167
            menuBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
 
168
                                    new MenuBarHeaderBorder(),
 
169
                                    new BasicBorders.MarginBorder());
 
170
        }
 
171
        return menuBarHeaderBorder;
 
172
    }
 
173
 
 
174
    /**
 
175
     * Returns a border instance for a <code>JMenu</code>.
 
176
     *
 
177
     * @return the lazily created menu border
 
178
     */
 
179
    static Border getMenuBorder() {
 
180
        if (menuBorder == null) {
 
181
            menuBorder = new BorderUIResource.CompoundBorderUIResource(
 
182
                            new MenuBorder(),
 
183
                            new BasicBorders.MarginBorder());
 
184
        }
 
185
        return menuBorder;
 
186
    }
 
187
 
 
188
    /**
 
189
     * Returns a border instance for a <code>JMenuItem</code>.
 
190
     *
 
191
     * @return the lazily created menu item border
 
192
     */
 
193
    static Border getMenuItemBorder() {
 
194
        if (menuItemBorder == null) {
 
195
            menuItemBorder =
 
196
                new BorderUIResource(new BasicBorders.MarginBorder());
 
197
        }
 
198
        return menuItemBorder;
 
199
    }
 
200
 
 
201
    /**
 
202
     * Returns a border instance for a <code>JPopupMenu</code>.
 
203
     *
 
204
     * @return the lazily created popup menu border
 
205
     */
 
206
    static Border getPopupMenuBorder() {
 
207
        if (popupMenuBorder == null) {
 
208
            popupMenuBorder = new PopupMenuBorder();
 
209
        }
 
210
        return popupMenuBorder;
 
211
    }
 
212
 
 
213
    /**
 
214
     * Returns a border instance for a <code>JPopupMenu</code> that
 
215
     * has no (extra) margin.
 
216
     *
 
217
     * @return the lazily created no-margin popup menu border
 
218
     */
 
219
    static Border getNoMarginPopupMenuBorder() {
 
220
        if (noMarginPopupMenuBorder == null) {
 
221
            noMarginPopupMenuBorder = new NoMarginPopupMenuBorder();
 
222
        }
 
223
        return noMarginPopupMenuBorder;
 
224
    }
 
225
 
 
226
    /**
 
227
     * Returns a border for a <code>JInternalFrame</code>'s palette.
 
228
     *
 
229
     * @return a border for an internal frame in palette mode
 
230
     */
 
231
    static Border getPaletteBorder() {
 
232
        return new PaletteBorder();
 
233
    }
 
234
 
 
235
    /**
 
236
     * Returns a rollover border for buttons in a <code>JToolBar</code>.
 
237
     *
 
238
     * @return the lazily created rollover button border
 
239
     */
 
240
    static Border getRolloverButtonBorder() {
 
241
        if (rolloverButtonBorder == null) {
 
242
            rolloverButtonBorder = new CompoundBorder( // No UIResource
 
243
                                        new RolloverButtonBorder(),
 
244
                                        new RolloverMarginBorder());
 
245
        }
 
246
        return rolloverButtonBorder;
 
247
    }
 
248
 
 
249
    /**
 
250
     * Returns a separator border instance for <code>JScrollPane</code>.
 
251
     *
 
252
     * @return the lazily created scroll pane border
 
253
     */
 
254
    static Border getScrollPaneBorder() {
 
255
        if (scrollPaneBorder == null) {
 
256
            scrollPaneBorder = new ScrollPaneBorder();
 
257
        }
 
258
        return scrollPaneBorder;
 
259
    }
 
260
 
 
261
    /**
 
262
     * Returns a separator border instance for <code>JMenuBar</code> or
 
263
     * <code>JToolBar</code>.
 
264
     *
 
265
     * @return the lazily created separator border
 
266
     */
 
267
    static Border getSeparatorBorder() {
 
268
        if (separatorBorder == null) {
 
269
            separatorBorder = new BorderUIResource.CompoundBorderUIResource(
 
270
                                    new SeparatorBorder(),
 
271
                                    new BasicBorders.MarginBorder());
 
272
        }
 
273
        return separatorBorder;
 
274
    }
 
275
 
 
276
    /**
 
277
     * Returns a border instance for a JTextField.
 
278
     *
 
279
     * @return the lazily created text field border
 
280
     */
 
281
    static Border getTextFieldBorder() {
 
282
        if (textFieldBorder == null) {
 
283
            textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
 
284
                                    new TextFieldBorder(),
 
285
                                    new BasicBorders.MarginBorder());
 
286
        }
 
287
        return textFieldBorder;
 
288
    }
 
289
 
 
290
    /**
 
291
     * Returns a thin lowered border.
 
292
     *
 
293
     * @return the lazily created thin lowered border
 
294
     */
 
295
    static Border getThinLoweredBorder() {
 
296
        if (thinLoweredBorder == null) {
 
297
            thinLoweredBorder = new ThinLoweredBorder();
 
298
        }
 
299
        return thinLoweredBorder;
 
300
    }
 
301
 
 
302
    /**
 
303
     * Returns a thin raised border.
 
304
     *
 
305
     * @return the lazily created thin raised border
 
306
     */
 
307
    static Border getThinRaisedBorder() {
 
308
        if (thinRaisedBorder == null) {
 
309
            thinRaisedBorder = new ThinRaisedBorder();
 
310
        }
 
311
        return thinRaisedBorder;
 
312
    }
 
313
 
 
314
    /**
 
315
     * Returns a border instance for a JToggleButton.
 
316
     *
 
317
     * @return the lazily created toggle button border
 
318
     */
 
319
    static Border getToggleButtonBorder(Insets buttonMargin) {
 
320
        return new BorderUIResource.CompoundBorderUIResource(
 
321
                                    new ToggleButtonBorder(buttonMargin),
 
322
                                    new BasicBorders.MarginBorder());
 
323
    }
 
324
 
 
325
    /**
 
326
     * Returns a special border for a <code>JToolBar</code> that
 
327
     * is used in a header just below a <code>JMenuBar</code>.
 
328
     *
 
329
     * @return the lazily created toolbar header border
 
330
     */
 
331
    static Border getToolBarHeaderBorder() {
 
332
        if (toolBarHeaderBorder == null) {
 
333
            toolBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
 
334
                                    new ToolBarHeaderBorder(),
 
335
                                    new BasicBorders.MarginBorder());
 
336
        }
 
337
        return toolBarHeaderBorder;
 
338
    }
 
339
 
 
340
        private static class Flush3DBorder extends AbstractBorder implements UIResource {
 
341
 
 
342
                private static final Insets INSETS = new Insets(2, 2, 2, 2);
 
343
 
 
344
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
345
                        if (c.isEnabled())
 
346
                                PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
347
                        else
 
348
                                PlasticUtils.drawDisabledBorder(g, x, y, w, h);
 
349
                }
 
350
 
 
351
                public Insets getBorderInsets(Component c) { return INSETS; }
 
352
 
 
353
                public Insets getBorderInsets(Component c, Insets newInsets) {
 
354
                        newInsets.top    = INSETS.top;
 
355
                        newInsets.left   = INSETS.left;
 
356
                        newInsets.bottom = INSETS.bottom;
 
357
                        newInsets.right  = INSETS.right;
 
358
                        return newInsets;
 
359
                }
 
360
        }
 
361
 
 
362
 
 
363
        private static class ButtonBorder extends AbstractBorder implements UIResource {
 
364
 
 
365
        protected final Insets insets;
 
366
 
 
367
        protected ButtonBorder(Insets insets) {
 
368
            this.insets = insets;
 
369
        }
 
370
 
 
371
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
372
                        AbstractButton button = (AbstractButton) c;
 
373
                        ButtonModel model = button.getModel();
 
374
 
 
375
                        if (model.isEnabled()) {
 
376
                                boolean isPressed = model.isPressed() && model.isArmed();
 
377
                                boolean isDefault = button instanceof JButton
 
378
                                                                         && ((JButton) button).isDefaultButton();
 
379
 
 
380
                                if (isPressed && isDefault)
 
381
                                        PlasticUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
 
382
                                else if (isPressed)
 
383
                                        PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
 
384
                                else if (isDefault)
 
385
                                        PlasticUtils.drawDefaultButtonBorder(g, x, y, w, h, false);
 
386
                                else
 
387
                                        PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
 
388
                        } else { // disabled state
 
389
                                PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
 
390
                        }
 
391
                }
 
392
 
 
393
                public Insets getBorderInsets(Component c) { return insets; }
 
394
 
 
395
                public Insets getBorderInsets(Component c, Insets newInsets) {
 
396
                        newInsets.top    = insets.top;
 
397
                        newInsets.left   = insets.left;
 
398
                        newInsets.bottom = insets.bottom;
 
399
                        newInsets.right  = insets.right;
 
400
                        return newInsets;
 
401
                }
 
402
        }
 
403
 
 
404
 
 
405
        private static final class ComboBoxArrowButtonBorder extends AbstractBorder implements UIResource {
 
406
 
 
407
            protected static final Insets INSETS = new Insets(1, 1, 1, 1);
 
408
 
 
409
            public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
410
                AbstractButton button = (AbstractButton) c;
 
411
                ButtonModel model = button.getModel();
 
412
 
 
413
                if (model.isEnabled()) {
 
414
                    boolean isPressed = model.isPressed() && model.isArmed();
 
415
 
 
416
                    if (isPressed)
 
417
                        PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
 
418
                    else
 
419
                        PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
 
420
                } else {
 
421
                    PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
 
422
                }
 
423
            }
 
424
 
 
425
            public Insets getBorderInsets(Component c) { return INSETS; }
 
426
        }
 
427
 
 
428
 
 
429
        private static final class ComboBoxEditorBorder extends AbstractBorder {
 
430
 
 
431
        private static final Insets INSETS  = new Insets(2, 2, 2, 0);
 
432
 
 
433
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
434
            if (c.isEnabled())
 
435
                PlasticUtils.drawFlush3DBorder(g, x, y, w + 2, h);
 
436
            else {
 
437
                PlasticUtils.drawDisabledBorder(g, x, y, w + 2, h-1);
 
438
                g.setColor(UIManager.getColor("control"));
 
439
                g.drawLine(x, y + h-1, x + w, y + h-1);
 
440
            }
 
441
        }
 
442
 
 
443
        public Insets getBorderInsets(Component c) { return INSETS; }
 
444
    }
 
445
 
 
446
 
 
447
        /**
 
448
         * A border used for <code>JInternalFrame</code>s.
 
449
         */
 
450
    private static final class InternalFrameBorder extends AbstractBorder implements UIResource {
 
451
 
 
452
        private static final Insets NORMAL_INSETS        = new Insets(1, 1, 1, 1);
 
453
        private static final Insets MAXIMIZED_INSETS = new Insets(1, 1, 0, 0);
 
454
 
 
455
 
 
456
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
457
                        JInternalFrame frame = (JInternalFrame) c;
 
458
                        if (frame.isMaximum())
 
459
                                paintMaximizedBorder(g, x, y, w, h);
 
460
                        else
 
461
                PlasticUtils.drawThinFlush3DBorder(g, x, y, w, h);
 
462
                }
 
463
 
 
464
                private void paintMaximizedBorder(Graphics g, int x, int y, int w, int h) {
 
465
            g.translate(x, y);
 
466
            g.setColor(PlasticLookAndFeel.getControlHighlight());
 
467
            g.drawLine(0, 0, w - 2, 0);
 
468
            g.drawLine(0, 0, 0, h - 2);
 
469
            g.translate(-x, -y);
 
470
                }
 
471
 
 
472
            public Insets getBorderInsets(Component c) {
 
473
                return ((JInternalFrame) c).isMaximum() ? MAXIMIZED_INSETS : NORMAL_INSETS;
 
474
            }
 
475
    }
 
476
 
 
477
 
 
478
        /**
 
479
         * A border used for the palette of <code>JInternalFrame</code>s.
 
480
         */
 
481
    private static final class PaletteBorder extends AbstractBorder implements UIResource {
 
482
 
 
483
        private static final Insets INSETS = new Insets(1, 1, 1, 1);
 
484
 
 
485
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h ) {
 
486
                    g.translate(x,y);
 
487
                    g.setColor(PlasticLookAndFeel.getControlDarkShadow());
 
488
                    g.drawRect(0, 0, w-1, h-1);
 
489
                    g.translate(-x,-y);
 
490
                }
 
491
 
 
492
        public Insets getBorderInsets(Component c) { return INSETS; }
 
493
    }
 
494
 
 
495
 
 
496
        /**
 
497
         * A border that looks like a separator line; used for menu bars
 
498
     * and tool bars.
 
499
         */
 
500
        private static final class SeparatorBorder extends AbstractBorder implements UIResource {
 
501
 
 
502
                private static final Insets INSETS = new Insets(0, 0, 2, 1);
 
503
 
 
504
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
505
                        g.translate(x, y);
 
506
                        g.setColor( UIManager.getColor("Separator.foreground"));
 
507
                        g.drawLine( 0, h - 2, w - 1, h - 2 );
 
508
 
 
509
                        g.setColor( UIManager.getColor("Separator.background"));
 
510
                        g.drawLine( 0, h - 1, w - 1, h - 1 );
 
511
                        g.translate(-x, -y);
 
512
                }
 
513
                public Insets getBorderInsets(Component c) { return INSETS; }
 
514
        }
 
515
 
 
516
 
 
517
        private static final class ThinRaisedBorder extends AbstractBorder implements UIResource {
 
518
                private static final Insets INSETS = new Insets(2, 2, 2, 2);
 
519
 
 
520
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
521
                        PlasticUtils.drawThinFlush3DBorder(g, x, y, w, h);
 
522
                }
 
523
 
 
524
                public Insets getBorderInsets(Component c) { return INSETS; }
 
525
        }
 
526
 
 
527
 
 
528
        private static final class ThinLoweredBorder extends AbstractBorder implements UIResource {
 
529
                private static final Insets INSETS = new Insets(2, 2, 2, 2);
 
530
 
 
531
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
532
                        PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
 
533
                }
 
534
 
 
535
                public Insets getBorderInsets(Component c) { return INSETS; }
 
536
        }
 
537
 
 
538
 
 
539
        /**
 
540
         * A border used for menu bars and tool bars in
 
541
     * <code>HeaderStyle.SINGLE</code>. The bar is wrapped by an inner thin
 
542
     * raised border, which in turn is wrapped by an outer thin lowered
 
543
     * border.
 
544
         */
 
545
        private static final class EtchedBorder extends AbstractBorder implements UIResource {
 
546
 
 
547
                private static final Insets INSETS = new Insets(2, 2, 2, 2);
 
548
 
 
549
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
550
                        PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
 
551
                        PlasticUtils.drawThinFlush3DBorder  (g, x + 1, y + 1, w - 2, h - 2);
 
552
                }
 
553
 
 
554
                public Insets getBorderInsets(Component c) { return INSETS; }
 
555
        }
 
556
 
 
557
 
 
558
        /**
 
559
         * A border used for menu bars in <code>HeaderStyle.BOTH</code>.
 
560
         * The menu bar and tool bar are wrapped by a thin raised border,
 
561
         * both together are wrapped by a thin lowered border.
 
562
         */
 
563
        private static final class MenuBarHeaderBorder extends AbstractBorder implements UIResource {
 
564
 
 
565
                private static final Insets INSETS = new Insets(2, 2, 1, 2);
 
566
 
 
567
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
568
                        PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h + 1);
 
569
                        PlasticUtils.drawThinFlush3DBorder  (g, x + 1, y + 1, w - 2, h - 1);
 
570
                }
 
571
 
 
572
                public Insets getBorderInsets(Component c) { return INSETS; }
 
573
        }
 
574
 
 
575
 
 
576
        /**
 
577
         * A border used for tool bars in <code>HeaderStyle.BOTH</code>.
 
578
         * The menu bar and tool bar are wrapped by a thin raised border,
 
579
         * both together are wrapped by a thin lowered border.
 
580
         */
 
581
        private static final class ToolBarHeaderBorder extends AbstractBorder implements UIResource {
 
582
 
 
583
                private static final Insets INSETS = new Insets(1, 2, 2, 2);
 
584
 
 
585
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
586
                        PlasticUtils.drawThinPressed3DBorder(g, x, y - 1, w, h + 1);
 
587
                        PlasticUtils.drawThinFlush3DBorder  (g, x + 1, y, w - 2, h - 1);
 
588
                }
 
589
 
 
590
                public Insets getBorderInsets(Component c) { return INSETS; }
 
591
        }
 
592
 
 
593
 
 
594
        private static final class MenuBorder extends AbstractBorder implements UIResource {
 
595
        private static final Insets INSETS = new Insets( 2, 2, 2, 2 );
 
596
 
 
597
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
598
                        JMenuItem b = (JMenuItem) c;
 
599
                        ButtonModel model = b.getModel();
 
600
 
 
601
                        if (model.isArmed() || model.isSelected()) {
 
602
                    g.setColor(PlasticLookAndFeel.getControlDarkShadow());
 
603
                    g.drawLine(0, 0, w - 2, 0 );
 
604
                    g.drawLine(0, 0, 0, h - 1 );
 
605
                    //g.drawLine(w - 2, 2, w - 2, h - 1 );
 
606
 
 
607
                    g.setColor(PlasticLookAndFeel.getPrimaryControlHighlight());
 
608
                    g.drawLine(w - 1, 0, w - 1, h - 1 );
 
609
                        } else if (model.isRollover()) {
 
610
                                g.translate(x, y);
 
611
                                PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
612
                                g.translate(-x, -y);
 
613
                        }
 
614
                }
 
615
 
 
616
        public Insets getBorderInsets(Component c) { return INSETS; }
 
617
 
 
618
        public Insets getBorderInsets(Component c, Insets newInsets) {
 
619
                newInsets.top    = INSETS.top;
 
620
                newInsets.left   = INSETS.left;
 
621
                newInsets.bottom = INSETS.bottom;
 
622
                newInsets.right  = INSETS.right;
 
623
                return newInsets;
 
624
                }
 
625
        }
 
626
 
 
627
 
 
628
        private static final class PopupMenuBorder extends AbstractBorder implements UIResource {
 
629
                private static final Insets INSETS = new Insets(3, 3, 3, 3);
 
630
 
 
631
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
632
                        g.translate(x, y);
 
633
                        g.setColor(PlasticLookAndFeel.getControlDarkShadow());
 
634
                        g.drawRect(0, 0, w-1, h-1);
 
635
            g.setColor(PlasticLookAndFeel.getMenuItemBackground());
 
636
                        g.drawRect(1, 1, w-3, h-3);
 
637
                        g.drawRect(2, 2, w-5, h-5);
 
638
                        g.translate(-x, -y);
 
639
                }
 
640
 
 
641
                public Insets getBorderInsets(Component c) { return INSETS; }
 
642
        }
 
643
 
 
644
 
 
645
    private static final class NoMarginPopupMenuBorder extends AbstractBorder implements UIResource {
 
646
        private static final Insets INSETS = new Insets(1, 1, 1, 1);
 
647
 
 
648
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
649
            g.translate(x, y);
 
650
            g.setColor(PlasticLookAndFeel.getControlDarkShadow());
 
651
            g.drawRect(0, 0, w-1, h-1);
 
652
            g.translate(-x, -y);
 
653
        }
 
654
 
 
655
        public Insets getBorderInsets(Component c) { return INSETS; }
 
656
    }
 
657
 
 
658
 
 
659
        private static class RolloverButtonBorder extends ButtonBorder {
 
660
 
 
661
        private RolloverButtonBorder() {
 
662
            super(new Insets(3, 3, 3, 3));
 
663
        }
 
664
 
 
665
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
666
                        AbstractButton b = (AbstractButton) c;
 
667
                        ButtonModel model = b.getModel();
 
668
 
 
669
                        if (!model.isEnabled())
 
670
                                return;
 
671
 
 
672
                        if (!(c instanceof JToggleButton)) {
 
673
                if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
 
674
                                super.paintBorder( c, g, x, y, w, h );
 
675
                }
 
676
                                return;
 
677
                        }
 
678
 
 
679
                        //if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
 
680
                        //super.paintBorder( c, g, x, y, w, h );
 
681
                        //}
 
682
 
 
683
                        if (model.isRollover()) {
 
684
                                if (model.isPressed() && model.isArmed()) {
 
685
                                        PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
 
686
                                } else {
 
687
                                        PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
688
                                }
 
689
                        } else if (model.isSelected())
 
690
                                PlasticUtils.drawDark3DBorder(g, x, y, w, h);
 
691
                }
 
692
        }
 
693
 
 
694
 
 
695
    /**
 
696
     * A border which is like a Margin border but it will only honor the margin
 
697
     * if the margin has been explicitly set by the developer.
 
698
     */
 
699
        static final class RolloverMarginBorder extends EmptyBorder {
 
700
 
 
701
        RolloverMarginBorder() {
 
702
            super(1, 1, 1, 1);
 
703
        }
 
704
 
 
705
 
 
706
        public Insets getBorderInsets(Component c) {
 
707
            return getBorderInsets(c, new Insets(0, 0, 0, 0));
 
708
        }
 
709
 
 
710
 
 
711
        public Insets getBorderInsets(Component c, Insets insets) {
 
712
            Insets margin = null;
 
713
 
 
714
            if (c instanceof AbstractButton) {
 
715
                margin = ((AbstractButton) c).getMargin();
 
716
            }
 
717
            if (margin == null || margin instanceof UIResource) {
 
718
                // default margin so replace
 
719
                insets.left = left;
 
720
                insets.top = top;
 
721
                insets.right = right;
 
722
                insets.bottom = bottom;
 
723
            } else {
 
724
                // Margin which has been explicitly set by the user.
 
725
                insets.left = margin.left;
 
726
                insets.top = margin.top;
 
727
                insets.right = margin.right;
 
728
                insets.bottom = margin.bottom;
 
729
            }
 
730
            return insets;
 
731
        }
 
732
    }
 
733
 
 
734
        /**
 
735
         * Unlike Metal we don't paint the (misplaced) control color edges.
 
736
         * Being a subclass of MetalBorders.ScrollPaneBorders ensures that
 
737
         * the ScrollPaneUI will update the ScrollbarsFreeStanding property.
 
738
         */
 
739
        private static final class ScrollPaneBorder extends MetalBorders.ScrollPaneBorder {
 
740
 
 
741
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
742
                        g.translate(x, y);
 
743
 
 
744
                        g.setColor(PlasticLookAndFeel.getControlDarkShadow());
 
745
                        g.drawRect(0, 0, w - 2, h - 2);
 
746
                        g.setColor(PlasticLookAndFeel.getControlHighlight());
 
747
                        g.drawLine(w - 1, 0, w - 1, h - 1);
 
748
                        g.drawLine(0, h - 1, w - 1, h - 1);
 
749
 
 
750
                        g.translate(-x, -y);
 
751
                }
 
752
        }
 
753
 
 
754
 
 
755
    private static final class TextFieldBorder extends Flush3DBorder {
 
756
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
757
 
 
758
                        if (!(c instanceof JTextComponent)) {
 
759
                                // special case for non-text components (bug ID 4144840)
 
760
                                if (c.isEnabled()) {
 
761
                                        PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
762
                                } else {
 
763
                                        PlasticUtils.drawDisabledBorder(g, x, y, w, h);
 
764
                                }
 
765
                                return;
 
766
                        }
 
767
 
 
768
                        if (c.isEnabled() && ((JTextComponent) c).isEditable())
 
769
                                PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
770
                        else
 
771
                                PlasticUtils.drawDisabledBorder(g, x, y, w, h);
 
772
                }
 
773
        }
 
774
 
 
775
 
 
776
        private static final class ToggleButtonBorder extends ButtonBorder {
 
777
 
 
778
        private ToggleButtonBorder(Insets insets) {
 
779
            super(insets);
 
780
        }
 
781
 
 
782
                public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
 
783
                        if (!c.isEnabled()) {
 
784
                                PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
 
785
                        } else {
 
786
                                AbstractButton button = (AbstractButton) c;
 
787
                                ButtonModel    model  = button.getModel();
 
788
                                if (model.isPressed() && model.isArmed())
 
789
                                        PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
 
790
                                else if (model.isSelected())
 
791
                                        PlasticUtils.drawDark3DBorder(g, x, y, w, h);
 
792
                                else
 
793
                                        PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
 
794
                        }
 
795
                }
 
796
 
 
797
        }
 
798
 
 
799
 
 
800
}