From 93bd63584790925e325857deaff02738332a0bd5 Mon Sep 17 00:00:00 2001 From: "ashuk%eng.sun.com" Date: Thu, 6 Apr 2000 17:36:57 +0000 Subject: [PATCH] Added AWT code to create a generic Dialog box. Used this to create a Find Dialog Box for the Find features in the CurrentPage interface a=ashuk r=edburns Bug=20659 Ashu --- .../mozilla/webclient/test/ButtonPanel.java | 40 ++++ .../mozilla/webclient/test/CheckBoxPanel.java | 39 ++++ .../mozilla/webclient/test/DialogClient.java | 13 ++ .../mozilla/webclient/test/FindDialog.java | 204 ++++++++++++++++++ .../org/mozilla/webclient/test/GJTDialog.java | 77 +++++++ .../org/mozilla/webclient/test/Postcard.java | 39 ++++ .../mozilla/webclient/test/WorkDialog.java | 60 ++++++ 7 files changed, 472 insertions(+) create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/ButtonPanel.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/CheckBoxPanel.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/DialogClient.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/FindDialog.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/GJTDialog.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/Postcard.java create mode 100644 java/webclient/classes_spec/org/mozilla/webclient/test/WorkDialog.java diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/ButtonPanel.java b/java/webclient/classes_spec/org/mozilla/webclient/test/ButtonPanel.java new file mode 100644 index 00000000000..6f1944aac84 --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/ButtonPanel.java @@ -0,0 +1,40 @@ +/** Ashu -- this is the ButtonPanel Class + * This acts a generic Button Panel + * for using in any Dialog + */ + +package org.mozilla.webclient.test; + +import java.awt.*; +import javax.swing.*; +import java.lang.*; + +public class ButtonPanel extends Panel { + Panel buttonPanel = new Panel(); + JSeparator separator = new JSeparator(); + + + public ButtonPanel() { + int buttonPanelOrient = FlowLayout.CENTER; + setLayout(new BorderLayout(0,5)); + buttonPanelOrient = FlowLayout.CENTER; + buttonPanel.setLayout(new FlowLayout(buttonPanelOrient)); + add(separator, "North"); + add(buttonPanel, "Center"); + } + + public void add(Button button) { + buttonPanel.add(button); + } + + public Button add(String buttonLabel) { + Button addMe = new Button(buttonLabel); + buttonPanel.add(addMe); + return addMe; + } + + protected String paramString() { + return super.paramString() + "buttons=" + getComponentCount(); + } +} + diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/CheckBoxPanel.java b/java/webclient/classes_spec/org/mozilla/webclient/test/CheckBoxPanel.java new file mode 100644 index 00000000000..b42cfd6d68a --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/CheckBoxPanel.java @@ -0,0 +1,39 @@ +/** Ashu -- this is the CheckBoxPanel Class + * This acts a generic CheckBox Panel + * for using in any Dialog + */ + +package org.mozilla.webclient.test; + +import java.awt.*; +import javax.swing.*; +import java.lang.*; + +public class CheckBoxPanel extends Panel { + Panel checkBoxPanel = new Panel(); + JSeparator separator = new JSeparator(); + + + public CheckBoxPanel() { + int checkBoxPanelOrient = FlowLayout.CENTER; + setLayout(new BorderLayout(5,0)); + checkBoxPanelOrient = FlowLayout.CENTER; + checkBoxPanel.setLayout(new FlowLayout(checkBoxPanelOrient)); + add(checkBoxPanel, "Center"); + } + + public void add(Checkbox checkBox) { + checkBoxPanel.add(checkBox); + } + + public Checkbox add(String checkBoxLabel) { + Checkbox addMe = new Checkbox(checkBoxLabel); + checkBoxPanel.add(addMe); + return addMe; + } + + protected String paramString() { + return super.paramString() + "checkBoxs=" + getComponentCount(); + } +} + diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/DialogClient.java b/java/webclient/classes_spec/org/mozilla/webclient/test/DialogClient.java new file mode 100644 index 00000000000..d009c13d935 --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/DialogClient.java @@ -0,0 +1,13 @@ +/** This is the DiaogClient interface + * for making client callbacks to the + * parent of a non-modal dialog box + */ + +package org.mozilla.webclient.test; + +import java.awt.*; + +public interface DialogClient { + void dialogDismissed(Dialog d); + void dialogCancelled(Dialog d); +} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/FindDialog.java b/java/webclient/classes_spec/org/mozilla/webclient/test/FindDialog.java new file mode 100644 index 00000000000..2c3875ae8e1 --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/FindDialog.java @@ -0,0 +1,204 @@ +/** Ashu -- this is the Find Dialog Class + instantiated within the EMWindow class, this + will act as the Modal dialog for calling Find/Find Next + functions for CurrentPage +*/ + +package org.mozilla.webclient.test; + +import java.awt.*; +import java.awt.event.*; + +public class FindDialog extends WorkDialog implements ActionListener, ItemListener{ + static private int _defaultTextFieldSize = 40; + private Button findButton; + private Button clearButton; + private Button closeButton; + private Checkbox backwardsCheckBox; + private Checkbox matchcaseCheckBox; + private String question; + private TextField textField; + private boolean wasClosed; + private boolean wasCleared; + public boolean backwards; + public boolean matchcase; + private ButtonPanel buttonPanel = new ButtonPanel(); + + + public FindDialog(Frame frame, DialogClient client, String title, + String question, String initialResponse) { + this(frame, client, title, question, initialResponse, + _defaultTextFieldSize, false); + } + + public FindDialog(Frame frame, DialogClient client, String title, + String question) { + this(frame, client, title, question, null, + _defaultTextFieldSize, false); + } + + public FindDialog(Frame frame, DialogClient client, String title, + String question, int textFieldSize) { + this(frame, client, title, question, null, + textFieldSize, false); + } + + public FindDialog(Frame frame, DialogClient client, String title, + String question, String initialResponse, int textFieldSize) { + this(frame, client, title, question, initialResponse, + textFieldSize, false); + } + + public FindDialog(Frame frame, DialogClient client, String title, + String question, String initialResponse, + int textFieldSize, boolean modal) { + super(frame, client, title, modal); + QuestionPanel questionPanel; + findButton = addButton("Find"); + clearButton = addButton("Clear"); + closeButton = addButton("Close"); + backwardsCheckBox = addCheckBox("Backwards"); + matchcaseCheckBox = addCheckBox("Matchcase"); + + findButton.addActionListener(this); + clearButton.addActionListener(this); + closeButton.addActionListener(this); + backwardsCheckBox.addItemListener(this); + matchcaseCheckBox.addItemListener(this); + + questionPanel = new QuestionPanel(this, question, initialResponse, + textFieldSize); + textField = questionPanel.getTextField(); + setWorkPanel(questionPanel); + } + + public void actionPerformed(ActionEvent ae) { + if(ae.getSource() == closeButton) { + wasClosed = true; + wasCleared = false; + dispose(true); + } + else if(ae.getSource() == clearButton) { + wasCleared = true; + wasClosed = false; + setTextField(""); + dispose(false); + } + else if(ae.getSource() == findButton) { + wasCleared = false; + wasClosed = false; + dispose(false); + } + /* else if(ae.getSource() == backwardsCheckBox) { + if(backwardsCheckBox.getState()) + backwards = true; + else + backwards = false; + } + else if(ae.getSource() == matchcaseCheckBox) { + if(matchcaseCheckBox.getState()) + matchcase = true; + else + matchcase = false; + } */ + } + + + public void itemStateChanged(ItemEvent e) { + if(e.getSource() == backwardsCheckBox) { + if(backwardsCheckBox.getState()) + backwards = true; + else + backwards = false; + } + else if(e.getSource() == matchcaseCheckBox) { + if(matchcaseCheckBox.getState()) + matchcase = true; + else + matchcase = false; + } + } + + public void setVisible(boolean b) { + textField.requestFocus(); + super.setVisible(b); + } + + public void returnInTextField() { + findButton.requestFocus(); + } + + public TextField getTextField() { + return textField; + } + + public void setTextField(String string) { + // questionPanel.setTextField(string); + textField.setText(string); + } + + public String getAnswer() { + return textField.getText(); + } + + public boolean wasClosed() { + return wasClosed; + } + + public boolean wasCleared() { + return wasCleared; + } + + private void setQuestion(String question) { + this.question = question; + } +} + + +class QuestionPanel extends Postcard { + private TextField field; + private FindDialog dialog; + + public QuestionPanel(FindDialog dialog, String question) { + this(dialog, question, null, 0); + } + + public QuestionPanel(FindDialog dialog, String question, int columns) { + this(dialog, question, null, columns); + } + + public QuestionPanel(FindDialog myDialog, String question, String initialResponse, int cols) { + super(new Panel()); + Panel panel = getPanel(); + this.dialog = myDialog; + panel.setLayout(new GridLayout()); + panel.add(new Label(question)); + + if(initialResponse != null) { + if(cols != 0) + panel.add(field = new TextField(initialResponse, cols)); + else + panel.add(field = new TextField(initialResponse)); + } + else { + if(cols != 0) panel.add(field = new TextField(cols)); + else panel.add(field = new TextField()); + } + + field.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + dialog.returnInTextField(); + } + } ); + } + + public TextField getTextField() { + return field; + } + + public void setTextField(String string) { + field.setText(string); + } + +} + diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/GJTDialog.java b/java/webclient/classes_spec/org/mozilla/webclient/test/GJTDialog.java new file mode 100644 index 00000000000..e87b9615f1c --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/GJTDialog.java @@ -0,0 +1,77 @@ +/** Ashu -- this is the GJTDialog Class + * This contains the basic dialog functionality + * for generic dialogs + */ + +package org.mozilla.webclient.test; + +import java.lang.*; +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import java.util.*; + + +public class GJTDialog extends Dialog { + protected DialogClient client; + protected Frame frame; + protected boolean centered; + + public GJTDialog(Frame frame, String title, DialogClient aClient, boolean modal) { + this(frame, title, aClient, true, modal); + } + + public GJTDialog(Frame frame, String title, DialogClient aClient, + boolean centered, boolean modal) { + super(frame, title, modal); + setClient(aClient); + setCentered(centered); + setFrame(frame); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent event) { + dispose(true); + if(client != null) + client.dialogCancelled(GJTDialog.this); + } + }); + } + + public void setCentered(boolean centered) { + this.centered = centered; + } + + public void setClient(DialogClient client) { + this.client = client; + } + + public void setFrame(Frame frame) { + this.frame = frame; + } + + public void dispose(boolean toDispose) { + if(toDispose) { + super.dispose(); + frame.toFront(); + } + if(client != null) + client.dialogDismissed(this); + } + + public void setVisible(boolean visible) { + pack(); + if(centered) { + Dimension frameSize = getParent().getSize(); + Point frameLoc = getParent().getLocation(); + Dimension mySize = getSize(); + int x,y; + x = frameLoc.x + (frameSize.width/2) - (mySize.width/2); + y = frameLoc.y + (frameSize.height/2) - (mySize.height/2); + setBounds(x,y,getSize().width,getSize().height); + } + super.setVisible(visible); + } + +} + diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/Postcard.java b/java/webclient/classes_spec/org/mozilla/webclient/test/Postcard.java new file mode 100644 index 00000000000..64ee4e11cfc --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/Postcard.java @@ -0,0 +1,39 @@ +/** Ashu -- this is the Postcard Class + * This acts a generic Panel for the Dialog + */ + +package org.mozilla.webclient.test; + +import java.awt.*; + + +public class Postcard extends Panel { + private Panel panel, panelContainer = new Panel(); + + + public Postcard(Panel panel) { + if(panel != null) setPanel(panel); + setLayout(new GridLayout()); + add(panelContainer); + } + + public Panel getPanel() { + if(panelContainer.getComponentCount() == 1) + return (Panel)panelContainer.getComponent(0); + else + return null; + } + + public void setPanel(Panel panel) { + if(panelContainer.getComponentCount() == 1) { + panelContainer.remove(getComponent(0)); + } + this.panel = panel; + panelContainer.add(panel); + } + + public Insets getInsets() { + return new Insets(10,10,10,10); + } + +} diff --git a/java/webclient/classes_spec/org/mozilla/webclient/test/WorkDialog.java b/java/webclient/classes_spec/org/mozilla/webclient/test/WorkDialog.java new file mode 100644 index 00000000000..5e7945a2180 --- /dev/null +++ b/java/webclient/classes_spec/org/mozilla/webclient/test/WorkDialog.java @@ -0,0 +1,60 @@ +/** Ashu -- this is the WorkDialog Class + * This acts a generic Dialog class with + * a buttons panel and a work area panel + */ + +package org.mozilla.webclient.test; + +import java.awt.*; +import java.awt.event.*; +import java.lang.*; + +public class WorkDialog extends GJTDialog { + private ButtonPanel buttonPanel; + private CheckBoxPanel checkBoxPanel; + private Panel workPanel; + + public WorkDialog(Frame frame, DialogClient client, String title) { + this(frame, client, title, null, false); + } + + public WorkDialog(Frame frame, DialogClient client, String title, boolean modal) { + this(frame, client, title, null, modal); + } + + public WorkDialog(Frame frame, DialogClient client, String title, + Panel workPanel, boolean modal) { + super(frame, title, client, modal); + this.workPanel = workPanel; + setLayout(new BorderLayout()); + if(workPanel != null) + add(workPanel, "North"); + add("West", checkBoxPanel = new CheckBoxPanel()); + add("South", buttonPanel = new ButtonPanel()); + } + + public void setWorkPanel(Panel workPanel) { + if(workPanel != null) + remove(workPanel); + this.workPanel = workPanel; + add(workPanel, "Center"); + if(isShowing()) + validate(); + } + + public Button addButton(String string) { + return buttonPanel.add(string); + } + + public void addButton(Button button) { + buttonPanel.add(button); + } + + public Checkbox addCheckBox(String string) { + return checkBoxPanel.add(string); + } + + public void addCheckBox(Checkbox checkBox) { + checkBoxPanel.add(checkBox); + } +}