List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. 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 w w . ja 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:edu.ku.brc.specify.tasks.ReportsBaseTask.java
/** * @return Return true if there is a small number of labels or whether the user wishes to continue. *///from w ww . ja va 2 s . c o m protected boolean checkForALotOfLabels(final RecordSetIFace recordSet) { // if (recordSet.getNumItems() > 200) // XXX Pref { Object[] options = { getResourceString("Create_New_Report"), getResourceString("CANCEL") }; int n = JOptionPane.showOptionDialog(UIRegistry.get(UIRegistry.FRAME), String.format(getResourceString("LotsOfLabels"), new Object[] { (recordSet.getNumItems()) }), getResourceString("LotsOfLabelsTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //don't use a custom Icon options, //the titles of buttons options[0]); //default button title if (n == 1) { return false; } } return true; }
From source file:com._17od.upm.gui.DatabaseActions.java
private boolean getLatestVersionOfDatabase() throws TransportException, ProblemReadingDatabaseFile, IOException, CryptoException, PasswordDatabaseException { boolean latestVersionDownloaded = false; // Ensure we're working with the latest version of the database if (databaseHasRemoteInstance() && localDatabaseDirty) { int answer = JOptionPane.showConfirmDialog(mainWindow, Translator.translate("askSyncWithRemoteDB"), Translator.translate("syncDatabase"), JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { latestVersionDownloaded = syncWithRemoteDatabase(); }/*from ww w . j av a 2 s .c o m*/ } else { latestVersionDownloaded = true; } return latestVersionDownloaded; }
From source file:net.chaosserver.timelord.swingui.CommonTaskPanel.java
/** * Catch action events generated by the popup menu. * * @param evt the event/*ww w. ja va 2s. c o m*/ */ public void actionPerformed(ActionEvent evt) { if (log.isTraceEnabled()) { log.trace("Got ActionEvent.getActionCommand [" + evt.getActionCommand() + "]"); } if (CommonTaskPopupMenu.ACTION_ADDTASK.equals(evt.getActionCommand())) { showAddTaskDialog(); } else if (CommonTaskPopupMenu.ACTION_ADDTIME.equals(evt.getActionCommand())) { showAddTimeDialog(); } else if (CommonTaskPopupMenu.ACTION_DELTASK.equals(evt.getActionCommand())) { TaskDayPanel taskDayPanel = popupMenu.getTaskDayPanel(); if (taskDayPanel != null) { TimelordTask timelordTask = taskDayPanel.getTimelordTask(); int result = JOptionPane.showConfirmDialog(this, "Delete [" + timelordTask.getTaskName() + "] Task?", "Delete Task", JOptionPane.YES_NO_OPTION); if (result == 0) { getTimelordData().removeTask(timelordTask); } } } else if (CommonTaskPopupMenu.ACTION_RENTASK.equals(evt.getActionCommand())) { TaskDayPanel taskDayPanel = popupMenu.getTaskDayPanel(); TimelordTask timelordTask = taskDayPanel.getTimelordTask(); String newName = JOptionPane.showInputDialog(this, "Rename Task", timelordTask.getTaskName()); if (newName != null) { if (taskDayPanel != null) { timelordTask.setTaskName(newName); getTimelordData().sortTaskCollection(); } } } else if (CommonTaskPopupMenu.ACTION_EXPORT.equals(evt.getActionCommand())) { TaskDayPanel taskDayPanel = popupMenu.getTaskDayPanel(); if (taskDayPanel != null) { TimelordTask timelordTask = taskDayPanel.getTimelordTask(); timelordTask.setExportable(!timelordTask.isExportable()); } } else if (CommonTaskPopupMenu.ACTION_HIDETASK.equals(evt.getActionCommand())) { TaskDayPanel taskDayPanel = popupMenu.getTaskDayPanel(); if (taskDayPanel != null) { TimelordTask timelordTask = taskDayPanel.getTimelordTask(); if (timelordTask.isHidden()) { timelordTask.setHidden(false); } else { timelordTask.setHidden(true); } } } else if (CommonTaskPopupMenu.ACTION_EDITNOTE.equals(evt.getActionCommand())) { TaskDayPanel taskDayPanel = popupMenu.getTaskDayPanel(); if (taskDayPanel != null) { TimelordTask timelordTask = taskDayPanel.getTimelordTask(); showEditNoteDialog(timelordTask); } } else if (ACTION_SEARCHTEXT.equals(evt.getActionCommand())) { if (log.isDebugEnabled()) { log.debug("Executing search with given input:" + searchTextField.getText()); this.setTasknameFilter(searchTextField.getText()); } } }
From source file:jhplot.HPlotChart.java
/** * Exports the image to some graphic format. *//*w w w . j a v a 2s . co m*/ private void exportDialog() { final JFileChooser fc = jhplot.gui.CommonGUI.openImageFileChooser(frame); if (fc.showDialog(frame, "Export to ") == 0) { // final File scriptFile = fileChooser.getSelectedFile(); final File scriptFile = jhplot.io.images.ExportVGraphics.getSelectedFileWithExtension(fc); // System.out.println(scriptFile.getAbsolutePath()); if (scriptFile == null) return; else if (scriptFile.exists()) { int res = JOptionPane.showConfirmDialog(frame, "The file exists. Do you want to overwrite the file?", "", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) return; } String mess = "write image file .."; Thread t = new Thread(mess) { public void run() { export(scriptFile.getAbsolutePath()); }; }; t.start(); } }
From source file:AppSpringLayout.java
/** * Initialize the contents of the frame. *///from w w w. ja v a 2s . co m private void initialize() { frame = new JFrame(); frame.setBounds(0, 0, 850, 750); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); springLayout = new SpringLayout(); frame.getContentPane().setLayout(springLayout); frame.setLocationRelativeTo(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); // frame.getContentPane().add(fc); btnTurnCameraOn = new JButton("Turn camera on"); springLayout.putConstraint(SpringLayout.WEST, btnTurnCameraOn, 51, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnTurnCameraOn, -581, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnTurnCameraOn); urlTextField = new JTextField(); springLayout.putConstraint(SpringLayout.SOUTH, btnTurnCameraOn, -6, SpringLayout.NORTH, urlTextField); springLayout.putConstraint(SpringLayout.WEST, urlTextField, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, urlTextField, 274, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(urlTextField); urlTextField.setColumns(10); originalImageLabel = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, originalImageLabel, 102, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, originalImageLabel, 34, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, originalImageLabel, -326, SpringLayout.SOUTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, originalImageLabel, -566, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, urlTextField, -6, SpringLayout.NORTH, originalImageLabel); frame.getContentPane().add(originalImageLabel); btnAnalyseImage = new JButton("Analyse image"); springLayout.putConstraint(SpringLayout.NORTH, btnAnalyseImage, 6, SpringLayout.SOUTH, originalImageLabel); springLayout.putConstraint(SpringLayout.WEST, btnAnalyseImage, 58, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, btnAnalyseImage, 252, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnAnalyseImage); lblTags = new JLabel("Tags:"); frame.getContentPane().add(lblTags); lblDescription = new JLabel("Description:"); springLayout.putConstraint(SpringLayout.WEST, lblDescription, 84, SpringLayout.EAST, lblTags); springLayout.putConstraint(SpringLayout.NORTH, lblTags, 0, SpringLayout.NORTH, lblDescription); springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 6, SpringLayout.SOUTH, btnAnalyseImage); springLayout.putConstraint(SpringLayout.SOUTH, lblDescription, -269, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblDescription); tagsTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, tagsTextArea, 459, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, tagsTextArea, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, tagsTextArea, -727, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(tagsTextArea); descriptionTextArea = new JTextArea(); springLayout.putConstraint(SpringLayout.NORTH, descriptionTextArea, 0, SpringLayout.SOUTH, lblDescription); springLayout.putConstraint(SpringLayout.WEST, descriptionTextArea, 18, SpringLayout.EAST, tagsTextArea); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); frame.getContentPane().add(descriptionTextArea); lblImageType = new JLabel("Image type"); springLayout.putConstraint(SpringLayout.WEST, lblTags, 0, SpringLayout.WEST, lblImageType); springLayout.putConstraint(SpringLayout.NORTH, lblImageType, 10, SpringLayout.SOUTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, lblImageType, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblImageType); lblSize = new JLabel("Size"); springLayout.putConstraint(SpringLayout.NORTH, lblSize, 21, SpringLayout.SOUTH, lblImageType); springLayout.putConstraint(SpringLayout.WEST, lblSize, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblSize); lblLicense = new JLabel("License"); springLayout.putConstraint(SpringLayout.WEST, lblLicense, 20, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(lblLicense); lblSafeSearch = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch, 10, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch, 139, SpringLayout.SOUTH, frame.getContentPane()); frame.getContentPane().add(lblSafeSearch); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; licenseBox = new JComboBox(licenseTypes); springLayout.putConstraint(SpringLayout.WEST, licenseBox, 28, SpringLayout.EAST, lblLicense); frame.getContentPane().add(licenseBox); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; sizeBox = new JComboBox(sizeTypes); springLayout.putConstraint(SpringLayout.WEST, sizeBox, 50, SpringLayout.EAST, lblSize); springLayout.putConstraint(SpringLayout.EAST, sizeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.EAST, licenseBox, 0, SpringLayout.EAST, sizeBox); frame.getContentPane().add(sizeBox); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; imageTypeBox = new JComboBox(imageTypes); springLayout.putConstraint(SpringLayout.SOUTH, descriptionTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.NORTH, imageTypeBox, 547, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, tagsTextArea, -6, SpringLayout.NORTH, imageTypeBox); springLayout.putConstraint(SpringLayout.WEST, imageTypeBox, 6, SpringLayout.EAST, lblImageType); springLayout.putConstraint(SpringLayout.EAST, imageTypeBox, -556, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.NORTH, sizeBox, 10, SpringLayout.SOUTH, imageTypeBox); frame.getContentPane().add(imageTypeBox); btnBrowse = new JButton("Browse"); springLayout.putConstraint(SpringLayout.WEST, btnBrowse, 0, SpringLayout.WEST, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.EAST, btnBrowse, -583, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(btnBrowse); lblSafeSearch_1 = new JLabel("Safe search"); springLayout.putConstraint(SpringLayout.WEST, lblSafeSearch_1, 20, SpringLayout.WEST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.SOUTH, lblLicense, -17, SpringLayout.NORTH, lblSafeSearch_1); frame.getContentPane().add(lblSafeSearch_1); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; safeSearchBox = new JComboBox(safeSearchTypes); springLayout.putConstraint(SpringLayout.SOUTH, licenseBox, -6, SpringLayout.NORTH, safeSearchBox); springLayout.putConstraint(SpringLayout.WEST, safeSearchBox, 4, SpringLayout.EAST, lblSafeSearch_1); springLayout.putConstraint(SpringLayout.EAST, safeSearchBox, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); springLayout.putConstraint(SpringLayout.SOUTH, lblSafeSearch_1, -13, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.SOUTH, safeSearchBox, -6, SpringLayout.NORTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.NORTH, btnSearchForSimilar, 689, SpringLayout.NORTH, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, btnSearchForSimilar, 36, SpringLayout.WEST, frame.getContentPane()); frame.getContentPane().add(btnSearchForSimilar); btnCancel = new JButton("Cancel"); springLayout.putConstraint(SpringLayout.NORTH, btnCancel, 0, SpringLayout.NORTH, btnBrowse); btnCancel.setVisible(false); frame.getContentPane().add(btnCancel); btnSave = new JButton("Save"); springLayout.putConstraint(SpringLayout.WEST, btnCancel, 6, SpringLayout.EAST, btnSave); springLayout.putConstraint(SpringLayout.NORTH, btnSave, 0, SpringLayout.NORTH, btnBrowse); btnSave.setVisible(false); frame.getContentPane().add(btnSave); btnTakeAPicture = new JButton("Take a picture"); springLayout.putConstraint(SpringLayout.WEST, btnTakeAPicture, 114, SpringLayout.EAST, btnBrowse); springLayout.putConstraint(SpringLayout.WEST, btnSave, 6, SpringLayout.EAST, btnTakeAPicture); springLayout.putConstraint(SpringLayout.NORTH, btnTakeAPicture, 0, SpringLayout.NORTH, btnBrowse); btnTakeAPicture.setVisible(false); frame.getContentPane().add(btnTakeAPicture); //// JScrollPane scroll = new JScrollPane(list); // Constraints c = springLayout.getConstraints(list); // frame.getContentPane().add(scroll, c); list = new JList(); JScrollPane scroll = new JScrollPane(list); springLayout.putConstraint(SpringLayout.EAST, descriptionTextArea, -89, SpringLayout.WEST, list); springLayout.putConstraint(SpringLayout.EAST, list, -128, SpringLayout.EAST, frame.getContentPane()); springLayout.putConstraint(SpringLayout.WEST, list, 64, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.NORTH, list, 0, SpringLayout.NORTH, btnTurnCameraOn); springLayout.putConstraint(SpringLayout.SOUTH, list, -35, SpringLayout.SOUTH, lblSafeSearch_1); Constraints c = springLayout.getConstraints(list); frame.getContentPane().add(scroll, c); // frame.getContentPane().add(list); progressBar = new JProgressBar(); springLayout.putConstraint(SpringLayout.NORTH, progressBar, 15, SpringLayout.SOUTH, list); springLayout.putConstraint(SpringLayout.WEST, progressBar, 24, SpringLayout.EAST, safeSearchBox); springLayout.putConstraint(SpringLayout.EAST, progressBar, 389, SpringLayout.WEST, btnTakeAPicture); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setVisible(false); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); labelTryLinks = new JLabel(); labelTryLinks.setVisible(false); springLayout.putConstraint(SpringLayout.NORTH, labelTryLinks, -16, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.WEST, labelTryLinks, -61, SpringLayout.EAST, licenseBox); springLayout.putConstraint(SpringLayout.SOUTH, labelTryLinks, 0, SpringLayout.SOUTH, btnSearchForSimilar); springLayout.putConstraint(SpringLayout.EAST, labelTryLinks, 0, SpringLayout.EAST, licenseBox); frame.getContentPane().add(labelTryLinks); lblFoundLinks = new JLabel(""); springLayout.putConstraint(SpringLayout.NORTH, lblFoundLinks, -29, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.WEST, lblFoundLinks, 6, SpringLayout.EAST, scroll); springLayout.putConstraint(SpringLayout.SOUTH, lblFoundLinks, -13, SpringLayout.NORTH, progressBar); springLayout.putConstraint(SpringLayout.EAST, lblFoundLinks, -10, SpringLayout.EAST, frame.getContentPane()); frame.getContentPane().add(lblFoundLinks); numberOfImagesToSearchFor = new JTextField(); springLayout.putConstraint(SpringLayout.NORTH, numberOfImagesToSearchFor, 0, SpringLayout.NORTH, tagsTextArea); springLayout.putConstraint(SpringLayout.WEST, numberOfImagesToSearchFor, 6, SpringLayout.EAST, descriptionTextArea); springLayout.putConstraint(SpringLayout.EAST, numberOfImagesToSearchFor, -36, SpringLayout.WEST, scroll); frame.getContentPane().add(numberOfImagesToSearchFor); numberOfImagesToSearchFor.setColumns(10); JLabel lblNumberOfImages = new JLabel("Number"); springLayout.putConstraint(SpringLayout.NORTH, lblNumberOfImages, 0, SpringLayout.NORTH, lblTags); springLayout.putConstraint(SpringLayout.WEST, lblNumberOfImages, 31, SpringLayout.EAST, btnAnalyseImage); springLayout.putConstraint(SpringLayout.EAST, lblNumberOfImages, -6, SpringLayout.WEST, scroll); frame.getContentPane().add(lblNumberOfImages); // label to get coordinates for web camera panel // lblNewLabel_1 = new JLabel("New label"); // springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_1, 0, // SpringLayout.NORTH, btnTurnCameraOn); // springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 98, // SpringLayout.EAST, originalImagesLabel); // springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -430, // SpringLayout.SOUTH, lblSafeSearch_1); // springLayout.putConstraint(SpringLayout.EAST, lblNewLabel_1, 0, // SpringLayout.EAST, btnCancel); // frame.getContentPane().add(lblNewLabel_1); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnCameraOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("turn camera on"); turnCameraOn(); btnCancel.setVisible(true); btnTakeAPicture.setVisible(true); } }); btnTakeAPicture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSave.setVisible(true); imageWebcam = webcam.getImage(); originalImage = imageWebcam; // to mirror the image we create a temporary file, flip it // horizontally and then delete // get user's name to store file in the user directory String user = System.getProperty("user.home"); String fileName = user + "/webCamPhoto.jpg"; File newFile = new File(fileName); try { ImageIO.write(originalImage, "jpg", newFile); } catch (IOException e1) { e1.printStackTrace(); } try { originalImage = (BufferedImage) ImageIO.read(newFile); } catch (IOException e1) { e1.printStackTrace(); } newFile.delete(); originalImage = mirrorImage(originalImage); icon = scaleBufferedImage(originalImage, originalImageLabel); originalImageLabel.setIcon(icon); } }); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if image already exists if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } ImageIO.write(toBufferedImage(originalImage), "jpg", output); System.out.println("Your image has been saved in the folder " + file.getPath()); } catch (IOException e1) { e1.printStackTrace(); } } } }); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnTakeAPicture.setVisible(false); btnCancel.setVisible(false); btnSave.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlTextField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlTextField.getText().length() > 0) { String linkNew = urlTextField.getText(); displayImage(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyseImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Token computerVisionToken = new Token(); String computerVisionTokenFileName = "APIToken.txt"; try { computerVisionImageToken = computerVisionToken.getApiToken(computerVisionTokenFileName); try { analyse(); } catch (NullPointerException e1) { // if user clicks on "analyze" button without uploading // image or posts a broken link JOptionPane.showMessageDialog(null, "Please choose an image"); e1.printStackTrace(); } } catch (NullPointerException e1) { e1.printStackTrace(); } } }); btnSearchForSimilar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { listModel.clear(); Token bingImageToken = new Token(); String bingImageTokenFileName = "SearchApiToken.txt"; bingToken = bingImageToken.getApiToken(bingImageTokenFileName); // in case user edited description or tags, update it and // replace new line character, spaces and breaks with %20 text = descriptionTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsTextArea.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String numberOfImages = numberOfImagesToSearchFor.getText(); try { int numberOfImagesTry = Integer.parseInt(numberOfImages); System.out.println(numberOfImagesTry); imageTypeString = imageTypeBox.getSelectedItem().toString(); sizeTypeString = sizeBox.getSelectedItem().toString(); licenseTypeString = licenseBox.getSelectedItem().toString(); safeSearchTypeString = safeSearchBox.getSelectedItem().toString(); searchParameters = tagsString + text; System.out.println("search parameters: " + searchParameters); if (searchParameters.length() != 0) { // add new thread for searching, so that progress bar // and searching could run simultaneously Thread t1 = new Thread(new Runnable() { @Override public void run() { progressBar.setVisible(true); workingUrls = searchToDisplayOnJList(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString, numberOfImages); } }); // start searching in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } catch (NumberFormatException e1) { JOptionPane.showMessageDialog(null, "Please insert a valid number of images to search for"); e1.printStackTrace(); } } }); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int i = list.getSelectedIndex(); if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { file = fc.getSelectedFile(); File output = new File(file.toString()); // check if file already exists, ask user if they // wish to overwrite it if (output.exists()) { int response = JOptionPane.showConfirmDialog(null, // "Do you want to replace the existing file?", // "Confirm", JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) { return; } } try { URL fileNameAsUrl = new URL(linksResponse[i]); originalImage = ImageIO.read(fileNameAsUrl); ImageIO.write(toBufferedImage(originalImage), "jpeg", output); System.out.println("image saved, in the folder: " + output.getAbsolutePath()); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } catch (NullPointerException e2) { e2.getMessage(); } } } }); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java
private void handleExportAction(boolean closeWhenDone) { String filename = filepathText.getText().trim(); OmittedEntities entities = exportExclusionBox.createOmittedObject(this.excludeThesePlotIds, this.excludeTheseTraitIds, this.excludeTheseSampleIds); this.excludeTheseTraitIds = entities.omittedTraits; final Integer maxDatabaseVersionForWorkPackage = kdsmartVersion3option.isSelected() ? WorkPackageFactory.MAX_DBVERSION_FOR_KDSMART_2 : MIN_DB_VERSION_FOR_KDSMART_3; BackgroundTask<File, Void> task = new BackgroundTask<File, Void>("Exporting...", true) { @Override//from w w w. j ava 2s .c o m public File generateResult(Closure<Void> publishPartial) throws Exception { if (!haveCollectedSamples) { // Need the KdxSamples into the sampleGroup TrialItemVisitor<Sample> visitor = new TrialItemVisitor<Sample>() { @Override public void setExpectedItemCount(int count) { } @Override public boolean consumeItem(Sample s) throws IOException { if (s instanceof KdxSample) { boolean suppressed = ((KdxSample) s).isSuppressed(); if (suppressed) { excludeTheseSampleIds.add(s.getSampleId()); return true; } if (!excludeTheseTraitIds.contains(s.getTraitId()) && !excludeThesePlotIds.contains(s.getPlotId())) { sampleGroup.addSample((KdxSample) s); } } return true; } }; kdxploreDatabase.getKDXploreKSmartDatabase().visitSamplesForTrial( SampleGroupChoice.create(sampleGroup.getSampleGroupId()), sampleGroup.getTrialId(), SampleOrder.ALL_UNORDERED, visitor); haveCollectedSamples = true; } return doExport(filename, maxDatabaseVersionForWorkPackage, entities); } @Override public void onCancel(CancellationException e) { } @Override public void onException(Throwable cause) { GuiUtil.errorMessage(SampleGroupExportDialog.this, cause, getTitle()); } @Override public void onTaskComplete(File result) { if (result != null) { int answer = JOptionPane.showConfirmDialog(SampleGroupExportDialog.this, "Saved: " + result.getPath() + "\nOpen containing directory?", getTitle(), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.YES_OPTION) { try { net.pearcan.util.Util.openFile(result.getParentFile()); } catch (IOException e) { GuiUtil.errorMessage(SampleGroupExportDialog.this, e.getMessage(), "Failed: " + getTitle()); } } if (closeWhenDone) { dispose(); } } } }; backgroundRunner.runBackgroundTask(task); }
From source file:com.floreantpos.ui.views.payment.SettleTicketDialog.java
public void settleTicket(PosTransaction transaction) { try {/*from ww w.j a va 2s . c om*/ final double dueAmount = ticket.getDueAmount(); confirmLoyaltyDiscount(ticket); PosTransactionService transactionService = PosTransactionService.getInstance(); transactionService.settleTicket(ticket, transaction); //FIXME printTicket(ticket, transaction); showTransactionCompleteMsg(dueAmount, transaction.getTenderAmount(), ticket, transaction); if (ticket.getDueAmount() > 0.0) { int option = JOptionPane.showConfirmDialog(Application.getPosWindow(), POSConstants.CONFIRM_PARTIAL_PAYMENT, POSConstants.MDS_POS, JOptionPane.YES_NO_OPTION); if (option != JOptionPane.YES_OPTION) { setCanceled(false); dispose(); } setTicket(ticket); } else { setCanceled(false); dispose(); } } catch (UnknownHostException e) { POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("SettleTicketDialog.12")); //$NON-NLS-1$ } catch (Exception e) { POSMessageDialog.showError(this, POSConstants.ERROR_MESSAGE, e); } }
From source file:course_generator.param.frmEditCurve.java
/** * Delete the selected line in the points table *//*from ww w . ja v a 2 s . c o m*/ protected void DeleteLine() { if (!bEditMode) return; int r = TablePoints.getSelectedRow(); if (r >= 0) { Object[] options = { " " + bundle.getString("frmEditCurve.DeleteYes") + " ", " " + bundle.getString("frmEditCurve.DeleteNo") + " " }; int ret = JOptionPane.showOptionDialog(this, bundle.getString("frmEditCurve.DeleteLineMessage"), bundle.getString("frmEditCurve.DeleteLineTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (ret == JOptionPane.YES_OPTION) { param.data.remove(r); Collections.sort(param.data); RefreshView(); } } }
From source file:livecanvas.mesheditor.MeshEditor.java
private void exit() { if (JOptionPane.showConfirmDialog(MeshEditor.this, "Are you sure you want to exit?", "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) != JOptionPane.YES_OPTION) { return;/*from w w w.j a v a2 s. c o m*/ } System.exit(0); }