List of usage examples for javax.swing JOptionPane YES_OPTION
int YES_OPTION
To view the source code for javax.swing JOptionPane YES_OPTION.
Click Source Link
From source file:net.sf.jabref.exporter.SaveDatabaseAction.java
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException { SaveSession session;// w ww. ja va 2 s . c om frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs) .withEncoding(encoding); BibDatabaseWriter databaseWriter = new BibDatabaseWriter(); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), prefs, panel.getSelectedEntries()); } else { session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); } panel.registerUndoableChanges(session); } catch (UnsupportedCharsetException ex2) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization .lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } catch (SaveException ex) { if (ex == SaveException.FILE_LOCKED) { throw ex; } if (ex.specificEntry()) { // Error occured during processing of // be. Highlight it: int row = panel.mainTable.findEntry(ex.getEntry()); int topShow = Math.max(0, row - 3); panel.mainTable.setRowSelectionInterval(row, row); panel.mainTable.scrollTo(topShow); panel.showEntry(ex.getEntry()); } else { LOGGER.error("Problem saving file", ex); } JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } finally { frame.unblock(); } boolean commit = true; if (!session.getWriter().couldEncodeAll()) { FormBuilder builder = FormBuilder.create() .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters()); ta.setEditable(false); builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1); builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding); if (choice == null) { commit = false; } else { Charset newEncoding = Charset.forName((String) choice); return saveDatabase(file, selectedOnly, newEncoding); } } else if (answer == JOptionPane.CANCEL_OPTION) { commit = false; } } try { if (commit) { session.commit(file); panel.setEncoding(encoding); // Make sure to remember which encoding we used. } else { session.cancel(); } } catch (SaveException e) { int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { session.setUseBackup(false); session.commit(file); panel.setEncoding(encoding); } else { commit = false; } } return commit; }
From source file:com.esp8266.mkspiffs.ESP8266FS.java
private void createAndUpload() { if (!PreferencesData.get("target_platform").contentEquals("esp8266")) { System.err.println();//from w w w .j a v a2s . c o m editor.statusError("SPIFFS Not Supported on " + PreferencesData.get("target_platform")); return; } if (!BaseNoGui.getBoardPreferences().containsKey("build.spiffs_start") || !BaseNoGui.getBoardPreferences().containsKey("build.spiffs_end")) { System.err.println(); editor.statusError("SPIFFS Not Defined for " + BaseNoGui.getBoardPreferences().get("name")); return; } long spiStart, spiEnd, spiPage, spiBlock; try { spiStart = getIntPref("build.spiffs_start"); spiEnd = getIntPref("build.spiffs_end"); spiPage = getIntPref("build.spiffs_pagesize"); if (spiPage == 0) spiPage = 256; spiBlock = getIntPref("build.spiffs_blocksize"); if (spiBlock == 0) spiBlock = 4096; } catch (Exception e) { editor.statusError(e); return; } TargetPlatform platform = BaseNoGui.getTargetPlatform(); //Make sure mkspiffs binary exists String mkspiffsCmd; if (PreferencesData.get("runtime.os").contentEquals("windows")) mkspiffsCmd = "mkspiffs.exe"; else mkspiffsCmd = "mkspiffs"; File tool = new File(platform.getFolder() + "/tools", mkspiffsCmd); if (!tool.exists() || !tool.isFile()) { tool = new File(platform.getFolder() + "/tools/mkspiffs", mkspiffsCmd); if (!tool.exists()) { tool = new File(PreferencesData.get("runtime.tools.mkspiffs.path"), mkspiffsCmd); if (!tool.exists()) { System.err.println(); editor.statusError("SPIFFS Error: mkspiffs not found!"); return; } } } Boolean isNetwork = false; File espota = new File(platform.getFolder() + "/tools"); File esptool = new File(platform.getFolder() + "/tools"); String serialPort = PreferencesData.get("serial.port"); //make sure the serial port or IP is defined if (serialPort == null || serialPort.isEmpty()) { System.err.println(); editor.statusError("SPIFFS Error: serial port not defined!"); return; } //find espota if IP else find esptool if (serialPort.split("\\.").length == 4) { isNetwork = true; String espotaCmd = "espota.py"; espota = new File(platform.getFolder() + "/tools", espotaCmd); if (!espota.exists() || !espota.isFile()) { System.err.println(); editor.statusError("SPIFFS Error: espota not found!"); return; } } else { String esptoolCmd = platform.getTool("esptool").get("cmd"); esptool = new File(platform.getFolder() + "/tools", esptoolCmd); if (!esptool.exists() || !esptool.isFile()) { esptool = new File(platform.getFolder() + "/tools/esptool", esptoolCmd); if (!esptool.exists()) { esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd); if (!esptool.exists()) { System.err.println(); editor.statusError("SPIFFS Error: esptool not found!"); return; } } } } //load a list of all files int fileCount = 0; File dataFolder = new File(editor.getSketch().getFolder(), "data"); if (!dataFolder.exists()) { dataFolder.mkdirs(); } if (dataFolder.exists() && dataFolder.isDirectory()) { File[] files = dataFolder.listFiles(); if (files.length > 0) { for (File file : files) { if ((file.isDirectory() || file.isFile()) && !file.getName().startsWith(".")) fileCount++; } } } String dataPath = dataFolder.getAbsolutePath(); String toolPath = tool.getAbsolutePath(); String sketchName = editor.getSketch().getName(); String imagePath = getBuildFolderPath(editor.getSketch()) + "\\" + sketchName + ".spiffs.bin"; String resetMethod = BaseNoGui.getBoardPreferences().get("upload.resetmethod"); String uploadSpeed = BaseNoGui.getBoardPreferences().get("upload.speed"); String uploadAddress = BaseNoGui.getBoardPreferences().get("build.spiffs_start"); Object[] options = { "Yes", "No" }; String title = "SPIFFS Create"; String message = "No files have been found in your data folder!\nAre you sure you want to create an empty SPIFFS image?"; if (fileCount == 0 && JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]) != JOptionPane.YES_OPTION) { System.err.println(); editor.statusError("SPIFFS Warning: mkspiffs canceled!"); return; } editor.statusNotice("SPIFFS Creating Image..."); System.out.println("[SPIFFS] data : " + dataPath); System.out.println("[SPIFFS] size : " + ((spiEnd - spiStart) / 1024)); System.out.println("[SPIFFS] page : " + spiPage); System.out.println("[SPIFFS] block : " + spiBlock); try { if (listenOnProcess(new String[] { toolPath, "-c", dataPath, "-p", spiPage + "", "-b", spiBlock + "", "-s", (spiEnd - spiStart) + "", imagePath }) != 0) { System.err.println(); editor.statusError("SPIFFS Create Failed!"); return; } } catch (Exception e) { editor.statusError(e); editor.statusError("SPIFFS Create Failed!"); return; } title = "SPIFFS Copy"; message = "Would you like a copy of the SPIFFS image in your project folder?"; if (JOptionPane.showOptionDialog(editor, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) { File source = new File(imagePath); File dest = new File(editor.getSketch().getFolder(), "\\" + sketchName + ".spiffs.bin"); try { Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); System.out.println("Copied SPIFFS image"); } catch (IOException e) { System.out.println(e); editor.statusError("Copy SPIFFS image failed"); } } editor.statusNotice("SPIFFS Uploading Image..."); System.out.println("[SPIFFS] upload : " + imagePath); if (isNetwork) { String pythonCmd; if (PreferencesData.get("runtime.os").contentEquals("windows")) pythonCmd = "python.exe"; else pythonCmd = "python"; System.out.println("[SPIFFS] IP : " + serialPort); System.out.println(); sysExec(new String[] { pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath }); } else { System.out.println("[SPIFFS] address: " + uploadAddress); System.out.println("[SPIFFS] reset : " + resetMethod); System.out.println("[SPIFFS] port : " + serialPort); System.out.println("[SPIFFS] speed : " + uploadSpeed); System.out.println(); sysExec(new String[] { esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath }); } }
From source file:gdt.jgui.tool.JEntityEditor.java
/** * Get the context menu./*from w w w . j a va 2 s.c o m*/ * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("EntityEditor:getConextMenu:menu selected"); if (editCellItem != null) menu.remove(editCellItem); if (deleteItemsItem != null) menu.remove(deleteItemsItem); if (copyItem != null) menu.remove(copyItem); if (pasteItem != null) menu.remove(pasteItem); if (cutItem != null) menu.remove(cutItem); if (hasEditingCell()) { //menu.addSeparator(); editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getEditCellLocator(); if (locator$ != null) JConsoleHandler.execute(console, locator$); } }); menu.add(editCellItem); } if (hasSelectedRows()) { deleteItemsItem = new JMenuItem("Delete items"); deleteItemsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete selected items ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { deleteRows(); } } }); menu.add(deleteItemsItem); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { element$ = null; content = getContent(true); } }); menu.add(copyItem); cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = tabbedPane.getSelectedIndex(); element$ = tabbedPane.getTitleAt(i); content = getContent(true); } }); menu.add(cutItem); } if (content != null) { pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { pasteTable(content); int j = tabbedPane.getSelectedIndex(); if (element$ != null) { int cnt = tabbedPane.getComponentCount(); for (int i = 0; i < cnt; i++) { if (element$.equals(tabbedPane.getTitleAt(i))) { tabbedPane.setSelectedIndex(i); cutTable(content); tabbedPane.setSelectedIndex(j); } } } } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); console.back(); } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); menu.addSeparator(); JMenuItem addItemItem = new JMenuItem("Add item"); addItemItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addRow(); } }); menu.add(addItemItem); JMenuItem addElementItem = new JMenuItem("Add element"); addElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String element$ = "new element"; //addElement(element$); String locator$ = getRenameElementLocator(element$); JConsoleHandler.execute(console, locator$); } }); menu.add(addElementItem); JMenuItem deleteElementItem = new JMenuItem("Delete element"); deleteElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete element ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { tabbedPane.remove(tabbedPane.getSelectedComponent()); } } }); menu.add(deleteElementItem); JMenuItem renameElementItem = new JMenuItem("Rename element"); renameElementItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int i = tabbedPane.getSelectedIndex(); String locator$ = getRenameElementLocator(tabbedPane.getTitleAt(i)); JConsoleHandler.execute(console, locator$); } }); menu.add(renameElementItem); menu.addSeparator(); if (hasEditingCell()) { editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String locator$ = getEditCellLocator(); if (locator$ != null) JConsoleHandler.execute(console, locator$); } }); menu.add(editCellItem); } return menu; }
From source file:net.sourceforge.doddle_owl.ui.GeneralOntologySelectionPanel.java
public void actionPerformed(ActionEvent e) { DODDLEProject project = DODDLE_OWL.getCurrentProject(); if (e.getSource() == removeGeneralOntologyDirButton) { int result = JOptionPane.showConfirmDialog(this, Translator.getTerm("RemoveGeneralOntologyDirectoryButton") + ": " + System.lineSeparator() + Utils.TEMP_DIR); if (result == JOptionPane.YES_OPTION) { String tmpDirName = "net.sourceforge.doddle-owl"; // tmpDirName??????????? File tmpDir = new File(Utils.TEMP_DIR); if (tmpDir.getAbsolutePath().contains(tmpDirName)) { deleteFile(tmpDir); // ??????? }//w w w .j a v a 2 s. c om } } else if (e.getSource() == edrCheckBox) { enableEDRDic(edrCheckBox.isSelected()); project.addLog("GenericEDRCheckBox", edrCheckBox.isSelected()); } else if (e.getSource() == edrtCheckBox) { enableEDRTDic(edrtCheckBox.isSelected()); project.addLog("TechnicalEDRCheckBox", edrtCheckBox.isSelected()); } else if (e.getSource() == wnCheckBox) { enableWordNetDic(wnCheckBox.isSelected()); wnVersionSelectionPanel.setEnabled(wnCheckBox.isSelected()); project.addLog("WordNetCheckBox", wnCheckBox.isSelected()); } else if (e.getSource() == jpnWnCheckBox) { enableJpnWordNetDic(jpnWnCheckBox.isSelected()); project.addLog("JpnWordNetCheckBox", jpnWnCheckBox.isSelected()); } else if (e.getSource() == jwoCheckBox) { if (jwoCheckBox.isSelected()) { File jwoDir = new File(JWO_HOME); if (!jwoDir.exists()) { jwoDir.mkdir(); } String[] tdbFiles = { "GOSP.dat", "GOSP.idn", "GOSP.info", "GPOS.dat", "GPOS.idn", "GPOS.info", "GSPO.dat", "GSPO.idn", "GSPO.info", "node2id.dat", "node2id.idn", "node2id.info", "nodes.dat", "nodes.info", "OSP.dat", "OSP.idn", "OSP.info", "OSPG.dat", "OSPG.idn", "OSPG.info", "POS.dat", "POS.idn", "POS.info", "POSG.dat", "POSG.idn", "POSG.info", "prefix2id.dat", "prefix2id.idn", "prefix2id.info", "prefixes.dat", "prefixes.info", "prefixIdx.dat", "prefixIdx.idn", "prefixIdx.info", "SPO.dat", "SPO.idn", "SPO.info", "SPOG.dat", "SPOG.idn", "SPOG.info", "this.info" }; for (String fname : tdbFiles) { File f = new File(JWO_HOME + File.separator + fname); if (!f.exists()) { URL url = DODDLE_OWL.class.getClassLoader() .getResource(Utils.RESOURCE_DIR + "jwo/" + f.getName()); try { if (url != null) { FileUtils.copyURLToFile(url, f); DODDLE_OWL.getLogger().log(Level.INFO, "copy: " + f.getAbsolutePath()); } } catch (IOException ioe) { ioe.printStackTrace(); } } } if (OWLOntologyManager.getRefOntology(jwoDir.getAbsolutePath()) == null) { dataset = TDBFactory.createDataset(jwoDir.getAbsolutePath()); Model ontModel = dataset.getDefaultModel(); ReferenceOWLOntology refOnt = new ReferenceOWLOntology(ontModel, jwoDir.getAbsolutePath(), nameSpaceTable); OWLOntologyManager.addRefOntology(refOnt.getURI(), refOnt); } } } }
From source file:com.floreantpos.customer.DefaultCustomerListView.java
protected void doRemoveCustomerFromTicket() { int option = POSMessageDialog.showYesNoQuestionDialog(this, Messages.getString("CustomerSelectionDialog.2"), //$NON-NLS-1$ Messages.getString("CustomerSelectionDialog.32")); //$NON-NLS-1$ if (option != JOptionPane.YES_OPTION) { return;/*www. ja v a2s .c o m*/ } ticket.removeCustomer(); TicketDAO.getInstance().saveOrUpdate(ticket); //setCanceled(false); //dispose(); }
From source file:dbseer.gui.panel.DBSeerMiddlewarePanel.java
@Override public void actionPerformed(ActionEvent actionEvent) { try {//from w ww .j av a 2s .c om if (actionEvent.getSource() == startMonitoringButton) { id = idField.getText(); password = String.valueOf(passwordField.getPassword()); ip = ipField.getText(); port = Integer.parseInt(portField.getText()); // liveDatasetPath = DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + // DBSeerConstants.LIVE_DATASET_PATH; String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); currentDatasetPath = DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + DBSeerConstants.ROOT_DATASET_PATH + File.separator + date; final File newDatasetDirectory = new File(currentDatasetPath); // create new dataset directory FileUtils.forceMkdir(newDatasetDirectory); if (newDatasetDirectory == null || !newDatasetDirectory.isDirectory()) { JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, String.format("We could not create the dataset directory: %s", currentDatasetPath), "Message", JOptionPane.PLAIN_MESSAGE); return; } if (runner != null) { runner.stop(); } DBSeerGUI.liveMonitorPanel.reset(); DBSeerGUI.liveMonitorInfo.reset(); DBSeerGUI.middlewareStatus.setText("Middleware: Connecting..."); startMonitoringButton.setEnabled(false); stopMonitoringButton.setEnabled(false); connectSuccess = true; runner = new MiddlewareClientRunner(id, password, ip, port, currentDatasetPath, this); runner.run(); int sleepCount = 0; while (liveLogProcessor == null || !liveLogProcessor.isStarted()) { Thread.sleep(250); sleepCount += 250; if (!connectSuccess) { return; } if (sleepCount > 10000) { JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, String.format("Failed to receive live logs."), "Message", JOptionPane.PLAIN_MESSAGE); runner.stop(); liveLogProcessor = null; return; } } DBSeerGUI.liveDatasets.clear(); String[] servers = liveLogProcessor.getServers(); for (String s : servers) { DBSeerDataSet newDataset = new DBSeerDataSet(); newDataset.setName(date + "_" + s); OpenDirectoryAction openDir = new OpenDirectoryAction(newDataset); openDir.openWithoutDialog(new File(newDatasetDirectory + File.separator + s)); DBSeerGUI.datasets.addElement(newDataset); newDataset.setCurrent(true); DBSeerGUI.liveDatasets.add(newDataset); } if (servers.length > 1) { DBSeerDataSet newDataset = new DBSeerDataSet(); newDataset.setName(date + "_all"); OpenDirectoryAction openDir = new OpenDirectoryAction(newDataset); openDir.openWithoutDialog(newDatasetDirectory); DBSeerGUI.datasets.addElement(newDataset); newDataset.setCurrent(true); DBSeerGUI.liveDatasets.add(newDataset); } // save last middleware connection DBSeerGUI.userSettings.setLastMiddlewareIP(ip); DBSeerGUI.userSettings.setLastMiddlewarePort(port); DBSeerGUI.userSettings.setLastMiddlewareID(id); XStreamHelper xmlHelper = new XStreamHelper(); xmlHelper.toXML(DBSeerGUI.userSettings, DBSeerGUI.settingsPath); } else if (actionEvent.getSource() == stopMonitoringButton) { int stopMonitoring = JOptionPane.showConfirmDialog(DBSeerGUI.mainFrame, "Do you really want to stop monitoring?", "Stop Monitoring", JOptionPane.YES_NO_OPTION); if (stopMonitoring == JOptionPane.YES_OPTION) { if (runner != null) { runner.stop(); } if (liveLogProcessor != null) { liveLogProcessor.stop(); } for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { dataset.setCurrent(false); } boolean isRemoved = false; if (DBSeerGUI.dbscan == null || (DBSeerGUI.dbscan != null && !DBSeerGUI.dbscan.isInitialized())) { JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, String.format( "Not enough transactions for clustering. You need at least %d transactions. Datasets are removed.", DBSeerGUI.settings.dbscanInitPts), "Message", JOptionPane.PLAIN_MESSAGE); for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { DBSeerGUI.datasets.removeElement(dataset); } isRemoved = true; } if (!isRemoved) { if (liveLogProcessor != null && !liveLogProcessor.isTxWritingStarted()) { JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, String.format( "Live monitoring has not written any transactions yet. Datasets are removed."), "Message", JOptionPane.PLAIN_MESSAGE); for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { DBSeerGUI.datasets.removeElement(dataset); } } } DBSeerGUI.liveDatasets.clear(); if (liveLogProcessor != null) { liveLogProcessor = null; } DBSeerGUI.liveMonitorPanel.reset(); startMonitoringButton.setEnabled(true); stopMonitoringButton.setEnabled(false); DBSeerGUI.middlewareStatus.setText("Middleware: Not Connected"); } // if (DBSeerGUI.dbscan == null || // (DBSeerGUI.dbscan != null && !DBSeerGUI.dbscan.isInitialized())) // { // JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, // String.format("Not enough transactions for clustering. You need at least %d transactions. Dataset is not saved.", DBSeerGUI.settings.dbscanInitPts), // "Message", JOptionPane.PLAIN_MESSAGE); // // DBSeerGUI.liveMonitorPanel.reset(); // DBSeerGUI.liveMonitorInfo.reset(); // // startMonitoringButton.setEnabled(true); // stopMonitoringButton.setEnabled(false); // DBSeerGUI.middlewareStatus.setText("Middleware: Not Connected"); // // return; // } // if (!liveLogProcessor.isTxWritingStarted()) // { // JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, // String.format("Live monitoring has not written any transactions yet. Dataset is not saved."), // "Message", JOptionPane.PLAIN_MESSAGE); // // DBSeerGUI.liveMonitorPanel.reset(); // DBSeerGUI.liveMonitorInfo.reset(); // // startMonitoringButton.setEnabled(true); // stopMonitoringButton.setEnabled(false); // DBSeerGUI.middlewareStatus.setText("Middleware: Not Connected"); // // return; // } // // int saveResult = JOptionPane.showConfirmDialog(DBSeerGUI.mainFrame, "Do you want to save the monitored data?", // "Save monitored data as a dataset", JOptionPane.YES_NO_OPTION); // // if (saveResult == JOptionPane.YES_OPTION) // { // String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); // String newDatasetPath = DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + // DBSeerConstants.ROOT_DATASET_PATH + File.separator + date; // File liveDatasetDirectory = new File(liveDatasetPath); // final File newDatasetDirectory = new File(newDatasetPath); // // // create new dataset directory // FileUtils.forceMkdir(newDatasetDirectory); // // // copy dataset // FileUtils.copyDirectory(liveDatasetDirectory, newDatasetDirectory, false); // // // show message dialog. // JOptionPane.showMessageDialog(DBSeerGUI.mainFrame, // String.format("Dataset has been successfully saved under '%s'", newDatasetDirectory.getCanonicalPath()), // "Message", JOptionPane.PLAIN_MESSAGE); // // String[] servers = liveLogProcessor.getServers(); // for (String s : servers) // { // DBSeerDataSet newDataset = new DBSeerDataSet(); // newDataset.setName(date + "_" + s); // OpenDirectoryAction openDir = new OpenDirectoryAction(newDataset); // openDir.openWithoutDialog(new File(newDatasetDirectory + File.separator + s)); // DBSeerGUI.datasets.addElement(newDataset); // } // if (servers.length > 1) // { // DBSeerDataSet newDataset = new DBSeerDataSet(); // newDataset.setName(date + "_all"); // OpenDirectoryAction openDir = new OpenDirectoryAction(newDataset); // openDir.openWithoutDialog(newDatasetDirectory); // DBSeerGUI.datasets.addElement(newDataset); // } // SaveSettingsAction saveSettings = new SaveSettingsAction(); // saveSettings.actionPerformed(new ActionEvent(this, 0, "")); // } } else if (actionEvent.getSource() == applyRefreshRateButton) { int rate = Integer.parseInt(refreshRateField.getText()); DBSeerGUI.liveMonitorRefreshRate = rate; } } catch (Exception e) { DBSeerExceptionHandler.handleException(e); } // old implementation /* final MiddlewareSocket socket = DBSeerGUI.middlewareSocket; if (actionEvent.getSource() == logInOutButton) { if (!isLoggedIn) { String ip = ipField.getText(); int port = Integer.parseInt(portField.getText()); String id = idField.getText(); String password = String.valueOf(passwordField.getPassword()); try { if (!socket.connect(ip, port)) { return; } if (socket.login(id, password)) { if (socket.isMonitoring(true)) { DBSeerGUI.middlewareStatus.setText("Middleware Connected: " + socket.getIp() + ":" + socket.getPort() + " as " + socket.getId() + " (Monitoring)"); startMonitoringButton.setEnabled(false); stopMonitoringButton.setEnabled(true); } else { DBSeerGUI.middlewareStatus.setText("Middleware Connected: " + socket.getIp() + ":" + socket.getPort() + " as " + socket.getId()); startMonitoringButton.setEnabled(true); stopMonitoringButton.setEnabled(false); } // save last login credentials DBSeerGUI.userSettings.setLastMiddlewareIP(socket.getIp()); DBSeerGUI.userSettings.setLastMiddlewarePort(socket.getPort()); DBSeerGUI.userSettings.setLastMiddlewareID(socket.getId()); XStreamHelper xmlHelper = new XStreamHelper(); xmlHelper.toXML(DBSeerGUI.userSettings, DBSeerGUI.settingsPath); this.setLogin(); } else { JOptionPane.showMessageDialog(null, socket.getErrorMessage(), "Middleware Login Error", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { DBSeerExceptionHandler.handleException(e, "Middleware Login Error"); // JOptionPane.showMessageDialog(null, e.getMessage(), "Middleware Login Error", JOptionPane.ERROR_MESSAGE); } } else // log out { try { socket.disconnect(); startMonitoringButton.setEnabled(false); stopMonitoringButton.setEnabled(false); } catch (Exception e) { DBSeerExceptionHandler.handleException(e); } } } else if (actionEvent.getSource() == startMonitoringButton) { try { if (socket.startMonitoring()) { DBSeerGUI.middlewareStatus.setText("Middleware Connected: " + socket.getIp() + ":" + socket.getPort() + " as " + socket.getId() + " (Monitoring)"); startMonitoringButton.setEnabled(false); stopMonitoringButton.setEnabled(true); } else { JOptionPane.showMessageDialog(null, socket.getErrorMessage(), "Middleware Monitoring Error", JOptionPane.ERROR_MESSAGE); } } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Middleware Error", JOptionPane.ERROR_MESSAGE); } } else if (actionEvent.getSource() == stopMonitoringButton) { try { startMonitoringButton.setEnabled(true); stopMonitoringButton.setEnabled(false); if (!socket.isMonitoring(false)) { return; } final String datasetRootPath = DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + DBSeerConstants.ROOT_DATASET_PATH; final String liveDatasetPath = DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + DBSeerConstants.LIVE_DATASET_PATH; final File rawDatasetDir = new File(datasetRootPath); if (!rawDatasetDir.exists()) { rawDatasetDir.mkdirs(); } String datasetName = (String)JOptionPane.showInputDialog(this, "Enter the name of new dataset", "New Dataset", JOptionPane.PLAIN_MESSAGE, null, null, "NewDataset"); boolean getData = true; File newRawDatasetDir = null; if (datasetName == null) { getData = false; } else { // newRawDatasetDir = new File(DBSeerConstants.RAW_DATASET_PATH + File.separator + datasetName); newRawDatasetDir = new File(datasetRootPath + File.separator + datasetName); while (newRawDatasetDir.exists()) { datasetName = (String) JOptionPane.showInputDialog(this, datasetName + " already exists.\n" + "Enter the name of new dataset", "New Dataset", JOptionPane.PLAIN_MESSAGE, null, null, "NewDataset"); newRawDatasetDir = new File(datasetRootPath + File.separator + datasetName); } newRawDatasetDir.mkdirs(); } final boolean downloadData = getData; final File datasetDir = newRawDatasetDir; final String datasetNameFinal = datasetName; final JPanel middlewarePanel = this; final JButton logButton = logInOutButton; final JButton startButton = startMonitoringButton; SwingWorker<Void, Void> datasetWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (downloadData) { DBSeerGUI.status.setText("Stopping monitoring..."); middlewarePanel.setEnabled(false); logButton.setEnabled(false); startButton.setEnabled(false); } if (socket.stopMonitoring(downloadData)) { DBSeerGUI.middlewareStatus.setText("Middleware Connected: " + socket.getIp() + ":" + socket.getPort() + " as " + socket.getId()); DBSeerGUI.liveMonitorPanel.reset(); if (!downloadData) { return null; } // File logFile = socket.getLogFile(); // byte[] buf = new byte[8192]; // int length = 0; // // FileInputStream byteStream = new FileInputStream(logFile); // ZipInputStream zipInputStream = new ZipInputStream(byteStream); // ZipEntry entry = null; // // // unzip the monitor package. // while ((entry = zipInputStream.getNextEntry()) != null) // { // File entryFile = new File(liveDatasetPath + File.separator + entry.getName()); // new File(entryFile.getParent()).mkdirs(); // // FileOutputStream out = new FileOutputStream(liveDatasetPath + File.separator + entry.getName()); // // try // { // while ((length = zipInputStream.read(buf, 0, 8192)) >= 0) // { // out.write(buf, 0, length); // } // } // catch (EOFException e) // { // // do nothing // } // // //zipInputStream.closeEntry(); // out.flush(); // out.close(); // } // zipInputStream.close(); // move dataset from 'temp' to user-specified directory File liveDir = new File(DBSeerGUI.userSettings.getDBSeerRootPath() + File.separator + DBSeerConstants.LIVE_DATASET_PATH); File[] files = liveDir.listFiles(); for (File f : files) { FileUtils.moveFileToDirectory(f, datasetDir, false); } // We may not need to process the data after all? // int confirm = JOptionPane.showConfirmDialog(null, // "The monitoring data has been downloaded.\n" + // "Do you want to proceed and process the downloaded dataset?", // "Warning", // JOptionPane.YES_NO_OPTION); // // if (confirm == JOptionPane.YES_OPTION) // { // // process the dataset // DBSeerGUI.status.setText("Processing the dataset..."); // DataCenter dc = new DataCenter(DBSeerConstants.ROOT_DATASET_PATH, datasetNameFinal, true); // if (!dc.parseLogs()) // { // JOptionPane.showMessageDialog(null, "Failed to parse received monitoring logs", "Error", JOptionPane.ERROR_MESSAGE); // } // // if (!dc.processDataset()) // { // JOptionPane.showMessageDialog(null, "Failed to process received dataset", "Error", JOptionPane.ERROR_MESSAGE); // } // } } else { JOptionPane.showMessageDialog(null, socket.getErrorMessage(), "Middleware Monitoring Error", JOptionPane.ERROR_MESSAGE); } return null; } @Override protected void done() { DBSeerGUI.status.setText(""); middlewarePanel.setEnabled(true); logButton.setEnabled(true); startButton.setEnabled(true); } }; datasetWorker.execute(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); DBSeerGUI.status.setText(""); } } else if (actionEvent.getSource() == applyRefreshRateButton) { int rate = Integer.parseInt(refreshRateField.getText()); DBSeerGUI.liveMonitorRefreshRate = rate; } */ }
From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java
private boolean showUnsavedChangesDialog() { int result = JOptionPane.showConfirmDialog(this, "You have unsaved changes. Cancel anyway?", "Unsaved changes", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { return true; }/*from w ww.ja v a2 s .com*/ return false; }
From source file:net.sf.jabref.gui.exporter.SaveDatabaseAction.java
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException { SaveSession session;/* w w w . ja v a 2 s . co m*/ frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs) .withEncoding(encoding); BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs); } else { session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); } panel.registerUndoableChanges(session); } catch (UnsupportedCharsetException ex2) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization .lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } catch (SaveException ex) { if (ex == SaveException.FILE_LOCKED) { throw ex; } if (ex.specificEntry()) { // Error occured during processing of // be. Highlight it: int row = panel.getMainTable().findEntry(ex.getEntry()); int topShow = Math.max(0, row - 3); panel.getMainTable().setRowSelectionInterval(row, row); panel.getMainTable().scrollTo(topShow); panel.showEntry(ex.getEntry()); } else { LOGGER.error("Problem saving file", ex); } JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } finally { frame.unblock(); } boolean commit = true; if (!session.getWriter().couldEncodeAll()) { FormBuilder builder = FormBuilder.create() .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters()); ta.setEditable(false); builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1); builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding); if (choice == null) { commit = false; } else { Charset newEncoding = Charset.forName((String) choice); return saveDatabase(file, selectedOnly, newEncoding); } } else if (answer == JOptionPane.CANCEL_OPTION) { commit = false; } } try { if (commit) { session.commit(file.toPath()); panel.getBibDatabaseContext().getMetaData().setEncoding(encoding); // Make sure to remember which encoding we used. } else { session.cancel(); } } catch (SaveException e) { int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { session.setUseBackup(false); session.commit(file.toPath()); panel.getBibDatabaseContext().getMetaData().setEncoding(encoding); } else { commit = false; } } return commit; }
From source file:com.xilinx.virtex7.MainScreen.java
public void initialize(LandingPage l, String imgName, int mode) { lp = l;//w ww . ja v a2 s . c o m blockDiagram = Toolkit.getDefaultToolkit() .getImage(getClass().getResource("/com/xilinx/virtex7/" + imgName)); led1 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/green.png")); led2 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/ledoff.png")); led3 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/gui/red.png")); this.mode = mode; setModeText(mode); dataMismatch0 = dataMismatch2 = errcnt0 = errcnt1 = false; dataMismatch4 = dataMismatch6 = errcnt2 = errcnt3 = false; di = null; di = new DriverInfo(); di.init(mode); int ret = di.get_PCIstate(); //ret = di.get_PowerStats(); test1_option = DriverInfo.ENABLE_LOOPBACK; test2_option = DriverInfo.ENABLE_LOOPBACK; test3_option = DriverInfo.ENABLE_LOOPBACK; test4_option = DriverInfo.ENABLE_LOOPBACK; // create a new jframe, and pack it frame = new JFrame("Virtex-7 XT Connectivity TRD Control & Monitoring Interface"); frame.pack(); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); final int m = mode; frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // check if tests are running or not if ((testStarted || testStarted1 || testStarted2 || testStarted3) && ((m != LandingPage.APPLICATION_MODE) || (m != LandingPage.APPLICATION_MODE_P2P))) { int confirmed = JOptionPane.showConfirmDialog(null, "This will stop the tests and uninstall the drivers. Do you want to continue?", "Exit", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { if (testStarted) { di.stopTest(0, test1_option, Integer.parseInt(t1_psize.getText())); testStarted = false; } if (testStarted1) { di.stopTest(1, test2_option, Integer.parseInt(t2_psize.getText())); testStarted1 = false; } if (testStarted2) { di.stopTest(2, test3_option, Integer.parseInt(t3_psize.getText())); testStarted2 = false; } if (testStarted3) { di.stopTest(3, test4_option, Integer.parseInt(t4_psize.getText())); testStarted3 = false; } timer.cancel(); textArea.removeAll(); di.flush(); di = null; System.gc(); lp.uninstallDrivers(); showDialog("Removing Device Drivers...Please wait..."); } } else { int confirmed = JOptionPane.showConfirmDialog(null, "This will Uninstall the drivers. Do you want to continue?", "Exit", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { timer.cancel(); textArea.removeAll(); di.flush(); di = null; System.gc(); lp.uninstallDrivers(); showDialog("Removing Device Drivers...Please wait..."); } } } }); // make the frame half the height and width Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); height = screenSize.height; width = screenSize.width; minWidth = 1000; minHeight = 600; minFrameWidth = 1024; minFrameHeight = 745; reqHeight = 745; if (width < 1280) reqWidth = 1024; else if (width == 1280) reqWidth = 1280; else if (width < 1600) { reqWidth = width - (width * 4) / 100; reqHeight = height - (height * 3) / 100; } else { reqWidth = reqHeight = height = height - (height * 10) / 100; } frame.setSize(new Dimension(minFrameWidth, minFrameHeight)); frame.setResizable(true); frame.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { frame.setSize(new Dimension(Math.max(minFrameWidth, frame.getWidth()), Math.max(minFrameHeight, frame.getHeight()))); } @Override public void componentMoved(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } @Override public void componentShown(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } @Override public void componentHidden(ComponentEvent ce) { //throw new UnsupportedOperationException("Not supported yet."); } }); frame.setVisible(true); frame.setIconImage( Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/xilinx/virtex7/icon.png"))); // center the jframe on screen frame.setLocationRelativeTo(null); frame.setContentPane(createContentPane()); keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.RED); StyleConstants.setBold(keyWord, true); logStatus = new SimpleAttributeSet(); StyleConstants.setForeground(logStatus, Color.BLACK); StyleConstants.setBold(logStatus, true); if ((mode == LandingPage.APPLICATION_MODE) || (mode == LandingPage.APPLICATION_MODE_P2P)) { testStarted = testStarted1 = testStarted2 = testStarted3 = true; } if (mode == LandingPage.PERFORMANCE_MODE_RAW) { t1_o1.setSelected(true); t1_o2.setEnabled(false); t1_o3.setEnabled(false); t2_o2.setEnabled(false); t2_o3.setEnabled(false); } if (mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { t1_o2.setEnabled(false); t1_o3.setEnabled(false); t2_o2.setEnabled(false); t2_o3.setEnabled(false); t1_o1.setSelected(true); } // initialize max packet size ret = di.get_EngineState(); EngState[] engData = di.getEngState(); maxpkt0 = engData[0].MaxPktSize; minpkt0 = engData[0].MinPktSize; minpkt1 = engData[2].MinPktSize; maxpkt1 = engData[2].MaxPktSize; maxpkt2 = engData[4].MaxPktSize; minpkt2 = engData[4].MinPktSize; minpkt3 = engData[6].MinPktSize; maxpkt3 = engData[6].MaxPktSize; t1_psize.setText(String.valueOf(maxpkt0)); t2_psize.setText(String.valueOf(maxpkt1)); t3_psize.setText(String.valueOf(maxpkt2)); t4_psize.setText(String.valueOf(maxpkt3)); t1_psize.setToolTipText(minpkt0 + "-" + maxpkt0); t2_psize.setToolTipText(minpkt1 + "-" + maxpkt1); t3_psize.setToolTipText(minpkt2 + "-" + maxpkt2); t4_psize.setToolTipText(minpkt3 + "-" + maxpkt3); updateLog(di.getPCIInfo().getVersionInfo(), logStatus); updateLog("Configuration: " + modeText, logStatus); // LED status di.get_LedStats(); lstats = di.getLedStats(); setLedStats(lstats); // if (mode == LandingPage.PERFORMANCE_MODE_RAW || mode == LandingPage.PERFORMANCE_MODE_RAW_DV) { t2_o1.setEnabled(true); t4_o1.setEnabled(true); } else { t2_o1.setEnabled(false); t4_o1.setEnabled(false); } t2_o2.setEnabled(false); t2_o3.setEnabled(false); t3_o2.setEnabled(false); t3_o3.setEnabled(false); t4_o2.setEnabled(false); t4_o3.setEnabled(false); startTimer(); }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Delete node(s)' action.//from w w w.j a va 2 s. c om * <p> * The action is created and mapped to the [Delete] key stroke * </p> * * @return the action */ @SuppressWarnings("serial") private Action getDeleteAction() { if (this.deleteAction == null) { String actionCommand = bundle.getString(DELETE_NODE_KEY); String actionKey = bundle.getString(DELETE_NODE_KEY + ".action"); this.deleteAction = new AbstractAction(actionCommand, Icons.DELETE) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { // Checks if several nodes will be deleted if (nodes.length > 1) { model.deleteNodes(nodes); } else { model.deleteNode(nodes[0]); } } } private boolean checkAction() { // No node selected if (nodes == null) { JOptionPane.showMessageDialog(JZVNodePanel.this, bundle.getString("dlg.error.deleteWithoutSelection"), bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE); return false; } return (JOptionPane.showConfirmDialog(JZVNodePanel.this, bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION); } }; this.deleteAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionKey); this.getActionMap().put(actionKey, this.deleteAction); } return this.deleteAction; }