01: package net.sourceforge.squirrel_sql.plugins.graph;
02:
03: import javax.swing.*;
04: import java.awt.*;
05: import java.awt.event.MouseListener;
06:
07: public class GraphTextAreaFactory {
08: private ColumnTextArea _txtColumns;
09: private ZoomableColumnTextArea _txtZoomColumns;
10:
11: public GraphTextAreaFactory(TableToolTipProvider toolTipProvider,
12: Zoomer zoomer) {
13: _txtColumns = new ColumnTextArea(toolTipProvider);
14: _txtColumns.setEditable(false);
15: _txtColumns.setBackground(new Color(255, 255, 204));
16:
17: _txtZoomColumns = new ZoomableColumnTextArea(toolTipProvider,
18: zoomer);
19: _txtZoomColumns.setBackground(new Color(255, 255, 204));
20:
21: }
22:
23: public JComponent getComponent(boolean zoomEnabled) {
24: if (zoomEnabled) {
25: return _txtZoomColumns;
26: } else {
27: return _txtColumns;
28: }
29: }
30:
31: /**
32: * Really tries it's best to provide the component. That means:
33: * 1. If a showing component exists it is returned.
34: * 2. If a visible and and non null Graphics providing Component exists it is returned
35: *
36: * If non of the above is true the method returns null.
37: * @return If not null the component is guranteed to provide Graphics
38: */
39: public JComponent getBestReadyComponent() {
40:
41: if (getComponent(true).isShowing()
42: || (getComponent(true).isVisible() && null != getComponent(
43: true).getGraphics())) {
44: return getComponent(true);
45: } else if (getComponent(false).isShowing()
46: || (getComponent(false).isVisible() && null != getComponent(
47: false).getGraphics())) {
48: return getComponent(false);
49: } else {
50: return null;
51: }
52: }
53:
54: public Graphics getGraphics() {
55: JComponent bestReadyComponent = getBestReadyComponent();
56: if (null == bestReadyComponent) {
57: return null;
58: }
59: return bestReadyComponent.getGraphics();
60: }
61:
62: public Font getFont() {
63: JComponent bestReadyComponent = getBestReadyComponent();
64: if (null == bestReadyComponent) {
65: return null;
66: }
67: return bestReadyComponent.getGraphics().getFont();
68: }
69:
70: public void setColumns(ColumnInfo[] columnInfos) {
71: _txtColumns.setGraphColumns(columnInfos);
72: _txtZoomColumns.setGraphColumns(columnInfos);
73: }
74:
75: public void addMouseListener(MouseListener ml) {
76: _txtColumns.addMouseListener(ml);
77: _txtZoomColumns.addMouseListener(ml);
78: }
79: }
|