List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException
optionType
parameter. From source file:gui.FormFrame.java
FormFrame(MainHandler mainHandler, final String usage, Pays argpays) throws PaysNotFoundException { this.setResizable(false); this.usage = usage; this.argpays = argpays; mainPanel = new JPanel(); formPanel = new JPanel(); this.mainHandler = mainHandler; //this.setLayout(new FlowLayout()); this.getContentPane().add(mainPanel); init();//from www . j a v a 2 s . c o m this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { close(); } public void close() { int dialButton = JOptionPane.OK_CANCEL_OPTION; int dialResult; dialResult = JOptionPane.showConfirmDialog(null, "Vous etes sur le point de quitter sans avoir" + usage, "Attention !", dialButton); if (dialResult == JOptionPane.YES_OPTION) { dispose(); } } }); }
From source file:net.sf.taverna.t2.renderers.SVGRenderer.java
@SuppressWarnings("serial") public JComponent getComponent(Path path) throws RendererException { if (DataBundles.isValue(path) || DataBundles.isReference(path)) { long approximateSizeInBytes = 0; try {// ww w . j av a2s . c o m approximateSizeInBytes = RendererUtils.getSizeInBytes(path); } catch (Exception ex) { logger.error("Failed to get the size of the data", ex); return new JTextArea("Failed to get the size of the data (see error log for more details): \n" + ex.getMessage()); } if (approximateSizeInBytes > MEGABYTE) { int response = JOptionPane.showConfirmDialog(null, "Result is approximately " + bytesToMeg(approximateSizeInBytes) + " MB in size, there could be issues with rendering this inside Taverna\nDo you want to continue?", "Render as SVG?", JOptionPane.YES_NO_OPTION); if (response != JOptionPane.YES_OPTION) { return new JTextArea( "Rendering cancelled due to size of data. Try saving and viewing in an external application."); } } String resolve = null; try { // Resolve it as a string resolve = RendererUtils.getString(path); } catch (Exception e) { logger.error("Reference Service failed to render data as string", e); return new JTextArea( "Reference Service failed to render data as string (see error log for more details): \n" + e.getMessage()); } final JSVGCanvas svgCanvas = new JSVGCanvas(); File tmpFile = null; try { tmpFile = File.createTempFile("taverna", "svg"); tmpFile.deleteOnExit(); FileUtils.writeStringToFile(tmpFile, resolve, "utf8"); } catch (IOException e) { logger.error("SVG Renderer: Failed to write the data to temporary file", e); return new JTextArea( "Failed to write the data to temporary file (see error log for more details): \n" + e.getMessage()); } try { svgCanvas.setURI(tmpFile.toURI().toASCIIString()); } catch (Exception e) { logger.error("Failed to create SVG renderer", e); return new JTextArea( "Failed to create SVG renderer (see error log for more details): \n" + e.getMessage()); } JPanel jp = new JPanel() { @Override protected void finalize() throws Throwable { svgCanvas.stopProcessing(); super.finalize(); } }; jp.add(svgCanvas); return jp; } else { logger.error("Failed to obtain the data to render: data is not a value or reference"); return new JTextArea("Failed to obtain the data to render: data is not a value or reference"); } }
From source file:com.bright.json.JSonRequestor.java
public static void main(String[] args) { String fileBasename = null;//from w w w. j a va 2s .c o m String[] zipArgs = null; JFileChooser chooser = new JFileChooser("/Users/panos/STR_GRID"); try { chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle("Select the input directory"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); // String fileBasename = // chooser.getSelectedFile().toString().substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator)+1,chooser.getSelectedFile().toString().lastIndexOf(".")); fileBasename = chooser.getSelectedFile().toString() .substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator) + 1); System.out.println("Base name: " + fileBasename); zipArgs = new String[] { chooser.getSelectedFile().toString(), chooser.getCurrentDirectory().toString() + File.separator + fileBasename + ".zip" }; com.bright.utils.ZipFile.main(zipArgs); } else { System.out.println("No Selection "); } } catch (Exception e) { System.out.println(e.toString()); } JTextField uiHost = new JTextField("ucs-head.brightcomputing.com"); // TextPrompt puiHost = new // TextPrompt("hadoop.brightcomputing.com",uiHost); JTextField uiUser = new JTextField("nexus"); // TextPrompt puiUser = new TextPrompt("nexus", uiUser); JTextField uiPass = new JPasswordField("system"); // TextPrompt puiPass = new TextPrompt("", uiPass); JTextField uiWdir = new JTextField("/home/nexus/pp1234"); // TextPrompt puiWdir = new TextPrompt("/home/nexus/nexus_workdir", // uiWdir); JTextField uiOut = new JTextField("foo"); // TextPrompt puiOut = new TextPrompt("foobar123", uiOut); JPanel myPanel = new JPanel(new GridLayout(5, 1)); myPanel.add(new JLabel("Bright HeadNode hostname:")); myPanel.add(uiHost); // myPanel.add(Box.createHorizontalStrut(1)); // a spacer myPanel.add(new JLabel("Username:")); myPanel.add(uiUser); myPanel.add(new JLabel("Password:")); myPanel.add(uiPass); myPanel.add(new JLabel("Working Directory:")); myPanel.add(uiWdir); // myPanel.add(Box.createHorizontalStrut(1)); // a spacer myPanel.add(new JLabel("Output Study Name ( -s ):")); myPanel.add(uiOut); int result = JOptionPane.showConfirmDialog(null, myPanel, "Please fill in all the fields.", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("Input received."); } String rfile = uiWdir.getText(); String rhost = uiHost.getText(); String ruser = uiUser.getText(); String rpass = uiPass.getText(); String nexusOut = uiOut.getText(); String[] myarg = new String[] { zipArgs[1], ruser + "@" + rhost + ":" + rfile, nexusOut, fileBasename }; com.bright.utils.ScpTo.main(myarg); String cmURL = "https://" + rhost + ":8081/json"; List<Cookie> cookies = doLogin(ruser, rpass, cmURL); chkVersion(cmURL, cookies); jobSubmit myjob = new jobSubmit(); jobSubmit.jobObject myjobObj = new jobSubmit.jobObject(); myjob.setService("cmjob"); myjob.setCall("submitJob"); myjobObj.setQueue("defq"); myjobObj.setJobname("myNexusJob"); myjobObj.setAccount(ruser); myjobObj.setRundirectory(rfile); myjobObj.setUsername(ruser); myjobObj.setGroupname("cmsupport"); myjobObj.setPriority("1"); myjobObj.setStdinfile(rfile + "/stdin-mpi"); myjobObj.setStdoutfile(rfile + "/stdout-mpi"); myjobObj.setStderrfile(rfile + "/stderr-mpi"); myjobObj.setResourceList(Arrays.asList("")); myjobObj.setDependencies(Arrays.asList("")); myjobObj.setMailNotify(false); myjobObj.setMailOptions("ALL"); myjobObj.setMaxWallClock("00:10:00"); myjobObj.setNumberOfProcesses(1); myjobObj.setNumberOfNodes(1); myjobObj.setNodes(Arrays.asList("")); myjobObj.setCommandLineInterpreter("/bin/bash"); myjobObj.setUserdefined(Arrays.asList("cd " + rfile, "date", "pwd")); myjobObj.setExecutable("mpirun"); myjobObj.setArguments("-env I_MPI_FABRICS shm:tcp " + Constants.NEXUSSIM_EXEC + " -mpi -c " + rfile + "/" + fileBasename + "/" + fileBasename + " -s " + rfile + "/" + fileBasename + "/" + nexusOut); myjobObj.setModules(Arrays.asList("shared", "nexus", "intel-mpi/64")); myjobObj.setDebug(false); myjobObj.setBaseType("Job"); myjobObj.setIsSlurm(true); myjobObj.setUniqueKey(0); myjobObj.setModified(false); myjobObj.setToBeRemoved(false); myjobObj.setChildType("SlurmJob"); myjobObj.setJobID("Nexus test"); // Map<String,jobSubmit.jobObject > mymap= new HashMap<String, // jobSubmit.jobObject>(); // mymap.put("Slurm",myjobObj); ArrayList<Object> mylist = new ArrayList<Object>(); mylist.add("slurm"); mylist.add(myjobObj); myjob.setArgs(mylist); GsonBuilder builder = new GsonBuilder(); builder.enableComplexMapKeySerialization(); // Gson g = new Gson(); Gson g = builder.create(); String json2 = g.toJson(myjob); // To be used from a real console and not Eclipse Delete.main(zipArgs[1]); String message = JSonRequestor.doRequest(json2, cmURL, cookies); @SuppressWarnings("resource") Scanner resInt = new Scanner(message).useDelimiter("[^0-9]+"); int jobID = resInt.nextInt(); System.out.println("Job ID: " + jobID); JOptionPane optionPane = new JOptionPane(message); JDialog myDialog = optionPane.createDialog(null, "CMDaemon response: "); myDialog.setModal(false); myDialog.setVisible(true); ArrayList<Object> mylist2 = new ArrayList<Object>(); mylist2.add("slurm"); String JobID = Integer.toString(jobID); mylist2.add(JobID); myjob.setArgs(mylist2); myjob.setService("cmjob"); myjob.setCall("getJob"); String json3 = g.toJson(myjob); System.out.println("JSON Request No. 4 " + json3); cmReadFile readfile = new cmReadFile(); readfile.setService("cmmain"); readfile.setCall("readFile"); readfile.setUserName(ruser); int fileByteIdx = 1; readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx); String json4 = g.toJson(readfile); String monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", ""); if (monFile.startsWith("Unable")) { monFile = ""; } else { fileByteIdx += countLines(monFile, "\\\\n"); System.out.println(""); } StringBuffer output = new StringBuffer(); // Get the correct Line Separator for the OS (CRLF or LF) String nl = System.getProperty("line.separator"); String filename = chooser.getCurrentDirectory().toString() + File.separator + fileBasename + ".sum.txt"; System.out.println("Local monitoring file: " + filename); output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator"))); String getJobJSON = JSonRequestor.doRequest(json3, cmURL, cookies); jobGet getJobObj = new Gson().fromJson(getJobJSON, jobGet.class); System.out.println("Job " + jobID + " status: " + getJobObj.getStatus().toString()); while (getJobObj.getStatus().toString().equals("RUNNING") || getJobObj.getStatus().toString().equals("COMPLETING")) { try { getJobJSON = JSonRequestor.doRequest(json3, cmURL, cookies); getJobObj = new Gson().fromJson(getJobJSON, jobGet.class); System.out.println("Job " + jobID + " status: " + getJobObj.getStatus().toString()); readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx); json4 = g.toJson(readfile); monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", ""); if (monFile.startsWith("Unable")) { monFile = ""; } else { output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator"))); System.out.println("FILE INDEX:" + fileByteIdx); fileByteIdx += countLines(monFile, "\\\\n"); } Thread.sleep(Constants.STATUS_CHECK_INTERVAL); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } Gson gson_nice = new GsonBuilder().setPrettyPrinting().create(); String json_out = gson_nice.toJson(getJobJSON); System.out.println(json_out); System.out.println("JSON Request No. 5 " + json4); readfile.setPath(rfile + "/" + fileBasename + "/" + fileBasename + ".sum@+" + fileByteIdx); json4 = g.toJson(readfile); monFile = JSonRequestor.doRequest(json4, cmURL, cookies).replaceAll("^\"|\"$", ""); if (monFile.startsWith("Unable")) { monFile = ""; } else { output.append(monFile.replaceAll("\\\\n", System.getProperty("line.separator"))); fileByteIdx += countLines(monFile, "\\\\n"); } System.out.println("FILE INDEX:" + fileByteIdx); /* * System.out.print("Monitoring file: " + monFile.replaceAll("\\n", * System.getProperty("line.separator"))); try { * FileUtils.writeStringToFile( new * File(chooser.getCurrentDirectory().toString() + File.separator + * fileBasename + ".sum.txt"), monFile.replaceAll("\\n", * System.getProperty("line.separator"))); } catch (IOException e) { * * e.printStackTrace(); } */ if (getJobObj.getStatus().toString().equals("COMPLETED")) { String[] zipArgs_from = new String[] { chooser.getSelectedFile().toString(), chooser.getCurrentDirectory().toString() + File.separator + fileBasename + "_out.zip" }; String[] myarg_from = new String[] { ruser + "@" + rhost + ":" + rfile + "/" + fileBasename + "_out.zip", zipArgs_from[1], rfile, fileBasename }; com.bright.utils.ScpFrom.main(myarg_from); JOptionPane optionPaneS = new JOptionPane("Job execution completed without errors!"); JDialog myDialogS = optionPaneS.createDialog(null, "Job status: "); myDialogS.setModal(false); myDialogS.setVisible(true); } else { JOptionPane optionPaneF = new JOptionPane("Job execution FAILED!"); JDialog myDialogF = optionPaneF.createDialog(null, "Job status: "); myDialogF.setModal(false); myDialogF.setVisible(true); } try { System.out.println("Local monitoring file: " + filename); BufferedWriter out = new BufferedWriter(new FileWriter(filename)); String outText = output.toString(); String newString = outText.replace("\\\\n", nl); System.out.println("Text: " + outText); out.write(newString); out.close(); rmDuplicateLines.main(filename); } catch (IOException e) { e.printStackTrace(); } doLogout(cmURL, cookies); System.exit(0); }
From source file:ca.uviccscu.lp.utils.Utils.java
@Deprecated public static boolean checkDir(File f) { l.trace("Checking dir: " + f.getAbsolutePath()); try {/* w ww . jav a 2s .c o m*/ boolean a = f.isDirectory(); if (a) { if (f.listFiles().length != 0) { l.error("Directory not empty"); //JDialog jd = new JDialog((JFrame) null, true); int resp = JOptionPane.showConfirmDialog(null, "Directory nonempty: " + f.getAbsolutePath() + ". Proceed? (will wipe)", "Confirm deletion", JOptionPane.YES_NO_OPTION); if (resp == JOptionPane.YES_OPTION) { FileUtils.deleteDirectory(f); } else { l.fatal("Delete denied"); System.exit(1); } } } FileUtils.forceMkdir(f); File test = new File(f.getAbsolutePath() + File.separator + "test.file"); boolean c = test.createNewFile(); return c; } catch (Exception e) { l.fatal("Az directory creation error", e); return false; } }
From source file:com.floreantpos.bo.actions.DataExportAction.java
@Override public void actionPerformed(ActionEvent e) { Session session = null;/*from www. ja v a 2 s . co m*/ Transaction transaction = null; FileWriter fileWriter = null; GenericDAO dao = new GenericDAO(); try { JFileChooser fileChooser = getFileChooser(); int option = fileChooser.showSaveDialog(com.floreantpos.util.POSUtil.getBackOfficeWindow()); if (option != JFileChooser.APPROVE_OPTION) { return; } File file = fileChooser.getSelectedFile(); if (file.exists()) { option = JOptionPane.showConfirmDialog(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataExportAction.1") + file.getName() + "?", //$NON-NLS-1$//$NON-NLS-2$ Messages.getString("DataExportAction.3"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION); if (option != JOptionPane.YES_OPTION) { return; } } // fixMenuItemModifierGroups(); JAXBContext jaxbContext = JAXBContext.newInstance(Elements.class); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); StringWriter writer = new StringWriter(); session = dao.createNewSession(); transaction = session.beginTransaction(); Elements elements = new Elements(); // * 2. USERS // * 3. TAX // * 4. MENU_CATEGORY // * 5. MENU_GROUP // * 6. MENU_MODIFIER // * 7. MENU_MODIFIER_GROUP // * 8. MENU_ITEM // * 9. MENU_ITEM_SHIFT // * 10. RESTAURANT // * 11. USER_TYPE // * 12. USER_PERMISSION // * 13. SHIFT elements.setTaxes(TaxDAO.getInstance().findAll(session)); elements.setMenuCategories(MenuCategoryDAO.getInstance().findAll(session)); elements.setMenuGroups(MenuGroupDAO.getInstance().findAll(session)); elements.setMenuModifiers(MenuModifierDAO.getInstance().findAll(session)); elements.setMenuModifierGroups(MenuModifierGroupDAO.getInstance().findAll(session)); elements.setMenuItems(MenuItemDAO.getInstance().findAll(session)); elements.setMenuItemModifierGroups(MenuItemModifierGroupDAO.getInstance().findAll(session)); // elements.setUsers(UserDAO.getInstance().findAll(session)); // // elements.setMenuItemShifts(MenuItemShiftDAO.getInstance().findAll(session)); // elements.setRestaurants(RestaurantDAO.getInstance().findAll(session)); // elements.setUserTypes(UserTypeDAO.getInstance().findAll(session)); // elements.setUserPermissions(UserPermissionDAO.getInstance().findAll(session)); // elements.setShifts(ShiftDAO.getInstance().findAll(session)); m.marshal(elements, writer); transaction.commit(); fileWriter = new FileWriter(file); fileWriter.write(writer.toString()); fileWriter.close(); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), Messages.getString("DataExportAction.4")); //$NON-NLS-1$ } catch (Exception e1) { transaction.rollback(); PosLog.error(getClass(), e1); POSMessageDialog.showMessage(com.floreantpos.util.POSUtil.getFocusedWindow(), e1.getMessage()); } finally { IOUtils.closeQuietly(fileWriter); dao.closeSession(session); } }
From source file:net.sf.maltcms.chromaui.ui.paintScales.PaintScaleDialogAction.java
/** * * @return/*from ww w . j a va2 s.c o m*/ */ public PaintScale showPaintScaleDialog() { if (this.psp == null) { this.psp = new PaintScalePanel(this.ps, this.alpha, this.beta); } int val = JOptionPane.showConfirmDialog(this.parent, psp, "Select Color Scale", JOptionPane.OK_CANCEL_OPTION); if (val == JOptionPane.OK_OPTION) { this.ps = psp.getPaintScale(); } if (this.ps == null) { this.ps = psp.getDefaultPaintScale(); } return this.ps; }
From source file:Listeners.MyActionListener.java
@Override public void actionPerformed(ActionEvent e) { switch (button.getName()) { case "abrir": getIListasRequest();/*ww w .j av a 2 s . com*/ break; case "eliminar": int n = JOptionPane.showConfirmDialog(vista, "Eliminar " + lista.getItems().get(list.getSelectedIndex()).getDescripcion() + "?", "Eliminar", JOptionPane.YES_NO_OPTION); if (n == 0) { lista.getItems_deleted().add(lista.getItems().get(list.getSelectedIndex())); lista.getItems().remove(list.getSelectedIndex()); } System.out.println("n" + n); list.setListData(lista.getItems().toArray()); break; case "anadir": addAction(); break; case "delete": break; case "editar": editAction(); break; case "sync": System.out.println("pulsado sync"); break; case "guardar": saveAction(); break; case "nuevo": lista.setCod(0); vista.getNomLista().setText("Lista sin nombre"); lista.getItems().clear(); lista.getItems_deleted().clear(); list.setListData(lista.getItems().toArray()); break; case "aceptarAdd": if (!validateAddAction(add.getNombre())) JOptionPane.showMessageDialog(add, "Debes insertar el nombre del producto", "Ops!", JOptionPane.WARNING_MESSAGE); else { System.out.println(add.getNombre().getText() + " " + add.getCantidad().getSelectedItem()); lista.addItem(new Item(add.getNombre().getText(), Integer.parseInt((String) add.getCantidad().getSelectedItem()), 0)); list.setListData(lista.getItems().toArray()); add.dispose(); } break; case "aceptarEdit": if (!validateEditAction(edit.getNombre())) JOptionPane.showMessageDialog(add, "Debes insertar el nombre del producto", "Ops!", JOptionPane.WARNING_MESSAGE); else { int new_check; if (edit.getCheck().isSelected()) new_check = 1; else new_check = 0; if (old_cant != Integer.parseInt((String) edit.getCantidad().getSelectedItem()) || old_check != new_check || old_name != edit.getNombre().getText()) { lista.getItems().get(index).setCambiado(true); lista.getItems().get(index).setCheck_item(new_check); lista.getItems().get(index) .setCantidad(Integer.parseInt((String) edit.getCantidad().getSelectedItem())); lista.getItems().get(index).setDescripcion(edit.getNombre().getText()); list.setListData(lista.getItems().toArray()); lista.setModificada(true); } edit.dispose(); } break; case "aceptarOpen": int cod = open.getListas().getSelectedIndex(); getItemsListaRequest(openLists.get(cod).getCod(), openLists.get(cod).getDescripcion()); break; } }
From source file:br.org.acessobrasil.silvinha.util.versoes.AtualizadorDeVersoes.java
public boolean confirmarAtualizacao() { String msg = TradAtualizadorDeVersoes.HA_NOVA_VERSAO + TradAtualizadorDeVersoes.ASES_NOME + TradAtualizadorDeVersoes.DESEJA_ATUALIZAR; if (JOptionPane.showConfirmDialog(null, msg, TradAtualizadorDeVersoes.ATUALIZACAO_PROGRAMA, JOptionPane.YES_NO_OPTION) == 0) { return baixarVersao(); } else {//from w ww . ja v a 2 s.co m return false; } }
From source file:SwingThreadingWait.java
public void actionPerformed(ActionEvent e) { start = System.currentTimeMillis(); new Thread(new Runnable() { public void run() { while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { }/*from ww w . j a v a 2s . c o m*/ final int elapsed = (int) ((System.currentTimeMillis() - start) / 1000); SwingUtilities.invokeLater(new Runnable() { public void run() { counter.setText("Time elapsed: " + elapsed + "s"); } }); if (elapsed == 4) { try { final int[] answer = new int[1]; SwingUtilities.invokeAndWait(new Runnable() { public void run() { answer[0] = JOptionPane.showConfirmDialog(SwingThreadingWait.this, "Abort long operation?", "Abort?", JOptionPane.YES_NO_OPTION); } }); if (answer[0] == JOptionPane.YES_OPTION) { return; } } catch (InterruptedException e1) { } catch (InvocationTargetException e1) { } } } } }).start(); }
From source file:com.aw.swing.mvp.ui.msg.MessageDisplayerImpl.java
public static boolean showConfirmMessage(Component parentContainer, String messageConfirm) { ProcessMsgBlocker.instance().removeMessage(); int result = JOptionPane.showConfirmDialog(parentContainer, messageConfirm, GENERIC_MESSAGE_TITLE, JOptionPane.YES_NO_OPTION); return (result == JOptionPane.YES_OPTION); }