List of usage examples for javax.swing JFileChooser showDialog
@SuppressWarnings("deprecation") public int showDialog(Component parent, String approveButtonText) throws HeadlessException
From source file:de.juwimm.cms.content.panel.PanDocuments.java
private void upload(String prosa, Integer unit, Integer viewComponentId, Integer documentId) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser fc = new JFileChooser(); int ff = fc.getChoosableFileFilters().length; FileFilter[] fft = fc.getChoosableFileFilters(); for (int i = 0; i < ff; i++) { fc.removeChoosableFileFilter(fft[i]); }// w w w . java2 s . c om fc.addChoosableFileFilter(new DocumentFilter()); fc.setAccessory(new ImagePreview(fc)); fc.setDialogTitle(prosa); fc.setMultiSelectionEnabled(true); fc.setCurrentDirectory(Constants.LAST_LOCAL_UPLOAD_DIR); int returnVal = fc.showDialog(this, Messages.getString("panel.content.documents.addDocument")); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = fc.getSelectedFiles(); uploadFiles(files, unit, viewComponentId, documentId); Constants.LAST_LOCAL_UPLOAD_DIR = fc.getCurrentDirectory(); } this.setCursor(Cursor.getDefaultCursor()); }
From source file:ca.canucksoftware.clockthemebuilder.ThemeBuilderView.java
private File loadFileChooser(javax.swing.filechooser.FileFilter ff, String saveName) { File result;//from w w w. jav a 2 s. 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:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java
/** * Verzeichnis fr die Daten auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * //from www . j ava2 s. c o m * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 03.08.2012 */ private void chooseDataDir() { JFileChooser fileChooser; int retVal; // // Einen Dateiauswahldialog Creieren // fileChooser = new JFileChooser(); fileChooser.setLocale(Locale.getDefault()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle(fileChooserDirTitle); fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG); fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip); // das existierende Logfile voreinstellen fileChooser.setSelectedFile(SpxPcloggerProgramConfig.databaseDir); retVal = fileChooser.showDialog(this, approveDirButtonText); // Mal sehen, was der User gewollt hat if (retVal == JFileChooser.APPROVE_OPTION) { // Ja, ich wollte das so databaseDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath()); wasChangedParameter = true; } }
From source file:de.dmarcini.submatix.pclogger.gui.ProgramProperetysDialog.java
/** * Das exportverzeichis auswhlen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * /*from ww w . jav a 2 s.co m*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 28.08.2012 */ private void chooseExportDir() { JFileChooser fileChooser; int retVal; // // Einen Dateiauswahldialog Creieren // fileChooser = new JFileChooser(); fileChooser.setLocale(Locale.getDefault()); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle(fileChooserExportDirTitle); fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG); fileChooser.setApproveButtonToolTipText(approveDirButtonTooltip); // das existierende Verzeichnis voreinstellen fileChooser.setSelectedFile(SpxPcloggerProgramConfig.exportDir); retVal = fileChooser.showDialog(this, approveDirButtonText); // Mal sehen, was der User gewollt hat if (retVal == JFileChooser.APPROVE_OPTION) { // Ja, ich wollte das so exportDirTextField.setText(fileChooser.getSelectedFile().getAbsolutePath()); wasChangedParameter = true; } }
From source file:net.pms.newgui.NavigationShareTab.java
private void initSimpleComponents(CellConstraints cc) { // Thumbnail seeking position seekpos = new JTextField("" + configuration.getThumbnailSeekPos()); seekpos.addKeyListener(new KeyAdapter() { @Override/* w ww . jav a 2 s. c o m*/ public void keyReleased(KeyEvent e) { try { int ab = Integer.parseInt(seekpos.getText()); configuration.setThumbnailSeekPos(ab); if (configuration.getUseCache()) { PMS.get().getDatabase().init(true); } } catch (NumberFormatException nfe) { LOGGER.debug("Could not parse thumbnail seek position from \"" + seekpos.getText() + "\""); } } }); if (configuration.isThumbnailGenerationEnabled()) { seekpos.setEnabled(true); } else { seekpos.setEnabled(false); } // Generate thumbnails thumbgenCheckBox = new JCheckBox(Messages.getString("NetworkTab.2"), configuration.isThumbnailGenerationEnabled()); thumbgenCheckBox.setContentAreaFilled(false); thumbgenCheckBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setThumbnailGenerationEnabled((e.getStateChange() == ItemEvent.SELECTED)); seekpos.setEnabled(configuration.isThumbnailGenerationEnabled()); mplayer_thumb.setEnabled(configuration.isThumbnailGenerationEnabled()); } }); // Use MPlayer for video thumbnails mplayer_thumb = new JCheckBox(Messages.getString("FoldTab.14"), configuration.isUseMplayerForVideoThumbs()); mplayer_thumb.setToolTipText(Messages.getString("FoldTab.61")); mplayer_thumb.setContentAreaFilled(false); mplayer_thumb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setUseMplayerForVideoThumbs((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isThumbnailGenerationEnabled()) { mplayer_thumb.setEnabled(true); } else { mplayer_thumb.setEnabled(false); } // DVD ISO thumbnails dvdiso_thumb = new JCheckBox(Messages.getString("FoldTab.19"), configuration.isDvdIsoThumbnails()); dvdiso_thumb.setContentAreaFilled(false); dvdiso_thumb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setDvdIsoThumbnails((e.getStateChange() == ItemEvent.SELECTED)); } }); // Image thumbnails image_thumb = new JCheckBox(Messages.getString("FoldTab.21"), configuration.getImageThumbnailsEnabled()); image_thumb.setContentAreaFilled(false); image_thumb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED)); } }); // Audio thumbnails import final KeyedComboBoxModel<CoverSupplier, String> thumbKCBM = new KeyedComboBoxModel<>( new CoverSupplier[] { CoverSupplier.NONE, CoverSupplier.COVER_ART_ARCHIVE }, new String[] { Messages.getString("FoldTab.35"), Messages.getString("FoldTab.73") }); audiothumbnail = new JComboBox<>(thumbKCBM); audiothumbnail.setEditable(false); thumbKCBM.setSelectedKey(configuration.getAudioThumbnailMethod()); audiothumbnail.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setAudioThumbnailMethod(thumbKCBM.getSelectedKey()); LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.26"), thumbKCBM.getSelectedValue()); } } }); // Alternate video cover art folder defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder()); defaultThumbFolder.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setAlternateThumbFolder(defaultThumbFolder.getText()); } }); // Alternate video cover art folder button select = new CustomJButton("..."); select.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28")); if (returnVal == JFileChooser.APPROVE_OPTION) { defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath()); configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath()); } } }); // Show Server Settings folder isShowFolderServerSettings = new JCheckBox(Messages.getString("FoldTab.ShowServerSettingsFolder"), configuration.isShowServerSettingsFolder()); isShowFolderServerSettings.setContentAreaFilled(false); isShowFolderServerSettings.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowServerSettingsFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); // Show #--TRANSCODE--# folder isShowFolderTranscode = new JCheckBox(Messages.getString("FoldTab.ShowTranscodeFolder"), configuration.isShowTranscodeFolder()); isShowFolderTranscode.setContentAreaFilled(false); isShowFolderTranscode.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowTranscodeFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); // Show Media Library folder isShowFolderMediaLibrary = new JCheckBox(Messages.getString("FoldTab.ShowMediaLibraryFolder"), configuration.isShowMediaLibraryFolder()); isShowFolderMediaLibrary.setContentAreaFilled(false); isShowFolderMediaLibrary.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); // Browse compressed archives archive = new JCheckBox(Messages.getString("NetworkTab.1"), configuration.isArchiveBrowsing()); archive.setContentAreaFilled(false); archive.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED); } }); // Enable the Media Library cacheenable = new JCheckBox(Messages.getString("NetworkTab.EnableMediaLibrary"), configuration.getUseCache()); cacheenable.setToolTipText(Messages.getString("FoldTab.ShowMediaLibraryFolderTooltip")); cacheenable.setContentAreaFilled(false); cacheenable.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED)); cachereset.setEnabled(configuration.getUseCache()); setScanLibraryEnabled(configuration.getUseCache()); } }); // Reset cache cachereset = new CustomJButton(Messages.getString("NetworkTab.EmptyMediaLibrary")); cachereset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("NetworkTab.MediaLibraryEmptiedExceptFullyPlayed") + "\n" + Messages.getString("NetworkTab.19"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { PMS.get().getDatabase().init(true); } } }); cachereset.setEnabled(configuration.getUseCache()); // Hide file extensions hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions()); hideextensions.setContentAreaFilled(false); if (configuration.isPrettifyFilenames()) { hideextensions.setEnabled(false); } hideextensions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED)); } }); // Hide transcoding engine names hideengines = new JCheckBox(Messages.getString("FoldTab.8"), configuration.isHideEngineNames()); hideengines.setToolTipText(Messages.getString("FoldTab.46")); hideengines.setContentAreaFilled(false); hideengines.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED)); } }); // Hide empty folders hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"), configuration.isHideEmptyFolders()); hideemptyfolders.setToolTipText(Messages.getString("FoldTab.59")); hideemptyfolders.setContentAreaFilled(false); hideemptyfolders.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED)); } }); // Show iTunes library itunes = new JCheckBox(Messages.getString("FoldTab.30"), configuration.isShowItunesLibrary()); itunes.setToolTipText(Messages.getString("FoldTab.47")); itunes.setContentAreaFilled(false); if (!(Platform.isMac() || Platform.isWindows())) { itunes.setEnabled(false); } itunes.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED)); } }); // Show iPhoto library iphoto = new JCheckBox(Messages.getString("FoldTab.29"), configuration.isShowIphotoLibrary()); iphoto.setContentAreaFilled(false); if (!Platform.isMac()) { iphoto.setEnabled(false); } iphoto.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED)); } }); // Show aperture library aperture = new JCheckBox(Messages.getString("FoldTab.34"), configuration.isShowApertureLibrary()); aperture.setContentAreaFilled(false); if (!Platform.isMac()) { aperture.setEnabled(false); } aperture.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED)); } }); // File order final KeyedComboBoxModel<Integer, String> kcbm = new KeyedComboBoxModel<>( new Integer[] { UMSUtils.SORT_LOC_SENS, // alphabetical UMSUtils.SORT_LOC_NAT, // natural sort UMSUtils.SORT_INS_ASCII, // ASCIIbetical UMSUtils.SORT_MOD_NEW, // newest first UMSUtils.SORT_MOD_OLD, // oldest first UMSUtils.SORT_RANDOM, // random UMSUtils.SORT_NO_SORT // no sorting }, new String[] { Messages.getString("FoldTab.15"), Messages.getString("FoldTab.22"), Messages.getString("FoldTab.20"), Messages.getString("FoldTab.16"), Messages.getString("FoldTab.17"), Messages.getString("FoldTab.58"), Messages.getString("FoldTab.62") }); sortmethod = new JComboBox<>(kcbm); sortmethod.setEditable(false); kcbm.setSelectedKey(configuration.getSortMethod(null)); sortmethod.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setSortMethod(kcbm.getSelectedKey()); LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.18"), kcbm.getSelectedValue()); } } }); // Ignore the word "the" while sorting ignorethewordthe = new JCheckBox(Messages.getString("FoldTab.39"), configuration.isIgnoreTheWordAandThe()); ignorethewordthe.setToolTipText(Messages.getString("FoldTab.44")); ignorethewordthe.setContentAreaFilled(false); ignorethewordthe.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setIgnoreTheWordAandThe((e.getStateChange() == ItemEvent.SELECTED)); } }); atzLimit = new JTextField("" + configuration.getATZLimit()); atzLimit.setToolTipText(Messages.getString("FoldTab.49")); atzLimit.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { int ab = Integer.parseInt(atzLimit.getText()); configuration.setATZLimit(ab); } catch (NumberFormatException nfe) { LOGGER.debug("Could not parse ATZ limit from \"" + atzLimit.getText() + "\""); LOGGER.debug("The full error was: " + nfe); } } }); isShowFolderLiveSubtitles = new JCheckBox(Messages.getString("FoldTab.ShowLiveSubtitlesFolder"), configuration.isShowLiveSubtitlesFolder()); isShowFolderLiveSubtitles.setContentAreaFilled(false); isShowFolderLiveSubtitles.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowLiveSubtitlesFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); prettifyfilenames = new JCheckBox(Messages.getString("FoldTab.43"), configuration.isPrettifyFilenames()); prettifyfilenames.setToolTipText(Messages.getString("FoldTab.45")); prettifyfilenames.setContentAreaFilled(false); prettifyfilenames.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setPrettifyFilenames((e.getStateChange() == ItemEvent.SELECTED)); hideextensions.setEnabled((e.getStateChange() != ItemEvent.SELECTED)); episodeTitles.setEnabled((e.getStateChange() == ItemEvent.SELECTED)); } }); episodeTitles = new JCheckBox(Messages.getString("FoldTab.74"), configuration.isUseInfoFromIMDb()); episodeTitles.setToolTipText(Messages.getString("FoldTab.64")); episodeTitles.setContentAreaFilled(false); if (!configuration.isPrettifyFilenames()) { episodeTitles.setEnabled(false); } episodeTitles.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setUseInfoFromIMDb((e.getStateChange() == ItemEvent.SELECTED)); } }); isShowFolderNewMedia = new JCheckBox(Messages.getString("FoldTab.ShowNewMediaFolder"), configuration.isShowNewMediaFolder()); isShowFolderNewMedia.setToolTipText(Messages.getString("FoldTab.66")); isShowFolderNewMedia.setContentAreaFilled(false); isShowFolderNewMedia.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowNewMediaFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); resume = new JCheckBox(Messages.getString("NetworkTab.68"), configuration.isResumeEnabled()); resume.setToolTipText(Messages.getString("NetworkTab.69")); resume.setContentAreaFilled(false); resume.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setResume((e.getStateChange() == ItemEvent.SELECTED)); } }); isShowFolderRecentlyPlayed = new JCheckBox(Messages.getString("FoldTab.ShowRecentlyPlayedFolder"), configuration.isShowRecentlyPlayedFolder()); isShowFolderRecentlyPlayed.setContentAreaFilled(false); isShowFolderRecentlyPlayed.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { configuration.setShowRecentlyPlayedFolder((e.getStateChange() == ItemEvent.SELECTED)); } }); // Fully played action final KeyedComboBoxModel<FullyPlayedAction, String> fullyPlayedActionModel = new KeyedComboBoxModel<>( new FullyPlayedAction[] { FullyPlayedAction.NO_ACTION, FullyPlayedAction.MARK, FullyPlayedAction.HIDE_VIDEO, FullyPlayedAction.MOVE_FOLDER, FullyPlayedAction.MOVE_TRASH }, new String[] { Messages.getString("FoldTab.67"), Messages.getString("FoldTab.68"), Messages.getString("FoldTab.69"), Messages.getString("FoldTab.70"), Messages.getString("FoldTab.71") }); fullyPlayedAction = new JComboBox<>(fullyPlayedActionModel); fullyPlayedAction.setEditable(false); fullyPlayedActionModel.setSelectedKey(configuration.getFullyPlayedAction()); fullyPlayedAction.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setFullyPlayedAction(fullyPlayedActionModel.getSelectedKey()); fullyPlayedOutputDirectory .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER); selectFullyPlayedOutputDirectory .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER); if (configuration.getUseCache() && fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.NO_ACTION) { PMS.get().getDatabase().init(true); } } } }); // Watched video output directory fullyPlayedOutputDirectory = new JTextField(configuration.getFullyPlayedOutputDirectory()); fullyPlayedOutputDirectory.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setFullyPlayedOutputDirectory(fullyPlayedOutputDirectory.getText()); } }); fullyPlayedOutputDirectory .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER); // Watched video output directory selection button selectFullyPlayedOutputDirectory = new CustomJButton("..."); selectFullyPlayedOutputDirectory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28")); if (returnVal == JFileChooser.APPROVE_OPTION) { fullyPlayedOutputDirectory.setText(chooser.getSelectedFile().getAbsolutePath()); configuration.setFullyPlayedOutputDirectory(chooser.getSelectedFile().getAbsolutePath()); } } }); selectFullyPlayedOutputDirectory .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER); }
From source file:net.sourceforge.entrainer.gui.EntrainerFX.java
private boolean showWavFileChooser() { JFileChooser wavChooser = getWavFileChooser(); int val = wavChooser.showDialog(this, "Ok"); if (val == JFileChooser.APPROVE_OPTION) { File wavFile = processFile(wavChooser.getSelectedFile()); if (!isValidFile(wavFile)) { JOptionPane.showMessageDialog(this, wavFile.getName() + " is not a valid WAV file name\n(it must end with a '.wav' extension)", "Invalid WAV File Name", JOptionPane.WARNING_MESSAGE); return false; }//from w w w .j a v a 2s. c o m control.setWavFile(wavFile); return true; } control.setWavFile(null); return false; }
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);//from w w w .j a v a 2s.c o 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:ir.ac.iust.nlp.postagger.POSTaggerForm.java
private String showFileDialog(String currentDir, boolean isFolder, FileNameExtensionFilter filter) { JFileChooser fc = new JFileChooser(); if (currentDir.length() == 0) { fc.setCurrentDirectory(new java.io.File(".")); } else {// ww w . j a v a 2 s.co m fc.setCurrentDirectory(new java.io.File(currentDir)); } fc.setMultiSelectionEnabled(false); if (filter != null) { fc.setFileFilter(filter); } String title = "Select File"; if (isFolder == true) { fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); title = "Select Folder"; } if (fc.showDialog(this, title) == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String path = file.getPath(); if (isFolder == true && path.lastIndexOf(File.separator) != path.length() - 1) { path = path + File.separator; } return path; } else { return currentDir; } }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
private File loadFileChooser(boolean dir, FileFilter filter, String text) { File result = null;//from w w w . ja va 2 s.c om 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:marytts.tools.redstart.AdminWindow.java
private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_OpenActionPerformed // Allow user to choose a different voice (prompt set) without exiting the tool // Create a file chooser final JFileChooser openDialog = new JFileChooser(); // Set the current directory to the voice currently in use openDialog.setCurrentDirectory(getVoiceFolderPath()); openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = openDialog.showDialog(AdminWindow.this, "Open Voice"); if (result == JFileChooser.APPROVE_OPTION) { File voice = openDialog.getSelectedFile(); setVoiceFolderPath(voice); // Set to the selected the voice folder path Test.output("Open voice: " + voice); setupVoice();//from ww w. j av a2 s .com } else { Test.output("Open command cancelled."); } }