001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.windows;
032:
033: import java.awt.Color;
034: import java.awt.Dimension;
035: import java.awt.Graphics;
036:
037: import javax.swing.UIManager;
038: import javax.swing.plaf.basic.BasicArrowButton;
039:
040: /**
041: * The JGoodies Windows Look&Feel implementation for
042: * arrow buttons used in scrollbars and comboboxes.
043: * <p>
044: * It differs from <code>BasicArrowButton</code> in that the preferred size
045: * is always a square.
046: * It differs from <code>WindowsScrollBarUI.WindowsArrowButton</code>
047: * in that the triangle is black and positioned correctly.
048: *
049: * @author Karsten Lentzsch
050: * @version $Revision: 1.3 $
051: */
052: final class WindowsArrowButton extends BasicArrowButton {
053:
054: public WindowsArrowButton(int direction) {
055: super (direction);
056: }
057:
058: public Dimension getPreferredSize() {
059: int width = Math.max(5, UIManager.getInt("ScrollBar.width"));
060: return new Dimension(width, width);
061: }
062:
063: public void paintTriangle(Graphics g, int x, int y, int size,
064: int triangleDirection, boolean isEnabled) {
065: Color oldColor = g.getColor();
066: int mid, i, j;
067:
068: j = 0;
069: size = Math.max(size, 2);
070: mid = (size - 1) / 2; // Modified by JGoodies
071:
072: g.translate(x, y);
073: if (isEnabled)
074: g.setColor(Color.black);
075: else
076: g.setColor(UIManager.getColor("controlShadow"));
077:
078: switch (triangleDirection) {
079: case NORTH:
080: for (i = 0; i < size; i++) {
081: g.drawLine(mid - i, i, mid + i, i);
082: }
083: if (!isEnabled) {
084: g.setColor(UIManager.getColor("controlLtHighlight"));
085: g.drawLine(mid - i + 2, i, mid + i, i);
086: }
087: break;
088: case SOUTH:
089: if (!isEnabled) {
090: g.translate(1, 1);
091: g.setColor(UIManager.getColor("controlLtHighlight"));
092: for (i = size - 1; i >= 0; i--) {
093: g.drawLine(mid - i, j, mid + i, j);
094: j++;
095: }
096: g.translate(-1, -1);
097: g.setColor(UIManager.getColor("controlShadow"));
098: }
099:
100: j = 0;
101: for (i = size - 1; i >= 0; i--) {
102: g.drawLine(mid - i, j, mid + i, j);
103: j++;
104: }
105: break;
106: case WEST:
107: for (i = 0; i < size; i++) {
108: g.drawLine(i, mid - i, i, mid + i);
109: }
110: if (!isEnabled) {
111: g.setColor(UIManager.getColor("controlLtHighlight"));
112: g.drawLine(i, mid - i + 2, i, mid + i);
113: }
114: break;
115: case EAST:
116: if (!isEnabled) {
117: g.translate(1, 1);
118: g.setColor(UIManager.getColor("controlLtHighlight"));
119: for (i = size - 1; i >= 0; i--) {
120: g.drawLine(j, mid - i, j, mid + i);
121: j++;
122: }
123: g.translate(-1, -1);
124: g.setColor(UIManager.getColor("controlShadow"));
125: }
126:
127: j = 0;
128: for (i = size - 1; i >= 0; i--) {
129: g.drawLine(j, mid - i, j, mid + i);
130: j++;
131: }
132: break;
133: }
134: g.translate(-x, -y);
135: g.setColor(oldColor);
136: }
137: }
|