List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException
optionType
parameter, where the messageType
parameter determines the icon to display. From source file:org.syncany.plugins.php.PhpTransferManager.java
@SuppressWarnings("deprecation") private CloseableHttpClient getHttpClient() { try {/*from w w w . j a v a 2 s . c o m*/ @SuppressWarnings("deprecation") SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { if (lastSite != null && !lastSite.equals("")) { Preferences prefs = Preferences.userRoot().node(this.getClass().getName()); int prevr = prefs.getInt(lastSite, -1); if (prevr == -1) { int r = JOptionPane.showConfirmDialog(null, lastSite + "'s SSL certificate is not trusted, do you want to accept it?", "Accept SSL Certificate?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); logger.warning(lastSite + " not trusted, user answered " + r); prevr = r; prefs.putInt(lastSite, r); } logger.warning(lastSite + " not trusted, registered user answer: " + prevr); if (prevr == 0) { return true; } else { return false; } } else { return false; } } }); @SuppressWarnings("deprecation") SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", 443, sf)); @SuppressWarnings("deprecation") ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry); return new DefaultHttpClient(ccm); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void btnDeleteActionPerformed(ActionEvent e) { try {/*from w w w . j a v a2s .c o m*/ DocumentSlimValue currDoc = null; String acc = bgrp.getSelection().getActionCommand(); int rowInModel = tblDocumentsModel.getRowForDocument(Integer.valueOf(acc)); if (rowInModel >= 0) { currDoc = (DocumentSlimValue) tblDocumentsModel.getValueAt(rowInModel, 4); } String tmp = acc; if (currDoc != null && currDoc.getDocumentName() != null && !"".equalsIgnoreCase(currDoc.getDocumentName())) { tmp += " (" + currDoc.getDocumentName() + ")"; } /* if (currDoc != null && (currDoc.getUseCountLastVersion() + currDoc.getUseCountPublishVersion()) > 0) { JOptionPane.showMessageDialog(this, SwingMessages.getString("panel.content.documents.deleteButInUse", tmp), SwingMessages.getString("panel.content.documents.deleteDocument"), JOptionPane.WARNING_MESSAGE); return; } */ int ret = JOptionPane.showConfirmDialog(this, Messages.getString("panel.content.documents.deleteThisDocument", tmp), Messages.getString("panel.content.documents.deleteDocument"), JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.YES_OPTION) { comm.removeDocument(Integer.valueOf(acc).intValue()); loadThumbs(((CboModel) this.cboRegion.getSelectedItem()).getRegionId()); } } catch (NullPointerException ex) { } catch (Exception ex) { if (ex.getMessage().contains("validation exception")) { JOptionPane.showConfirmDialog(this, rb.getString("panel.content.documents.delete.exception"), rb.getString("panel.content.documents.deleteDocument"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } else { log.warn("exception on delete document"); if (log.isDebugEnabled()) { log.debug(ex); } } } }
From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java
private void filterSampleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterSampleButtonActionPerformed int r = JOptionPane.showConfirmDialog(chartPanel, filterPanel, "Select evaluation sample", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (r == JOptionPane.OK_OPTION) { updateChart();//w ww. ja v a 2 s .c o m } }
From source file:com.jug.MotherMachine.java
/** * * @param guiFrame//from w ww .j av a 2s .co m * parent frame * @param path * path to be suggested to open * @return */ private File showStartupDialog(final JFrame guiFrame, final String path) { final String parentFolder = path.substring(0, path.lastIndexOf(File.separatorChar)); int decision = 0; if (path.equals(System.getProperty("user.home"))) { decision = JOptionPane.NO_OPTION; } else { final String message = "Should the MotherMachine be opened with the data found in:\n" + path + "\n\nIn case you want to choose a folder please select 'No'..."; final String title = "MotherMachine Start Dialog"; decision = JOptionPane.showConfirmDialog(guiFrame, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } if (decision == JOptionPane.YES_OPTION) { return new File(path); } else { return showFolderChooser(guiFrame, parentFolder); } }
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// w w w .ja va2 s . co 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:AppSpringLayout.java
/** * Initialize the contents of the frame. *///from w ww . ja v a 2 s . c om 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:ru.apertum.qsystem.client.forms.FAdmin.java
/** * Creates new form FAdmin// www . ja va 2 s . com */ public FAdmin() { addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { timer.stop(); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { Uses.closeSplash(); } @Override public void windowDeactivated(WindowEvent e) { } }); initComponents(); setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF())); try { setIconImage( ImageIO.read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png"))); } catch (IOException ex) { System.err.println(ex); } // final Toolkit kit = Toolkit.getDefaultToolkit(); setLocation((Math.round(kit.getScreenSize().width - getWidth()) / 2), (Math.round(kit.getScreenSize().height - getHeight()) / 2)); // ? ? final JFrame fr = this; tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/admin.png", getLocaleMessage("tray.caption")); tray.addItem(getLocaleMessage("tray.caption"), (ActionEvent e) -> { setVisible(true); setState(JFrame.NORMAL); }); tray.addItem("-", (ActionEvent e) -> { }); tray.addItem(getLocaleMessage("tray.exit"), (ActionEvent e) -> { dispose(); System.exit(0); }); int ii = 1; final ButtonGroup bg = new ButtonGroup(); final String currLng = Locales.getInstance().getLangCurrName(); for (String lng : Locales.getInstance().getAvailableLocales()) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem( org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext() .getActionMap(FAdmin.class, fr).get("setCurrentLang")); bg.add(item); item.setSelected(lng.equals(currLng)); item.setText(lng); // NOI18N item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N menuLangs.add(item); } // ?? ??. listUsers.addListSelectionListener((ListSelectionEvent e) -> { userListChange(); }); // ?? ??. listResponse.addListSelectionListener((ListSelectionEvent e) -> { responseListChange(); }); listSchedule.addListSelectionListener((ListSelectionEvent e) -> { scheduleListChange(); }); listCalendar.addListSelectionListener(new ListSelectionListener() { private int oldSelectedValue = 0; private int tmp = 0; public int getOldSelectedValue() { return oldSelectedValue; } public void setOldSelectedValue(int oldSelectedValue) { this.oldSelectedValue = tmp; this.tmp = oldSelectedValue; } private boolean canceled = false; @Override public void valueChanged(ListSelectionEvent e) { if (canceled) { canceled = false; } else { if (tableCalendar.getModel() instanceof CalendarTableModel) { final CalendarTableModel model = (CalendarTableModel) tableCalendar.getModel(); if (!model.isSaved()) { final int res = JOptionPane.showConfirmDialog(null, getLocaleMessage("calendar.change.title"), getLocaleMessage("calendar.change.caption"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); switch (res) { case 0: // ? ?? model.save(); calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); break; case 1: // ?? ?? calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); break; case 2: // ?? ??? canceled = true; listCalendar.setSelectedIndex(getOldSelectedValue()); break; } } else { calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); } } else { calendarListChange(); setOldSelectedValue(listCalendar.getSelectedIndex()); } } } }); // ?? ? ??. treeServices.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); treeInfo.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); /* treeServices.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); setText(((Element) value).attributeValue(Uses.TAG_NAME)); return this; } });*/ treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> { serviceListChange(); }); treeInfo.addTreeSelectionListener((TreeSelectionEvent e) -> { infoListChange(); }); textFieldStartTime.setInputVerifier(DateVerifier); textFieldFinishTime.setInputVerifier(DateVerifier); // ? loadSettings(); // ? ?. startTimer(); // loadConfig(); spinnerPropServerPort.getModel().addChangeListener(new ChangeNet()); spinnerPropClientPort.getModel().addChangeListener(new ChangeNet()); spinnerWebServerPort.getModel().addChangeListener(new ChangeNet()); spinnerServerPort.getModel().addChangeListener(new ChangeSettings()); spinnerClientPort.getModel().addChangeListener(new ChangeSettings()); spinnerUserRS.getModel().addChangeListener(new ChangeUser()); //? . final Helper helper = Helper.getHelp("ru/apertum/qsystem/client/help/admin.hs"); helper.setHelpListener(menuItemHelp); helper.enableHelpKey(jPanel1, "introduction"); helper.enableHelpKey(jPanel3, "monitoring"); helper.enableHelpKey(jPanel4, "configuring"); helper.enableHelpKey(jPanel8, "net"); helper.enableHelpKey(jPanel17, "schedulers"); helper.enableHelpKey(jPanel19, "calendars"); helper.enableHelpKey(jPanel2, "infoSystem"); helper.enableHelpKey(jPanel13, "responses"); helper.enableHelpKey(jPanel18, "results"); treeServices.setTransferHandler(new TransferHandler() { @Override public boolean canImport(TransferHandler.TransferSupport info) { final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation(); if (dl.getChildIndex() == -1) { return false; } // Get the string that is being dropped. final Transferable t = info.getTransferable(); final QService data; try { data = (QService) t.getTransferData(DataFlavor.stringFlavor); return (data.getParent().getId() .equals(((QService) dl.getPath().getLastPathComponent()).getId())); } catch (UnsupportedFlavorException | IOException e) { return false; } } @Override public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } final QService data; try { data = (QService) info.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { System.err.println(e); return false; } final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation(); final TreePath tp = dl.getPath(); final QService parent = (QService) tp.getLastPathComponent(); ((QServiceTree) treeServices.getModel()).moveNode(data, parent, dl.getChildIndex()); return true; } @Override public int getSourceActions(JComponent c) { return MOVE; } @Override protected Transferable createTransferable(JComponent c) { return (QService) ((JTree) c).getLastSelectedPathComponent(); } }); treeServices.setDropMode(DropMode.INSERT); // ? final AnnotationSessionFactoryBean as = (AnnotationSessionFactoryBean) Spring.getInstance().getFactory() .getBean("conf"); if (as.getServers().size() > 1) { final JMenu menu = new JMenu(getLocaleMessage("admin.servers")); as.getServers().stream().map((ser) -> { final JMenuItem mi1 = new JMenuItem(as); mi1.setText(ser.isCurrent() ? "<html><u><i>" + ser.getName() + "</i></u>" : ser.getName()); return mi1; }).forEach((mi1) -> { menu.add(mi1); }); jMenuBar1.add(menu, 4); jMenuBar1.add(new JLabel( "<html><span style='font-size:13.0pt;color:red'> [" + as.getName() + "]")); } comboBoxVoices.setVisible(false); }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
private void showPropertyEditor(int tabIndex) { Hist2DChartEditor editor = new Hist2DChartEditor(getChart(), this); editor.getTabs().setSelectedIndex(tabIndex); int result = JOptionPane.showConfirmDialog(this, editor, localizationResources.getString("Chart_Properties"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(getChart());//from ww w. j av a 2 s.com } }
From source file:net.sf.jabref.external.DroppedFileHandler.java
/** * Copy the given file to the base directory for its file type, and give it * the given name./*from w w w . ja v a 2 s . c o m*/ * * @param fileName The name of the source file. * @param toFile The destination filename. An existing path-component will be removed. * @param edits TODO we should be able to undo this! * @return */ private boolean doCopy(String fileName, String toFile, NamedCompound edits) { List<String> dirs = panel.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) { // OOps, we don't know which directory to put it in, or the given // dir doesn't exist.... // This should not happen!! LOGGER.warn("Cannot determine destination directory or destination directory does not exist"); return false; } String destinationFileName = new File(toFile).getName(); File destFile = new File(dirs.get(found) + System.getProperty("file.separator") + destinationFileName); if (destFile.equals(new File(fileName))) { // File is already in the correct position. Don't override! return true; } if (destFile.exists()) { int answer = JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", destFile.getPath()), Localization.lang("File exists"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { return false; } } try { FileUtil.copyFile(new File(fileName), destFile, true); } catch (IOException e) { LOGGER.error("Problem copying file", e); return false; } return true; }
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;// w w w . j av a 2 s. co m } System.exit(0); }