diff options
Diffstat (limited to 'NET/worlds/console/MailDialog.java')
| -rw-r--r-- | NET/worlds/console/MailDialog.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/NET/worlds/console/MailDialog.java b/NET/worlds/console/MailDialog.java new file mode 100644 index 0000000..95b976b --- /dev/null +++ b/NET/worlds/console/MailDialog.java @@ -0,0 +1,107 @@ +package NET.worlds.console; + +import java.awt.Component; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Label; +import java.awt.TextArea; +import java.awt.TextField; +import java.util.StringTokenizer; + +class MailDialog extends OkCancelDialog { + private static final long serialVersionUID = -5118823076163262543L; + private TextField recipientField; + private TextField subjectField; + private TextArea bodyTextArea; + private static Font font = new Font(Console.message("ConsoleFont"), 0, 12); + + public MailDialog(Console console) { + super(Console.getFrame(), new MailDialogReceiver(console), Console.message("Mail"), Console.message("Dont-Send"), Console.message("Send"), null, false); + this.setConfirmKey(0); + this.recipientField = new TextField(); + this.recipientField.setFont(font); + this.subjectField = new TextField(); + this.subjectField.setFont(font); + this.bodyTextArea = new TextArea("", 5, 50, 1); + this.bodyTextArea.setEditable(true); + this.bodyTextArea.setFont(font); + this.setAlignment(1); + } + + public MailDialog(Console console, String recipient) { + this(console); + this.recipientField.setText(Console.parseExtended(recipient)); + this.recipientField.setFont(font); + } + + @Override + protected void build() { + GridBagConstraints c = new GridBagConstraints(); + int line = 0; + c.fill = 0; + c.anchor = 13; + this.add(this.gbag, new Label(Console.message("To")), c, 0, line, 1, 1, 0, 0); + c.fill = 2; + c.anchor = 17; + this.add(this.gbag, this.recipientField, c, 1, line, 3, 1, 100, 0); + line++; + c.fill = 0; + c.anchor = 13; + Label subjectLabel = new Label(Console.message("Subject")); + subjectLabel.setFont(font); + this.add(this.gbag, subjectLabel, c, 0, line, 1, 1, 0, 0); + c.fill = 2; + c.anchor = 17; + this.add(this.gbag, this.subjectField, c, 1, line, 3, 1, 100, 0); + line++; + c.anchor = 10; + c.fill = 1; + this.add(this.gbag, this.bodyTextArea, c, 0, line, 4, 1, 100, 100); + line++; + c.fill = 0; + if (this.okButton != null) { + this.okButton.setFont(font); + this.add(this.gbag, this.okButton, c, 1, line, 1, 1, 100, 0); + } + + if (this.cancelButton != null) { + this.cancelButton.setFont(font); + this.add(this.gbag, this.cancelButton, c, 2, line, 1, 1, 100, 0); + } + } + + private void add(GridBagLayout gbag, Component comp, GridBagConstraints cont, int x, int y, int w, int h, int wx, int wy) { + cont.gridx = x; + cont.gridy = y; + cont.gridwidth = w; + cont.gridheight = h; + cont.weightx = wx; + cont.weighty = wy; + this.add(gbag, comp, cont); + } + + public String[] getTo() { + Console console = Console.getActive(); + String toLine = this.recipientField.getText(); + StringTokenizer tokenizer = new StringTokenizer(toLine, ","); + String[] to = new String[tokenizer.countTokens()]; + + for (int i = 0; tokenizer.hasMoreTokens(); i++) { + to[i] = tokenizer.nextToken().trim(); + if (to[i].indexOf("@") == -1 && console != null) { + to[i] = to[i] + "@" + console.getMailDomain(); + } + } + + return to; + } + + public String getSubject() { + return this.subjectField.getText(); + } + + public String getBody() { + return this.bodyTextArea.getText(); + } +} |