001: // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
002: //
003: // This software is made available under the terms of the "MIT License"
004: // A copy of this license is included with this source distribution
005: // in "license.txt" and is also available at:
006: // http://www.opensource.org/licenses/mit-license.html
007: // Any queries should be directed to Michael Kolling mik@bluej.org
008:
009: package bluej.editor.moe;
010:
011: import bluej.Config;
012: import bluej.utility.DialogManager;
013: import bluej.utility.BlueJFileReader;
014:
015: import java.awt.*; // MenuBar, MenuItem, Menu, Button, etc.
016: import java.awt.event.*; // New Event model
017: import javax.swing.*; // all the GUI components
018: import java.io.*;
019:
020: /**
021: *
022: * @author Michael Kolling
023: */
024: public final class Info extends JPanel implements ActionListener {
025: static final ImageIcon helpImage = Config
026: .getImageAsIcon("image.editor.help");
027:
028: public static Font infoFont = new Font("SansSerif", Font.BOLD, 10);
029:
030: // -------- INSTANCE VARIABLES --------
031:
032: private JLabel line1;
033: private JLabel line2;
034: String originalMsg;
035: boolean isClear;
036: JButton helpButton;
037: String helpGroup;
038:
039: // ------------- METHODS --------------
040:
041: public Info() {
042: super ();
043: setLayout(new BorderLayout());
044: setBorder(BorderFactory.createLineBorder(Color.black));
045: setFont(infoFont);
046:
047: JPanel body = new JPanel(new GridLayout(0, 1)); // one col, many rows
048: body.setBackground(MoeEditor.infoColor);
049: line1 = new JLabel();
050: line2 = new JLabel();
051: body.add(line1);
052: body.add(line2);
053: add(body, BorderLayout.CENTER);
054:
055: helpButton = new JButton(helpImage);
056: helpButton.setMargin(new Insets(0, 0, 0, 0));
057: helpButton.addActionListener(this );
058: helpButton.setRequestFocusEnabled(false); // never get focus
059: add(helpButton, BorderLayout.EAST);
060: helpButton.setVisible(false);
061:
062: isClear = true;
063: helpGroup = "";
064: }
065:
066: /**
067: * display a one line message
068: */
069: public void message(String msg) {
070: originalMsg = msg;
071: int newline = msg.indexOf('\n');
072: if (newline == -1)
073: if (msg.length() <= 81)
074: message(msg, "");
075: else
076: message(msg.substring(0, 80), msg.substring(80));
077: else
078: message(msg.substring(0, newline), msg
079: .substring(newline + 1));
080: }
081:
082: /**
083: * display a two line message
084: */
085: public void message(String msg1, String msg2) {
086: line1.setText(msg1);
087: line2.setText(msg2.replace('\n', ' '));
088:
089: isClear = false;
090:
091: hideHelp();
092: }
093:
094: /**
095: * display a one line warning (message with beep)
096: */
097: public void warning(String msg) {
098: message(msg);
099: MoeEditorManager.editorManager.beep();
100: }
101:
102: /**
103: * display a two line warning (message with beep)
104: */
105: public void warning(String msg1, String msg2) {
106: message(msg1, msg2);
107: MoeEditorManager.editorManager.beep();
108: }
109:
110: /**
111: * clear the display
112: */
113: public void clear() {
114: if (!isClear) {
115: message(" ", " ");
116: isClear = true;
117: }
118: }
119:
120: /**
121: *
122: */
123: public void setHelp(String helpGroup) {
124: this .helpGroup = helpGroup;
125: helpButton.setVisible(true);
126: }
127:
128: /**
129: *
130: */
131: public void hideHelp() {
132: helpButton.setVisible(false);
133: }
134:
135: // ---- ActionListener interface ----
136:
137: public void actionPerformed(ActionEvent evt) {
138: displayHelp(helpGroup);
139: }
140:
141: private void displayHelp(String helpGroup) {
142: File fileName = Config.getLanguageFile(helpGroup + ".help");
143: int i = originalMsg.indexOf('\n');
144:
145: // fix for newline bug #386 with jdk1.4.0
146: String line;
147: if (i < 0) {
148: line = originalMsg;
149: } else {
150: line = originalMsg.substring(0, i);
151: }
152:
153: String helpText = BlueJFileReader.readHelpText(fileName, line
154: .trim(), false);
155: // if(originalMsg.length() > 60) {
156: // int half = originalMsg.length() / 2;
157: // originalMsg = originalMsg.substring(0, half) + "\n" +
158: // originalMsg.substring(half);
159: // }
160:
161: if (helpText == null)
162: DialogManager.showMessageWithText(null, "no-help", "\n"
163: + originalMsg);
164: else
165: DialogManager.showText(null, originalMsg + "\n\n"
166: + helpText);
167: }
168:
169: } // end class Info
|