import java.awt.Dimension;
import java.util.List;
import java.util.Vector;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import fbench.FBench;
import fbench.plugin.PluginManager;
/**
* Plug-in for FBench which lists all the available plug-ins
*
* @author Jason Park, Cheng Pang
*/
public class ListPlugIn extends javax.swing.JFrame {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = -8657175942653142601L;
private FBench fBench;
private java.util.Vector<org.jdom.Element> xmlList;
private PluginManager pluginManager;
public ListPlugIn() {
}
public void launchPluginList(Vector<Object> args) {
fBench = ((fbench.FBench) args.get(1));
pluginManager = fBench.getPluginManager();
xmlList = pluginManager.loadXML();
initComponents();
Dimension pluginListSize = this.getSize();
setLocation((int) (fBench.getX() + fBench.getWidth() / 2 - pluginListSize.getWidth() / 2),
(int) (fBench.getY() + fBench.getHeight() / 2 - pluginListSize.getHeight() / 2));
setVisible(true);
}
private void initComponents() {
contentPanel = new javax.swing.JPanel();
pListPane = new javax.swing.JScrollPane();
pList = new javax.swing.JList();
fileScrlPane = new javax.swing.JScrollPane();
fileList = new javax.swing.JList();
descriptionPane = new javax.swing.JScrollPane();
descriptionArea = new javax.swing.JTextArea();
listLabel = new javax.swing.JLabel();
pluginInfoLbl = new javax.swing.JLabel();
nameLabel = new javax.swing.JLabel();
nameIndicatorLbl = new javax.swing.JLabel();
authorIndicatorLbl = new javax.swing.JLabel();
versionIndicatorLbl = new javax.swing.JLabel();
authorLabel = new javax.swing.JLabel();
versionLabel = new javax.swing.JLabel();
fileIndicatorLbl = new javax.swing.JLabel();
copyrightIndicatorLbl = new javax.swing.JLabel();
copyrightLabel = new javax.swing.JLabel();
descriptionIndicatorLbl = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("List of Plug-ins for FBench");
setResizable(false);
pList.setModel(new javax.swing.AbstractListModel() {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = -5950106441181815063L;
Object[] names = getPluginNames();
public Object[] getPluginNames() {
Object[] pluginNames = new Object[xmlList.size()];
for(int i = 0; i < pluginNames.length; i++) {
pluginNames[i] = xmlList.get(i).getAttributeValue("Name");
}
return pluginNames;
}
public int getSize() {
return names.length;
}
public Object getElementAt(int i) {
return names[i];
}
});
pList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel listSelectionModel = pList.getSelectionModel();
listSelectionModel.addListSelectionListener(new pListSelectionListener());
pListPane.setViewportView(pList);
fileList.setFont(new java.awt.Font("Tahoma", 0, 9));
fileList.setModel(new javax.swing.AbstractListModel() {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = -4680206517439356803L;
String[] files = {};
public int getSize() {
return files.length;
}
public Object getElementAt(int i) {
return files[i];
}
});
fileScrlPane.setViewportView(fileList);
descriptionPane
.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
descriptionArea.setColumns(20);
descriptionArea.setEditable(false);
descriptionArea.setFont(new java.awt.Font("Verdana", 0, 10));
descriptionArea.setLineWrap(true);
descriptionArea.setRows(1);
descriptionArea.setTabSize(3);
descriptionArea.setText("");
descriptionArea.setWrapStyleWord(true);
descriptionPane.setViewportView(descriptionArea);
listLabel.setFont(new java.awt.Font("Verdana", 1, 12));
listLabel.setForeground(new java.awt.Color(51, 0, 102));
listLabel.setText("Plug-in List");
pluginInfoLbl.setFont(new java.awt.Font("Verdana", 1, 12));
pluginInfoLbl.setForeground(new java.awt.Color(51, 0, 102));
pluginInfoLbl.setText("Plug-in Information");
nameIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
nameIndicatorLbl.setText("Name");
nameLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
nameLabel.setText("");
authorIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
authorIndicatorLbl.setText("Author");
authorLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
authorLabel.setText("");
versionIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
versionIndicatorLbl.setText("Version (Schema Version)");
versionLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
versionLabel.setText("");
copyrightIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
copyrightIndicatorLbl.setText("Copyright");
copyrightLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
copyrightLabel.setText("");
descriptionIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
descriptionIndicatorLbl.setText("Description");
fileIndicatorLbl.setFont(new java.awt.Font("Tahoma", 1, 11));
fileIndicatorLbl.setText("Files");
javax.swing.GroupLayout contentPanelLayout = new javax.swing.GroupLayout(contentPanel);
contentPanel.setLayout(contentPanelLayout);
contentPanelLayout
.setHorizontalGroup(contentPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addContainerGap()
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(listLabel)
.addComponent(
pListPane,
javax.swing.GroupLayout.PREFERRED_SIZE,
126,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pluginInfoLbl)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGap(10, 10,
10)
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
nameIndicatorLbl)
.addComponent(
authorIndicatorLbl)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGap(
10,
10,
10)
.addComponent(
nameLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
116,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGap(
10,
10,
10)
.addComponent(
authorLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
105,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
18,
Short.MAX_VALUE)
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGap(
10,
10,
10)
.addComponent(
copyrightLabel))
.addComponent(
copyrightIndicatorLbl)
.addComponent(
versionIndicatorLbl)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGap(
10,
10,
10)
.addComponent(
versionLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
169,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(
descriptionIndicatorLbl)
.addComponent(
fileIndicatorLbl)
.addComponent(
fileScrlPane,
javax.swing.GroupLayout.DEFAULT_SIZE,
323,
Short.MAX_VALUE)
.addComponent(
descriptionPane,
javax.swing.GroupLayout.DEFAULT_SIZE,
323,
Short.MAX_VALUE))))
.addContainerGap()));
contentPanelLayout
.setVerticalGroup(contentPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addContainerGap()
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addComponent(
listLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
18,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
pListPane,
javax.swing.GroupLayout.DEFAULT_SIZE,
244,
Short.MAX_VALUE))
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addComponent(
pluginInfoLbl)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
nameIndicatorLbl)
.addGap(
3,
3,
3)
.addComponent(
nameLabel))
.addGroup(
contentPanelLayout
.createSequentialGroup()
.addComponent(
versionIndicatorLbl)
.addGap(
3,
3,
3)
.addComponent(
versionLabel)))
.addGap(10, 10,
10)
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
authorIndicatorLbl)
.addComponent(
copyrightIndicatorLbl))
.addGap(3, 3, 3)
.addGroup(
contentPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
authorLabel)
.addComponent(
copyrightLabel))
.addGap(10, 10,
10)
.addComponent(
descriptionIndicatorLbl)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
descriptionPane,
javax.swing.GroupLayout.PREFERRED_SIZE,
51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
fileIndicatorLbl)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
fileScrlPane,
javax.swing.GroupLayout.PREFERRED_SIZE,
67,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()));
jMenu1.setText("Menu");
menuBar.add(jMenu1);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(contentPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE));
layout.setVerticalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addComponent(contentPanel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
contentPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL,
new java.awt.Component[]{authorIndicatorLbl, authorLabel,
copyrightIndicatorLbl,
copyrightLabel, nameIndicatorLbl,
nameLabel, versionIndicatorLbl,
versionLabel});
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// new View().setVisible(true);
}
});
}
private javax.swing.JLabel authorIndicatorLbl;
private javax.swing.JLabel authorLabel;
private javax.swing.JPanel contentPanel;
private javax.swing.JLabel copyrightIndicatorLbl;
private javax.swing.JLabel copyrightLabel;
private javax.swing.JTextArea descriptionArea;
private javax.swing.JLabel descriptionIndicatorLbl;
private javax.swing.JScrollPane descriptionPane;
private javax.swing.JLabel fileIndicatorLbl;
private javax.swing.JList fileList;
private javax.swing.JScrollPane fileScrlPane;
private javax.swing.JMenu jMenu1;
private javax.swing.JLabel listLabel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JLabel nameIndicatorLbl;
private javax.swing.JLabel nameLabel;
private javax.swing.JList pList;
private javax.swing.JScrollPane pListPane;
private javax.swing.JLabel pluginInfoLbl;
private javax.swing.JLabel versionIndicatorLbl;
private javax.swing.JLabel versionLabel;
private class pListSelectionListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
if(!e.getValueIsAdjusting()) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
int minIndex = lsm.getMinSelectionIndex();
int maxIndex = lsm.getMaxSelectionIndex();
for(int i = minIndex; i <= maxIndex; i++) {
if(lsm.isSelectedIndex(i)) {
org.jdom.Element elem = (org.jdom.Element) xmlList.get(i);
String pluginName = elem.getAttributeValue("Name");
String authorName = elem.getAttributeValue("Author");
String pluginVersion = elem.getAttributeValue("PluginVersion");
String schemaVersion = elem.getAttributeValue("SchemaVersion");
String copyright = elem.getAttributeValue("Copyright");
String description = elem.getAttributeValue("Description");
List classFileList = elem.getChildren("Class");
nameLabel.setText(pluginName);
authorLabel.setText(authorName);
versionLabel.setText(pluginVersion + " (" + schemaVersion + ")");
copyrightLabel.setText(copyright);
descriptionArea.setText(description);
fileList.setListData(classFileList.toArray());
}
}
}
}
}
public void refreshMenu(Vector<Object> args) {
}
}