1 9 package bluej.editor.moe; 10 11 import bluej.Config; 12 import bluej.utility.DialogManager; 13 import bluej.utility.BlueJFileReader; 14 15 import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; 19 20 24 public final class Info extends JPanel 25 implements ActionListener 26 { 27 static final ImageIcon helpImage = Config.getImageAsIcon("image.editor.help"); 28 29 public static Font infoFont = new Font("SansSerif", Font.BOLD, 10); 30 31 33 private JLabel line1; 34 private JLabel line2; 35 String originalMsg; 36 boolean isClear; 37 JButton helpButton; 38 String helpGroup; 39 40 42 public Info() 43 { 44 super(); 45 setLayout(new BorderLayout()); 46 setBorder(BorderFactory.createLineBorder(Color.black)); 47 setFont(infoFont); 48 49 JPanel body = new JPanel(new GridLayout(0, 1)); body.setBackground(MoeEditor.infoColor); 51 line1 = new JLabel(); 52 line2 = new JLabel(); 53 body.add(line1); 54 body.add(line2); 55 add(body, BorderLayout.CENTER); 56 57 helpButton = new JButton(helpImage); 58 helpButton.setMargin(new Insets(0,0,0,0)); 59 helpButton.addActionListener(this); 60 helpButton.setRequestFocusEnabled(false); add(helpButton, BorderLayout.EAST); 62 helpButton.setVisible(false); 63 64 isClear = true; 65 helpGroup = ""; 66 } 67 68 71 public void message(String msg) 72 { 73 originalMsg = msg; 74 int newline = msg.indexOf('\n'); 75 if (newline == -1) 76 if(msg.length() <= 81) 77 message (msg, ""); 78 else 79 message (msg.substring(0, 80), msg.substring(80)); 80 else 81 message (msg.substring(0, newline), msg.substring(newline+1)); 82 } 83 84 85 88 public void message(String msg1, String msg2) 89 { 90 line1.setText(msg1); 91 line2.setText(msg2.replace('\n', ' ')); 92 93 isClear = false; 94 95 hideHelp(); 96 } 97 98 99 102 public void warning(String msg) 103 { 104 message (msg); 105 MoeEditorManager.editorManager.beep(); 106 } 107 108 109 112 public void warning(String msg1, String msg2) 113 { 114 message (msg1, msg2); 115 MoeEditorManager.editorManager.beep(); 116 } 117 118 119 122 public void clear() 123 { 124 if (!isClear) { 125 message (" ", " "); 126 isClear = true; 127 } 128 } 129 130 131 134 public void setHelp(String helpGroup) 135 { 136 this.helpGroup = helpGroup; 137 helpButton.setVisible(true); 138 } 139 140 143 public void hideHelp() 144 { 145 helpButton.setVisible(false); 146 } 147 148 150 public void actionPerformed(ActionEvent evt) 151 { 152 displayHelp(helpGroup); 153 } 154 155 private void displayHelp(String helpGroup) 156 { 157 File fileName = Config.getLanguageFile(helpGroup + ".help"); 158 int i = originalMsg.indexOf('\n'); 159 160 String line; 162 if (i<0) { 163 line = originalMsg; 164 } else { 165 line = originalMsg.substring(0,i); 166 } 167 168 String helpText = BlueJFileReader.readHelpText(fileName, line.trim(), 169 false); 170 176 if(helpText == null) 177 DialogManager.showMessageWithText(null, "no-help", 178 "\n" + originalMsg); 179 else 180 DialogManager.showText(null, originalMsg + "\n\n" + helpText); 181 } 182 183 } | Popular Tags |