/* -------------------------------------------------------------------------- */
/* */
/* ASP CODE DOCUMENTOR GUI CONTROL CLASS */
/* */
/* Frans Coenen */
/* */
/* Wednesday 17 October 2006 */
/* */
/* Department of Computer Science */
/* The University of Liverpool */
/* */
/* -------------------------------------------------------------------------- */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
/** GUI control softwarte for asp code documentor.
@author Frans Coenen
@version 12 October 2006 */
public class ASPdocControl extends JFrame implements ActionListener,
ItemListener {
/* ------ FIELDS ------ */
// CONSTANTS
// OBJECTS
/** Instance of ASPdoc class. */
private ASPdoc newASPdoc = null;
// GUI ITEMS
// Menues
/** Input menu. */
private JMenu inputMenu;
/** Output menu. */
private JMenu outputMenu;
/** Document menu. */
private JMenu documentMenu;
// Menu items
/** Input menu items. */
private JMenuItem[] inputMenuItems;
/** Output menu items. */
private JCheckBoxMenuItem[] outputMenuItems;
/** Dcocument menu items. */
private JMenuItem[] docMenuItems;
// Menu labels
/** Input menu labels. */
private String inputMenuLabels[] = {"Select Files","Add Files","Reset"};
/** Output menu labels. */
private String outputMenuLabels[] = {"Links","ASP Blocks",
"ASP Functions","Script Blocks","Script Functions"};
/** Document menu labels. */
private String docMenuLabels[] = {"Start","Exit"};
// OTHER COMPONENTS
/** Credits panel */
private JPanel creditsPanel;
/** Text Area. */
private JTextArea textArea;
// FLAGS
/** Output links flag. */
private boolean outputLinksFlag = true;
/** Output asp blocks flag. */
private boolean outputASPblocksFlag = true;
/** Output asp functions flag. */
private boolean outputASPfuncsFlag = true;
/** Output script blocks flag. */
private boolean outputScriptBlocksFlag = true;
/** Output script functions flag. */
private boolean outputScriptFuncsFlag = true;
// OTHER FIELDS
/** Input data file name list. */
private File[] inputFileNames;
/* --------------------------------------------------- */
/* */
/* CONSTRUCTORS */
/* */
/* --------------------------------------------------- */
/** One argument constructor to create the ASP code documentor GUI.
@param newNewASPdoc new isntance of ASPdoc class. */
public ASPdocControl(ASPdoc newNewASPdoc) {
super("ASP Code Documentoir GUI");
// Set fields
newASPdoc = newNewASPdoc;
// Content pane
getContentPane().setBackground(Color.pink);
getContentPane().setLayout(new BorderLayout(5,5)); // 5 pixel gaps
// Create menus
createInputMenu();
createOutputMenu();
createDocumentMenu();
// Create menu bar
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(inputMenu);
bar.add(outputMenu);
bar.add(documentMenu);
// Add text area
textArea = new JTextArea(40,40);
textArea.setEditable(false);
getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER);
// Credits Panel
createCreditsPanel();
getContentPane().add(creditsPanel,BorderLayout.SOUTH);
}
/** Creates input menu */
private void createInputMenu() {
// Create input menu
inputMenu = new JMenu("Input");
inputMenu.setMnemonic('I');
// Create input menu items
inputMenuItems = new JMenuItem[inputMenuLabels.length];
for (int index=0;index0) inputMenu.addSeparator();
inputMenu.add(inputMenuItems[index]);
}
}
/** Creates output sub-menu comprising check boxes. */
private void createOutputMenu() {
// Create file menu
outputMenu = new JMenu("Output");
outputMenu.setMnemonic('O');
// Create buttons
outputMenuItems = new JCheckBoxMenuItem[outputMenuLabels.length];
for (int index=0;index0) documentMenu.addSeparator();
documentMenu.add(docMenuItems[index]);
}
}
/* --------------------------------- */
/* */
/* CREATE CREDITS PANELS */
/* */
/* --------------------------------- */
/** Creates credits panel. */
private void createCreditsPanel() {
// Swet up panel
creditsPanel = new JPanel();
creditsPanel.setBackground(Color.pink);
creditsPanel.setLayout(new GridLayout(4,1));
// Create labels
Label creditLabel1 = new Label("ASP code documentor created as part of " +
"Transglobal KTP ptoject between Transglobal ");
Label creditLabel2 = new Label("Express Ltd. and the Department of " +
"Computer Science at The University of Liverpool");
Label creditLabel3 = new Label(" ");
Label creditLabel4 = new Label("Frans Coenen (17 October 2007)");
// Add labels
creditsPanel.add(creditLabel1);
creditsPanel.add(creditLabel2);
creditsPanel.add(creditLabel3);
creditsPanel.add(creditLabel4);
}
/* -------------------- */
/* */
/* HANDLERS */
/* */
/* -------------------- */
/** Action performed handler.
@param event the triggered event. */
public void actionPerformed(ActionEvent event) {
// Input menu item Select Files
if (event.getActionCommand().equals("Select Files")) {
textArea.append("GET INPUT FILE NAMES:\n");
getInputFileNames();
textArea.append("-------------------------------------\n");
}
// Input menu item Add Files
else if (event.getActionCommand().equals("Add Files")) {
textArea.append("ADD TO LIST OF INPUT FILE NAMES:\n");
addtoInputFileNames();
textArea.append("-------------------------------------\n");
}
// Input menu item Add Files
else if (event.getActionCommand().equals("Reset")) {
textArea.append("RESET FIELDS TO START VALUES:\n");
reset();
textArea.append("Done\n-------------------------------------\n");
}
// Document menu item Start
else if (event.getActionCommand().equals("Start")) {
textArea.append("RUN DOCUMENTOR:\n");
runDocumentor();
textArea.append("-------------------------------------\n");
}
// Document menu item Exit
else if (event.getActionCommand().equals("Exit")) {
System.exit(0);
}
}
/** Item state change handler.
@param event the triggered event. */
public void itemStateChanged(ItemEvent event) {
// Output links
if (outputMenuItems[0].isSelected()) {
if (!outputLinksFlag) {
textArea.append("Output links\n");
outputLinksFlag = true;
textArea.append("-------------------------------------\n");
}
}
else outputLinksFlag = false;
// Output ASP blocks
if (outputMenuItems[1].isSelected()) {
if (!outputASPblocksFlag) {
textArea.append("Output ASP blocks\n");
outputASPblocksFlag = true;
textArea.append("-------------------------------------\n");
}
}
else outputASPblocksFlag = false;
// Output ASP functions
if (outputMenuItems[2].isSelected()) {
if (!outputASPfuncsFlag) {
textArea.append("Output ASP functions\n");
outputASPfuncsFlag = true;
textArea.append("-------------------------------------\n");
}
}
else outputASPfuncsFlag = false;
// Output script blocks
if (outputMenuItems[3].isSelected()) {
if (!outputScriptBlocksFlag) {
textArea.append("Output script blocks\n");
outputScriptBlocksFlag = true;
textArea.append("-------------------------------------\n");
}
}
else outputScriptBlocksFlag = false;
// Output Script functions
if (outputMenuItems[4].isSelected()) {
if (!outputScriptFuncsFlag) {
textArea.append("Output scfript functions\n");
outputScriptFuncsFlag = true;
textArea.append("-------------------------------------\n");
}
}
else outputScriptFuncsFlag = false;
}
/* ---------------------------- */
/* */
/* INOPUT FILE NAMES */
/* */
/* ---------------------------- */
/** Get list of file names to be documented. */
private void getInputFileNames() {
// Display file dialog so user can select file to open
JFileChooser fileChooser = new JFileChooser();
// Enable files only and multiple selection
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(true);
// Show the dialog
int result = fileChooser.showOpenDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) {
textArea.append("Operation cancelled\n");
return;
}
// Otherwise retrieve the selected files.
inputFileNames = fileChooser.getSelectedFiles();
// List to text area
for (int i=0;i