1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /******************************************************************************
25 * AttributeTable.java
26 *
27 * The Container panel for the Attribute Table
28 *****************************************************************************/
29
30 package zeus.generator.util;
31
32 import java.awt.*;
33 import java.awt.event.*;
34 import javax.swing.*;
35 import javax.swing.border.*;
36 import javax.swing.table.*;
37 import javax.swing.text.*;
38
39 import zeus.gui.fields.*;
40 import zeus.gui.editors.*;
41 import zeus.util.Core;
42
43 public class AttributeTable extends JPanel {
44
45 protected JTable table;
46 protected AttributeModel model;
47 protected AttributeDialog dialog;
48 protected AttributeTreeModel attributeTreeModel;
49
50 public AttributeTable(AttributeModel model) {
51 this.model = model;
52 attributeTreeModel = new AttributeTreeModel(model);
53
54 TableColumnModel tm = new DefaultTableColumnModel();
55 TableColumn column;
56 column = new TableColumn(AttributeModel.ATTRIBUTE,12);
57 column.setHeaderValue(model.getColumnName(AttributeModel.ATTRIBUTE));
58 tm.addColumn(column);
59 ExpressionCellEditor editor = new ExpressionCellEditor(model);
60 editor.addMouseListener(new SymMouseAction());
61 column = new TableColumn(AttributeModel.VALUE,24,
62 new ValidatingCellRenderer(model,AttributeModel.VALUE), editor);
63 column.setHeaderValue(model.getColumnName(AttributeModel.VALUE));
64 tm.addColumn(column);
65
66 table = new JTable(model,tm);
67 table.getTableHeader().setReorderingAllowed(false);
68 table.setColumnSelectionAllowed(false);
69
70 GridBagLayout gridBagLayout = new GridBagLayout();
71 setLayout(gridBagLayout);
72 setBackground(Color.lightGray);
73 setBorder(new BevelBorder(BevelBorder.LOWERED));
74 setPreferredSize(new Dimension(200,120));
75
76 JScrollPane scrollPane = new JScrollPane(table);
77 scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
78 scrollPane.setPreferredSize(new Dimension(400,80));
79 table.setBackground(Color.white);
80
81 GridBagConstraints gbc = new GridBagConstraints();
82 gbc.gridwidth = GridBagConstraints.REMAINDER;
83 gbc.anchor = GridBagConstraints.WEST;
84 gbc.fill = GridBagConstraints.BOTH;
85 gbc.weightx = gbc.weighty = 1;
86 gbc.insets = new Insets(4,4,4,4);
87 gridBagLayout.setConstraints(scrollPane, gbc);
88 add(scrollPane);
89 }
90
91 public void setFactModel(BasicFactModel factmodel) {
92 attributeTreeModel.setFactModel(factmodel);
93 }
94 public void setFactModels(BasicFactModel preModel, BasicFactModel postModel) {
95 attributeTreeModel.setFactModels(preModel,postModel);
96 }
97
98 class SymMouseAction extends MouseAdapter implements AttributeSelector {
99 protected JTextComponent field = null;
100
101 public void mouseClicked(MouseEvent e) {
102 if ( SwingUtilities.isRightMouseButton(e) ) {
103 if ( dialog == null ) {
104 Component comp = SwingUtilities.getRoot(table);
105 if ( comp instanceof Frame )
106 dialog = new AttributeDialog((Frame)comp,attributeTreeModel);
107 else if ( comp instanceof Dialog )
108 dialog = new AttributeDialog((Dialog)comp,attributeTreeModel);
109 else
110 Core.ERROR(null,1,this);
111 }
112 field = (JTextComponent)e.getSource();
113 dialog.setLocationRelativeTo(field);
114 dialog.display(this);
115 }
116 }
117 public void attributeSelected(String attribute) {
118 try {
119 Document doc = field.getDocument();
120 int length = doc.getLength();
121 AttributeSet a = doc.getDefaultRootElement().getAttributes();
122 doc.insertString(length,attribute,a);
123 }
124 catch(BadLocationException e) {
125 }
126 }
127 }
128 }