001: /*
002: * Copyright 2000-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package org.apache.bcel.verifier;
018:
019: import java.awt.AWTEvent;
020: import java.awt.CardLayout;
021: import java.awt.Color;
022: import java.awt.Dimension;
023: import java.awt.GridLayout;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.WindowEvent;
026: import javax.swing.BorderFactory;
027: import javax.swing.JFrame;
028: import javax.swing.JList;
029: import javax.swing.JMenu;
030: import javax.swing.JMenuBar;
031: import javax.swing.JMenuItem;
032: import javax.swing.JOptionPane;
033: import javax.swing.JPanel;
034: import javax.swing.JScrollPane;
035: import javax.swing.JSplitPane;
036: import javax.swing.JTextPane;
037: import javax.swing.ListSelectionModel;
038: import javax.swing.event.ListSelectionEvent;
039: import org.apache.bcel.Repository;
040: import org.apache.bcel.classfile.JavaClass;
041:
042: /**
043: * This class implements a machine-generated frame for use with
044: * the GraphicalVerfifier.
045: *
046: * @version $Id: VerifierAppFrame.java 386056 2006-03-15 11:31:56Z tcurdt $
047: * @author Enver Haase
048: * @see GraphicalVerifier
049: */
050: public class VerifierAppFrame extends JFrame {
051:
052: JPanel contentPane;
053: JSplitPane jSplitPane1 = new JSplitPane();
054: JPanel jPanel1 = new JPanel();
055: JPanel jPanel2 = new JPanel();
056: JSplitPane jSplitPane2 = new JSplitPane();
057: JPanel jPanel3 = new JPanel();
058: JList classNamesJList = new JList();
059: GridLayout gridLayout1 = new GridLayout();
060: JPanel messagesPanel = new JPanel();
061: GridLayout gridLayout2 = new GridLayout();
062: JMenuBar jMenuBar1 = new JMenuBar();
063: JMenu jMenu1 = new JMenu();
064: JScrollPane jScrollPane1 = new JScrollPane();
065: JScrollPane messagesScrollPane = new JScrollPane();
066: JScrollPane jScrollPane3 = new JScrollPane();
067: GridLayout gridLayout4 = new GridLayout();
068: JScrollPane jScrollPane4 = new JScrollPane();
069: CardLayout cardLayout1 = new CardLayout();
070: private String JUSTICE_VERSION = "JustIce by Enver Haase";
071: private String current_class;
072: GridLayout gridLayout3 = new GridLayout();
073: JTextPane pass1TextPane = new JTextPane();
074: JTextPane pass2TextPane = new JTextPane();
075: JTextPane messagesTextPane = new JTextPane();
076: JMenuItem newFileMenuItem = new JMenuItem();
077: JSplitPane jSplitPane3 = new JSplitPane();
078: JSplitPane jSplitPane4 = new JSplitPane();
079: JScrollPane jScrollPane2 = new JScrollPane();
080: JScrollPane jScrollPane5 = new JScrollPane();
081: JScrollPane jScrollPane6 = new JScrollPane();
082: JScrollPane jScrollPane7 = new JScrollPane();
083: JList pass3aJList = new JList();
084: JList pass3bJList = new JList();
085: JTextPane pass3aTextPane = new JTextPane();
086: JTextPane pass3bTextPane = new JTextPane();
087: JMenu jMenu2 = new JMenu();
088: JMenuItem whatisMenuItem = new JMenuItem();
089: JMenuItem aboutMenuItem = new JMenuItem();
090:
091: /** Constructor. */
092: public VerifierAppFrame() {
093: enableEvents(AWTEvent.WINDOW_EVENT_MASK);
094: try {
095: jbInit();
096: } catch (Exception e) {
097: e.printStackTrace();
098: }
099: }
100:
101: /** Initizalization of the components. */
102: private void jbInit() throws Exception {
103: //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]")));
104: contentPane = (JPanel) this .getContentPane();
105: contentPane.setLayout(cardLayout1);
106: this .setJMenuBar(jMenuBar1);
107: this .setSize(new Dimension(708, 451));
108: this .setTitle("JustIce");
109: jPanel1.setMinimumSize(new Dimension(100, 100));
110: jPanel1.setPreferredSize(new Dimension(100, 100));
111: jPanel1.setLayout(gridLayout1);
112: jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
113: jPanel2.setLayout(gridLayout2);
114: jPanel3.setMinimumSize(new Dimension(200, 100));
115: jPanel3.setPreferredSize(new Dimension(400, 400));
116: jPanel3.setLayout(gridLayout4);
117: messagesPanel.setMinimumSize(new Dimension(100, 100));
118: messagesPanel.setLayout(gridLayout3);
119: jPanel2.setMinimumSize(new Dimension(200, 100));
120: jMenu1.setText("File");
121: jScrollPane1.getViewport().setBackground(Color.red);
122: messagesScrollPane.getViewport().setBackground(Color.red);
123: messagesScrollPane.setPreferredSize(new Dimension(10, 10));
124: classNamesJList
125: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
126:
127: public void valueChanged(ListSelectionEvent e) {
128: classNamesJList_valueChanged(e);
129: }
130: });
131: classNamesJList
132: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
133: jScrollPane3.setBorder(BorderFactory
134: .createLineBorder(Color.black));
135: jScrollPane3.setPreferredSize(new Dimension(100, 100));
136: gridLayout4.setRows(4);
137: gridLayout4.setColumns(1);
138: gridLayout4.setHgap(1);
139: jScrollPane4.setBorder(BorderFactory
140: .createLineBorder(Color.black));
141: jScrollPane4.setPreferredSize(new Dimension(100, 100));
142: pass1TextPane
143: .setBorder(BorderFactory.createRaisedBevelBorder());
144: pass1TextPane.setToolTipText("");
145: pass1TextPane.setEditable(false);
146: pass2TextPane
147: .setBorder(BorderFactory.createRaisedBevelBorder());
148: pass2TextPane.setEditable(false);
149: messagesTextPane.setBorder(BorderFactory
150: .createRaisedBevelBorder());
151: messagesTextPane.setEditable(false);
152: newFileMenuItem.setText("New...");
153: newFileMenuItem.setAccelerator(javax.swing.KeyStroke
154: .getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK,
155: true));
156: newFileMenuItem
157: .addActionListener(new java.awt.event.ActionListener() {
158:
159: public void actionPerformed(ActionEvent e) {
160: newFileMenuItem_actionPerformed(e);
161: }
162: });
163: pass3aTextPane.setEditable(false);
164: pass3bTextPane.setEditable(false);
165: pass3aJList
166: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
167:
168: public void valueChanged(ListSelectionEvent e) {
169: pass3aJList_valueChanged(e);
170: }
171: });
172: pass3bJList
173: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
174:
175: public void valueChanged(ListSelectionEvent e) {
176: pass3bJList_valueChanged(e);
177: }
178: });
179: jMenu2.setText("Help");
180: whatisMenuItem.setText("What is...");
181: whatisMenuItem
182: .addActionListener(new java.awt.event.ActionListener() {
183:
184: public void actionPerformed(ActionEvent e) {
185: whatisMenuItem_actionPerformed(e);
186: }
187: });
188: aboutMenuItem.setText("About");
189: aboutMenuItem
190: .addActionListener(new java.awt.event.ActionListener() {
191:
192: public void actionPerformed(ActionEvent e) {
193: aboutMenuItem_actionPerformed(e);
194: }
195: });
196: jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM);
197: messagesPanel.add(messagesScrollPane, null);
198: messagesScrollPane.getViewport().add(messagesTextPane, null);
199: jSplitPane2.add(jPanel3, JSplitPane.TOP);
200: jPanel3.add(jScrollPane3, null);
201: jScrollPane3.getViewport().add(pass1TextPane, null);
202: jPanel3.add(jScrollPane4, null);
203: jPanel3.add(jSplitPane3, null);
204: jSplitPane3.add(jScrollPane2, JSplitPane.LEFT);
205: jScrollPane2.getViewport().add(pass3aJList, null);
206: jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT);
207: jScrollPane5.getViewport().add(pass3aTextPane, null);
208: jPanel3.add(jSplitPane4, null);
209: jSplitPane4.add(jScrollPane6, JSplitPane.LEFT);
210: jScrollPane6.getViewport().add(pass3bJList, null);
211: jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT);
212: jScrollPane7.getViewport().add(pass3bTextPane, null);
213: jScrollPane4.getViewport().add(pass2TextPane, null);
214: jSplitPane1.add(jPanel2, JSplitPane.TOP);
215: jPanel2.add(jScrollPane1, null);
216: jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
217: jPanel1.add(jSplitPane2, null);
218: jScrollPane1.getViewport().add(classNamesJList, null);
219: jMenuBar1.add(jMenu1);
220: jMenuBar1.add(jMenu2);
221: contentPane.add(jSplitPane1, "jSplitPane1");
222: jMenu1.add(newFileMenuItem);
223: jMenu2.add(whatisMenuItem);
224: jMenu2.add(aboutMenuItem);
225: jSplitPane2.setDividerLocation(300);
226: jSplitPane3.setDividerLocation(150);
227: jSplitPane4.setDividerLocation(150);
228: }
229:
230: /** Overridden to stop the application on a closing window. */
231: protected void processWindowEvent(WindowEvent e) {
232: super .processWindowEvent(e);
233: if (e.getID() == WindowEvent.WINDOW_CLOSING) {
234: System.exit(0);
235: }
236: }
237:
238: synchronized void classNamesJList_valueChanged(ListSelectionEvent e) {
239: if (e.getValueIsAdjusting()) {
240: return;
241: }
242: current_class = classNamesJList.getSelectedValue().toString();
243: try {
244: verify();
245: } catch (ClassNotFoundException ex) {
246: // FIXME: report the error using the GUI
247: ex.printStackTrace();
248: }
249: classNamesJList.setSelectedValue(current_class, true);
250: }
251:
252: private void verify() throws ClassNotFoundException {
253: setTitle("PLEASE WAIT");
254: Verifier v = VerifierFactory.getVerifier(current_class);
255: v.flush(); // Don't cache the verification result for this class.
256: VerificationResult vr;
257: vr = v.doPass1();
258: if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
259: pass1TextPane.setText(vr.getMessage());
260: pass1TextPane.setBackground(Color.red);
261: pass2TextPane.setText("");
262: pass2TextPane.setBackground(Color.yellow);
263: pass3aTextPane.setText("");
264: pass3aJList.setListData(new Object[0]);
265: pass3aTextPane.setBackground(Color.yellow);
266: pass3bTextPane.setText("");
267: pass3bJList.setListData(new Object[0]);
268: pass3bTextPane.setBackground(Color.yellow);
269: } else { // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
270: pass1TextPane.setBackground(Color.green);
271: pass1TextPane.setText(vr.getMessage());
272: vr = v.doPass2();
273: if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
274: pass2TextPane.setText(vr.getMessage());
275: pass2TextPane.setBackground(Color.red);
276: pass3aTextPane.setText("");
277: pass3aTextPane.setBackground(Color.yellow);
278: pass3aJList.setListData(new Object[0]);
279: pass3bTextPane.setText("");
280: pass3bTextPane.setBackground(Color.yellow);
281: pass3bJList.setListData(new Object[0]);
282: } else { // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
283: pass2TextPane.setText(vr.getMessage());
284: pass2TextPane.setBackground(Color.green);
285: JavaClass jc = Repository.lookupClass(current_class);
286: /*
287: boolean all3aok = true;
288: boolean all3bok = true;
289: String all3amsg = "";
290: String all3bmsg = "";
291: */
292: String[] methodnames = new String[jc.getMethods().length];
293: for (int i = 0; i < jc.getMethods().length; i++) {
294: methodnames[i] = jc.getMethods()[i].toString()
295: .replace('\n', ' ').replace('\t', ' ');
296: }
297: pass3aJList.setListData(methodnames);
298: pass3aJList.setSelectionInterval(0,
299: jc.getMethods().length - 1);
300: pass3bJList.setListData(methodnames);
301: pass3bJList.setSelectionInterval(0,
302: jc.getMethods().length - 1);
303: }
304: }
305: String[] msgs = v.getMessages();
306: messagesTextPane.setBackground(msgs.length == 0 ? Color.green
307: : Color.yellow);
308: String allmsgs = "";
309: for (int i = 0; i < msgs.length; i++) {
310: msgs[i] = msgs[i].replace('\n', ' ');
311: allmsgs += msgs[i] + "\n\n";
312: }
313: messagesTextPane.setText(allmsgs);
314: setTitle(current_class + " - " + JUSTICE_VERSION);
315: }
316:
317: void newFileMenuItem_actionPerformed(ActionEvent e) {
318: String classname = JOptionPane
319: .showInputDialog("Please enter the fully qualified name of a class or interface to verify:");
320: if ((classname == null) || (classname.equals(""))) {
321: return;
322: }
323: VerifierFactory.getVerifier(classname); // let observers do the rest.
324: classNamesJList.setSelectedValue(classname, true);
325: }
326:
327: synchronized void pass3aJList_valueChanged(ListSelectionEvent e) {
328: if (e.getValueIsAdjusting()) {
329: return;
330: }
331: Verifier v = VerifierFactory.getVerifier(current_class);
332: String all3amsg = "";
333: boolean all3aok = true;
334: boolean rejected = false;
335: for (int i = 0; i < pass3aJList.getModel().getSize(); i++) {
336: if (pass3aJList.isSelectedIndex(i)) {
337: VerificationResult vr = v.doPass3a(i);
338: if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
339: all3aok = false;
340: rejected = true;
341: }
342: JavaClass jc = null;
343: try {
344: jc = Repository.lookupClass(v.getClassName());
345: all3amsg += "Method '" + jc.getMethods()[i] + "': "
346: + vr.getMessage().replace('\n', ' ')
347: + "\n\n";
348: } catch (ClassNotFoundException ex) {
349: // FIXME: handle the error
350: ex.printStackTrace();
351: }
352: }
353: }
354: pass3aTextPane.setText(all3amsg);
355: pass3aTextPane.setBackground(all3aok ? Color.green
356: : (rejected ? Color.red : Color.yellow));
357: }
358:
359: synchronized void pass3bJList_valueChanged(ListSelectionEvent e) {
360: if (e.getValueIsAdjusting()) {
361: return;
362: }
363: Verifier v = VerifierFactory.getVerifier(current_class);
364: String all3bmsg = "";
365: boolean all3bok = true;
366: boolean rejected = false;
367: for (int i = 0; i < pass3bJList.getModel().getSize(); i++) {
368: if (pass3bJList.isSelectedIndex(i)) {
369: VerificationResult vr = v.doPass3b(i);
370: if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
371: all3bok = false;
372: rejected = true;
373: }
374: JavaClass jc = null;
375: try {
376: jc = Repository.lookupClass(v.getClassName());
377: all3bmsg += "Method '" + jc.getMethods()[i] + "': "
378: + vr.getMessage().replace('\n', ' ')
379: + "\n\n";
380: } catch (ClassNotFoundException ex) {
381: // FIXME: handle the error
382: ex.printStackTrace();
383: }
384: }
385: }
386: pass3bTextPane.setText(all3bmsg);
387: pass3bTextPane.setBackground(all3bok ? Color.green
388: : (rejected ? Color.red : Color.yellow));
389: }
390:
391: void aboutMenuItem_actionPerformed(ActionEvent e) {
392: JOptionPane
393: .showMessageDialog(
394: this ,
395: "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001, 2002.\n<http://jakarta.apache.org/bcel/index.html>",
396: JUSTICE_VERSION,
397: JOptionPane.INFORMATION_MESSAGE);
398: }
399:
400: void whatisMenuItem_actionPerformed(ActionEvent e) {
401: JOptionPane
402: .showMessageDialog(
403: this ,
404: "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.",
405: JUSTICE_VERSION,
406: JOptionPane.INFORMATION_MESSAGE);
407: }
408: }
|