home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-04-08 | 3.0 KB | 153 lines |
- //
- // Mini Java Editor dialogs
- //
-
- import java.awt.*;
-
- //
- // Go to line dialog
- //
-
- class GotoDialog extends Dialog {
- MJEWindow win;
- TextField lineText;
-
- public GotoDialog(Frame parent) {
- super(parent, "Go to Line...", false);
-
- win = (MJEWindow) parent;
- lineText = new TextField("", 7);
-
- add("West", new Label("Line:"));
- add("Center", lineText);
- add("East", new Button(" Go "));
- }
-
- public boolean handleEvent(Event evt) {
- if (evt.id == Event.WINDOW_DESTROY)
- dispose();
-
- return super.handleEvent(evt);
- }
-
- public boolean action(Event evt, Object obj) {
- // if (evt.target instanceof Button) {
- win.gotoLine(new Integer(lineText.getText()).intValue());
- return true;
- // }
-
- // return false;
- }
- }
-
- //
- // Find dialog
- //
-
- class FindDialog extends Dialog {
- MJEWindow win;
- TextField findText, replaceText;
- Checkbox match;
-
- public FindDialog(Frame parent) {
- super(parent, "Find...", false);
-
- win = (MJEWindow) parent;
- findText = new TextField("", 8);
- replaceText = new TextField("", 8);
- match = new Checkbox("Match Case");
-
- HVPanel p1 = new HVPanel(HVPanel.HORIZONTAL, 5, 0, 0);
- p1.add(0, new Label("Find:"));
- p1.add(0, findText);
- p1.add(0, new Label("Replace:"));
- p1.add(0, replaceText);
-
- HVPanel p2 = new HVPanel(HVPanel.HORIZONTAL, 5, 0, 0);
- p2.add(0, match);
- p2.add(0, new Button("Find"));
- p2.add(0, new Button("Replace"));
-
- add("North", p1);
- add("South", p2);
- }
-
- public boolean handleEvent(Event evt) {
- if (evt.id == Event.WINDOW_DESTROY)
- dispose();
-
- return super.handleEvent(evt);
- }
-
- public boolean action(Event evt, Object obj) {
- if (evt.target instanceof Button) {
- String name = (String) obj;
- TextArea area = win.getTextArea();
-
- // Replace text
-
- if (obj.equals("Replace")) {
- int start = area.getSelectionStart();
- int end = area.getSelectionEnd();
-
- if (end > start)
- area.replaceText(replaceText.getText(), start, end);
- }
-
- // Find text
-
- String txt, str;
-
- if (match.getState()) {
- txt = area.getText();
- str = findText.getText();
- }
- else {
- txt = area.getText().toLowerCase();
- str = findText.getText().toLowerCase();
- }
-
- area.requestFocus();
- int pos = txt.indexOf(str, area.getSelectionEnd());
-
- if (pos > 0)
- area.select(pos, pos + str.length());
-
- return true;
- }
-
- if (evt.target instanceof Checkbox)
- return true;
-
- return false;
- }
- }
-
- //
- // Info dialog
- //
-
- class InfoDialog extends Dialog {
- public InfoDialog(Frame parent, String title, String msg) {
- super(parent, title, true);
-
- Label text = new Label(msg);
- Button button = new Button("OK");
-
- HVPanel p1 = new HVPanel(HVPanel.HORIZONTAL, 5, 0, 80);
- p1.add(0, button);
-
- HVPanel p2 = new HVPanel(HVPanel.VERTICAL, 5, 5, 0);
- p2.add(0, text);
- p2.add(0, p1);
-
- add("Center", p2);
- }
-
- public boolean action(Event evt, Object obj) {
- dispose();
- return true;
- }
- }
-
-