List of usage examples for javax.swing JFileChooser setFileSelectionMode
@BeanProperty(preferred = true, enumerationValues = { "JFileChooser.FILES_ONLY", "JFileChooser.DIRECTORIES_ONLY", "JFileChooser.FILES_AND_DIRECTORIES" }, description = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode)
JFileChooser
to allow the user to just select files, just select directories, or select both files and directories. From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java
public void actionPerformed(ActionEvent arg0) { JMenuItem source = (JMenuItem) (arg0.getSource()); if (source.getText().equals(MENU_ABOUT)) { JOptionPane.showMessageDialog(this, WDBearManager.VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "\n" + "Supports any WDB version\n" + "\n" + "Thanks to:\n" + "DarkMan for testing,\n" + "John for the 1.10 specs, Annunaki for helping with the header,\n" + "Andrikos for the 1.6.x WDB specs, Pyro's WDBViewer, WDDG Forum,\n" + "blizzhackers, etc etc\n\n" + "This program uses: \n" + "JGoodies from http://www.jgoodies.com/\n" + "Hypersonic SQL database 1.7.3\n" + "Apache Log4J, Xerces\n" + "Jakarta Commons Logging and CLI\n" + "Castor from ExoLab\n" + "MySQL JDBC connector 3.1.7\n" + "HTTPUNIT from Russell Gold\n" + "Jython 2.1\n" + "Refer to directory 'licenses' for more details about the software used\n" + "PLEASE:\n" + "If you like this program and find it usefull:\n" + "Please donate money to a charity oranization of your choice.\n" + "I recommend any organization that fights cancer.\n\n" + "License:\n" + "WDBearMgr is placed under the GNU GPL. \n" + "For further information, see the page :\n" + "http://www.gnu.org/copyleft/gpl.html.\n" + "See licenses/GPL_license.html\n" + "\n" + "For a different license please contact the author.", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return;/*from ww w. j a va 2 s.com*/ } else if (source.getText().equals(MENU_HELP)) { JFrame myFrame = new JFrame("doc/html/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/html/index.html"); urlHTML = scriptFile.toURL();//this.getClass().getResource("/scripts/"+source.getName()+".py"); // .out.println( urlHTML ); // .out.println( urlHTML.toExternalForm() ); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/html/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_JDOCS)) { JFrame myFrame = new JFrame("doc/javadoc/index.html"); //myFrame.setFont( ); URL urlHTML = null; try { JEditorPane htmlPane = new JEditorPane(); //htmlPane.setFont(sourceFont); // .out.println("/scripts/"+source.getName()+".py"); File scriptFile = new File("doc/javadoc/index.html"); urlHTML = scriptFile.toURL(); htmlPane.setPage(urlHTML); htmlPane.setEditable(false); JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane); htmlPane.addHyperlinkListener(myJEPHL); myFrame.getContentPane().add(new JScrollPane(htmlPane)); myFrame.pack(); myFrame.setSize(640, 480); myFrame.show(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not open 'doc/javadoc/index.html'", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); } } else if (source.getText().equals(MENU_CHECKUPDATE)) { Properties dbProps = null; String filName = PROPS_CHECK_UPDATE; try { dbProps = ReadPropertiesFile.readProperties(filName); String updFile = dbProps.getProperty(KEY_UPD_FILE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find update information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } String updSite = dbProps.getProperty(KEY_WDBMGR_SITE); if (updFile == null) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "Could not find SITE information", "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE); return; } URL urlUpdScript = new URL(updFile); BufferedReader in = new BufferedReader(new InputStreamReader(urlUpdScript.openStream())); String versionTXT = in.readLine(); String downloadName = in.readLine(); in.close(); if (versionTXT.equals(WDBearManager.VERSION_INFO)) { JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n" + "You are using the latest version, no updates available", "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); return; } else { // Read version.txt String versionInfo = (String) dbProps.getProperty(KEY_VERSION_INFO); URL urlversionInfo = new URL(versionInfo); BufferedReader brVInfo = new BufferedReader(new InputStreamReader(urlversionInfo.openStream())); StringBuffer sbuVInfo = new StringBuffer(); String strLine = ""; boolean foundStart = false; while ((strLine = brVInfo.readLine()) != null) { if (strLine.startsWith("---")) { break; } if (foundStart == true) { sbuVInfo.append(strLine); sbuVInfo.append("\n"); continue; } if (strLine.startsWith(versionTXT)) { foundStart = true; continue; } } brVInfo.close(); int n = JOptionPane.showConfirmDialog(this, "New version available - Please visit " + updSite + "\n\n" + versionTXT + "\n" + "\n" + "You are using version:\n" + WDBearManager.VERSION_INFO + "\n" + "\n" + "Do you want to download this version?\n\n" + "Version information:\n" + sbuVInfo.toString(), VERSION_INFO + "by kizura", JOptionPane.YES_NO_OPTION); // JOptionPane.showMessageDialog(this, VERSION_INFO + "\n" // + "by kizura\n" + WDBManager.EMAIL + "\n\n" // + "New version available - Please visit " + updSite, // "Warning " // + VERSION_INFO, JOptionPane.WARNING_MESSAGE); if (n == 0) { JFileChooser chooser = new JFileChooser(new File(".")); chooser.setDialogTitle("Please select download location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { URL urlUpd = new URL(downloadName); BufferedInputStream bin = new BufferedInputStream(urlUpd.openStream()); System.out.println( new File(chooser.getSelectedFile(), urlUpd.getFile()).getAbsolutePath()); File thisFile = new File(chooser.getSelectedFile(), urlUpd.getFile()); BufferedOutputStream bout = new BufferedOutputStream( new FileOutputStream(thisFile)); byte[] bufFile = new byte[102400]; int bytesRead = 0; while ((bytesRead = bin.read(bufFile)) != -1) { bout.write(bufFile, 0, bytesRead); } bin.close(); bout.close(); JOptionPane.showMessageDialog(this, "Update downloaded successfully" + "\n" + "Please check '" + thisFile.getAbsolutePath() + "'", "Success " + WDBearManager.VERSION_INFO, JOptionPane.INFORMATION_MESSAGE); //String msg = WriteCSV.writeCSV(chooser.getSelectedFile(), this.items); } catch (Exception ex) { String msg = ex.getMessage(); JOptionPane.showMessageDialog(this, msg + "\n" + "Error downloading update", "Error " + WDBearManager.VERSION_INFO, JOptionPane.ERROR_MESSAGE); } } } // user selected "download" return; } } catch (Exception ex) { ex.printStackTrace(); } } else { System.exit(0); } }
From source file:com.freedomotic.jfrontend.MainWindow.java
private void mnuOpenEnvironmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuOpenEnvironmentActionPerformed mnuSaveActionPerformed(null);/*from w w w . j ava 2 s . co m*/ final JFileChooser fc = new JFileChooser(Info.PATHS.PATH_DATA_FOLDER + "/furn/"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File file = null; int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); LOG.info("Opening environment file \"{}\"", file.getAbsolutePath()); try { api.environments().init(file); setEnvironment(api.environments().findAll().get(0)); mnuSelectEnvironmentActionPerformed(null); } catch (RepositoryException e) { LOG.error(Freedomotic.getStackTraceInfo(e)); } setWindowedMode(); } else { LOG.info(i18n.msg("canceled_by_user")); } }
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//from ww w .j av a 2 s .com 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:com.freedomotic.jfrontend.MainWindow.java
/** * //w w w . ja v a 2s.c o m * @param evt */ private void mnuNewEnvironmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuNewEnvironmentActionPerformed // we are about to make changes to environments: we'd better save current status mnuSaveActionPerformed(null); File oldEnv = api.environments().findAll().get(0).getSource(); //creates a new environment coping it from a template File template = new File( Info.PATHS.PATH_DATA_FOLDER + "/furn/templates/template-square/template-square.xenv"); LOG.info("Opening new environment template file \"{}\"", template.getAbsolutePath()); setEnvironment(api.environments().findAll().get(0)); try { EnvironmentLogic enL = api.environments().loadEnvironmentFromFile(template); if (enL != null) { //EnvObjectPersistence.loadObjects(EnvironmentPersistence.getEnvironments().get(0).getObjectFolder(), false); final JFileChooser fc = new JFileChooser(oldEnv.getParentFile().getParentFile()); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setDialogTitle(api.getI18n().msg("select_env_folder_save")); fc.setSelectedFile(oldEnv.getParentFile()); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File folder = fc.getSelectedFile(); if (!folder.getName().isEmpty()) { if (!folder.getAbsolutePath().equalsIgnoreCase(oldEnv.getParentFile().getAbsolutePath())) { // we are making a new environment set api.environments().deleteAll(); } EnvironmentLogic newenv = api.environments().copy(enL); newenv.setSource(new File(folder + "/" + newenv.getPojo().getUUID() + ".xenv")); setEnvironment(newenv); api.environments().saveAs(newenv, folder); } } else { LOG.info("Save command cancelled by user."); //reload the old file api.environments().init(oldEnv.getParentFile()); setEnvironment(api.environments().findAll().get(0)); } } } catch (Exception e) { LOG.error(Freedomotic.getStackTraceInfo(e)); } setWindowedMode(); }
From source file:com.jug.MotherMachine.java
/** * Shows a JFileChooser set up to accept the selection of folders. * If 'cancel' is pressed this method terminates the MotherMachine app. * * @param guiFrame//w w w . j a v a 2 s .c o m * parent frame * @param path * path to the folder to open initially * @return an instance of {@link File} pointing at the selected folder. */ private File showFolderChooser(final JFrame guiFrame, final String path) { final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(path)); chooser.setDialogTitle("Select folder containing image sequence..."); chooser.setFileFilter(new FileFilter() { @Override public final boolean accept(final File file) { return file.isDirectory(); } @Override public String getDescription() { return "We only take directories"; } }); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else { System.exit(0); return null; } }
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 ww.jav a 2 s. 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:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
private void exportActiveOutlineToAtom() { if (MindRaider.profile.getActiveOutline() == null) { JOptionPane.showMessageDialog(MindRaiderMainWindow.this, Messages.getString("MindRaiderJFrame.exportNotebookWarning"), Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE); return;// ww w . j a va 2 s . co m } JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator + "sharing"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String dstDirectory = fc.getSelectedFile().getAbsolutePath(); Utils.createDirectory(dstDirectory); final String dstFileName = dstDirectory + File.separator + "MindRaider-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + "-" + Utils.getCurrentDataTimeAsPrettyString() + ".atom.xml"; logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName)); MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_ATOM, dstFileName); } else { logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser")); } }
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 {/*from w ww .j av 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:la2launcher.MainFrame.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {/* www.j a v a2 s .c o m*/ JFileChooser fc; if (gamePath == null || gamePath.trim().equals("")) { fc = new JFileChooser(); } else { if (new File(gamePath).isDirectory()) { fc = new JFileChooser(gamePath); } else { fc = new JFileChooser(); } } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(this); File f = fc.getSelectedFile(); if (f != null) { gamePath = f.getAbsolutePath(); jTextField2.setText(gamePath); } boolean systemFound = false; for (String fname : f.list()) { if (fname.toUpperCase().equals("SYSTEM")) { systemFound = true; break; } } if (!systemFound) { JOptionPane.showMessageDialog(this, "? system. . ? ?."); } } catch (Exception ex) { logg(""); logg(ex); } }
From source file:grupob.TipoProceso.java
private void seleccionarHuellasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionarHuellasActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Seleccionar Carpeta"); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); if (!Utils.validarRutaImagenHuella(selectedFile.getAbsolutePath(), 1)) { JOptionPane.showMessageDialog(null, "Debe seleccionar una carpeta con archivos JPG con la cantidad de registros de votantes exacta."); } else {//w w w . jav a 2s.co m textConfHuellas.setText("" + selectedFile); } // Recorte.rutaHuella=""+selectedFile; } }