1 package com.bonevich.erj.ui.editor;
2
3 import com.bonevich.erj.diagram.ERDiagramGraphModel;
4 import com.bonevich.erj.ErjConstants;
5
6 import org.tigris.gef.base.Editor;
7 import org.tigris.gef.base.Globals;
8 import org.tigris.gef.presentation.Fig;
9
10 import java.util.LinkedList;
11 import java.util.Iterator;
12 import java.util.Vector;
13
14 import java.awt.*;
15 import java.awt.event.*;
16 import javax.swing.*;
17 import javax.swing.border.*;
18
19 /*** A base class for model editors. Provides a single
20 * pane which contains the name, label, and description
21 * fields common to most model elements. Subclasses
22 * can create additional tab panes by creating instances
23 * of <code>TabInfo</code> and adding them to the tab
24 * list.
25 */
26 public abstract class ModelEditor implements ErjConstants
27 {
28 //////////////////////////////////////////////////////////
29 // Constants
30 public static final String NAME_STR = "Name:";
31 public static final String IDENTIFIER_STR = "Identifier:";
32 public static final String DESC_STR = "Description";
33
34 //////////////////////////////////////////////////////////
35 // Attributes
36 private JTabbedPane _parent;
37 private Window _window;
38 private Object _owner;
39 private String _defaultLabel = null;
40 private Icon _defaultIcon = null;
41 private String _defaultTip = null;
42 private int _defaultIndex = 0;
43 private LinkedList _tabs = new LinkedList();
44
45 protected JPanel _propPane = new JPanel();
46 protected JPanel _namePane = new JPanel();
47 protected JLabel _nameLabel = new JLabel(NAME_STR);
48 protected JTextField _nameText = new JTextField(20);
49 protected JPanel _identifierPane = new JPanel();
50 protected JLabel _identifierLabel = new JLabel(IDENTIFIER_STR);
51 protected IdentifierTextField _identifierText = new IdentifierTextField();
52 protected JPanel _descPane = new JPanel();
53 protected Border _descBrdr = BorderFactory.createTitledBorder(DESC_STR);
54 protected JTextArea _descText = new JTextArea(5, 20);
55 {
56 _nameLabel.setFont(EDITOR_FONT);
57 _nameLabel.setForeground(EDITOR_COLOR);
58 _identifierLabel.setFont(EDITOR_FONT);
59 _identifierLabel.setForeground(EDITOR_COLOR);
60 ((TitledBorder)_descBrdr).setTitleFont(EDITOR_FONT);
61 ((TitledBorder)_descBrdr).setTitleColor(EDITOR_COLOR);
62 }
63
64 //////////////////////////////////////////////////////////
65 // Constructors
66 public ModelEditor(JTabbedPane parent, Object owner)
67 {
68 setParent(parent);
69 setOwner(owner);
70 initTabs();
71 installTabs();
72 updateEditor();
73 }
74
75 //////////////////////////////////////////////////////////
76 // Operations
77 protected JTabbedPane getParent()
78 {
79 return _parent;
80 }
81 protected void setParent(JTabbedPane parent)
82 {
83 _parent = parent;
84 }
85
86 protected Object getOwner()
87 {
88 return _owner;
89 }
90 protected void setOwner(Object owner)
91 {
92 _owner = owner;
93 }
94
95 public Window getWindow()
96 {
97 return _window;
98 }
99 public void setWindow(Window window)
100 {
101 _window = window;
102 }
103
104 /*
105 protected void repaintUI()
106 {
107 Editor ce = Globals.curEditor();
108 Vector figs = ce.getSelectionManager().getFigs();
109 Fig ui = (Fig)figs.elements().nextElement();
110 if (ui != null)
111 {
112 ui.damage();
113 }
114
115 _window.invalidate();
116 _window.repaint();
117 _parent.revalidate();
118 }
119 */
120
121 protected void ownerUpdated()
122 {
123 Editor ce = Globals.curEditor();
124 ERDiagramGraphModel erdgm = (ERDiagramGraphModel)ce.getGraphModel();
125 erdgm.fireGraphChanged(getOwner());
126 }
127
128 protected TabInfo addTab(String l, Icon i, Component c, String t, int idx)
129 {
130 TabInfo info = new TabInfo(l,i,c,t,idx);
131 _tabs.add(info);
132 return info;
133 }
134
135 protected void setDefaultLabel(String label)
136 {
137 _defaultLabel = label;
138 }
139 protected void setDefaultIcon(Icon icon)
140 {
141 _defaultIcon = icon;
142 }
143 protected void setDefaultTip(String tip)
144 {
145 _defaultTip = tip;
146 }
147 protected void setDefaultIndex(int index)
148 {
149 _defaultIndex = index;
150 }
151
152 protected void initTabs()
153 {
154 _propPane.setLayout(new BoxLayout(_propPane, BoxLayout.Y_AXIS));
155
156 _namePane.setLayout(new BoxLayout(_namePane, BoxLayout.X_AXIS));
157 _namePane.setAlignmentX(Component.LEFT_ALIGNMENT);
158 _nameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
159 _nameText.setAlignmentX(Component.LEFT_ALIGNMENT);
160 _nameText.getDocument().addDocumentListener(_identifierText);
161 _namePane.add(_nameLabel);
162 _namePane.add(_nameText);
163
164 _identifierPane.setLayout(new BoxLayout(_identifierPane, BoxLayout.X_AXIS));
165 _identifierPane.setAlignmentX(Component.LEFT_ALIGNMENT);
166 _identifierLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
167 _identifierText.setAlignmentX(Component.LEFT_ALIGNMENT);
168 _identifierPane.add(_identifierLabel);
169 _identifierPane.add(_identifierText);
170
171 _descPane.setLayout(new BoxLayout(_descPane, BoxLayout.Y_AXIS));
172 _descPane.setAlignmentX(Component.LEFT_ALIGNMENT);
173 _descPane.setBorder(_descBrdr);
174 _descText.setAlignmentX(Component.LEFT_ALIGNMENT);
175 _descText.setLineWrap(true);
176 _descText.setWrapStyleWord(true);
177
178 JScrollPane scrPane = new JScrollPane(_descText);
179 scrPane.setAlignmentX(Component.LEFT_ALIGNMENT);
180 scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
181 scrPane.setPreferredSize(new Dimension(350, 100));
182 _descPane.add(scrPane);
183
184 JPanel pane1 = new JPanel(new BorderLayout());
185 JPanel pane2 = new JPanel(new BorderLayout());
186 pane1.setAlignmentX(Component.LEFT_ALIGNMENT);
187 pane2.setAlignmentX(Component.LEFT_ALIGNMENT);
188 pane2.add(_namePane, BorderLayout.NORTH);
189 pane2.add(_identifierPane, BorderLayout.SOUTH);
190 pane1.add(pane2, BorderLayout.NORTH);
191 pane1.add(_descPane, BorderLayout.CENTER);
192
193 _propPane.add(pane1);
194 addTab(_defaultLabel, _defaultIcon, _propPane, _defaultTip, _defaultIndex);
195 }
196
197 private void installTabs()
198 {
199 Iterator itr = _tabs.iterator();
200 while (itr.hasNext())
201 {
202 TabInfo tab = (TabInfo) itr.next();
203 tab.install(_parent);
204 }
205 }
206
207 public abstract boolean validate();
208
209 public abstract void updateModel();
210
211 public abstract void updateEditor();
212
213 private final class TabInfo
214 {
215 private String _label;
216 private Icon _icon;
217 private Component _component;
218 private String _tip;
219 private int _index = -1;
220
221 TabInfo(String l, Icon i, Component c, String t, int idx)
222 {
223 _label = l; _icon = i; _component = c; _tip = t; _index = idx;
224 }
225
226 void install(JTabbedPane pane)
227 {
228 pane.insertTab(_label, _icon, _component, _tip, _index);
229 }
230 }
231
232 } /* end class ModelEditor */
This page was automatically generated by Maven