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.GridBagConstraints;
029: import java.awt.GridBagLayout;
030: import java.awt.GridLayout;
031:
032: import javax.swing.BorderFactory;
033: import javax.swing.Icon;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036:
037: /**
038: *
039: *
040: * @author $author$
041: * @version $Revision: 1.14 $
042: */
043: public class StatusBar extends JPanel {
044: /** */
045: public final static Icon GREEN_LED_ON = new ResourceIcon(
046: StatusBar.class, "greenledon.png");
047:
048: /** */
049: public final static Icon GREEN_LED_OFF = new ResourceIcon(
050: StatusBar.class, "greenledoff.png");
051:
052: /** */
053: public final static Icon RED_LED_ON = new ResourceIcon(
054: StatusBar.class, "redledon.png");
055:
056: /** */
057: public final static Icon RED_LED_OFF = new ResourceIcon(
058: StatusBar.class, "redledoff.png");
059:
060: //
061: private StatusLabel connected;
062:
063: //
064: private StatusLabel statusText;
065:
066: //
067: private StatusLabel host;
068:
069: //
070: private StatusLabel user;
071:
072: //
073: private StatusLabel rid;
074: private JLabel sending;
075: private JLabel receiving;
076: private javax.swing.Timer sendingTimer;
077: private javax.swing.Timer receivingTimer;
078:
079: /**
080: * Creates a new StatusBar object.
081: */
082: public StatusBar() {
083: super (new GridBagLayout());
084:
085: GridBagConstraints gbc = new GridBagConstraints();
086: gbc.anchor = GridBagConstraints.WEST;
087: gbc.fill = GridBagConstraints.BOTH;
088: gbc.weightx = 0.0;
089: connected = new StatusLabel(RED_LED_OFF);
090: connected.setHorizontalAlignment(JLabel.CENTER);
091: UIUtil.jGridBagAdd(this , connected, gbc, 1);
092:
093: JPanel lights = new JPanel(new GridLayout(1, 2));
094: sending = new JLabel(GREEN_LED_OFF);
095: sending.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
096: sending.setHorizontalAlignment(JLabel.CENTER);
097: receiving = new JLabel(GREEN_LED_OFF);
098: receiving.setHorizontalAlignment(JLabel.CENTER);
099: lights.add(sending);
100: lights.add(receiving);
101: gbc.weightx = 0.0;
102: lights.setBorder(BorderFactory.createCompoundBorder(
103: BorderFactory.createLoweredBevelBorder(), BorderFactory
104: .createEmptyBorder(1, 1, 1, 1)));
105: gbc.weightx = 1.5;
106: host = new StatusLabel();
107: UIUtil.jGridBagAdd(this , host, gbc, 1);
108: user = new StatusLabel();
109: UIUtil.jGridBagAdd(this , user, gbc, 1);
110: rid = new StatusLabel();
111: UIUtil.jGridBagAdd(this , rid, gbc, 1);
112: statusText = new StatusLabel();
113: gbc.weightx = 4.0;
114: UIUtil.jGridBagAdd(this , statusText, gbc,
115: GridBagConstraints.RELATIVE);
116: gbc.weightx = 0.0;
117: UIUtil.jGridBagAdd(this , lights, gbc,
118: GridBagConstraints.REMAINDER);
119: }
120:
121: /**
122: *
123: *
124: * @param receiving
125: */
126: public void setReceiving(boolean receiving) {
127: this .receiving
128: .setIcon(receiving ? GREEN_LED_ON : GREEN_LED_OFF);
129: }
130:
131: /**
132: *
133: *
134: * @param sending
135: */
136: public void setSending(boolean sending) {
137: this .sending.setIcon(sending ? GREEN_LED_ON : GREEN_LED_OFF);
138: }
139:
140: /**
141: *
142: *
143: * @param connected
144: */
145: public void setConnected(boolean connected) {
146: this .connected.setIcon(connected ? RED_LED_ON : RED_LED_OFF);
147: }
148:
149: /**
150: *
151: *
152: * @param text
153: */
154: public void setStatusText(String text) {
155: statusText.setText(text);
156: }
157:
158: /**
159: *
160: *
161: * @param text
162: */
163: public void setHost(String text) {
164: host.setText(text);
165: }
166:
167: /**
168: *
169: *
170: * @param text
171: * @param port
172: */
173: public void setHost(String text, int port) {
174: host.setText(text + ":" + String.valueOf(port));
175: }
176:
177: /**
178: *
179: *
180: * @param remoteId
181: */
182: public void setRemoteId(String remoteId) {
183: rid.setText(remoteId);
184: }
185:
186: /**
187: *
188: *
189: * @param text
190: */
191: public void setUser(String text) {
192: user.setText(text);
193: }
194:
195: class StatusLabel extends JLabel {
196: StatusLabel(Icon icon) {
197: super (icon);
198: init();
199: }
200:
201: StatusLabel() {
202: super ();
203: init();
204: }
205:
206: void init() {
207: setFont(getFont().deriveFont(10f));
208: setBorder(BorderFactory.createCompoundBorder(BorderFactory
209: .createLoweredBevelBorder(), BorderFactory
210: .createEmptyBorder(1, 1, 1, 1)));
211: }
212: }
213: }
|