LabelBar.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) LabelBar.java 1.25 - last change made 07/25/97
*/
/* BEGIN JSTYLED */
/**
* Displays a 3D bar with text within it. Useful as a divider between
* different parts of a panel. Uses the java.awt.Label contants for
* its alignment settings (LEFT, CENTER, RIGHT.) <P>
*
* When the alignment is set to LEFT, the label
* looks something like this:
*
* <pre>
* ----label---------------------------
* </pre>
*
* Set the edge offset attribute to control how far from the edge the
* text in the label rests. When the alignment is CENTER, the offset
* is the distance on both sides on the label. You may set
* the label text to null to get a label bar that acts merely as a
* separator.
*
* @version 1.25, 07/25/97
*/
/* END JSTYLED */
/**
* The left alignment.
*/
/**
* The center alignment.
*/
/**
* The right alignment.
*/
/**
* The number of pixels (both sides) between bar and label.
*/
private static final int barAndLabelPad = 2;
/**
* The number of pixels (both sides) between bar edge
*/
private static final int barAndEdgePad = 1;
/**
* The number of pixels in the bar's thickness.
*/
private static final int barThickness = 2;
private int labelOffsetFromEdge = 10;
public LabelBar() {
}
}
repaint();
}
return (label);
}
public void setLabelOffsetFromEdge(int offset) {
if (offset != labelOffsetFromEdge) {
repaint();
}
}
public int getLabelOffsetFromEdge() {
return (labelOffsetFromEdge);
}
public void setAlignment(int alignment) {
switch (alignment) {
case LEFT:
case CENTER:
case RIGHT:
repaint();
break;
default:
throw new IllegalArgumentException(
/* JSTYLED */
}
}
public int getAlignment() {
return (alignment);
}
public Dimension preferredSize() {
return (minimumSize());
}
public Dimension minimumSize() {
labelOffsetFromEdge * 2,
} else {
}
}
/**
* Sets the foreground color (the label bar text.) This overrides
* the setForeground call in Component in order to get an immediate
* repaint when the foreground color setting is changed.
*/
public void setForeground(Color c) {
super.setForeground(c);
repaint();
}
/**
* Disables this component. This overrides the same call in
* Component in order to get an immediate repaint when it is
* called.
*/
public void disable() {
super.disable();
repaint();
}
/**
* Enables this component. This overrides the same call in
* Component in order to get an immediate repaint when it is
* called.
*/
public void enable() {
super.enable();
repaint();
}
/**
* Stipples the given area in a checkerboard fashion using the given
* color. It could be called, for example, after regular painting
* is complete whenever this component is disabled by using the
* background color as the stipple color.
*/
g.setColor(c);
if (y % 2 == x % 2)
g.drawLine(x, y, x, y);
}
/**
* Paints LabelBar contents.
*/
g = getGraphics();
synchronized (DesignerAccess.mutex) {
super.paint(g);
// set up and draw the label location
// according to the alignment
int labelBegin;
switch (alignment) {
case LEFT:
break;
case CENTER:
break;
case RIGHT:
break;
default:
throw new IllegalArgumentException(
/* JSTYLED */
}
g.setColor(getForeground());
// set up and draw the bars according
// to the location of the label
int leftBarBegin = barAndEdgePad;
g.setColor(getBackground());
if (leftBarWidth > 0)
barThickness, false);
if (rightBarWidth > 0)
barThickness, false);
} else {
// no label, just draw a single bar
int barBegin = barAndEdgePad;
g.setColor(getBackground());
false);
}
// if disabled, stipple everything just
// painted with the background color
if (!isEnabled())
}
}
}