Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.ui » [javadoc | source]
    1   /*
    2    *  SSHTools - Java SSH2 API
    3    *
    4    *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
    5    *
    6    *  Contributions made by:
    7    *
    8    *  Brett Smith
    9    *  Richard Pernavas
   10    *  Erwin Bolwidt
   11    *
   12    *  This program is free software; you can redistribute it and/or
   13    *  modify it under the terms of the GNU General Public License
   14    *  as published by the Free Software Foundation; either version 2
   15    *  of the License, or (at your option) any later version.
   16    *
   17    *  This program is distributed in the hope that it will be useful,
   18    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20    *  GNU General Public License for more details.
   21    *
   22    *  You should have received a copy of the GNU General Public License
   23    *  along with this program; if not, write to the Free Software
   24    *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   25    */
   26   package com.sshtools.common.ui;
   27   
   28   import java.awt.GridBagConstraints;
   29   import java.awt.GridBagLayout;
   30   import java.awt.GridLayout;
   31   
   32   import javax.swing.BorderFactory;
   33   import javax.swing.Icon;
   34   import javax.swing.JLabel;
   35   import javax.swing.JPanel;
   36   
   37   
   38   /**
   39    *
   40    *
   41    * @author $author$
   42    * @version $Revision: 1.14 $
   43    */
   44   public class StatusBar extends JPanel {
   45       /**  */
   46       public final static Icon GREEN_LED_ON = new ResourceIcon(StatusBar.class,
   47               "greenledon.png");
   48   
   49       /**  */
   50       public final static Icon GREEN_LED_OFF = new ResourceIcon(StatusBar.class,
   51               "greenledoff.png");
   52   
   53       /**  */
   54       public final static Icon RED_LED_ON = new ResourceIcon(StatusBar.class,
   55               "redledon.png");
   56   
   57       /**  */
   58       public final static Icon RED_LED_OFF = new ResourceIcon(StatusBar.class,
   59               "redledoff.png");
   60   
   61       //
   62       private StatusLabel connected;
   63   
   64       //
   65       private StatusLabel statusText;
   66   
   67       //
   68       private StatusLabel host;
   69   
   70       //
   71       private StatusLabel user;
   72   
   73       //
   74       private StatusLabel rid;
   75       private JLabel sending;
   76       private JLabel receiving;
   77       private javax.swing.Timer sendingTimer;
   78       private javax.swing.Timer receivingTimer;
   79   
   80       /**
   81   * Creates a new StatusBar object.
   82   */
   83       public StatusBar() {
   84           super(new GridBagLayout());
   85   
   86           GridBagConstraints gbc = new GridBagConstraints();
   87           gbc.anchor = GridBagConstraints.WEST;
   88           gbc.fill = GridBagConstraints.BOTH;
   89           gbc.weightx = 0.0;
   90           connected = new StatusLabel(RED_LED_OFF);
   91           connected.setHorizontalAlignment(JLabel.CENTER);
   92           UIUtil.jGridBagAdd(this, connected, gbc, 1);
   93   
   94           JPanel lights = new JPanel(new GridLayout(1, 2));
   95           sending = new JLabel(GREEN_LED_OFF);
   96           sending.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
   97           sending.setHorizontalAlignment(JLabel.CENTER);
   98           receiving = new JLabel(GREEN_LED_OFF);
   99           receiving.setHorizontalAlignment(JLabel.CENTER);
  100           lights.add(sending);
  101           lights.add(receiving);
  102           gbc.weightx = 0.0;
  103           lights.setBorder(BorderFactory.createCompoundBorder(
  104                   BorderFactory.createLoweredBevelBorder(),
  105                   BorderFactory.createEmptyBorder(1, 1, 1, 1)));
  106           gbc.weightx = 1.5;
  107           host = new StatusLabel();
  108           UIUtil.jGridBagAdd(this, host, gbc, 1);
  109           user = new StatusLabel();
  110           UIUtil.jGridBagAdd(this, user, gbc, 1);
  111           rid = new StatusLabel();
  112           UIUtil.jGridBagAdd(this, rid, gbc, 1);
  113           statusText = new StatusLabel();
  114           gbc.weightx = 4.0;
  115           UIUtil.jGridBagAdd(this, statusText, gbc, GridBagConstraints.RELATIVE);
  116           gbc.weightx = 0.0;
  117           UIUtil.jGridBagAdd(this, lights, gbc, GridBagConstraints.REMAINDER);
  118       }
  119   
  120       /**
  121   *
  122   *
  123   * @param receiving
  124   */
  125       public void setReceiving(boolean receiving) {
  126           this.receiving.setIcon(receiving ? GREEN_LED_ON : GREEN_LED_OFF);
  127       }
  128   
  129       /**
  130   *
  131   *
  132   * @param sending
  133   */
  134       public void setSending(boolean sending) {
  135           this.sending.setIcon(sending ? GREEN_LED_ON : GREEN_LED_OFF);
  136       }
  137   
  138       /**
  139   *
  140   *
  141   * @param connected
  142   */
  143       public void setConnected(boolean connected) {
  144           this.connected.setIcon(connected ? RED_LED_ON : RED_LED_OFF);
  145       }
  146   
  147       /**
  148   *
  149   *
  150   * @param text
  151   */
  152       public void setStatusText(String text) {
  153           statusText.setText(text);
  154       }
  155   
  156       /**
  157   *
  158   *
  159   * @param text
  160   */
  161       public void setHost(String text) {
  162           host.setText(text);
  163       }
  164   
  165       /**
  166   *
  167   *
  168   * @param text
  169   * @param port
  170   */
  171       public void setHost(String text, int port) {
  172           host.setText(text + ":" + String.valueOf(port));
  173       }
  174   
  175       /**
  176   *
  177   *
  178   * @param remoteId
  179   */
  180       public void setRemoteId(String remoteId) {
  181           rid.setText(remoteId);
  182       }
  183   
  184       /**
  185   *
  186   *
  187   * @param text
  188   */
  189       public void setUser(String text) {
  190           user.setText(text);
  191       }
  192   
  193       class StatusLabel extends JLabel {
  194           StatusLabel(Icon icon) {
  195               super(icon);
  196               init();
  197           }
  198   
  199           StatusLabel() {
  200               super();
  201               init();
  202           }
  203   
  204           void init() {
  205               setFont(getFont().deriveFont(10f));
  206               setBorder(BorderFactory.createCompoundBorder(
  207                       BorderFactory.createLoweredBevelBorder(),
  208                       BorderFactory.createEmptyBorder(1, 1, 1, 1)));
  209           }
  210       }
  211   }

Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.ui » [javadoc | source]