List of usage examples for javax.swing JOptionPane showInputDialog
@SuppressWarnings("deprecation") public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException
From source file:levelBuilder.DialogMaker.java
/** * Popup for selecting file to load./*from w w w.ja va2 s .c o m*/ */ private static void loadFilePopup() { File savesFolder = new File(saveDir); File[] saves = savesFolder.listFiles(fileFilter); if (savesFolder.exists()) { if (saves.length > 0) { String[] saveNames = savesFolder.list(fileFilter); saveName = (String) JOptionPane.showInputDialog(null, "Which file would you like to load?", "Choose!", JOptionPane.PLAIN_MESSAGE, null, saveNames, saveNames[0]); if (saveName == null) { splashWindow(); } else { loadGraph(false); } } else { JOptionPane.showMessageDialog(null, "No existing save files", null, JOptionPane.PLAIN_MESSAGE); splashWindow(); } } else { savesFolder.mkdir(); JOptionPane.showMessageDialog(null, "No existing save files", null, JOptionPane.PLAIN_MESSAGE); splashWindow(); } }
From source file:serial.ChartFromSerial.java
private void pause_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pause_jBtnActionPerformed if ("Play".equals(pause_jBtn.getText())) { while (!chosenPort.openPort()) { if (JOptionPane.showConfirmDialog(rootPane, "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?", "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) { buttonsOff();/*from w w w . j a v a 2 s. co m*/ return; } else { portNames = SerialPort.getCommPorts(); if (portNames.length > 0) { if (portNames.length >= 1) { Object[] possibilities = new Object[portNames.length]; for (int i = 0; i < portNames.length; i++) { possibilities[i] = portNames[i].getSystemPortName(); } String s = (String) JOptionPane.showInputDialog(rootPane, "Other ports are available.\nSelect one to continue on that port or cancel to disconnect.", "Another port is available", JOptionPane.PLAIN_MESSAGE, null, possibilities, null); chosenPort.closePort(); if (s != null) { chosenPort = SerialPort.getCommPort(s); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); chosenPort.setBaudRate( Integer.parseInt(baudRate_jCombo.getSelectedItem().toString())); softRefresh(); portList_jCombo.setSelectedItem(s); if (chosenPort.openPort()) { createSerialThread(chosenPort); pause_jBtn.setText("Pause"); connect_jBtn.setEnabled(true); return; } } else { buttonsOff(); return; } } else { if (JOptionPane.showConfirmDialog(rootPane, portNames[0].getSystemPortName() + " is available. Would you like to use it instead?", "Another port is available", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { chosenPort.closePort(); chosenPort = SerialPort.getCommPort(portNames[0].getSystemPortName()); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); chosenPort.setBaudRate( Integer.parseInt(baudRate_jCombo.getSelectedItem().toString())); softRefresh(); portList_jCombo.setSelectedItem(portNames[0].getSystemPortName()); if (chosenPort.openPort()) { createSerialThread(chosenPort); pause_jBtn.setText("Pause"); connect_jBtn.setEnabled(true); return; } } else { buttonsOff(); return; } } } else { JOptionPane.showMessageDialog(rootPane, "You are currently not connected to any devices.", "No devices found", JOptionPane.INFORMATION_MESSAGE); softRefresh(); buttonsOff(); return; } } } createSerialThread(chosenPort); pause_jBtn.setText("Pause"); } else { chosenPort.closePort(); pause_jBtn.setText("Play"); } }
From source file:com.ejie.uda.jsonI18nEditor.Editor.java
public void showAddTranslationDialog() { String key = ""; String newKey = ""; TranslationTreeNode node = translationTree.getSelectedNode(); if (node != null && !node.isRoot()) { key = node.getKey();/*from w w w . jav a 2s . c o m*/ } while (newKey != null && newKey.isEmpty()) { newKey = (String) JOptionPane.showInputDialog(this, MessageBundle.get("dialogs.translation.add.text"), MessageBundle.get("dialogs.translation.add.title"), JOptionPane.QUESTION_MESSAGE, null, null, key); if (newKey != null) { newKey = newKey.trim(); if (!TranslationKeys.isValid(newKey)) { showError(MessageBundle.get("dialogs.translation.add.error")); } else { addTranslationKey(newKey); } } } }
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
private void ChangeIpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChangeIpActionPerformed // TODO add your handling code here: Object s = ""; do {//ww w . j a va2s . c o m s = JOptionPane.showInputDialog(this, "Geef Ip van MacFinish op", "ip", JOptionPane.PLAIN_MESSAGE, null, null, clockServer.getIp()); } while (!InetAddressUtils.isIPv4Address((String) s)); clockServer.changeIp((String) s); }
From source file:gui.QTLResultsPanel.java
void runPerm() { Object[] values = { "Full Model", "Reduced Model" }; Object selected = JOptionPane.showInputDialog(MsgBox.frm, "Please select which model to use:", "Select Model", JOptionPane.QUESTION_MESSAGE, null, values, values[0]); if (selected == null) return;/* www . j a v a2 s .c o m*/ // Full model or reduced? boolean fullModel = selected == values[0]; int cmLength = (int) order.getDistanceTotal(); String tName = currentTrait.getName(); PermDialog dialog = new PermDialog(MsgBox.frm, qtlResult.getTraitFile(), fullModel, tName, cmLength); if (dialog.isOK()) { PermResult result = dialog.getResult(); currentTrait.setPermResult(result); displayTrait(currentTrait); AppFrameMenuBar.aFileSave.setEnabled(true); } }
From source file:lu.fisch.moenagade.model.Project.java
public boolean renameSound(SoundFile soundFile) { String name = getFilename(soundFile); String ext = getExtension(soundFile); boolean result; do {//from www. jav a 2 s.co m result = true; name = (String) JOptionPane.showInputDialog(frame, "Please enter the sound's new name.", "Rename sound", JOptionPane.PLAIN_MESSAGE, null, null, name); if (name == null) return false; // check if name is OK Matcher matcher = Pattern.compile("^[a-zA-Z_$][a-zA-Z_$0-9]*$").matcher(name); boolean found = matcher.find(); if (!found) { result = false; JOptionPane.showMessageDialog(frame, "Please chose a valid name.", "Error", JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR); } // check if name is unique else if ((new File(directoryName + System.getProperty("file.separator") + "bloxs" + System.getProperty("file.separator") + "sounds" + System.getProperty("file.separator") + name + "." + ext)).exists()) { result = false; JOptionPane.showMessageDialog(frame, "There exists already a sound with this name!", "Error", JOptionPane.ERROR_MESSAGE, Moenagade.IMG_ERROR); } else { // send refresh refresh(new Change(null, -1, "rename.sound", soundFile.toString(), name + "." + ext)); // do the rename File fFrom = new File(directoryName + System.getProperty("file.separator") + "bloxs" + System.getProperty("file.separator") + "sounds" + System.getProperty("file.separator") + soundFile.toString()); File fTo = new File(directoryName + System.getProperty("file.separator") + "bloxs" + System.getProperty("file.separator") + "sounds" + System.getProperty("file.separator") + name + "." + ext); if (fFrom.exists()) fFrom.renameTo(fTo); return true; } } while (!result); return false; }
From source file:levelBuilder.DialogMaker.java
/** * Saves graph to file.//from ww w.j a v a 2s . com */ private static void saveGraph() { //Checks for errors ArrayList<String> errorList = new ArrayList<String>(); errorList = dg.check(); if (errorList.isEmpty()) { //Save popup. String filePath = null; File savesFolder = new File(saveDir); if (!savesFolder.exists()) savesFolder.mkdir(); String[] saveNames = new String[savesFolder.list(fileFilter).length + 1]; for (int i = 0; i < saveNames.length - 1; i++) { saveNames[i] = savesFolder.list(fileFilter)[i]; } saveNames[saveNames.length - 1] = "New File"; if (saveNames.length > 0) { saveName = (String) JOptionPane.showInputDialog(null, "Choose file to overwrite, or a new file", "Choose!", JOptionPane.PLAIN_MESSAGE, null, saveNames, saveName); if (saveName == "New File") { filePath = JOptionPane.showInputDialog(null, "New file name", "Write!", JOptionPane.PLAIN_MESSAGE); filePath = saveDir + filePath + ".xml"; } else if (saveName == null) { return; } else { filePath = saveDir + saveName; } // //Saves position of each node. // for (DialogNode n : nodeMap.values()) { // n.setX(((AbstractLayout<DialogNode, Double>) layout).getX(n)); // n.setY(((AbstractLayout<DialogNode, Double>) layout).getY(n)); // } //Saves graph dg.save(filePath); } } //Display errors else { JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0)); for (String error : errorList) panel.add(new JLabel(error)); JOptionPane.showMessageDialog(null, panel, "Errors. Fix these to continue.", JOptionPane.PLAIN_MESSAGE); } }
From source file:fi.hoski.remote.ui.Admin.java
private JMenuItem menuItemRemoveEntity() { final String title = TextUtil.getText("REMOVE ENTITY"); JMenuItem removeEntityItem = new JMenuItem(title); ActionListener removeEntityAction = new ActionListener() { @Override/*from w ww . j a v a2 s . co m*/ public void actionPerformed(ActionEvent e) { Object kind = JOptionPane.showInputDialog(frame, title, "", JOptionPane.OK_CANCEL_OPTION, null, serverProperties.getTables(), null); if (kind != null) { String confirm = TextUtil.getText("CONFIRM REMOVE") + " " + kind; if (JOptionPane.showConfirmDialog(frame, confirm, "", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { List<String> kindList = new ArrayList<String>(); kindList.add(kind.toString()); int count = dss.remove(kindList); JOptionPane.showMessageDialog(frame, TextUtil.getText("REMOVED") + " " + count); } } } }; removeEntityAction = createActionListener(frame, removeEntityAction); removeEntityItem.addActionListener(removeEntityAction); return removeEntityItem; }
From source file:gui.QTLResultsPanel.java
private int getSelectedModel(boolean allowZero, int best) { int length = allowZero ? 11 : 10; Object[] values = new Object[length]; int m = allowZero ? 0 : 1; for (int i = 0; i < length; i++) { values[i] = getModel(m++);/*from ww w. j a va 2 s . co m*/ } Object selected = JOptionPane.showInputDialog(MsgBox.frm, "Please select which model to use:", "Select Model", JOptionPane.QUESTION_MESSAGE, null, values, values[best]); if (selected == null) return -1; for (int i = 0; i < length; i++) { if (selected == values[i]) { if (allowZero) { return i; } else { return i + 1; } } } return -1; }
From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java
private void handleFileDrop(Component component, List<File> files, DropLocationInfo dli) { Integer column = dli.column;//www. j av a2s . c om Integer row = dli.rowOrIndex; List<Plot> plots = fieldViewPanel.getFieldLayout().getItemsAt(Arrays.asList(new Point(column, row))); System.out.println("Dropped on: col,row=" + column + "," + row); List<File> filesAdded = new ArrayList<>(); for (Plot plot : plots) { System.out.println("plot: " + plot.getPlotId() + ": " + plot.getPlotColumn() + "," + plot.getPlotRow()); List<Specimen> specimens = plot.getSpecimens(); if (specimens == null || specimens.isEmpty()) { try { for (File file : files) { File storedFile = copyToMediaStoreDir(file, plot, PlotOrSpecimen.ORGANISM_NUMBER_IS_PLOT); database.addMediaFile(sampleGroupChoiceForNewMedia, trial, plot, PlotOrSpecimen.ORGANISM_NUMBER_IS_PLOT, storedFile); filesAdded.add(file); } } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(FieldViewDialog.this, e, "Database Error", JOptionPane.ERROR_MESSAGE); break; } } else { List<String> plotOrSpecimen = new ArrayList<>(); Map<String, PlotOrSpecimen> specimenByIdent = new HashMap<>(); String plotIdent = trial.getPlotIdentOption().createPlotIdentString(plot, ","); plotOrSpecimen.add(plotIdent); specimenByIdent.put(plotIdent, plot); for (Specimen s : specimens) { if (PlotOrSpecimen.isSpecimenNumberForSpecimen(s.getSpecimenNumber())) { String ident = "Individual#" + s.getSpecimenNumber(); plotOrSpecimen.add(ident); specimenByIdent.put(ident, s); } } Object[] selectionValues = plotOrSpecimen.toArray(new String[plotOrSpecimen.size()]); Object initialSelectionValue = null; Object chosen = JOptionPane.showInputDialog(FieldViewDialog.this, "Select Plot or Specimen", "Add Attachment", JOptionPane.OK_CANCEL_OPTION, null, selectionValues, initialSelectionValue); if (chosen != null) { PlotOrSpecimen choice = specimenByIdent.get(chosen); if (choice != null) { try { for (File file : files) { File storedFile = copyToMediaStoreDir(file, plot, choice.getSpecimenNumber()); database.addMediaFile(sampleGroupChoiceForNewMedia, trial, plot, choice.getSpecimenNumber(), storedFile); filesAdded.add(file); } } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(FieldViewDialog.this, e, "Database Error", JOptionPane.ERROR_MESSAGE); } } } } } if (!filesAdded.isEmpty()) { String message = filesAdded.stream().map(File::getName).collect(Collectors.joining("\n")); JOptionPane.showMessageDialog(FieldViewDialog.this, message, "Attachments Added", JOptionPane.INFORMATION_MESSAGE); } }