summaryrefslogtreecommitdiff
path: root/NET/worlds/console/MailDialog.java
blob: 95b976b1db6f2c4140df3f938e38e94cb2357a8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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();
   }
}