1 package rero.dialogs; 2 3 import javax.swing.*; 4 import javax.swing.event.*; 5 import javax.swing.tree.*; 6 7 import java.awt.*; 8 import java.awt.event.*; 9 10 import rero.config.*; 11 import rero.dialogs.help.*; 12 import rero.gui.*; 13 14 import java.net.*; 15 16 import java.util.*; 17 18 public class HelpWindow extends JDialog implements HyperlinkListener 19 { 20 private static HelpWindow dialog; 21 private static HashMap helpData = new HashMap(); 22 private static HelpData commandData; 23 24 private JEditorPane display; 25 private JScrollPane scroller; 26 27 public static LinkedList getBuiltInAliases() 28 { 29 if (commandData == null) 30 commandData = new HelpData(); 31 32 return commandData.getAliases(); 33 } 34 35 public static HelpData getCommandData() 36 { 37 return commandData; 38 } 39 40 public String getCommand(String key) 41 { 42 return commandData.getCommand(key).toString(); 43 } 44 45 public void scrollTo(String ref) 46 { 47 display.scrollToReference(ref); 48 } 49 50 public void updateText(String text) 51 { 52 display.setText(text); 53 display.setCaretPosition(0); 54 } 55 56 private static Frame frame; 57 58 public static void initialize(Component comp) 59 { 60 if (JOptionPane.getFrameForComponent(comp) != frame) 61 { 62 frame = JOptionPane.getFrameForComponent(comp); 63 dialog = new HelpWindow(frame); 64 } 65 } 66 67 public static String showDialog(Component comp) 68 { 69 KeyBindings.is_dialog_active = true; 70 dialog.setLocationRelativeTo(comp); 71 dialog.setVisible(true); 72 73 dialog.addWindowListener(new WindowAdapter() 74 { 75 public void windowClosing(WindowEvent ev) { KeyBindings.is_dialog_active = false; } 76 }); 77 return ""; 78 } 79 80 private HelpWindow(Frame frame) 81 { 82 super(frame, "jIRCii Help", false); 83 84 if (commandData == null) 85 commandData = new HelpData(); 86 87 JButton closeButton = new JButton("Ok"); 89 closeButton.setMnemonic('O'); 90 91 closeButton.addActionListener(new ActionListener() 92 { 93 public void actionPerformed(ActionEvent e) 94 { 95 HelpWindow.dialog.setVisible(false); 96 KeyBindings.is_dialog_active = false; 97 } 98 }); 99 100 getContentPane().setLayout(new BorderLayout(5, 5)); 101 102 JPanel main = new JPanel(); 103 main.setLayout(new BorderLayout(5, 5)); 104 main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 105 106 getContentPane().add(main, BorderLayout.CENTER); 107 108 HelpNormal general = new HelpNormal(); 112 general.setHelp(this); 113 114 HelpCommands commands = new HelpCommands(); 115 commands.setHelp(this); 116 117 JTabbedPane left = new JTabbedPane(); 118 left.addTab("Help", null, general.getNavigation(), "detailed information."); 119 left.addTab("Commands", null, commands.getNavigation(), "jIRCii command reference."); 120 121 left.setSelectedIndex(0); 122 left.setPreferredSize(new Dimension(175, 295)); 123 124 JPanel center = new JPanel(); 128 center.setLayout(new BorderLayout(5, 5)); 129 JPanel space = new JPanel(); 130 space.setPreferredSize(new Dimension(0, 15)); 131 132 center.add(space, BorderLayout.NORTH); 133 134 display = new JTextPane(); 135 display.setEditable(false); 136 display.setContentType("text/html"); display.setOpaque(true); 138 display.setBackground(Color.white); 139 140 display.addHyperlinkListener(this); 141 142 scroller = new JScrollPane(display); 143 scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 144 scroller.setPreferredSize(new Dimension(250, 250)); 145 146 center.add(scroller, BorderLayout.CENTER); 147 148 JPanel south = new JPanel(); 152 south.setLayout(new BorderLayout(5, 5)); 153 154 south.add(closeButton, BorderLayout.EAST); 155 south.add(new JPanel(), BorderLayout.CENTER); 156 157 main.add(left, BorderLayout.WEST); 161 main.add(center, BorderLayout.CENTER); 162 main.add(south, BorderLayout.SOUTH); 163 164 pack(); 165 166 setSize(new Dimension(600, 363)); 167 169 general.showHelpOn("About"); 170 } 171 172 public void hyperlinkUpdate(HyperlinkEvent ev) 173 { 174 if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 175 { 176 try 177 { 178 if (ev.getURL().getRef() != null) 179 { 180 display.scrollToReference(ev.getURL().getRef()); 181 } 182 else 183 { 184 Runtime.getRuntime().exec(ClientState.getClientState().getString("ui.openfiles", ClientDefaults.ui_openfiles) + " " + ev.getURL().toString()); 185 } 186 } 187 catch (Exception ex) { } 188 } 189 } 190 } 191 192 193 194 | Popular Tags |