/* * Copyright, Aspect Security, Inc. * * This file is part of JavaSnoop. * * JavaSnoop 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 3 of the License, or * (at your option) any later version. * * JavaSnoop 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 JavaSnoop. If not, see <http://www.gnu.org/licenses/>. */ package com.aspect.snoop.ui.choose.process; import com.aspect.snoop.util.ReflectionUtil; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.List; import java.util.Vector; import javassist.ClassPool; import javassist.CtClass; import javassist.NotFoundException; import javax.swing.DefaultListModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.apache.log4j.Logger; import org.jdesktop.application.Action; public class SearchMainMethodsView extends javax.swing.JDialog { private static final Logger logger = Logger.getLogger(SearchMainMethodsView.class); List<ChangeListener> changeListeners = new Vector<ChangeListener>(); public SearchMainMethodsView(java.awt.Frame parent, boolean modal, ClassPool pool, List<String> classes) { super(parent, modal); initComponents(); lstSearchMainClasses.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int index = lstSearchMainClasses.locationToIndex(e.getPoint()); logger.trace("Double clicked on Item " + index); select(); } } }); // Get all classes with main() methods in the ClassPool DefaultListModel list = new DefaultListModel(); for (String clazz : classes) { try { CtClass c = pool.get(clazz); if (ReflectionUtil.hasMainClass(c,pool)) list.addElement(clazz); } catch (NotFoundException e) { logger.warn(e); } } lstSearchMainClasses.setModel(list); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); lstSearchMainClasses = new javax.swing.JList(); btnCancel = new javax.swing.JButton(); btnSelect = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.aspect.snoop.JavaSnoop.class).getContext().getResourceMap(SearchMainMethodsView.class); setTitle(resourceMap.getString("Form.title")); // NOI18N setName("Form"); // NOI18N jScrollPane1.setName("jScrollPane1"); // NOI18N lstSearchMainClasses.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); lstSearchMainClasses.setName("lstSearchMainClasses"); // NOI18N jScrollPane1.setViewportView(lstSearchMainClasses); javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(com.aspect.snoop.JavaSnoop.class).getContext().getActionMap(SearchMainMethodsView.class, this); btnCancel.setAction(actionMap.get("cancel")); // NOI18N btnCancel.setText(resourceMap.getString("btnCancel.text")); // NOI18N btnCancel.setName("btnCancel"); // NOI18N btnSelect.setAction(actionMap.get("select")); // NOI18N btnSelect.setText(resourceMap.getString("btnSelect.text")); // NOI18N btnSelect.setName("btnSelect"); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(btnCancel) .addGap(18, 18, 18) .addComponent(btnSelect))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnSelect) .addComponent(btnCancel)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents void addChangeListener(ChangeListener changeListener) { changeListeners.add(changeListener); } @Action public void select() { for (ChangeListener changeListener : changeListeners) { changeListener.stateChanged(new ChangeEvent(lstSearchMainClasses.getSelectedValue())); } setVisible(false); } @Action public void cancel() { setVisible(false); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnSelect; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JList lstSearchMainClasses; // End of variables declaration//GEN-END:variables }