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:modmanager.MainWindow.java
private void selectSkyrimDirectory(boolean force) { skyrimDirectoryChooser.setDialogTitle("Select Skyrim folder"); skyrimDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); boolean chosen = false; while (skyrimDirectoryChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { /**/*from w w w. jav a2 s. c o m*/ * Use a while loop to check for valid skyrim installation ... */ if (!FileUtils.getFile(skyrimDirectoryChooser.getSelectedFile(), "TESV.exe").exists()) { int result = JOptionPane.showConfirmDialog(this, "It seems that this directory does not contain Skyrim!\nContinue anyways?", "Invalid Skyrim directory", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.CANCEL_OPTION) { break; } if (result == JOptionPane.YES_OPTION) { chosen = true; break; } } else { chosen = true; break; } } if (force && !chosen) { System.exit(0); } modifications.setSkyrimDirectory(skyrimDirectoryChooser.getSelectedFile()); }
From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;//from w w w . j av a 2 s. c o m final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }
From source file:net.sf.jabref.external.MoveFileAction.java
@Override public void actionPerformed(ActionEvent event) { int selected = editor.getSelectedRow(); if (selected == -1) { return;/*from w w w . j a v a 2 s . co m*/ } FileListEntry entry = editor.getTableModel().getEntry(selected); // Check if the current file exists: String ln = entry.link; boolean httpLink = ln.toLowerCase(Locale.ENGLISH).startsWith("http"); if (httpLink) { // TODO: notify that this operation cannot be done on remote links return; } // Get an absolute path representation: List<String> dirs = frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory(); int found = -1; for (int i = 0; i < dirs.size(); i++) { if (new File(dirs.get(i)).exists()) { found = i; break; } } if (found < 0) { JOptionPane.showMessageDialog(frame, Localization.lang("File_directory_is_not_set_or_does_not_exist!"), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); return; } File file = new File(ln); if (!file.isAbsolute()) { file = FileUtil.expandFilename(ln, dirs).orElse(null); } if ((file != null) && file.exists()) { // Ok, we found the file. Now get a new name: String extension = null; if (entry.type.isPresent()) { extension = "." + entry.type.get().getExtension(); } File newFile = null; boolean repeat = true; while (repeat) { repeat = false; String chosenFile; if (toFileDir) { // Determine which name to suggest: String suggName = FileUtil .createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(), Globals.journalAbbreviationLoader, Globals.prefs) .concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : ""); CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"), Localization.lang("Rename to '%0'", suggName), Globals.prefs.getBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR)); int answer; // Only ask about renaming file if the file doesn't have the proper name already: if (suggName.equals(file.getName())) { answer = JOptionPane.showConfirmDialog(frame, Localization.lang("Move file to file directory?"), MOVE_RENAME, JOptionPane.YES_NO_OPTION); } else { answer = JOptionPane.showConfirmDialog(frame, cbm, MOVE_RENAME, JOptionPane.YES_NO_OPTION); } if (answer != JOptionPane.YES_OPTION) { return; } Globals.prefs.putBoolean(JabRefPreferences.RENAME_ON_MOVE_FILE_TO_FILE_DIR, cbm.isSelected()); StringBuilder sb = new StringBuilder(dirs.get(found)); if (!dirs.get(found).endsWith(File.separator)) { sb.append(File.separator); } if (cbm.isSelected()) { // Rename: sb.append(suggName); } else { // Do not rename: sb.append(file.getName()); } chosenFile = sb.toString(); } else { chosenFile = FileDialogs.getNewFile(frame, file, Collections.singletonList(extension), JFileChooser.SAVE_DIALOG, false); } if (chosenFile == null) { return; // canceled } newFile = new File(chosenFile); // Check if the file already exists: if (newFile.exists() && (JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", newFile.getName()), MOVE_RENAME, JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)) { if (toFileDir) { return; } else { repeat = true; } } } if (!newFile.equals(file)) { try { boolean success = file.renameTo(newFile); if (!success) { success = FileUtil.copyFile(file, newFile, true); } if (success) { // Remove the original file: if (!file.delete()) { LOGGER.info("Cannot delete original file"); } // Relativise path, if possible. String canPath = new File(dirs.get(found)).getCanonicalPath(); if (newFile.getCanonicalPath().startsWith(canPath)) { if ((newFile.getCanonicalPath().length() > canPath.length()) && (newFile .getCanonicalPath().charAt(canPath.length()) == File.separatorChar)) { String newLink = newFile.getCanonicalPath().substring(1 + canPath.length()); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } else { String newLink = newFile.getCanonicalPath().substring(canPath.length()); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } } else { String newLink = newFile.getCanonicalPath(); editor.getTableModel().setEntry(selected, new FileListEntry(entry.description, newLink, entry.type)); } eEditor.updateField(editor); //JOptionPane.showMessageDialog(frame, Globals.lang("File moved"), // Globals.lang("Move/Rename file"), JOptionPane.INFORMATION_MESSAGE); frame.output(Localization.lang("File moved")); } else { JOptionPane.showMessageDialog(frame, Localization.lang("Move file failed"), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); } } catch (SecurityException | IOException ex) { LOGGER.warn("Could not move file", ex); JOptionPane.showMessageDialog(frame, Localization.lang("Could not move file '%0'.", file.getAbsolutePath()) + ex.getMessage(), MOVE_RENAME, JOptionPane.ERROR_MESSAGE); } } } else { // File doesn't exist, so we can't move it. JOptionPane.showMessageDialog(frame, Localization.lang("Could not find file '%0'.", entry.link), Localization.lang("File not found"), JOptionPane.ERROR_MESSAGE); } }
From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java
public void run() { log.debug("run() start"); boolean loop = true; int queueSize = IdentifyQueue.getInstance().size(); log.info("Trying to Sending item to Protex Server - Identify Queue Size: " + queueSize); long startTime = System.currentTimeMillis(); while (loop) { // block BackgroundJobManager.getInstance().requestStopIdentifyThread(); long endTime = System.currentTimeMillis(); long timeDuration = endTime - startTime; if (timeDuration % 100 == 0) System.out.println("delayTime : " + timeDuration); if (timeDuration >= TIME_LIMIT) { log.error("TIME_LIMIT_EXCEED during completing sending items to Protex server "); loop = false;//w w w . j a va 2 s . c o m aDialogDiaplayerThread.closeDialog(); String exitMessage = "OSI fails to sync with Protex Server.\n" + "Please contact to OSI Development Team to resolve this problem."; String[] button = { "OK" }; JOptionPane.showOptionDialog( // block null, exitMessage, "Exit", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, button, "OK"); continue; } else { boolean isAllidentifyThreadStopped = BackgroundJobManager.getInstance() .isAllIdentifyThreadReadyStatus(); if (isAllidentifyThreadStopped) { queueSize = IdentifyQueue.getInstance().size(); log.info("OSI succeeds to sync with Protex Server. - Identify Queue Size: " + queueSize + " / " + timeDuration + " ms."); loop = false; aDialogDiaplayerThread.closeDialog(); } } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } log.debug("run() end"); }
From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java
private void checkCaCerts(final KseFrame kseFrame) { File caCertificatesFile = applicationSettings.getCaCertificatesFile(); if (caCertificatesFile.exists()) { return;//from w w w . j a v a 2 s . c o m } // cacerts file is not where we expected it => detect location and inform user final File newCaCertsFile = new File(AuthorityCertificates.getDefaultCaCertificatesLocation().toString()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int selected = JOptionPane.showConfirmDialog(kseFrame.getUnderlyingFrame(), MessageFormat .format(res.getString("CreateApplicationGui.CaCertsFileNotFound.message"), newCaCertsFile), KSE.getApplicationName(), JOptionPane.YES_NO_OPTION); if (selected == JOptionPane.YES_OPTION) { applicationSettings.setCaCertificatesFile(newCaCertsFile); } } }); }
From source file:calendarexportplugin.exporter.GoogleExporter.java
public boolean exportPrograms(Program[] programs, CalendarExportSettings settings, AbstractPluginProgramFormating formatting) { try {/*w w w. j a va2 s . co m*/ boolean uploadedItems = false; mPassword = IOUtilities.xorDecode(settings.getExporterProperty(PASSWORD), 345903).trim(); if (!settings.getExporterProperty(STORE_PASSWORD, false)) { if (!showLoginDialog(settings)) { return false; } } if (!settings.getExporterProperty(STORE_SETTINGS, false)) { if (!showCalendarSettings(settings)) { return false; } } GoogleService myService = new GoogleService("cl", "tvbrowser-tvbrowsercalenderplugin-" + CalendarExportPlugin.getInstance().getInfo().getVersion().toString()); myService.setUserCredentials(settings.getExporterProperty(USERNAME).trim(), mPassword); URL postUrl = new URL("http://www.google.com/calendar/feeds/" + settings.getExporterProperty(SELECTED_CALENDAR) + "/private/full"); SimpleDateFormat formatDay = new SimpleDateFormat("yyyy-MM-dd"); formatDay.setTimeZone(TimeZone.getTimeZone("GMT")); SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); formatTime.setTimeZone(TimeZone.getTimeZone("GMT")); ParamParser parser = new ParamParser(); for (Program program : programs) { final String title = parser.analyse(formatting.getTitleValue(), program); // First step: search for event in calendar boolean createEvent = true; CalendarEventEntry entry = findEntryForProgram(myService, postUrl, title, program); if (entry != null) { int ret = JOptionPane.showConfirmDialog(null, mLocalizer.msg("alreadyAvailable", "already available", program.getTitle()), mLocalizer.msg("title", "Add event?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ret != JOptionPane.YES_OPTION) { createEvent = false; } } // add event to calendar if (createEvent) { EventEntry myEntry = new EventEntry(); myEntry.setTitle(new PlainTextConstruct(title)); String desc = parser.analyse(formatting.getContentValue(), program); myEntry.setContent(new PlainTextConstruct(desc)); Calendar c = CalendarToolbox.getStartAsCalendar(program); DateTime startTime = new DateTime(c.getTime(), c.getTimeZone()); c = CalendarToolbox.getEndAsCalendar(program); DateTime endTime = new DateTime(c.getTime(), c.getTimeZone()); When eventTimes = new When(); eventTimes.setStartTime(startTime); eventTimes.setEndTime(endTime); myEntry.addTime(eventTimes); if (settings.getExporterProperty(REMINDER, false)) { int reminderMinutes = 0; try { reminderMinutes = settings.getExporterProperty(REMINDER_MINUTES, 0); } catch (NumberFormatException e) { e.printStackTrace(); } if (settings.getExporterProperty(REMINDER_ALERT, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.ALERT); } if (settings.getExporterProperty(REMINDER_EMAIL, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.EMAIL); } if (settings.getExporterProperty(REMINDER_SMS, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.SMS); } } if (settings.isShowBusy()) { myEntry.setTransparency(BaseEventEntry.Transparency.OPAQUE); } else { myEntry.setTransparency(BaseEventEntry.Transparency.TRANSPARENT); } // Send the request and receive the response: myService.insert(postUrl, myEntry); uploadedItems = true; } } if (uploadedItems) { JOptionPane.showMessageDialog(CalendarExportPlugin.getInstance().getBestParentFrame(), mLocalizer.msg("exportDone", "Google Export done."), mLocalizer.msg("export", "Export"), JOptionPane.INFORMATION_MESSAGE); } return true; } catch (AuthenticationException e) { ErrorHandler.handle(mLocalizer.msg("loginFailure", "Problems during login to Service.\nMaybe bad username or password?"), e); settings.setExporterProperty(STORE_PASSWORD, false); } catch (Exception e) { ErrorHandler.handle(mLocalizer.msg("commError", "Error while communicating with Google!"), e); } return false; }
From source file:InternalFrameTest.java
/** * Creates an internal frame on the desktop. * @param c the component to display in the internal frame * @param t the title of the internal frame. *///from w w w . j a va 2 s . c o m public void createInternalFrame(Component c, String t) { final JInternalFrame iframe = new JInternalFrame(t, true, // resizable true, // closable true, // maximizable true); // iconifiable iframe.add(c, BorderLayout.CENTER); desktop.add(iframe); iframe.setFrameIcon(new ImageIcon("document.gif")); // add listener to confirm frame closing iframe.addVetoableChangeListener(new VetoableChangeListener() { public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException { String name = event.getPropertyName(); Object value = event.getNewValue(); // we only want to check attempts to close a frame if (name.equals("closed") && value.equals(true)) { // ask user if it is ok to close int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option", JOptionPane.YES_NO_OPTION); // if the user doesn't agree, veto the close if (result != JOptionPane.YES_OPTION) throw new PropertyVetoException("User canceled close", event); } } }); // position frame int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; iframe.reshape(nextFrameX, nextFrameY, width, height); iframe.show(); // select the frame--might be vetoed try { iframe.setSelected(true); } catch (PropertyVetoException e) { } frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight(); // compute placement for next frame nextFrameX += frameDistance; nextFrameY += frameDistance; if (nextFrameX + width > desktop.getWidth()) nextFrameX = 0; if (nextFrameY + height > desktop.getHeight()) nextFrameY = 0; }
From source file:com.sec.ose.osi.sdk.protexsdk.project.ProjectAPIWrapper.java
private static String createProject(String newProjectName, AnalysisSourceLocation newAnalysisSourceLocation, UIResponseObserver observer) {//from w w w. j a va 2 s . c o m if (observer == null) { observer = new DefaultUIResponseObserver(); } if (isExistedProjectName(newProjectName) == true) { observer.setFailMessage("\"" + newProjectName + "\" is already existed."); log.debug("\"" + newProjectName + "\" is already existed."); return null; } String projectID = null; ProjectRequest pRequest = new ProjectRequest(); PolicyCheckResult p = ProjectNamePolicy.checkProjectName(newProjectName); if (p.getResult() != PolicyCheckResult.PROJECT_NAME_OK) { observer.setFailMessage(p.getResultMsg()); return null; } final String DESCRIPTION = "This project is created by OSI - " + DateUtil.getCurrentTime("[%1$tY/%1$tm/%1$te(%1$ta) %1$tl:%1$tM:%1$tS %1$tp]"); pRequest.setName(newProjectName); pRequest.setDescription(DESCRIPTION); if (newAnalysisSourceLocation != null) { pRequest.setAnalysisSourceLocation(newAnalysisSourceLocation); } try { projectID = ProtexSDKAPIManager.getProjectAPI().createProject(pRequest, LicenseCategory.PROPRIETARY); } catch (SdkFault e) { log.warn(e); ErrorCode errorCode = e.getFaultInfo().getErrorCode(); try { Thread.sleep(1000); } catch (InterruptedException ie) { ie.printStackTrace(); } if (errorCode == ErrorCode.DUPLICATE_PROJECT_NAME) { String[] button = { "OK" }; JOptionPane.showOptionDialog( // block null, "The project name \"" + newProjectName + "\" is already created by other user.", "Duplicated project name", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, button, "OK"); } return null; } if (projectID == null) return null; setScanIgnorePattern(projectID, ProjectNamePolicy.IGNORED_PATTERN, observer); observer.pushMessage("[ok]\n"); return projectID; }
From source file:com.sshtools.shift.FileTransferDialog.java
/** * Creates a new FileTransferDialog object. * * @param frame/* ww w.j a va 2 s.co m*/ * @param title * @param fileCount */ /*public FileTransferDialog(Frame frame, String title) { this(frame, title, op.getNewFiles().size() + op.getUpdatedFiles().size()); this.op = op; }*/ public FileTransferDialog(Frame frame, String title, int fileCount) { super("0% Complete - " + title); this.setIconImage(ShiftSessionPanel.FILE_BROWSER_ICON.getImage()); this.title = title; try { jbInit(); pack(); } catch (Exception ex) { ex.printStackTrace(); } this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (cancelled || completed) { setVisible(false); } else { if (JOptionPane.showConfirmDialog(FileTransferDialog.this, "Cancel the file operation(s)?", "Close Window", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) { cancelOperation(); hide(); } } } }); }
From source file:com.net2plan.gui.GUINet2Plan.java
private static void askForClose() { int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit Net2Plan?", "Exit from Net2Plan", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) System.exit(0);// w w w . ja va 2 s . c o m }