summaryrefslogtreecommitdiff
path: root/NET/worlds/console/PersonalInfoDialog.java
blob: db5c6e2e5a1eeee71eef61694832c271a51d3c42 (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
108
109
110
111
112
113
package NET.worlds.console;

import java.awt.Button;
import java.awt.Event;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.util.StringTokenizer;
import java.util.Vector;

class PersonalInfoDialog extends PolledDialog {
   private static final long serialVersionUID = 1200424099007473332L;
   private Vector<String> info;
   private Button okButton = new Button(Console.message("OK"));
   private static Font font = new Font(Console.message("MenuFont"), 0, 12);
   private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);

   public PersonalInfoDialog(String name, Vector<String> info) {
      super(Console.getFrame(), null, Console.message("Personal-Info") + name, false);
      this.info = info;
      this.ready();
   }

   @Override
   protected void build() {
      GridBagLayout gbag = new GridBagLayout();
      this.setLayout(gbag);
      GridBagConstraints c = new GridBagConstraints();

      try {
         int count = this.info.size();
         int i = 0;

         while (i < count) {
            StringTokenizer tok = new StringTokenizer(this.info.elementAt(i++), ":");
            String heading = tok.nextToken();
            c.gridwidth = -1;
            c.gridheight = 1;
            c.fill = 1;
            Label lHead = new Label(heading, 1);
            lHead.setFont(font);
            this.add(gbag, lHead, c);
            int totalLines = Integer.parseInt(tok.nextToken());
            int displayLines = Math.max(Math.min(3, totalLines), 1);
            int maxLine = 0;

            for (int j = 0; j < totalLines; j++) {
               maxLine = Math.max(maxLine, this.info.elementAt(i + j).length());
            }

            int scrollFlags = 3;
            if (maxLine > 40) {
               if (totalLines > ++displayLines) {
                  scrollFlags = 0;
               } else {
                  scrollFlags = 2;
               }
            } else if (totalLines > displayLines) {
               scrollFlags = 1;
            }

            TextArea t = new TextArea("", displayLines, 40, scrollFlags);
            t.setFont(font);

            for (int j = 0; j < totalLines; j++) {
               if (j > 0) {
                  t.append("\n");
               }

               t.append(this.info.elementAt(i++));
            }

            c.fill = 0;
            c.gridwidth = 0;
            c.gridheight = displayLines;
            t.setEditable(false);
            this.add(gbag, t, c);
         }
      } catch (Exception var14) {
         this.removeAll();
         c.fill = 0;
         c.gridwidth = 0;
         c.gridheight = 1;
         Label lFormat = new Label(Console.message("Format-error"));
         lFormat.setFont(font);
         this.add(gbag, lFormat, c);
      }

      c.fill = 0;
      c.gridwidth = 0;
      c.gridheight = 1;
      this.okButton.setFont(bfont);
      this.add(gbag, this.okButton, c);
   }

   @Override
   public boolean action(Event event, Object what) {
      return event.target == this.okButton ? this.done(false) : false;
   }

   @Override
   public boolean keyDown(Event event, int key) {
      return key != 27 && key != 10 ? super.keyDown(event, key) : this.done(false);
   }

   @Override
   public void show() {
      super.show();
      this.okButton.requestFocus();
   }
}