View Javadoc
1   package net.logAnalyzer.utils.gui;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Color;
5   import java.awt.Dimension;
6   
7   import javax.swing.JLabel;
8   import javax.swing.JProgressBar;
9   import javax.swing.JToolBar;
10  
11  import net.logAnalyzer.gui.LAViewContainer;
12  
13  /***
14   * This class implements a status bar extending a {@link javax.swing.JToolBar}.
15   * @author Karim REFEYTON
16   * @version 0.1
17   */
18  public class JStatusBar extends JToolBar {
19      private static final long serialVersionUID = 1L;
20  
21      /***
22       * Message.
23       */
24      private JLabel messageLabel = new JLabel("-");
25  
26      /***
27       * Progress bar.
28       */
29      private JProgressBar progressbar = new JProgressBar();
30  
31      /***
32       * Used to manage layout between the message panel and the progressBar. 
33       * If true, message panel and progressBar are on the same line, side by side. 
34       * If false, message panel is above the progressbar.
35       */
36      private boolean sideBySide = true;
37  
38      /***
39       * 
40       */
41      public JStatusBar() {
42          this(JToolBar.HORIZONTAL);
43      }
44  
45      /***
46       * @param orientation
47       */
48      public JStatusBar(int orientation) {
49          this(null, orientation);
50  
51      }
52  
53      /***
54       * @param name
55       */
56      public JStatusBar(String name) {
57          this(name, JToolBar.HORIZONTAL);
58      }
59  
60      /***
61       * @param name
62       * @param orientation
63       */
64      public JStatusBar(String name, int orientation) {
65          super(name, orientation);
66          addComponents();
67      }
68  
69      /***
70       * 
71       */
72      public JStatusBar(boolean isSideBySide) {
73          this(JToolBar.HORIZONTAL, isSideBySide);
74      }
75  
76      /***
77       * @param orientation
78       */
79      public JStatusBar(int orientation, boolean isSideBySide) {
80          this(null, orientation, isSideBySide);
81  
82      }
83  
84      /***
85       * @param name
86       */
87      public JStatusBar(String name, boolean isSideBySide) {
88          this(name, JToolBar.HORIZONTAL, isSideBySide);
89      }
90  
91      /***
92       * @param name
93       * @param orientation
94       */
95      public JStatusBar(String name, int orientation, boolean isSideBySide) {
96          super(name, orientation);
97          sideBySide = isSideBySide;
98          addComponents();
99      }
100 
101     /***
102      * Adds view components. Called by
103      * {@link net.logAnalyzer.gui.LAView#setViewContainer(LAViewContainer)}.
104      */
105     protected void addComponents() {
106         setLayout(new BorderLayout());
107         // Add messageLabel
108         
109         add(messageLabel, BorderLayout.CENTER);
110         // Add progressbar
111         progressbar.setMinimum(0);
112         progressbar.setMaximum(100);
113         progressbar.setPreferredSize(new Dimension(100, 15));
114         progressbar.setStringPainted(true);
115         if (sideBySide) {
116             add(progressbar, BorderLayout.EAST);
117         } else {
118             add(progressbar, BorderLayout.SOUTH);
119         }
120     }
121 
122     /***
123      * Set the messageLabel in the status bar.
124      * @param message Message to display.
125      */
126     public void setMessage(String message) {
127         this.messageLabel.setText(message);
128     }
129 
130     /***
131      * Set the progressbar messageLabel and value.
132      * @param message Progressbar messageLabel.
133      * @param percents Progressbar value.
134      */
135     public void setProgressBar(String message, int percents) {
136         progressbar.setValue(percents);
137         progressbar.setString(message);
138     }
139     
140     public void setMessageColor(Color arg0){
141         if(messageLabel != null){
142             messageLabel.setForeground(arg0);
143         }
144     }
145     
146     public void setBackground(Color arg0) {
147         super.setBackground(arg0);
148         if(progressbar != null){
149             progressbar.setBackground(arg0);
150         }
151     }
152     
153 }