001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: RotatableLabel.java,v 1.8 2005/12/04 13:46:04 jesper Exp $
023: package net.infonode.gui;
024:
025: import net.infonode.util.Direction;
026:
027: import javax.swing.*;
028: import javax.swing.plaf.LabelUI;
029: import java.awt.*;
030:
031: public class RotatableLabel extends JLabel {
032: private RotatableLabelUI ui = new RotatableLabelUI(Direction.RIGHT);
033:
034: public RotatableLabel(String text) {
035: super (text);
036: init();
037: }
038:
039: public RotatableLabel(String text, Icon icon) {
040: super (text, icon, LEFT);
041: init();
042: }
043:
044: private void init() {
045: super .setUI(ui);
046: super .setOpaque(false);
047: }
048:
049: public Direction getDirection() {
050: return ui.getDirection();
051: }
052:
053: public void setDirection(Direction direction) {
054: if (ui.getDirection() != direction) {
055: ui.setDirection(direction);
056: revalidate();
057: }
058: }
059:
060: public void setMirror(boolean mirror) {
061: ui.setMirror(mirror);
062: revalidate();
063: }
064:
065: public boolean isMirror() {
066: return ui.isMirror();
067: }
068:
069: public void setUI(LabelUI ui) {
070: // Ignore
071: }
072:
073: private boolean isVertical() {
074: return !ui.getDirection().isHorizontal();
075: }
076:
077: private Dimension rotateDimension(Dimension dim) {
078: return dim == null ? null : isVertical() ? new Dimension(
079: dim.height, dim.width) : dim;
080: }
081:
082: public Dimension getPreferredSize() {
083: return rotateDimension(super .getPreferredSize());
084: }
085:
086: public Dimension getMinimumSize() {
087: return rotateDimension(super .getMinimumSize());
088: }
089:
090: public Dimension getMaximumSize() {
091: return rotateDimension(super .getMaximumSize());
092: }
093:
094: public void setMinimumSize(Dimension minimumSize) {
095: super .setMinimumSize(rotateDimension(minimumSize));
096: }
097:
098: public void setMaximumSize(Dimension maximumSize) {
099: super .setMaximumSize(rotateDimension(maximumSize));
100: }
101:
102: public void setPreferredSize(Dimension preferredSize) {
103: super .setPreferredSize(rotateDimension(preferredSize));
104: }
105:
106: public void setOpaque(boolean opaque) {
107: }
108:
109: }
|