1 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 public TableHeaderListener(JTable table, OOMetricsTableModel model) { 48 this.table = table; 49 this.model = model; 50 } 51 52 public void mouseClicked(MouseEvent event) { 53 int viewColumn = table.getColumnModel().getColumnIndexAtX(event.getX()); 54 int column = table.convertColumnIndexToModel(viewColumn); 55 String columnName = model.getRawColumnName(column); 56 int columnDispose = model.getRawColumnDispose(column); 57 58 Logger.getLogger(getClass()).debug("mouseClicked"); 59 Logger.getLogger(getClass()).debug("event.getX() = " + event.getX()); 60 Logger.getLogger(getClass()).debug("view column = " + viewColumn); 61 Logger.getLogger(getClass()).debug("column = " + column); 62 Logger.getLogger(getClass()).debug("raw column name = " + columnName); 63 Logger.getLogger(getClass()).debug("raw column dispose = " + columnDispose); 64 65 model.sortOn(columnName, columnDispose); 66 } 67 68 public void mouseEntered(MouseEvent event) { 69 Logger.getLogger(getClass()).debug("mouseEntered"); 70 } 71 72 public void mouseExited(MouseEvent event) { 73 Logger.getLogger(getClass()).debug("mouseExited"); 74 } 75 76 public void mousePressed(MouseEvent event) { 77 Logger.getLogger(getClass()).debug("mousePressed"); 78 } 79 80 public void mouseReleased(MouseEvent event) { 81 Logger.getLogger(getClass()).debug("mouseReleased"); 82 } 83 84 public void mouseDragged(MouseEvent event) { 85 Logger.getLogger(getClass()).debug("mouseDragged"); 86 } 87 88 public void mouseMoved(MouseEvent event) { 89 if (event.getComponent() instanceof JComponent) { 90 JComponent component = (JComponent) event.getComponent(); 91 92 int viewColumn = table.getColumnModel().getColumnIndexAtX(event.getX()); 93 int column = table.convertColumnIndexToModel(viewColumn); 94 MeasurementDescriptor descriptor = model.getColumnDescriptor(column); 95 int columnDispose = model.getRawColumnDispose(column); 96 97 String text = null; 98 99 if (descriptor != null) { 100 StringBuffer tooltip = new StringBuffer (); 101 tooltip.append("<html><body><p>"); 102 tooltip.append(descriptor.getLongName()); 103 104 if (descriptor.getClassFor().equals(StatisticalMeasurement.class)) { 105 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 tooltip.append(", ").append(StatisticalMeasurement.getDisposeLabel(columnDispose)); 113 break; 114 case StatisticalMeasurement.DISPOSE_IGNORE: 115 case StatisticalMeasurement.DISPOSE_NB_DATA_POINTS: 116 default: 117 break; 119 } 120 } 121 122 tooltip.append("<br>valid range: ").append(descriptor.getRangeAsString()); 123 124 tooltip.append("</p></body></html>"); 125 126 text = tooltip.toString(); 127 } 128 129 component.setToolTipText(text); 130 } 131 } 132 } 133 | Popular Tags |