KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SSHTools - Java SSH2 API
3  *
4  * Copyright (C) 2002 Lee David Painter.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * You may also distribute it and/or modify it under the terms of the
12  * Apache style J2SSH Software License. A copy of which should have
13  * been provided with the distribution.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * License document supplied with your distribution for more details.
19  *
20  */

21 package com.sshtools.ui.swing;
22
23 import java.awt.BorderLayout JavaDoc;
24 import java.awt.Color JavaDoc;
25 import java.awt.Component JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.Icon JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 /**
33  *
34  *
35  * @author $author$
36  */

37 public class IconWrapperPanel extends JPanel JavaDoc {
38     private JLabel JavaDoc iconLabel;
39     private JPanel JavaDoc westPanel;
40     private Component JavaDoc component;
41
42     /**
43      * Creates a new IconWrapperPanel object.
44      *
45      * @param icon
46      * @param component
47      */

48     public IconWrapperPanel(Icon JavaDoc icon, Component JavaDoc component) {
49         super(new BorderLayout JavaDoc());
50         // Create the west panel with the icon in it
51
westPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
52         westPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4));
53         westPanel.add(iconLabel = new JLabel JavaDoc(icon), BorderLayout.NORTH);
54         // Build this panel
55
setOpaque(false);
56         add(westPanel, BorderLayout.WEST);
57         if(component != null) {
58             this.component = component;
59             add(component, BorderLayout.CENTER);
60         }
61     }
62     
63     public void setComponent(Component JavaDoc component) {
64         invalidate();
65         if(this.component != null) {
66             remove(this.component);
67         }
68         add(component, BorderLayout.CENTER);
69         this.component = component;
70         validate();
71         repaint();
72     }
73     
74     public void setBackground(Color JavaDoc background) {
75         super.setBackground(background);
76         if(westPanel != null) {
77             westPanel.setBackground(background);
78         }
79     }
80     
81     public void setForeground(Color JavaDoc foreground) {
82         super.setForeground(foreground);
83         if(westPanel != null) {
84             westPanel.setForeground(foreground);
85         }
86     }
87     
88     public void setOpaque(boolean opaque) {
89         super.setOpaque(opaque);
90         if(westPanel != null)
91             westPanel.setOpaque(opaque);
92     }
93
94     public void setIcon(Icon JavaDoc icon) {
95         iconLabel.setIcon(icon);
96     }
97
98     public void setIconPosition(String JavaDoc position) {
99         invalidate();
100         remove(westPanel);
101         add(westPanel, position);
102         validate();
103     }
104 }
Popular Tags