List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION
int OK_CANCEL_OPTION
To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:css.variable.converter.CSSVariableConverter.java
/** * Ask which file is the main file(so we can get variables) * * @return The Main File that has the ":root" identifier for variables. * @throws HeadlessException/* ww w . j av a 2s . c o m*/ */ private static File getMainCSSFile() throws HeadlessException { // Convert CSS Filenames into a string array String[] cssStrNames = new String[theCSSList.size()]; for (int i = 0; i < theCSSList.size(); i++) { cssStrNames[i] = theCSSList.get(i).getName(); } // Create JComboBox and prompt to choose main file RootFilePanel getCSSRoot = new RootFilePanel(cssStrNames); JOptionPane.showConfirmDialog(null, getCSSRoot, "Select your CSS File with root variables", JOptionPane.OK_CANCEL_OPTION); int index = getCSSRoot.getSelectedIndex(); if (index == -1) { return null; } return theCSSList.get(index); }
From source file:mysynopsis.FTPUploader.java
public static void display() throws IOException { JTextField address = new JTextField(server); JTextField username = new JTextField(user); JPasswordField password = new JPasswordField(pass); JTextField directory = new JTextField(dir); JPanel panel = new JPanel(new GridLayout(10, 1)); panel.add(new JLabel("Server Address:")); panel.add(address);/* w ww. java2 s . c om*/ panel.add(new JLabel("Username:")); panel.add(username); panel.add(new JLabel("Password:")); panel.add(password); panel.add(new JLabel("Upload Directory:")); panel.add(directory); int result; /*JOptionPane pane = new JOptionPane(panel,JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); JDialog dialog = pane.createDialog(MotherFrame.mframe, "FTP Upload Wizard - My Synopsis"); dialog.setSize(new Dimension(300,300)); dialog.setVisible(true);*/ result = JOptionPane.showConfirmDialog(MotherFrame.mframe, panel, "FTP Upload Wizard", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { server = address.getText(); user = username.getText(); pass = new String(password.getPassword()); // System.out.println(pass); dir = directory.getText(); JOptionPane.showMessageDialog(MotherFrame.mframe, "Press OK to start FTP Upload"); HTMLWriter.writeHTML(); JOptionPane.showMessageDialog(MotherFrame.mframe, uploadWizard()); } else { // System.out.println("Cancelled"); } }
From source file:net.minder.KnoxWebHdfsJavaClientExamplesTest.java
@BeforeClass public static void setupSuite() { Console console = System.console(); if (console != null) { console.printf("Knox Host: "); KNOX_HOST = console.readLine();/*from w w w. ja va 2 s.c o m*/ console.printf("Topology : "); TOPOLOGY_PATH = console.readLine(); console.printf("Username : "); TEST_USERNAME = console.readLine(); console.printf("Password: "); TEST_PASSWORD = new String(console.readPassword()); } else { JLabel label = new JLabel("Enter Knox host, topology, username, password:"); JTextField host = new JTextField(KNOX_HOST); JTextField topology = new JTextField(TOPOLOGY_PATH); JTextField username = new JTextField(TEST_USERNAME); JPasswordField password = new JPasswordField(TEST_PASSWORD); int choice = JOptionPane.showConfirmDialog(null, new Object[] { label, host, topology, username, password }, "Credentials", JOptionPane.OK_CANCEL_OPTION); assertThat(choice, is(JOptionPane.YES_OPTION)); TEST_USERNAME = username.getText(); TEST_PASSWORD = new String(password.getPassword()); KNOX_HOST = host.getText(); TOPOLOGY_PATH = topology.getText(); } TOPOLOGY_URL = String.format("%s://%s:%d/%s/%s", KNOX_SCHEME, KNOX_HOST, KNOX_PORT, KNOX_PATH, TOPOLOGY_PATH); WEBHDFS_URL = String.format("%s/%s", TOPOLOGY_URL, WEBHDFS_PATH); }
From source file:com.gs.obevo.util.inputreader.DialogInputReader.java
@Override public String readPassword(String promptMessage) { final JPasswordField jpf = new JPasswordField(); JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = jop.createDialog(promptMessage); dialog.addComponentListener(new ComponentAdapter() { @Override/* w w w. j av a 2 s .c o m*/ public void componentShown(ComponentEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jpf.requestFocusInWindow(); } }); } }); dialog.setVisible(true); int result = (Integer) jop.getValue(); dialog.dispose(); String password = null; if (result == JOptionPane.OK_OPTION) { password = new String(jpf.getPassword()); } if (StringUtils.isEmpty(password)) { return null; } else { return password; } }
From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java
private char[] getPin() { Box mainPanel = Box.createVerticalBox(); Box passwordPanel = Box.createHorizontalBox(); JLabel promptLabel = new JLabel("eID PIN:"); passwordPanel.add(promptLabel);//from w ww .ja v a 2 s.c o m passwordPanel.add(Box.createHorizontalStrut(5)); JPasswordField passwordField = new JPasswordField(8); passwordPanel.add(passwordField); mainPanel.add(passwordPanel); Component parentComponent = null; int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { char[] pin = passwordField.getPassword(); return pin; } throw new RuntimeException("operation canceled."); }
From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsdChooser = new JFileChooser(); xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsdChooser.getSelectedFile(); if (isXSD(file)) { XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName()); int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) { errorMessage();//from w w w.j a v a 2 s.com } else { if (saveXsd(file, xsdInfoQueryComponent.getName(), false, xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) { JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName()); newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { errorMessage(); } } } } else { errorMessage(); } } }
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 2s . co 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:hr.fer.zemris.vhdllab.platform.gui.dialog.AbstractOptionPaneDialogManager.java
private Object[] getOptionsForType(int optionType) { switch (optionType) { case JOptionPane.DEFAULT_OPTION: return getOption("ok"); case JOptionPane.YES_NO_CANCEL_OPTION: return getOption("yes", "no", "cancel"); case JOptionPane.YES_NO_OPTION: return getOption("yes", "no"); case JOptionPane.OK_CANCEL_OPTION: return getOption("ok", "cancel"); default://from w w w . j av a2s . c o m throw new IllegalStateException("Unknown option: " + optionType); } }
From source file:com.bright.json.JSonRequestor.java
public static void main(String[] args) { String fileBasename = null;// ww w. j av a 2 s. c om 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:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by PublicKey HashMap input. Create a dialog popup with a combobox to choose the correct JWK to use. * //from w ww .jav a2s .c o m * @param publicKeys * HashMap containing a PublicKey and related describing string * @throws AttackPreparationFailedException * @return Selected {@link PublicKey} */ @SuppressWarnings("unchecked") public static PublicKey getRsaPublicKeyByJwkSelectionPanel(HashMap<String, PublicKey> publicKeys) throws AttackPreparationFailedException { // TODO: Move to other class? JPanel selectionPanel = new JPanel(); selectionPanel.setLayout(new java.awt.GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridy = 0; selectionPanel.add(new JLabel("Multiple JWKs found. Please choose one:"), constraints); JComboBox jwkSetKeySelection = new JComboBox<>(); DefaultComboBoxModel<String> jwkSetKeySelectionModel = new DefaultComboBoxModel<>(); for (Map.Entry<String, PublicKey> publicKey : publicKeys.entrySet()) { jwkSetKeySelectionModel.addElement(publicKey.getKey()); } jwkSetKeySelection.setModel(jwkSetKeySelectionModel); constraints.gridy = 1; selectionPanel.add(jwkSetKeySelection, constraints); int resultButton = JOptionPane.showConfirmDialog(null, selectionPanel, "Select JWK", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (resultButton == JOptionPane.CANCEL_OPTION) { throw new AttackPreparationFailedException("No JWK from JWK Set selected!"); } loggerInstance.log(Converter.class, "Key selected: " + jwkSetKeySelection.getSelectedIndex(), Logger.LogLevel.DEBUG); return publicKeys.get(jwkSetKeySelection.getSelectedItem()); }