Example usage for javax.swing ButtonGroup ButtonGroup

List of usage examples for javax.swing ButtonGroup ButtonGroup

Introduction

In this page you can find the example usage for javax.swing ButtonGroup ButtonGroup.

Prototype

public ButtonGroup() 

Source Link

Document

Creates a new ButtonGroup.

Usage

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void makeDefaultXsdMenuItems() {
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem jRadioButtonMenuItem;
    for (Xsd_enum xsdEnum : Xsd_enum.values()) {
        jRadioButtonMenuItem = new JRadioButtonMenuItem(xsdEnum.getReadableName());
        if (xsdEnum.getReadableName().equals(retrieveFromDb.retrieveDefaultXsd())) {
            jRadioButtonMenuItem.setSelected(true);
        }/*from   w  w  w . j  av a  2s.co m*/
        jRadioButtonMenuItem.addActionListener(new XsdSelectActionListener());
        group.add(jRadioButtonMenuItem);
        defaultXsdSelectionSubmenu.add(jRadioButtonMenuItem);
    }
    for (XsdObject additionalXsd : retrieveFromDb.retrieveAdditionalXsds()) {
        jRadioButtonMenuItem = new JRadioButtonMenuItem(additionalXsd.getName());
        if (additionalXsd.getName().equals(retrieveFromDb.retrieveDefaultXsd())) {
            jRadioButtonMenuItem.setSelected(true);
        }
        jRadioButtonMenuItem.addActionListener(new XsdSelectActionListener());
        group.add(jRadioButtonMenuItem);
        defaultXsdSelectionSubmenu.add(jRadioButtonMenuItem);
    }
}

From source file:ffx.ui.ModelingPanel.java

private void loadCommand() {
    synchronized (this) {
        // Force Field X Command
        Element command;/* w w  w .  j  av  a 2  s. c  om*/
        // Command Options
        NodeList options;
        Element option;
        // Option Values
        NodeList values;
        Element value;
        // Options may be Conditional based on previous Option values (not
        // always supplied)
        NodeList conditionalList;
        Element conditional;
        // JobPanel GUI Components that change based on command
        JPanel optionPanel;
        // Clear the previous components
        commandPanel.removeAll();
        optionsTabbedPane.removeAll();
        conditionals.clear();
        String currentCommand = (String) currentCommandBox.getSelectedItem();
        if (currentCommand == null) {
            commandPanel.validate();
            commandPanel.repaint();
            return;
        }
        command = null;
        for (int i = 0; i < commandList.getLength(); i++) {
            command = (Element) commandList.item(i);
            String name = command.getAttribute("name");
            if (name.equalsIgnoreCase(currentCommand)) {
                break;
            }
        }
        int div = splitPane.getDividerLocation();
        descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description"));
        splitPane.setBottomComponent(descriptScrollPane);
        splitPane.setDividerLocation(div);
        // The "action" tells Force Field X what to do when the
        // command finishes
        commandActions = command.getAttribute("action").trim();
        // The "fileType" specifies what file types this command can execute
        // on
        String string = command.getAttribute("fileType").trim();
        String[] types = string.split(" +");
        commandFileTypes.clear();
        for (String type : types) {
            if (type.contains("XYZ")) {
                commandFileTypes.add(FileType.XYZ);
            }
            if (type.contains("INT")) {
                commandFileTypes.add(FileType.INT);
            }
            if (type.contains("ARC")) {
                commandFileTypes.add(FileType.ARC);
            }
            if (type.contains("PDB")) {
                commandFileTypes.add(FileType.PDB);
            }
            if (type.contains("ANY")) {
                commandFileTypes.add(FileType.ANY);
            }
        }
        // Determine what options are available for this command
        options = command.getElementsByTagName("Option");
        int length = options.getLength();
        for (int i = 0; i < length; i++) {
            // This Option will be enabled (isEnabled = true) unless a
            // Conditional disables it
            boolean isEnabled = true;
            option = (Element) options.item(i);
            conditionalList = option.getElementsByTagName("Conditional");
            /*
             * Currently, there can only be 0 or 1 Conditionals per Option
             * There are three types of Conditionals implemented. 1.)
             * Conditional on a previous Option, this option may be
             * available 2.) Conditional on input for this option, a
             * sub-option may be available 3.) Conditional on the presence
             * of keywords, this option may be available
             */
            if (conditionalList != null) {
                conditional = (Element) conditionalList.item(0);
            } else {
                conditional = null;
            }
            // Get the command line flag
            String flag = option.getAttribute("flag").trim();
            // Get the description
            String optionDescript = option.getAttribute("description");
            JTextArea optionTextArea = new JTextArea("  " + optionDescript.trim());
            optionTextArea.setEditable(false);
            optionTextArea.setLineWrap(true);
            optionTextArea.setWrapStyleWord(true);
            optionTextArea.setBorder(etchedBorder);
            // Get the default for this Option (if one exists)
            String defaultOption = option.getAttribute("default");
            // Option Panel
            optionPanel = new JPanel(new BorderLayout());
            optionPanel.add(optionTextArea, BorderLayout.NORTH);
            String swing = option.getAttribute("gui");
            JPanel optionValuesPanel = new JPanel(new FlowLayout());
            optionValuesPanel.setBorder(etchedBorder);
            ButtonGroup bg = null;
            if (swing.equalsIgnoreCase("CHECKBOXES")) {
                // CHECKBOXES allows selection of 1 or more values from a
                // predefined set (Analyze, for example)
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JCheckBox jcb = new JCheckBox(value.getAttribute("name"));
                    jcb.addMouseListener(this);
                    jcb.setName(flag);
                    if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jcb.setSelected(true);
                    }
                    optionValuesPanel.add(jcb);
                }
            } else if (swing.equalsIgnoreCase("TEXTFIELD")) {
                // TEXTFIELD takes an arbitrary String as input
                JTextField jtf = new JTextField(20);
                jtf.addMouseListener(this);
                jtf.setName(flag);
                if (defaultOption != null && defaultOption.equals("ATOMS")) {
                    FFXSystem sys = mainPanel.getHierarchy().getActive();
                    if (sys != null) {
                        jtf.setText("" + sys.getAtomList().size());
                    }
                } else if (defaultOption != null) {
                    jtf.setText(defaultOption);
                }
                optionValuesPanel.add(jtf);
            } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) {
                // RADIOBUTTONS allows one choice from a set of predifined
                // values
                bg = new ButtonGroup();
                values = option.getElementsByTagName("Value");
                for (int j = 0; j < values.getLength(); j++) {
                    value = (Element) values.item(j);
                    JRadioButton jrb = new JRadioButton(value.getAttribute("name"));
                    jrb.addMouseListener(this);
                    jrb.setName(flag);
                    bg.add(jrb);
                    if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) {
                        jrb.setSelected(true);
                    }
                    optionValuesPanel.add(jrb);
                }
            } else if (swing.equalsIgnoreCase("PROTEIN")) {
                // Protein allows selection of amino acids for the protein
                // builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getAminoAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("PROTEIN");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("PROTEIN");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton reset = new JButton("Reset");
                reset.setActionCommand("PROTEIN");
                reset.addActionListener(this);
                reset.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(reset);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("NUCLEIC")) {
                // Nucleic allows selection of nucleic acids for the nucleic
                // acid builder
                optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS));
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(getNucleicAcidPanel());
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidComboBox.removeAllItems();
                JButton add = new JButton("Edit");
                add.setActionCommand("NUCLEIC");
                add.addActionListener(this);
                add.setAlignmentX(Button.CENTER_ALIGNMENT);
                JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidTextField);
                comboPanel.add(add);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton remove = new JButton("Remove");
                add.setMinimumSize(remove.getPreferredSize());
                add.setPreferredSize(remove.getPreferredSize());
                remove.setActionCommand("NUCLEIC");
                remove.addActionListener(this);
                remove.setAlignmentX(Button.CENTER_ALIGNMENT);
                comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
                comboPanel.add(acidComboBox);
                comboPanel.add(remove);
                optionValuesPanel.add(comboPanel);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                optionValuesPanel.add(acidScrollPane);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                JButton button = new JButton("Reset");
                button.setActionCommand("NUCLEIC");
                button.addActionListener(this);
                button.setAlignmentX(Button.CENTER_ALIGNMENT);
                optionValuesPanel.add(button);
                optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
                acidTextArea.setText("");
                acidTextField.setText("");
            } else if (swing.equalsIgnoreCase("SYSTEMS")) {
                // SYSTEMS allows selection of an open system
                JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems());
                jcb.setSize(jcb.getMaximumSize());
                jcb.addActionListener(this);
                optionValuesPanel.add(jcb);
            }
            // Set up a Conditional for this Option
            if (conditional != null) {
                isEnabled = false;
                String conditionalName = conditional.getAttribute("name");
                String conditionalValues = conditional.getAttribute("value");
                String cDescription = conditional.getAttribute("description");
                String cpostProcess = conditional.getAttribute("postProcess");
                if (conditionalName.toUpperCase().startsWith("KEYWORD")) {
                    optionPanel.setName(conditionalName);
                    String keywords[] = conditionalValues.split(" +");
                    if (activeSystem != null) {
                        Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords();
                        for (String key : keywords) {
                            if (systemKeywords.containsKey(key.toUpperCase())) {
                                isEnabled = true;
                            }
                        }
                    }
                } else if (conditionalName.toUpperCase().startsWith("VALUE")) {
                    isEnabled = true;
                    // Add listeners to the values of this option so
                    // the conditional options can be disabled/enabled.
                    for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) {
                        JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j);
                        jtb.addActionListener(this);
                        jtb.setActionCommand("Conditional");
                    }
                    JPanel condpanel = new JPanel();
                    condpanel.setBorder(etchedBorder);
                    JLabel condlabel = new JLabel(cDescription);
                    condlabel.setEnabled(false);
                    condlabel.setName(conditionalValues);
                    JTextField condtext = new JTextField(10);
                    condlabel.setLabelFor(condtext);
                    if (cpostProcess != null) {
                        condtext.setName(cpostProcess);
                    }
                    condtext.setEnabled(false);
                    condpanel.add(condlabel);
                    condpanel.add(condtext);
                    conditionals.add(condlabel);
                    optionPanel.add(condpanel, BorderLayout.SOUTH);
                } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) {
                    String[] condModifiers;
                    if (conditionalValues.equalsIgnoreCase("AltLoc")) {
                        condModifiers = activeSystem.getAltLocations();
                        if (condModifiers != null && condModifiers.length > 1) {
                            isEnabled = true;
                            bg = new ButtonGroup();
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi);
                                if (j == 0) {
                                    jrbmi.setSelected(true);
                                }
                            }
                        }
                    } else if (conditionalValues.equalsIgnoreCase("Chains")) {
                        condModifiers = activeSystem.getChainNames();
                        if (condModifiers != null && condModifiers.length > 0) {
                            isEnabled = true;
                            for (int j = 0; j < condModifiers.length; j++) {
                                JRadioButton jrbmi = new JRadioButton(condModifiers[j]);
                                jrbmi.addMouseListener(this);
                                bg.add(jrbmi);
                                optionValuesPanel.add(jrbmi, j);
                            }
                        }
                    }
                }
            }
            optionPanel.add(optionValuesPanel, BorderLayout.CENTER);
            optionPanel.setPreferredSize(optionPanel.getPreferredSize());
            optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel);
            optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled);
        }
    }
    optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize());
    commandPanel.setLayout(borderLayout);
    commandPanel.add(optionsTabbedPane, BorderLayout.CENTER);
    commandPanel.validate();
    commandPanel.repaint();
    loadLogSettings();
    statusLabel.setText("  " + createCommandInput());
}

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void makeDefaultXslMenuItems() {
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem jRadioButtonMenuItem;
    for (File xsltFile : Utilities.getXsltFiles()) {
        jRadioButtonMenuItem = new JRadioButtonMenuItem(xsltFile.getName());
        if (xsltFile.getName().equals(retrieveFromDb.retrieveDefaultXsl())) {
            jRadioButtonMenuItem.setSelected(true);
        }// www  . ja  v  a 2s  .  c om
        jRadioButtonMenuItem.addActionListener(new XslSelectActionListener());
        group.add(jRadioButtonMenuItem);
        defaultXslSelectionSubmenu.add(jRadioButtonMenuItem);
    }
}

From source file:net.sf.jabref.gui.JabRefFrame.java

private void fillMenu() {
    mb.setBorder(null);/*from w w  w  .j a va2 s. com*/
    JMenu file = JabRefFrame.subMenu(Localization.menuTitle("File"));
    JMenu edit = JabRefFrame.subMenu(Localization.menuTitle("Edit"));
    JMenu search = JabRefFrame.subMenu(Localization.menuTitle("Search"));
    JMenu groups = JabRefFrame.subMenu(Localization.menuTitle("Groups"));
    JMenu bibtex = JabRefFrame.subMenu("&BibTeX");
    JMenu quality = JabRefFrame.subMenu(Localization.menuTitle("Quality"));
    JMenu view = JabRefFrame.subMenu(Localization.menuTitle("View"));
    JMenu tools = JabRefFrame.subMenu(Localization.menuTitle("Tools"));
    JMenu options = JabRefFrame.subMenu(Localization.menuTitle("Options"));
    JMenu newSpec = JabRefFrame.subMenu(Localization.menuTitle("New entry by type..."));
    JMenu helpMenu = JabRefFrame.subMenu(Localization.menuTitle("Help"));

    file.add(newBibtexDatabaseAction);
    file.add(newBiblatexDatabaseAction);
    file.add(getOpenDatabaseAction());
    file.add(mergeDatabaseAction);
    file.add(save);
    file.add(saveAs);
    file.add(saveAll);
    file.add(saveSelectedAs);
    file.add(saveSelectedAsPlain);
    file.addSeparator();
    file.add(importNew);
    file.add(importCurrent);
    file.add(exportAll);
    file.add(exportSelected);
    file.addSeparator();
    file.add(dbConnect);
    file.add(dbImport);
    file.add(dbExport);

    file.addSeparator();
    file.add(databaseProperties);
    file.add(editModeAction);
    file.addSeparator();

    file.add(fileHistory);
    file.addSeparator();
    file.add(closeDatabaseAction);
    file.add(quit);
    mb.add(file);

    edit.add(undo);
    edit.add(redo);

    edit.addSeparator();

    edit.add(cut);
    edit.add(copy);
    edit.add(paste);

    edit.addSeparator();

    edit.add(copyKey);
    edit.add(copyCiteKey);
    edit.add(copyKeyAndTitle);
    edit.add(exportToClipboard);
    edit.add(sendAsEmail);

    edit.addSeparator();
    edit.add(mark);
    JMenu markSpecific = JabRefFrame.subMenu(Localization.menuTitle("Mark specific color"));
    for (int i = 0; i < EntryMarker.MAX_MARKING_LEVEL; i++) {
        markSpecific.add(new MarkEntriesAction(this, i).getMenuItem());
    }
    edit.add(markSpecific);
    edit.add(unmark);
    edit.add(unmarkAll);
    edit.addSeparator();
    if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) {
        JMenu m;
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) {
            m = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(m, Rank.getInstance(), this);
            edit.add(m);
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) {
            edit.add(toggleRelevance);
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) {
            edit.add(toggleQualityAssured);
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) {
            m = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(m, Priority.getInstance(), this);
            edit.add(m);
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) {
            edit.add(togglePrinted);
        }
        if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) {
            m = new JMenu();
            RightClickMenu.populateSpecialFieldMenu(m, ReadStatus.getInstance(), this);
            edit.add(m);
        }
        edit.addSeparator();
    }

    edit.add(getManageKeywords());
    edit.add(getMassSetField());
    edit.addSeparator();
    edit.add(selectAll);
    mb.add(edit);

    search.add(normalSearch);
    search.add(replaceAll);
    search.addSeparator();
    search.add(new JCheckBoxMenuItem(generalFetcher.getAction()));
    if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) {
        sidePaneManager.register(generalFetcher.getTitle(), generalFetcher);
        sidePaneManager.show(generalFetcher.getTitle());
    }
    mb.add(search);

    groups.add(new JCheckBoxMenuItem(toggleGroups));
    groups.addSeparator();
    groups.add(addToGroup);
    groups.add(removeFromGroup);
    groups.add(moveToGroup);
    groups.addSeparator();
    JRadioButtonMenuItem toggleHighlightAnyItem = new JRadioButtonMenuItem(toggleHighlightAny);
    groups.add(toggleHighlightAnyItem);
    JRadioButtonMenuItem toggleHighlightAllItem = new JRadioButtonMenuItem(toggleHighlightAll);
    groups.add(toggleHighlightAllItem);
    JRadioButtonMenuItem toggleHighlightDisableItem = new JRadioButtonMenuItem(toggleHighlightDisable);
    groups.add(toggleHighlightDisableItem);
    ButtonGroup highlightButtonGroup = new ButtonGroup();
    highlightButtonGroup.add(toggleHighlightDisableItem);
    highlightButtonGroup.add(toggleHighlightAnyItem);
    highlightButtonGroup.add(toggleHighlightAllItem);

    HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences(
            Globals.prefs);
    if (highlightMatchingGroupPreferences.isAll()) {
        toggleHighlightAllItem.setSelected(true);
    } else if (highlightMatchingGroupPreferences.isAny()) {
        toggleHighlightAnyItem.setSelected(true);
    } else {
        toggleHighlightDisableItem.setSelected(true);
    }

    mb.add(groups);

    view.add(getBackAction());
    view.add(getForwardAction());
    view.add(focusTable);
    view.add(nextTab);
    view.add(prevTab);
    view.add(sortTabs);
    view.addSeparator();
    view.add(increaseFontSize);
    view.add(decreseFontSize);
    view.addSeparator();
    view.add(new JCheckBoxMenuItem(toggleToolbar));
    view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getAction())));
    view.add(new JCheckBoxMenuItem(toggleGroups));
    view.add(new JCheckBoxMenuItem(togglePreview));
    view.add(getSwitchPreviewAction());

    mb.add(view);

    bibtex.add(newEntryAction);

    for (NewEntryAction a : newSpecificEntryAction) {
        newSpec.add(a);
    }
    bibtex.add(newSpec);

    bibtex.add(plainTextImport);
    bibtex.addSeparator();
    bibtex.add(editEntry);
    bibtex.add(editPreamble);
    bibtex.add(editStrings);
    bibtex.addSeparator();
    bibtex.add(customizeAction);
    bibtex.addSeparator();
    bibtex.add(deleteEntry);
    mb.add(bibtex);

    quality.add(dupliCheck);
    quality.add(mergeEntries);
    quality.addSeparator();
    quality.add(resolveDuplicateKeys);
    quality.add(checkIntegrity);
    quality.add(cleanupEntries);
    quality.add(makeKeyAction);
    quality.addSeparator();
    quality.add(autoSetFile);
    quality.add(findUnlinkedFiles);
    quality.add(autoLinkFile);
    quality.add(downloadFullText);
    mb.add(quality);

    tools.add(newSubDatabaseAction);
    tools.add(writeXmpAction);
    OpenOfficePanel otp = OpenOfficePanel.getInstance();
    otp.init(this, sidePaneManager);
    tools.add(otp.getMenuItem());
    tools.add(pushExternalButton.getMenuAction());
    tools.addSeparator();
    tools.add(openFolder);
    tools.add(openFile);
    tools.add(openUrl);
    tools.add(openConsole);
    tools.addSeparator();
    tools.add(abbreviateIso);
    tools.add(abbreviateMedline);
    tools.add(unabbreviate);
    mb.add(tools);

    options.add(showPrefs);

    AbstractAction genFieldsCustomization = new GenFieldsCustomizationAction();
    options.add(genFieldsCustomization);
    options.add(customExpAction);
    options.add(customImpAction);
    options.add(customFileTypesAction);
    options.add(manageJournals);
    options.add(manageSelectors);
    options.add(selectKeys);
    mb.add(options);

    helpMenu.add(help);
    helpMenu.add(openForumAction);
    helpMenu.addSeparator();
    helpMenu.add(errorConsole);
    helpMenu.addSeparator();
    helpMenu.add(forkMeOnGitHubAction);
    helpMenu.add(donationAction);
    helpMenu.addSeparator();
    helpMenu.add(new SearchForUpdateAction());
    helpMenu.add(about);
    mb.add(helpMenu);

    createDisabledIconsForMenuEntries(mb);
}

From source file:edu.ucla.stat.SOCR.chart.Chart.java

public void initMapPanel() {
    listIndex = new int[dataTable.getColumnCount()];
    for (int j = 0; j < listIndex.length; j++)
        listIndex[j] = 1;/*from w  ww  . jav  a  2s . c  o  m*/
    bPanel = new JPanel(new BorderLayout());
    // topPanel = new JPanel(new FlowLayout());
    //bottomPanel = new JPanel(new FlowLayout());
    mapPanel = new JPanel(new GridLayout(2, 3, 50, 50));
    //  bPanel.add(new JPanel(),BorderLayout.EAST);
    //   bPanel.add(new JPanel(),BorderLayout.WEST);
    //   bPanel.add(new JPanel(),BorderLayout.SOUTH);
    bPanel.add(mapPanel, BorderLayout.CENTER);
    //   bPanel.add(new JPanel(),BorderLayout.NORTH);

    addButton1.addActionListener(this);
    addButton2.addActionListener(this);
    removeButton1.addActionListener(this);
    removeButton2.addActionListener(this);

    lModelAdded = new DefaultListModel();
    lModelDep = new DefaultListModel();
    lModelIndep = new DefaultListModel();

    //JLabel depLabel = new JLabel(DEPENDENT);
    //JLabel indLabel = new JLabel(INDEPENDENT);        
    //JLabel varLabel = new JLabel(VARIABLE);

    int cellWidth = 10;

    listAdded = new JList(lModelAdded);
    listAdded.setSelectedIndex(0);
    listDepRemoved = new JList(lModelDep);
    listIndepRemoved = new JList(lModelIndep);

    paintMappingLists(listIndex);
    listAdded.setFixedCellWidth(cellWidth);
    listDepRemoved.setFixedCellWidth(cellWidth);
    listIndepRemoved.setFixedCellWidth(cellWidth);

    tools1 = new JToolBar(JToolBar.VERTICAL);
    tools2 = new JToolBar(JToolBar.VERTICAL);

    if (mapDep) {
        tools1.add(depLabel);
        tools1.add(addButton1);
        tools1.add(removeButton1);
    }
    if (mapIndep) {
        tools2.add(indLabel);
        tools2.add(addButton2);
        tools2.add(removeButton2);
    }
    tools1.setFloatable(false);
    tools2.setFloatable(false);

    /*  topPanel.add(listAdded);
    topPanel.add(addButton);
    topPanel.add(listDepRemoved);
    bottomPanel.add(listIndepRemoved);
    bottomPanel.add(addButton2);
    bottomPanel.add(list4); */

    JRadioButton legendPanelOnSwitch;
    JRadioButton legendPanelOffSwitch;
    //
    JPanel choicesPanel = new JPanel();
    choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
    legendPanelOnSwitch = new JRadioButton("On");
    legendPanelOnSwitch.addActionListener(this);
    legendPanelOnSwitch.setActionCommand(LEGENDON);
    legendPanelOnSwitch.setSelected(false);
    legendPanelOn = false;

    legendPanelOffSwitch = new JRadioButton("Off");
    legendPanelOffSwitch.addActionListener(this);
    legendPanelOffSwitch.setActionCommand(LEGENDOFF);
    legendPanelOffSwitch.setSelected(true);

    ButtonGroup group = new ButtonGroup();
    group.add(legendPanelOnSwitch);
    group.add(legendPanelOffSwitch);
    choicesPanel.add(new JLabel("Turn the legend panel:"));
    choicesPanel.add(legendPanelOnSwitch);
    choicesPanel.add(legendPanelOffSwitch);
    choicesPanel.setPreferredSize(new Dimension(200, 100));

    mapPanel.add(new JScrollPane(listAdded));
    JPanel emptyPanel = new JPanel();
    JPanel emptyPanel2 = new JPanel();
    JPanel emptyPanel3 = new JPanel();

    if (mapDep) {
        mapPanel.add(tools1);
        mapPanel.add(new JScrollPane(listDepRemoved));
        if (LEGEND_SWITCH)
            mapPanel.add(choicesPanel);
        else
            mapPanel.add(emptyPanel);

        if (mapIndep) {
            mapPanel.add(tools2);
            mapPanel.add(new JScrollPane(listIndepRemoved));
        } else {
            mapPanel.add(emptyPanel2);
            mapPanel.add(emptyPanel3);
        }
    } else {
        mapPanel.add(emptyPanel);
        mapPanel.add(emptyPanel2);

        if (LEGEND_SWITCH)
            mapPanel.add(emptyPanel3);
        else
            mapPanel.add(choicesPanel);
        if (mapIndep) {
            mapPanel.add(tools2);
            mapPanel.add(new JScrollPane(listIndepRemoved));
        }
    }

}

From source file:com.marginallyclever.makelangelo.MainGUI.java

public void updateMenuBar() {
    JMenu menu, subMenu;/*from   w w w . ja va2 s . c o  m*/
    ButtonGroup group;
    int i;

    if (settingsPane != null) {
        buttonAdjustMachineSize.setEnabled(!isrunning);
        buttonAdjustPulleySize.setEnabled(!isrunning);
        buttonJogMotors
                .setEnabled(connectionToRobot != null && connectionToRobot.isRobotConfirmed() && !isrunning);
        buttonChangeTool.setEnabled(!isrunning);
        buttonAdjustTool.setEnabled(!isrunning);
    }
    if (preparePane != null) {
        buttonHilbertCurve.setEnabled(!isrunning);
        buttonText2GCODE.setEnabled(!isrunning);
    }
    if (driveControls != null) {
        boolean x = connectionToRobot != null && connectionToRobot.isRobotConfirmed();
        driveControls.updateButtonAccess(x, isrunning);
    }

    menuBar.removeAll();

    // File menu
    menu = new JMenu(translator.get("MenuMakelangelo"));
    menu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(menu);

    subMenu = new JMenu(translator.get("MenuPreferences"));

    buttonAdjustSounds = new JMenuItem(translator.get("MenuSoundsTitle"));
    buttonAdjustSounds.addActionListener(this);
    subMenu.add(buttonAdjustSounds);

    buttonAdjustGraphics = new JMenuItem(translator.get("MenuGraphicsTitle"));
    buttonAdjustGraphics.addActionListener(this);
    subMenu.add(buttonAdjustGraphics);

    buttonAdjustLanguage = new JMenuItem(translator.get("MenuLanguageTitle"));
    buttonAdjustLanguage.addActionListener(this);
    subMenu.add(buttonAdjustLanguage);
    menu.add(subMenu);

    buttonCheckForUpdate = new JMenuItem(translator.get("MenuUpdate"), KeyEvent.VK_U);
    buttonCheckForUpdate.addActionListener(this);
    buttonCheckForUpdate.setEnabled(true);
    menu.add(buttonCheckForUpdate);

    buttonAbout = new JMenuItem(translator.get("MenuAbout"), KeyEvent.VK_A);
    buttonAbout.addActionListener(this);
    menu.add(buttonAbout);

    menu.addSeparator();

    buttonExit = new JMenuItem(translator.get("MenuQuit"), KeyEvent.VK_Q);
    buttonExit.addActionListener(this);
    menu.add(buttonExit);

    // Connect menu
    subMenu = new JMenu(translator.get("MenuConnect"));
    subMenu.setEnabled(!isrunning);
    group = new ButtonGroup();

    String[] connections = connectionManager.listConnections();
    buttonPorts = new JRadioButtonMenuItem[connections.length];
    for (i = 0; i < connections.length; ++i) {
        buttonPorts[i] = new JRadioButtonMenuItem(connections[i]);
        if (connectionToRobot != null && connectionToRobot.getRecentConnection().equals(connections[i])
                && connectionToRobot.isConnectionOpen()) {
            buttonPorts[i].setSelected(true);
        }
        buttonPorts[i].addActionListener(this);
        group.add(buttonPorts[i]);
        subMenu.add(buttonPorts[i]);
    }

    subMenu.addSeparator();

    buttonRescan = new JMenuItem(translator.get("MenuRescan"), KeyEvent.VK_N);
    buttonRescan.addActionListener(this);
    subMenu.add(buttonRescan);

    buttonDisconnect = new JMenuItem(translator.get("MenuDisconnect"), KeyEvent.VK_D);
    buttonDisconnect.addActionListener(this);
    buttonDisconnect.setEnabled(connectionToRobot != null && connectionToRobot.isConnectionOpen());
    subMenu.add(buttonDisconnect);

    menuBar.add(subMenu);

    // view menu
    menu = new JMenu(translator.get("MenuPreview"));
    buttonZoomOut = new JMenuItem(translator.get("ZoomOut"));
    buttonZoomOut.addActionListener(this);
    buttonZoomOut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ActionEvent.ALT_MASK));
    menu.add(buttonZoomOut);

    buttonZoomIn = new JMenuItem(translator.get("ZoomIn"), KeyEvent.VK_EQUALS);
    buttonZoomIn.addActionListener(this);
    buttonZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.ALT_MASK));
    menu.add(buttonZoomIn);

    buttonZoomToFit = new JMenuItem(translator.get("ZoomFit"));
    buttonZoomToFit.addActionListener(this);
    menu.add(buttonZoomToFit);

    menuBar.add(menu);

    // finish
    menuBar.updateUI();
}

From source file:display.ANNFileFilter.java

License:asdf

Yanng() {
    JPanel toolBars;//  w  w  w  . j  a  va2s .  c  om
    JMenuBar menuBar;
    JToolBar utilBar, fileBar;
    JButton toJava, runner, trainer, modify, getTraininger, inputer, newwer, saver, saveAser, loader, helper;
    JMenu file;
    final JMenu util;
    JMenu help;

    ImageIcon IJava, IRun, ITrain, IModify, INew, ISave, ILoad, IGetTrainingSet, IGetInput, ISaveAs;

    //initialize main window
    mainWindow = new JFrame("YANNG - Yet Another Neural Network (simulator) Generator");
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWindow.setLayout(new BorderLayout());
    mainWindow.setSize(675, 525);
    mainWindow.setIconImage(new ImageIcon(ClassLoader.getSystemResource("display/icons/logo.png")).getImage());
    loadingImage = new ImageIcon(ClassLoader.getSystemResource("display/icons/loading.gif"));

    path = new Vector<String>();
    net = new Vector<NeuralNetwork>();
    oneNet = new Vector<JPanel>();
    tabPanel = new Vector<JPanel>();
    readOut = new Vector<JTextArea>();
    readOutLocale = new Vector<JScrollPane>();
    loadingBar = new Vector<JLabel>();
    title = new Vector<JLabel>();
    close = new Vector<JButton>();
    netName = new Vector<StringBuffer>();
    netKind = new Vector<StringBuffer>();

    resultsPane = new JTabbedPane();

    mainWindow.add(resultsPane);

    toolBars = new JPanel();
    toolBars.setLayout(new FlowLayout(FlowLayout.LEFT));

    //create utilities toolbar with 3 buttons
    utilBar = new JToolBar("Utilities");
    IRun = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/running.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    ITrain = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/training.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    IModify = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/modifyNet.png"))
            .getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    IGetTrainingSet = new ImageIcon(
            new ImageIcon(ClassLoader.getSystemResource("display/icons/trainingSet.png")).getImage()
                    .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    IGetInput = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/input.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    //set the icons/tooltips for the utilitiy bar    
    runner = new JButton(IRun);
    runner.setToolTipText(
            "<html>Run  the  Current  Neural   Network<br>Once Through with the Current Input</html>");

    trainer = new JButton(ITrain);
    trainer.setToolTipText(
            "<html>Train the Network with the Current<br>Configuration  and  Training  Set</html>");

    modify = new JButton(IModify);
    modify.setToolTipText("<html>Modify the Network<br>for Fun and Profit</html>");

    getTraininger = new JButton(IGetTrainingSet);
    getTraininger.setToolTipText("Get Training Set from File");

    inputer = new JButton(IGetInput);
    inputer.setToolTipText("Get Input Set from File");

    utilBar.add(inputer);
    utilBar.add(runner);
    utilBar.add(getTraininger);
    utilBar.add(trainer);
    utilBar.add(modify);

    //create file toolbar
    fileBar = new JToolBar("file");
    ISaveAs = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/saveAs.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    INew = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/new.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    ISave = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/save.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    ILoad = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/load.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));
    IJava = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/toJava.png")).getImage()
            .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH));

    newwer = new JButton(INew);
    newwer.setToolTipText("Create New Neural Network");

    saver = new JButton(ISave);
    saver.setToolTipText("Save Current Network Configuration");

    saveAser = new JButton(ISaveAs);
    saveAser.setToolTipText("Save Network As");

    loader = new JButton(ILoad);
    loader.setToolTipText("Load Network Configuration from File");

    toJava = new JButton(IJava);
    toJava.setToolTipText("Export Network to Java Project");

    fileBar.add(newwer);
    fileBar.add(loader);
    fileBar.add(saver);
    fileBar.add(saveAser);
    fileBar.add(toJava);
    toolBars.add(fileBar);
    toolBars.add(utilBar);
    mainWindow.add(toolBars, BorderLayout.NORTH);

    //create a menubar with three menus on it
    menuBar = new JMenuBar();
    file = new JMenu("File");
    util = new JMenu("Utilities");
    help = new JMenu("Help");

    //add menu items for file menu
    load = new JMenuItem("Load Network Configuration");
    newNet = new JMenuItem("New Network");
    saveAs = new JMenuItem("Save Network As");
    save = new JMenuItem("Save Current Configuration");
    exportNet = new JMenuItem("Export Network to Java Project");
    exportOutput = new JMenuItem("Export Output to Text File");
    file.add(load);
    file.add(newNet);
    file.addSeparator();
    file.add(saveAs);
    file.add(save);
    file.addSeparator();
    file.add(exportNet);
    file.add(exportOutput);
    menuBar.add(file);

    //add menu items for utilities menu
    changeConfig = new JMenuItem("Modify Network Settings");
    getInput = new JMenuItem("Get Input From File");
    getTraining = new JMenuItem("Get Training Set From File");
    run = new JMenuItem("Run");
    train = new JMenuItem("Train");
    getColorMap = new JMenuItem("View Color Map");
    getColorMap.setVisible(false);
    util.add(changeConfig);
    util.addSeparator();
    util.add(getInput);
    util.add(getTraining);
    util.addSeparator();
    util.add(run);
    util.add(train);
    menuBar.add(util);

    //add menu items for help menu
    quickStart = new JMenuItem("Quick Start Guide");
    searchHelp = new JMenuItem("Programming with Yanng");
    about = new JMenuItem("License");
    links = new JMenuItem("<html>Links to Resources<br>about Neural Networks</html>");
    help.add(quickStart);
    help.addSeparator();
    help.add(searchHelp);
    help.addSeparator();
    help.add(about);
    help.addSeparator();
    help.add(links);
    menuBar.add(help);

    mainWindow.setJMenuBar(menuBar);

    //opens the quickstart guide
    quickStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                File myFile = new File(URLDecoder
                        .decode(ClassLoader.getSystemResource("ann/quick-start.pdf").getFile(), "UTF-8"));
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                try {
                    Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/quick-start.pdf");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(mainWindow,
                            "Your desktop is not supported by java,\ngo to yanng/src/ann/quick-start.pdf to view the technical manual.",
                            "Desktop not Supported", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    links.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                File myFile = new File(
                        URLDecoder.decode(ClassLoader.getSystemResource("ann/links.pdf").getFile(), "UTF-8"));
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                try {
                    Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/links.pdf");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(mainWindow,
                            "Your desktop is not supported by java,\ngo to yanng/src/ann/links.pdf to view the technical manual.",
                            "Desktop not Supported", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    //Displays license information
    about.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JTextArea x = new JTextArea("Copyright [2015] [Sam Findler and Michael Scott]\n" + "\n"
                    + "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
                    + "you may not use this file except in compliance with the License.\n"
                    + "You may obtain a copy of the License at\n" + "\n"
                    + "http://www.apache.org/licenses/LICENSE-2.0\n" + "\n"
                    + "Unless required by applicable law or agreed to in writing, software\n"
                    + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
                    + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
                    + "See the License for the specific language governing permissions and\n"
                    + "limitations under the License.");
            JDialog aboutDialog = new JDialog(mainWindow, "License", true);
            aboutDialog.setSize(500, 250);
            aboutDialog.setLayout(new FlowLayout());
            aboutDialog.add(x);
            x.setEditable(false);
            aboutDialog.setVisible(true);
        }
    });

    //opens the more technical user guide
    searchHelp.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                File myFile = new File(URLDecoder
                        .decode(ClassLoader.getSystemResource("ann/technical-manual.pdf").getFile(), "UTF-8"));
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                try {
                    Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/technical-manual.pdf");
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(mainWindow,
                            "Your desktop is not supported by java,\ngo to yanng/src/ann/technical-manual.pdf to view the technical manual.",
                            "Desktop not Supported", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });
    //class trains the neural network in the background while the loading bar displays, then prints out the output/connections listings/average error to the readOut pane
    class Trainer extends SwingWorker<NeuralNetwork, Object> {
        protected NeuralNetwork doInBackground() {
            net.get(resultsPane.getSelectedIndex()).trainNet();
            setProgress(1);
            return net.get(resultsPane.getSelectedIndex());
        }

        public void done() {
            if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) {
                if (Double.isNaN(net.get(resultsPane.getSelectedIndex()).getAverageError()))
                    JOptionPane.showMessageDialog(mainWindow, "Training Set Formatted Incorrectly",
                            "Formatting Error", JOptionPane.ERROR_MESSAGE);
                else {
                    printConnections();
                    readOut.get(resultsPane.getSelectedIndex()).append(
                            "Results of Training " + netName.get(resultsPane.getSelectedIndex()) + ":\n\n");
                    printOutput();
                    readOut.get(resultsPane.getSelectedIndex()).append("Average Error = "
                            + net.get(resultsPane.getSelectedIndex()).getAverageError() + "\n\n");
                    loadingBar.get(resultsPane.getSelectedIndex()).setVisible(false);
                    JOptionPane.showMessageDialog(mainWindow,
                            "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>");
                }
            } else if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) {
                readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Untrained Map:\n");
                printInitMap();
                loadingBar.get(resultsPane.getSelectedIndex()).setVisible(false);
                JOptionPane.showMessageDialog(mainWindow,
                        "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>");
            }
        }

    }
    //starts the training class when train is pressed in the utilities menu
    train.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {

            if (resultsPane.getTabCount() != 0) {
                if (net.get(resultsPane.getSelectedIndex()).getTrainingSet() != null) {
                    loadingBar.get(resultsPane.getSelectedIndex()).setText(
                            "<html><font color = rgb(160,0,0)>Training</font> <font color = rgb(0,0,248)>net...</font></html>");
                    loadingBar.get(resultsPane.getSelectedIndex()).setVisible(true);
                    (thisTrainer = new Trainer()).execute();
                } else
                    JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error",
                            JOptionPane.ERROR_MESSAGE);
            }

            else
                JOptionPane.showMessageDialog(mainWindow, "Can't Train Nonexistent Neural Network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
        }
    });
    //associates the toolbar button with the jump rope guy with the training button on the utilities menu
    trainer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : train.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //runs through one set of inputs and prints the results to the readOut pane  
    run.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) {
                if (net.get(resultsPane.getSelectedIndex()).getInputSet() != null) {
                    net.get(resultsPane.getSelectedIndex()).runNet();
                    if (Double.isNaN(net.get(resultsPane.getSelectedIndex()).getAverageError()))
                        JOptionPane.showMessageDialog(mainWindow, "Training Set Formatted Incorrectly",
                                "Formatting Error", JOptionPane.ERROR_MESSAGE);
                    else {
                        readOut.get(resultsPane.getSelectedIndex()).append("Results of Running through Network "
                                + netName.get(resultsPane.getSelectedIndex()) + ":\n\n");
                        printOutput();
                        System.out.println("Results:");
                        for (int i = 0; i < net.get(resultsPane.getSelectedIndex())
                                .getOutputSet().length; i++) {
                            System.out.println("\n   Output of Input Vector " + i + ":");
                            for (int j = 0; j < net.get(resultsPane.getSelectedIndex())
                                    .getOutputSet()[i].length; j++) {
                                System.out.println("      Output Node " + j + " = "
                                        + net.get(resultsPane.getSelectedIndex()).getOutputSet()[i][j]);
                            }
                        }
                        JOptionPane.showMessageDialog(mainWindow,
                                "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>");
                    }
                } else
                    JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error",
                            JOptionPane.ERROR_MESSAGE);
            } else if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) {
                if (net.get(resultsPane.getSelectedIndex()).getInputValues() != null) {
                    loadingBar.get(resultsPane.getSelectedIndex()).setText(
                            "<html><font color = rgb(160,0,0)>Training</font> <font color = rgb(0,0,248)>net...</font></html>");
                    loadingBar.get(resultsPane.getSelectedIndex()).setVisible(true);
                    (thisTrainer = new Trainer()).execute();
                } else
                    JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error",
                            JOptionPane.ERROR_MESSAGE);
            } else
                JOptionPane.showMessageDialog(mainWindow, "Can't Run Nonexistent Neural Network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
        }
    });

    runner.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : run.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //the following code is for the getTraining button under utilities
    getTrainingSet = new JFileChooser();
    getTrainingSet.setFileFilter(new TrainingFileFilter());

    getTraining.addActionListener(new ActionListener() {
        //this method/class gets a training set (tsv/csv file) and parse it through the neural network.  Kind of test that the file is formatted correctly, but if the data is wrong, there isn't much it can do.
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) {
                int result;
                result = getTrainingSet.showOpenDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION)
                    if (getTrainingSet.getSelectedFile().getName().endsWith(".csv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".tsv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".txt"))
                        if (net.get(resultsPane.getSelectedIndex())
                                .parseTrainingSet(getTrainingSet.getSelectedFile()))
                            JOptionPane.showMessageDialog(mainWindow,
                                    "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>",
                                    "Formatting Warning", JOptionPane.WARNING_MESSAGE);
                        else
                            JOptionPane.showMessageDialog(mainWindow,
                                    "File Mismatch with Network Configuration", "Correspondence Error",
                                    JOptionPane.ERROR_MESSAGE);
                    else {
                        JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                else {
                    JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) {
                int result;
                result = getTrainingSet.showOpenDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION)
                    if (getTrainingSet.getSelectedFile().getName().endsWith(".csv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".tsv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".txt"))
                        if (net.get(resultsPane.getSelectedIndex())
                                .parseTrainingSet(getTrainingSet.getSelectedFile())) {
                            JOptionPane.showMessageDialog(mainWindow,
                                    "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>",
                                    "Formatting Warning", JOptionPane.WARNING_MESSAGE);
                            readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Untrained Map:\n");
                            printInitMap();
                        } else
                            JOptionPane.showMessageDialog(mainWindow,
                                    "File Mismatch with Network Configuration", "Correspondence Error",
                                    JOptionPane.ERROR_MESSAGE);
                    else {
                        JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                else {
                    JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Can't Train Nonexistent Neural Network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    getTraininger.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : getTraining.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //this ends the getTraining section of the code   

    getInput.addActionListener(new ActionListener() {
        //this method/class gets an input set (tsv/csv file) and parses it through the neural network.  Somewhat tests that the file is formatted correctly, but cannot give a garuntee.
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0) {
                int result;
                result = getTrainingSet.showOpenDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION)
                    if (getTrainingSet.getSelectedFile().getName().endsWith(".csv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".tsv")
                            || getTrainingSet.getSelectedFile().getName().endsWith(".txt"))
                        if (net.get(resultsPane.getSelectedIndex())
                                .parseInputSet(getTrainingSet.getSelectedFile())) {
                            JOptionPane.showMessageDialog(mainWindow,
                                    "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>",
                                    "Formatting Warning", JOptionPane.WARNING_MESSAGE);
                            if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                    .equals("Self-Organizing Map"))
                                printInitMap();
                        } else
                            JOptionPane.showMessageDialog(mainWindow,
                                    "File Mismatch with Network Configuration", "Correspondence Error",
                                    JOptionPane.ERROR_MESSAGE);
                    else
                        JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error",
                                JOptionPane.ERROR_MESSAGE);
                else
                    JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning",
                            JOptionPane.WARNING_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Can't train nonexistent network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    //opens and displays a color map of a SOM
    getColorMap.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0) {
                if (netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) {
                    MapNode[][] map;

                    map = net.get(resultsPane.getSelectedIndex()).getMapArray();

                    int lValue = net.get(resultsPane.getSelectedIndex()).getLatticeValue();

                    int inputDimensions = net.get(resultsPane.getSelectedIndex()).getInputDimensions();

                    int[][] colorValues = new int[(lValue * lValue)][3];

                    double dMax = net.get(resultsPane.getSelectedIndex()).getDataMax();
                    double dMin = net.get(resultsPane.getSelectedIndex()).getDataMin();

                    int count = 0;

                    for (int i = 0; i < lValue; i++) {
                        for (int j = 0; j < lValue; j++) {
                            for (int k = 0; k < 3; k++) {
                                Vector tempVec = map[i][j].getWeights();
                                if (inputDimensions % 3 == 0) {
                                    colorValues[count][k] = Integer.parseInt(String.valueOf((Math.round(255
                                            * (Double.parseDouble(String.valueOf(tempVec.elementAt(k))))))));
                                }
                                if (inputDimensions % 3 == 1) {
                                    if (k == 0)
                                        colorValues[count][k] = 0;
                                    if (k == 1) {
                                        colorValues[count][k] = Integer
                                                .parseInt(String.valueOf((Math.round(255 * (Double
                                                        .parseDouble(String.valueOf(tempVec.elementAt(0))))))));
                                    }
                                    if (k == 2)
                                        colorValues[count][k] = 0;
                                }
                                if (inputDimensions % 3 == 2) {
                                    if (k == 2) {
                                        colorValues[count][k] = 0;
                                    } else
                                        colorValues[count][k] = Integer
                                                .parseInt(String.valueOf((Math.round(255 * (Double
                                                        .parseDouble(String.valueOf(tempVec.elementAt(k))))))));
                                }
                            }
                            count++;
                        }
                    }

                    JFrame frame = new JFrame();

                    frame.setTitle("Color Map");
                    frame.setPreferredSize(new Dimension(525, 500));
                    frame.add(new DrawPanel(colorValues, lValue));
                    frame.pack();
                    frame.setVisible(true);
                }

                else {
                    JOptionPane.showMessageDialog(mainWindow,
                            "This Feauture is only available for Self-Organizing Maps", "Not a Som Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Network does not exist", "Existential Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    inputer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : getInput.getActionListeners())
                a.actionPerformed(ae);
        }
    });

    getNet = new JFileChooser();
    getNet.setFileFilter(new ANNFileFilter());

    //saves the net, or opens save as dialog if net is not saved yet
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0) {
                if (!path.get(resultsPane.getSelectedIndex()).equals("")) {
                    net.get(resultsPane.getSelectedIndex())
                            .save(new File(path.get(resultsPane.getSelectedIndex())));
                }

                else {
                    for (ActionListener a : saveAs.getActionListeners()) {
                        a.actionPerformed(ae);
                    }
                }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Can't save NonExistent Neural Network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    saver.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : save.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //opens dialog for saving the net
    saveAs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0) {
                int result, override;
                String tempName;
                result = getNet.showSaveDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION)
                    if ((new File(tempName = getNet.getSelectedFile().getName())).exists()
                            || (new File(tempName + ".ffn")).exists() || (new File(tempName + ".som")).exists()
                            || (new File(tempName + ".hfn")).exists()) {
                        override = JOptionPane.showConfirmDialog(mainWindow,
                                tempName + " already exists, do you want to override?", "File Exists",
                                JOptionPane.YES_NO_OPTION);
                        if (override == JOptionPane.YES_OPTION) {
                            if (net.get(resultsPane.getSelectedIndex()).save(getNet.getSelectedFile())) {
                                if (tempName.endsWith(".ffn") || tempName.endsWith(".som")) {
                                    netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName));
                                    title.get(resultsPane.getSelectedIndex()).setText(tempName + " ");
                                } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                        .equals("Feed Forward Network")) {
                                    netName.set(resultsPane.getSelectedIndex(),
                                            new StringBuffer(tempName + ".ffn"));
                                    title.get(resultsPane.getSelectedIndex()).setText(tempName + ".ffn ");
                                } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                        .equals("Self-Organizing Map")) {
                                    netName.set(resultsPane.getSelectedIndex(),
                                            new StringBuffer(tempName + ".som"));
                                    title.get(resultsPane.getSelectedIndex()).setText(tempName + ".som ");
                                }
                                path.set(resultsPane.getSelectedIndex(), getNet.getSelectedFile().getPath());

                            } else
                                JOptionPane.showMessageDialog(mainWindow, "Could not save file", "File Error",
                                        JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        if (net.get(resultsPane.getSelectedIndex()).save(getNet.getSelectedFile())) {
                            if (tempName.endsWith(".ffn") || tempName.endsWith(".som")
                                    || tempName.endsWith(".hfn")) {
                                netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName));
                                title.get(resultsPane.getSelectedIndex()).setText(tempName + " ");
                            } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                    .equals("Feed Forward Network")) {
                                netName.set(resultsPane.getSelectedIndex(),
                                        new StringBuffer(tempName + ".ffn"));
                                title.get(resultsPane.getSelectedIndex()).setText(tempName + ".ffn ");
                            } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                    .equals("Self-Organizing Map")) {
                                netName.set(resultsPane.getSelectedIndex(),
                                        new StringBuffer(tempName + ".som"));
                                title.get(resultsPane.getSelectedIndex()).setText(tempName + ".som ");
                                path.set(resultsPane.getSelectedIndex(), getNet.getSelectedFile().getPath());
                            }
                        } else
                            JOptionPane.showMessageDialog(mainWindow, "Could not save file", "File Error",
                                    JOptionPane.ERROR_MESSAGE);
                    }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Nothing to Save", "Existetial Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    saveAser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : saveAs.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //loads a net
    load.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int result;
            boolean test = true;
            String tempName;
            result = getNet.showOpenDialog(mainWindow);
            if (result == JFileChooser.APPROVE_OPTION) {
                tempName = getNet.getSelectedFile().getName();
                for (StringBuffer names : netName) {
                    if (names.toString().equals(tempName))
                        test = false;
                }
                if (test != false) {
                    //creates and sets the network configuration
                    if (tempName.endsWith(".ffn")) {
                        net.add(new FullyConnectedFeedForwardNet());
                    }
                    if (tempName.endsWith(".som")) {
                        net.add(new SelfOrganizingMap());
                    }
                    if (net.get(openNets).load(getNet.getSelectedFile()))
                        try {
                            //adds a close button to the top corner of each tab
                            title.add(new JLabel(tempName + " "));
                            close.add(new JButton("X"));
                            close.get(openNets).setActionCommand(tempName);
                            close.get(openNets)
                                    .setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
                            close.get(openNets).setMargin(new Insets(0, 0, 0, 0));
                            tabPanel.add(new JPanel(new GridBagLayout()));
                            tabPanel.get(openNets).setOpaque(false);
                            GridBagConstraints grid = new GridBagConstraints();
                            grid.fill = GridBagConstraints.HORIZONTAL;
                            grid.gridx = 0;
                            grid.gridy = 0;
                            grid.weightx = 1;
                            tabPanel.get(openNets).add(title.get(openNets), grid);
                            grid.gridx = 1;
                            grid.gridy = 0;
                            grid.weightx = 0;
                            tabPanel.get(openNets).add(close.get(openNets), grid);

                            //adds a loading bar
                            loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER));
                            loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT);
                            loadingBar.get(openNets).setVisible(false);

                            path.add(getNet.getSelectedFile().getPath());

                            netKind.add(new StringBuffer(netType.getSelectedItem().toString()));
                            netName.add(new StringBuffer(tempName));
                            oneNet.add(new JPanel());
                            oneNet.get(openNets).setLayout(new GridBagLayout());
                            GridBagConstraints constraints = new GridBagConstraints();
                            constraints.fill = GridBagConstraints.BOTH;

                            //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar
                            readOut.add(new JTextArea(""));
                            readOutLocale.add(new JScrollPane(readOut.get(openNets)));
                            readOut.get(openNets).setEditable(false);
                            constraints.gridx = 0;
                            constraints.gridy = 0;
                            constraints.weighty = 1.0;
                            constraints.weightx = 1.0;
                            constraints.gridwidth = 2;
                            constraints.ipady = 90;
                            oneNet.get(openNets).add(readOutLocale.get(openNets), constraints);
                            constraints.fill = GridBagConstraints.HORIZONTAL;
                            constraints.gridx = 0;
                            constraints.gridy = 1;
                            constraints.ipady = 0;
                            constraints.gridwidth = 2;
                            constraints.anchor = GridBagConstraints.PAGE_END;

                            //add everythign to the tabbed pane
                            oneNet.get(openNets).add(loadingBar.get(openNets), constraints);
                            resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets));
                            resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets));

                            //display the starting configuration of the network
                            readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n");
                            resultsPane.setSelectedIndex(openNets++);
                            if (tempName.endsWith(".ffn"))
                                printConnections();
                            if (tempName.endsWith(".som")) {
                                readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Map:\n");
                                printInitMap();
                            }

                            //unfortunately difficult way that I made to add the close button functionality to close a tab
                            //it works, but there has to be a better way to do this
                            close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() {
                                public void actionPerformed(final ActionEvent ae) {
                                    int result;
                                    result = 0;
                                    for (StringBuffer names : netName) {
                                        if (ae.getActionCommand().equals(names.toString())) {
                                            result = JOptionPane.showConfirmDialog(createFFN,
                                                    "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>",
                                                    "Close Network", JOptionPane.OK_CANCEL_OPTION);
                                            resultsPane.setSelectedIndex(netName.indexOf(names));
                                        }
                                    }
                                    if (result == JOptionPane.OK_OPTION) {
                                        net.remove(resultsPane.getSelectedIndex());
                                        oneNet.remove(resultsPane.getSelectedIndex());
                                        readOutLocale.remove(resultsPane.getSelectedIndex());
                                        readOut.remove(resultsPane.getSelectedIndex());
                                        loadingBar.remove(resultsPane.getSelectedIndex());
                                        tabPanel.remove(resultsPane.getSelectedIndex());
                                        title.remove(resultsPane.getSelectedIndex());
                                        close.remove(resultsPane.getSelectedIndex());
                                        netName.remove(resultsPane.getSelectedIndex());
                                        resultsPane.remove(resultsPane.getSelectedIndex());
                                        openNets--;
                                    }
                                }
                            });
                        } catch (Error e) {
                            JOptionPane.showMessageDialog(mainWindow, "File Formatted Incorrectly",
                                    "Formatting Error", JOptionPane.ERROR_MESSAGE);
                        }
                    else {
                        //if file was unable to load, remove the newly created neural network and display an error message
                        net.remove(openNets);
                        JOptionPane.showMessageDialog(mainWindow, "File Formatted Incorrectly",
                                "Formatting Error", JOptionPane.ERROR_MESSAGE);
                    }
                }

                else {
                    JOptionPane.showMessageDialog(mainWindow, "File Already Open", "Duality Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    //associates the load toolbar button with load from the file menu
    loader.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : load.getActionListeners())
                a.actionPerformed(ae);
        }
    });

    textFileChooser = new JFileChooser();
    textFileChooser.setFileFilter(new TextFileFilter());

    //exports all text from readout to a text file
    exportOutput.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0) {
                int result;
                result = textFileChooser.showSaveDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION) {
                    if (textFileChooser.getSelectedFile().exists()
                            || (new File(textFileChooser.getSelectedFile().getPath() + ".txt")).exists()) {
                        result = JOptionPane.showConfirmDialog(mainWindow,
                                "The File you have selected already Exists, do you want to Overwrite it?",
                                "File Exits", JOptionPane.YES_NO_OPTION);
                        if (result == JOptionPane.YES_OPTION) {
                            try {
                                if (textFileChooser.getSelectedFile().getPath().endsWith(".txt"))
                                    FileUtils.writeStringToFile(textFileChooser.getSelectedFile(),
                                            readOut.get(resultsPane.getSelectedIndex()).getText());
                                else
                                    FileUtils.writeStringToFile(
                                            new File(textFileChooser.getSelectedFile().getPath() + ".txt"),
                                            readOut.get(resultsPane.getSelectedIndex()).getText());
                                JOptionPane.showMessageDialog(mainWindow, "Succesfully wrote readout to file");
                            } catch (Exception e) {
                                JOptionPane.showMessageDialog(mainWindow, "Could not write to file", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    } else {
                        try {
                            if (textFileChooser.getSelectedFile().getPath().endsWith(".txt"))
                                FileUtils.writeStringToFile(textFileChooser.getSelectedFile(),
                                        readOut.get(resultsPane.getSelectedIndex()).getText());
                            else
                                FileUtils.writeStringToFile(
                                        new File(textFileChooser.getSelectedFile().getPath() + ".txt"),
                                        readOut.get(resultsPane.getSelectedIndex()).getText());
                            JOptionPane.showMessageDialog(mainWindow, "Succesfully wrote readout to file");
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(mainWindow, "Could not write to file", "Error",
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Nothing to Export", "Existential Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    projectFileChooser = new JFileChooser();
    projectFileChooser.setFileFilter(new ProjectFileFilter());

    //exports a neural network to a java/android project
    exportNet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int result, override, override2;
            String tempName;
            String templateFile;
            String directory;
            String path;
            if (resultsPane.getTabCount() != 0) {
                result = projectFileChooser.showSaveDialog(mainWindow);
                if (result == JFileChooser.APPROVE_OPTION) {
                    path = projectFileChooser.getSelectedFile().getPath();
                    directory = projectFileChooser.getSelectedFile().getPath().substring(0,
                            projectFileChooser.getSelectedFile().getPath().lastIndexOf(File.separator));
                    tempName = projectFileChooser.getSelectedFile().getName();
                    if (projectFileChooser.getSelectedFile().exists()
                            || (new File(directory, tempName + ".java")).exists()) {
                        override = JOptionPane.showConfirmDialog(mainWindow,
                                "Java Class File" + tempName + " already exists, do you want to overwrite it?",
                                "File Exists", JOptionPane.YES_NO_OPTION);
                        if (override == JOptionPane.YES_OPTION) {
                            try {
                                if (!(new File(directory, "ann")).exists())
                                    FileUtils.copyDirectoryToDirectory(
                                            FileUtils.toFile(ClassLoader.getSystemResource("ann/")),
                                            new File(directory));
                                if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                        .equals("Feed Forward Network")) {
                                    templateFile = FileUtils.readFileToString(FileUtils
                                            .toFile(ClassLoader.getSystemResource("ann/FFNTemplate.txt")));
                                    templateFile = templateFile.replaceAll("yourpackagename",
                                            (new File(directory)).getName());
                                    templateFile = templateFile.replaceAll("YourProjectName",
                                            projectFileChooser.getSelectedFile().getName());
                                    if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".ffn"))
                                        templateFile = templateFile.replaceAll("networkName",
                                                (new File(directory)).getName() + File.separator + netName
                                                        .get(resultsPane.getSelectedIndex()).toString());
                                    else
                                        templateFile = templateFile.replaceAll("networkName",
                                                (new File(directory)).getName() + File.separator
                                                        + netName.get(resultsPane.getSelectedIndex()).toString()
                                                        + ".ffn");
                                    if (path.indexOf('.') > 0) {
                                        FileUtils.writeStringToFile(
                                                new File(path.substring(0, path.lastIndexOf('.')) + ".java"),
                                                templateFile);
                                    } else
                                        FileUtils.writeStringToFile(new File(path + ".java"), templateFile);
                                    if ((new File(directory,
                                            (tempName = netName.get(resultsPane.getSelectedIndex())
                                                    .toString()))).exists()
                                            || (new File(directory, tempName + ".ffn")).exists()) {
                                        override2 = JOptionPane.showConfirmDialog(mainWindow,
                                                "Neural Network " + tempName
                                                        + " already exists, do you want to overwrite it?",
                                                "File Exists", JOptionPane.YES_NO_OPTION);
                                        if (override2 == JOptionPane.YES_OPTION)
                                            if (net.get(resultsPane.getSelectedIndex())
                                                    .save(new File(directory + File.separator + tempName))) {
                                                JOptionPane.showMessageDialog(mainWindow, "Network Exported to "
                                                        + (new File(directory)).getName());
                                            } else {
                                                JOptionPane.showMessageDialog(mainWindow,
                                                        "Couldn't save neural network to file, the rest of the project is exported",
                                                        "Write Error", JOptionPane.ERROR_MESSAGE);
                                            }
                                    } else {
                                        if (net.get(resultsPane.getSelectedIndex())
                                                .save(new File(directory + File.separator + tempName))) {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Network Exported to " + (new File(directory)).getName());
                                        } else {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Couldn't save neural network to file, the rest of the project is exported",
                                                    "Write Error", JOptionPane.ERROR_MESSAGE);
                                        }
                                    }
                                } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                        .equals("Self-Organizing Map")) {
                                    templateFile = FileUtils.readFileToString(FileUtils
                                            .toFile(ClassLoader.getSystemResource("ann/SOMTemplate.txt")));
                                    templateFile = templateFile.replaceAll("yourpackagename",
                                            (new File(directory)).getName());
                                    templateFile = templateFile.replaceAll("YourProjectName",
                                            projectFileChooser.getSelectedFile().getName());
                                    if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".som"))
                                        templateFile = templateFile.replaceAll("networkName",
                                                (new File(directory)).getName() + File.separator + netName
                                                        .get(resultsPane.getSelectedIndex()).toString());
                                    else
                                        templateFile = templateFile.replaceAll("networkName",
                                                (new File(directory)).getName() + File.separator
                                                        + netName.get(resultsPane.getSelectedIndex()).toString()
                                                        + ".som");
                                    if (path.indexOf('.') > 0) {
                                        FileUtils.writeStringToFile(
                                                new File(path.substring(0, path.lastIndexOf('.')) + ".java"),
                                                templateFile);
                                    } else
                                        FileUtils.writeStringToFile(new File(path + ".java"), templateFile);
                                    if ((new File(directory,
                                            (tempName = netName.get(resultsPane.getSelectedIndex())
                                                    .toString()))).exists()
                                            || (new File(directory, tempName + ".som")).exists()) {
                                        override2 = JOptionPane.showConfirmDialog(mainWindow,
                                                "Neural Network " + tempName
                                                        + " already exists, do you want to overwrite it?",
                                                "File Exists", JOptionPane.YES_NO_OPTION);
                                        if (override2 == JOptionPane.YES_OPTION)
                                            if (net.get(resultsPane.getSelectedIndex())
                                                    .save(new File(directory + File.separator + tempName))) {
                                                JOptionPane.showMessageDialog(mainWindow, "Network Exported to "
                                                        + (new File(directory)).getName());
                                            } else {
                                                JOptionPane.showMessageDialog(mainWindow,
                                                        "Couldn't save neural network to file, the rest of the project is exported",
                                                        "Write Error", JOptionPane.ERROR_MESSAGE);
                                            }
                                    } else {
                                        if (net.get(resultsPane.getSelectedIndex())
                                                .save(new File(directory + File.separator + tempName))) {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Network Exported to " + (new File(directory)).getName());
                                        } else {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Couldn't save neural network to file, the rest of the project is exported",
                                                    "Write Error", JOptionPane.ERROR_MESSAGE);
                                        }
                                    }
                                }
                            } catch (IOException io) {
                                System.out.println(io);
                            }

                        }
                    } else {
                        try {
                            if (!(new File(directory, "ann")).exists())
                                FileUtils.copyDirectoryToDirectory(
                                        FileUtils.toFile(ClassLoader.getSystemResource("ann/")),
                                        new File(directory));
                            if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                    .equals("Feed Forward Network")) {
                                templateFile = FileUtils.readFileToString(
                                        FileUtils.toFile(ClassLoader.getSystemResource("ann/FFNTemplate.txt")));
                                templateFile = templateFile.replaceAll("yourpackagename",
                                        (new File(directory)).getName());
                                templateFile = templateFile.replaceAll("YourProjectName",
                                        projectFileChooser.getSelectedFile().getName());
                                if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".ffn"))
                                    templateFile = templateFile.replaceAll("networkName",
                                            (new File(directory)).getName() + File.separator
                                                    + netName.get(resultsPane.getSelectedIndex()).toString());
                                else
                                    templateFile = templateFile.replaceAll("networkName",
                                            (new File(directory)).getName() + File.separator
                                                    + netName.get(resultsPane.getSelectedIndex()).toString()
                                                    + ".ffn");
                                if (path.indexOf('.') > 0) {
                                    FileUtils.writeStringToFile(
                                            new File(path.substring(0, path.lastIndexOf('.')) + ".java"),
                                            templateFile);
                                } else
                                    FileUtils.writeStringToFile(new File(path + ".java"), templateFile);
                                if ((new File(directory + File.separator
                                        + (tempName = netName.get(resultsPane.getSelectedIndex()).toString())))
                                                .exists()
                                        || (new File(directory + File.separator + tempName + ".ffn"))
                                                .exists()) {
                                    override2 = JOptionPane.showConfirmDialog(mainWindow,
                                            "Neural Network " + tempName
                                                    + " already exists, do you want to overwrite it?",
                                            "File Exists", JOptionPane.YES_NO_OPTION);
                                    if (override2 == JOptionPane.YES_OPTION)
                                        if (net.get(resultsPane.getSelectedIndex())
                                                .save(new File(directory + File.separator + tempName))) {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Network Exported to " + (new File(directory)).getName());
                                        } else {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Couldn't save neural network to file, the rest of the project is exported",
                                                    "Write Error", JOptionPane.ERROR_MESSAGE);
                                        }
                                } else {
                                    if (net.get(resultsPane.getSelectedIndex())
                                            .save(new File(directory + File.separator + tempName))) {
                                        JOptionPane.showMessageDialog(mainWindow,
                                                "Network Exported to " + (new File(directory)).getName());
                                    } else {
                                        JOptionPane.showMessageDialog(mainWindow,
                                                "Couldn't save neural network to file, the rest of the project is exported",
                                                "Write Error", JOptionPane.ERROR_MESSAGE);
                                    }
                                }
                            } else if (netKind.get(resultsPane.getSelectedIndex()).toString()
                                    .equals("Self-Organizing Map")) {
                                templateFile = FileUtils.readFileToString(
                                        FileUtils.toFile(ClassLoader.getSystemResource("ann/SOMTemplate.txt")));
                                templateFile = templateFile.replaceAll("yourpackagename",
                                        (new File(directory)).getName());
                                templateFile = templateFile.replaceAll("YourProjectName",
                                        projectFileChooser.getSelectedFile().getName());
                                if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".som"))
                                    templateFile = templateFile.replaceAll("networkName",
                                            (new File(directory)).getName() + File.separator
                                                    + netName.get(resultsPane.getSelectedIndex()).toString());
                                else
                                    templateFile = templateFile.replaceAll("networkName",
                                            (new File(directory)).getName() + File.separator
                                                    + netName.get(resultsPane.getSelectedIndex()).toString()
                                                    + ".som");
                                if (path.indexOf('.') > 0) {
                                    FileUtils.writeStringToFile(
                                            new File(path.substring(0, path.lastIndexOf('.')) + ".java"),
                                            templateFile);
                                } else
                                    FileUtils.writeStringToFile(new File(path + ".java"), templateFile);
                                if ((new File(directory,
                                        (tempName = netName.get(resultsPane.getSelectedIndex()).toString())))
                                                .exists()
                                        || (new File(directory, tempName + ".som")).exists()) {
                                    override2 = JOptionPane.showConfirmDialog(mainWindow,
                                            "Neural Network " + tempName
                                                    + " already exists, do you want to overwrite it?",
                                            "File Exists", JOptionPane.YES_NO_OPTION);
                                    if (override2 == JOptionPane.YES_OPTION)
                                        if (net.get(resultsPane.getSelectedIndex())
                                                .save(new File(directory + File.separator + tempName))) {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Network Exported to " + (new File(directory)).getName());
                                        } else {
                                            JOptionPane.showMessageDialog(mainWindow,
                                                    "Couldn't save neural network to file, the rest of the project is exported",
                                                    "Write Error", JOptionPane.ERROR_MESSAGE);
                                        }
                                } else {
                                    if (net.get(resultsPane.getSelectedIndex())
                                            .save(new File(directory + File.separator + tempName))) {
                                        JOptionPane.showMessageDialog(mainWindow,
                                                "Network Exported to " + (new File(directory)).getName());
                                    } else {
                                        JOptionPane.showMessageDialog(mainWindow,
                                                "Couldn't save neural network to file, the rest of the project is exported",
                                                "Write Error", JOptionPane.ERROR_MESSAGE);
                                    }
                                }
                            }
                        } catch (IOException io) {
                            System.out.println(io);
                        }
                    }
                }
            } else {
                JOptionPane.showMessageDialog(mainWindow, "Can't Export NonExistent Neural Network",
                        "Existential Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    toJava.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : exportNet.getActionListeners())
                a.actionPerformed(ae);
        }
    });

    //settings menu
    changeConfig.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) {

                modifyFFNDialog = new JDialog(mainWindow, "Network Settings", true);
                modifyFFNDialog.setSize(500, 500);
                modifyFFNDialog.setLayout(new GridBagLayout());
                GridBagConstraints asdf = new GridBagConstraints();
                asdf.gridwidth = 5;
                asdf.gridheight = 1;
                asdf.gridx = 0;
                asdf.gridy = 0;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.gridwidth = 5;
                asdf.gridheight = 15;
                asdf.weightx = 1.0;
                asdf.weighty = 1.0;
                asdf.gridx = 0;
                asdf.gridy = 1;
                asdf.fill = GridBagConstraints.BOTH;
                settings = new JTextArea();
                settings.setEditable(false);
                settings.setBorder(BorderFactory.createEtchedBorder());
                modifyFFNDialog.add(settings, asdf);
                asdf.fill = GridBagConstraints.HORIZONTAL;
                asdf.gridwidth = 5;
                asdf.gridheight = 1;
                asdf.gridx = 0;
                asdf.gridy = 16;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.gridwidth = 2;
                asdf.gridx = 7;
                asdf.gridy = 0;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 1;
                learningRateL = new JLabel("Set Learning Rate:");
                modifyFFNDialog.add(learningRateL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 2;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                learningRateTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance()));
                learningRateTF.setText("");
                modifyFFNDialog.add(learningRateTF, asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 3;
                momentumL = new JLabel("Set Momentum:");
                modifyFFNDialog.add(momentumL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 4;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                momentumTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance()));
                momentumTF.setText("");
                modifyFFNDialog.add(momentumTF, asdf);
                asdf.gridx = 7;
                asdf.gridy = 5;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                /*asdf.gridwidth = 2;
                asdf.gridheight = 1;
                asdf.gridx = 7;
                asdf.gridy = 6;
                setNoise = new JLabel("Use Noise: ");
                modifyFFNDialog.add(setNoise, asdf);
                asdf.gridx = 7;
                asdf.gridy = 7;
                asdf.gridwidth = 1;
                noiseOn = new JRadioButton("yes");
                noiseOff = new JRadioButton("no");
                noiseGroup = new ButtonGroup();
                noiseGroup.add(noiseOn);
                noiseGroup.add(noiseOff);
                modifyFFNDialog.add(noiseOn,asdf);
                asdf.gridx = 8;
                asdf.gridy = 7;
                modifyFFNDialog.add(noiseOff,asdf);
                asdf.gridx = 7;
                asdf.gridy = 8;
                asdf.gridwidth = 2;
                setNoiseRange = new JButton("Set Noise Range");
                modifyFFNDialog.add(setNoiseRange,asdf);
                asdf.gridx = 7;
                asdf.gridy = 9;
                setNoiseTiming = new JButton("Set Noise Timing");
                modifyFFNDialog.add(setNoiseTiming,asdf);*/
                asdf.gridx = 7;
                asdf.gridy = 10;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 11;
                setTrainingStyle = new JLabel("Set Training Style:");
                modifyFFNDialog.add(setTrainingStyle, asdf);
                asdf.gridx = 7;
                asdf.gridy = 12;
                asdf.gridwidth = 1;
                batchOn = new JRadioButton("batch");
                onlineOn = new JRadioButton("online");
                batchGroup = new ButtonGroup();
                batchGroup.add(batchOn);
                batchGroup.add(onlineOn);
                modifyFFNDialog.add(batchOn, asdf);
                asdf.gridx = 8;
                modifyFFNDialog.add(onlineOn, asdf);
                asdf.gridx = 7;
                asdf.gridy = 13;
                asdf.gridwidth = 2;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 14;
                modifyBiases = new JButton("Modify Biases");
                modifyFFNDialog.add(modifyBiases, asdf);
                asdf.gridx = 7;
                asdf.gridy = 15;
                trainingCompletionButton = new JButton("Modify End Condition");
                modifyFFNDialog.add(trainingCompletionButton, asdf);
                asdf.fill = GridBagConstraints.HORIZONTAL;
                asdf.gridy = 16;
                modifyFFNDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridwidth = 1;
                asdf.gridx = 3;
                asdf.gridy = 17;
                asdf.anchor = GridBagConstraints.PAGE_END;
                modifyFFN = new JButton("OK");
                modifyFFNDialog.add(modifyFFN, asdf);
                asdf.gridx = 7;
                cancelModifyFFN = new JButton("Cancel");
                modifyFFNDialog.add(cancelModifyFFN, asdf);
                settings.setText("");
                settings.append(
                        "\n\n\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                settings.append("\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum());
                settings.append("\n\nTraining Style: ");
                if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) {
                    settings.append("batch");
                    batchOn.setSelected(true);
                } else {
                    settings.append("online");
                    onlineOn.setSelected(true);
                }
                settings.append("\n\nTraining End Condition: ");
                if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) {
                    settings.append("Iterative");
                    settings.append(
                            "\n\nIterations: " + net.get(resultsPane.getSelectedIndex()).getIterations());
                } else {
                    settings.append("Ideal Error");
                    settings.append(
                            "\n\nIdeal Error: " + net.get(resultsPane.getSelectedIndex()).getIdealError());
                }

                //expiremental feature, needs work on the back end to be properly implemented   
                modifyBiases.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        JButton addBiases, removeBiases;

                        biasesDialog = new JDialog(modifyFFNDialog, "Set Biases");
                        biasesDialog.setSize(200, 46);
                        biasesDialog.setLayout(new GridLayout(2, 1));
                        addBiases = new JButton("Add Bias");
                        removeBiases = new JButton("Remove Bias");

                        biasesDialog.add(addBiases);
                        biasesDialog.add(removeBiases);

                        addBiases.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                JLabel howManyBiasLayersLabel, whatBiasNodeLabel, whatBiasValueLabel;
                                final JFormattedTextField howManyBiasLayers, whatBiasNode, whatBiasValue;
                                JButton addBiasOK, addBiasCancel;
                                biasesDialog.setVisible(false);
                                addBiasDialog = new JDialog(modifyFFNDialog, "Add Bias");
                                addBiasDialog.setSize(756, 90);
                                addBiasDialog.setLayout(new GridLayout(4, 2));
                                howManyBiasLayersLabel = new JLabel("What Layer will get the Bias?");
                                howManyBiasLayers = new JFormattedTextField(
                                        new NumberFormatter(NumberFormat.getIntegerInstance()));
                                whatBiasNodeLabel = new JLabel("Which Node will get the Bias?");
                                whatBiasNode = new JFormattedTextField(
                                        new NumberFormatter(NumberFormat.getIntegerInstance()));
                                whatBiasValueLabel = new JLabel("What Value will the Bias have?");
                                whatBiasValue = new JFormattedTextField(
                                        new NumberFormatter(NumberFormat.getInstance()));
                                addBiasOK = new JButton("OK");
                                addBiasCancel = new JButton("Cancel");
                                addBiasDialog.add(howManyBiasLayersLabel);
                                addBiasDialog.add(howManyBiasLayers);
                                addBiasDialog.add(whatBiasNodeLabel);
                                addBiasDialog.add(whatBiasNode);
                                addBiasDialog.add(whatBiasValueLabel);
                                addBiasDialog.add(whatBiasValue);
                                addBiasDialog.add(addBiasOK);
                                addBiasDialog.add(addBiasCancel);

                                addBiasOK.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent ae) {
                                        if (!howManyBiasLayers.getText().equals("")
                                                && !whatBiasNode.getText().equals("")
                                                && !whatBiasValue.getText().equals("")) {
                                            addBiasDialog.setVisible(false);
                                            if (net.get(resultsPane.getSelectedIndex()).addBias(
                                                    Integer.parseInt(howManyBiasLayers.getText()) - 1,
                                                    Integer.parseInt(whatBiasNode.getText()) - 1,
                                                    Double.parseDouble(whatBiasValue.getText()))) {
                                            } else {
                                                JOptionPane.showMessageDialog(modifyFFNDialog,
                                                        "Existential Error", "Invalid Node for Bias",
                                                        JOptionPane.ERROR_MESSAGE);
                                            }
                                        } else {
                                            JOptionPane.showMessageDialog(modifyFFNDialog, "Form Error",
                                                    "Form not completed", JOptionPane.ERROR_MESSAGE);
                                        }
                                    }
                                });
                                addBiasCancel.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent ae) {
                                        addBiasDialog.setVisible(false);
                                    }
                                });

                                addBiasDialog.setVisible(true);
                            }
                        });

                        removeBiases.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                JLabel howManyBiasLayersLabel, whatBiasNodeLabel;
                                final JFormattedTextField howManyBiasLayers, whatBiasNode;
                                JButton addBiasOK, addBiasCancel;
                                biasesDialog.setVisible(false);
                                removeBiasDialog = new JDialog(modifyFFNDialog, "Remove Bias");
                                removeBiasDialog.setSize(756, 90);
                                removeBiasDialog.setLayout(new GridLayout(3, 2));
                                howManyBiasLayersLabel = new JLabel("What Layer will lose the Bias?");
                                howManyBiasLayers = new JFormattedTextField(
                                        new NumberFormatter(NumberFormat.getIntegerInstance()));
                                whatBiasNodeLabel = new JLabel("Which Node will get the Bias?");
                                whatBiasNode = new JFormattedTextField(
                                        new NumberFormatter(NumberFormat.getIntegerInstance()));
                                addBiasOK = new JButton("OK");
                                addBiasCancel = new JButton("Cancel");
                                removeBiasDialog.add(howManyBiasLayersLabel);
                                removeBiasDialog.add(howManyBiasLayers);
                                removeBiasDialog.add(whatBiasNodeLabel);
                                removeBiasDialog.add(whatBiasNode);
                                removeBiasDialog.add(addBiasOK);
                                removeBiasDialog.add(addBiasCancel);

                                addBiasOK.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent ae) {
                                        if (!howManyBiasLayers.getText().equals("")
                                                && !whatBiasNode.getText().equals("")) {
                                            addBiasDialog.setVisible(false);
                                            if (net.get(resultsPane.getSelectedIndex()).removeBias(
                                                    Integer.parseInt(howManyBiasLayers.getText()) - 1,
                                                    Integer.parseInt(whatBiasNode.getText()) - 1)) {
                                            } else {
                                                JOptionPane.showMessageDialog(modifyFFNDialog,
                                                        "Existential Error", "Invalid Node for Bias",
                                                        JOptionPane.ERROR_MESSAGE);
                                            }
                                        } else {
                                            JOptionPane.showMessageDialog(modifyFFNDialog, "Form Error",
                                                    "Form not completed", JOptionPane.ERROR_MESSAGE);
                                        }
                                    }
                                });
                                addBiasCancel.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent ae) {
                                        addBiasDialog.setVisible(false);
                                    }
                                });

                                removeBiasDialog.setVisible(true);
                            }
                        });

                        biasesDialog.setVisible(true);

                    }
                });

                trainingCompletionButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        final JDialog iterationsDialog;
                        JLabel numberOfIterationsLabel;
                        final JFormattedTextField numberOfIterations;
                        JButton iterationsOK, iterationsCancel;
                        iterationsDialog = new JDialog(modifyFFNDialog, "Set Iterations");
                        iterationsDialog.setSize(765, 75);
                        iterationsDialog.setLayout(new GridLayout(2, 2));
                        numberOfIterationsLabel = new JLabel("How Many Iterations do you want to Train?");
                        numberOfIterations = new JFormattedTextField(
                                new NumberFormatter(NumberFormat.getIntegerInstance()));
                        iterationsOK = new JButton("OK");
                        iterationsCancel = new JButton("Cancel");
                        iterationsDialog.add(numberOfIterationsLabel);
                        iterationsDialog.add(numberOfIterations);
                        iterationsDialog.add(iterationsOK);
                        iterationsDialog.add(iterationsCancel);
                        iterationsOK.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                if (!numberOfIterations.getText().equals("")) {
                                    iterationsDialog.setVisible(false);
                                    if (net.get(resultsPane.getSelectedIndex())
                                            .setIterations(Integer.parseInt(numberOfIterations.getText()))) {
                                        settings.setText("");
                                        settings.append("\n\n\n\nLearning Rate: "
                                                + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                                        settings.append("\n\nMomentum: "
                                                + net.get(resultsPane.getSelectedIndex()).getMomentum());
                                        settings.append("\n\nTraining Style: ");
                                        if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) {
                                            settings.append("batch");
                                            batchOn.setSelected(true);
                                        } else {
                                            settings.append("online");
                                            onlineOn.setSelected(true);
                                        }
                                        settings.append("\n\nTraining End Condition: ");
                                        if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) {
                                            settings.append("Iterative");
                                            settings.append("\n\nIterations: "
                                                    + net.get(resultsPane.getSelectedIndex()).getIterations());
                                        } else {
                                            settings.append("Ideal Error");
                                            settings.append("\n\nIdeal Error: "
                                                    + net.get(resultsPane.getSelectedIndex()).getIdealError());
                                        }
                                        modifyFFNDialog.setVisible(true);
                                    } else {
                                        JOptionPane.showMessageDialog(modifyFFNDialog,
                                                "Invalid Number of Iterations", "Math Error",
                                                JOptionPane.ERROR_MESSAGE);
                                    }
                                } else {
                                    JOptionPane.showMessageDialog(iterationsDialog, "Field not filled out",
                                            "Form Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        });
                        iterationsCancel.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                iterationsDialog.setVisible(false);
                            }
                        });
                        iterationsDialog.setVisible(true);
                    }
                });

                modifyFFN.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if (!learningRateTF.getText().equals("")) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setLearningRate(Double.parseDouble(learningRateTF.getText()));
                            learningRateTF.setText("");
                        }
                        if (!momentumTF.getText().equals("")) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setMomentum(Double.parseDouble(momentumTF.getText()));
                            momentumTF.setText("");
                        }
                        if (batchOn.isSelected()) {
                            net.get(resultsPane.getSelectedIndex()).setBatchvOnline(true);
                        } else {
                            net.get(resultsPane.getSelectedIndex()).setBatchvOnline(false);
                        }

                        modifyFFNDialog.setVisible(false);
                    }
                });

                learningRateTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if (learningRateTF.getText() != "") {
                            net.get(resultsPane.getSelectedIndex())
                                    .setLearningRate(Double.parseDouble(learningRateTF.getText()));
                        }
                        settings.setText("");
                        settings.append("\n\n\n\nLearning Rate: "
                                + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                        settings.append(
                                "\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum());
                        settings.append("\n\nTraining Style: ");

                        if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) {
                            settings.append("batch");
                            batchOn.setSelected(true);
                        } else {
                            settings.append("online");
                            onlineOn.setSelected(true);
                        }
                        settings.append("\n\nTraining End Condition: ");
                        if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) {
                            settings.append("Iterative");
                            settings.append("\n\nIterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getIterations());
                        } else {
                            settings.append("Ideal Error");
                            settings.append("\n\nIdeal Error: "
                                    + net.get(resultsPane.getSelectedIndex()).getIdealError());
                        }
                        modifyFFNDialog.setVisible(true);
                    }
                });
                momentumTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if (momentumTF.getText() != "") {
                            net.get(resultsPane.getSelectedIndex())
                                    .setMomentum(Double.parseDouble(momentumTF.getText()));
                        }
                        settings.setText("");
                        settings.append("\n\n\n\nLearning Rate: "
                                + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                        settings.append(
                                "\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum());
                        settings.append("\n\nTraining Style: ");
                        if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) {
                            settings.append("batch");
                            batchOn.setSelected(true);
                        } else {
                            settings.append("online");
                            onlineOn.setSelected(true);
                        }
                        settings.append("\n\nTraining End Condition: ");
                        if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) {
                            settings.append("Iterative");
                            settings.append("\n\nIterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getIterations());
                        } else {
                            settings.append("Ideal Error");
                            settings.append("\n\nIdeal Error: "
                                    + net.get(resultsPane.getSelectedIndex()).getIdealError());
                        }
                        modifyFFNDialog.setVisible(true);
                    }
                });
                cancelModifyFFN.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        modifyFFNDialog.setVisible(false);
                    }
                });
                modifyFFNDialog.setVisible(true);
            }
            if (resultsPane.getTabCount() != 0
                    && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) {
                modifySOMDialog = new JDialog(mainWindow, "Network Settings", true);
                modifySOMDialog.setSize(500, 400);
                modifySOMDialog.setLayout(new GridBagLayout());
                GridBagConstraints asdf = new GridBagConstraints();
                asdf.gridwidth = 5;
                asdf.gridheight = 1;
                asdf.gridx = 0;
                asdf.gridy = 0;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                modifySOMDialog.add(new JSeparator(), asdf);
                asdf.gridwidth = 5;
                asdf.gridheight = 15;
                asdf.weightx = 1.0;
                asdf.weighty = 1.0;
                asdf.gridx = 0;
                asdf.gridy = 1;
                asdf.fill = GridBagConstraints.BOTH;
                settings = new JTextArea();
                settings.setEditable(false);
                settings.setBorder(BorderFactory.createEtchedBorder());
                modifySOMDialog.add(settings, asdf);
                asdf.fill = GridBagConstraints.HORIZONTAL;
                asdf.gridwidth = 5;
                asdf.gridheight = 1;
                asdf.gridx = 0;
                asdf.gridy = 16;
                modifySOMDialog.add(new JSeparator(), asdf);
                asdf.gridwidth = 2;
                asdf.gridx = 7;
                asdf.gridy = 0;
                modifySOMDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 1;
                mIterationL = new JLabel("Set Number of Iterations:");
                modifySOMDialog.add(mIterationL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 2;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                mIterationTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
                mIterationTF.setText("");
                modifySOMDialog.add(mIterationTF, asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 3;
                mLRL = new JLabel("Set Learning Rate (0-1):");
                modifySOMDialog.add(mLRL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 4;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                mLRTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance()));
                mLRTF.setText("");
                modifySOMDialog.add(mLRTF, asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 5;
                mMaxL = new JLabel("Set Data Maximum:");
                modifySOMDialog.add(mMaxL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 6;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                mMaxTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance()));
                mMaxTF.setText("");
                modifySOMDialog.add(mMaxTF, asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridx = 7;
                asdf.gridy = 7;
                mMinL = new JLabel("Set Data Minimum:");
                modifySOMDialog.add(mMinL, asdf);
                asdf.gridx = 7;
                asdf.gridy = 8;
                asdf.fill = GridBagConstraints.HORIZONTAL;
                mMinTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance()));
                mMinTF.setText("");
                modifySOMDialog.add(mMinTF, asdf);
                asdf.fill = GridBagConstraints.HORIZONTAL;
                asdf.gridy = 16;
                modifySOMDialog.add(new JSeparator(), asdf);
                asdf.fill = GridBagConstraints.NONE;
                asdf.gridwidth = 1;
                asdf.gridx = 3;
                asdf.gridy = 17;
                asdf.anchor = GridBagConstraints.PAGE_END;
                modifySOM = new JButton("OK");
                modifySOMDialog.add(modifySOM, asdf);
                asdf.gridx = 7;
                cancelModifySOM = new JButton("Cancel");
                modifySOMDialog.add(cancelModifySOM, asdf);
                settings.setText("");
                settings.append("\n\nNumber of Iterations: "
                        + net.get(resultsPane.getSelectedIndex()).getNumIterations());
                settings.append(
                        "\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax());
                settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin());

                mIterationTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if (mIterationTF.getText() != "") {
                            net.get(resultsPane.getSelectedIndex())
                                    .setNumIterations(Integer.parseInt(mIterationTF.getText()));

                            settings.setText("");
                            settings.append("\n\nNumber of Iterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getNumIterations());
                            settings.append("\n\nLearning Rate: "
                                    + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                            settings.append("\n\nData Maximum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMax());
                            settings.append("\n\nData Minimum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMin());
                        }
                    }
                });

                mLRTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if ((mLRTF.getText() != "") && ((Double.parseDouble(mLRTF.getText())) <= 1.0)) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setLearningRate(Double.parseDouble(mLRTF.getText()));

                            settings.setText("");
                            settings.append("\n\nNumber of Iterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getNumIterations());
                            settings.append("\n\nLearning Rate: "
                                    + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                            settings.append("\n\nData Maximum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMax());
                            settings.append("\n\nData Minimum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMin());
                        } else {
                            JOptionPane.showMessageDialog(mLRTF, "Pick a number from 0 - 1", "Incorrect Value",
                                    JOptionPane.ERROR_MESSAGE);
                            mLRTF.setText("");
                        }
                    }
                });

                mMaxTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if ((mMaxTF.getText() != "") && (((Double.parseDouble(mMaxTF.getText())) > net
                                .get(resultsPane.getSelectedIndex()).getDataMin()))) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setDataMax(Double.parseDouble(mMaxTF.getText()));

                            settings.setText("");
                            settings.append("\n\nNumber of Iterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getNumIterations());
                            settings.append("\n\nLearning Rate: "
                                    + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                            settings.append("\n\nData Maximum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMax());
                            settings.append("\n\nData Minimum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMin());
                        } else {
                            JOptionPane.showMessageDialog(mMaxTF, "Max value must be greater than Min value",
                                    "Incorrect Value", JOptionPane.ERROR_MESSAGE);
                            mMaxTF.setText("");
                        }
                    }
                });

                mMinTF.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if ((mMinTF.getText() != "") && ((Double.parseDouble(mMinTF.getText())) < net
                                .get(resultsPane.getSelectedIndex()).getDataMax())) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setDataMin(Double.parseDouble(mMinTF.getText()));

                            settings.setText("");
                            settings.append("\n\nNumber of Iterations: "
                                    + net.get(resultsPane.getSelectedIndex()).getNumIterations());
                            settings.append("\n\nLearning Rate: "
                                    + net.get(resultsPane.getSelectedIndex()).getLearningRate());
                            settings.append("\n\nData Maximum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMax());
                            settings.append("\n\nData Minimum: "
                                    + net.get(resultsPane.getSelectedIndex()).getDataMin());
                        } else {
                            JOptionPane.showMessageDialog(mMinTF, "Min value must be less than Max value",
                                    "Incorrect Value", JOptionPane.ERROR_MESSAGE);
                            mMinTF.setText("");
                        }
                    }
                });

                modifySOM.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        boolean error = false;
                        if (!("".equals(mIterationTF.getText()))) {
                            net.get(resultsPane.getSelectedIndex())
                                    .setNumIterations(Integer.parseInt(mIterationTF.getText()));
                        }
                        if (!("".equals(mLRTF.getText()))) {
                            if ((Double.parseDouble(mLRTF.getText())) > 1.0) {
                                error = true;
                                mLRTF.setText("");
                            } else
                                net.get(resultsPane.getSelectedIndex())
                                        .setLearningRate(Double.parseDouble(mLRTF.getText()));
                        }
                        if (!("".equals(mMaxTF.getText()))) {
                            if (((Double.parseDouble(mMaxTF.getText())) < net
                                    .get(resultsPane.getSelectedIndex()).getDataMin())) {
                                error = true;
                                mMaxTF.setText("");
                            } else
                                net.get(resultsPane.getSelectedIndex())
                                        .setDataMax(Double.parseDouble(mMaxTF.getText()));
                        }
                        if (!("".equals(mMinTF.getText()))) {
                            if ((Double.parseDouble(mMinTF.getText())) > net.get(resultsPane.getSelectedIndex())
                                    .getDataMax()) {
                                error = true;
                                mMinTF.setText("");
                            } else
                                net.get(resultsPane.getSelectedIndex())
                                        .setDataMin(Double.parseDouble(mMinTF.getText()));
                        }

                        if (error == true) {
                            JOptionPane.showMessageDialog(modifySOMDialog,
                                    "One or more fields have incorrect values", "Incorrect Value",
                                    JOptionPane.ERROR_MESSAGE);
                        } else {
                            modifySOMDialog.setVisible(false);
                            readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Map:\n");
                            printInitMap();
                        }

                    }
                });

                cancelModifySOM.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        modifySOMDialog.setVisible(false);
                    }
                });

                modifySOMDialog.setVisible(true);
            }
        }

    });

    modify.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : changeConfig.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //The following code is for the newNet button under file:

    //create a dialog to be activated when "New Network" is pressed in the file menu
    newDialog = new JDialog(mainWindow, "New Network", true);
    newDialog.setSize(375, 100);
    newDialog.setLayout(new GridLayout(3, 2)); //going to change the layout to GridBagLayout for better customization

    name = new JLabel("Network Name:");
    newName = new JTextField(10);
    type = new JLabel("Type of Network:");
    netTypes = new String[] { "Feed Forward Network", "Self-Organizing Map" };
    netType = new JComboBox<String>(netTypes);
    netType.setSelectedItem("Feed Forward Network");
    createNewNet = new JButton("create");
    cancelNew = new JButton("cancel");
    newDialog.add(name);
    newDialog.add(newName);
    newDialog.add(type);
    newDialog.add(netType);
    newDialog.add(createNewNet);
    newDialog.add(cancelNew);

    //utilities for a second dialog(Feed Forward Network) in the process of creating a new network   
    number = new JLabel("Enter the number of layers you want for your network:");
    howManyLayers = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
    createFFNArchitecture = new JButton("OK");
    cancelFFN = new JButton("Cancel");

    howManyNodes = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
    createFFN = new JButton("OK");
    cancelNodes = new JButton("Cancel");

    //Written by Michael Scott
    somLattice = new JLabel("   Lattice number for your Map:");
    somLatticeField = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
    somLatticeField.setFocusLostBehavior(1);
    somMax = new JLabel("   Maximum value of your input (if known):");
    somMaxField = new JFormattedTextField(new NumberFormatter(NumberFormat.getInstance()));
    somMaxField.setFocusLostBehavior(1);
    somMin = new JLabel("   Minimum value of your input (if known):");
    somMinField = new JFormattedTextField(new NumberFormatter(NumberFormat.getInstance()));
    somMinField.setFocusLostBehavior(1);
    somDim = new JLabel("   Node Dimensions:");
    somDimField = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
    somDimField.setFocusLostBehavior(1);
    createSOM = new JButton("OK");
    cancelSOM = new JButton("Cancel");

    //displays the newDialog window when newNet is pressed
    newNet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {

            newDialog.setVisible(true);
        }
    });

    newwer.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            newDialog.setVisible(true);
        }
    });

    //makes hitting enter in the text box do the same thing as clicking "create"
    newName.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : createNewNet.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //when create net is pressed, this reads the selections from the newNet dialog and creates the approriate next dialog
    createNewNet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int test;
            test = 0;
            for (StringBuffer names : netName) {
                if (names.toString().equals(newName.getText()))
                    test = 1;
            }
            if (test == 0)
                if (!newName.getText().equals("")) {
                    if (netType.getSelectedIndex() == 0) { //if the net selected is Feed Forward, create and display the prompt for a feed forward network
                        newDialog.setVisible(false);
                        fFNDialog = new JDialog(mainWindow, newName.getText(), true);
                        fFNDialog.setSize(919, 65);
                        fFNDialog.setLayout(new GridLayout(2, 2));
                        fFNDialog.add(number);
                        fFNDialog.add(howManyLayers);
                        fFNDialog.add(createFFNArchitecture);
                        fFNDialog.add(cancelFFN);
                        fFNDialog.setVisible(true);
                    }
                    //Written by Michael Scott
                    if (netType.getSelectedIndex() == 1) {
                        newDialog.setVisible(false);
                        sOMDialog = new JDialog(mainWindow, newName.getText(), true);
                        sOMDialog.setSize(500, 180);
                        sOMDialog.setLayout(new GridLayout(5, 2));
                        sOMDialog.add(somLattice);
                        sOMDialog.add(somLatticeField);
                        sOMDialog.add(somDim);
                        sOMDialog.add(somDimField);
                        sOMDialog.add(somMax);
                        sOMDialog.add(somMaxField);
                        sOMDialog.add(somMin);
                        sOMDialog.add(somMinField);
                        sOMDialog.add(createSOM);
                        sOMDialog.add(cancelSOM);
                        sOMDialog.setVisible(true);

                    }
                } else
                    JOptionPane.showMessageDialog(createNewNet, "Network must have a Name",
                            "Namelessness Error", JOptionPane.ERROR_MESSAGE);
            else {
                JOptionPane.showMessageDialog(createNewNet, "Network " + newName.getText() + " already exists",
                        "Existential Naming Error", JOptionPane.ERROR_MESSAGE);
                newName.setText("");
            }
        }

    });
    //beginning of section about creating Feed Forward Networks   
    //cancel clears the name field and hides the newDialog dialog
    cancelNew.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            newDialog.setVisible(false);
            newName.setText("");
        }
    });

    //makes hitting enter the same as clicking "ok"
    howManyLayers.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : createFFNArchitecture.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //create a prompt for the first layer to determine how many nodes will go into the first layer
    createFFNArchitecture.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (!howManyLayers.getText().equals("")
                    && (layers = Integer.parseInt(howManyLayers.getText())) > 1) {
                nodeConfiguration = new int[layers]; //create an array to hold the node configuration that will be passed to the Net constructor
                layer = 1; //create a variable to hold the current layer the prompt series is on
                numberofNodes = new JLabel("How many nodes do you want in layer " + layer + "?");
                fFNDialog.setVisible(false);
                howManyNodesDialog = new JDialog(mainWindow, newName.getText(), true);
                howManyNodesDialog.setSize(919, 65);
                howManyNodesDialog.setLayout(new GridLayout(2, 2));
                howManyNodesDialog.add(numberofNodes);
                howManyNodesDialog.add(howManyNodes);
                howManyNodesDialog.add(createFFN);
                howManyNodesDialog.add(cancelNodes);
                howManyNodesDialog.setVisible(true);
            } else {
                //if the string is not valid, pop up an error message
                JOptionPane.showMessageDialog(fFNDialog,
                        "<html>Number Out of Bounds<br>Please Enter a Number Greater than 1</html>",
                        "Out of Bounds", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    //runs each time ok is pressed, until all the layers have a vaule for the number of nodes in the layer
    createFFN.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (!howManyNodes.getText().equals("")
                    && (nodeConfiguration[layer - 1] = Integer.parseInt(howManyNodes.getText())) > 0) {
                if (layer == layers) {
                    try {
                        //adds a close button to the top corner of each tab
                        title.add(new JLabel(newName.getText() + " "));
                        close.add(new JButton("X"));
                        close.get(openNets).setActionCommand(newName.getText());
                        close.get(openNets).setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
                        close.get(openNets).setMargin(new Insets(0, 0, 0, 0));
                        tabPanel.add(new JPanel(new GridBagLayout()));
                        tabPanel.get(openNets).setOpaque(false);
                        GridBagConstraints grid = new GridBagConstraints();
                        grid.fill = GridBagConstraints.HORIZONTAL;
                        grid.gridx = 0;
                        grid.gridy = 0;
                        grid.weightx = 1;
                        tabPanel.get(openNets).add(title.get(openNets), grid);
                        grid.gridx = 1;
                        grid.gridy = 0;
                        grid.weightx = 0;
                        tabPanel.get(openNets).add(close.get(openNets), grid);

                        //adds a loading bar
                        loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER));
                        loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT);
                        loadingBar.get(openNets).setVisible(false);
                        //creates and sets the network configuration
                        net.add(new FullyConnectedFeedForwardNet(nodeConfiguration));

                        netKind.add(new StringBuffer(netType.getSelectedItem().toString()));
                        netName.add(new StringBuffer(newName.getText()));
                        oneNet.add(new JPanel());
                        oneNet.get(openNets).setLayout(new GridBagLayout());
                        GridBagConstraints constraints = new GridBagConstraints();
                        constraints.fill = GridBagConstraints.BOTH;

                        //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar
                        readOut.add(new JTextArea(""));
                        readOutLocale.add(new JScrollPane(readOut.get(openNets)));
                        readOut.get(openNets).setEditable(false);
                        constraints.gridx = 0;
                        constraints.gridy = 0;
                        constraints.weighty = 1.0;
                        constraints.weightx = 1.0;
                        constraints.gridwidth = 2;
                        constraints.ipady = 90;
                        oneNet.get(openNets).add(readOutLocale.get(openNets), constraints);
                        constraints.fill = GridBagConstraints.HORIZONTAL;
                        constraints.gridx = 0;
                        constraints.gridy = 1;
                        constraints.ipady = 0;
                        constraints.gridwidth = 2;
                        constraints.anchor = GridBagConstraints.PAGE_END;

                        //add everythign to the tabbed pane
                        oneNet.get(openNets).add(loadingBar.get(openNets), constraints);
                        resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets));
                        resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets));

                        path.add("");

                        //display the starting configuration of the network
                        readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n");
                        resultsPane.setSelectedIndex(openNets++);
                        printConnections();

                        //erases all the text in the setup fields and closes the window
                        howManyNodes.setValue(null);
                        howManyLayers.setText("");
                        newName.setText("");
                        howManyNodesDialog.setVisible(false);

                        //unfortunately difficult way that I made to add the close button functionality to close a tab
                        //it works, but there has to be a better way to do this
                        close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() {
                            public void actionPerformed(final ActionEvent ae) {
                                int result;
                                result = 0;
                                for (StringBuffer names : netName) {
                                    if (ae.getActionCommand().equals(names.toString())) {
                                        result = JOptionPane.showConfirmDialog(createFFN,
                                                "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>",
                                                "Close Network", JOptionPane.OK_CANCEL_OPTION);
                                        resultsPane.setSelectedIndex(netName.indexOf(names));
                                    }
                                }
                                if (result == JOptionPane.OK_OPTION) {
                                    net.remove(resultsPane.getSelectedIndex());
                                    oneNet.remove(resultsPane.getSelectedIndex());
                                    readOutLocale.remove(resultsPane.getSelectedIndex());
                                    readOut.remove(resultsPane.getSelectedIndex());
                                    loadingBar.remove(resultsPane.getSelectedIndex());
                                    tabPanel.remove(resultsPane.getSelectedIndex());
                                    title.remove(resultsPane.getSelectedIndex());
                                    close.remove(resultsPane.getSelectedIndex());
                                    netName.remove(resultsPane.getSelectedIndex());
                                    resultsPane.remove(resultsPane.getSelectedIndex());
                                    openNets--;
                                }
                            }
                        });
                    } catch (OutOfMemoryError e) {
                        JOptionPane.showMessageDialog(mainWindow,
                                "<html>Net too Large for Memory.<br>Try Closing some of the Nets.</html>",
                                "Memory Error", JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    layer++;
                    howManyNodes.setText("");
                    numberofNodes.setText("How many nodes do you want in layer " + layer + "?");
                }

            } else {
                JOptionPane.showMessageDialog(createFFN,
                        "<html>Number Out of Bounds<br>Please Enter a Number Greater than 0", "Out of Bounds",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    //makes hitting enter in text box the same as clicking ok
    howManyNodes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            for (ActionListener a : createFFN.getActionListeners()) {
                a.actionPerformed(ae);
            }
        }
    });

    //cancels the node prompt
    cancelNodes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            newName.setText("");
            howManyLayers.setText("");
            howManyNodes.setText("");
            howManyNodesDialog.setVisible(false);
        }
    });

    //cancel clears both name fields so far filled in the series of dialogs and hides the dialog
    cancelFFN.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            newName.setText("");
            howManyLayers.setText("");
            fFNDialog.setVisible(false);
        }
    });
    //end of section about creating FFNs
    //end of section about newNet   

    //Method to create a SOM
    createSOM.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            if (somLatticeField.getText().equals("") || somDimField.getText().equals("")) {
                JOptionPane.showMessageDialog(createSOM, "<html>Empty Field<br>Please Fill All Fields",
                        "Empty Field", JOptionPane.ERROR_MESSAGE);
            } else {
                if (somMaxField.getText().equals(""))
                    somMaxField.setText("100");
                if (somMinField.getText().equals(""))
                    somMinField.setText("0");
                if (Double.parseDouble(somMaxField.getText().replace(",", "")) < Double
                        .parseDouble(somMinField.getText().replace(",", ""))) {
                    JOptionPane.showMessageDialog(createSOM, "MIN GREATER THAN MAX!!!!", "Stupidity Error",
                            JOptionPane.ERROR_MESSAGE);
                }

                try {
                    //adds a close button to the top corner of each tab
                    title.add(new JLabel(newName.getText() + " "));
                    close.add(new JButton("X"));
                    close.get(openNets).setActionCommand(newName.getText());
                    close.get(openNets).setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
                    close.get(openNets).setMargin(new Insets(0, 0, 0, 0));
                    tabPanel.add(new JPanel(new GridBagLayout()));
                    tabPanel.get(openNets).setOpaque(false);
                    GridBagConstraints grid = new GridBagConstraints();
                    grid.fill = GridBagConstraints.HORIZONTAL;
                    grid.gridx = 0;
                    grid.gridy = 0;
                    grid.weightx = 1;
                    tabPanel.get(openNets).add(title.get(openNets), grid);
                    grid.gridx = 1;
                    grid.gridy = 0;
                    grid.weightx = 0;
                    tabPanel.get(openNets).add(close.get(openNets), grid);

                    //adds a loading bar
                    loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER));
                    loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT);
                    loadingBar.get(openNets).setVisible(false);
                    //creates and sets the network configuration
                    net.add(new SelfOrganizingMap());

                    netKind.add(new StringBuffer(netType.getSelectedItem().toString()));
                    netName.add(new StringBuffer(newName.getText()));
                    oneNet.add(new JPanel());
                    oneNet.get(openNets).setLayout(new GridBagLayout());
                    GridBagConstraints constraints = new GridBagConstraints();
                    constraints.fill = GridBagConstraints.BOTH;

                    //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar
                    readOut.add(new JTextArea(""));
                    readOutLocale.add(new JScrollPane(readOut.get(openNets)));
                    readOut.get(openNets).setEditable(false);
                    constraints.gridx = 0;
                    constraints.gridy = 0;
                    constraints.weighty = 1.0;
                    constraints.weightx = 1.0;
                    constraints.gridwidth = 2;
                    constraints.ipady = 90;
                    oneNet.get(openNets).add(readOutLocale.get(openNets), constraints);
                    constraints.fill = GridBagConstraints.HORIZONTAL;
                    constraints.gridx = 0;
                    constraints.gridy = 1;
                    constraints.ipady = 0;
                    constraints.gridwidth = 2;
                    constraints.anchor = GridBagConstraints.PAGE_END;

                    //add everythign to the tabbed pane
                    oneNet.get(openNets).add(loadingBar.get(openNets), constraints);
                    resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets));
                    resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets));

                    path.add("");

                    //display the starting configuration of the network
                    readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n");
                    resultsPane.setSelectedIndex(openNets++);
                    try {
                        net.get(resultsPane.getSelectedIndex())
                                .setLatticeValue(Integer.parseInt(somLatticeField.getText().replace(",", "")));
                        net.get(resultsPane.getSelectedIndex())
                                .setDataMax(Double.parseDouble(somMaxField.getText().replace(",", "")));
                        net.get(resultsPane.getSelectedIndex())
                                .setDataMin(Double.parseDouble(somMinField.getText().replace(",", "")));
                        net.get(resultsPane.getSelectedIndex())
                                .setInputDimensions(Integer.parseInt(somDimField.getText().replace(",", "")));
                        net.get(resultsPane.getSelectedIndex()).runNet();
                        readOut.get(resultsPane.getSelectedIndex()).append("Initial Untrained Map:\n");
                        printInitMap();

                        if (!getColorMap.isVisible()) {
                            util.addSeparator();
                            util.add(getColorMap);
                            getColorMap.setVisible(true);
                        }

                        //erases all the text in the setup fields and closes the window
                        newName.setText("");
                        somLatticeField.setText("");
                        somDimField.setText("");
                        somMaxField.setText("");
                        somMinField.setText("");
                        sOMDialog.setVisible(false);

                        //unfortunately difficult way that I made to add the close button functionality to close a tab
                        //it works, but there has to be a better way to do this
                        close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() {
                            public void actionPerformed(final ActionEvent ae) {
                                int result;
                                result = 0;
                                for (StringBuffer names : netName) {
                                    if (ae.getActionCommand().equals(names.toString())) {
                                        result = JOptionPane.showConfirmDialog(createSOM,
                                                "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>",
                                                "Close Network", JOptionPane.OK_CANCEL_OPTION);
                                        resultsPane.setSelectedIndex(netName.indexOf(names));
                                    }
                                }
                                if (result == JOptionPane.OK_OPTION) {
                                    net.remove(resultsPane.getSelectedIndex());
                                    oneNet.remove(resultsPane.getSelectedIndex());
                                    readOutLocale.remove(resultsPane.getSelectedIndex());
                                    readOut.remove(resultsPane.getSelectedIndex());
                                    loadingBar.remove(resultsPane.getSelectedIndex());
                                    tabPanel.remove(resultsPane.getSelectedIndex());
                                    title.remove(resultsPane.getSelectedIndex());
                                    close.remove(resultsPane.getSelectedIndex());
                                    netName.remove(resultsPane.getSelectedIndex());
                                    resultsPane.remove(resultsPane.getSelectedIndex());
                                    openNets--;
                                }
                            }
                        });
                    } catch (Exception e) {
                        net.remove(resultsPane.getSelectedIndex());
                        oneNet.remove(resultsPane.getSelectedIndex());
                        readOutLocale.remove(resultsPane.getSelectedIndex());
                        readOut.remove(resultsPane.getSelectedIndex());
                        loadingBar.remove(resultsPane.getSelectedIndex());
                        tabPanel.remove(resultsPane.getSelectedIndex());
                        title.remove(resultsPane.getSelectedIndex());
                        close.remove(resultsPane.getSelectedIndex());
                        netName.remove(resultsPane.getSelectedIndex());
                        resultsPane.remove(resultsPane.getSelectedIndex());
                        openNets--;
                        JOptionPane.showMessageDialog(sOMDialog, "Numbers too large to parse", "Parse error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } catch (OutOfMemoryError e) {
                    JOptionPane.showMessageDialog(mainWindow,
                            "<html>Net too Large for Memory.<br>Try Closing some of the Nets.</html>",
                            "Memory Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    cancelSOM.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            newName.setText("");
            somLatticeField.setText("");
            somMaxField.setText("");
            somMinField.setText("");
            sOMDialog.setVisible(false);
        }
    });

    //end of SOM creation
    mainWindow.setVisible(true);
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openUIOptionsDialog() {
    JPanel options = new JPanel(new GridLayout(0, 1));
    options.setName("User Interface");
    // Button size
    ActionListener buttonSizeRadioListener = new ActionListener() {
        @Override//from  ww w .  j  a v a  2s .  com
        public void actionPerformed(ActionEvent e) {
            prefs.setButtonSize(e.getActionCommand());
        }
    };
    JRadioButton small = new JRadioButton("Small");
    small.setActionCommand(BUTTON_SIZE_SMALL);
    small.addActionListener(buttonSizeRadioListener);
    if (BUTTON_SIZE_SMALL.equals(prefs.getButtonSize()))
        small.setSelected(true);
    JRadioButton medium = new JRadioButton("Medium");
    medium.setActionCommand(BUTTON_SIZE_MEDIUM);
    medium.addActionListener(buttonSizeRadioListener);
    if (BUTTON_SIZE_MEDIUM.equals(prefs.getButtonSize()))
        medium.setSelected(true);
    JRadioButton large = new JRadioButton("Large");
    large.setActionCommand(BUTTON_SIZE_LARGE);
    large.addActionListener(buttonSizeRadioListener);
    if (BUTTON_SIZE_LARGE.equals(prefs.getButtonSize()))
        large.setSelected(true);

    ButtonGroup group = new ButtonGroup();
    group.add(small);
    group.add(medium);
    group.add(large);

    // Close windows on stop
    final JCheckBox closeAllWindowsOnStopCheckBox = new JCheckBox("Close all windows on Stop");
    closeAllWindowsOnStopCheckBox.setSelected(prefs.isCloseAllWindowsOnStop());

    // Refresh interval
    JPanel refreshIntervalPanel = new JPanel();
    final JTextField refreshIntervalField = new JTextField(5);
    refreshIntervalPanel.add(new JLabel("Refresh interval for cpu, screen, etc. (ms):"));

    refreshIntervalField.setText("" + prefs.getRefreshIntervalMs());
    refreshIntervalPanel.add(refreshIntervalField);

    // Setup panel
    options.add(new JLabel("Button size :"));
    options.add(small);
    options.add(medium);
    options.add(large);
    options.add(closeAllWindowsOnStopCheckBox);
    options.add(refreshIntervalPanel);
    options.add(new JLabel("Larger value greatly increases emulation speed"));

    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, options, "Preferences",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) {
        // save
        prefs.setButtonSize(group.getSelection().getActionCommand());
        prefs.setCloseAllWindowsOnStop(closeAllWindowsOnStopCheckBox.isSelected());
        int refreshIntervalMs = 0;
        try {
            refreshIntervalMs = Integer.parseInt(refreshIntervalField.getText());
        } catch (NumberFormatException e) {
            // noop
        }
        refreshIntervalMs = Math.max(Math.min(refreshIntervalMs, 10000), 10);
        prefs.setRefreshIntervalMs(refreshIntervalMs);
        applyPrefsToUI();
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Create the configuration menu/*  w  w w.  j a  va 2  s.co  m*/
 * 
 * @return The configuration menu
 */
private JMenu setupConfigurationMenu() {
    final JMenu menu = new JMenu("Configure");
    ButtonGroup buttonGroup;

    menu.setMnemonic(KeyEvent.VK_C);
    menu.setToolTipText("Menu items related to configuration");

    buttonGroup = new ButtonGroup();
    setupOutputAssertionLanguage = new JCheckBoxMenuItem[FORMATS.length + 1];
    setupOutputAssertionLanguage[0] = new JCheckBoxMenuItem("Output Format: Auto");
    buttonGroup.add(setupOutputAssertionLanguage[0]);
    menu.add(setupOutputAssertionLanguage[0]);

    for (int index = 0; index < FORMATS.length; ++index) {
        setupOutputAssertionLanguage[index + 1] = new JCheckBoxMenuItem("Output Format: " + FORMATS[index]);
        buttonGroup.add(setupOutputAssertionLanguage[index + 1]);
        menu.add(setupOutputAssertionLanguage[index + 1]);
    }
    setupOutputAssertionLanguage[0].setSelected(true);

    menu.addSeparator();

    buttonGroup = new ButtonGroup();
    setupOutputModelTypeAssertions = new JCheckBoxMenuItem("Output Assertions Only");
    buttonGroup.add(setupOutputModelTypeAssertions);
    menu.add(setupOutputModelTypeAssertions);

    setupOutputModelTypeAssertionsAndInferences = new JCheckBoxMenuItem("Output Assertions and Inferences");
    buttonGroup.add(setupOutputModelTypeAssertionsAndInferences);
    menu.add(setupOutputModelTypeAssertionsAndInferences);

    setupOutputModelTypeAssertions.setSelected(true);

    menu.addSeparator();

    setupAllowMultilineResultOutput = new JCheckBoxMenuItem(
            "Allow Multiple Lines of Text Per Row in SPARQL Query Output");
    setupAllowMultilineResultOutput.setToolTipText("Wrap long values into multiple lines in a display cell");
    setupAllowMultilineResultOutput.setSelected(false);
    menu.add(setupAllowMultilineResultOutput);

    setupOutputFqnNamespaces = new JCheckBoxMenuItem("Show FQN Namespaces Instead of Prefixes in Query Output");
    setupOutputFqnNamespaces
            .setToolTipText("Use the fully qualified namespace. If unchecked use the prefix, if defined");
    setupOutputFqnNamespaces.setSelected(false);
    menu.add(setupOutputFqnNamespaces);

    setupOutputDatatypesForLiterals = new JCheckBoxMenuItem("Show Datatypes on Literals");
    setupOutputDatatypesForLiterals.setToolTipText("Display the datatype after the value, e.g. 4^^xsd:integer");
    setupOutputDatatypesForLiterals.setSelected(false);
    menu.add(setupOutputDatatypesForLiterals);

    setupOutputFlagLiteralValues = new JCheckBoxMenuItem("Flag Literal Values in Query Output");
    setupOutputFlagLiteralValues.setToolTipText("Includes the text 'Lit:' in front of any literal values");
    setupOutputFlagLiteralValues.setSelected(false);
    menu.add(setupOutputFlagLiteralValues);

    setupApplyFormattingToLiteralValues = new JCheckBoxMenuItem("Apply Formatting to Literal Values");
    setupApplyFormattingToLiteralValues.setToolTipText(
            "Apply the XSD-based formatting defined in the configuration to literal values in SPARQL results and tree view display");
    setupApplyFormattingToLiteralValues.setSelected(true);
    menu.add(setupApplyFormattingToLiteralValues);

    setupDisplayImagesInSparqlResults = new JCheckBoxMenuItem(
            "Display Images in Query Output (Slows Results Retrieval)");
    setupDisplayImagesInSparqlResults.setToolTipText("Attempts to download images linked in the results. "
            + "Can run very slowly depending on number and size of images");
    setupDisplayImagesInSparqlResults.setSelected(true);
    menu.add(setupDisplayImagesInSparqlResults);

    menu.addSeparator();

    buttonGroup = new ButtonGroup();
    setupExportSparqlResultsAsCsv = new JCheckBoxMenuItem(
            "Export SPARQL Results to " + EXPORT_FORMAT_LABEL_CSV);
    setupExportSparqlResultsAsCsv.setToolTipText("Export to Comma Separated Value format");
    buttonGroup.add(setupExportSparqlResultsAsCsv);
    menu.add(setupExportSparqlResultsAsCsv);

    setupExportSparqlResultsAsTsv = new JCheckBoxMenuItem(
            "Export SPARQL Results to " + EXPORT_FORMAT_LABEL_TSV);
    setupExportSparqlResultsAsTsv.setToolTipText("Export to Tab Separated Value format");
    buttonGroup.add(setupExportSparqlResultsAsTsv);
    menu.add(setupExportSparqlResultsAsTsv);

    menu.addSeparator();

    setupSparqlResultsToFile = new JCheckBoxMenuItem("Send SPARQL Results Directly to File");
    setupSparqlResultsToFile.setToolTipText(
            "For large results sets this permits writing to file without trying to render on screen");
    menu.add(setupSparqlResultsToFile);

    menu.addSeparator();

    setupEnableStrictMode = new JCheckBoxMenuItem("Enable Strict Checking Mode");
    setupEnableStrictMode.setSelected(true);
    setupEnableStrictMode.addActionListener(new ReasonerConfigurationChange());
    menu.add(setupEnableStrictMode);

    menu.addSeparator();

    setupFont = new JMenuItem("Font");
    setupFont.setMnemonic(KeyEvent.VK_F);
    setupFont.setToolTipText("Set the font used for the display");
    setupFont.addActionListener(new FontSetupListener());
    menu.add(setupFont);

    menu.addSeparator();

    setupProxyEnabled = new JCheckBoxMenuItem("Enable Proxy");
    setupProxyEnabled.setToolTipText("Pass network SPARQL requests through a proxy");
    setupProxyEnabled.addActionListener(new ProxyStatusChangeListener());
    menu.add(setupProxyEnabled);

    setupProxyConfiguration = new JMenuItem("Proxy Settings");
    setupProxyConfiguration.setToolTipText("Configure the proxy");
    setupProxyConfiguration.addActionListener(new ProxySetupListener());
    menu.add(setupProxyConfiguration);

    return menu;
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openChipOptionsDialog(final int chip) {

    // ------------------------ Disassembly options

    JPanel disassemblyOptionsPanel = new JPanel(new MigLayout("", "[left,grow][left,grow]"));

    // Prepare sample code area
    final RSyntaxTextArea listingArea = new RSyntaxTextArea(20, 90);
    SourceCodeFrame.prepareAreaFormat(chip, listingArea);

    final List<JCheckBox> outputOptionsCheckBoxes = new ArrayList<JCheckBox>();
    ActionListener areaRefresherListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Set<OutputOption> sampleOptions = EnumSet.noneOf(OutputOption.class);
                dumpOptionCheckboxes(outputOptionsCheckBoxes, sampleOptions);
                int baseAddress = framework.getPlatform(chip).getCpuState().getResetAddress();
                int lastAddress = baseAddress;
                Memory sampleMemory = new DebuggableMemory(false);
                sampleMemory.map(baseAddress, 0x100, true, true, true);
                StringWriter writer = new StringWriter();
                Disassembler disassembler;
                if (chip == Constants.CHIP_FR) {
                    sampleMemory.store16(lastAddress, 0x1781); // PUSH    RP
                    lastAddress += 2;//from w  w w.  j  a v a 2s .  co m
                    sampleMemory.store16(lastAddress, 0x8FFE); // PUSH    (FP,AC,R12,R11,R10,R9,R8)
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x83EF); // ANDCCR  #0xEF
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x9F80); // LDI:32  #0x68000000,R0
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x6800);
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x0000);
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x2031); // LD      @(FP,0x00C),R1
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0xB581); // LSL     #24,R1
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x1A40); // DMOVB   R13,@0x40
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x9310); // ORCCR   #0x10
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x8D7F); // POP     (R8,R9,R10,R11,R12,AC,FP)
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x0781); // POP    RP
                    lastAddress += 2;

                    disassembler = new Dfr();
                    disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore
                    disassembler.setOutputFileName(null);
                    disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x"
                            + Format.asHex(lastAddress, 8) + "=CODE" });
                } else {
                    sampleMemory.store32(lastAddress, 0x340B0001); // li      $t3, 0x0001
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x17600006); // bnez    $k1, 0xBFC00020
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x00000000); //  nop
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x54400006); // bnezl   $t4, 0xBFC00028
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x3C0C0000); //  ?lui   $t4, 0x0000
                    lastAddress += 4;

                    int baseAddress16 = lastAddress;
                    int lastAddress16 = baseAddress16;
                    sampleMemory.store32(lastAddress16, 0xF70064F6); // save    $ra,$s0,$s1,$s2-$s7,$fp, 0x30
                    lastAddress16 += 4;
                    sampleMemory.store16(lastAddress16, 0x6500); // nop
                    lastAddress16 += 2;
                    sampleMemory.store32(lastAddress16, 0xF7006476); // restore $ra,$s0,$s1,$s2-$s7,$fp, 0x30
                    lastAddress16 += 4;
                    sampleMemory.store16(lastAddress16, 0xE8A0); // ret
                    lastAddress16 += 2;

                    disassembler = new Dtx();
                    disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore
                    disassembler.setOutputFileName(null);
                    disassembler.processOptions(new String[] { "-m",
                            "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8)
                                    + "=CODE:32",
                            "-m", "0x" + Format.asHex(baseAddress16, 8) + "-0x" + Format.asHex(lastAddress16, 8)
                                    + "=CODE:16" });
                }
                disassembler.setOutputOptions(sampleOptions);
                disassembler.setMemory(sampleMemory);
                disassembler.initialize();
                disassembler.setOutWriter(writer);
                disassembler.disassembleMemRanges();
                disassembler.cleanup();
                listingArea.setText("");
                listingArea.append(writer.toString());
                listingArea.setCaretPosition(0);

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };

    int i = 1;
    for (OutputOption outputOption : OutputOption.allFormatOptions) {
        JCheckBox checkBox = makeOutputOptionCheckBox(chip, outputOption, prefs.getOutputOptions(chip), false);
        if (checkBox != null) {
            outputOptionsCheckBoxes.add(checkBox);
            disassemblyOptionsPanel.add(checkBox, (i % 2 == 0) ? "wrap" : "");
            checkBox.addActionListener(areaRefresherListener);
            i++;
        }
    }
    if (i % 2 == 0) {
        disassemblyOptionsPanel.add(new JLabel(), "wrap");
    }

    // Force a refresh
    areaRefresherListener.actionPerformed(new ActionEvent(outputOptionsCheckBoxes.get(0), 0, ""));

    //        disassemblyOptionsPanel.add(new JLabel("Sample output:", SwingConstants.LEADING), "gapbottom 1, span, split 2, aligny center");
    //        disassemblyOptionsPanel.add(new JSeparator(), "span 2,wrap");
    disassemblyOptionsPanel.add(new JSeparator(), "span 2, gapleft rel, growx, wrap");
    disassemblyOptionsPanel.add(new JLabel("Sample output:"), "span 2,wrap");
    disassemblyOptionsPanel.add(new JScrollPane(listingArea), "span 2,wrap");
    disassemblyOptionsPanel.add(new JLabel("Tip: hover over the option checkboxes for help"),
            "span 2, center, wrap");

    // ------------------------ Emulation options

    JPanel emulationOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));
    emulationOptionsPanel.add(new JLabel());
    JLabel warningLabel = new JLabel(
            "NOTE: these options only take effect after reloading the firmware (or performing a 'Stop and reset')");
    warningLabel.setBackground(Color.RED);
    warningLabel.setOpaque(true);
    warningLabel.setForeground(Color.WHITE);
    warningLabel.setHorizontalAlignment(SwingConstants.CENTER);
    emulationOptionsPanel.add(warningLabel);
    emulationOptionsPanel.add(new JLabel());

    final JCheckBox writeProtectFirmwareCheckBox = new JCheckBox("Write-protect firmware");
    writeProtectFirmwareCheckBox.setSelected(prefs.isFirmwareWriteProtected(chip));
    emulationOptionsPanel.add(writeProtectFirmwareCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, any attempt to write to the loaded firmware area will result in an Emulator error. This can help trap spurious writes"));

    final JCheckBox dmaSynchronousCheckBox = new JCheckBox("Make DMA synchronous");
    dmaSynchronousCheckBox.setSelected(prefs.isDmaSynchronous(chip));
    emulationOptionsPanel.add(dmaSynchronousCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, DMA operations will be performed immediately, pausing the CPU. Otherwise they are performed in a separate thread."));

    final JCheckBox autoEnableTimersCheckBox = new JCheckBox("Auto enable timers");
    autoEnableTimersCheckBox.setSelected(prefs.isAutoEnableTimers(chip));
    emulationOptionsPanel.add(autoEnableTimersCheckBox);
    emulationOptionsPanel
            .add(new JLabel("If checked, timers will be automatically enabled upon reset or firmware load."));

    // Log memory messages
    final JCheckBox logMemoryMessagesCheckBox = new JCheckBox("Log memory messages");
    logMemoryMessagesCheckBox.setSelected(prefs.isLogMemoryMessages(chip));
    emulationOptionsPanel.add(logMemoryMessagesCheckBox);
    emulationOptionsPanel
            .add(new JLabel("If checked, messages related to memory will be logged to the console."));

    // Log serial messages
    final JCheckBox logSerialMessagesCheckBox = new JCheckBox("Log serial messages");
    logSerialMessagesCheckBox.setSelected(prefs.isLogSerialMessages(chip));
    emulationOptionsPanel.add(logSerialMessagesCheckBox);
    emulationOptionsPanel.add(
            new JLabel("If checked, messages related to serial interfaces will be logged to the console."));

    // Log register messages
    final JCheckBox logRegisterMessagesCheckBox = new JCheckBox("Log register messages");
    logRegisterMessagesCheckBox.setSelected(prefs.isLogRegisterMessages(chip));
    emulationOptionsPanel.add(logRegisterMessagesCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, warnings related to unimplemented register addresses will be logged to the console."));

    // Log pin messages
    final JCheckBox logPinMessagesCheckBox = new JCheckBox("Log pin messages");
    logPinMessagesCheckBox.setSelected(prefs.isLogPinMessages(chip));
    emulationOptionsPanel.add(logPinMessagesCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, warnings related to unimplemented I/O pins will be logged to the console."));

    emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL));

    // Alt mode upon Debug
    JPanel altDebugPanel = new JPanel(new FlowLayout());
    Object[] altDebugMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray();
    final JComboBox altModeForDebugCombo = new JComboBox(new DefaultComboBoxModel(altDebugMode));
    for (int j = 0; j < altDebugMode.length; j++) {
        if (altDebugMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponDebug(chip))) {
            altModeForDebugCombo.setSelectedIndex(j);
        }
    }
    altDebugPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip]
            + " runs in sync Debug: "));
    altDebugPanel.add(altModeForDebugCombo);
    emulationOptionsPanel.add(altDebugPanel);
    emulationOptionsPanel
            .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip]
                    + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Debug mode"));

    // Alt mode upon Step
    JPanel altStepPanel = new JPanel(new FlowLayout());
    Object[] altStepMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray();
    final JComboBox altModeForStepCombo = new JComboBox(new DefaultComboBoxModel(altStepMode));
    for (int j = 0; j < altStepMode.length; j++) {
        if (altStepMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponStep(chip))) {
            altModeForStepCombo.setSelectedIndex(j);
        }
    }
    altStepPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip]
            + " runs in sync Step: "));
    altStepPanel.add(altModeForStepCombo);
    emulationOptionsPanel.add(altStepPanel);
    emulationOptionsPanel
            .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip]
                    + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Step mode"));

    // ------------------------ Prepare tabbed pane

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Disassembly Options", null, disassemblyOptionsPanel);
    tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Emulation Options", null, emulationOptionsPanel);

    if (chip == Constants.CHIP_TX) {
        JPanel chipSpecificOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));

        chipSpecificOptionsPanel.add(new JLabel("Eeprom status upon startup:"));

        ActionListener eepromInitializationRadioActionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                prefs.setEepromInitMode(Prefs.EepromInitMode.valueOf(e.getActionCommand()));
            }
        };
        JRadioButton blank = new JRadioButton("Blank");
        blank.setActionCommand(Prefs.EepromInitMode.BLANK.name());
        blank.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.BLANK.equals(prefs.getEepromInitMode()))
            blank.setSelected(true);
        JRadioButton persistent = new JRadioButton("Persistent across sessions");
        persistent.setActionCommand(Prefs.EepromInitMode.PERSISTENT.name());
        persistent.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.PERSISTENT.equals(prefs.getEepromInitMode()))
            persistent.setSelected(true);
        JRadioButton lastLoaded = new JRadioButton("Last Loaded");
        lastLoaded.setActionCommand(Prefs.EepromInitMode.LAST_LOADED.name());
        lastLoaded.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.LAST_LOADED.equals(prefs.getEepromInitMode()))
            lastLoaded.setSelected(true);

        ButtonGroup group = new ButtonGroup();
        group.add(blank);
        group.add(persistent);
        group.add(lastLoaded);

        chipSpecificOptionsPanel.add(blank);
        chipSpecificOptionsPanel.add(persistent);
        chipSpecificOptionsPanel.add(lastLoaded);

        chipSpecificOptionsPanel.add(new JLabel("Front panel type:"));
        final JComboBox frontPanelNameCombo = new JComboBox(new String[] { "D5100_small", "D5100_large" });
        if (prefs.getFrontPanelName() != null) {
            frontPanelNameCombo.setSelectedItem(prefs.getFrontPanelName());
        }
        frontPanelNameCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                prefs.setFrontPanelName((String) frontPanelNameCombo.getSelectedItem());
            }
        });
        chipSpecificOptionsPanel.add(frontPanelNameCombo);

        emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL));

        tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " specific options", null, chipSpecificOptionsPanel);
    }

    // ------------------------ Show it

    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, tabbedPane,
            Constants.CHIP_LABEL[chip] + " options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
            null, null, JOptionPane.DEFAULT_OPTION)) {
        // save output options
        dumpOptionCheckboxes(outputOptionsCheckBoxes, prefs.getOutputOptions(chip));
        // apply
        TxCPUState.initRegisterLabels(prefs.getOutputOptions(chip));

        // save other prefs
        prefs.setFirmwareWriteProtected(chip, writeProtectFirmwareCheckBox.isSelected());
        prefs.setDmaSynchronous(chip, dmaSynchronousCheckBox.isSelected());
        prefs.setAutoEnableTimers(chip, autoEnableTimersCheckBox.isSelected());
        prefs.setLogRegisterMessages(chip, logRegisterMessagesCheckBox.isSelected());
        prefs.setLogSerialMessages(chip, logSerialMessagesCheckBox.isSelected());
        prefs.setLogPinMessages(chip, logPinMessagesCheckBox.isSelected());
        prefs.setLogMemoryMessages(chip, logMemoryMessagesCheckBox.isSelected());
        prefs.setAltExecutionModeForSyncedCpuUponDebug(chip,
                (EmulationFramework.ExecutionMode) altModeForDebugCombo.getSelectedItem());
        prefs.setAltExecutionModeForSyncedCpuUponStep(chip,
                (EmulationFramework.ExecutionMode) altModeForStepCombo.getSelectedItem());

    }
}