01: package net.sourceforge.squirrel_sql.client.gui.session;
02:
03: import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanel;
04:
05: import javax.swing.*;
06: import javax.swing.event.CaretListener;
07: import javax.swing.event.CaretEvent;
08: import javax.swing.border.Border;
09: import java.awt.*;
10:
11: class RowColumnLabel extends JLabel {
12: private ISQLEntryPanel _sqlEntryPanel;
13: private StringBuffer _msg = new StringBuffer();
14:
15: RowColumnLabel(ISQLEntryPanel sqlEntryPanel) {
16: super (" ", JLabel.CENTER);
17:
18: _sqlEntryPanel = sqlEntryPanel;
19:
20: sqlEntryPanel.addCaretListener(new CaretListener() {
21: public void caretUpdate(CaretEvent e) {
22: onCaretUpdate(e);
23: }
24:
25: });
26:
27: writePosition(0, 0);
28: }
29:
30: private void onCaretUpdate(CaretEvent e) {
31: int caretLineNumber = _sqlEntryPanel.getCaretLineNumber();
32: int caretLinePosition = _sqlEntryPanel.getCaretLinePosition();
33:
34: writePosition(caretLineNumber, caretLinePosition);
35: }
36:
37: private void writePosition(int caretLineNumber,
38: int caretLinePosition) {
39: _msg.setLength(0);
40: _msg.append(caretLineNumber + 1).append(",").append(
41: caretLinePosition + 1);
42: setText(_msg.toString());
43: }
44:
45: /**
46: * Return the preferred size of this component.
47: *
48: * @return the preferred size of this component.
49: */
50: public Dimension getPreferredSize() {
51: Dimension dim = super .getPreferredSize();
52: FontMetrics fm = getFontMetrics(getFont());
53: dim.width = fm.stringWidth("000,000");
54: Border border = getBorder();
55: if (border != null) {
56: Insets ins = border.getBorderInsets(this );
57: if (ins != null) {
58: dim.width += (ins.left + ins.right);
59: }
60: }
61: Insets ins = getInsets();
62: if (ins != null) {
63: dim.width += (ins.left + ins.right);
64: }
65: return dim;
66: }
67:
68: }
|