View Javadoc

1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.common.gui;
20  
21  import java.awt.Color;
22  import java.awt.Dimension;
23  import java.awt.Font;
24  import java.awt.GridLayout;
25  import java.util.ArrayList;
26  
27  import javax.swing.ImageIcon;
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  import javax.swing.border.Border;
31  
32  import org.apache.log4j.Logger;
33  
34  /***
35   *  <b>Erweiterte Statusleiste</b>
36   * @version $Id: EStatusBar.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $
37   * @author <address> Steve McMee &lt;Steve@users.sourceforge.net&gt; </address>
38   */
39  
40  public class EStatusBar extends JPanel {
41  
42      /*** CVS ID of this file */
43      public static final String CVS_ID =
44          "$Id: EStatusBar.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $";
45  
46      /***
47       * logger instance for this class
48       */
49  
50      private static Logger log = Logger.getLogger(EStatusBar.class);
51  
52      /*** alle Labels */
53      private java.util.List labels;
54      /*** Anzahl der Labels*/
55      private int size;
56  
57      /***
58       * Konstruktor
59       * @param size Anzahl der Labels
60       * @param color Hintergrundfarbe
61       */
62      public EStatusBar(int size, Color color) {
63          this(size);
64          this.setBackground(color);
65      }
66      /***
67       * Konstruktor
68       * @param size Anzahl der Labels
69       */
70      public EStatusBar(int size) {
71          this.size = size;
72          labels = new ArrayList(size);
73          this.setLayout(new GridLayout(1, size));
74          for (int i = 0; i < size; i++) {
75              JLabel label = new JLabel("               ");
76              labels.add(label);
77              this.add(label);
78          }
79      }
80  
81      /***
82       * Setzt einen Text innerhalb eines Labels
83       * @param pos Angabe des Labels
84       * @param text angezeigter Text
85       */
86      public void setText(int pos, String text) {
87          if (pos < size) {
88              JLabel label = (JLabel) labels.get(pos);
89              if (label != null) {
90                  label.setText(text);
91              }
92          }
93      }
94      /***
95       * Setzt einen Text innerhalb eines Labels
96       * @param pos Angabe des Labels
97       * @param text angezeigter Text
98       * @param color Textfarbe
99       */
100     public void setText(int pos, String text, Color color) {
101         if (pos < size) {
102             JLabel label = (JLabel) labels.get(pos);
103             if (label != null) {
104                 label.setForeground(color);
105                 label.setText(text);
106             }
107         }
108     }
109 
110     /***
111      * Setzt den Font für alle Texte innerhalb eines Labels
112      * @param font Textfont
113      */
114     public void setFont(Font font) {
115         for (int i = 0; i < size; i++) {
116              ((JLabel) labels.get(i)).setFont(font);
117         }
118     }
119     /***
120      * Setzt den Rahmen für alle Labels
121      * @param Border Rahmen
122      */
123     public void setBorder(Border border) {
124         for (int i = 0; i < size; i++) {
125              ((JLabel) labels.get(i)).setBorder(border);
126         }
127     }
128     /***
129      * Setzt einen Icon innerhalb eines Labels
130      * @param pos Angabe des Labels
131      * @param icon angezeigtes Icon
132      * @param color Textfarbe
133      */
134     public void setIcon(int pos, ImageIcon icon, String tooltip) {
135         if (log.isDebugEnabled()) {
136             log.debug("setIcon(" + pos + "," + icon + "," + tooltip + ")");
137         }
138         if (pos < size) {
139             JLabel label = (JLabel) labels.get(pos);
140             if (label != null) {
141                 label.setToolTipText(tooltip);
142                 label.setText(tooltip);
143                 label.setIcon(icon);
144                 label.repaint();
145             }
146         }
147     }
148     /***
149      * Setzt einen Icon innerhalb eines Labels
150      * @param pos Angabe des Labels
151      * @param icon angezeigtes Icon
152      * @param tooltip Text für Tooltip und Beschriftung
153      * @param color Textfarbe
154      */
155     public void setIcon(int pos, ImageIcon icon, String tooltip, Color color) {
156         if (log.isDebugEnabled()) {
157             log.debug("setIcon(" + pos + "," + icon + "," + tooltip + ")");
158         }
159         if (pos < size) {
160             JLabel label = (JLabel) labels.get(pos);
161             if (label != null) {
162                 label.setToolTipText(tooltip);
163                 label.setText(tooltip);
164                 label.setForeground(color);
165                 label.setIcon(icon);
166                 label.repaint();
167             }
168         }
169     }
170 
171     /*
172      * sets the preferd Size for a Label
173      * @param pos the position of the label
174      * @param preferredSize the dimension for the label
175      */
176     public void setPreferredSize(int pos, Dimension preferredSize) {
177         JLabel label = (JLabel) labels.get(pos);
178         label.setPreferredSize(preferredSize);
179     }
180 
181 }