01: package org.swingml.component;
02:
03: import java.awt.event.*;
04:
05: import javax.swing.*;
06:
07: import org.swingml.*;
08: import org.swingml.event.*;
09: import org.swingml.model.*;
10:
11: /**
12: * @author NumberSix
13: */
14: public class JIconComponent extends JLabel implements MouseListener {
15:
16: private IconModel model = null;
17:
18: public JIconComponent(IconModel model) {
19: super ();
20: setBorder(BorderFactory.createEmptyBorder());
21:
22: setModel(model);
23: addMouseListener(this );
24:
25: if (model.getIcon() == null) {
26: if (model.getTooltip() != null) {
27: setToolTipText(model.getTooltip());
28: }
29:
30: if (model.getText() != null) {
31: setText(model.getText());
32: }
33: } else {
34: Icon icon = IconFactory.getIcon(model);
35: if (icon != null) {
36: setIcon(icon);
37: }
38: }
39: }
40:
41: public IconModel getIconModel() {
42: return model;
43: }
44:
45: public void mouseClicked(MouseEvent e) {
46: final int DOUBLE_CLICK_COUNT = 2;
47: final int SINGLE_CLICK_COUNT = 1;
48: String theEventType = null;
49: switch (e.getClickCount()) {
50: case DOUBLE_CLICK_COUNT:
51: theEventType = Constants.MOUSE_DOUBLE_CLICKED;
52: break;
53: case SINGLE_CLICK_COUNT:
54: theEventType = Constants.MOUSE_SINGLE_CLICKED;
55: break;
56: default:
57: theEventType = null;
58: break;
59: }
60: if (theEventType != null && theEventType.length() > 0) {
61: EventHandler.getInstance().handleEvent(getIconModel(),
62: theEventType, this );
63: }
64: }
65:
66: public void mouseEntered(MouseEvent e) {
67: }
68:
69: public void mouseExited(MouseEvent e) {
70: }
71:
72: public void mousePressed(MouseEvent e) {
73: }
74:
75: public void mouseReleased(MouseEvent e) {
76: }
77:
78: public void setModel(IconModel model) {
79: this.model = model;
80: }
81:
82: }
|