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.resources;
25
26 import javax.swing.*;
27 import javax.swing.table.*;
28 import javax.swing.event.*;
29 import javax.swing.border.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.util.*;
33
34
35 import zeus.agentviewer.*;
36 import zeus.util.*;
37
38
39
40 public class ResourceTableUI extends ZeusInternalFrame implements ListSelectionListener,
41 ActionListener,
42 ChangeListener
43
44 {
45 String fsep = System.getProperty("file.separator");
46 String IMAGEPATH = SystemProps.getProperty("gif.dir") + "agentviewer" + fsep;
47 private JPanel contentPane;
48 private JTable table;
49 private JTextArea bottomPane;
50 private JScrollPane topPane;
51
52 final int IMGw = 20;
53 final int IMGh = 20;
54 final int TOP_PANE_MIN_HEIGHT = 120;
55 final int TOP_PANE_MIN_WIDTH = 500;
56 final int BOTTOM_PANE_MIN_WIDTH = 500;
57 final int BOTTOM_PANE_MIN_HEIGHT = 100;
58
59 private static int NUMBER_DISPLAYED = 0;
60 private InternalFramesPanel deskTop;
61 ResourceTableModel resourceBuffer;
62 private FactAttributesTableModel attributesTableModel;
63 JTable attributesTable;
64
65
66
67
68
69 public ResourceTableUI(InternalFramesPanel deskTop,
70 ResourceTableModel resourceBuffer)
71 {
72 super(" ",true,true,true,true);
73 setTitle("Resource Database:" + (++NUMBER_DISPLAYED) );
74 ImageIcon icon = new ImageIcon(IMAGEPATH + ViewerNames.RESDB_IMG);
75 setFrameIcon(icon);
76 this.deskTop = deskTop;
77 this.resourceBuffer =resourceBuffer;
78 attributesTableModel = new FactAttributesTableModel(resourceBuffer);
79 buildUI();
80 deskTop.addInternalFrame(this);
81 setVisible(true);
82 }
83
84
85 Icon getIcon(String imgFile, int w, int h){
86
87 String imgStr = new String(IMAGEPATH + imgFile);
88 Image aImg = Toolkit.getDefaultToolkit().getImage(imgStr);
89 aImg = aImg.getScaledInstance(w,h,Image.SCALE_SMOOTH);
90 Icon aIcon = new ImageIcon(aImg);
91 return aIcon;
92 }
93
94 public void stateChanged(ChangeEvent c){
95 bottomPane.setText(" ");
96 }
97
98 public void actionPerformed(ActionEvent e){
99 String cmd = e.getActionCommand();
100 int sRow;
101
102 if (cmd.equals("delResBtn")) {
103 sRow = table.getSelectedRow();
104 if (sRow == -1) {
105 JOptionPane.showMessageDialog(this," Select resource",
106 "Resource not selected",JOptionPane.ERROR_MESSAGE);
107 return;
108 }
109 else {
110
111
112
113 }
114
115 }
116 }
117
118 JToolBar getToolBar(){
119
120 JButton delResBtn;
121 String img;
122 JToolBar toolBar = new JToolBar();
123
124 delResBtn = new JButton(getIcon(ViewerNames.DELETE_IMG,IMGw,IMGh));
125 delResBtn.setToolTipText("Delete resource");
126 delResBtn.addActionListener(this);
127 delResBtn.setActionCommand("delResBtn");
128 toolBar.add(delResBtn);
129
130 toolBar.setFloatable(false);
131
132 return toolBar;
133 }
134
135 private TitledBorder makeBorder(String title){
136 TitledBorder border = (BorderFactory.createTitledBorder(title));
137 border.setTitlePosition(TitledBorder.TOP);
138 border.setTitleJustification(TitledBorder.RIGHT);
139 border.setTitleFont(new Font("Helvetica", Font.BOLD, 12));
140 border.setTitleColor(Color.black);
141 return border;
142
143 }
144
145 private void buildUI(){
146
147 table = new JTable(resourceBuffer);
148 table.setPreferredScrollableViewportSize(new Dimension(TOP_PANE_MIN_WIDTH,
149 TOP_PANE_MIN_HEIGHT));
150 topPane = new JScrollPane(table);
151 table.getSelectionModel().addListSelectionListener(this );
152 table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
153
154 bottomPane = new JTextArea();
155 bottomPane.setEditable(false);
156 bottomPane.setLineWrap(true);
157 bottomPane.setWrapStyleWord(true);
158 bottomPane.setPreferredSize(new Dimension(BOTTOM_PANE_MIN_WIDTH,
159 BOTTOM_PANE_MIN_HEIGHT));
160 JScrollPane bottomSP = new JScrollPane(bottomPane);
161 bottomSP.setBorder(BorderFactory.createEtchedBorder(Color.black,Color.gray));
162
163
164 attributesTable = new JTable(attributesTableModel);
165 attributesTable.setColumnSelectionAllowed(false);
166 attributesTable = new JTable(attributesTableModel);
167 attributesTable.setPreferredScrollableViewportSize(new Dimension(BOTTOM_PANE_MIN_WIDTH,
168 BOTTOM_PANE_MIN_HEIGHT));
169
170 JPanel attributesPanel = new JPanel(new BorderLayout());
171 attributesPanel.setBorder(makeBorder("Attributes"));
172 attributesPanel.add(BorderLayout.CENTER,new JScrollPane(attributesTable));
173
174 JPanel centerPanel = new JPanel(new BorderLayout());
175 centerPanel.add(BorderLayout.NORTH,topPane);
176 centerPanel.add(BorderLayout.CENTER,attributesPanel);
177
178
179 contentPane = (JPanel) getContentPane();
180 contentPane.setLayout(new BorderLayout());
181
182 contentPane.add(BorderLayout.CENTER,centerPanel);
183
184
185 pack();
186
187 }
188
189 void displayAttributes(){
190
191 int row = table.getSelectedRow();
192 if (row >= 0 && row < resourceBuffer.getRowCount()) {
193 attributesTableModel.setFact(resourceBuffer.getAttributesOf(row));
194 reSize();
195 }
196
197 }
198
199 public void valueChanged(ListSelectionEvent e) {
200 int row;
201 if (e.getSource() == table.getSelectionModel() ) {
202
203 row = table.getSelectedRow();
204 if (row >= 0 && row < resourceBuffer.getRowCount()) {
205
206
207 displayAttributes();
208
209 }
210 }
211
212 }
213
214
215 void reSize(){
216 setSize(getWidth()+1,getHeight());
217 setSize(getWidth()-1,getHeight());
218 }
219
220 }