KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > FolderBar


1 /* HEADER*/
2 package com.sshtools.ui.swing;
3
4 import java.awt.BorderLayout JavaDoc;
5 import java.awt.Color JavaDoc;
6 import java.awt.Font JavaDoc;
7 import javax.swing.Action JavaDoc;
8 import javax.swing.Icon JavaDoc;
9 import javax.swing.JLabel JavaDoc;
10 import javax.swing.JPanel JavaDoc;
11
12 /**
13  * Simple Swing component that just shows an icon and some boldened text on a darkened
14  * background. The icon and text can also be derived from an Action.
15  *
16  * @author $Author: james $
17  */

18
19 public class FolderBar
20     extends JPanel JavaDoc {
21
22   // Private instance variables
23

24   private JLabel JavaDoc textLabel;
25
26   private JLabel JavaDoc iconLabel;
27
28   private Action JavaDoc action;
29
30   /**
31    * Construct a new FolderBar.
32    */

33
34   public FolderBar() {
35     this(null, null);
36
37   }
38
39   /**
40    * Construct a new FolderBar with some text.
41    *
42    * @param text text
43    */

44
45   public FolderBar(String JavaDoc text) {
46     this(text, null);
47
48   }
49
50   /**
51    * Construct a new FolderBar with some text and an icon.
52    *
53    * @param text text
54    * @param icon icon
55    */

56
57   public FolderBar(String JavaDoc text, Icon JavaDoc icon) {
58     super(new BorderLayout JavaDoc());
59     setOpaque(true);
60     setBackground(getBackground().darker());
61     add(textLabel = new JLabel JavaDoc(), BorderLayout.CENTER);
62     add(iconLabel = new JLabel JavaDoc(), BorderLayout.WEST);
63     iconLabel.setFont(iconLabel.getFont().deriveFont(Font.BOLD));
64     textLabel.setVerticalAlignment(JLabel.CENTER);
65     textLabel.setVerticalTextPosition(JLabel.BOTTOM);
66     textLabel.setForeground(Color.lightGray);
67     iconLabel.setVerticalAlignment(JLabel.CENTER);
68     setIcon(icon);
69     setText(text);
70
71   }
72
73   /**
74    * Get the action that built this folder bar.
75    *
76    * @return action
77    */

78
79   public Action JavaDoc getAction() {
80     return action;
81
82   }
83
84   /**
85    * Set the icon and text from an action. The {@link Action.NAME} values is
86    * used to derive the text and {@link Action.ICON} for the icon.
87    *
88    * @param action
89    */

90
91   public void setAction(Action JavaDoc action) {
92     this.action = action;
93     setIcon(action == null ? null : (Icon JavaDoc) action.getValue(Action.SMALL_ICON));
94     setText(action == null ? null : (String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
95
96   }
97
98   /**
99    * Set the text of this folder bar.
100    *
101    * @param text text
102    */

103
104   public void setText(String JavaDoc text) {
105     textLabel.setText(text);
106
107   }
108
109   /**
110    * Set the icon on this folder bar.
111    *
112    * @param icon icon
113    */

114
115   public void setIcon(Icon JavaDoc icon) {
116     iconLabel.setIcon(icon);
117
118   }
119
120 }
121
Popular Tags