summaryrefslogtreecommitdiff
path: root/tags/host/0.8.1/src/org/reprap/gui/steppertest/LineTest.java
blob: ac20c6d1386ea9b8822abf14f09761786e0a82b5 (plain)
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
package org.reprap.gui.steppertest;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

import org.reprap.devices.GenericExtruder;
import org.reprap.devices.GenericStepperMotor;
import org.reprap.devices.pseudo.LinePrinter;

/**
 * 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 LineTest extends javax.swing.JDialog {
	private JButton OkButton;
	private JLabel jLabel4;
	private JButton plotButton;
	private JButton moveButton;
	private JLabel jLabel3;
	private JTextField endY;
	private JTextField startY;
	private JTextField endX;
	private JTextField startX;
	private JLabel jLabel2;
	private JLabel jLabel1;
	
	private int motorSpeed, extruderSpeed;
	
	private LinePrinter line;

	public LineTest(JFrame frame, GenericStepperMotor motorX, GenericStepperMotor motorY, GenericExtruder extruder, int motorSpeed, int extruderSpeed) throws IOException {
		super(frame);
		this.motorSpeed = motorSpeed;
		this.extruderSpeed = extruderSpeed;
		
		line = new LinePrinter(motorX, motorY, extruder);
		
		initGUI();
		
		startX.setText(Integer.toString(motorX.getPosition()));
		startY.setText(Integer.toString(motorY.getPosition()));
		
		if (extruder == null || !extruder.isAvailable())
			plotButton.setEnabled(false);
	}
	
	private void initGUI() {
		try {
			{
				OkButton = new JButton();
				getContentPane().add(OkButton);
				OkButton.setText("Done");
				OkButton.setBounds(280, 119, 77, 28);
				OkButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						OkButtonActionPerformed(evt);
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("End position");
				jLabel1.setBounds(14, 70, 98, 28);
				jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Start position");
				jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
				jLabel2.setBounds(14, 35, 98, 28);
			}
			{
				startX = new JTextField();
				getContentPane().add(startX);
				startX.setText("400");
				startX.setBounds(126, 35, 63, 28);
				startX.setEditable(false);
			}
			{
				endX = new JTextField();
				getContentPane().add(endX);
				endX.setText("3200");
				endX.setBounds(126, 70, 63, 28);
				endX.setName("");
			}
			{
				startY = new JTextField();
				getContentPane().add(startY);
				startY.setText("400");
				startY.setBounds(203, 35, 63, 28);
				startY.setEditable(false);
			}
			{
				endY = new JTextField();
				getContentPane().add(endY);
				endY.setText("2400");
				endY.setName("");
				endY.setBounds(203, 70, 63, 28);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Y");
				jLabel3.setBounds(203, 14, 63, 21);
				jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("X");
				jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
				jLabel4.setBounds(126, 14, 63, 21);
			}
			{
				moveButton = new JButton();
				getContentPane().add(moveButton);
				moveButton.setText("Move");
				moveButton.setBounds(280, 35, 77, 28);
				moveButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						moveButtonActionPerformed(evt);
					}
				});
			}
			{
				plotButton = new JButton();
				getContentPane().add(plotButton);
				plotButton.setText("Plot");
				plotButton.setBounds(280, 70, 77, 28);
				plotButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						plotButtonActionPerformed(evt);
					}
				});
			}
			{
				getContentPane().setLayout(null);
				this.setModal(true);
				this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
				this.setTitle("Line Test");
			}
			this.setSize(386, 193);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void OkButtonActionPerformed(ActionEvent evt) {
		dispose();
	}
	
	private void moveButtonActionPerformed(ActionEvent evt) {
		int x1 = Integer.parseInt(endX.getText()); 
		int y1 = Integer.parseInt(endY.getText()); 
		
		try {
			line.moveTo(x1, y1, motorSpeed);
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(null, "Move exception: " + ex);
			ex.printStackTrace();
		}
		
		startX.setText(endX.getText());
		startY.setText(endY.getText());
	}
	
	private void plotButtonActionPerformed(ActionEvent evt) {
		int x1 = Integer.parseInt(startX.getText()); 
		int y1 = Integer.parseInt(startY.getText()); 
		int x2 = Integer.parseInt(endX.getText()); 
		int y2 = Integer.parseInt(endY.getText()); 
		
		try {
			line.printLine(x1, y1, x2, y2, motorSpeed, extruderSpeed, true);
		} catch (Exception ex) {
			JOptionPane.showMessageDialog(null, "Plot exception: " + ex);
			ex.printStackTrace();
		}

		startX.setText(endX.getText());
		startY.setText(endY.getText());
		
	}

}