1173N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
1173N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1173N/A *
1173N/A * This code is free software; you can redistribute it and/or modify it
1173N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1173N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1173N/A *
1173N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1173N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1173N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1173N/A * version 2 for more details (a copy is included in the LICENSE file that
1173N/A * accompanied this code).
1173N/A *
1173N/A * You should have received a copy of the GNU General Public License version
1173N/A * 2 along with this work; if not, write to the Free Software Foundation,
1173N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1173N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1173N/A */
1173N/A
1173N/Apackage javax.swing.plaf.nimbus;
1173N/A
1173N/Aimport javax.swing.plaf.nimbus.AbstractRegionPainter.PaintContext.CacheMode;
1173N/Aimport java.awt.Dimension;
1173N/Aimport java.awt.Graphics2D;
1173N/Aimport java.awt.Insets;
1173N/Aimport javax.swing.JComponent;
1173N/A
1173N/A/**
1173N/A * A special painter implementation for tool bar separators in Nimbus.
1173N/A * The designer tool doesn't have support for painters which render
1173N/A * repeated patterns, but that's exactly what the toolbar separator design
1173N/A * is for Nimbus. This custom painter is designed to handle this situation.
1173N/A * When support is added to the design tool / code generator to deal with
1173N/A * repeated patterns, then we can remove this class.
1173N/A * <p>
1173N/A */
1173N/Afinal class ToolBarSeparatorPainter extends AbstractRegionPainter {
1173N/A private static final int SPACE = 3;
1173N/A private static final int INSET = 2;
1173N/A
1173N/A @Override
1173N/A protected PaintContext getPaintContext() {
1173N/A //the paint context returned will have a few dummy values. The
1173N/A //implementation of doPaint doesn't bother with the "decode" methods
1173N/A //but calculates where to paint the circles manually. As such, we
1173N/A //only need to indicate in our PaintContext that we don't want this
1173N/A //to ever be cached
1173N/A return new PaintContext(
1173N/A new Insets(1, 0, 1, 0),
1173N/A new Dimension(38, 7),
1173N/A false, CacheMode.NO_CACHING, 1, 1);
1173N/A }
1173N/A
1173N/A @Override
1173N/A protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
1173N/A //it is assumed that in the normal orientation the separator renders
1173N/A //horizontally. Other code rotates it as necessary for a vertical
1173N/A //separator.
1173N/A g.setColor(c.getForeground());
1173N/A int y = height / 2;
1173N/A for (int i=INSET; i<=width-INSET; i+=SPACE) {
1173N/A g.fillRect(i, y, 1, 1);
1173N/A }
1173N/A }
1173N/A}