001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.metadata.swing;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.vfs.context.*;
027: import org.openharmonise.vfs.gui.*;
028:
029: /**
030: *
031: * @author Matthew Large
032: * @version $Revision: 1.1 $
033: *
034: */
035: public class HelpPopup extends JFrame implements ContextListener,
036: WindowListener, LayoutManager {
037:
038: private static HelpPopup m_instance = null;
039:
040: private HelpIcon m_helpIcon = null;
041:
042: private JLabel m_titleLabel = null;
043:
044: private JTextArea m_textArea = null;
045:
046: public static HelpPopup getInstance() {
047: if (m_instance == null) {
048: JFrame frame = new JFrame();
049: frame.setUndecorated(true);
050: m_instance = new HelpPopup();
051: m_instance.setIconImage(((ImageIcon) IconManager
052: .getInstance().getIcon("16-command-help.gif"))
053: .getImage());
054: m_instance.setup();
055: }
056: return m_instance;
057: }
058:
059: private void setup() {
060: ContextHandler.getInstance().addListener(
061: ContextType.CONTEXT_APP_FOCUS, this );
062:
063: this .getContentPane().setLayout(new BorderLayout());
064: JPanel panel = new JPanel();
065: panel.setLayout(this );
066:
067: panel.setBorder(BorderFactory.createBevelBorder(3, Color.GRAY,
068: Color.LIGHT_GRAY));
069: this .getContentPane().add(panel);
070:
071: this .setSize(100, 100);
072: int x = this .getGraphicsConfiguration().getBounds().width / 2
073: - this .getSize().width / 2;
074: int y = this .getGraphicsConfiguration().getBounds().height / 2
075: - this .getSize().height / 2;
076:
077: this .setLocation(x, y);
078:
079: String fontName = "Dialog";
080: int fontSize = 11;
081: Font font = new Font(fontName, Font.PLAIN, fontSize);
082: Font fontBold = new Font(fontName, Font.BOLD, fontSize);
083: panel.setBackground(new Color(224, 224, 224));
084:
085: this .addWindowListener(this );
086:
087: panel.setBackground(Color.YELLOW);
088:
089: this .m_titleLabel = new JLabel();
090: this .m_titleLabel.setOpaque(false);
091: this .m_titleLabel.setFont(fontBold);
092: panel.add(this .m_titleLabel);
093:
094: this .m_textArea = new JTextArea();
095: this .m_textArea.setOpaque(false);
096: this .m_textArea.setWrapStyleWord(true);
097: this .m_textArea.setColumns(20);
098: this .m_textArea.setLineWrap(true);
099: this .m_textArea.setFont(font);
100: this .m_textArea.setEditable(false);
101: panel.add(this .m_textArea);
102: }
103:
104: /* (non-Javadoc)
105: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
106: */
107: public void layoutContainer(Container arg0) {
108: this .m_titleLabel.setSize(this .m_titleLabel.getPreferredSize());
109: this .m_titleLabel.setLocation(10, 10);
110:
111: this .m_textArea.setSize(this .m_textArea.getPreferredSize());
112: this .m_textArea.setLocation(10,
113: this .m_titleLabel.getSize().height + 20);
114:
115: }
116:
117: /* (non-Javadoc)
118: * @see java.awt.Component#getPreferredSize()
119: */
120: public Dimension getPreferredSize() {
121: this .layoutContainer(null);
122: int nWidth = this .m_textArea.getPreferredSize().width + 20;
123: int nHeight = this .m_titleLabel.getSize().height
124: + this .m_textArea.getPreferredSize().height + 50;
125: return new Dimension(nWidth, nHeight);
126: }
127:
128: public void setHelpInfo(HelpIcon helpIcon) {
129:
130: if (helpIcon != this .m_helpIcon) {
131: this .m_titleLabel.setText(helpIcon.getTitle());
132: this .m_textArea.setEditable(true);
133: this .m_textArea.setText(helpIcon.getSummary());
134: this .m_textArea.setEditable(false);
135: if (this .m_helpIcon != null) {
136: this .m_helpIcon.setSelected(false);
137: }
138: this .m_helpIcon = helpIcon;
139: this .setSize(this .getPreferredSize());
140: if (this .m_helpIcon != null) {
141: this
142: .setLocation(
143: this .m_helpIcon.getLocationOnScreen().x
144: - this .getPreferredSize().width
145: - 5,
146: this .m_helpIcon.getLocationOnScreen().y
147: + this .m_helpIcon
148: .getPreferredSize().height
149: + 5);
150: }
151: this .show();
152: this .toFront();
153: this .toFront();
154: } else {
155: this .hide();
156: this .m_helpIcon = null;
157: }
158: }
159:
160: /* (non-Javadoc)
161: * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
162: */
163: public void contextMessage(ContextEvent ce) {
164: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_APP_FOCUS) {
165:
166: }
167: }
168:
169: /* (non-Javadoc)
170: * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
171: */
172: public void windowClosing(WindowEvent arg0) {
173: if (this .m_helpIcon != null) {
174: this .m_helpIcon.setSelected(false);
175: this .m_helpIcon = null;
176: }
177: }
178:
179: /* (non-Javadoc)
180: * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
181: */
182: public void windowClosed(WindowEvent arg0) {
183: }
184:
185: /**
186: * @throws java.awt.HeadlessException
187: */
188: private HelpPopup() throws HeadlessException {
189: super ();
190: }
191:
192: /* (non-Javadoc)
193: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
194: */
195: public void removeLayoutComponent(Component arg0) {
196: }
197:
198: /* (non-Javadoc)
199: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
200: */
201: public void addLayoutComponent(String arg0, Component arg1) {
202: }
203:
204: /* (non-Javadoc)
205: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
206: */
207: public Dimension minimumLayoutSize(Container arg0) {
208: return this .getPreferredSize();
209: }
210:
211: /* (non-Javadoc)
212: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
213: */
214: public Dimension preferredLayoutSize(Container arg0) {
215: return this .getPreferredSize();
216: }
217:
218: /* (non-Javadoc)
219: * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
220: */
221: public void windowActivated(WindowEvent arg0) {
222: }
223:
224: /* (non-Javadoc)
225: * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
226: */
227: public void windowDeactivated(WindowEvent arg0) {
228: }
229:
230: /* (non-Javadoc)
231: * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
232: */
233: public void windowDeiconified(WindowEvent arg0) {
234: }
235:
236: /* (non-Javadoc)
237: * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
238: */
239: public void windowIconified(WindowEvent arg0) {
240: }
241:
242: /* (non-Javadoc)
243: * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
244: */
245: public void windowOpened(WindowEvent arg0) {
246: }
247:
248: }
|