1 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 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 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 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 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 147 public void contextMessage(ContextEvent ce) { 148 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 149 150 } 151 } 152 153 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 166 public void windowClosed(WindowEvent arg0) { 167 } 168 169 172 private HelpPopup() throws HeadlessException { 173 super(); 174 } 175 176 179 public void removeLayoutComponent(Component arg0) { 180 } 181 182 185 public void addLayoutComponent(String arg0, Component arg1) { 186 } 187 188 191 public Dimension minimumLayoutSize(Container arg0) { 192 return this.getPreferredSize(); 193 } 194 195 198 public Dimension preferredLayoutSize(Container arg0) { 199 return this.getPreferredSize(); 200 } 201 202 205 public void windowActivated(WindowEvent arg0) { 206 } 207 208 211 public void windowDeactivated(WindowEvent arg0) { 212 } 213 214 217 public void windowDeiconified(WindowEvent arg0) { 218 } 219 220 223 public void windowIconified(WindowEvent arg0) { 224 } 225 226 229 public void windowOpened(WindowEvent arg0) { 230 } 231 232 } 233 | Popular Tags |