List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
From source file:App.java
/** * Initialize the contents of the frame. *//*from ww w . j a va2 s. c o m*/ private void initialize() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1000, 750); frame.getContentPane().setLayout(null); FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "jpeg", "png"); fc = new JFileChooser(); fc.setFileFilter(filter); frame.getContentPane().add(fc); stepOne = new JLabel(""); stepOne.setToolTipText("here comes something"); stepOne.setIcon(new ImageIcon("img/stepOne.png")); stepOne.setBounds(266, -4, 67, 49); frame.getContentPane().add(stepOne); btnBrowse = new JButton("Browse"); btnBrowse.setBounds(66, 6, 117, 29); frame.getContentPane().add(btnBrowse); btnTurnWebcamOn = new JButton("Take a picture with webcam"); btnTurnWebcamOn.setBounds(66, 34, 212, 29); frame.getContentPane().add(btnTurnWebcamOn); JButton btnTakePictureWithWebcam = new JButton("Take a picture"); btnTakePictureWithWebcam.setBounds(430, 324, 117, 29); frame.getContentPane().add(btnTakePictureWithWebcam); btnTakePictureWithWebcam.setVisible(false); JButton btnCancel = new JButton("Cancel"); btnCancel.setBounds(542, 324, 117, 29); frame.getContentPane().add(btnCancel); btnCancel.setVisible(false); JButton btnSaveImage = new JButton("Save image"); btnSaveImage.setBounds(497, 357, 117, 29); frame.getContentPane().add(btnSaveImage); btnSaveImage.setVisible(false); urlField = new JTextField(); urlField.setBounds(66, 67, 220, 26); frame.getContentPane().add(urlField); urlField.setColumns(10); originalImageLabel = new JLabel(); originalImageLabel.setHorizontalAlignment(SwingConstants.CENTER); originalImageLabel.setBounds(33, 98, 300, 300); frame.getContentPane().add(originalImageLabel); stepTwo = new JLabel(""); stepTwo.setToolTipText("here comes something else"); stepTwo.setIcon(new ImageIcon("img/stepTwo.png")); stepTwo.setBounds(266, 413, 67, 49); frame.getContentPane().add(stepTwo); btnAnalyse = new JButton("Analyse image"); btnAnalyse.setBounds(68, 423, 196, 29); frame.getContentPane().add(btnAnalyse); tagsField = new JTextArea(); tagsField.setBounds(23, 479, 102, 89); tagsField.setLineWrap(true); tagsField.setWrapStyleWord(true); frame.getContentPane().add(tagsField); tagsField.setColumns(10); lblTags = new JLabel("Tags:"); lblTags.setBounds(46, 451, 61, 16); frame.getContentPane().add(lblTags); descriptionField = new JTextArea(); descriptionField.setLineWrap(true); descriptionField.setWrapStyleWord(true); descriptionField.setBounds(137, 479, 187, 89); frame.getContentPane().add(descriptionField); descriptionField.setColumns(10); lblDescription = new JLabel("Description:"); lblDescription.setBounds(163, 451, 77, 16); frame.getContentPane().add(lblDescription); stepThree = new JLabel(""); stepThree.setToolTipText("here comes something different"); stepThree.setIcon(new ImageIcon("img/stepThree.png")); stepThree.setBounds(266, 685, 67, 49); frame.getContentPane().add(stepThree); JLabel lblImageType = new JLabel("Image type"); lblImageType.setBounds(23, 580, 102, 16); frame.getContentPane().add(lblImageType); String[] imageTypes = { "unspecified", "AnimategGif", "Clipart", "Line", "Photo" }; JComboBox imageTypeBox = new JComboBox(imageTypes); imageTypeBox.setBounds(137, 580, 187, 23); frame.getContentPane().add(imageTypeBox); JLabel lblSizeType = new JLabel("Size"); lblSizeType.setBounds(23, 608, 102, 16); frame.getContentPane().add(lblSizeType); String[] sizeTypes = { "unspecified", "Small", "Medium", "Large", "Wallpaper" }; JComboBox sizeBox = new JComboBox(sizeTypes); sizeBox.setBounds(137, 608, 187, 23); frame.getContentPane().add(sizeBox); JLabel lblLicenseType = new JLabel("License"); lblLicenseType.setBounds(23, 636, 102, 16); frame.getContentPane().add(lblLicenseType); String[] licenseTypes = { "unspecified", "Public", "Share", "ShareCommercially", "Modify" }; JComboBox licenseBox = new JComboBox(licenseTypes); licenseBox.setBounds(137, 636, 187, 23); frame.getContentPane().add(licenseBox); JLabel lblSafeSearchType = new JLabel("Safe search"); lblSafeSearchType.setBounds(23, 664, 102, 16); frame.getContentPane().add(lblSafeSearchType); String[] safeSearchTypes = { "Strict", "Moderate", "Off" }; JComboBox safeSearchBox = new JComboBox(safeSearchTypes); safeSearchBox.setBounds(137, 664, 187, 23); frame.getContentPane().add(safeSearchBox); btnSearchForSimilar = new JButton("Search for similar images"); btnSearchForSimilar.setVisible(true); btnSearchForSimilar.setBounds(66, 695, 189, 29); frame.getContentPane().add(btnSearchForSimilar); // label to try urls to display images, not shown on the main frame labelTryLinks = new JLabel(); labelTryLinks.setBounds(0, 0, 100, 100); foundImagesLabel1 = new JLabel(); foundImagesLabel1.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel1.setBounds(400, 49, 250, 250); frame.getContentPane().add(foundImagesLabel1); foundImagesLabel2 = new JLabel(); foundImagesLabel2.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel2.setBounds(400, 313, 250, 250); frame.getContentPane().add(foundImagesLabel2); foundImagesLabel3 = new JLabel(); foundImagesLabel3.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel3.setBounds(673, 49, 250, 250); frame.getContentPane().add(foundImagesLabel3); foundImagesLabel4 = new JLabel(); foundImagesLabel4.setHorizontalAlignment(SwingConstants.CENTER); foundImagesLabel4.setBounds(673, 313, 250, 250); frame.getContentPane().add(foundImagesLabel4); progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setStringPainted(true); progressBar.setBounds(440, 602, 440, 29); Border border = BorderFactory .createTitledBorder("We are checking every image, pixel by pixel, it may take a while..."); progressBar.setBorder(border); frame.getContentPane().add(progressBar); progressBar.setVisible(false); btnHelp = new JButton(""); btnHelp.setBorderPainted(false); ImageIcon btnIcon = new ImageIcon("img/helpRed.png"); btnHelp.setIcon(btnIcon); btnHelp.setBounds(917, 4, 77, 59); frame.getContentPane().add(btnHelp); // all action listeners btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { openFilechooser(); } } }); btnTurnWebcamOn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setAllFoundImagesLabelsAndPreviewsToNull(); btnTakePictureWithWebcam.setVisible(true); btnCancel.setVisible(true); turnCameraOn(); } }); btnTakePictureWithWebcam.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnSaveImage.setVisible(true); // take a photo with web camera 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); } }); btnSaveImage.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() { @Override public void actionPerformed(ActionEvent e) { btnTakePictureWithWebcam.setVisible(false); btnCancel.setVisible(false); btnSaveImage.setVisible(false); webcam.close(); panel.setVisible(false); } }); urlField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (urlField.getText().length() > 0) { String linkNew = urlField.getText(); getImageFromHttp(linkNew, originalImageLabel); originalImage = imageResponses; } } }); btnAnalyse.addActionListener(new ActionListener() { @Override 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) { // clear labels in case there were results of previous search setAllFoundImagesLabelsAndPreviewsToNull(); System.out.println("=========================================="); System.out.println("new search"); System.out.println("=========================================="); 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 = descriptionField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); String tagsString = tagsField.getText().replace(" ", "%20").replace("\r", "%20").replace("\n", "%20"); 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); searchForSimilarImages(searchParameters, imageTypeString, sizeTypeString, licenseTypeString, safeSearchTypeString); } }); // start searching for similar images in a separate thread t1.start(); } else { JOptionPane.showMessageDialog(null, "Please choose first an image to analyse or insert search parameters"); } } }); foundImagesLabel1.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel1.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(firstImageUrl); } } } }); foundImagesLabel2.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel2.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(secondImageUrl); } } } }); foundImagesLabel3.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel3.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(thirdImageUrl); } } } }); foundImagesLabel4.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (foundImagesLabel4.getIcon() != null) { if (fc.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { saveFileChooser(fourthImageUrl); } } } }); btnHelp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO write help HelpFrame help = new HelpFrame(); } }); }
From source file:misc.ModalityDemo.java
/** * Create the GUI and show it. For thread safety, * this method is invoked from the//w w w .ja va2 s .co m * event-dispatching thread. */ private void createAndShowGUI() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc); int sw = gc.getBounds().width - ins.left - ins.right; int sh = gc.getBounds().height - ins.top - ins.bottom; // first document // frame f1 f1 = new JFrame("Book 1 (parent frame)"); f1.setBounds(32, 32, 300, 200); f1.addWindowListener(closeWindow); // create radio buttons rb11 = new JRadioButton("Biography", true); rb12 = new JRadioButton("Funny tale", false); rb13 = new JRadioButton("Sonnets", false); // place radio buttons into a single group ButtonGroup bg1 = new ButtonGroup(); bg1.add(rb11); bg1.add(rb12); bg1.add(rb13); JButton b1 = new JButton("OK"); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // get label of selected radiobutton String title = null; if (rb11.isSelected()) { title = rb11.getText(); } else if (rb12.isSelected()) { title = rb12.getText(); } else { title = rb13.getText(); } // prepend radio button label to dialogs' titles d2.setTitle(title + " (modeless dialog)"); d3.setTitle(title + " (document-modal dialog)"); d2.setVisible(true); } }); Container cp1 = f1.getContentPane(); // create three containers to improve layouting cp1.setLayout(new GridLayout(1, 3)); // an empty container Container cp11 = new Container(); // a container to layout components Container cp12 = new Container(); // an empty container Container cp13 = new Container(); // add a button into a separate panel JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout()); p1.add(b1); // add radio buttons and the OK button one after another into a single column cp12.setLayout(new GridLayout(4, 1)); cp12.add(rb11); cp12.add(rb12); cp12.add(rb13); cp12.add(p1); // add three containers cp1.add(cp11); cp1.add(cp12); cp1.add(cp13); // dialog d2 d2 = new JDialog(f1); d2.setBounds(132, 132, 300, 200); d2.addWindowListener(closeWindow); JLabel l2 = new JLabel("Enter your name: "); l2.setHorizontalAlignment(SwingConstants.CENTER); tf2 = new JTextField(12); JButton b2 = new JButton("OK"); b2.setHorizontalAlignment(SwingConstants.CENTER); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //pass a name into the document modal dialog l3.setText("by " + tf2.getText()); d3.setVisible(true); } }); Container cp2 = d2.getContentPane(); // add label, text field and button one after another into a single column cp2.setLayout(new BorderLayout()); cp2.add(l2, BorderLayout.NORTH); cp2.add(tf2, BorderLayout.CENTER); JPanel p2 = new JPanel(); p2.setLayout(new FlowLayout()); p2.add(b2); cp2.add(p2, BorderLayout.SOUTH); // dialog d3 d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL); d3.setBounds(232, 232, 300, 200); d3.addWindowListener(closeWindow); JTextArea ta3 = new JTextArea(); l3 = new JLabel(); l3.setHorizontalAlignment(SwingConstants.RIGHT); Container cp3 = d3.getContentPane(); cp3.setLayout(new BorderLayout()); cp3.add(new JScrollPane(ta3), BorderLayout.CENTER); JPanel p3 = new JPanel(); p3.setLayout(new FlowLayout(FlowLayout.RIGHT)); p3.add(l3); cp3.add(p3, BorderLayout.SOUTH); // second document // frame f4 f4 = new JFrame("Book 2 (parent frame)"); f4.setBounds(sw - 300 - 32, 32, 300, 200); f4.addWindowListener(closeWindow); // create radio buttons rb41 = new JRadioButton("Biography", true); rb42 = new JRadioButton("Funny tale", false); rb43 = new JRadioButton("Sonnets", false); // place radio buttons into a single group ButtonGroup bg4 = new ButtonGroup(); bg4.add(rb41); bg4.add(rb42); bg4.add(rb43); JButton b4 = new JButton("OK"); b4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // get label of selected radiobutton String title = null; if (rb41.isSelected()) { title = rb41.getText(); } else if (rb42.isSelected()) { title = rb42.getText(); } else { title = rb43.getText(); } // prepend radiobutton label to dialogs' titles d5.setTitle(title + " (modeless dialog)"); d6.setTitle(title + " (document-modal dialog)"); d5.setVisible(true); } }); Container cp4 = f4.getContentPane(); // create three containers to improve layouting cp4.setLayout(new GridLayout(1, 3)); Container cp41 = new Container(); Container cp42 = new Container(); Container cp43 = new Container(); // add the button into a separate panel JPanel p4 = new JPanel(); p4.setLayout(new FlowLayout()); p4.add(b4); // add radiobuttons and the OK button one after another into a single column cp42.setLayout(new GridLayout(4, 1)); cp42.add(rb41); cp42.add(rb42); cp42.add(rb43); cp42.add(p4); //add three containers cp4.add(cp41); cp4.add(cp42); cp4.add(cp43); // dialog d5 d5 = new JDialog(f4); d5.setBounds(sw - 400 - 32, 132, 300, 200); d5.addWindowListener(closeWindow); JLabel l5 = new JLabel("Enter your name: "); l5.setHorizontalAlignment(SwingConstants.CENTER); tf5 = new JTextField(12); tf5.setHorizontalAlignment(SwingConstants.CENTER); JButton b5 = new JButton("OK"); b5.setHorizontalAlignment(SwingConstants.CENTER); b5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //pass a name into the document modal dialog l6.setText("by " + tf5.getText()); d6.setVisible(true); } }); Container cp5 = d5.getContentPane(); // add label, text field and button one after another into a single column cp5.setLayout(new BorderLayout()); cp5.add(l5, BorderLayout.NORTH); cp5.add(tf5, BorderLayout.CENTER); JPanel p5 = new JPanel(); p5.setLayout(new FlowLayout()); p5.add(b5); cp5.add(p5, BorderLayout.SOUTH); // dialog d6 d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL); d6.setBounds(sw - 500 - 32, 232, 300, 200); d6.addWindowListener(closeWindow); JTextArea ta6 = new JTextArea(); l6 = new JLabel(); l6.setHorizontalAlignment(SwingConstants.RIGHT); Container cp6 = d6.getContentPane(); cp6.setLayout(new BorderLayout()); cp6.add(new JScrollPane(ta6), BorderLayout.CENTER); JPanel p6 = new JPanel(); p6.setLayout(new FlowLayout(FlowLayout.RIGHT)); p6.add(l6); cp6.add(p6, BorderLayout.SOUTH); // third document // frame f7 f7 = new JFrame("Classics (excluded frame)"); f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); f7.setBounds(32, sh - 200 - 32, 300, 200); f7.addWindowListener(closeWindow); JLabel l7 = new JLabel("Famous writers: "); l7.setHorizontalAlignment(SwingConstants.CENTER); // create radio buttons rb71 = new JRadioButton("Burns", true); rb72 = new JRadioButton("Dickens", false); rb73 = new JRadioButton("Twain", false); // place radio buttons into a single group ButtonGroup bg7 = new ButtonGroup(); bg7.add(rb71); bg7.add(rb72); bg7.add(rb73); Container cp7 = f7.getContentPane(); // create three containers to improve layouting cp7.setLayout(new GridLayout(1, 3)); Container cp71 = new Container(); Container cp72 = new Container(); Container cp73 = new Container(); // add the label into a separate panel JPanel p7 = new JPanel(); p7.setLayout(new FlowLayout()); p7.add(l7); // add a label and radio buttons one after another into a single column cp72.setLayout(new GridLayout(4, 1)); cp72.add(p7); cp72.add(rb71); cp72.add(rb72); cp72.add(rb73); // add three containers cp7.add(cp71); cp7.add(cp72); cp7.add(cp73); // fourth document // frame f8 f8 = new JFrame("Feedback (parent frame)"); f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200); f8.addWindowListener(closeWindow); JButton b8 = new JButton("Rate yourself"); b8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } }); Container cp8 = f8.getContentPane(); cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8)); cp8.add(b8); }
From source file:gmgen.util.MiscUtilities.java
/** * Copy a file/*from w w w. j a v a 2 s . c o m*/ * @param from_file * @param to_file * @throws IOException */ public static void copy(File from_file, File to_file) throws IOException { // First make sure the source file exists, is a file, and is readable. if (!from_file.exists()) { throw new IOException("FileCopy: no such source file: " + from_file.getPath()); } if (!from_file.isFile()) { throw new IOException("FileCopy: can't copy directory: " + from_file.getPath()); } if (!from_file.canRead()) { throw new IOException("FileCopy: source file is unreadable: " + from_file.getPath()); } // If the destination is a directory, use the source file name // as the destination file name if (to_file.isDirectory()) { to_file = new File(to_file, from_file.getName()); } // If the destination exists, make sure it is a writeable file // and ask before overwriting it. If the destination doesn't // exist, make sure the directory exists and is writeable. if (to_file.exists()) { if (!to_file.canWrite()) { throw new IOException("FileCopy: destination file is unwriteable: " + to_file.getPath()); } // Ask whether to overwrite it int choice = JOptionPane.showConfirmDialog(null, "Overwrite existing file " + to_file.getPath(), "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice != JOptionPane.YES_OPTION) { throw new IOException("FileCopy: existing file was not overwritten."); } } else { // if file doesn't exist, check if directory exists and is writeable. // If getParent() returns null, then the directory is the current dir. // so look up the user.dir system property to find out what that is. String parent = to_file.getParent(); // Get the destination directory if (parent == null) { parent = Globals.getDefaultPath(); // or CWD } File dir = new File(parent); // Convert it to a file. if (!dir.exists()) { throw new IOException("FileCopy: destination directory doesn't exist: " + parent); } if (dir.isFile()) { throw new IOException("FileCopy: destination is not a directory: " + parent); } if (!dir.canWrite()) { throw new IOException("FileCopy: destination directory is unwriteable: " + parent); } } // If we've gotten this far, then everything is okay. // So we copy the file, a buffer of bytes at a time. FileInputStream from = null; // Stream to read from source FileOutputStream to = null; // Stream to write to destination try { from = new FileInputStream(from_file); // Create input stream to = new FileOutputStream(to_file); // Create output stream byte[] buffer = new byte[4096]; // A buffer to hold file contents int bytes_read; // How many bytes in buffer while ((bytes_read = from.read(buffer)) != -1) { // Read bytes until EOF to.write(buffer, 0, bytes_read); // write bytes } } // Always close the streams, even if exceptions were thrown finally { if (from != null) { try { from.close(); } catch (IOException e) { //TODO: Should this really be ignored? } } if (to != null) { try { to.close(); } catch (IOException e) { //TODO: Should this really be ignored? } } } }
From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a password./*from w ww .j ava 2 s .c om*/ * @param topframe the parent frame * @return the password */ public static String askForPassword(final Frame topframe) { PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel label = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(label, cc.xy(1, 1)); builder.add(passField, cc.xy(3, 1)); builder.add(savePassword, cc.xy(3, 3)); JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), //$NON-NLS-1$ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); if (savePassword.isSelected()) { AppPreferences appPrefs = AppPreferences.getRemote(); if (StringUtils.isNotEmpty(passwordText)) { appPrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } return passwordText; }
From source file:net.sf.jabref.external.DroppedFileHandler.java
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {//from w ww . java2s .c om String dialogTitle = Localization.lang("Link to file %0", linkFileName); 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) { destDirLabel.setText(Localization.lang("File directory is not set or does not exist!")); copyRadioButton.setEnabled(false); moveRadioButton.setEnabled(false); renameToTextBox.setEnabled(false); renameCheckBox.setEnabled(false); linkInPlace.setSelected(true); } else { destDirLabel.setText(Localization.lang("File directory is '%0':", dirs.get(found))); copyRadioButton.setEnabled(true); moveRadioButton.setEnabled(true); renameToTextBox.setEnabled(true); renameCheckBox.setEnabled(true); } ChangeListener cl = arg0 -> { renameCheckBox.setEnabled(!linkInPlace.isSelected()); renameToTextBox.setEnabled(!linkInPlace.isSelected()); }; linkInPlace.setText(Localization.lang("Leave file in its current directory")); copyRadioButton.setText(Localization.lang("Copy file to file directory")); moveRadioButton.setText(Localization.lang("Move file to file directory")); renameCheckBox.setText(Localization.lang("Rename file to").concat(": ")); // Determine which name to suggest: String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader, Globals.prefs); renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension())); linkInPlace.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_LEAVE)); copyRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_COPY)); moveRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_MOVE)); renameCheckBox.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_RENAME)); linkInPlace.addChangeListener(cl); cl.stateChanged(new ChangeEvent(linkInPlace)); try { Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel }; int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (reply == JOptionPane.OK_OPTION) { // store user's choice frame.prefs().putBoolean(DroppedFileHandler.DFH_LEAVE, linkInPlace.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_COPY, copyRadioButton.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_MOVE, moveRadioButton.isSelected()); frame.prefs().putBoolean(DroppedFileHandler.DFH_RENAME, renameCheckBox.isSelected()); return true; } else { return false; } } finally { linkInPlace.removeChangeListener(cl); } }
From source file:latexstudio.editor.EditorTopComponent.java
public UnsavedWorkState canOpen() { if (isModified() && !isPreviewDisplayed()) { int userChoice = JOptionPane.showConfirmDialog(this, "This document has been modified. Do you want to save it first?", "Save document", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (userChoice == JOptionPane.YES_OPTION) { return UnsavedWorkState.SAVE_AND_OPEN; } else if (userChoice == JOptionPane.NO_OPTION) { return UnsavedWorkState.OPEN; } else {/*from w w w .j a v a2s. c o m*/ return UnsavedWorkState.CANCEL; } } else { return UnsavedWorkState.OPEN; } }
From source file:fr.vdl.android.holocolors.HoloColorsDialog.java
private void checkLicence() { try {/*from w w w . j av a2 s . c o m*/ String userHome = System.getProperty("user.home"); File holoColorsFolder = new File(userHome + File.separator + ".holocolors"); File licenceFile = new File(holoColorsFolder, ".licence"); File noDonationFile = new File(holoColorsFolder, ".nodonation"); if (noDonationFile.exists()) { return; } int usage = 1; boolean showPopup = false; if (!holoColorsFolder.exists()) { holoColorsFolder.mkdir(); showPopup = true; licenceFile.createNewFile(); } else { Scanner in = new Scanner(new FileReader(licenceFile)); if (in.hasNextInt()) { usage = in.nextInt() + 1; } in.close(); } if (usage > 10) { usage = 1; showPopup = true; } Writer out = new BufferedWriter(new FileWriter(licenceFile)); out.write(String.valueOf(usage)); out.close(); if (showPopup) { Object[] donationOption = { "Make a donation", "Maybe later", "No Never" }; int option = JOptionPane.showOptionDialog(ahcPanel, "Thanks for using Android Holo Colors!\n\nAndroid Holo Colors (website and plugin) is free to use.\nIf you save time and money with it, please make a donation.", "Support Android Holo Colors", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon(getClass().getResource("/icons/H64.png")), donationOption, donationOption[0]); if (option == 0) { openWebpage( "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XQSBX55A2Z46U"); } if (option == 2) { noDonationFile.createNewFile(); } } } catch (Exception e) { // no matter, nothing to do e.printStackTrace(); } }
From source file:com.jvms.i18neditor.editor.Editor.java
public void showRenameTranslationDialog(String key) { String newKey = ""; while (newKey != null && newKey.isEmpty()) { newKey = Dialogs.showInputDialog(this, MessageBundle.get("dialogs.translation.rename.title"), MessageBundle.get("dialogs.translation.rename.text"), JOptionPane.QUESTION_MESSAGE, key, true); if (newKey != null) { if (!ResourceKeys.isValid(newKey)) { showError(MessageBundle.get("dialogs.translation.rename.error")); } else { TranslationTreeNode newNode = translationTree.getNodeByKey(newKey); TranslationTreeNode oldNode = translationTree.getNodeByKey(key); if (newNode != null) { boolean isReplace = newNode.isLeaf() || oldNode.isLeaf(); boolean confirm = Dialogs.showConfirmDialog(this, MessageBundle.get("dialogs.translation.conflict.title"), MessageBundle.get( "dialogs.translation.conflict.text." + (isReplace ? "replace" : "merge")), JOptionPane.WARNING_MESSAGE); if (confirm) { renameTranslationKey(key, newKey); }/*from w w w. j a v a2 s . c om*/ } else { renameTranslationKey(key, newKey); } } } } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java
/** * @param args/*from w w w.j a va 2 s . c o m*/ */ public static void main(String[] args) { log.debug("********* Current [" + (new File(".").getAbsolutePath()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // This is for Windows and Exe4J, turn the args into System Properties for (String s : args) { String[] pairs = s.split("="); //$NON-NLS-1$ if (pairs.length == 2) { log.debug("[" + pairs[0] + "][" + pairs[1] + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (pairs[0].startsWith("-D")) //$NON-NLS-1$ { System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]); } } } // Now check the System Properties String appDir = System.getProperty("appdir"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(appDir)) { UIRegistry.setDefaultWorkingPath(appDir); } String appdatadir = System.getProperty("appdatadir"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(appdatadir)) { UIRegistry.setBaseAppDataDir(appdatadir); } SwingUtilities.invokeLater(new Runnable() { public void run() { // Set App Name, MUST be done very first thing! UIRegistry.setAppName("Specify"); //$NON-NLS-1$ // Then set this IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ try { UIHelper.OSTYPE osType = UIHelper.getOSType(); if (osType == UIHelper.OSTYPE.Windows) { //UIManager.setLookAndFeel(new WindowsLookAndFeel()); UIManager.setLookAndFeel(new PlasticLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); } else if (osType == UIHelper.OSTYPE.Linux) { //UIManager.setLookAndFeel(new GTKLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new SkyKrupp()); //PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); //PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); //PlasticLookAndFeel.setPlasticTheme(new ExperienceRoyale()); UIManager.setLookAndFeel(new PlasticLookAndFeel()); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerFrame.class, e); e.printStackTrace(); } AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.setDirPath(UIRegistry.getAppDataDir()); //Specify.adjustLocaleFromPrefs(); System.setProperty(AppContextMgr.factoryName, "edu.ku.brc.specify.config.SpecifyAppContextMgr"); // Needed by AppContextMgr //$NON-NLS-1$ System.setProperty(SchemaI18NService.factoryName, "edu.ku.brc.specify.config.SpecifySchemaI18NService"); // Needed for Localization and Schema //$NON-NLS-1$ System.setProperty(UIFieldFormatterMgr.factoryName, "edu.ku.brc.specify.ui.SpecifyUIFieldFormatterMgr"); // Needed for CatalogNumbering //$NON-NLS-1$ System.setProperty(WebLinkMgr.factoryName, "edu.ku.brc.specify.config.SpecifyWebLinkMgr"); // Needed for WebLnkButton //$NON-NLS-1$ System.setProperty(DataObjFieldFormatMgr.factoryName, "edu.ku.brc.specify.config.SpecifyDataObjFieldFormatMgr"); // Needed for WebLnkButton //$NON-NLS-1$ SpecifyDataObjFieldFormatMgr.setDoingLocal(true); SpecifyUIFieldFormatterMgr.setDoingLocal(true); SpecifyWebLinkMgr.setDoingLocal(true); Object[] options = { getResourceString("SchemaLocalizerFrame.FULL_SCHEMA"), //$NON-NLS-1$ getResourceString("SchemaLocalizerFrame.WB_SCHEMA") }; //$NON-NLS-1$ int retVal = JOptionPane.showOptionDialog(null, getResourceString("SchemaLocalizerFrame.WHICH_SCHEMA"), //$NON-NLS-1$ getResourceString("SchemaLocalizerFrame.CHOOSE_SCHEMA"), JOptionPane.YES_NO_CANCEL_OPTION, //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE, null, options, options[0]); SchemaLocalizerFrame sla; if (retVal == JOptionPane.NO_OPTION) { DBTableIdMgr schema = new DBTableIdMgr(false); schema.initialize(new File(XMLHelper.getConfigDirPath("specify_workbench_datamodel.xml"))); //$NON-NLS-1$ sla = new SchemaLocalizerFrame(SpLocaleContainer.WORKBENCH_SCHEMA, schema); } else { sla = new SchemaLocalizerFrame(SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance()); } AppContextMgr.getInstance().setHasContext(true); sla.createDisplay(); sla.pack(); Dimension size = sla.getSize(); size.width += 250; sla.setSize(size); UIHelper.centerAndShow(sla); final SchemaLocalizerFrame slaf = sla; slaf.setDefaultCloseOperation(EXIT_ON_CLOSE); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { slaf.chooseCurrentLocale(); } }); } }); }
From source file:gdt.jgui.entity.JEntityFacetPanel.java
private void removeFacets() { try {/* w w w. j ava 2s .co m*/ // System.out.println("EntityFacetPanel:removeFacets:BEGIN"); JItemPanel[] ipa = getItems(); if (ipa == null) return; ArrayList<JFacetOpenItem> foil = new ArrayList<JFacetOpenItem>(); for (JItemPanel aIpa : ipa) { if (aIpa.isChecked()) { if (((JFacetOpenItem) aIpa).isRemovable()) foil.add((JFacetOpenItem) aIpa); else aIpa.setChecked(false); } } JFacetOpenItem[] foia = foil.toArray(new JFacetOpenItem[0]); if (foia.length < 1) return; int response = JOptionPane.showConfirmDialog(this, "Delete selected facets ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response != JOptionPane.YES_OPTION) return; for (JFacetOpenItem foi : foia) foi.removeFacet(); console.putContext(instantiate(console, this.locator$), this.locator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } }