Subversion Repositories svn.mios

Rev

Rev 628 | Rev 660 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 628 Rev 657
Line 51... Line 51...
51
        MouseMotionListener, KeyListener, FocusListener {
51
        MouseMotionListener, KeyListener, FocusListener {
52
52
53
    public final static int LINEAR = 0;
53
    public final static int LINEAR = 0;
54
54
55
    public final static int ROUND = 1;
55
    public final static int ROUND = 1;
56
-
 
57
    public static int mouseDragType = LINEAR;
-
 
58
-
 
59
    private Icon icon;
-
 
60
56
61
    private final static float START = 225;
57
    private final static float START = 225;
62
58
63
    private final static float LENGTH = 270;
59
    private final static float LENGTH = 270;
64
60
Line 71... Line 67...
71
67
72
    private final static float MULTIP = 180 / (float) Math.PI;
68
    private final static float MULTIP = 180 / (float) Math.PI;
73
69
74
    private final static Color FOCUS_COLOR = UIManager.getColor("Slider.focus");
70
    private final static Color FOCUS_COLOR = UIManager.getColor("Slider.focus");
75
71
-
 
72
    private int mouseDragType = LINEAR;
-
 
73
-
 
74
    private Icon icon;
-
 
75
76
    private float DRAG_SPEED;
76
    private float dragSpeed;
77
77
78
    private float CLICK_SPEED;
78
    private int clickSpeed;
79
79
80
    private static Dimension PREF_SIZE;
80
    private static Dimension preferredSize;
81
81
82
    private int middle;
82
    private int middle;
83
83
84
    private ChangeEvent changeEvent = null;
84
    private ChangeEvent changeEvent = null;
85
85
Line 87... Line 87...
87
87
88
    private Arc2D hitArc = new Arc2D.Float(Arc2D.PIE);
88
    private Arc2D hitArc = new Arc2D.Float(Arc2D.PIE);
89
89
90
    private float ang = START_ANG;
90
    private float ang = START_ANG;
91
91
92
    private float minValue = 0f;
92
    private int minValue = 0;
93
93
94
    private float maxValue = 1.0f;
94
    private int maxValue = 100;
95
95
96
    private float value;
96
    private int value;
97
97
98
    private int dragpos = -1;
98
    private int dragpos = -1;
99
99
100
    private float startVal;
100
    private int startVal;
101
101
102
    private double lastAng;
102
    private double lastAng;
103
103
104
    private Color tickColor;
104
    private Color tickColor;
105
105
106
    public Knob(ImageIcon icon) {
106
    public Knob(ImageIcon icon) {
107
107
108
        this.icon = icon;
108
        this.icon = icon;
109
109
110
        PREF_SIZE = new Dimension(icon.getIconHeight() + 8, icon
110
        preferredSize = new Dimension(icon.getIconHeight() + 8, icon
111
                .getIconHeight() + 8);
111
                .getIconHeight() + 8);
112
        DRAG_SPEED = 0.0075F;// 0.01F;
112
        dragSpeed = 0.0075F;// 0.01F;
113
        CLICK_SPEED = 0.01F;
113
        clickSpeed = 1;
114
114
115
        hitArc.setAngleStart(235); // Degrees ??? Radians???
115
        hitArc.setAngleStart(235); // Degrees ??? Radians???
116
        hitArc.setFrame(4, 4, icon.getIconHeight(), icon.getIconHeight());
116
        hitArc.setFrame(4, 4, icon.getIconHeight(), icon.getIconHeight());
117
        middle = getHeight() / 2;
117
        middle = getHeight() / 2;
118
118
Line 125... Line 125...
125
    public boolean isFocusable() {
125
    public boolean isFocusable() {
126
        return true;
126
        return true;
127
    }
127
    }
128
128
129
    private void incValue() {
129
    private void incValue() {
-
 
130
130
        setValue(value + CLICK_SPEED);
131
        setValue(value + clickSpeed);
131
    }
132
    }
132
133
133
    private void decValue() {
134
    private void decValue() {
134
        setValue(value - CLICK_SPEED);
135
        setValue(value - clickSpeed);
135
    }
136
    }
136
137
137
    public float getMaxValue() {
138
    public float getMaxValue() {
138
        return maxValue;
139
        return maxValue;
139
    }
140
    }
140
141
141
    public void setMaxValue(float maxValue) {
142
    public void setMaxValue(int maxValue) {
142
        this.maxValue = maxValue;
143
        this.maxValue = maxValue;
143
    }
144
    }
144
145
145
    public float getMinValue() {
146
    public int getMinValue() {
146
        return minValue;
147
        return minValue;
147
    }
148
    }
148
149
149
    public void setMinValue(float minValue) {
150
    public void setMinValue(int minValue) {
150
        this.minValue = minValue;
151
        this.minValue = minValue;
151
    }
152
    }
152
153
153
    public float getValue() {
154
    public int getValue() {
154
        return value;
155
        return value;
155
    }
156
    }
156
157
157
    public void setValue(float val) {
158
    public void setValue(int value) {
-
 
159
158
        if (val < 0)
160
        value = Math.min(value, maxValue);
159
            val = 0;
-
 
160
        if (val > 1)
161
        value = Math.max(value, minValue);
161
            val = 1;
162
162
        float oldVal = this.value;
163
        if (value != this.value) {
-
 
164
163
        this.value = val;
165
            this.value = value;
-
 
166
164
        ang = START_ANG - LENGTH_ANG * val;
167
            ang = START_ANG - LENGTH_ANG * this.value;
165
        repaint();
168
            repaint();
166
        if (oldVal != this.value) {
-
 
-
 
169
167
            fireChangeEvent();
170
            fireChangeEvent();
168
        }
171
        }
169
    }
172
    }
170
173
171
    public void addChangeListener(ChangeListener cl) {
174
    public void addChangeListener(ChangeListener cl) {
Line 175... Line 178...
175
    public void removeChangeListener(ChangeListener cl) {
178
    public void removeChangeListener(ChangeListener cl) {
176
        listenerList.remove(ChangeListener.class, cl);
179
        listenerList.remove(ChangeListener.class, cl);
177
    }
180
    }
178
181
179
    public Dimension getMinimumSize() {
182
    public Dimension getMinimumSize() {
180
        return PREF_SIZE;
183
        return preferredSize;
181
    }
184
    }
182
185
183
    public Dimension getPreferredSize() {
186
    public Dimension getPreferredSize() {
184
        return PREF_SIZE;
187
        return preferredSize;
185
    }
188
    }
186
189
187
    public void setTickColor(Color tickColor) {
190
    public void setTickColor(Color tickColor) {
188
        this.tickColor = tickColor;
191
        this.tickColor = tickColor;
189
        repaint();
192
        repaint();
Line 256... Line 259...
256
259
257
        if (icon != null) {
260
        if (icon != null) {
258
261
259
            g2d.clipRect(offsetX, offsetY, icon.getIconHeight(), icon
262
            g2d.clipRect(offsetX, offsetY, icon.getIconHeight(), icon
260
                    .getIconHeight());
263
                    .getIconHeight());
-
 
264
            offsetX -= icon.getIconHeight()
261
            offsetX -= icon.getIconHeight() * ((int) (value * noImages));
265
                    * ((int) ((float) value / (float) maxValue * noImages));
262
            icon.paintIcon(this, g2d, offsetX, offsetY);
266
            icon.paintIcon(this, g2d, offsetX, offsetY);
263
            g2d.dispose();
267
            g2d.dispose();
264
        }
268
        }
265
    }
269
    }
266
270
Line 299... Line 303...
299
    public void mouseMoved(MouseEvent me) {
303
    public void mouseMoved(MouseEvent me) {
300
    }
304
    }
301
305
302
    public void mouseDragged(MouseEvent me) {
306
    public void mouseDragged(MouseEvent me) {
303
        if (mouseDragType == LINEAR) {
307
        if (mouseDragType == LINEAR) {
-
 
308
            float f = (dragSpeed * maxValue)
304
            float f = DRAG_SPEED * (float) ((me.getX() - me.getY()) - dragpos);
309
                    * (float) ((me.getX() - me.getY()) - dragpos);
305
            setValue(startVal + f);
310
            setValue((int) (startVal + f));
306
        }
311
        }
307
312
308
        else if (mouseDragType == ROUND) {
313
        else if (mouseDragType == ROUND) {
309
            int xpos = middle - me.getX();
314
            int xpos = middle - me.getX();
310
            int ypos = middle - me.getY();
315
            int ypos = middle - me.getY();
311
            double ang = Math.atan2(xpos, ypos);
316
            double ang = Math.atan2(xpos, ypos);
312
            double diff = lastAng - ang;
317
            double diff = lastAng - ang;
313
318
314
            setValue((float) (value + (diff / LENGTH_ANG)));
319
            setValue((int) ((((value) / 100f) + (diff / LENGTH_ANG)) * 100f));
315
320
316
            lastAng = ang;
321
            lastAng = ang;
317
        }
322
        }
-
 
323
318
    }
324
    }
319
325
320
    public void keyPressed(KeyEvent e) {
326
    public void keyPressed(KeyEvent e) {
321
        int k = e.getKeyCode();
327
        int k = e.getKeyCode();
322
        if (k == KeyEvent.VK_RIGHT)
328
        if (k == KeyEvent.VK_RIGHT)