001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.Font;
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031:
032: import java.util.StringTokenizer;
033:
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036:
037: /**
038: *
039: *
040: * @author $author$
041: * @version $Revision: 1.13 $
042: */
043: public class MultilineLabel extends JPanel {
044: // Private instance variables
045: private GridBagConstraints constraints;
046: private String text;
047:
048: /**
049: * Creates a new MultilineLabel object.
050: */
051: public MultilineLabel() {
052: this ("");
053: }
054:
055: /**
056: * Creates a new MultilineLabel object.
057: *
058: * @param text
059: */
060: public MultilineLabel(String text) {
061: super (new GridBagLayout());
062: constraints = new GridBagConstraints();
063: constraints.anchor = GridBagConstraints.NORTHWEST;
064: constraints.fill = GridBagConstraints.NONE;
065: setText(text);
066: }
067:
068: /**
069: *
070: *
071: * @param f
072: */
073: public void setFont(Font f) {
074: super .setFont(f);
075:
076: for (int i = 0; i < getComponentCount(); i++) {
077: getComponent(i).setFont(f);
078: }
079: }
080:
081: /**
082: *
083: *
084: * @param text
085: */
086: public void setText(String text) {
087: this .text = text;
088: removeAll();
089:
090: StringTokenizer tok = new StringTokenizer(text, "\n");
091: constraints.weighty = 0.0;
092: constraints.weightx = 1.0;
093:
094: while (tok.hasMoreTokens()) {
095: String t = tok.nextToken();
096:
097: if (!tok.hasMoreTokens()) {
098: constraints.weighty = 1.0;
099: }
100:
101: UIUtil.jGridBagAdd(this , new JLabel(t), constraints,
102: GridBagConstraints.REMAINDER);
103: }
104:
105: revalidate();
106: repaint();
107: }
108:
109: /**
110: *
111: *
112: * @return
113: */
114: public String getText() {
115: return text;
116: }
117: }
|