jdk/src/java.desktop/share/classes/javax/swing/plaf/nimbus/ToolBarSeparatorPainter.java
author serb
Fri, 21 Jul 2017 16:27:35 -0700
changeset 47160 ac5434728c3b
parent 25859 3317bb8137f4
permissions -rw-r--r--
8134256: copy/paste duplicated tests in some condition statements Reviewed-by: azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     4
 *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    10
 *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    15
 * accompanied this code).
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    16
 *
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    23
 * questions.
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    24
 */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    25
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    26
package javax.swing.plaf.nimbus;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    27
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    28
import javax.swing.plaf.nimbus.AbstractRegionPainter.PaintContext.CacheMode;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    29
import java.awt.Dimension;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    30
import java.awt.Graphics2D;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    31
import java.awt.Insets;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    32
import javax.swing.JComponent;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    33
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    34
/**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    35
 * A special painter implementation for tool bar separators in Nimbus.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    36
 * The designer tool doesn't have support for painters which render
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    37
 * repeated patterns, but that's exactly what the toolbar separator design
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    38
 * is for Nimbus. This custom painter is designed to handle this situation.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    39
 * When support is added to the design tool / code generator to deal with
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    40
 * repeated patterns, then we can remove this class.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    41
 * <p>
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    42
 */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    43
final class ToolBarSeparatorPainter extends AbstractRegionPainter {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    44
    private static final int SPACE = 3;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    45
    private static final int INSET = 2;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    46
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    47
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    48
    protected PaintContext getPaintContext() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    49
        //the paint context returned will have a few dummy values. The
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    50
        //implementation of doPaint doesn't bother with the "decode" methods
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    51
        //but calculates where to paint the circles manually. As such, we
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    52
        //only need to indicate in our PaintContext that we don't want this
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    53
        //to ever be cached
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    54
        return new PaintContext(
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    55
                new Insets(1, 0, 1, 0),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    56
                new Dimension(38, 7),
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    57
                false, CacheMode.NO_CACHING, 1, 1);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    58
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    59
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    60
    @Override
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    61
    protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    62
        //it is assumed that in the normal orientation the separator renders
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    63
        //horizontally. Other code rotates it as necessary for a vertical
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    64
        //separator.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    65
        g.setColor(c.getForeground());
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    66
        int y = height / 2;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    67
        for (int i=INSET; i<=width-INSET; i+=SPACE) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    68
            g.fillRect(i, y, 1, 1);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    69
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    70
    }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents:
diff changeset
    71
}