001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Color;
023: import java.awt.Dimension;
024: import java.awt.Graphics;
025:
026: import javax.swing.JComponent;
027: import javax.swing.JSeparator;
028: import javax.swing.LookAndFeel;
029: import javax.swing.SwingConstants;
030: import javax.swing.plaf.ComponentUI;
031: import javax.swing.plaf.SeparatorUI;
032:
033: import org.apache.harmony.x.swing.Utilities;
034:
035: public class BasicSeparatorUI extends SeparatorUI {
036:
037: private static final String PROPERTY_PREFIX = "Separator.";
038:
039: protected Color shadow;
040: protected Color highlight;
041:
042: public static ComponentUI createUI(final JComponent c) {
043: return new BasicSeparatorUI();
044: }
045:
046: public void installUI(final JComponent c) {
047: installDefaults((JSeparator) c);
048: installListeners((JSeparator) c);
049: }
050:
051: public void uninstallUI(final JComponent c) {
052: uninstallListeners((JSeparator) c);
053: uninstallDefaults((JSeparator) c);
054: }
055:
056: protected void installDefaults(final JSeparator s) {
057: LookAndFeel.installColors(s, PROPERTY_PREFIX + "background",
058: PROPERTY_PREFIX + "foreground");
059: }
060:
061: protected void uninstallDefaults(final JSeparator s) {
062: if (s == null) {
063: return;
064: }
065: Utilities.uninstallColorsAndFont(s);
066: }
067:
068: protected void installListeners(final JSeparator s) {
069: }
070:
071: protected void uninstallListeners(final JSeparator s) {
072: }
073:
074: public void paint(final Graphics g, final JComponent c) {
075: Dimension size = c.getSize();
076: Color oldColor = g.getColor();
077: if (((JSeparator) c).getOrientation() == SwingConstants.HORIZONTAL) {
078: g.setColor(c.getForeground());
079: g.drawLine(0, 0, size.width, 0);
080: g.setColor(c.getBackground());
081: g.drawLine(0, 1, size.width, 1);
082: } else {
083: g.setColor(c.getForeground());
084: g.drawLine(0, 0, 0, size.height);
085: g.setColor(c.getBackground());
086: g.drawLine(1, 0, 1, size.height);
087: }
088: g.setColor(oldColor);
089: }
090:
091: public Dimension getPreferredSize(final JComponent c) {
092: return ((JSeparator) c).getOrientation() == SwingConstants.HORIZONTAL ? new Dimension(
093: 0, 2)
094: : new Dimension(2, 0);
095: }
096:
097: public Dimension getMinimumSize(final JComponent c) {
098: return null;
099: }
100:
101: public Dimension getMaximumSize(final JComponent c) {
102: return null;
103: }
104:
105: }
|