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.common;
032:
033: import java.awt.Dimension;
034: import java.awt.Graphics;
035: import java.awt.Insets;
036:
037: import javax.swing.JComponent;
038: import javax.swing.JSeparator;
039: import javax.swing.UIManager;
040: import javax.swing.plaf.ComponentUI;
041: import javax.swing.plaf.basic.BasicPopupMenuSeparatorUI;
042:
043: /**
044: * Renders the separator in popup and pull-down menus.
045: * Unlike its superclass we use a setting for the insets and
046: * it uses a shared UI delegate.
047: *
048: * @author Karsten Lentzsch
049: * @version $Revision: 1.3 $
050: */
051: public final class ExtBasicPopupMenuSeparatorUI extends
052: BasicPopupMenuSeparatorUI {
053:
054: private static final int SEPARATOR_HEIGHT = 2;
055:
056: private Insets insets;
057:
058: /** Shared UI object. */
059: private static ComponentUI popupMenuSeparatorUI;
060:
061: public static ComponentUI createUI(JComponent b) {
062: if (popupMenuSeparatorUI == null) {
063: popupMenuSeparatorUI = new ExtBasicPopupMenuSeparatorUI();
064: }
065: return popupMenuSeparatorUI;
066: }
067:
068: protected void installDefaults(JSeparator s) {
069: super .installDefaults(s);
070: insets = UIManager.getInsets("PopupMenuSeparator.margin");
071: }
072:
073: public void paint(Graphics g, JComponent c) {
074: Dimension s = c.getSize();
075:
076: int topInset = insets.top;
077: int leftInset = insets.left;
078: int rightInset = insets.right;
079:
080: // Paint background
081: g.setColor(UIManager.getColor("MenuItem.background"));
082: g.fillRect(0, 0, s.width, s.height);
083:
084: // Draw side
085: /*
086: g.setColor(UIManager.getColor("controlHighlight"));
087: g.drawLine(0, 0, 0, s.height -1);
088: g.drawLine(s.width-1, 0, s.width-1, s.height-1);
089: */
090:
091: g.translate(0, topInset);
092: g.setColor(c.getForeground());
093: g.drawLine(leftInset, 0, s.width - rightInset, 0);
094:
095: g.setColor(c.getBackground());
096: g.drawLine(leftInset, 1, s.width - rightInset, 1);
097: g.translate(0, -topInset);
098: }
099:
100: public Dimension getPreferredSize(JComponent c) {
101: return new Dimension(0, insets.top + SEPARATOR_HEIGHT
102: + insets.bottom);
103: }
104:
105: }
|