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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
package org.reprap.gui;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.OutputStream;
import java.net.URL;
import java.util.Properties;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Preferences extends javax.swing.JDialog {
private JButton jButtonOK;
private JButton jButtonCancel;
private JComboBox geometry;
private JLabel jLabel2;
private JLabel jLabel4;
private JLabel jLabel8;
private JTextField extruderRz1;
private JTextField extruderAddress1;
private JTextField extruderBeta1;
private JLabel jLabel15;
private JLabel jLabel14;
private JLabel jLabel13;
private JLabel jLabel12;
private JLabel jLabel11;
private JPanel jPanelExtruders;
private JLabel jLabel10;
private JLabel jLabel9;
private JTextField motorTorque1;
private JTextField motorTorque2;
private JTextField motorTorque3;
private JTextField motorAddress1;
private JTextField motorAddress2;
private JTextField motorAddress3;
private JLabel jLabel7;
private JLabel jLabel6;
private JLabel jLabel5;
private JLabel jLabel3;
private JPanel jPanelMotors;
private JTextPane jTextPane1;
private JTextField serialPort;
private JLabel jLabel1;
private JPanel jPanelGeneral;
private JTabbedPane jTabbedPane1;
private String [][] geometries =
{
{ "cartesian", "Cartesian" },
{ "nullcartesian", "Null cartesian" }
};
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
Preferences inst = new Preferences(frame);
inst.setVisible(true);
}
public void loadPreferences() {
try {
Properties props = new Properties();
URL url = ClassLoader.getSystemResource("reprap.properties");
props.load(url.openStream());
serialPort.setText(props.getProperty("Port"));
motorAddress1.setText(props.getProperty("Axis1Address"));
motorAddress2.setText(props.getProperty("Axis2Address"));
motorAddress3.setText(props.getProperty("Axis3Address"));
motorTorque1.setText(props.getProperty("Axis1Torque"));
motorTorque2.setText(props.getProperty("Axis2Torque"));
motorTorque3.setText(props.getProperty("Axis3Torque"));
extruderAddress1.setText(props.getProperty("Extruder1Address"));
extruderBeta1.setText(props.getProperty("Extruder1Beta"));
extruderRz1.setText(props.getProperty("Extruder1Rz"));
String geometryName = props.getProperty("Geometry");
for(int i = 0; i < geometries.length; i++)
if (geometries[i][0].compareToIgnoreCase(geometryName) == 0)
geometry.setSelectedIndex(i);
// Fall back to some defaults
if (motorTorque1.getText().length() == 0) motorTorque1.setText("33");
if (motorTorque2.getText().length() == 0) motorTorque2.setText("33");
if (motorTorque3.getText().length() == 0) motorTorque3.setText("33");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Loading preferences: " + ex);
ex.printStackTrace();
}
}
public void savePreferences() {
try {
Properties props = new Properties();
URL url = ClassLoader.getSystemResource("reprap.properties");
props.load(url.openStream());
props.setProperty("Port", serialPort.getText());
props.setProperty("Axis1Address", motorAddress1.getText());
props.setProperty("Axis2Address", motorAddress2.getText());
props.setProperty("Axis3Address", motorAddress3.getText());
props.setProperty("Axis1Torque", motorTorque1.getText());
props.setProperty("Axis2Torque", motorTorque2.getText());
props.setProperty("Axis3Torque", motorTorque3.getText());
props.setProperty("Geometry", geometries[geometry.getSelectedIndex()][0]);
props.setProperty("Extruder1Address", extruderAddress1.getText());
props.setProperty("Extruder1Beta", extruderBeta1.getText());
props.setProperty("Extruder1Rz", extruderRz1.getText());
extruderAddress1.setText(props.getProperty("Extruder1Address"));
extruderBeta1.setText(props.getProperty("Extruder1Beta"));
extruderRz1.setText(props.getProperty("Extruder1Rz"));
OutputStream output = new java.io.FileOutputStream(url.getPath());
props.store(output, "Reprap properties http://reprap.org/");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Saving preferences: " + ex);
ex.printStackTrace();
}
}
public Preferences(JFrame frame) {
super(frame);
initGUI();
loadPreferences();
Utility.centerWindowOnParent(this, frame);
}
private void initGUI() {
try {
{
jButtonOK = new JButton();
getContentPane().add(jButtonOK);
jButtonOK.setText("OK");
jButtonOK.setBounds(308, 238, 77, 28);
jButtonOK.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
jButtonOKMouseClicked(evt);
}
});
}
{
jButtonCancel = new JButton();
getContentPane().add(jButtonCancel);
jButtonCancel.setText("Cancel");
jButtonCancel.setBounds(217, 238, 77, 28);
jButtonCancel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
jButtonCancelMouseClicked(evt);
}
});
}
{
jTabbedPane1 = new JTabbedPane();
getContentPane().add(jTabbedPane1);
jTabbedPane1.setBounds(7, 7, 378, 224);
{
jPanelGeneral = new JPanel();
jTabbedPane1.addTab("General", null, jPanelGeneral, null);
jPanelGeneral.setPreferredSize(new java.awt.Dimension(373, 198));
jPanelGeneral.setLayout(null);
{
jLabel1 = new JLabel();
jPanelGeneral.add(jLabel1);
jLabel1.setText("Serial port");
jLabel1.setBounds(7, 14, 84, 28);
}
{
serialPort = new JTextField();
jPanelGeneral.add(serialPort);
serialPort.setBounds(91, 14, 154, 28);
}
{
jTextPane1 = new JTextPane();
jPanelGeneral.add(jTextPane1);
jTextPane1.setText("For linux use a number such as \"0\", \"1\" or alternatively use the full path to your serial device. For Windows use \"COM1\", \"COM2\" etc.");
jTextPane1.setBounds(91, 49, 273, 63);
jTextPane1.setEnabled(false);
jTextPane1.setEditable(false);
jTextPane1.setOpaque(false);
}
}
{
jPanelMotors = new JPanel();
jTabbedPane1.addTab("Axes", null, jPanelMotors, null);
jPanelMotors.setLayout(null);
{
String [] geometryList = new String[geometries.length];
for(int i = 0; i < geometries.length; i++)
geometryList[i] = geometries[i][1];
ComboBoxModel geometryModel = new DefaultComboBoxModel(
geometryList);
geometry = new JComboBox();
jPanelMotors.add(geometry);
geometry.setModel(geometryModel);
geometry.setBounds(91, 14, 182, 28);
}
{
jLabel2 = new JLabel();
jPanelMotors.add(jLabel2);
jLabel2.setText("Geometry");
jLabel2.setBounds(14, 14, 63, 28);
}
{
jLabel3 = new JLabel();
jPanelMotors.add(jLabel3);
jLabel3.setText("Motor 1 (X)");
jLabel3.setBounds(14, 81, 84, 28);
}
{
jLabel4 = new JLabel();
jPanelMotors.add(jLabel4);
jLabel4.setText("Motor 2 (Y)");
jLabel4.setBounds(14, 109, 84, 28);
}
{
jLabel5 = new JLabel();
jPanelMotors.add(jLabel5);
jLabel5.setText("Motor 3 (Z)");
jLabel5.setBounds(14, 137, 84, 28);
}
{
jLabel6 = new JLabel();
jPanelMotors.add(jLabel6);
jLabel6.setText("Address");
jLabel6.setBounds(105, 56, 63, 28);
jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
}
{
jLabel7 = new JLabel();
jPanelMotors.add(jLabel7);
jLabel7.setText("Max torque");
jLabel7.setBounds(182, 56, 77, 28);
}
{
motorAddress3 = new JTextField();
jPanelMotors.add(motorAddress3);
motorAddress3.setBounds(112, 140, 49, 21);
}
{
motorAddress1 = new JTextField();
jPanelMotors.add(motorAddress1);
motorAddress1.setBounds(112, 84, 49, 21);
}
{
motorAddress2 = new JTextField();
jPanelMotors.add(motorAddress2);
motorAddress2.setBounds(112, 112, 49, 21);
}
{
motorTorque1 = new JTextField();
jPanelMotors.add(motorTorque1);
motorTorque1.setBounds(182, 84, 35, 21);
}
{
motorTorque3 = new JTextField();
jPanelMotors.add(motorTorque3);
motorTorque3.setBounds(182, 140, 35, 21);
}
{
motorTorque2 = new JTextField();
jPanelMotors.add(motorTorque2);
motorTorque2.setBounds(182, 112, 35, 21);
}
{
jLabel8 = new JLabel();
jPanelMotors.add(jLabel8);
jLabel8.setText("%");
jLabel8.setBounds(224, 140, 21, 21);
}
{
jLabel9 = new JLabel();
jPanelMotors.add(jLabel9);
jLabel9.setText("%");
jLabel9.setBounds(224, 84, 21, 21);
}
{
jLabel10 = new JLabel();
jPanelMotors.add(jLabel10);
jLabel10.setText("%");
jLabel10.setBounds(224, 112, 21, 21);
}
}
{
jPanelExtruders = new JPanel();
jTabbedPane1.addTab(
"Extruders",
null,
jPanelExtruders,
null);
jPanelExtruders.setLayout(null);
{
jLabel11 = new JLabel();
jPanelExtruders.add(jLabel11);
jLabel11.setText("Extruder");
jLabel11.setBounds(7, 7, 56, 21);
jLabel11.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
jLabel14 = new JLabel();
jPanelExtruders.add(jLabel14);
jLabel14.setText("Rz");
jLabel14.setBounds(224, 7, 63, 21);
}
{
jLabel12 = new JLabel();
jPanelExtruders.add(jLabel12);
jLabel12.setText("1");
jLabel12.setBounds(35, 28, 21, 28);
jLabel12.setHorizontalAlignment(SwingConstants.RIGHT);
}
{
jLabel15 = new JLabel();
jPanelExtruders.add(jLabel15);
jLabel15.setText("Beta");
jLabel15.setBounds(154, 7, 63, 21);
}
{
jLabel13 = new JLabel();
jPanelExtruders.add(jLabel13);
jLabel13.setText("Address");
jLabel13.setBounds(77, 7, 63, 21);
}
{
extruderBeta1 = new JTextField();
jPanelExtruders.add(extruderBeta1);
extruderBeta1.setBounds(140, 28, 63, 28);
}
{
extruderAddress1 = new JTextField();
jPanelExtruders.add(extruderAddress1);
extruderAddress1.setBounds(70, 28, 63, 28);
}
{
extruderRz1 = new JTextField();
jPanelExtruders.add(extruderRz1);
extruderRz1.setBounds(210, 28, 63, 28);
}
}
}
{
getContentPane().setLayout(null);
this.setTitle("RepRap Preferences");
}
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
private void jButtonOKMouseClicked(MouseEvent evt) {
// Update all preferences
savePreferences();
dispose();
}
private void jButtonCancelMouseClicked(MouseEvent evt) {
// Close without saving
dispose();
}
}
|