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 | |
package com.jeantessier.dependencyfinder.gui; |
34 | |
|
35 | |
import java.awt.event.*; |
36 | |
|
37 | |
import javax.swing.*; |
38 | |
|
39 | |
import org.apache.log4j.*; |
40 | |
|
41 | |
import com.jeantessier.metrics.*; |
42 | |
|
43 | |
class TableHeaderListener implements MouseListener, MouseMotionListener { |
44 | |
private JTable table; |
45 | |
private OOMetricsTableModel model; |
46 | |
|
47 | 0 | public TableHeaderListener(JTable table, OOMetricsTableModel model) { |
48 | 0 | this.table = table; |
49 | 0 | this.model = model; |
50 | 0 | } |
51 | |
|
52 | |
public void mouseClicked(MouseEvent event) { |
53 | 0 | int viewColumn = table.getColumnModel().getColumnIndexAtX(event.getX()); |
54 | 0 | int column = table.convertColumnIndexToModel(viewColumn); |
55 | 0 | String columnName = model.getRawColumnName(column); |
56 | 0 | int columnDispose = model.getRawColumnDispose(column); |
57 | |
|
58 | 0 | Logger.getLogger(getClass()).debug("mouseClicked"); |
59 | 0 | Logger.getLogger(getClass()).debug("event.getX() = " + event.getX()); |
60 | 0 | Logger.getLogger(getClass()).debug("view column = " + viewColumn); |
61 | 0 | Logger.getLogger(getClass()).debug("column = " + column); |
62 | 0 | Logger.getLogger(getClass()).debug("raw column name = " + columnName); |
63 | 0 | Logger.getLogger(getClass()).debug("raw column dispose = " + columnDispose); |
64 | |
|
65 | 0 | model.sortOn(columnName, columnDispose); |
66 | 0 | } |
67 | |
|
68 | |
public void mouseEntered(MouseEvent event) { |
69 | 0 | Logger.getLogger(getClass()).debug("mouseEntered"); |
70 | 0 | } |
71 | |
|
72 | |
public void mouseExited(MouseEvent event) { |
73 | 0 | Logger.getLogger(getClass()).debug("mouseExited"); |
74 | 0 | } |
75 | |
|
76 | |
public void mousePressed(MouseEvent event) { |
77 | 0 | Logger.getLogger(getClass()).debug("mousePressed"); |
78 | 0 | } |
79 | |
|
80 | |
public void mouseReleased(MouseEvent event) { |
81 | 0 | Logger.getLogger(getClass()).debug("mouseReleased"); |
82 | 0 | } |
83 | |
|
84 | |
public void mouseDragged(MouseEvent event) { |
85 | 0 | Logger.getLogger(getClass()).debug("mouseDragged"); |
86 | 0 | } |
87 | |
|
88 | |
public void mouseMoved(MouseEvent event) { |
89 | 0 | if (event.getComponent() instanceof JComponent) { |
90 | 0 | JComponent component = (JComponent) event.getComponent(); |
91 | |
|
92 | 0 | int viewColumn = table.getColumnModel().getColumnIndexAtX(event.getX()); |
93 | 0 | int column = table.convertColumnIndexToModel(viewColumn); |
94 | 0 | MeasurementDescriptor descriptor = model.getColumnDescriptor(column); |
95 | 0 | int columnDispose = model.getRawColumnDispose(column); |
96 | |
|
97 | 0 | String text = null; |
98 | |
|
99 | 0 | if (descriptor != null) { |
100 | 0 | StringBuffer tooltip = new StringBuffer(); |
101 | 0 | tooltip.append("<html><body><p>"); |
102 | 0 | tooltip.append(descriptor.getLongName()); |
103 | |
|
104 | 0 | if (descriptor.getClassFor().equals(StatisticalMeasurement.class)) { |
105 | 0 | switch (columnDispose) { |
106 | |
case StatisticalMeasurement.DISPOSE_MINIMUM: |
107 | |
case StatisticalMeasurement.DISPOSE_MEDIAN: |
108 | |
case StatisticalMeasurement.DISPOSE_AVERAGE: |
109 | |
case StatisticalMeasurement.DISPOSE_STANDARD_DEVIATION: |
110 | |
case StatisticalMeasurement.DISPOSE_MAXIMUM: |
111 | |
case StatisticalMeasurement.DISPOSE_SUM: |
112 | 0 | tooltip.append(", ").append(StatisticalMeasurement.getDisposeLabel(columnDispose)); |
113 | 0 | break; |
114 | |
case StatisticalMeasurement.DISPOSE_IGNORE: |
115 | |
case StatisticalMeasurement.DISPOSE_NB_DATA_POINTS: |
116 | |
default: |
117 | |
|
118 | |
break; |
119 | |
} |
120 | |
} |
121 | |
|
122 | 0 | tooltip.append("<br>valid range: ").append(descriptor.getRangeAsString()); |
123 | |
|
124 | 0 | tooltip.append("</p></body></html>"); |
125 | |
|
126 | 0 | text = tooltip.toString(); |
127 | |
} |
128 | |
|
129 | 0 | component.setToolTipText(text); |
130 | |
} |
131 | 0 | } |
132 | |
} |