List of usage examples for javax.swing JFileChooser setSelectedFile
@BeanProperty(preferred = true) public void setSelectedFile(File file)
From source file:jboost.visualization.HistogramFrame.java
private File selectDumpFile() { File fFile = new File("ExamplesDumpFile.txt"); JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(new FileFilter() { public boolean accept(File f) { String path = f.getAbsolutePath(); if (f.isDirectory() || path.endsWith(".txt")) return true; else/* w w w. j a v a 2s.c om*/ return false; } public String getDescription() { return "Text Files"; } }); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return null; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "Overwrite existing file?", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) return null; } return fFile; } else { return null; } }
From source file:com.opendoorlogistics.studio.AppFrame.java
@SuppressWarnings("serial") private List<MyAction> initFileActions() { ArrayList<MyAction> ret = new ArrayList<>(); ret.add(new MyAction("New", "Create new file", null, "document-new-6.png", false, KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK)) { @Override/* w ww . j a v a 2s.c o m*/ public void actionPerformed(ActionEvent e) { createNewDatastore(); } }); ret.add(new MyAction("Open", "Open file", null, "document-open-3.png", false, KeyStroke.getKeyStroke(KeyEvent.VK_O, java.awt.Event.CTRL_MASK)) { @Override public void actionPerformed(ActionEvent e) { openDatastoreWithUserPrompt(); } }); ret.add(null); ret.add(new MyAction("Close", "Close file", null, "document-close-4.png", true, KeyStroke.getKeyStroke(KeyEvent.VK_W, java.awt.Event.CTRL_MASK)) { @Override public void actionPerformed(ActionEvent e) { if (!canCloseDatastore()) { return; } closeDatastore(); } }); ret.add(null); ret.add(new MyAction("Save", "Save file", null, "document-save-2.png", true, KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)) { @Override public void actionPerformed(ActionEvent e) { saveDatastoreWithoutUserPrompt(loaded.getLastFile()); } @Override public void updateEnabled() { setEnabled(loaded != null && loaded.getLastFile() != null); } }); ret.add(new MyAction("Save as", "Save file as", null, "document-save-as-2.png", true, KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK | Event.ALT_MASK)) { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = SupportedFileType.EXCEL.createFileChooser(); if (loaded.getLastFile() != null) { chooser.setSelectedFile(loaded.getLastFile()); } else { File file = PreferencesManager.getSingleton().getFile(PrefKey.LAST_IO_DIR); IOUtils.setFile(file, chooser); } if (chooser.showSaveDialog(AppFrame.this) == JFileChooser.APPROVE_OPTION) { saveDatastoreWithoutUserPrompt(chooser.getSelectedFile()); } } }); return ret; }
From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java
private File loadFileChooser(javax.swing.filechooser.FileFilter ff, String saveName) { File result;/* w ww . j av a 2s. co m*/ JFileChooser fc = new JFileChooser(); //Create a file chooser fc.setMultiSelectionEnabled(false); if (ff != null) { fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(ff); } else { fc.setAcceptAllFileFilterUsed(true); } if (saveName == null) { fc.setDialogTitle(""); if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); } else { result = null; } } else { fc.setDialogTitle("Save As..."); fc.setSelectedFile(new File(saveName)); if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); } else { result = null; } } return result; }
From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java
private File showSaveDialog(final JFileChooser fc, final File file, final String extension) { fc.setSelectedFile(file); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); if (!FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase(extension)) { selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + "." + extension); }/*w ww . j a v a 2 s .c o m*/ if (selectedFile.exists()) { String msg = String.format("The file '%s' already exists. Overwrite?", selectedFile); switch (JOptionPane.showConfirmDialog(this, msg)) { case JOptionPane.YES_OPTION: return selectedFile; case JOptionPane.NO_OPTION: return showSaveDialog(fc, file, extension); default: return null; } } return selectedFile; } return null; }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
private File loadFileChooser(boolean dir, FileFilter filter, String text) { File result = null;// w w w .j a v a 2s .c o m JFileChooser fc = new JFileChooser(); //Create a file chooser disableNewFolderButton(fc); if (text != null) { fc.setSelectedFile(new File(text)); } if (dir) { fc.setDialogTitle(""); File lastDir = new File( Preferences.userRoot().get("lastDir", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastDir); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); jTextField1.setText(result.getAbsolutePath()); Preferences.userRoot().put("lastDir", result.getParentFile().getAbsolutePath()); } } else { File lastSaved = null; File lastSelected = null; if (filter != null) { fc.setDialogTitle("Save As..."); lastSaved = new File( Preferences.userRoot().get("lastSaved", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSaved); fc.setFileFilter(filter); } else { fc.setDialogTitle(""); lastSelected = new File( Preferences.userRoot().get("lastSelected", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSelected); fc.setAcceptAllFileFilterUsed(true); } if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); if (lastSaved != null) { Preferences.userRoot().put("lastSaved", result.getParentFile().getAbsolutePath()); } if (lastSelected != null) { Preferences.userRoot().put("lastSelected", result.getParentFile().getAbsolutePath()); } } } return result; }
From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java
private void initFrame() { frame = new JFrame(); frame.setTitle("libautocaptcha vodafone.it tool"); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tabbedPane = new JTabbedPane(JTabbedPane.TOP); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); JPanel setupPanel = new JPanel(); FlowLayout flowLayout = (FlowLayout) setupPanel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Setup", null, setupPanel, null); JPanel setupFormPanel = new JPanel(); setupPanel.add(setupFormPanel);// w w w . jav a 2 s .co m GridBagLayout gbl_setupFormPanel = new GridBagLayout(); gbl_setupFormPanel.columnWidths = new int[] { 150, 250 }; gbl_setupFormPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_setupFormPanel.columnWeights = new double[] { 0.0, 1.0 }; gbl_setupFormPanel.rowWeights = new double[] { 0.0, 0.0, 0.0 }; setupFormPanel.setLayout(gbl_setupFormPanel); JLabel usernameLabel = new JLabel("Username"); GridBagConstraints gbc_usernameLabel = new GridBagConstraints(); gbc_usernameLabel.anchor = GridBagConstraints.WEST; gbc_usernameLabel.fill = GridBagConstraints.VERTICAL; gbc_usernameLabel.insets = new Insets(0, 0, 5, 5); gbc_usernameLabel.gridx = 0; gbc_usernameLabel.gridy = 0; setupFormPanel.add(usernameLabel, gbc_usernameLabel); usernameField = new JTextField(); GridBagConstraints gbc_usernameField = new GridBagConstraints(); gbc_usernameField.fill = GridBagConstraints.BOTH; gbc_usernameField.insets = new Insets(0, 0, 5, 0); gbc_usernameField.gridx = 1; gbc_usernameField.gridy = 0; setupFormPanel.add(usernameField, gbc_usernameField); usernameField.setColumns(10); JLabel passwordLabel = new JLabel("Password"); GridBagConstraints gbc_passwordLabel = new GridBagConstraints(); gbc_passwordLabel.anchor = GridBagConstraints.WEST; gbc_passwordLabel.fill = GridBagConstraints.VERTICAL; gbc_passwordLabel.insets = new Insets(0, 0, 5, 5); gbc_passwordLabel.gridx = 0; gbc_passwordLabel.gridy = 1; setupFormPanel.add(passwordLabel, gbc_passwordLabel); passwordField = new JPasswordField(); GridBagConstraints gbc_passwordField = new GridBagConstraints(); gbc_passwordField.fill = GridBagConstraints.BOTH; gbc_passwordField.insets = new Insets(0, 0, 5, 0); gbc_passwordField.gridx = 1; gbc_passwordField.gridy = 1; setupFormPanel.add(passwordField, gbc_passwordField); passwordField.setColumns(10); JLabel receiverLabel = new JLabel("Mobile number"); GridBagConstraints gbc_receiverLabel = new GridBagConstraints(); gbc_receiverLabel.fill = GridBagConstraints.VERTICAL; gbc_receiverLabel.anchor = GridBagConstraints.WEST; gbc_receiverLabel.insets = new Insets(0, 0, 5, 5); gbc_receiverLabel.gridx = 0; gbc_receiverLabel.gridy = 2; setupFormPanel.add(receiverLabel, gbc_receiverLabel); receiverField = new JTextField(); GridBagConstraints gbc_receiverField = new GridBagConstraints(); gbc_receiverField.insets = new Insets(0, 0, 5, 0); gbc_receiverField.fill = GridBagConstraints.BOTH; gbc_receiverField.gridx = 1; gbc_receiverField.gridy = 2; setupFormPanel.add(receiverField, gbc_receiverField); receiverField.setColumns(10); JPanel backgroundPanel = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) backgroundPanel.getLayout(); flowLayout_1.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Background", null, backgroundPanel, null); JPanel backgroundFormPanel = new JPanel(); backgroundPanel.add(backgroundFormPanel); GridBagLayout gbl_backgroundFormPanel = new GridBagLayout(); gbl_backgroundFormPanel.columnWidths = new int[] { 150, 50, 100, 0 }; gbl_backgroundFormPanel.rowHeights = new int[] { 0, 25, 0 }; gbl_backgroundFormPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_backgroundFormPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; backgroundFormPanel.setLayout(gbl_backgroundFormPanel); JLabel numberLabel = new JLabel("Number of CAPTCHAs"); GridBagConstraints gbc_numberLabel = new GridBagConstraints(); gbc_numberLabel.anchor = GridBagConstraints.WEST; gbc_numberLabel.insets = new Insets(0, 0, 5, 5); gbc_numberLabel.gridx = 0; gbc_numberLabel.gridy = 0; backgroundFormPanel.add(numberLabel, gbc_numberLabel); numberField = new JTextField(); numberField.setText("5"); GridBagConstraints gbc_numberField = new GridBagConstraints(); gbc_numberField.anchor = GridBagConstraints.WEST; gbc_numberField.insets = new Insets(0, 0, 5, 5); gbc_numberField.gridx = 1; gbc_numberField.gridy = 0; backgroundFormPanel.add(numberField, gbc_numberField); numberField.setColumns(3); JButton numberButton = new JButton("Download"); numberButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int counter = 0; do { BufferedImage captcha = downloadCAPTCHA(); if (captcha != null) { try { int number = new File(tempFolder.getAbsolutePath()).listFiles().length; File file = new File(tempFolder.getAbsolutePath() + "/background_" + number + ".png"); ImageIO.write(captcha, "png", file); Thread.sleep(2500); } catch (Exception x) { x.printStackTrace(); } } } while (++counter < Integer.valueOf(numberField.getText())); Image background = loadBackground(); if (background != null) { backgroundImage.setIcon(new ImageIcon(background)); } } }); GridBagConstraints gbc_numberButton = new GridBagConstraints(); gbc_numberButton.anchor = GridBagConstraints.NORTHWEST; gbc_numberButton.insets = new Insets(0, 0, 5, 0); gbc_numberButton.gridx = 2; gbc_numberButton.gridy = 0; backgroundFormPanel.add(numberButton, gbc_numberButton); JLabel backgroundLabel = new JLabel("Current background"); GridBagConstraints gbc_backgroundLabel = new GridBagConstraints(); gbc_backgroundLabel.anchor = GridBagConstraints.WEST; gbc_backgroundLabel.insets = new Insets(0, 0, 0, 5); gbc_backgroundLabel.gridx = 0; gbc_backgroundLabel.gridy = 1; backgroundFormPanel.add(backgroundLabel, gbc_backgroundLabel); backgroundImage = new JLabel(""); GridBagConstraints gbc_backgroundImage = new GridBagConstraints(); gbc_backgroundImage.anchor = GridBagConstraints.WEST; gbc_backgroundImage.gridwidth = 2; gbc_backgroundImage.insets = new Insets(0, 0, 0, 5); gbc_backgroundImage.gridx = 1; gbc_backgroundImage.gridy = 1; backgroundFormPanel.add(backgroundImage, gbc_backgroundImage); JPanel trainingPanel = new JPanel(); tabbedPane.addTab("Training", null, trainingPanel, null); GridBagLayout gbl_trainingPanel = new GridBagLayout(); gbl_trainingPanel.columnWidths = new int[] { 437, 0 }; gbl_trainingPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_trainingPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_trainingPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; trainingPanel.setLayout(gbl_trainingPanel); trainingLoadPanel = new JPanel(); GridBagConstraints gbc_trainingLoadPanel = new GridBagConstraints(); gbc_trainingLoadPanel.anchor = GridBagConstraints.NORTHWEST; gbc_trainingLoadPanel.insets = new Insets(0, 0, 5, 0); gbc_trainingLoadPanel.gridx = 0; gbc_trainingLoadPanel.gridy = 0; trainingPanel.add(trainingLoadPanel, gbc_trainingLoadPanel); trainingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JButton trainingLoadButton = new JButton("Download"); trainingLoadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trainingCaptcha = downloadCAPTCHA(); if (trainingCaptcha != null) { trainingCaptchaImage.setIcon(new ImageIcon(trainingCaptcha)); List<Image> glyphs = loadGlyphs(trainingCaptcha); for (int g = 0; g < 5; ++g) { trainingGlyphImage[g].setIcon(null); trainingGlyphField[g].setText(""); } for (int g = 0; g < glyphs.size() && g < 5; ++g) { trainingGlyph[g] = glyphs.get(g); trainingGlyphImage[g].setIcon(new ImageIcon(trainingGlyph[g])); } trainingLoadPanel.invalidate(); trainingSavePanel.invalidate(); } } }); trainingLoadPanel.add(trainingLoadButton); trainingCaptchaImage = new JLabel(""); trainingLoadPanel.add(trainingCaptchaImage); trainingSavePanel = new JPanel(); GridBagConstraints gbc_trainingSavePanel = new GridBagConstraints(); gbc_trainingSavePanel.insets = new Insets(0, 5, 0, 0); gbc_trainingSavePanel.anchor = GridBagConstraints.NORTHWEST; gbc_trainingSavePanel.gridx = 0; gbc_trainingSavePanel.gridy = 1; trainingPanel.add(trainingSavePanel, gbc_trainingSavePanel); GridBagLayout gbl_trainingSavePanel = new GridBagLayout(); gbl_trainingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 }; gbl_trainingSavePanel.rowHeights = new int[] { 25, 0, 0 }; gbl_trainingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_trainingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; trainingSavePanel.setLayout(gbl_trainingSavePanel); trainingGlyph = new Image[5]; trainingGlyphImage = new JLabel[5]; trainingGlyphField = new JTextField[5]; trainingGlyphImage[0] = new JLabel(""); GridBagConstraints gbc_glyphImage0 = new GridBagConstraints(); gbc_glyphImage0.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage0.insets = new Insets(0, 0, 5, 5); gbc_glyphImage0.gridx = 0; gbc_glyphImage0.gridy = 0; trainingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[0], gbc_glyphImage0); trainingGlyphImage[1] = new JLabel(""); GridBagConstraints gbc_glyphImage1 = new GridBagConstraints(); gbc_glyphImage1.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage1.insets = new Insets(0, 0, 5, 5); gbc_glyphImage1.gridx = 1; gbc_glyphImage1.gridy = 0; trainingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[1], gbc_glyphImage1); trainingGlyphImage[2] = new JLabel(""); GridBagConstraints gbc_glyphImage2 = new GridBagConstraints(); gbc_glyphImage2.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage2.insets = new Insets(0, 0, 5, 5); gbc_glyphImage2.gridx = 2; gbc_glyphImage2.gridy = 0; trainingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[2], gbc_glyphImage2); trainingGlyphImage[3] = new JLabel(""); GridBagConstraints gbc_glyphImage3 = new GridBagConstraints(); gbc_glyphImage3.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage3.insets = new Insets(0, 0, 5, 5); gbc_glyphImage3.gridx = 3; gbc_glyphImage3.gridy = 0; trainingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[3], gbc_glyphImage3); trainingGlyphImage[4] = new JLabel(""); GridBagConstraints gbc_glyphImage4 = new GridBagConstraints(); gbc_glyphImage4.insets = new Insets(0, 0, 5, 5); gbc_glyphImage4.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage4.gridx = 4; gbc_glyphImage4.gridy = 0; trainingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[4], gbc_glyphImage4); JButton trainingSaveButton = new JButton("Train"); trainingSaveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int g = 0; g < 5; ++g) { String s = trainingGlyphField[g].getText(); if (s.length() == 1) { char c = Character.toUpperCase(s.charAt(0)); net.sourceforge.javaocr.Image glyph = convertImage(trainingGlyph[g]); grayFilter.process(glyph); ThresholdFilter thresholdFilter = new ThresholdFilter(0, FG, BG); thresholdFilter.process(glyph); train(glyph, c); } trainingGlyphField[g].setText(""); } for (Map.Entry<Character, Cluster> m : clusters.entrySet()) { System.out.println("****************************************"); System.out.print(" character: "); // int samples = ((EuclidianDistanceCluster) m.getValue()).getAmountSamples(); int samples = ((SigmaWeightedEuclidianDistanceCluster) m.getValue()).getAmountSamples(); for (int s = 0; s < samples; ++s) System.out.print(m.getKey()); System.out.println(); double[] c = m.getValue().center(); for (int i = 0; i < c.length; ++i) System.out.println(" centroid[" + i + "]: " + c[i]); } System.out.println("****************************************"); System.out.println("TOTAL CLUSTERS: " + clusters.size()); } }); GridBagConstraints gbc_trainingSaveButton = new GridBagConstraints(); gbc_trainingSaveButton.gridheight = 2; gbc_trainingSaveButton.insets = new Insets(0, 0, 5, 0); gbc_trainingSaveButton.gridx = 5; gbc_trainingSaveButton.gridy = 0; trainingSavePanel.add(trainingSaveButton, gbc_trainingSaveButton); trainingGlyphField[0] = new JTextField(); GridBagConstraints gbc_glyphField0 = new GridBagConstraints(); gbc_glyphField0.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField0.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField0.insets = new Insets(0, 0, 0, 5); gbc_glyphField0.gridx = 0; gbc_glyphField0.gridy = 1; trainingSavePanel.add(trainingGlyphField[0], gbc_glyphField0); trainingGlyphField[0].setColumns(2); trainingGlyphField[1] = new JTextField(); GridBagConstraints gbc_glyphField1 = new GridBagConstraints(); gbc_glyphField1.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField1.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField1.insets = new Insets(0, 0, 0, 5); gbc_glyphField1.gridx = 1; gbc_glyphField1.gridy = 1; trainingSavePanel.add(trainingGlyphField[1], gbc_glyphField1); trainingGlyphField[1].setColumns(2); trainingGlyphField[2] = new JTextField(); GridBagConstraints gbc_glyphField2 = new GridBagConstraints(); gbc_glyphField2.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField2.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField2.insets = new Insets(0, 0, 0, 5); gbc_glyphField2.gridx = 2; gbc_glyphField2.gridy = 1; trainingSavePanel.add(trainingGlyphField[2], gbc_glyphField2); trainingGlyphField[2].setColumns(2); trainingGlyphField[3] = new JTextField(); GridBagConstraints gbc_glyphField3 = new GridBagConstraints(); gbc_glyphField3.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField3.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField3.insets = new Insets(0, 0, 0, 5); gbc_glyphField3.gridx = 3; gbc_glyphField3.gridy = 1; trainingSavePanel.add(trainingGlyphField[3], gbc_glyphField3); trainingGlyphField[3].setColumns(2); trainingGlyphField[4] = new JTextField(); GridBagConstraints gbc_glyphField4 = new GridBagConstraints(); gbc_glyphField4.insets = new Insets(0, 0, 0, 5); gbc_glyphField4.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField4.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField4.gridx = 4; gbc_glyphField4.gridy = 1; trainingSavePanel.add(trainingGlyphField[4], gbc_glyphField4); trainingGlyphField[4].setColumns(2); JPanel testingPanel = new JPanel(); tabbedPane.addTab("Testing", null, testingPanel, null); GridBagLayout gbl_testingPanel = new GridBagLayout(); gbl_testingPanel.columnWidths = new int[] { 437, 0 }; gbl_testingPanel.rowHeights = new int[] { 0, 0, 0, 0 }; gbl_testingPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_testingPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE }; testingPanel.setLayout(gbl_testingPanel); testingLoadPanel = new JPanel(); GridBagConstraints gbc_testingLoadPanel = new GridBagConstraints(); gbc_testingLoadPanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingLoadPanel.insets = new Insets(0, 0, 5, 0); gbc_testingLoadPanel.gridx = 0; gbc_testingLoadPanel.gridy = 0; testingPanel.add(testingLoadPanel, gbc_testingLoadPanel); testingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JButton testingLoadButton = new JButton("Download"); testingLoadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { testingCaptcha = downloadCAPTCHA(); if (testingCaptcha != null) { testingCaptchaImage.setIcon(new ImageIcon(testingCaptcha)); List<Image> glyphs = loadGlyphs(testingCaptcha); for (int g = 0; g < 5; ++g) { testingGlyphImage[g].setIcon(null); testingGlyphField[g].setText(""); } for (int g = 0; g < glyphs.size() && g < 5; ++g) { testingGlyph[g] = glyphs.get(g); testingGlyphImage[g].setIcon(new ImageIcon(testingGlyph[g])); } testingLoadPanel.invalidate(); testingSavePanel.invalidate(); } } }); testingLoadPanel.add(testingLoadButton); testingCaptchaImage = new JLabel(""); testingLoadPanel.add(testingCaptchaImage); testingSavePanel = new JPanel(); GridBagConstraints gbc_testingSavePanel = new GridBagConstraints(); gbc_testingSavePanel.insets = new Insets(0, 5, 5, 0); gbc_testingSavePanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingSavePanel.gridx = 0; gbc_testingSavePanel.gridy = 1; testingPanel.add(testingSavePanel, gbc_testingSavePanel); GridBagLayout gbl_testingSavePanel = new GridBagLayout(); gbl_testingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 }; gbl_testingSavePanel.rowHeights = new int[] { 25, 0, 0 }; gbl_testingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_testingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; testingSavePanel.setLayout(gbl_testingSavePanel); testingGlyph = new Image[5]; testingGlyphImage = new JLabel[5]; testingGlyphField = new JTextField[5]; testingGlyphImage[0] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage0 = new GridBagConstraints(); gbc_testingGlyphImage0.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage0.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage0.gridx = 0; gbc_testingGlyphImage0.gridy = 0; testingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[0], gbc_testingGlyphImage0); testingGlyphImage[1] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage1 = new GridBagConstraints(); gbc_testingGlyphImage1.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage1.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage1.gridx = 1; gbc_testingGlyphImage1.gridy = 0; testingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[1], gbc_testingGlyphImage1); testingGlyphImage[2] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage2 = new GridBagConstraints(); gbc_testingGlyphImage2.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage2.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage2.gridx = 2; gbc_testingGlyphImage2.gridy = 0; testingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[2], gbc_testingGlyphImage2); testingGlyphImage[3] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage3 = new GridBagConstraints(); gbc_testingGlyphImage3.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage3.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage3.gridx = 3; gbc_testingGlyphImage3.gridy = 0; testingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[3], gbc_testingGlyphImage3); testingGlyphImage[4] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage4 = new GridBagConstraints(); gbc_testingGlyphImage4.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage4.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage4.gridx = 4; gbc_testingGlyphImage4.gridy = 0; testingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[4], gbc_testingGlyphImage4); JButton testingSaveButton = new JButton("Save and test"); testingSaveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = ""; for (int g = 0; g < 5; ++g) { String s = testingGlyphField[g].getText(); if (s.length() == 1) text += s.toUpperCase(); trainingGlyphField[g].setText(""); } if (text.length() != 5) return; try { File file = new File(tempFolder.getAbsolutePath() + "/captcha_" + text + ".png"); ImageIO.write(testingCaptcha, "png", file); } catch (IOException x) { x.printStackTrace(); } testingViewArea.setText(loadStatistics()); } }); GridBagConstraints gbc_testingSaveButton = new GridBagConstraints(); gbc_testingSaveButton.gridheight = 2; gbc_testingSaveButton.insets = new Insets(0, 0, 5, 0); gbc_testingSaveButton.gridx = 5; gbc_testingSaveButton.gridy = 0; testingSavePanel.add(testingSaveButton, gbc_testingSaveButton); testingGlyphField[0] = new JTextField(); GridBagConstraints gbc_testingGlyphField0 = new GridBagConstraints(); gbc_testingGlyphField0.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField0.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField0.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField0.gridx = 0; gbc_testingGlyphField0.gridy = 1; testingSavePanel.add(testingGlyphField[0], gbc_testingGlyphField0); testingGlyphField[0].setColumns(2); testingGlyphField[1] = new JTextField(); GridBagConstraints gbc_testingGlyphField1 = new GridBagConstraints(); gbc_testingGlyphField1.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField1.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField1.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField1.gridx = 1; gbc_testingGlyphField1.gridy = 1; testingSavePanel.add(testingGlyphField[1], gbc_testingGlyphField1); testingGlyphField[1].setColumns(2); testingGlyphField[2] = new JTextField(); GridBagConstraints gbc_testingGlyphField2 = new GridBagConstraints(); gbc_testingGlyphField2.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField2.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField2.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField2.gridx = 2; gbc_testingGlyphField2.gridy = 1; testingSavePanel.add(testingGlyphField[2], gbc_testingGlyphField2); testingGlyphField[2].setColumns(2); testingGlyphField[3] = new JTextField(); GridBagConstraints gbc_testingGlyphField3 = new GridBagConstraints(); gbc_testingGlyphField3.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField3.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField3.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField3.gridx = 3; gbc_testingGlyphField3.gridy = 1; testingSavePanel.add(testingGlyphField[3], gbc_testingGlyphField3); testingGlyphField[3].setColumns(2); testingGlyphField[4] = new JTextField(); GridBagConstraints gbc_testingGlyphField4 = new GridBagConstraints(); gbc_testingGlyphField4.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField4.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField4.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField4.gridx = 4; gbc_testingGlyphField4.gridy = 1; testingSavePanel.add(testingGlyphField[4], gbc_testingGlyphField4); JPanel testingViewPanel = new JPanel(); GridBagConstraints gbc_testingViewPanel = new GridBagConstraints(); gbc_testingViewPanel.fill = GridBagConstraints.HORIZONTAL; gbc_testingViewPanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingViewPanel.gridx = 0; gbc_testingViewPanel.gridy = 2; testingPanel.add(testingViewPanel, gbc_testingViewPanel); GridBagLayout gbl_testingViewPanel = new GridBagLayout(); gbl_testingViewPanel.columnWidths = new int[] { 330, 0 }; gbl_testingViewPanel.rowHeights = new int[] { 75, 0 }; gbl_testingViewPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_testingViewPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; testingViewPanel.setLayout(gbl_testingViewPanel); testingViewArea = new JTextArea(); testingViewArea.setRows(5); testingViewArea.setColumns(30); GridBagConstraints gbc_testingViewArea = new GridBagConstraints(); gbc_testingViewArea.fill = GridBagConstraints.BOTH; gbc_testingViewArea.anchor = GridBagConstraints.NORTHWEST; gbc_testingViewArea.gridx = 0; gbc_testingViewArea.gridy = 0; testingViewPanel.add(testingViewArea, gbc_testingViewArea); testingGlyphField[4].setColumns(2); JPanel outputPanel = new JPanel(); FlowLayout flowLayout2 = (FlowLayout) outputPanel.getLayout(); flowLayout2.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Output", null, outputPanel, null); JPanel outputFormPanel = new JPanel(); outputPanel.add(outputFormPanel); GridBagLayout gbl_outputFormPanel = new GridBagLayout(); gbl_outputFormPanel.columnWidths = new int[] { 150, 250 }; gbl_outputFormPanel.rowHeights = new int[] { 0 }; gbl_outputFormPanel.columnWeights = new double[] { 0.0, 1.0 }; gbl_outputFormPanel.rowWeights = new double[] { 0.0 }; outputFormPanel.setLayout(gbl_outputFormPanel); JLabel javaLabel = new JLabel("Output .java file"); GridBagConstraints gbc_javaLabel = new GridBagConstraints(); gbc_javaLabel.anchor = GridBagConstraints.WEST; gbc_javaLabel.fill = GridBagConstraints.VERTICAL; gbc_javaLabel.insets = new Insets(0, 0, 5, 5); gbc_javaLabel.gridx = 0; gbc_javaLabel.gridy = 0; outputFormPanel.add(javaLabel, gbc_javaLabel); javaField = new JTextField(); javaField.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { javaField.removeFocusListener(this); } public void focusGained(FocusEvent e) { JFileChooser chooser = new JFileChooser(outFolderName); chooser.setSelectedFile(new File(outFileName)); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showDialog(frame, "Save .java file") == JFileChooser.APPROVE_OPTION) { javaField.setText(chooser.getSelectedFile().getAbsolutePath()); try { PrintWriter output = new PrintWriter( new FileWriter(chooser.getSelectedFile().getAbsolutePath())); output.println("package com.googlecode.libautocaptcha.decoder.data;"); output.println("import net.sourceforge.javaocr.plugin.cluster.Cluster;"); output.println("import net.sourceforge.javaocr.plugin.cluster.MahalanobisDistanceCluster;"); output.println("public class VodafoneItalyData {"); output.println(" public static final int[] " + BACKGROUND_FIELD + " = "); output.print(" new int[] { "); for (int y = 0; y < HEIGHT; ++y) for (int x = 0; x < WIDTH; ++x) output.print(background.get(x, y) + ", "); output.println("};"); output.println(" public static final char[] " + CHARACTERS_FIELD + " = "); output.print(" new char[] { "); for (Character c : clusters.keySet()) output.print("'" + c + "', "); output.println("};"); output.println(" public static final Cluster[] " + CLUSTERS_FIELD + " = "); output.print(" new MahalanobisDistanceCluster[] { "); for (Cluster c : clusters.values()) { output.print("new MahalanobisDistanceCluster(new double[] { "); double[] mx = ((MahalanobisDistanceCluster) c).getMx(); for (double i : mx) output.print(i + ", "); output.print("}, new double[][] { "); double[][] invcov = ((MahalanobisDistanceCluster) c).getInvcov(); for (double[] row : invcov) { output.print("new double[] { "); for (double i : row) output.print(i + ", "); output.print("}, "); } output.print("}), "); } output.println("};"); output.println("}"); output.close(); } catch (IOException x) { x.printStackTrace(); } } } }); GridBagConstraints gbc_javaField = new GridBagConstraints(); gbc_javaField.fill = GridBagConstraints.BOTH; gbc_javaField.insets = new Insets(0, 0, 5, 0); gbc_javaField.gridx = 1; gbc_javaField.gridy = 0; outputFormPanel.add(javaField, gbc_javaField); javaField.setColumns(10); JPanel statusPanel = new JPanel(); frame.getContentPane().add(statusPanel, BorderLayout.SOUTH); GridBagLayout gbl_statusPanel = new GridBagLayout(); gbl_statusPanel.columnWidths = new int[] { 150, 0, 0 }; gbl_statusPanel.rowHeights = new int[] { 14, 0 }; gbl_statusPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; gbl_statusPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; statusPanel.setLayout(gbl_statusPanel); statusBar = new JProgressBar(); GridBagConstraints gbc_statusBar = new GridBagConstraints(); gbc_statusBar.insets = new Insets(0, 0, 0, 5); gbc_statusBar.gridx = 0; gbc_statusBar.gridy = 0; statusPanel.add(statusBar, gbc_statusBar); statusLabel = new JLabel(""); GridBagConstraints gbc_statusLabel = new GridBagConstraints(); gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; gbc_statusLabel.gridx = 1; gbc_statusLabel.gridy = 0; statusPanel.add(statusLabel, gbc_statusLabel); }
From source file:AltiConsole.AltiConsoleMainScreen.java
public boolean SavingFlight() { JFileChooser saveFile = new JFileChooser(); String currentFligtName = null; if (Serial.MyFlight == null) { System.out.println("Serial.MyFlight is null "); return false; }//from w ww . j av a 2s. c om if (flightList == null) { System.out.println("flightList is null "); return false; } if (!flightList.isValid()) { System.out.println("flightList is invalid "); return false; } if (flightList.getComponentCount() > 0) { System.out.println("nbr of flight " + flightList.getComponentCount() + "\n"); System.out.println("flightname " + flightList.getSelectedValue().toString() + "\n"); currentFligtName = flightList.getSelectedValue().toString(); } else return false; saveFile.setSelectedFile(new File(flightList.getSelectedValue().toString() + ".csv")); if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File file = saveFile.getSelectedFile(); try { // get flight data XYSeriesCollection flightData = null; flightData = Serial.MyFlight.GetFlightData(flightList.getSelectedValue().toString()); int numberOfPoints; numberOfPoints = flightData.getSeries(0).getItemCount(); // Create file FileWriter fstream = new FileWriter(file.getName()); BufferedWriter out = new BufferedWriter(fstream); out.write("time, altitude\n"); int i; for (i = 0; i < numberOfPoints; i++) { long X, Y; X = flightData.getSeries(0).getX(i).longValue(); Y = flightData.getSeries(0).getY(i).longValue(); System.out.println(X + "," + Y + "\n"); out.write(X + "," + Y + "\n"); } // Close the output stream out.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } return true; }
From source file:it.isislab.dmason.tools.batch.BatchWizard.java
public File SaveFileChooser() { JFileChooser fileChooser = new JFileChooser(); // fileChooser.setCurrentDirectory(new File(FTP_HOME)); fileChooser.setSelectedFile( new File(FilenameUtils.removeExtension(simulationFile.getName()) + "_" + configFileName)); int n = fileChooser.showSaveDialog(BatchWizard.this); if (n == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFile(); } else//from w w w . j a va 2s . c om return null; }
From source file:musite.ui.MusiteResultPanel.java
private void exportComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportComboBoxActionPerformed String name = panelName.replaceAll("[\\\\/:\\*\\?\"<>\\|]+", "-"); String defaultFile = MusiteInit.defaultPath + File.separator + name; if (sliderTitleComboBox.getSelectedItem().equals(SPECIFICITY)) { defaultFile += String.format("-Sp_%.2f", specificity); } else {/*from ww w . j a v a 2 s . c o m*/ defaultFile += String.format("-Score_%.3f", threshold); } defaultFile += ".result"; switch (exportComboBox.getSelectedIndex()) { case 1: // tab-delimited text file { JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); fc.setSelectedFile(new File(defaultFile)); ArrayList<String> exts = new ArrayList<String>(1); String fasta = "txt"; exts.add(fasta); FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts, "Tab-delimited file (.txt)"); fc.addChoosableFileFilter(fastaFilter); //fc.setAcceptAllFileFilterUsed(true); fc.setDialogTitle("Save the the result to..."); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); MusiteInit.defaultPath = file.getParent(); String filePath = MusiteInit.defaultPath + File.separator + file.getName(); String ext = FilePathParser.getExt(filePath); if (ext == null || !ext.equalsIgnoreCase("txt")) { filePath += ".txt"; } if (IOUtil.fileExist(filePath)) { int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) break; } Vector<Vector> data = formatData(proteinList, false, true); int n = data.size(); ArrayList<String> dataOut = new ArrayList(n + 1); dataOut.add(StringUtils.join(header.iterator(), '\t')); for (Vector vec : data) { dataOut.add(StringUtils.join(vec.iterator(), '\t')); } try { IOUtil.writeCollectionAscii(dataOut, filePath); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error: failed to write the file."); break; } JOptionPane.showMessageDialog(this, "Successfully exported."); } break; } // case 2: // fasta // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String fasta = "fasta"; // exts.add(fasta); // FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts,"Fasta file (.fasta)"); // fc.addChoosableFileFilter(fastaFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("fasta")) { // filePath += ".fasta"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsWriter writer = new ModifiedProteinsFastaWriter(); // WriteTask writeTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(writeTask); // if (!writeTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } // case 3: // xml // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String xml = "xml"; // exts.add(xml); // FileExtensionsFilter xmlFilter = new FileExtensionsFilter(exts,"XML file (.xml)"); // fc.addChoosableFileFilter(xmlFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("xml")) { // filePath += ".xml"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsXMLWriter writer = ProteinsXMLWriter.createWriter(); // WriteTask xmlWriteTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(xmlWriteTask); // if (!xmlWriteTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } } exportComboBox.setSelectedIndex(0); }
From source file:musite.ui.MusiteResultPanel.java
public boolean saveResult(boolean showConfirm) { JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // TODO: windows reserverd String fileName = panelName.replaceAll("[" + StringUtil.toOct("|\\?*<\":>+[]/") + "]+", "_"); fc.setSelectedFile(new File(MusiteInit.defaultPath + File.separator + fileName + ".pred.xml.gz")); ArrayList<String> exts = new ArrayList<String>(2); exts.add("xml"); exts.add("xml.gz"); fc.addChoosableFileFilter(new FileExtensionsFilter(exts, "Prediction XML file (.xml, .xml.gz)")); exts = new ArrayList<String>(2); exts.add("pred.xml"); exts.add("pred.xml.gz"); fc.addChoosableFileFilter(new FileExtensionsFilter(exts, "Prediction result file (pred.xml, pred.xml.gz)")); //fc.setAcceptAllFileFilterUsed(true); fc.setDialogTitle("Save the the result to..."); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); MusiteInit.defaultPath = file.getParent(); String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // if (!filePath.toLowerCase().endsWith(".xml")&&!filePath.toLowerCase().endsWith(".xml.gz")) { // filePath += ".pred.xml.gz"; // } if (IOUtil.fileExist(filePath)) { int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) return false; }//from ww w. j ava 2 s . c o m PredictionResultXMLWriter writer = PredictionResultXMLWriter.createWriter(); WriteTask task = new WriteTask(result, writer, filePath); TaskUtil.execute(task); if (task.success()) { if (showConfirm) JOptionPane.showMessageDialog(this, "Result saved!"); saved = true; return true; } else { JOptionPane.showMessageDialog(this, "Failed to save the result."); return false; } } else { return false; } }