Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / colorslideredition / ColorSliderEdition.java @ 40561

History | View | Annotate | Download (19.1 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.colorslideredition;
25

    
26
import java.awt.Color;
27
import java.awt.Cursor;
28
import java.awt.Dimension;
29
import java.awt.Graphics;
30
import java.awt.Image;
31
import java.awt.Polygon;
32
import java.awt.Shape;
33
import java.awt.event.MouseEvent;
34
import java.awt.event.MouseListener;
35
import java.awt.event.MouseMotionListener;
36
import java.util.ArrayList;
37
import java.util.Iterator;
38

    
39
import javax.swing.JComponent;
40
/**
41
 * <code>DoubleSlider</code> representa un componente que tiene dos
42
 * deslizadores. Se puede definir un m?ximo y un m?nimo.
43
 *
44
 * @version 04/05/2007
45
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
46
 */
47
public class ColorSliderEdition extends JComponent implements MouseListener, MouseMotionListener {
48
        private static final long serialVersionUID = 663355422780987493L;
49

    
50
        private ArrayList<ColorSliderListener> actionCommandListeners   = new ArrayList<ColorSliderListener>();
51
        private ArrayList<ColorSliderListener> actionSelectionListeners = new ArrayList<ColorSliderListener>();
52
        private ArrayList<ItemColorSlider>     items                    = new ArrayList<ItemColorSlider>();
53

    
54
        private final int LEFT_PAD       = 3;
55
        private final int RIGHT_PAD      = 3;
56

    
57
        private Image     bufferImage    = null;
58
        private int       width          = 0;
59
        private int       height         = 0;
60
        private Graphics  bufferGraphics = null;
61
        private boolean   interpolated   = true;
62

    
63
        /**
64
         * Crea un DoubleSlider con las opciones por defecto.
65
         */
66
        public ColorSliderEdition() {
67
                this.setPreferredSize(new Dimension(100, 46));
68
                addMouseListener(this);
69
                addMouseMotionListener(this);
70
        }
71

    
72
        /*
73
         * (non-Javadoc)
74
         * @see javax.swing.JComponent#addNotify()
75
         */
76
        public void addNotify() {
77
                super.addNotify();
78

    
79
                refreshImage();
80
        }
81

    
82
        public void addItem(ItemColorSlider value) {
83
                addItem(value, true);
84
        }
85

    
86
        public void addItem(ItemColorSlider value, boolean repaint) {
87
                items.add(value);
88
                if (repaint)
89
                        refreshImage();
90
        }
91

    
92
        /**
93
         * Devuelve un color de interpolacion entre dos colores
94
         * @param value
95
         * @param pos
96
         * @return
97
         */
98
        private Color interpolatedColor(ArrayList newItems, double value, int pos) {
99
                if (newItems.size() <= 0)
100
                        return Color.black;
101

    
102
                if ((pos + 1) == newItems.size())
103
                        return ((ItemColorSlider) newItems.get(pos)).getColor();
104

    
105
                if (value <= ((ItemColorSlider) newItems.get(0)).getValue())
106
                        return ((ItemColorSlider) newItems.get(0)).getColor();
107

    
108
                ItemColorSlider item1 = (ItemColorSlider) newItems.get(pos);
109
                ItemColorSlider item2 = (ItemColorSlider) newItems.get(pos + 1);
110

    
111
                double percValue = ((value - item1.getValue()) * 100) / (item2.getValue() - item1.getValue());
112

    
113
                Color halfColor = new Color(
114
                                (item2.getColor().getRed() + item1.getColor().getRed()) >> 1,
115
                                (item2.getColor().getGreen() + item1.getColor().getGreen()) >> 1,
116
                                (item2.getColor().getBlue() + item1.getColor().getBlue()) >> 1,
117
                                (item2.getColor().getAlpha() + item1.getColor().getAlpha()) >> 1);
118

    
119
                Color color1, color2;
120
                double perc1, perc2;
121

    
122
                if (percValue > item2.getInterpolated()) {
123
                        color1 = halfColor;
124
                        color2 = item2.getColor();
125
                        perc1 = item2.getInterpolated();
126
                        perc2 = 100;
127
                } else {
128
                        color1 = item1.getColor();
129
                        color2 = halfColor;
130
                        perc1 = 0;
131
                        perc2 = item2.getInterpolated();
132
                }
133

    
134
                double percNew = (percValue - perc1) / (perc2 - perc1);
135

    
136
                Color newColor = new Color(
137
                                (int) (color1.getRed() + ((color2.getRed() - color1.getRed()) * percNew)) & 0xff,
138
                                (int) (color1.getGreen() + ((color2.getGreen() - color1.getGreen()) * percNew)) & 0xff,
139
                                (int) (color1.getBlue() + ((color2.getBlue() - color1.getBlue()) * percNew)) & 0xff,
140
                                (int) (color1.getAlpha() + ((color2.getAlpha() - color1.getAlpha()) * percNew)) & 0xff);
141

    
142

    
143
                return newColor;
144
        }
145

    
146
        /**
147
         * Crea un graphics con las dimensiones del componente si no estaba creado y
148
         * lo devuelve para poder usarlo para dibujar en ?l.
149
         * @return Graphics
150
         */
151
        private Graphics getBufferGraphics() {
152
                int width2 = getBounds().width;
153
                int height2 = getBounds().height;
154
                if (width2 <= 0)
155
                        width2 = 1;
156
                if (height2 <= 0)
157
                        height2 = 1;
158

    
159
                if ((width != width2) || (height != height2)) {
160
                        bufferImage = createImage(width2, height2);
161
                        if (bufferImage == null)
162
                                return null;
163
                        bufferGraphics = bufferImage.getGraphics();
164
                }
165

    
166
                width = width2;
167
                height = height2;
168

    
169
                return bufferGraphics;
170
        }
171

    
172
        private void sortItems() {
173
                for (int i = 0; i < items.size(); i++) {
174
                        for (int j = i + 1; j < items.size(); j++) {
175
                                if (items.get(j).getValue() < items.get(i).getValue()) {
176
                                        ItemColorSlider aux = items.get(i);
177
                                        items.set(i, items.get(j));
178
                                        items.set(j, aux);
179
                                }
180
                        }
181
                }
182
        }
183

    
184
        private int getPosForValue(double value, ArrayList newArray) {
185
                int pos = 0;
186
                for (int j = 1; j <= newArray.size(); j++) {
187
                        if (j < newArray.size()) {
188
                                if (value < ((ItemColorSlider) newArray.get(j)).getValue()) {
189
                                        pos = j - 1;
190
                                        break;
191
                                }
192
                        } else {
193
                                pos = j - 1;
194
                                break;
195
                        }
196
                }
197
                return pos;
198
        }
199

    
200
        /**
201
         * Convierte a gris y aclara el color si esta inactivo el componente, en caso
202
         * contrario devuelve el color tal cual
203
         */
204
        private Color convertColor(Color value) {
205
                if (isEnabled())
206
                        return value;
207

    
208
                int aux = (value.getRed() + value.getGreen() + value.getBlue()) / 3;
209

    
210
                aux = (int) ((aux * 91.0 / 255.0) + 164.0);
211

    
212
                return new Color(aux, aux, aux, value.getAlpha());
213
        }
214

    
215
        /**
216
         * Redibujar el componente en el graphics temporal
217
         */
218
        private void redrawBuffer() {
219
                if (getBufferGraphics() == null)
220
                        return;
221

    
222
                sortItems();
223

    
224
                getBufferGraphics().setColor(this.getBackground());
225

    
226
                getBufferGraphics().fillRect(0, 0, width, height);
227

    
228
                getBufferGraphics().setColor(Color.black);
229
                getBufferGraphics().drawRect(LEFT_PAD, 0, width - 1 - LEFT_PAD - RIGHT_PAD, height - 18);
230

    
231
                Shape oldClip = getBufferGraphics().getClip();
232
                getBufferGraphics().setClip(LEFT_PAD + 2, 2, width - 4 - LEFT_PAD - RIGHT_PAD, height - 21);
233
                for (int i = 0; (i * 4 + 2) <= (width - 3 - LEFT_PAD - RIGHT_PAD); i++) {
234
                        for (int j = 0; (j * 4 + 2) <= (height - 20); j++) {
235
                                if ((i + j) % 2 == 0)
236
                                        getBufferGraphics().setColor(Color.white);
237
                                else
238
                                        getBufferGraphics().setColor(new Color(204, 204, 204));
239
                                getBufferGraphics().fillRect(i * 4 + 2 + LEFT_PAD, j * 4 + 2, 4, 4);
240
                        }
241
                }
242
                Color newColor = Color.black;
243

    
244
                ArrayList<ItemColorSlider> newArray = getItemsShowed();
245

    
246
                for (int i = LEFT_PAD + 2; i <= width - 2 - RIGHT_PAD; i++) {
247
                        int pos = getPosForValue(pixelToValue(i), newArray);
248

    
249
                        if (isInterpolated()) {
250
                                newColor = interpolatedColor(newArray, pixelToValue(i), pos);
251
                        } else {
252
                                if ((pos + 1) < newArray.size()) {
253
                                        double min = newArray.get(pos).getValue();
254
                                        double max = newArray.get(pos + 1).getValue();
255
                                        if ((min + ((max - min) * newArray.get(pos + 1).getInterpolated() / 100)) < pixelToValue(i))
256
                                                pos++;
257
                                }
258
                                if (pos < newArray.size())
259
                                        newColor = newArray.get(pos).getColor();
260
                        }
261
                        if (newColor != null) {
262
                                getBufferGraphics().setColor(convertColor(newColor));
263
                                getBufferGraphics().drawLine(i, 2, i, height - 18);
264
                        }
265
                }
266

    
267
                getBufferGraphics().setClip(oldClip);
268

    
269
                boolean paintNext = false;
270
                for (int i = 0; i < items.size(); i++) {
271
                        ItemColorSlider aux = items.get(i);
272
                        if (!aux.isVisible())
273
                                continue;
274
                        // Dibujar los deslizadores de la interpolacion
275
                        if (aux.getSelected() != -1)
276
                                paintNext = true;
277
                        if (paintNext && isEnabled()) {
278
                                if (i != 0) {
279
                                        double value = items.get(i - 1).getValue() + ((items.get(i).getValue() - items.get(i - 1).getValue()) * items.get(i).getInterpolated() / 100);
280

    
281
                                        drawSliderInterpolation(valueToPixel(value), height - 17, aux.getColor(), (aux.getSelected() == 2));
282
                                }
283
                                paintNext = false;
284
                        }
285
                        if (aux.getSelected() == 1)
286
                                paintNext = true;
287
                }
288

    
289
                for (int i = items.size() - 1; i >= 0; i--) {
290
                        ItemColorSlider aux = items.get(i);
291
                        if (!aux.isVisible())
292
                                continue;
293
                        drawSliderColor(valueToPixel(aux.getValue()), height - 17, convertColor(aux.getColor()), (aux.getSelected() == 1) && (isEnabled()));
294
                }
295
        }
296

    
297
        /**
298
         * Convierte un porcentaje al valor pixel en X
299
         * @param value
300
         * @return
301
         */
302
        private int valueToPixel(double value) {
303
                if (value < 0)
304
                        value = 0;
305
                if (value > 100)
306
                        value = 100;
307
                return (int) (((width - 5 - LEFT_PAD - RIGHT_PAD) * value) / 100) + 2 + LEFT_PAD;
308
        }
309

    
310
        /**
311
         * Convierte un valor en X en porcentaje
312
         * @param value
313
         * @return
314
         */
315
        private double pixelToValue(int value) {
316
                double aux = value - LEFT_PAD - 1;
317
                return (aux * 100.0f) / (width - LEFT_PAD - RIGHT_PAD - 4.0f);
318
        }
319

    
320
        /**
321
         * Dibujar un triangulo, un triangulo es un deslizador del componente. Puedes
322
         * indicarle que color tendra y en que posici?n estar?.
323
         * @param x
324
         * @param color
325
         */
326
        private void drawSliderColor(int x, int y, Color color, boolean isSelected) {
327
                if (color == null)
328
                        return;
329
                Polygon p = new Polygon();
330
                p.addPoint(x, y);
331
                p.addPoint(x - 5, y + 6);
332
                p.addPoint(x - 5, y + 16);
333
                p.addPoint(x + 5, y + 16);
334
                p.addPoint(x + 5, y + 6);
335
                if (!isSelected) {
336
                        getBufferGraphics().setColor(this.getBackground());
337
                        getBufferGraphics().fillPolygon(p);
338
                        getBufferGraphics().setColor(new Color(172, 168, 153));
339
                        getBufferGraphics().drawLine(x + 1, y + 2, x + 4, y + 6);
340
                        getBufferGraphics().drawLine(x - 4, y + 6, x + 4, y + 6);
341
                } else {
342
                        getBufferGraphics().setColor(Color.black);
343
                        getBufferGraphics().fillPolygon(p);
344
                }
345

    
346
                getBufferGraphics().setColor(Color.black);
347
                getBufferGraphics().drawPolygon(p);
348

    
349
                getBufferGraphics().setColor(new Color(172, 168, 153));
350
                getBufferGraphics().drawLine(x - 3, y + 15, x + 4, y + 15);
351
                getBufferGraphics().drawLine(x + 4, y + 8, x + 4, y + 15);
352

    
353
                getBufferGraphics().setColor(Color.white);
354
                getBufferGraphics().drawLine(x - 4, y + 7, x - 4, y + 15);
355
                getBufferGraphics().drawLine(x - 4, y + 7, x + 4, y + 7);
356

    
357
                getBufferGraphics().setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
358
                getBufferGraphics().fillRect(x - 3, y + 8, 7, 7);
359
        }
360

    
361
        /**
362
         * Dibujar un triangulo, un triangulo es un deslizador del componente. Puedes
363
         * indicarle que color tendra y en que posici?n estar?.
364
         * @param x
365
         * @param color
366
         */
367
        private void drawSliderInterpolation(int x, int y, Color color, boolean isSelected) {
368
                Polygon p = new Polygon();
369
                p.addPoint(x, y);
370
                p.addPoint(x - 3, y + 3);
371
                p.addPoint(x, y + 6);
372
                p.addPoint(x + 3, y + 3);
373
                if (isSelected)
374
                        getBufferGraphics().setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
375
                else
376
                        getBufferGraphics().setColor(this.getBackground());
377

    
378
                getBufferGraphics().fillPolygon(p);
379

    
380
                getBufferGraphics().setColor(Color.black);
381
                getBufferGraphics().drawPolygon(p);
382
        }
383

    
384
        /**
385
         * Redibujar el componente en el graphics temporal y representarlo en el
386
         * componente
387
         */
388
        private void refreshImage() {
389
                redrawBuffer();
390
                if (bufferImage != null)
391
                        getGraphics().drawImage(bufferImage, 0, 0, this);
392
                super.paint(getGraphics());
393
        }
394

    
395
        /*
396
         * (non-Javadoc)
397
         * @see javax.swing.JComponent#paint(java.awt.Graphics)
398
         */
399
        public void paint(Graphics g) {
400
                redrawBuffer();
401
                g.drawImage(bufferImage, 0, 0, this);
402
                super.paint(g);
403
        }
404

    
405
        /*
406
         * (non-Javadoc)
407
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
408
         */
409
        public void mousePressed(MouseEvent e) {
410
                if (!isEnabled())
411
                        return;
412
                int onmask = MouseEvent.BUTTON1_DOWN_MASK;
413
                if ((e.getModifiersEx() & onmask) != onmask)
414
                        return;
415
                onmask = MouseEvent.ALT_DOWN_MASK;
416
                boolean newItem = false;
417
                if ((e.getModifiersEx() & onmask) == onmask)
418
                        newItem = true;
419

    
420
                if ((e.getY() > height) || (e.getY() < (height - 18))) {
421
                        clearSelected();
422
                        refreshImage();
423
                        return;
424
                }
425

    
426
                int type = 1;
427
                ItemColorSlider itemSelected = getItem(e.getX(), e.getY());
428
                if ((itemSelected == null) || (newItem)) {
429
                        itemSelected = getItemInterpolated(e.getX(), e.getY());
430
                        if ((itemSelected == null) || (newItem)) {
431
                                int pos = getPosForValue(pixelToValue(e.getX()), items);
432

    
433
                                Color newColor = interpolatedColor(items, pixelToValue(e.getX()), pos);
434

    
435
                                itemSelected = new ItemColorSlider(pixelToValue(e.getX()), newColor);
436
                                items.add(itemSelected);
437
                        } else {
438
                                type = 2;
439
                        }
440
                }
441
                setItemSelected(itemSelected, type);
442

    
443
                callSelectionChangedListeners();
444
                callValueChangedListeners();
445

    
446
                refreshImage();
447
        }
448

    
449
        private void clearSelected() {
450
                for (int i = items.size() - 1; i >= 0; i--)
451
                        items.get(i).setSelected(-1);
452
        }
453

    
454
        private void setItemSelected(ItemColorSlider aux, int type) {
455
                clearSelected();
456
                aux.setSelected(type);
457
        }
458

    
459
        /*
460
         * (non-Javadoc)
461
         * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
462
         */
463
        public void mouseReleased(MouseEvent e) {
464
                if (!isEnabled())
465
                        return;
466
                try {
467
                        for (int i = items.size() - 1; i >= 0; i--) {
468
                                if (items.size() <= 2)
469
                                        return;
470
                                if (items.get(i).isVisible() == false)
471
                                        items.remove(i);
472
                        }
473
                } finally {
474
                        callValueChangedListeners();
475
                }
476
        }
477

    
478
        public ItemColorSlider getSelectedItem() {
479
                for (int i = 0; i < items.size(); i++) {
480
                        if (items.get(i).getSelected() != -1)
481
                                return items.get(i);
482
                }
483
                return null;
484
        }
485

    
486
        /*
487
         * (non-Javadoc)
488
         * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
489
         */
490
        public void mouseDragged(MouseEvent e) {
491
                if (!isEnabled())
492
                        return;
493
                ItemColorSlider aux = getSelectedItem();
494
                if (aux != null) {
495
                        if (aux.getSelected() == 1) {
496
                                aux.setValue(pixelToValue(e.getX()));
497
                                refreshImage();
498
                                setMouseCursor(e.getX(), e.getY());
499
                                aux.setVisible((e.getY() <= height) && (e.getY() >= 0) || items.size() <= 2);
500
                                callValueDraggedListeners();
501
                                return;
502
                        }
503
                        if (aux.getSelected() == 2) {
504
                                int pos = -1;
505
                                for (int i = 0; i < items.size(); i++) {
506
                                        if (items.get(i) == aux)
507
                                                pos = i;
508
                                }
509
                                if (pos > 0) {
510
                                        double min = items.get(pos - 1).getValue();
511
                                        double max = items.get(pos).getValue();
512

    
513
                                        double newValue = 100 * (pixelToValue(e.getX()) - min) / (max - min);
514

    
515
                                        aux.setInterpolated(newValue);
516
                                        refreshImage();
517
                                        setMouseCursor(e.getX(), e.getY());
518
                                        callValueDraggedListeners();
519
                                }
520
                                return;
521
                        }
522
                }
523
        }
524

    
525
        private ItemColorSlider getItem(int x, int y) {
526
                for (int i = 0; i < items.size(); i++) {
527
                        if ((x >= (valueToPixel(items.get(i).getValue()) - 5)) &&
528
                                        (x <= (valueToPixel(items.get(i).getValue()) + 5)) &&
529
                                        (y <= height) &&
530
                                        (y >= (height - 18))) {
531
                                return items.get(i);
532
                        }
533
                }
534
                return null;
535
        }
536

    
537
        private ItemColorSlider getItemInterpolated(int x, int y) {
538
                for (int i = 1; i < items.size(); i++) {
539
                        int value = valueToPixel(items.get(i - 1).getValue() + ((items.get(i).getValue() - items.get(i - 1).getValue()) * items.get(i).getInterpolated() / 100));
540

    
541
                        if ((x >= value - 3) &&
542
                                        (x <= value + 3) &&
543
                                        (y <= (height - 11)) &&
544
                                        (y >= (height - 18))) {
545
                                if (items.get(i).getSelected() != -1)
546
                                        return items.get(i);
547
                                if (items.get(i - 1).getSelected() == 1)
548
                                        return items.get(i);
549
                        }
550
                }
551
                return null;
552
        }
553

    
554
        private void setMouseCursor(int x, int y) {
555
                if (getItem(x, y) != null) {
556
                        setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
557
                        return;
558
                }
559
                if (getItemInterpolated(x, y) != null) {
560
                        setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
561
                        return;
562
                }
563
                if ((y <= height) && (y >= (height - 18))) {
564
                        setCursor(new Cursor(Cursor.HAND_CURSOR));
565
                        return;
566
                }
567
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
568
                return;
569
        }
570

    
571
        /*
572
         * (non-Javadoc)
573
         * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
574
         */
575
        public void mouseMoved(MouseEvent e) {
576
                if (!isEnabled())
577
                        return;
578
                setMouseCursor(e.getX(), e.getY());
579
        }
580

    
581
        /**
582
         * @return the interpolated
583
         */
584
        public boolean isInterpolated() {
585
                return interpolated;
586
        }
587

    
588
        /**
589
         * @param interpolated the interpolated to set
590
         */
591
        public void setInterpolated(boolean interpolated) {
592
                this.interpolated = interpolated;
593
                refreshImage();
594
        }
595

    
596
        /**
597
         * A?adir un listener a la lista de eventos
598
         * @param listener
599
         */
600
        public void addValueChangedListener(ColorSliderListener listener) {
601
                if (!actionCommandListeners.contains(listener))
602
                        actionCommandListeners.add(listener);
603
        }
604

    
605
        /**
606
         * Borrar un listener de la lista de eventos
607
         * @param listener
608
         */
609
        public void removeValueChangedListener(ColorSliderListener listener) {
610
                actionCommandListeners.remove(listener);
611
        }
612

    
613
        /**
614
         * A?adir un listener a la lista de eventos
615
         * @param listener
616
         */
617
        public void addSelectionChangedListener(ColorSliderListener listener) {
618
                if (!actionSelectionListeners.contains(listener))
619
                        actionSelectionListeners.add(listener);
620
        }
621

    
622
        /**
623
         * Borrar un listener de la lista de eventos
624
         * @param listener
625
         */
626
        public void removeSelectionChangedListener(ColorSliderListener listener) {
627
                actionSelectionListeners.remove(listener);
628
        }
629

    
630
        /**
631
         * Invocar a los eventos asociados al componente
632
         */
633
        private void callSelectionChangedListeners() {
634
                Iterator<ColorSliderListener> acIterator = actionSelectionListeners.iterator();
635
                while (acIterator.hasNext()) {
636
                        ColorSliderListener listener = acIterator.next();
637
                        listener.actionSelectionChanged(new ColorSliderEvent(this));
638
                }
639
        }
640

    
641
        /**
642
         * Invocar a los eventos asociados al componente
643
         */
644
        private void callValueChangedListeners() {
645
                Iterator<ColorSliderListener> acIterator = actionCommandListeners.iterator();
646
                while (acIterator.hasNext()) {
647
                        ColorSliderListener listener = acIterator.next();
648
                        listener.actionValueChanged(new ColorSliderEvent(this));
649
                }
650
        }
651

    
652
        /**
653
         * Invocar a los eventos asociados al componente
654
         */
655
        private void callValueDraggedListeners() {
656
                Iterator<ColorSliderListener> acIterator = actionCommandListeners.iterator();
657
                while (acIterator.hasNext()) {
658
                        ColorSliderListener listener = acIterator.next();
659
                        listener.actionValueDragged(new ColorSliderEvent(this));
660
                }
661
        }
662

    
663
        public void removeAllItems() {
664
                items.clear();
665
        }
666

    
667
        /**
668
         * @return the items
669
         */
670
        public ArrayList getItems() {
671
                return items;
672
        }
673

    
674
        /**
675
         * Devuelve los items que estan visibles en el componente
676
         * @return the items
677
         */
678
        public ArrayList getItemsShowed() {
679
                ArrayList newArray = (ArrayList) items.clone();
680
                for (int i = newArray.size() - 1; i >= 0; i--) {
681
                        if (((ItemColorSlider) newArray.get(i)).isVisible() == false)
682
                                newArray.remove(i);
683
                }
684

    
685
                return newArray;
686
        }
687

    
688
        /* (non-Javadoc)
689
         * @see javax.swing.JComponent#setEnabled(boolean)
690
         */
691
        public void setEnabled(boolean enabled) {
692
                super.setEnabled(enabled);
693
                refreshImage();
694
        }
695

    
696
        public void mouseClicked(MouseEvent e) {}
697
        public void mouseEntered(MouseEvent e) {}
698
        public void mouseExited(MouseEvent e) {}
699
}