Normand Briere
2018-05-22 42107f9a01652cb2f47228d20c1148a2a22f6a63
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
package mocap.gui;
 
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
 
import mocap.figure.Bone;
 
/**
 *
 * @author Michael Kipp
 */
public class BoneInfoPanel extends JPanel implements ChangeListener {
 
    private JLabel _bone,  _dof,  _x,  _y,  _z;
    private JSlider _xs,  _ys,  _zs;
    private DecimalFormat _fm = new DecimalFormat("##.##");
    private Bone _currentBone;
 
    public BoneInfoPanel() {
        setBorder(BorderFactory.createTitledBorder("Joint"));
        _bone = new JLabel("name: ---");
        _dof = new JLabel("dof: ---");
        JPanel px = new JPanel();
        JPanel py = new JPanel();
        JPanel pz = new JPanel();
        _x = new JLabel("x: ---");
        _y = new JLabel("y: ---");
        _z = new JLabel("z: ---");
        _xs = createSlider();
        _ys = createSlider();
        _zs = createSlider();
        JButton apply = new JButton("apply");
        px.add(_x);
        px.add(_xs);
        py.add(_y);
        py.add(_ys);
        pz.add(_z);
        pz.add(_zs);
        setLayout(new GridLayout(0, 1));
        add(_bone);
        add(_dof);
        add(px);
        add(py);
        add(pz);
        add(apply);
        apply.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                setBoneRotation();
            }
        });
    }
 
    private JSlider createSlider() {
        JSlider s = new JSlider(-60, 60);
        s.addChangeListener(this);
        s.setPaintLabels(true);
        s.setMajorTickSpacing(60);
        return s;
    }
 
    private void setBoneRotation() {
        if (_currentBone != null) {
            _currentBone.setRot((float) Math.toRadians(_xs.getValue()),
                    (float) Math.toRadians(_ys.getValue()),
                    (float) Math.toRadians(_zs.getValue()));
        }
    }
 
    public void setBone(Bone b) {
        _currentBone = b;
        _bone.setText("name: " + b.getName());
        _dof.setText(b.getDOFString());
//        setRot(b.getCurrentRotation());
    }
 
    private void setRot(float[] r) {
        if (r.length > 2) {
            double x = Math.toDegrees(r[0]);
            double y = Math.toDegrees(r[1]);
            double z = Math.toDegrees(r[2]);
            _x.setText("x: " + _fm.format(x));
            _y.setText("y: " + _fm.format(y));
            _z.setText("z: " + _fm.format(z));
            _xs.setValue((int) x);
            _ys.setValue((int) y);
            _zs.setValue((int) z);
        }
    }
 
    public void stateChanged(ChangeEvent e) {
        if (e.getSource().equals(_xs)) {
            _x.setText("x: " + _xs.getValue());
        }
        if (e.getSource().equals(_ys)) {
            _y.setText("y: " + _ys.getValue());
        }
        if (e.getSource().equals(_zs)) {
            _z.setText("z: " + _zs.getValue());
        }
    }
}