| 1 22 package info.monitorenter.gui.chart.layout.views; 23 24 import info.monitorenter.gui.chart.Chart2D; 25 import info.monitorenter.gui.chart.TracePoint2D; 26 27 import java.awt.GridBagConstraints ; 28 import java.awt.GridBagLayout ; 29 import java.awt.event.MouseEvent ; 30 import java.awt.event.MouseMotionAdapter ; 31 import java.awt.event.MouseMotionListener ; 32 33 import javax.swing.Box ; 34 import javax.swing.JLabel ; 35 import javax.swing.JPanel ; 36 import javax.swing.JTextField ; 37 38 39 48 public class ChartCoordinateView extends JPanel { 49 50 53 private static final long serialVersionUID = 2547926983897553336L; 54 55 56 private Chart2D m_chart2D; 57 58 59 private JTextField m_xView; 60 61 62 private JTextField m_yView; 63 64 69 private MouseMotionListener m_mouseListener; 70 71 79 public ChartCoordinateView(final Chart2D chart) { 80 this.m_chart2D = chart; 81 this.m_xView = new JTextField (10); 82 this.m_xView.setEditable(false); 83 this.m_yView = new JTextField (10); 84 this.m_yView.setEditable(false); 85 86 this.m_mouseListener = new MouseMotionAdapter () { 87 public void mouseMoved(final MouseEvent me) { 88 TracePoint2D value = ChartCoordinateView.this.m_chart2D.translateMousePosition(me); 89 if (value != null) { 90 ChartCoordinateView.this.m_xView.setText(ChartCoordinateView.this.m_chart2D.getAxisX() 91 .getFormatter().format(value.x)); 92 ChartCoordinateView.this.m_yView.setText(ChartCoordinateView.this.m_chart2D.getAxisY() 93 .getFormatter().format(value.y)); 94 } 95 } 96 }; 97 this.m_chart2D.addMouseMotionListener(this.m_mouseListener); 98 99 this.setLayout(new GridBagLayout ()); 104 105 GridBagConstraints gbc = new GridBagConstraints (); 107 gbc.insets.left = 4; 108 gbc.insets.right = 4; 109 gbc.insets.top = 4; 110 gbc.insets.bottom = 4; 111 gbc.gridx = 0; 112 gbc.gridy = 0; 113 gbc.gridwidth = 1; 114 gbc.weightx = 0; 115 gbc.gridheight = 1; 116 gbc.weighty = 0; 117 this.add(new JLabel ("X value:"), gbc); 118 119 gbc.gridx = 1; 120 gbc.weightx = 0.2; 121 this.add(Box.createHorizontalStrut(4)); 122 123 gbc.gridx = 2; 124 gbc.weightx = 0; 125 this.add(this.m_xView, gbc); 126 127 gbc.gridx = 0; 129 gbc.gridy = 1; 130 gbc.gridwidth = 1; 131 this.add(new JLabel ("Y value:"), gbc); 132 133 gbc.weightx = 0.2; 134 gbc.gridx = 1; 135 this.add(Box.createHorizontalStrut(4)); 136 137 gbc.gridx = 2; 138 gbc.weightx = 0; 139 this.add(this.m_yView, gbc); 140 141 } 142 143 151 public void finalize() throws Throwable { 152 super.finalize(); 153 this.m_chart2D.removeMouseMotionListener(this.m_mouseListener); 154 this.m_chart2D = null; 155 this.m_xView = null; 156 this.m_yView = null; 157 } 158 } 159 | Popular Tags |