blob: fc7eb1159b702d1748e57dcda2c7c3441e9fcbea (
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
|
package org.reprap.gui.steppertest;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.reprap.devices.GenericExtruder;
public class ExtruderPanel extends JPanel {
private GenericExtruder extruder;
private boolean extruding = false;
private JButton extrudeButton;
private JSlider speed;
public ExtruderPanel(GenericExtruder extruder) {
super();
this.extruder = extruder;
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
add(new JLabel("Extrusion speed: "), c);
speed = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
speed.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
onExtrudeSpeed();
}
});
c.gridx = 1;
c.gridy = 0;
add(speed, c);
extrudeButton = new JButton("Extrude");
extrudeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onExtrudeButton();
}
});
c.gridx = 2;
c.gridy = 0;
c.insets.left = 5;
add(extrudeButton, c);
if (!extruder.isAvailable()) {
extrudeButton.setEnabled(false);
speed.setEnabled(false);
}
}
protected void onExtrudeSpeed() {
if (extruding)
setExtruderSpeed();
}
private void setExtruderSpeed() {
try {
extruder.setExtrusion(extruding?speed.getValue():0);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Extruder exception: " + ex);
ex.printStackTrace();
}
}
protected void onExtrudeButton() {
if (extruding) {
extruding = false;
extrudeButton.setText("Extrude");
} else {
extrudeButton.setPreferredSize(extrudeButton.getSize());
extruding = true;
extrudeButton.setText("Stop");
}
setExtruderSpeed();
}
public int getSpeed() {
return speed.getValue();
}
}
|