/
DrawingVarsPanel.java
executable file
·275 lines (237 loc) · 9.62 KB
/
DrawingVarsPanel.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* DrawingVarsPanel.java
*
* Created on August 22, 2006, 4:31 PM
*
* Author: David Pilo
*
Pilo's Visualization Tools for Scheme (PVTS). A Basic Visual Scheme Interpreter.
Copyright (C) 2007 David A. Pilo Mansion
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact information:
David Pilo
davidpilo@gmail.com
*/
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
*
/**
*
* @author david
*/
public class DrawingVarsPanel extends JPanel {
public static boolean varTableShow = true;
public static boolean primTableShow = false;
public static boolean procTableShow = true;
public static boolean listTableShow = true;
public JTable primTable = new JTable(300,1);
public JTable procTable = new JTable(300,2);
public JTable listTable = new JTable(300,2);
public JTable varsTable = new JTable(300,2);
public JLabel primLabel = new JLabel("Primitives:");
public JLabel procLabel = new JLabel("Procedures:");
public JLabel listLabel = new JLabel("Lists Variables:");
public JLabel varsLabel = new JLabel("Other Variables:");
public JPanel primPanel = new JPanel();
public JPanel procPanel = new JPanel();
public JPanel listPanel = new JPanel();
public JPanel varsPanel = new JPanel();
/** Creates a new instance of DrawingTreesPanel */
public DrawingVarsPanel() {
primPanel.add(primLabel);
primPanel.add(primTable);
primPanel.setLayout(new BoxLayout(primPanel, BoxLayout.PAGE_AXIS));
procPanel.add(procLabel);
procPanel.add(procTable);
procPanel.setLayout(new BoxLayout(procPanel, BoxLayout.PAGE_AXIS));
listPanel.add(listLabel);
listPanel.add(listTable);
listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.PAGE_AXIS));
varsPanel.add(varsLabel);
varsPanel.add(varsTable);
varsPanel.setLayout(new BoxLayout(varsPanel, BoxLayout.PAGE_AXIS));
this.add(listPanel);
this.add(varsPanel);
this.add(procPanel);
//this.add(primPanel);
addTableListeners();
}
public void paintComponent(Graphics g) {
// Paint background
super.paintComponent(g);
this.removeAll();
if (listTableShow) {
this.add(listPanel);
drawListsTable();
}
if (varTableShow) {
this.add(varsPanel);
drawVariablesTable();
}
if (procTableShow) {
this.add(procPanel);
drawProceduresTable();
}
if (primTableShow) {
this.add(primPanel);
drawPrimitivesTable();
}
this.revalidate();
} // paintComponent
public void addTableListeners() {
procTable.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {
}
public void mouseEntered(MouseEvent mouseEvent) {
}
public void mouseExited(MouseEvent mouseEvent) {
}
public void mousePressed(MouseEvent mouseEvent) {
}
public void mouseReleased(MouseEvent mouseEvent) {
JFrame f = new JFrame("Information:");
JTextArea t = new JTextArea();
t.setLineWrap(true);
f.add(t);
t.setText((procTable.getValueAt(procTable.getSelectedRow(),procTable.getSelectedColumn())).toString());
f.setVisible(true);
f.setLocation(java.awt.MouseInfo.getPointerInfo().getLocation());
f.setSize(new Dimension(400,150));
}
});
primTable.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {
}
public void mouseEntered(MouseEvent mouseEvent) {
}
public void mouseExited(MouseEvent mouseEvent) {
}
public void mousePressed(MouseEvent mouseEvent) {
}
public void mouseReleased(MouseEvent mouseEvent) {
JFrame f = new JFrame("Information:");
JTextArea t = new JTextArea();
t.setLineWrap(true);
f.add(t);
t.setText((primTable.getValueAt(primTable.getSelectedRow(),primTable.getSelectedColumn())).toString());
f.setVisible(true);
f.setLocation(java.awt.MouseInfo.getPointerInfo().getLocation());
f.setSize(new Dimension(400,150));
}
});
varsTable.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {
}
public void mouseEntered(MouseEvent mouseEvent) {
}
public void mouseExited(MouseEvent mouseEvent) {
}
public void mousePressed(MouseEvent mouseEvent) {
}
public void mouseReleased(MouseEvent mouseEvent) {
JFrame f = new JFrame("Information:");
JTextArea t = new JTextArea();
t.setLineWrap(true);
f.add(t);
t.setText((varsTable.getValueAt(varsTable.getSelectedRow(),varsTable.getSelectedColumn())).toString());
f.setVisible(true);
f.setLocation(java.awt.MouseInfo.getPointerInfo().getLocation());
f.setSize(new Dimension(400,150));
}
});
listTable.addMouseListener(new java.awt.event.MouseListener() {
public void mouseClicked(MouseEvent mouseEvent) {
}
public void mouseEntered(MouseEvent mouseEvent) {
}
public void mouseExited(MouseEvent mouseEvent) {
}
public void mousePressed(MouseEvent mouseEvent) {
}
public void mouseReleased(MouseEvent mouseEvent) {
//if (listTable.(listTable.getSelectedRow(),listTable.getSelectedColumn())) {
JFrame f = new JFrame("Information:");
JTextArea t = new JTextArea();
t.setLineWrap(true);
f.add(t);
t.setText((listTable.getValueAt(listTable.getSelectedRow(),listTable.getSelectedColumn())).toString());
f.setVisible(true);
f.setLocation(java.awt.MouseInfo.getPointerInfo().getLocation());
f.setSize(new Dimension(400,150));
// }
}
});
}
public void drawVariablesTable () {
varsTable.setBackground(new Color(210,210,210));
// varsTable.selectAll();
// varsTable.removeAll();
// varsTable.clearSelection();
clearTable(varsTable);
varsTable.setValueAt("Name:",0,0);
varsTable.setValueAt("Value:",0,1);
LinkedList l = PVTS.envStack.getAllVariables();
for (int i=0; i < ((LinkedList)l.get(0)).size(); i= i+2) {
//varsTable.setSize(new Dimension(30,2));
varsTable.setValueAt(((LinkedList)l.get(0)).get(i),i/2+1,0);
varsTable.setValueAt(((LinkedList)l.get(0)).get(i+1),i/2+1,1);
}
}
public void drawListsTable () {
listTable.setBackground(new Color(210,210,210));
// listTable.removeAll();
clearTable(listTable);
listTable.setValueAt("Name:",0,0);
listTable.setValueAt("Value:",0,1);
LinkedList l = PVTS.envStack.getAllLists();
for (int i=0; i < ((LinkedList)l.get(0)).size(); i= i+2) {
//varsTable.setSize(new Dimension(30,2));
listTable.setValueAt(((LinkedList)l.get(0)).get(i),i/2+1,0);
listTable.setValueAt(((LinkedList)l.get(0)).get(i+1),i/2+1,1);
}
}
public void drawPrimitivesTable () {
primTable.setBackground(new Color(210,210,210));
clearTable(primTable);
primTable.setValueAt("Name:",0,0);
LinkedList l = PVTS.envStack.getAllPrimitives();
for (int i=0; i < ((LinkedList)l.get(0)).size(); i= i+1) {
//varsTable.setSize(new Dimension(30,2));
primTable.setValueAt(((LinkedList)l.get(0)).get(i),i+1,0);
}
}
public void drawProceduresTable () {
procTable.setBackground(new Color(210,210,210));
// procTable.selectAll();
//procTable.clearSelection();
clearTable(procTable);
procTable.setValueAt("Name:",0,0);
procTable.setValueAt("Value:",0,1);
LinkedList l = PVTS.envStack.getAllProcedures();
for (int i=0; i < ((LinkedList)l.get(0)).size(); i= i+2) {
//varsTable.setSize(new Dimension(30,2));
procTable.setValueAt(((LinkedList)l.get(0)).get(i),i/2+1,0);
procTable.setValueAt(((LinkedList)l.get(0)).get(i+1),i/2+1,1);
}
}
public void clearTable(JTable t) {
for (int i = 0 ; i < t.getColumnCount(); i ++) {
for (int j = 0; j < t.getRowCount(); j ++) {
t.setValueAt("",j,i);
}
}
}
}