package com.laytonsmith.tools;
import com.laytonsmith.PureUtilities.Common.UIUtils;
import com.laytonsmith.tools.docgen.DocGenUI;
import com.laytonsmith.tools.pnviewer.PNViewer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
*/
public class UILauncher extends javax.swing.JFrame {
private List<UI> uis = new ArrayList<>();
private UI selectedUI = null;
/**
* Creates new form UILauncher
*/
public UILauncher() {
final String[] args = {};
uis.add(new UI("Persistence Network Viewer", "Allows easier visualization of the Persistence Network", new Runnable() {
@Override
public void run() {
PNViewer.main(args);
}
}));
uis.add(new UI("DocGen", "Allows uploading of the built-in documentation to MediaWiki software.", new Runnable() {
@Override
public void run() {
DocGenUI.main(args);
}
}));
initComponents();
setTitle("MethodScript UI Tool Launcher");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
launchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(selectedUI == null){
JOptionPane.showMessageDialog(UILauncher.this, "Please select a tool from the list on the left.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
selectedUI.getLauncher().run();
UILauncher.this.setVisible(false);
}
});
exitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
launcherList.setModel(new AbstractListModel() {
@Override
public int getSize() {
return uis.size();
}
@Override
public Object getElementAt(int index) {
return uis.get(index);
}
});
launcherList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
UI ui = uis.get(e.getFirstIndex());
descriptionTextArea.setText(ui.getTooltip());
selectedUI = ui;
}
});
launcherList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2){
launchButton.doClick();
}
}
});
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
launcherList = new javax.swing.JList();
launchButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
descriptionTextArea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
launcherList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(launcherList);
launchButton.setText("Launch");
exitButton.setText("Exit");
descriptionTextArea.setEditable(false);
descriptionTextArea.setColumns(20);
descriptionTextArea.setLineWrap(true);
descriptionTextArea.setRows(5);
descriptionTextArea.setWrapStyleWord(true);
descriptionTextArea.setEnabled(false);
jScrollPane2.setViewportView(descriptionTextArea);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(launchButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(exitButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
.addComponent(jScrollPane2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(launchButton)
.addComponent(exitButton))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(UILauncher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(UILauncher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(UILauncher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(UILauncher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
UILauncher ui = new UILauncher();
UIUtils.centerWindow(ui);
ui.setVisible(true);
}
});
}
private static class UI {
private final String name;
private final String tooltip;
private final Runnable launch;
public UI(String name, String tooltip, Runnable launch){
this.name = name;
this.tooltip = tooltip;
this.launch = launch;
}
public String getName(){
return name;
}
public String getTooltip(){
return tooltip;
}
public Runnable getLauncher(){
return launch;
}
@Override
public String toString() {
return name;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea descriptionTextArea;
private javax.swing.JButton exitButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton launchButton;
private javax.swing.JList launcherList;
// End of variables declaration//GEN-END:variables
}