Source code: com/sshtools/sshterm/FolderBar.java
1 /*
2 * Sshtools - SSHTerm
3 *
4 * Copyright (C) 2002 Lee David Painter.
5 *
6 * Written by: 2002 Lee David Painter <lee@sshtools.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 package com.sshtools.sshterm;
22
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Font;
26
27 import javax.swing.Action;
28 import javax.swing.Icon;
29 import javax.swing.JLabel;
30 import javax.swing.JPanel;
31
32
33 public class FolderBar extends JPanel {
34 // Private instance variables
35 private JLabel textLabel;
36
37 // Private instance variables
38 private JLabel iconLabel;
39 private Action action;
40
41 public FolderBar() {
42 this(null, null);
43 }
44
45 public FolderBar(String text) {
46 this(text, null);
47 }
48
49 public FolderBar(String text, Icon icon) {
50 super(new BorderLayout());
51 setOpaque(true);
52 setBackground(getBackground().darker());
53 add(textLabel = new JLabel(), BorderLayout.CENTER);
54 add(iconLabel = new JLabel(), BorderLayout.WEST);
55 iconLabel.setFont(iconLabel.getFont().deriveFont(Font.BOLD));
56 textLabel.setVerticalAlignment(JLabel.CENTER);
57 textLabel.setVerticalTextPosition(JLabel.BOTTOM);
58 textLabel.setForeground(Color.lightGray);
59 iconLabel.setVerticalAlignment(JLabel.CENTER);
60 setIcon(icon);
61 setText(text);
62 }
63
64 public Action getAction() {
65 return action;
66 }
67
68 public void setAction(Action action) {
69 this.action = action;
70 setIcon((Icon) action.getValue(Action.SMALL_ICON));
71 setText((String) action.getValue(Action.NAME));
72 }
73
74 public void setText(String text) {
75 textLabel.setText(text);
76 }
77
78 public void setIcon(Icon icon) {
79 iconLabel.setIcon(icon);
80 }
81 }