1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.agentviewer.acquaintances;
25
26 import javax.swing.*;
27 import javax.swing.table.*;
28 import javax.swing.border.*;
29 import javax.swing.event.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import zeus.agentviewer.*;
33 import zeus.util.*;
34
35
36
37
38 public class AcquaintanceUI extends ZeusInternalFrame implements ListSelectionListener {
39 String fsep = System.getProperty("file.separator");
40 String IMAGEPATH = SystemProps.getProperty("gif.dir") + "agentviewer" + fsep;
41
42 private JPanel contentPane;
43 private JTable relationsTable,abilitiesTable, attributesTable;
44
45 private AbilitiesTableModel abilitiesTableModel;
46 private RelationsTableModel relationsTableModel;
47 private AttributesTableModel attributesTableModel;
48 private JScrollPane relationsSP, abilitiesSP, attributesSP;
49
50 final int IMGw = 20;
51 final int IMGh = 20;
52 final int TABLE_HEIGHT = 10;
53 final int TABLE_WIDTH = 200;
54 final int FIRST_ROW =0;
55 private static int NUMBER_DISPLAYED = 0;
56 private InternalFramesPanel deskTop;
57 private TitledBorder border;
58
59
60
61
62
63 public AcquaintanceUI(InternalFramesPanel deskTop, RelationsTableModel relationsBuffer,
64 AbilitiesTableModel abilitiesBuffer,
65 AttributesTableModel attributesBuffer)
66 {
67 super(" ",true,true,true,true);
68 setTitle("Aquaintance Database: " + (++NUMBER_DISPLAYED) );
69 ImageIcon icon = new ImageIcon(IMAGEPATH + ViewerNames.ACQDB_IMG);
70 setFrameIcon(icon);
71 this.deskTop = deskTop;
72 relationsTableModel = relationsBuffer;
73 abilitiesTableModel = abilitiesBuffer;
74 attributesTableModel = attributesBuffer;
75 buildUI();
76
77 deskTop.addInternalFrame(this);
78 setVisible(true);
79 }
80
81 private TitledBorder makeBorder(String title){
82 TitledBorder border = (BorderFactory.createTitledBorder(title));
83 border.setTitlePosition(TitledBorder.TOP);
84 border.setTitleJustification(TitledBorder.RIGHT);
85 border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
86 border.setTitleColor(Color.blue);
87 return border;
88
89 }
90
91 Icon getIcon(String imgFile, int w, int h){
92
93 String imgStr = new String(IMAGEPATH + imgFile);
94 Image aImg = Toolkit.getDefaultToolkit().getImage(imgStr);
95 aImg = aImg.getScaledInstance(w,h,Image.SCALE_SMOOTH);
96 Icon aIcon = new ImageIcon(aImg);
97 return aIcon;
98 }
99
100 private void buildUI(){
101
102
103 relationsTable = new JTable(relationsTableModel);
104 relationsTable.setColumnSelectionAllowed(false);
105 relationsTable.setPreferredScrollableViewportSize(new Dimension(TABLE_WIDTH,
106 TABLE_HEIGHT));
107 relationsSP = new JScrollPane(relationsTable);
108 relationsTable.setBackground(Color.white);
109 relationsTable.getSelectionModel().addListSelectionListener(this );
110 relationsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
111
112 abilitiesTable = new JTable(abilitiesTableModel);
113 abilitiesTable.setColumnSelectionAllowed(false);
114 abilitiesTable.setPreferredScrollableViewportSize(new Dimension(TABLE_WIDTH,
115 TABLE_HEIGHT*2));
116 abilitiesSP = new JScrollPane(abilitiesTable);
117 abilitiesTable.setBackground(Color.white);
118 abilitiesTable.getSelectionModel().addListSelectionListener(this );
119 abilitiesTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
120
121
122 attributesTable = new JTable(attributesTableModel);
123 attributesTable.setColumnSelectionAllowed(false);
124 attributesTable = new JTable(attributesTableModel);
125 attributesTable.setPreferredScrollableViewportSize(new Dimension(TABLE_WIDTH,
126 TABLE_HEIGHT*3));
127 attributesSP = new JScrollPane(attributesTable);
128 attributesTable.setBackground(Color.white);
129
130
131 JPanel centerPanel = new JPanel();
132 centerPanel.setLayout(new GridLayout(3,1,10,15));
133
134 JPanel relationsPanel = new JPanel(new BorderLayout());
135 relationsPanel.setBorder(makeBorder("Known Relations"));
136 relationsPanel.add(BorderLayout.CENTER,relationsSP);
137 JPanel abilitiesPanel = new JPanel(new BorderLayout());
138 abilitiesPanel.setBorder(makeBorder("Agent's Abilities"));
139 abilitiesPanel.add(BorderLayout.CENTER,abilitiesSP);
140 JPanel attributesPanel = new JPanel(new BorderLayout());
141 attributesPanel.setBorder(makeBorder("Fact Attributes"));
142 attributesPanel.add(BorderLayout.CENTER,attributesSP);
143
144 centerPanel.add(relationsPanel);
145 centerPanel.add(abilitiesPanel);
146 centerPanel.add(attributesPanel);
147
148 contentPane = (JPanel) getContentPane();
149 contentPane.setLayout(new BorderLayout());
150 contentPane.add(BorderLayout.CENTER,centerPanel);
151 pack();
152 }
153
154 void displayAbilities(){
155 int selectedRow = relationsTable.getSelectedRow();
156 if (selectedRow >= 0 && selectedRow < relationsTableModel.getRowCount()) {
157 String name = relationsTableModel.getName(selectedRow);
158 if (abilitiesTableModel.hasAbilities(name)== false){
159 attributesTableModel.setFact(null);
160 return;
161 }
162 abilitiesTableModel.setAbilitiesof(name);
163 attributesTableModel.setFact(abilitiesTableModel.getAttributesof(FIRST_ROW));
164 reSize();
165 }
166 }
167
168 void displayAttributes(){
169
170 int selectedRow = abilitiesTable.getSelectedRow();
171 if (selectedRow >= 0 && selectedRow < abilitiesTableModel.getRowCount()) {
172 attributesTableModel.setFact(abilitiesTableModel.getAttributesof(selectedRow));
173 reSize();
174 }
175 }
176
177 public void valueChanged(ListSelectionEvent e) {
178
179 String aValue;
180 if (e.getSource() == relationsTable.getSelectionModel() ) {
181 displayAbilities();
182 }
183 else if (e.getSource() == abilitiesTable.getSelectionModel() ) {
184 displayAttributes();
185 }
186 }
187
188 void reSize(){
189 setSize(getWidth()+1,getHeight());
190 setSize(getWidth()-1,getHeight());
191 }
192
193 }
194