summaryrefslogtreecommitdiff
path: root/NET/worlds/console/SnapToolPanel.java
blob: 460c065e314e0ecda1de32afbf0893dede284c7f (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package NET.worlds.console;

import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Point;
import java.awt.TextField;

public class SnapToolPanel extends Frame implements MainCallback, MainTerminalCallback {
   private static final long serialVersionUID = 1673536928568480266L;
   private Label xLabel;
   private Label yLabel;
   private Label zLabel;
   private TextField xValue;
   private TextField yValue;
   private TextField zValue;
   private Checkbox useSnapBox;
   private Button okButton = new Button("Ok");
   private Button cancelButton = new Button("Cancel");
   private int snapX;
   private int snapY;
   private int snapZ;
   private boolean useSnap;

   public SnapToolPanel(java.awt.Window parent) {
      super("Snap Tool Settings");
      this.xLabel = new Label("X Snap Value");
      this.yLabel = new Label("Y Snap Value");
      this.zLabel = new Label("Z Snap Value");
      this.snapX = SnapTool.snapTool().getSnapX();
      this.snapY = SnapTool.snapTool().getSnapY();
      this.snapZ = SnapTool.snapTool().getSnapZ();
      this.useSnap = SnapTool.snapTool().useSnap();
      this.useSnapBox = new Checkbox("Use Snap Tool", this.useSnap);
      this.xValue = new TextField("" + this.snapX);
      this.yValue = new TextField("" + this.snapY);
      this.zValue = new TextField("" + this.snapZ);
      GridBagLayout gbag = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      this.setLayout(gbag);
      this.setBackground(Color.gray);
      c.gridx = 1;
      c.gridy = 1;
      c.gridheight = 1;
      c.gridwidth = 1;
      c.anchor = 18;
      gbag.setConstraints(this.xLabel, c);
      this.add(this.xLabel);
      c.gridx = 2;
      c.gridy = 1;
      gbag.setConstraints(this.xValue, c);
      this.add(this.xValue);
      c.gridx = 1;
      c.gridy = 2;
      gbag.setConstraints(this.yLabel, c);
      this.add(this.yLabel);
      c.gridx = 2;
      c.gridy = 2;
      gbag.setConstraints(this.yValue, c);
      this.add(this.yValue);
      c.gridx = 1;
      c.gridy = 3;
      gbag.setConstraints(this.zLabel, c);
      this.add(this.zLabel);
      c.gridx = 2;
      c.gridy = 3;
      gbag.setConstraints(this.zValue, c);
      this.add(this.zValue);
      c.gridx = 2;
      c.gridy = 5;
      gbag.setConstraints(this.useSnapBox, c);
      this.add(this.useSnapBox);
      c.gridx = 5;
      c.gridy = 1;
      gbag.setConstraints(this.okButton, c);
      this.add(this.okButton);
      c.gridx = 5;
      c.gridy = 2;
      gbag.setConstraints(this.cancelButton, c);
      this.add(this.cancelButton);
      this.pack();
      Point loc = parent.location();
      Dimension size = parent.getSize();
      this.reshape(loc.x + (size.width - 320) / 2, loc.y + (size.height - 240) / 2, 320, 240);
      this.show();
      Main.register(this);
   }

   @Override
   public boolean handleEvent(Event ev) {
      switch (ev.id) {
         case 201:
            this.dispose();
            return true;
         default:
            return super.handleEvent(ev);
      }
   }

   @Override
   public boolean action(Event e, Object o) {
      if (e.target == this.cancelButton) {
         this.dispose();
         return true;
      } else if (e.target == this.okButton) {
         this.snapX = Integer.parseInt(this.xValue.getText());
         this.snapY = Integer.parseInt(this.yValue.getText());
         this.snapZ = Integer.parseInt(this.zValue.getText());
         this.useSnap = this.useSnapBox.getState();
         SnapTool.snapTool().setSnap(this.useSnap);
         SnapTool.snapTool().setSnapX(this.snapX);
         SnapTool.snapTool().setSnapY(this.snapY);
         SnapTool.snapTool().setSnapZ(this.snapZ);
         this.dispose();
         return true;
      } else {
         return false;
      }
   }

   @Override
   public void mainCallback() {
   }

   @Override
   public void terminalCallback() {
      Main.unregister(this);
   }
}