List of usage examples for javax.swing JMenu addSeparator
public void addSeparator()
From source file:edu.ku.brc.specify.Specify.java
/** * Create menus/* w w w .j ava 2s.c o m*/ */ public JMenuBar createMenus() { JMenuBar mb = new JMenuBar(); JMenuItem mi; //-------------------------------------------------------------------- //-- File Menu //-------------------------------------------------------------------- JMenu menu = null; if (!UIHelper.isMacOS() || !isWorkbenchOnly) { menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!isWorkbenchOnly) { // Add Menu for switching Collection String title = "Specify.CHANGE_COLLECTION"; //$NON-NLS-1$ String mnu = "Specify.CHANGE_COLL_MNEU"; //$NON-NLS-1$ changeCollectionMenuItem = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); changeCollectionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (SubPaneMgr.getInstance().aboutToShutdown()) { // Actually we really need to start over // "true" means that it should NOT use any cached values it can find to automatically initialize itself // instead it should ask the user any questions as if it were starting over restartApp(null, databaseName, userName, true, false); } } }); menu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent e) { } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuSelected(MenuEvent e) { boolean enable = Uploader.getCurrentUpload() == null && ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getNumOfCollectionsForUser() > 1 && !TaskMgr.areTasksDisabled(); changeCollectionMenuItem.setEnabled(enable); } }); } if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { if (!UIRegistry.isMobile()) { menu.addSeparator(); } String title = "Specify.EXIT"; //$NON-NLS-1$ String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); } mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doExit(true); } }); } menu = UIRegistry.getInstance().createEditMenu(); mb.add(menu); //menu = UIHelper.createMenu(mb, "EditMenu", "EditMneu"); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menu.addSeparator(); String title = "Specify.PREFERENCES"; //$NON-NLS-1$ String mnu = "Specify.PREFERENCES_MNEU";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doPreferences(); } }); mi.setEnabled(true); } //-------------------------------------------------------------------- //-- Data Menu //-------------------------------------------------------------------- JMenu dataMenu = UIHelper.createLocalizedMenu(mb, "Specify.DATA_MENU", "Specify.DATA_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ ResultSetController.addMenuItems(dataMenu); dataMenu.addSeparator(); // Save And New Menu Item Action saveAndNewAction = new AbstractAction(getResourceString("Specify.SAVE_AND_NEW")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.setSaveAndNew(((JCheckBoxMenuItem) e.getSource()).isSelected()); } } }; saveAndNewAction.setEnabled(false); JCheckBoxMenuItem saveAndNewCBMI = new JCheckBoxMenuItem(saveAndNewAction); dataMenu.add(saveAndNewCBMI); UIRegistry.register("SaveAndNew", saveAndNewCBMI); //$NON-NLS-1$ UIRegistry.registerAction("SaveAndNew", saveAndNewAction); //$NON-NLS-1$ mb.add(dataMenu); // Configure Carry Forward Action configCarryForwardAction = new AbstractAction( getResourceString("Specify.CONFIG_CARRY_FORWARD_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.configureCarryForward(); } } }; configCarryForwardAction.setEnabled(false); JMenuItem configCFWMI = new JMenuItem(configCarryForwardAction); dataMenu.add(configCFWMI); UIRegistry.register("ConfigCarryForward", configCFWMI); //$NON-NLS-1$ UIRegistry.registerAction("ConfigCarryForward", configCarryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); //--------------------------------------- // Carry Forward Menu Item (On / Off) Action carryForwardAction = new AbstractAction(getResourceString("Specify.CARRY_FORWARD_CHECKED_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleCarryForward(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isDoCarryForward()); } } }; carryForwardAction.setEnabled(false); JCheckBoxMenuItem carryForwardCBMI = new JCheckBoxMenuItem(carryForwardAction); dataMenu.add(carryForwardCBMI); UIRegistry.register("CarryForward", carryForwardCBMI); //$NON-NLS-1$ UIRegistry.registerAction("CarryForward", carryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); if (!isWorkbenchOnly) { final String AUTO_NUM = "AutoNumbering"; //--------------------------------------- // AutoNumber Menu Item (On / Off) Action autoNumberOnOffAction = new AbstractAction( getResourceString("FormViewObj.SET_AUTONUMBER_ONOFF")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleAutoNumberOnOffState(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isAutoNumberOn()); } } }; autoNumberOnOffAction.setEnabled(false); JCheckBoxMenuItem autoNumCBMI = new JCheckBoxMenuItem(autoNumberOnOffAction); dataMenu.add(autoNumCBMI); UIRegistry.register(AUTO_NUM, autoNumCBMI); //$NON-NLS-1$ UIRegistry.registerAction(AUTO_NUM, autoNumberOnOffAction); //$NON-NLS-1$ } if (System.getProperty("user.name").equals("rods")) { dataMenu.addSeparator(); AbstractAction gpxAction = new AbstractAction("GPS Data") { @Override public void actionPerformed(ActionEvent e) { GPXPanel.getDlgInstance().setVisible(true); } }; JMenuItem gpxMI = new JMenuItem(gpxAction); dataMenu.add(gpxMI); UIRegistry.register("GPXDlg", gpxMI); //$NON-NLS-1$ UIRegistry.registerAction("GPXDlg", gpxAction); //$NON-NLS-1$ } mb.add(dataMenu); SubPaneMgr.getInstance(); // force creating of the Mgr so the menu Actions are created. //-------------------------------------------------------------------- //-- System Menu //-------------------------------------------------------------------- if (!isWorkbenchOnly) { // TODO This needs to be moved into the SystemTask, but right now there is no way // to ask a task for a menu. menu = UIHelper.createLocalizedMenu(mb, "Specify.SYSTEM_MENU", "Specify.SYSTEM_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ /*if (true) { menu = UIHelper.createMenu(mb, "Forms", "o"); Action genForms = new AbstractAction() { public void actionPerformed(ActionEvent ae) { FormGenerator fg = new FormGenerator(); fg.generateForms(); } }; mi = UIHelper.createMenuItemWithAction(menu, "Generate All Forms", "G", "", true, genForms); }*/ } //-------------------------------------------------------------------- //-- Tab Menu //-------------------------------------------------------------------- menu = UIHelper.createLocalizedMenu(mb, "Specify.TABS_MENU", "Specify.TABS_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MENU"); String mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseCurrent")); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAll")); if (!UIHelper.isMacOS()) { mi.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAllBut")); menu.addSeparator(); // Configure Task JMenuItem configTaskMI = new JMenuItem(getAction("ConfigureTask")); menu.add(configTaskMI); //UIRegistry.register("ConfigureTask", configTaskMI); //$NON-NLS-1$ //-------------------------------------------------------------------- //-- Debug Menu //-------------------------------------------------------------------- boolean doDebug = AppPreferences.getLocalPrefs().getBoolean("debug.menu", false); if (!UIRegistry.isRelease() || doDebug) { menu = UIHelper.createLocalizedMenu(mb, "Specify.DEBUG_MENU", "Specify.DEBUG_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttle = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ String mneu = "Specify.SHOW_LOC_PREF_MNEU";//$NON-NLS-1$ String desc = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openLocalPrefs(); } }); ttle = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mneu = "Specify.SHOW_REM_PREFS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openRemotePrefs(); } }); menu.addSeparator(); ttle = "Specify.CONFIG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { final LoggerDialog dialog = new LoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); ttle = "Specify.CONFIG_DEBUG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_DEBUG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_DEBUG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { DebugLoggerDialog dialog = new DebugLoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); menu.addSeparator(); ttle = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mneu = "Specify.SHOW_MEM_STATS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { System.gc(); System.runFinalization(); // Get current size of heap in bytes double meg = 1024.0 * 1024.0; double heapSize = Runtime.getRuntime().totalMemory() / meg; // Get maximum size of heap in bytes. The heap cannot grow beyond this size. // Any attempt will result in an OutOfMemoryException. double heapMaxSize = Runtime.getRuntime().maxMemory() / meg; // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created. double heapFreeSize = Runtime.getRuntime().freeMemory() / meg; UIRegistry.getStatusBar() .setText(String.format("Heap Size: %7.2f Max: %7.2f Free: %7.2f Used: %7.2f", //$NON-NLS-1$ heapSize, heapMaxSize, heapFreeSize, (heapSize - heapFreeSize))); } }); JMenu prefsMenu = new JMenu(UIRegistry.getResourceString("Specify.PREFS_IMPORT_EXPORT")); //$NON-NLS-1$ menu.add(prefsMenu); ttle = "Specify.IMPORT_MENU";//$NON-NLS-1$ mneu = "Specify.IMPORT_MNEU";//$NON-NLS-1$ desc = "Specify.IMPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { importPrefs(); } }); ttle = "Specify.EXPORT_MENU";//$NON-NLS-1$ mneu = "Specify.EXPORT_MNEU";//$NON-NLS-1$ desc = "Specify.EXPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { exportPrefs(); } }); ttle = "Associate Storage Items";//$NON-NLS-1$ mneu = "A";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { associateStorageItems(); } }); ttle = "Load GPX Points";//$NON-NLS-1$ mneu = "a";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { CustomDialog dlg = GPXPanel.getDlgInstance(); if (dlg != null) { dlg.setVisible(true); } } }); JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("Security Activated"); //$NON-NLS-1$ menu.add(cbMenuItem); cbMenuItem.setSelected(AppContextMgr.isSecurityOn()); cbMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean isSecurityOn = !SpecifyAppContextMgr.isSecurityOn(); AppContextMgr.getInstance().setSecurity(isSecurityOn); ((JMenuItem) ae.getSource()).setSelected(isSecurityOn); JLabel secLbl = statusField.getSectionLabel(3); if (secLbl != null) { secLbl.setIcon(IconManager.getImage(isSecurityOn ? "SecurityOn" : "SecurityOff", IconManager.IconSize.Std16)); secLbl.setHorizontalAlignment(SwingConstants.CENTER); secLbl.setToolTipText(getResourceString("Specify.SEC_" + (isSecurityOn ? "ON" : "OFF"))); } } }); JMenuItem sizeMenuItem = new JMenuItem("Set to " + PREFERRED_WIDTH + "x" + PREFERRED_HEIGHT); //$NON-NLS-1$ menu.add(sizeMenuItem); sizeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { topFrame.setSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } }); } //---------------------------------------------------- //-- Helper Menu //---------------------------------------------------- JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ HelpMgr.createHelpMenuItem(helpMenu, getResourceString("SPECIFY_HELP")); //$NON-NLS-1$ helpMenu.addSeparator(); String ttle = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ String mneu = "Specify.LOG_SHOW_FILES_MNEU";//$NON-NLS-1$ String desc = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); helpMenu.addSeparator(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { AppBase.displaySpecifyLogFiles(); } }); ttle = "SecurityAdminTask.CHANGE_PWD_MENU"; //$NON-NLS-1$ mneu = "SecurityAdminTask.CHANGE_PWD_MNEU"; //$NON-NLS-1$ desc = "SecurityAdminTask.CHANGE_PWD_DESC"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { SecurityAdminTask.changePassword(true); } }); ttle = "Specify.CHECK_UPDATE";//$NON-NLS-1$ mneu = "Specify.CHECK_UPDATE_MNEU";//$NON-NLS-1$ desc = "Specify.CHECK_UPDATE_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { checkForUpdates(); } }); ttle = "Specify.AUTO_REG";//$NON-NLS-1$ mneu = "Specify.AUTO_REG_MNEU";//$NON-NLS-1$ desc = "Specify.AUTO_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.register(true, 0); } }); ttle = "Specify.SA_REG";//$NON-NLS-1$ mneu = "Specify.SA_REG_MNEU";//$NON-NLS-1$ desc = "Specify.SA_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.registerISA(); } }); ttle = "Specify.FEEDBACK";//$NON-NLS-1$ mneu = "Specify.FB_MNEU";//$NON-NLS-1$ desc = "Specify.FB_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { FeedBackDlg feedBackDlg = new FeedBackDlg(); feedBackDlg.sendFeedback(); } }); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { helpMenu.addSeparator(); ttle = "Specify.ABOUT";//$NON-NLS-1$ mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ desc = "Specify.ABOUT";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doAbout(); } }); } return mb; }
From source file:JDAC.JDAC.java
public JDAC() { setTitle("JDAC"); ImageIcon img = new ImageIcon("logo.png"); setIconImage(img.getImage());/*from www . j a v a 2 s. co m*/ //setLayout(new FlowLayout()); mDataset = createDataset("A"); mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL, false, true, false); mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"), PlotOrientation.VERTICAL, false, true, false); mChart.getXYPlot().getDomainAxis().setLowerMargin(0); mChart.getXYPlot().getDomainAxis().setUpperMargin(0); mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0); mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0); ChartPanel chartPanel = new ChartPanel(mChart); ChartPanel chartLastPanel = new ChartPanel(mLastChart); //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) ); XYPlot plot = mChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); XYPlot lastPlot = mLastChart.getXYPlot(); XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer(); lastRenderer.setSeriesPaint(0, Color.RED); lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f)); lastPlot.setRenderer(lastRenderer); resetChartButton = new JButton("Reset"); resetChartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetChart(); } }); mMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu sensorMenu = new JMenu("Sensor"); JMenu deviceMenu = new JMenu("Device"); portSubMenu = new JMenu("Port"); JMenu helpMenu = new JMenu("Help"); serialStatusLabel = new JLabel("Disconnected"); statusLabel = new JLabel("Ready"); clearStatus = new LabelClear(statusLabel); clearStatus.resetTime(); connectButton = new JMenuItem("Connect"); disconnectButton = new JMenuItem("Disconnect"); startButton = new JButton("Start"); stopButton = new JButton("Stop"); scanButton = new JMenuItem("Refresh port list"); exportCSVButton = new JMenuItem("Export data to CSV"); exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S")); exportCSVButton.setMnemonic(KeyEvent.VK_S); exportPNGButton = new JMenuItem("Export chart to PNG"); JPanel optionsPanel = new JPanel(new BorderLayout()); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setAccelerator(KeyStroke.getKeyStroke("control X")); exitItem.setMnemonic(KeyEvent.VK_X); JMenuItem aboutItem = new JMenuItem("About"); JMenuItem helpItem = new JMenuItem("Help"); JMenuItem quickStartItem = new JMenuItem("Quick start"); lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1)); ActionListener mSensorListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setSensor(e.getActionCommand()); } }; ButtonGroup sensorGroup = new ButtonGroup(); JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Distance"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Voltage"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Generic"); tmpRadioButton.setSelected(true); setSensor("Generic"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedPortName == null) { setStatus("No port selected"); return; } connect(selectedPortName); } }); disconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { serialStatusLabel.setText("Disconnecting..."); if (serialPort == null) { serialStatusLabel.setText("Disconnected"); serialConnected = false; return; } stopCollect(); disconnect(); } }); scanButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { searchForPorts(); } }); exportCSVButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveData(); } }); exportPNGButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportPNG(); } }); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { startCollect(); } }); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopCollect(); } }); lastSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { numLastValues = (Integer) lastSpinner.getValue(); updateLastTitle(); } }); updateLastTitle(); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); helpItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new HelpFrame(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutFrame(); } }); quickStartItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new StartFrame(); } }); fileMenu.add(exportCSVButton); fileMenu.add(exportPNGButton); fileMenu.addSeparator(); fileMenu.add(exitItem); deviceMenu.add(connectButton); deviceMenu.add(disconnectButton); deviceMenu.addSeparator(); deviceMenu.add(portSubMenu); deviceMenu.add(scanButton); helpMenu.add(quickStartItem); helpMenu.add(helpItem); helpMenu.add(aboutItem); mMenuBar.add(fileMenu); mMenuBar.add(sensorMenu); mMenuBar.add(deviceMenu); mMenuBar.add(helpMenu); JPanel controlsPanel = new JPanel(); controlsPanel.add(startButton); controlsPanel.add(stopButton); controlsPanel.add(resetChartButton); optionsPanel.add(controlsPanel, BorderLayout.LINE_START); JPanel lastPanel = new JPanel(new FlowLayout()); lastPanel.add(new JLabel("Shown values: ")); lastPanel.add(lastSpinner); optionsPanel.add(lastPanel); JPanel serialPanel = new JPanel(new FlowLayout()); serialPanel.add(serialStatusLabel); optionsPanel.add(serialPanel, BorderLayout.LINE_END); add(optionsPanel, BorderLayout.PAGE_START); JPanel mainPanel = new JPanel(new GridLayout(0, 2)); mainPanel.add(chartPanel); mainPanel.add(chartLastPanel); add(mainPanel); add(statusLabel, BorderLayout.PAGE_END); setJMenuBar(mMenuBar); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); } }); setSize(800, 800); pack(); new StartFrame(); //center on screen Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - getWidth()) / 2); int y = (int) ((dimension.getHeight() - getHeight()) / 2); setLocation(x, y); setVisible(true); }
From source file:com.adobe.aem.demomachine.gui.AemDemo.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void initialize() { // Initialize properties setDefaultProperties(AemDemoUtils//from w w w .java 2 s .c o m .loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties")); setPersonalProperties(AemDemoUtils.loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator + "conf" + File.separator + "build-personal.properties")); // Constructing the main frame frameMain = new JFrame(); frameMain.setBounds(100, 100, 700, 530); frameMain.getContentPane().setLayout(null); // Main menu bar for the Frame JMenuBar menuBar = new JMenuBar(); JMenu mnAbout = new JMenu("AEM Demo Machine"); mnAbout.setMnemonic(KeyEvent.VK_A); menuBar.add(mnAbout); JMenuItem mntmUpdates = new JMenuItem("Check for Updates"); mntmUpdates.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmUpdates.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "demo_update"); } }); mnAbout.add(mntmUpdates); JMenuItem mntmDoc = new JMenuItem("Help and Documentation"); mntmDoc.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmDoc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties, AemDemoConstants.OPTIONS_DOCUMENTATION)); } }); mnAbout.add(mntmDoc); JMenuItem mntmScripts = new JMenuItem("Demo Scripts (VPN)"); mntmScripts.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties, AemDemoConstants.OPTIONS_SCRIPTS)); } }); mnAbout.add(mntmScripts); JMenuItem mntmDiagnostics = new JMenuItem("Diagnostics"); mntmDiagnostics.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Map<String, String> env = System.getenv(); System.out.println("====== System Environment Variables ======"); for (String envName : env.keySet()) { System.out.format("%s=%s%n", envName, env.get(envName)); } System.out.println("====== JVM Properties ======"); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> jvmArgs = runtimeMXBean.getInputArguments(); for (String arg : jvmArgs) { System.out.println(arg); } System.out.println("====== Runtime Properties ======"); Properties props = System.getProperties(); props.list(System.out); } }); mnAbout.add(mntmDiagnostics); JMenuItem mntmQuit = new JMenuItem("Quit"); mntmQuit.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmQuit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(-1); } }); mnAbout.add(mntmQuit); JMenu mnNew = new JMenu("New"); menuBar.add(mnNew); // New Demo Machine JMenuItem mntmNewDemo = new JMenuItem("Demo Environment"); mntmNewDemo.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmNewDemo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (AemDemo.this.getBuildInProgress()) { JOptionPane.showMessageDialog(null, "A Demo Environment is currently being built. Please wait until it is finished."); } else { final AemDemoNew dialogNew = new AemDemoNew(AemDemo.this); dialogNew.setModal(true); dialogNew.setVisible(true); dialogNew.getDemoBuildName().requestFocus(); ; } } }); mnNew.add(mntmNewDemo); JMenuItem mntmNewOptions = new JMenuItem("Demo Properties"); mntmNewOptions.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmNewOptions.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final AemDemoOptions dialogOptions = new AemDemoOptions(AemDemo.this); dialogOptions.setModal(true); dialogOptions.setVisible(true); } }); mnNew.add(mntmNewOptions); JMenu mnUpdate = new JMenu("Add-ons"); menuBar.add(mnUpdate); // Sites Add-on JMenu mnSites = new JMenu("Sites"); mnUpdate.add(mnSites); JMenuItem mntmSitesDownloadAddOn = new JMenuItem("Download Demo Add-on"); mntmSitesDownloadAddOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_sites"); } }); mnSites.add(mntmSitesDownloadAddOn); JMenuItem mntmSitesDownloadFP = new JMenuItem("Download Packages (PackageShare)"); mntmSitesDownloadFP.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_sites_packages"); } }); mnSites.add(mntmSitesDownloadFP); // Assets Add-on JMenu mnAssets = new JMenu("Assets"); mnUpdate.add(mnAssets); JMenuItem mntmAssetsDownloadAddOn = new JMenuItem("Download Demo Add-on"); mntmAssetsDownloadAddOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_assets"); } }); mnAssets.add(mntmAssetsDownloadAddOn); JMenuItem mntmAssetsDownloadFP = new JMenuItem("Download Packages (PackageShare)"); mntmAssetsDownloadFP.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_assets_packages"); } }); mnAssets.add(mntmAssetsDownloadFP); // Communities Add-on JMenu mnCommunities = new JMenu("Communities/Livefyre"); mnUpdate.add(mnCommunities); JMenuItem mntmAemCommunitiesFeaturePacks = new JMenuItem("Download Packages (PackageShare)"); mntmAemCommunitiesFeaturePacks.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_communities_packages"); } }); mnCommunities.add(mntmAemCommunitiesFeaturePacks); // Forms Add-on JMenu mnForms = new JMenu("Forms"); mnUpdate.add(mnForms); JMenuItem mntmAemFormsAddon = new JMenuItem("Download Demo Add-on"); mntmAemFormsAddon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_forms"); } }); mnForms.add(mntmAemFormsAddon); JMenuItem mntmAemFormsFP = new JMenuItem("Download Packages (PackageShare)"); mntmAemFormsFP.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_forms_packages"); } }); mnForms.add(mntmAemFormsFP); // Mobile Add-on JMenu mnApps = new JMenu("Mobile"); mnUpdate.add(mnApps); JMenuItem mntmAemAppsAddon = new JMenuItem("Download Demo Add-on"); mntmAemAppsAddon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_apps"); } }); mnApps.add(mntmAemAppsAddon); JMenuItem mntmAemApps = new JMenuItem("Download Packages (PackageShare)"); mntmAemApps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_apps_packages"); } }); mnApps.add(mntmAemApps); // Commerce Add-on JMenu mnCommerce = new JMenu("Commerce"); mnUpdate.add(mnCommerce); JMenu mnCommerceDownload = new JMenu("Download Packages"); mnCommerce.add(mnCommerceDownload); // Commerce EP JMenuItem mnCommerceDownloadEP = new JMenuItem("ElasticPath (PackageShare)"); mnCommerceDownloadEP.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_commerce_ep"); } }); mnCommerceDownload.add(mnCommerceDownloadEP); // Commerce WebSphere JMenuItem mnCommerceDownloadWAS = new JMenuItem("WebSphere (PackageShare)"); mnCommerceDownloadWAS.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_commerce_websphere"); } }); mnCommerceDownload.add(mnCommerceDownloadWAS); // WeRetail Add-on JMenu mnWeRetail = new JMenu("We-Retail"); mnUpdate.add(mnWeRetail); JMenuItem mnWeRetailAddon = new JMenuItem("Download Demo Add-on"); mnWeRetailAddon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_weretail"); } }); mnWeRetail.add(mnWeRetailAddon); // Download all section mnUpdate.addSeparator(); JMenuItem mntmAemDownloadAll = new JMenuItem("Download All Add-ons"); mntmAemDownloadAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_all"); } }); mnUpdate.add(mntmAemDownloadAll); JMenu mnInfrastructure = new JMenu("Infrastructure"); menuBar.add(mnInfrastructure); JMenu mnMongo = new JMenu("MongoDB"); JMenuItem mntmInfraMongoDB = new JMenuItem("Download"); mntmInfraMongoDB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_mongo"); } }); mnMongo.add(mntmInfraMongoDB); JMenuItem mntmInfraMongoDBInstall = new JMenuItem("Install"); mntmInfraMongoDBInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "install_mongo"); } }); mnMongo.add(mntmInfraMongoDBInstall); mnMongo.addSeparator(); JMenuItem mntmInfraMongoDBStart = new JMenuItem("Start"); mntmInfraMongoDBStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "mongo_start"); } }); mnMongo.add(mntmInfraMongoDBStart); JMenuItem mntmInfraMongoDBStop = new JMenuItem("Stop"); mntmInfraMongoDBStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "mongo_stop"); } }); mnMongo.add(mntmInfraMongoDBStop); mnInfrastructure.add(mnMongo); // SOLR options JMenu mnSOLR = new JMenu("SOLR"); JMenuItem mntmInfraSOLR = new JMenuItem("Download"); mntmInfraSOLR.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_solr"); } }); mnSOLR.add(mntmInfraSOLR); JMenuItem mntmInfraSOLRInstall = new JMenuItem("Install"); mntmInfraSOLRInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "install_solr"); } }); mnSOLR.add(mntmInfraSOLRInstall); mnSOLR.addSeparator(); JMenuItem mntmInfraSOLRStart = new JMenuItem("Start"); mntmInfraSOLRStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "solr_start"); } }); mnSOLR.add(mntmInfraSOLRStart); JMenuItem mntmInfraSOLRStop = new JMenuItem("Stop"); mntmInfraSOLRStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "solr_stop"); } }); mnSOLR.add(mntmInfraSOLRStop); mnInfrastructure.add(mnSOLR); // MySQL options JMenu mnMySQL = new JMenu("MySQL"); JMenuItem mntmInfraMysql = new JMenuItem("Download"); mntmInfraMysql.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_mysql"); } }); mnMySQL.add(mntmInfraMysql); JMenuItem mntmInfraMysqlInstall = new JMenuItem("Install"); mntmInfraMysqlInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "install_mysql"); } }); mnMySQL.add(mntmInfraMysqlInstall); mnMySQL.addSeparator(); JMenuItem mntmInfraMysqlStart = new JMenuItem("Start"); mntmInfraMysqlStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "mysql_start"); } }); mnMySQL.add(mntmInfraMysqlStart); JMenuItem mntmInfraMysqlStop = new JMenuItem("Stop"); mntmInfraMysqlStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "mysql_stop"); } }); mnMySQL.add(mntmInfraMysqlStop); mnInfrastructure.add(mnMySQL); // James options JMenu mnJames = new JMenu("James SMTP/POP"); JMenuItem mntmInfraJames = new JMenuItem("Download"); mntmInfraJames.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_james"); } }); mnJames.add(mntmInfraJames); JMenuItem mntmInfraJamesInstall = new JMenuItem("Install"); mntmInfraJamesInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "install_james"); } }); mnJames.add(mntmInfraJamesInstall); mnJames.addSeparator(); JMenuItem mntmInfraJamesStart = new JMenuItem("Start"); mntmInfraJamesStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "james_start"); } }); mnJames.add(mntmInfraJamesStart); JMenuItem mntmInfraJamesStop = new JMenuItem("Stop"); mntmInfraJamesStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "james_stop"); } }); mnJames.add(mntmInfraJamesStop); mnInfrastructure.add(mnJames); // FFMPEPG options JMenu mnFFMPEG = new JMenu("FFMPEG"); JMenuItem mntmInfraFFMPEG = new JMenuItem("Download"); mntmInfraFFMPEG.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_ffmpeg"); } }); mnFFMPEG.add(mntmInfraFFMPEG); JMenuItem mntmInfraFFMPEGInstall = new JMenuItem("Install"); mntmInfraFFMPEGInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "install_ffmpeg"); } }); mnFFMPEG.add(mntmInfraFFMPEGInstall); mnInfrastructure.add(mnFFMPEG); mnInfrastructure.addSeparator(); // InDesignServer options JMenu mnInDesignServer = new JMenu("InDesign Server"); JMenuItem mntmInfraInDesignServerDownload = new JMenuItem("Download"); mntmInfraInDesignServerDownload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_indesignserver"); } }); mnInDesignServer.add(mntmInfraInDesignServerDownload); mnInDesignServer.addSeparator(); JMenuItem mntmInfraInDesignServerStart = new JMenuItem("Start"); mntmInfraInDesignServerStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "start_indesignserver"); } }); mnInDesignServer.add(mntmInfraInDesignServerStart); JMenuItem mntmInfraInDesignServerStop = new JMenuItem("Stop"); mntmInfraInDesignServerStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "stop_indesignserver"); } }); mnInDesignServer.add(mntmInfraInDesignServerStop); mnInfrastructure.add(mnInDesignServer); mnInfrastructure.addSeparator(); JMenuItem mntmInfraInstall = new JMenuItem("All in One Setup"); mntmInfraInstall.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "infrastructure"); } }); mnInfrastructure.add(mntmInfraInstall); JMenu mnOther = new JMenu("Other"); menuBar.add(mnOther); JMenu mntmAemDownload = new JMenu("AEM & License files (VPN)"); JMenuItem mntmAemLoad = new JMenuItem("Download Latest AEM Load"); mntmAemLoad.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmAemLoad.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_load"); } }); mntmAemDownload.add(mntmAemLoad); JMenuItem mntmAemSnapshot = new JMenuItem("Download Latest AEM Snapshot"); mntmAemSnapshot.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmAemSnapshot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_snapshot"); } }); mntmAemDownload.add(mntmAemSnapshot); JMenuItem mntmAemDownloadAEM62 = new JMenuItem("Download AEM 6.2"); mntmAemDownloadAEM62.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_aem62"); } }); mntmAemDownload.add(mntmAemDownloadAEM62); JMenuItem mntmAemDownloadAEM61 = new JMenuItem("Download AEM 6.1"); mntmAemDownloadAEM61.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_aem61"); } }); mntmAemDownload.add(mntmAemDownloadAEM61); JMenuItem mntmAemDownloadAEM60 = new JMenuItem("Download AEM 6.0"); mntmAemDownloadAEM60.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_aem60"); } }); mntmAemDownload.add(mntmAemDownloadAEM60); JMenuItem mntmAemDownloadCQ561 = new JMenuItem("Download CQ 5.6.1"); mntmAemDownloadCQ561.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_cq561"); } }); mntmAemDownload.add(mntmAemDownloadCQ561); JMenuItem mntmAemDownloadCQ56 = new JMenuItem("Download CQ 5.6"); mntmAemDownloadCQ56.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_cq56"); } }); mntmAemDownload.add(mntmAemDownloadCQ56); JMenuItem mntmAemDownloadOthers = new JMenuItem("Other Releases & License files"); mntmAemDownloadOthers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.openWebpage(AemDemoUtils.getActualPropertyValue(defaultProperties, personalProperties, AemDemoConstants.OPTIONS_DOWNLOAD)); } }); mntmAemDownload.add(mntmAemDownloadOthers); mnOther.add(mntmAemDownload); JMenuItem mntmAemHotfix = new JMenuItem("Download Latest Hotfixes (PackageShare)"); mntmAemHotfix.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmAemHotfix.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_hotfixes_packages"); } }); mnOther.add(mntmAemHotfix); JMenuItem mntmAemAcs = new JMenuItem("Download Latest ACS Commons and Tools"); mntmAemAcs.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mntmAemAcs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "download_acs"); } }); mnOther.add(mntmAemAcs); // Adding the menu bar frameMain.setJMenuBar(menuBar); // Adding other form elements JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(24, 163, 650, 230); frameMain.getContentPane().add(scrollPane); final JTextArea textArea = new JTextArea(""); textArea.setEditable(false); scrollPane.setViewportView(textArea); // List of demo machines available JScrollPane scrollDemoList = new JScrollPane(); scrollDemoList.setBounds(24, 34, 208, 100); frameMain.getContentPane().add(scrollDemoList); listModelDemoMachines = AemDemoUtils.listDemoMachines(buildFile.getParentFile().getAbsolutePath()); listDemoMachines = new JList(listModelDemoMachines); listDemoMachines.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listDemoMachines.setSelectedIndex(AemDemoUtils.getSelectedIndex(listDemoMachines, this.getDefaultProperties(), this.getPersonalProperties(), AemDemoConstants.OPTIONS_BUILD_DEFAULT)); scrollDemoList.setViewportView(listDemoMachines); // Capturing the output stream of ANT commands AemDemoOutputStream out = new AemDemoOutputStream(textArea); System.setOut(new PrintStream(out)); JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "start"); } }); btnStart.setBounds(250, 29, 117, 29); frameMain.getContentPane().add(btnStart); // Set Start as the default button JRootPane rootPane = SwingUtilities.getRootPane(btnStart); rootPane.setDefaultButton(btnStart); JButton btnInfo = new JButton("Details"); btnInfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "details"); } }); btnInfo.setBounds(250, 59, 117, 29); frameMain.getContentPane().add(btnInfo); // Rebuild action JButton btnRebuild = new JButton("Rebuild"); btnRebuild.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (AemDemo.this.getBuildInProgress()) { JOptionPane.showMessageDialog(null, "A Demo Environment is currently being built. Please wait until it is finished."); } else { final AemDemoRebuild dialogRebuild = new AemDemoRebuild(AemDemo.this); dialogRebuild.setModal(true); dialogRebuild.setVisible(true); dialogRebuild.getDemoBuildName().requestFocus(); ; } } }); btnRebuild.setBounds(250, 89, 117, 29); frameMain.getContentPane().add(btnRebuild); // Stop action JButton btnStop = new JButton("Stop"); btnStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you really want to stop the running instances?", "Warning", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.NO_OPTION) { return; } AemDemoUtils.antTarget(AemDemo.this, "stop"); } }); btnStop.setBounds(500, 29, 117, 29); frameMain.getContentPane().add(btnStop); JButton btnExit = new JButton("Exit"); btnExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(-1); } }); btnExit.setBounds(550, 408, 117, 29); frameMain.getContentPane().add(btnExit); JButton btnClear = new JButton("Clear"); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(""); } }); btnClear.setBounds(40, 408, 117, 29); frameMain.getContentPane().add(btnClear); JButton btnBackup = new JButton("Backup"); btnBackup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "backup"); } }); btnBackup.setBounds(500, 59, 117, 29); frameMain.getContentPane().add(btnBackup); JButton btnRestore = new JButton("Restore"); btnRestore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AemDemoUtils.antTarget(AemDemo.this, "restore"); } }); btnRestore.setBounds(500, 89, 117, 29); frameMain.getContentPane().add(btnRestore); JButton btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you really want to permanently delete the selected demo configuration?", "Warning", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.NO_OPTION) { return; } AemDemoUtils.antTarget(AemDemo.this, "uninstall"); } }); btnDelete.setBounds(500, 119, 117, 29); frameMain.getContentPane().add(btnDelete); JLabel lblSelectYourDemo = new JLabel("Select your Demo Environment"); lblSelectYourDemo.setBounds(24, 10, 219, 16); frameMain.getContentPane().add(lblSelectYourDemo); JLabel lblCommandOutput = new JLabel("Command Output"); lblCommandOutput.setBounds(24, 143, 160, 16); frameMain.getContentPane().add(lblCommandOutput); // Initializing and launching the ticker String tickerOn = AemDemoUtils.getPropertyValue(buildFile, "demo.ticker"); if (tickerOn == null || (tickerOn != null && tickerOn.equals("true"))) { AemDemoMarquee mp = new AemDemoMarquee(AemDemoConstants.Credits, 60); mp.setBounds(140, 440, 650, 30); frameMain.getContentPane().add(mp); mp.start(); } // Launching the download tracker task AemDemoDownload aemDownload = new AemDemoDownload(AemDemo.this); ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); executor.scheduleAtFixedRate(aemDownload, 0, 5, TimeUnit.SECONDS); // Loading up the README.md file String line = null; try { FileReader fileReader = new FileReader( buildFile.getParentFile().getAbsolutePath() + File.separator + "README.md"); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { if (line.indexOf("AEM Demo Machine!") > 0) { line = line + " (version: " + aemDemoMachineVersion + ")"; } if (!line.startsWith("Double")) System.out.println(line); } bufferedReader.close(); } catch (Exception ex) { logger.error(ex.getMessage()); } }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Create the SPARQL server menu//from w w w. java 2 s. co m * * @return The SPARQL server menu */ private JMenu setupSparqlServerMenu() { final JMenu menu = new JMenu("SPARQL Server"); menu.setMnemonic(KeyEvent.VK_P); menu.setToolTipText("Options for using the SPARQL server"); sparqlServerStartup = new JMenuItem("Startup SPARQL Server"); sparqlServerStartup.setMnemonic(KeyEvent.VK_S); sparqlServerStartup.setToolTipText("Start the SPARQL server"); sparqlServerStartup.addActionListener(new SparqlServerStartupListener()); menu.add(sparqlServerStartup); sparqlServerShutdown = new JMenuItem("Shutdown SPARQL Server"); sparqlServerShutdown.setMnemonic(KeyEvent.VK_H); sparqlServerShutdown.setToolTipText("Stop the SPARQL server"); sparqlServerShutdown.addActionListener(new SparqlServerShutdownListener()); menu.add(sparqlServerShutdown); menu.addSeparator(); sparqlServerPublishCurrentModel = new JMenuItem("Publish Current Reasoned Model"); sparqlServerPublishCurrentModel.setMnemonic(KeyEvent.VK_P); sparqlServerPublishCurrentModel .setToolTipText("Set the model for the SPARQL server to the current one reasoned"); sparqlServerPublishCurrentModel.addActionListener(new SparqlServerPublishModelListener()); menu.add(sparqlServerPublishCurrentModel); menu.addSeparator(); sparqlServerConfig = new JMenuItem("Configure the SPARQL Server"); sparqlServerConfig.setMnemonic(KeyEvent.VK_C); sparqlServerConfig.setToolTipText("Configure the server endpoint"); sparqlServerConfig.addActionListener(new SparqlServerConfigurationListener()); menu.add(sparqlServerConfig); return menu; }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Create the configuration menu/* ww w . j a va 2s . c o 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.monead.semantic.workbench.SemanticWorkbench.java
/** * Create the edit menu//from w ww . j a v a2 s .c o m * * @return The edit menu */ private JMenu setupEditMenu() { final JMenu menu = new JMenu("Edit"); menu.setMnemonic(KeyEvent.VK_E); menu.setToolTipText("Menu items related to editing the ontology"); editFind = new JMenuItem("Find (in assertions)"); editFind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK)); editFind.setMnemonic(KeyEvent.VK_F); editFind.setToolTipText("Find text in the assertions editor"); editFind.addActionListener(new FindAssertionsTextListener()); menu.add(editFind); editFindNextMatch = new JMenuItem("Next (matching assertion text)"); editFindNextMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); editFindNextMatch.setMnemonic(KeyEvent.VK_N); editFindNextMatch.setToolTipText("Find next text match in the assertions editor"); editFindNextMatch.addActionListener(new FindNextAssertionsTextListener()); menu.add(editFindNextMatch); menu.addSeparator(); editCommentToggle = new JMenuItem("Toggle Comment"); editCommentToggle.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.CTRL_MASK)); editCommentToggle.setMnemonic(KeyEvent.VK_T); editCommentToggle .setToolTipText("Switch the chosen assertion or query lines between commented and not commented"); editCommentToggle.addActionListener(new CommentToggleListener()); editCommentToggle.setEnabled(false); menu.add(editCommentToggle); editInsertPrefixes = new JMenuItem("Insert Prefixes"); editInsertPrefixes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); editInsertPrefixes.setMnemonic(KeyEvent.VK_I); editInsertPrefixes.setToolTipText("Insert standard prefixes (namespaces)"); editInsertPrefixes.addActionListener(new InsertPrefixesListener()); menu.add(editInsertPrefixes); menu.addSeparator(); editExpandAllTreeNodes = new JMenuItem("Expand Entire Tree"); editExpandAllTreeNodes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, ActionEvent.ALT_MASK)); editExpandAllTreeNodes.setMnemonic(KeyEvent.VK_E); editExpandAllTreeNodes.setToolTipText("Expand all tree nodes"); editExpandAllTreeNodes.addActionListener(new ExpandTreeListener()); menu.add(editExpandAllTreeNodes); editCollapseAllTreeNodes = new JMenuItem("Collapse Entire Tree"); editCollapseAllTreeNodes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, ActionEvent.ALT_MASK)); editCollapseAllTreeNodes.setMnemonic(KeyEvent.VK_C); editCollapseAllTreeNodes.setToolTipText("Expand all tree nodes"); editCollapseAllTreeNodes.addActionListener(new CollapseTreeListener()); menu.add(editCollapseAllTreeNodes); menu.addSeparator(); editEditListOfSparqlServiceUrls = new JMenuItem("Edit SPARQL Service URLs List"); editEditListOfSparqlServiceUrls.setMnemonic(KeyEvent.VK_S); editEditListOfSparqlServiceUrls.setToolTipText("Remove unwanted URLs from the dropdown list"); editEditListOfSparqlServiceUrls.addActionListener(new EditListOfSparqlServiceUrls()); menu.add(editEditListOfSparqlServiceUrls); return menu; }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Create the filters menu/*from www . j a va2 s . co m*/ * * @return The filters menu */ private JMenu setupFiltersMenu() { final JMenu menu = new JMenu("Tree Filter"); menu.setMnemonic(KeyEvent.VK_F); menu.setToolTipText("Menu items related to filtering values out of the model's tree"); filterEnableFilters = new JCheckBoxMenuItem("Enable Filters"); filterEnableFilters.setSelected(true); filterEnableFilters .setToolTipText("Enforce the filtered list of classes and properties when creating the tree view"); menu.add(filterEnableFilters); filterShowAnonymousNodes = new JCheckBoxMenuItem("Show Anonymous Nodes"); filterShowAnonymousNodes.setSelected(false); filterShowAnonymousNodes.setToolTipText("Include anonymous nodes in the tree view"); menu.add(filterShowAnonymousNodes); showFqnInTree = new JCheckBoxMenuItem("Show FQN In Tree"); showFqnInTree.setSelected(false); showFqnInTree .setToolTipText("Show the fully qualified name for classes, properties and objects in the tree"); menu.add(showFqnInTree); menu.addSeparator(); filterEditFilteredClasses = new JMenuItem("Edit List of Filtered Classes"); filterEditFilteredClasses .setToolTipText("Present the list of filtered classes and allow them to be edited"); filterEditFilteredClasses.addActionListener(new EditFilteredClassesListener()); menu.add(filterEditFilteredClasses); filterEditFilteredProperties = new JMenuItem("Edit List of Filtered Properties"); filterEditFilteredProperties .setToolTipText("Present the list of filtered properties and allow them to be edited"); filterEditFilteredProperties.addActionListener(new EditFilteredPropertiesListener()); menu.add(filterEditFilteredProperties); menu.addSeparator(); filterSetMaximumIndividualsPerClassInTree = new JMenuItem("Set Maximum Individuals Per Class in Tree"); filterSetMaximumIndividualsPerClassInTree .setToolTipText("Limit number of individuals shown for each class in the tree view."); filterSetMaximumIndividualsPerClassInTree .addActionListener(new SetMaximumIndividualsPerClassInTreeListener()); menu.add(filterSetMaximumIndividualsPerClassInTree); return menu; }
From source file:com.monead.semantic.workbench.SemanticWorkbench.java
/** * Create the model menu//from w w w . j a va 2 s. c o m * * @return The model menu */ private JMenu setupModelMenu() { final JMenu menu = new JMenu("Model"); menu.setMnemonic(KeyEvent.VK_M); menu.setToolTipText("Menu items related to viewing the model"); modelCreateTreeView = new JMenuItem("Create Tree"); modelCreateTreeView.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK)); modelCreateTreeView.setMnemonic(KeyEvent.VK_T); modelCreateTreeView.setToolTipText("Create tree representation of current model"); modelCreateTreeView.addActionListener(new GenerateTreeListener()); menu.add(modelCreateTreeView); modelListInferredTriples = new JMenuItem("Identify Inferred Triples"); modelListInferredTriples.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.ALT_MASK)); modelListInferredTriples.setMnemonic(KeyEvent.VK_I); modelListInferredTriples.setToolTipText("Create a list of inferred triples from the current model"); modelListInferredTriples.addActionListener(new GenerateInferredTriplesListener()); menu.add(modelListInferredTriples); menu.addSeparator(); filterResetTree = new JMenuItem("Clear Tree"); filterResetTree .setToolTipText("Remove the tree view of the ontology. This may help if memory is running low"); filterResetTree.addActionListener(new ClearTreeModelListener()); menu.add(filterResetTree); return menu; }
From source file:display.ANNFileFilter.java
License:asdf
Yanng() { JPanel toolBars;//w ww . ja v a 2 s . c o m 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:nl.detoren.ijsco.ui.Mainscreen.java
private void addMenubar() { // Menu bar met 1 niveau Mainscreen ms = this; JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("Bestand"); // File menu//from ww w . jav a 2 s . c om JMenuItem item; /* item = new JMenuItem("Openen..."); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); //controller.leesBestand(file.getAbsolutePath()); ms.repaint(); } } }); filemenu.add(item); */ /* item = new JMenuItem("Opslaan"); item.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //controller.saveState(true, "save"); } }); filemenu.add(item); */ filemenu.addSeparator(); item = new JMenuItem("Instellingen..."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actieInstellingen(); } }); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); filemenu.add(item); filemenu.addSeparator(); item = new JMenuItem("Afsluiten"); item.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { controller.saveState(false, null); System.exit(EXIT_ON_CLOSE); } }); filemenu.add(item); menubar.add(filemenu); /** * Toernooi menu */ JMenu toernooimenu = new JMenu("Toernooi"); item = new JMenuItem("Toernooiinformatie"); item.setAccelerator(KeyStroke.getKeyStroke('T', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); bewerkToernooi(); hoofdPanel.repaint(); } }); toernooimenu.add(item); menubar.add(toernooimenu); /** * Spelersdatabase menu */ JMenu spelermenu = new JMenu("Spelersdatabase"); item = new JMenuItem("OSBO JSON lijst ophalen (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('J', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/currentratings.json"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO htmllijst ophalen !verouderd! (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/jrating.htm"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO/IJSCO compatible lijst inlezen (Bestand)"); item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesOSBOlijstBestand(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); /* item = new JMenuItem("Groslijst CSV inlezen (Bestand) N/A"); item.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesCSV(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); */ menubar.add(spelermenu); JMenu deelnemersmenu = new JMenu("Deelnemers"); item = new JMenuItem("Wis Deelnemerslijst"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser wisDeelnemers(); hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Importeren Deelnemerslijst"); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Export Deelnemerslijst (JSON)"); item.setAccelerator(KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JSON", "json"); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showSaveDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); schrijfDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); menubar.add(deelnemersmenu); JMenu uitslagenmenu = new JMenu("Uitslagen"); Component hs = this; item = new JMenuItem("Importeer uitslagenbestand"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(hs); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); status.groepenuitslagen = (GroepsUitslagen) new ExcelImport().importeerUitslagen(file); OutputUitslagen ou = new OutputUitslagen(); ou.exportuitslagen(status.groepenuitslagen); IJSCOController.t().wisUitslagen(); ou.exportJSON(status.groepenuitslagen); GroepsUitslagen verwerkteUitslag = new Uitslagverwerker() .verwerkUitslag(status.groepenuitslagen); logger.log(Level.INFO, verwerkteUitslag.ToString()); new OutputUitslagen().exporteindresultaten(verwerkteUitslag); JOptionPane.showMessageDialog(null, "Uitslagen geimporteerd en bestanden aangemaakt."); } hoofdPanel.repaint(); } }); uitslagenmenu.add(item); menubar.add(uitslagenmenu); JMenu osbomenu = new JMenu("OSBO"); item = new JMenuItem("Verstuur uitslagen handmatig."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("Uitslagen.json"); hoofdPanel.repaint(); } }); osbomenu.add(item); menubar.add(osbomenu); JMenu helpmenu = new JMenu("Help"); item = new JMenuItem("Verstuur logging"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("IJSCO_UI.log"); hoofdPanel.repaint(); } }); helpmenu.add(item); item = new JMenuItem("About"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AboutDialog ad = new AboutDialog(ms); ad.setVisible(true); hoofdPanel.repaint(); } }); helpmenu.add(item); menubar.add(helpmenu); /* JMenu indelingMenu = new JMenu("Indeling"); //item = new JMenuItem("Automatisch aan/uit"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieAutomatisch(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak wedstrijdgroep"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieMaakWedstrijdgroep(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evetn) { //actieMaakSpeelschema(); } }); indelingMenu.add(item); //item = new JMenuItem("Bewerk speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //updateAutomatisch(false); // ResultaatDialoog //actieBewerkSchema(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Export"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieExport(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Vul uitslagen in"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVoerUitslagenIn(); } }); indelingMenu.add(item); //item = new JMenuItem("Externe spelers"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieExterneSpelers(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak nieuwe stand"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieUpdateStand(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Volgende ronde"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVolgendeRonde(); } }); indelingMenu.add(item); menubar.add(indelingMenu); */ /* JMenu overigmenu = new JMenu("Overig"); //item = new JMenuItem("Reset punten"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //controller.resetPunten(); hoofdPanel.repaint(); } }); overigmenu.add(item); menubar.add(overigmenu); */ this.setJMenuBar(menubar); }