1 2 package com.sshtools.ui.swing; 3 4 import java.awt.BorderLayout ; 5 import java.awt.Color ; 6 import java.awt.Font ; 7 import javax.swing.Action ; 8 import javax.swing.Icon ; 9 import javax.swing.JLabel ; 10 import javax.swing.JPanel ; 11 12 18 19 public class FolderBar 20 extends JPanel { 21 22 24 private JLabel textLabel; 25 26 private JLabel iconLabel; 27 28 private Action action; 29 30 33 34 public FolderBar() { 35 this(null, null); 36 37 } 38 39 44 45 public FolderBar(String text) { 46 this(text, null); 47 48 } 49 50 56 57 public FolderBar(String text, Icon icon) { 58 super(new BorderLayout ()); 59 setOpaque(true); 60 setBackground(getBackground().darker()); 61 add(textLabel = new JLabel (), BorderLayout.CENTER); 62 add(iconLabel = new JLabel (), 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 78 79 public Action getAction() { 80 return action; 81 82 } 83 84 90 91 public void setAction(Action action) { 92 this.action = action; 93 setIcon(action == null ? null : (Icon ) action.getValue(Action.SMALL_ICON)); 94 setText(action == null ? null : (String ) action.getValue(Action.LONG_DESCRIPTION)); 95 96 } 97 98 103 104 public void setText(String text) { 105 textLabel.setText(text); 106 107 } 108 109 114 115 public void setIcon(Icon icon) { 116 iconLabel.setIcon(icon); 117 118 } 119 120 } 121 | Popular Tags |