KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > swing > HelpPopup


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.swing;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.vfs.context.*;
27 import org.openharmonise.vfs.gui.*;
28
29 /**
30  *
31  * @author Matthew Large
32  * @version $Revision: 1.1 $
33  *
34  */

35 public class HelpPopup extends JFrame implements ContextListener, WindowListener, LayoutManager {
36
37     private static HelpPopup m_instance = null;
38     
39     private HelpIcon m_helpIcon = null;
40     
41     private JLabel m_titleLabel = null;
42     
43     private JTextArea m_textArea = null;
44     
45     public static HelpPopup getInstance() {
46         if(m_instance==null) {
47             JFrame frame = new JFrame();
48             frame.setUndecorated(true);
49             m_instance = new HelpPopup();
50             m_instance.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("16-command-help.gif")).getImage() );
51             m_instance.setup();
52         }
53         return m_instance;
54     }
55     
56     private void setup() {
57         ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this);
58         
59         this.getContentPane().setLayout(new BorderLayout());
60         JPanel panel = new JPanel();
61         panel.setLayout(this);
62         
63         panel.setBorder(BorderFactory.createBevelBorder(3, Color.GRAY, Color.LIGHT_GRAY));
64         this.getContentPane().add(panel);
65         
66         this.setSize(100,100);
67         int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2;
68         int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2;
69         
70         this.setLocation(x, y);
71
72         String JavaDoc fontName = "Dialog";
73         int fontSize = 11;
74         Font font = new Font(fontName, Font.PLAIN, fontSize);
75         Font fontBold = new Font(fontName, Font.BOLD, fontSize);
76         panel.setBackground(new Color(224,224,224));
77         
78         this.addWindowListener(this);
79         
80         panel.setBackground(Color.YELLOW);
81         
82         this.m_titleLabel = new JLabel();
83         this.m_titleLabel.setOpaque(false);
84         this.m_titleLabel.setFont(fontBold);
85         panel.add(this.m_titleLabel);
86
87         this.m_textArea = new JTextArea();
88         this.m_textArea.setOpaque(false);
89         this.m_textArea.setWrapStyleWord(true);
90         this.m_textArea.setColumns(20);
91         this.m_textArea.setLineWrap(true);
92         this.m_textArea.setFont(font);
93         this.m_textArea.setEditable(false);
94         panel.add(this.m_textArea);
95     }
96
97     /* (non-Javadoc)
98      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
99      */

100     public void layoutContainer(Container arg0) {
101         this.m_titleLabel.setSize(this.m_titleLabel.getPreferredSize());
102         this.m_titleLabel.setLocation(10, 10);
103         
104         this.m_textArea.setSize(this.m_textArea.getPreferredSize());
105         this.m_textArea.setLocation(10, this.m_titleLabel.getSize().height + 20);
106         
107
108     }
109
110     /* (non-Javadoc)
111      * @see java.awt.Component#getPreferredSize()
112      */

113     public Dimension getPreferredSize() {
114         this.layoutContainer(null);
115         int nWidth = this.m_textArea.getPreferredSize().width+20;
116         int nHeight = this.m_titleLabel.getSize().height + this.m_textArea.getPreferredSize().height + 50;
117         return new Dimension(nWidth, nHeight);
118     }
119     
120     public void setHelpInfo(HelpIcon helpIcon) {
121         
122         if(helpIcon!=this.m_helpIcon) {
123             this.m_titleLabel.setText(helpIcon.getTitle());
124             this.m_textArea.setEditable(true);
125             this.m_textArea.setText(helpIcon.getSummary());
126             this.m_textArea.setEditable(false);
127             if(this.m_helpIcon!=null) {
128                 this.m_helpIcon.setSelected(false);
129             }
130             this.m_helpIcon = helpIcon;
131             this.setSize(this.getPreferredSize());
132             if(this.m_helpIcon!=null) {
133                 this.setLocation( this.m_helpIcon.getLocationOnScreen().x-this.getPreferredSize().width-5, this.m_helpIcon.getLocationOnScreen().y + this.m_helpIcon.getPreferredSize().height+5);
134             }
135             this.show();
136             this.toFront();
137             this.toFront();
138         } else {
139             this.hide();
140             this.m_helpIcon = null;
141         }
142     }
143
144     /* (non-Javadoc)
145      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
146      */

147     public void contextMessage(ContextEvent ce) {
148         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) {
149             
150         }
151     }
152
153     /* (non-Javadoc)
154      * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
155      */

156     public void windowClosing(WindowEvent arg0) {
157         if(this.m_helpIcon!=null) {
158             this.m_helpIcon.setSelected(false);
159             this.m_helpIcon = null;
160         }
161     }
162
163     /* (non-Javadoc)
164      * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
165      */

166     public void windowClosed(WindowEvent arg0) {
167     }
168
169     /**
170      * @throws java.awt.HeadlessException
171      */

172     private HelpPopup() throws HeadlessException {
173         super();
174     }
175
176     /* (non-Javadoc)
177      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
178      */

179     public void removeLayoutComponent(Component arg0) {
180     }
181
182     /* (non-Javadoc)
183      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
184      */

185     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
186     }
187
188     /* (non-Javadoc)
189      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
190      */

191     public Dimension minimumLayoutSize(Container arg0) {
192         return this.getPreferredSize();
193     }
194
195     /* (non-Javadoc)
196      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
197      */

198     public Dimension preferredLayoutSize(Container arg0) {
199         return this.getPreferredSize();
200     }
201
202     /* (non-Javadoc)
203      * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
204      */

205     public void windowActivated(WindowEvent arg0) {
206     }
207
208     /* (non-Javadoc)
209      * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
210      */

211     public void windowDeactivated(WindowEvent arg0) {
212     }
213
214     /* (non-Javadoc)
215      * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
216      */

217     public void windowDeiconified(WindowEvent arg0) {
218     }
219
220     /* (non-Javadoc)
221      * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
222      */

223     public void windowIconified(WindowEvent arg0) {
224     }
225
226     /* (non-Javadoc)
227      * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
228      */

229     public void windowOpened(WindowEvent arg0) {
230     }
231
232 }
233
Popular Tags