List of usage examples for javax.swing JFileChooser setSelectedFile
@BeanProperty(preferred = true) public void setSelectedFile(File file)
From source file:org.kse.gui.dialogs.sign.DSignJar.java
private void inputJarBrowsePressed() { JFileChooser chooser = FileChooserFactory.getArchiveFileChooser(); File currentFile = new File(jtfInputJar.getText().trim()); if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) { chooser.setCurrentDirectory(currentFile.getParentFile()); chooser.setSelectedFile(currentFile); } else {/* w w w . j a v a 2 s .c o m*/ chooser.setCurrentDirectory(CurrentDirectory.get()); } chooser.setDialogTitle(res.getString("DSignJar.ChooseInputJar.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(this, res.getString("DSignJar.InputJarChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); jtfInputJar.setText(chosenFile.toString()); jtfInputJar.setCaretPosition(0); populateOutputJarFileName(chosenFile); } }
From source file:org.kse.gui.dialogs.sign.DSignJar.java
private void outputJarBrowsePressed() { JFileChooser chooser = FileChooserFactory.getArchiveFileChooser(); File currentFile = new File(jtfOutputJar.getText()); if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) { chooser.setCurrentDirectory(currentFile.getParentFile()); chooser.setSelectedFile(currentFile); } else {/*from ww w . java2 s .c om*/ chooser.setCurrentDirectory(CurrentDirectory.get()); } chooser.setDialogTitle(res.getString("DSignJar.ChooseOutputJar.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DSignJar.OutputJarChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); jtfOutputJar.setText(chosenFile.toString()); jtfOutputJar.setCaretPosition(0); } }
From source file:org.kse.gui.dialogs.sign.DSignMidlet.java
private void inputJadBrowsePressed() { JFileChooser chooser = FileChooserFactory.getJadFileChooser(); File currentFile = new File(jtfInputJad.getText()); if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) { chooser.setCurrentDirectory(currentFile.getParentFile()); chooser.setSelectedFile(currentFile); } else {//w ww .j a va2 s . co m chooser.setCurrentDirectory(CurrentDirectory.get()); } chooser.setDialogTitle(res.getString("DSignMidlet.ChooseInputJad.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = chooser.showDialog(this, res.getString("DSignMidlet.InputJadChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); jtfInputJad.setText(chosenFile.toString()); jtfInputJad.setCaretPosition(0); populateOutputJadFileName(chosenFile); } }
From source file:org.kse.gui.dialogs.sign.DSignMidlet.java
private void outputJadBrowsePressed() { JFileChooser chooser = FileChooserFactory.getJadFileChooser(); File currentFile = new File(jtfOutputJad.getText()); if (currentFile.getParentFile() != null && currentFile.getParentFile().exists()) { chooser.setCurrentDirectory(currentFile.getParentFile()); chooser.setSelectedFile(currentFile); } else {/*from w ww . jav a 2s.co m*/ chooser.setCurrentDirectory(CurrentDirectory.get()); } chooser.setDialogTitle(res.getString("DSignMidlet.ChooseOutputJad.Title")); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DSignMidlet.OutputJadChooser.button")); if (rtnValue == JFileChooser.APPROVE_OPTION) { File chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); jtfOutputJad.setText(chosenFile.toString()); jtfOutputJad.setCaretPosition(0); } }
From source file:org.kuali.test.creator.TestCreator.java
/** * * @param testHeader//from w ww .j a v a2s .c om */ public void handleExportTest(TestHeader testHeader) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setSelectedFile(new File(Utils.formatForFileName(testHeader.getTestName()) + ".export")); if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); PrintWriter pw = null; try { pw = new PrintWriter(new FileWriter(file)); Platform platform = (Platform) Utils.findPlatform(getConfiguration(), testHeader.getPlatformName()) .copy(); platform.setEmailAddresses(""); if (platform.getTestSuites() != null) { platform.getTestSuites().setTestSuiteArray(new TestSuite[0]); } if (platform.getPlatformTests() != null) { platform.getPlatformTests().setTestHeaderArray(new TestHeader[0]); } platform.setEmailAddresses(""); platform.setDatabaseConnectionName(""); pw.println("[test-platform]"); pw.println(platform.toString().replace("xml-fragment", "test:platform")); pw.println(); pw.println("[test-header]"); pw.println(testHeader.toString().replace("xml-fragment", "test:test-header")); pw.println(); pw.println("[test-desription]"); File ftest = new File(Utils.getTestFilePath(getConfiguration(), testHeader)); pw.println(Utils.getTestDescription(ftest)); pw.println(); pw.println("[test-operations]"); pw.println(new String(FileUtils.readFileToByteArray(ftest))); } catch (Exception ex) { LOG.error(ex.toString(), ex); UIUtils.showError(this, "File Export Error", "Error exporting file: " + file.getName() + " - " + ex.toString()); } finally { try { if (pw != null) { pw.close(); } } catch (Exception ex) { } ; } } }
From source file:org.nuclos.client.dbtransfer.DBTransferImport.java
private PanelWizardStep newStep5(final MainFrameTab ifrm) { final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate(); final JLabel lbResult = new JLabel(); final JEditorPane editLog = new JEditorPane(); final JScrollPane scrollLog = new JScrollPane(editLog); final JLabel lbStructureChangeResult = new JLabel( localeDelegate.getMessage("dbtransfer.import.step5.1", "\u00c4nderungen am Datenbankschema")); final JButton btnSaveStructureChangeScript = new JButton( localeDelegate.getMessage("dbtransfer.import.step5.2", "Script speichern") + "..."); final JButton btnSaveStructureChangeLog = new JButton( localeDelegate.getMessage("dbtransfer.import.step5.3", "Log speichern") + "..."); editLog.setContentType("text/html"); editLog.setEditable(false);// ww w. j av a 2s . c o m final PanelWizardStep step = new PanelWizardStep( localeDelegate.getMessage("dbtransfer.import.step5.4", "Ergebnis"), localeDelegate.getMessage( "dbtransfer.import.step5.5", "Hier wird Ihnen das Ergebnis des Imports angezeigt.")) { @Override public void prepare() { if (!importTransferResult.hasWarnings() && !importTransferResult.hasCriticals()) { lbResult.setText(localeDelegate.getMessage("dbtransfer.import.step5.6", "Import erfolgreich!")); this.setComplete(true); } else { lbResult.setText( localeDelegate.getMessage("dbtransfer.import.step5.7", "Ein Problem ist aufgetreten!")); blnSaveOfLogRecommend = true; } StringBuffer sbLog = new StringBuffer(); sbLog.append("<html><body>"); if (!importTransferResult.foundReferences.isEmpty()) { sbLog.append(localeDelegate.getMessage("dbtransfer.import.step5.8", "Folgende Konfigurationsobjekte sollten entfernt werden, werden aber noch verwendet") + ":<br />"); for (Pair<String, String> reference : importTransferResult.foundReferences) { sbLog.append( "- " + reference.y + " (" + localeDelegate.getLabelFromMetaDataVO( MetaDataClientProvider.getInstance().getEntity(reference.x)) + ")<br />"); } sbLog.append("<br />" + localeDelegate.getMessage("dbtransfer.import.step5.9", "Passen Sie Ihre Konfiguration dahingehend an oder bearbeiten Sie die Daten,\nwelche noch auf die Konfigurationsobjekte verweisen.")); sbLog.append("<br />"); } sbLog.append("<font color=\"#800000\">" + importTransferObject.result.getCriticals() + "</font>" + (importTransferObject.result.hasCriticals() ? "<br />" : "")); sbLog.append(importTransferResult.getWarnings()); sbLog.append("</body></html>"); editLog.setText(sbLog.toString()); } }; utils.initJPanel(step, new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL }, new double[] { 20, TableLayout.FILL, TableLayout.PREFERRED }); step.add(lbResult, "0,0,3,0"); step.add(scrollLog, "0,1,3,1"); step.add(lbStructureChangeResult, "0,2"); step.add(btnSaveStructureChangeScript, "1,2"); step.add(btnSaveStructureChangeLog, "2,2"); btnSaveStructureChangeScript.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { UIUtils.showWaitCursorForFrame(ifrm, true); final StringBuffer sbSql = new StringBuffer(); org.apache.commons.collections.CollectionUtils.forAllDo(importTransferResult.script, new Closure() { @Override public void execute(Object element) { sbSql.append("<DDL>" + element + "</DDL>\n\n"); } }); final JFileChooser filechooser = utils.getFileChooser( localeDelegate.getMessage("configuration.transfer.file.sql", "SQL-Dateien"), ".import-sql.txt"); filechooser.setSelectedFile(new File(tfTransferFile.getText() + ".import-sql.txt")); final int iBtn = filechooser.showSaveDialog(step); if (iBtn == JFileChooser.APPROVE_OPTION) { final File file = filechooser.getSelectedFile(); if (file != null) { String fileName = file.getPath(); if (!fileName.toLowerCase().endsWith(".import-sql.txt")) { fileName += ".import-sql.txt"; } File outFile = new File(fileName); final Writer out = new BufferedWriter(new FileWriter(outFile)); try { out.write(sbSql.toString()); } finally { out.close(); } if (blnSaveOfScriptRecommend) { step.setComplete(true); } } } } catch (Exception e) { Errors.getInstance().showExceptionDialog(ifrm, e); } finally { UIUtils.showWaitCursorForFrame(ifrm, false); } } }); btnSaveStructureChangeLog.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { UIUtils.showWaitCursorForFrame(ifrm, true); final JFileChooser filechooser = utils.getFileChooser( localeDelegate.getMessage("configuration.transfer.file.log", "Log-Dateien"), ".import-log.html"); filechooser.setSelectedFile(new File(tfTransferFile.getText() + ".import-log.html")); final int iBtn = filechooser.showSaveDialog(step); if (iBtn == JFileChooser.APPROVE_OPTION) { final File file = filechooser.getSelectedFile(); if (file != null) { String fileName = file.getPath(); if (!fileName.toLowerCase().endsWith(".import-log.html")) { fileName += ".import-log.html"; } File outFile = new File(fileName); final Writer out = new BufferedWriter(new FileWriter(outFile)); try { out.write(editLog.getText()); } finally { out.close(); } if (blnSaveOfLogRecommend) { step.setComplete(true); } } } } catch (Exception e) { Errors.getInstance().showExceptionDialog(ifrm, e); } finally { UIUtils.showWaitCursorForFrame(ifrm, false); } } }); return step; }
From source file:org.omegat.gui.align.AlignPanelController.java
/** * Display the align tool. The tool is not modal, so this call will return immediately. * //w w w.j a v a2 s . c om * @param parent * Parent window of the align tool */ public void show(Component parent) { frame = new AlignMenuFrame(); frame.setTitle(OStrings.getString("ALIGNER_PANEL")); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { closeFrame(frame); } }); panel = new AlignPanel(); ActionListener comparisonListener = e -> { ComparisonMode newValue = (ComparisonMode) ((JComboBox<?>) e.getSource()).getSelectedItem(); if (newValue != aligner.comparisonMode && confirmReset(frame)) { aligner.comparisonMode = newValue; reloadBeads(); } else { panel.comparisonComboBox.setSelectedItem(aligner.comparisonMode); } }; panel.comparisonComboBox.addActionListener(comparisonListener); panel.comparisonComboBox.setRenderer(new EnumRenderer<ComparisonMode>("ALIGNER_ENUM_COMPARISON_MODE_")); ActionListener algorithmListener = e -> { AlgorithmClass newValue = (AlgorithmClass) ((JComboBox<?>) e.getSource()).getSelectedItem(); if (newValue != aligner.algorithmClass && confirmReset(frame)) { aligner.algorithmClass = newValue; reloadBeads(); } else { panel.algorithmComboBox.setSelectedItem(aligner.algorithmClass); } }; panel.algorithmComboBox.addActionListener(algorithmListener); panel.algorithmComboBox.setRenderer(new EnumRenderer<AlgorithmClass>("ALIGNER_ENUM_ALGORITHM_CLASS_")); ActionListener calculatorListener = e -> { CalculatorType newValue = (CalculatorType) ((JComboBox<?>) e.getSource()).getSelectedItem(); if (newValue != aligner.calculatorType && confirmReset(frame)) { aligner.calculatorType = newValue; reloadBeads(); } else { panel.calculatorComboBox.setSelectedItem(aligner.calculatorType); } }; panel.calculatorComboBox.addActionListener(calculatorListener); panel.calculatorComboBox.setRenderer(new EnumRenderer<CalculatorType>("ALIGNER_ENUM_CALCULATOR_TYPE_")); ActionListener counterListener = e -> { CounterType newValue = (CounterType) ((JComboBox<?>) e.getSource()).getSelectedItem(); if (newValue != aligner.counterType && confirmReset(frame)) { aligner.counterType = newValue; reloadBeads(); } else { panel.counterComboBox.setSelectedItem(aligner.counterType); } }; panel.counterComboBox.addActionListener(counterListener); panel.counterComboBox.setRenderer(new EnumRenderer<CounterType>("ALIGNER_ENUM_COUNTER_TYPE_")); ActionListener segmentingListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean newValue = ((AbstractButton) e.getSource()).isSelected(); if (newValue != aligner.segment && confirmReset(frame)) { aligner.segment = newValue; reloadBeads(); } else { panel.segmentingCheckBox.setSelected(aligner.segment); frame.segmentingItem.setSelected(aligner.segment); } } }; panel.segmentingCheckBox.addActionListener(segmentingListener); frame.segmentingItem.addActionListener(segmentingListener); ActionListener segmentingRulesListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (confirmReset(frame)) { SegmentationCustomizer customizer = new SegmentationCustomizer(false, SRX.getDefault(), Core.getSegmenter().getSRX(), null); if (customizer.show(frame)) { customizedSRX = customizer.getResult(); Core.setSegmenter(new Segmenter(customizedSRX)); reloadBeads(); } } } }; panel.segmentingRulesButton.addActionListener(segmentingRulesListener); frame.segmentingRulesItem.addActionListener(segmentingRulesListener); ActionListener filterSettingsListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (confirmReset(frame)) { FiltersCustomizer customizer = new FiltersCustomizer(false, FilterMaster.createDefaultFiltersConfig(), Core.getFilterMaster().getConfig(), null); if (customizer.show(frame)) { customizedFilters = customizer.getResult(); Core.setFilterMaster(new FilterMaster(customizedFilters)); aligner.clearLoaded(); reloadBeads(); } } } }; panel.fileFilterSettingsButton.addActionListener(filterSettingsListener); frame.fileFilterSettingsItem.addActionListener(filterSettingsListener); TableCellRenderer renderer = new MultilineCellRenderer(); panel.table.setDefaultRenderer(Object.class, renderer); panel.table.setDefaultRenderer(Boolean.class, renderer); panel.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { resizeRows(panel.table); } }); ActionListener oneAdjustListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] rows = panel.table.getSelectedRows(); int col = panel.table.getSelectedColumn(); boolean up = e.getSource().equals(panel.moveUpButton) || e.getSource().equals(frame.moveUpItem); BeadTableModel model = (BeadTableModel) panel.table.getModel(); if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) { int trgRow = up ? model.prevBeadFromRow(rows[0]) : model.nextBeadFromRow(rows[rows.length - 1]); moveRows(rows, col, trgRow); } else { int offset = up ? -1 : 1; slideRows(rows, col, offset); } } }; panel.moveUpButton.addActionListener(oneAdjustListener); frame.moveUpItem.addActionListener(oneAdjustListener); panel.moveDownButton.addActionListener(oneAdjustListener); frame.moveDownItem.addActionListener(oneAdjustListener); ActionListener mergeListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] rows = panel.table.getSelectedRows(); int col = panel.table.getSelectedColumn(); BeadTableModel model = (BeadTableModel) panel.table.getModel(); if (rows.length == 1) { rows = new int[] { rows[0], model.nextNonEmptyCell(rows[0], col) }; } int beads = model.beadsInRowSpan(rows); if (beads < 1) { // Do nothing } else if (beads == 1) { mergeRows(rows, col); } else { moveRows(rows, col, rows[0]); } } }; panel.mergeButton.addActionListener(mergeListener); frame.mergeItem.addActionListener(mergeListener); ActionListener splitListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int[] rows = panel.table.getSelectedRows(); int col = panel.table.getSelectedColumn(); BeadTableModel model = (BeadTableModel) panel.table.getModel(); int beads = model.beadsInRowSpan(rows); if (beads != 1) { // Do nothing } else if (rows.length == 1) { splitRow(rows[0], col); } else { splitBead(rows, col); } } }; panel.splitButton.addActionListener(splitListener); frame.splitItem.addActionListener(splitListener); ActionListener editListener = new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { int row = panel.table.getSelectedRow(); int col = panel.table.getSelectedColumn(); editRow(row, col); } }; panel.editButton.addActionListener(editListener); frame.editItem.addActionListener(editListener); ListSelectionListener selectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateCommandAvailability(panel, frame); } }; panel.table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener); panel.table.getSelectionModel().addListSelectionListener(selectionListener); ActionListener saveListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!confirmSaveTMX(panel)) { return; } while (true) { JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(new File(defaultSaveDir, getOutFileName())); chooser.setDialogTitle(OStrings.getString("ALIGNER_PANEL_DIALOG_SAVE")); if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(frame)) { File file = chooser.getSelectedFile(); if (file.isFile()) { if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(frame, StringUtil.format(OStrings.getString("ALIGNER_PANEL_DIALOG_OVERWRITE"), file.getName()), OStrings.getString("ALIGNER_DIALOG_WARNING_TITLE"), JOptionPane.WARNING_MESSAGE)) { continue; } } List<MutableBead> beads = ((BeadTableModel) panel.table.getModel()).getData(); try { aligner.writePairsToTMX(file, MutableBead.beadsToEntries(aligner.srcLang, aligner.trgLang, beads)); modified = false; } catch (Exception ex) { Log.log(ex); JOptionPane.showMessageDialog(frame, OStrings.getString("ALIGNER_PANEL_SAVE_ERROR"), OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE); } } break; } } }; panel.saveButton.addActionListener(saveListener); frame.saveItem.addActionListener(saveListener); ActionListener resetListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (confirmReset(frame)) { if (phase == Phase.ALIGN) { aligner.restoreDefaults(); } reloadBeads(); } } }; panel.resetButton.addActionListener(resetListener); frame.resetItem.addActionListener(resetListener); ActionListener reloadListener = e -> { if (confirmReset(frame)) { aligner.clearLoaded(); reloadBeads(); } }; frame.reloadItem.addActionListener(reloadListener); ActionListener removeTagsListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean newValue = ((AbstractButton) e.getSource()).isSelected(); if (newValue != aligner.removeTags && confirmReset(frame)) { aligner.removeTags = newValue; aligner.clearLoaded(); reloadBeads(); } else { panel.removeTagsCheckBox.setSelected(aligner.removeTags); frame.removeTagsItem.setSelected(aligner.removeTags); } } }; panel.removeTagsCheckBox.addActionListener(removeTagsListener); frame.removeTagsItem.addActionListener(removeTagsListener); panel.continueButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { phase = Phase.EDIT; updatePanel(); } }); ActionListener highlightListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doHighlight = ((AbstractButton) e.getSource()).isSelected(); updateHighlight(); } }; panel.highlightCheckBox.addActionListener(highlightListener); frame.highlightItem.addActionListener(highlightListener); ActionListener highlightPatternListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PatternPanelController patternEditor = new PatternPanelController(highlightPattern); highlightPattern = patternEditor.show(frame); Preferences.setPreference(Preferences.ALIGNER_HIGHLIGHT_PATTERN, highlightPattern.pattern()); updateHighlight(); } }; panel.highlightPatternButton.addActionListener(highlightPatternListener); frame.highlightPatternItem.addActionListener(highlightPatternListener); frame.markAcceptedItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setStatus(MutableBead.Status.ACCEPTED, panel.table.getSelectedRows()); } }); frame.markNeedsReviewItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setStatus(MutableBead.Status.NEEDS_REVIEW, panel.table.getSelectedRows()); } }); frame.clearMarkItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setStatus(MutableBead.Status.DEFAULT, panel.table.getSelectedRows()); } }); frame.toggleSelectedItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleEnabled(panel.table.getSelectedRows()); } }); frame.closeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeFrame(frame); } }); frame.keepAllItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleAllEnabled(true); } }); frame.keepNoneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleAllEnabled(false); } }); frame.realignPendingItem.addActionListener(e -> { realignPending(); }); frame.pinpointAlignStartItem.addActionListener(e -> { phase = Phase.PINPOINT; ppRow = panel.table.getSelectedRow(); ppCol = panel.table.getSelectedColumn(); panel.table.clearSelection(); updatePanel(); }); frame.pinpointAlignEndItem.addActionListener(e -> { pinpointAlign(panel.table.getSelectedRow(), panel.table.getSelectedColumn()); }); frame.pinpointAlignCancelItem.addActionListener(e -> { phase = Phase.EDIT; ppRow = -1; ppCol = -1; panel.table.repaint(); updatePanel(); }); panel.table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (phase == Phase.PINPOINT) { JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); int col = table.columnAtPoint(e.getPoint()); pinpointAlign(row, col); } } }); frame.resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | KeyEvent.SHIFT_DOWN_MASK)); frame.realignPendingItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); frame.saveItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); frame.closeItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); // emacs-like keys for table navigation // See javax.swing.plaf.BasicTableUI.Actions for supported action names. setKeyboardShortcut(panel.table, "selectNextRow", 'n'); setKeyboardShortcut(panel.table, "selectNextRowExtendSelection", 'N'); setKeyboardShortcut(panel.table, "selectPreviousRow", 'p'); setKeyboardShortcut(panel.table, "selectPreviousRowExtendSelection", 'P'); setKeyboardShortcut(panel.table, "selectNextColumn", 'f'); setKeyboardShortcut(panel.table, "selectNextColumnExtendSelection", 'F'); setKeyboardShortcut(panel.table, "selectPreviousColumn", 'b'); setKeyboardShortcut(panel.table, "selectPreviousColumnExtendSelection", 'B'); panel.table.setTransferHandler(new AlignTransferHandler()); panel.table.addPropertyChangeListener("dropLocation", new DropLocationListener()); if (Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) { try { String fontName = Preferences.getPreference(Preferences.TF_SRC_FONT_NAME); int fontSize = Integer.parseInt(Preferences.getPreference(Preferences.TF_SRC_FONT_SIZE)); panel.table.setFont(new Font(fontName, Font.PLAIN, fontSize)); } catch (Exception e) { Log.log(e); } } // Set initial state updateHighlight(); updatePanel(); reloadBeads(); frame.add(panel); frame.pack(); frame.setMinimumSize(frame.getSize()); frame.setLocationRelativeTo(parent); frame.setVisible(true); }
From source file:org.omegat.gui.dialogs.LogDialog.java
private void saveAsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsButtonActionPerformed String curDir = Preferences.getPreferenceDefault(Preferences.CURRENT_FOLDER, System.getProperty("user.home")); JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(new File(curDir, Log.getLogFileName())); if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) { return;//from ww w. j ava 2s. c o m } File outFile = chooser.getSelectedFile(); if (outFile.exists() && !FileCollisionDialog.promptToReplace(this, outFile.getName())) { return; } try { FileUtils.copyFile(new File(Log.getLogFilePath()), chooser.getSelectedFile()); } catch (IOException ex) { Log.log(ex); } Preferences.setPreference(Preferences.CURRENT_FOLDER, outFile.getParent()); }
From source file:org.panbox.desktop.common.vfs.backend.dropbox.DropboxClientIntegration.java
@Override public File getCurrentSyncDir() throws IOException { Settings settings = Settings.getInstance(); File f = new File(settings.getDropboxSynchronizationDir()); if (!f.exists() || !f.isDirectory()) { // FIXME: this should be handled in a dedicated pane for // CSP-specific settings int res = JOptionPane.showConfirmDialog(null, bundle.getString("DropboxClientIntegration.configureDropboxDir"), bundle.getString("DropboxClientIntegration.syncDirLookup"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { f = readSyncDirFromMetadata(); JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(bundle.getString("DropboxClientIntegration.syncDir")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setSelectedFile(f); int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { f = chooser.getSelectedFile(); if (f.exists() && f.isDirectory()) { settings.setDropboxSynchronizationDir(f.getAbsolutePath()); settings.flush();/* w w w .j a v a2 s .com*/ return f; } } } } else { return f; } return null; }
From source file:org.parosproxy.paros.control.MenuFileControl.java
public void saveAsSession() { if (!informStopActiveActions()) { return;/*from w ww .jav a2 s . c om*/ } Session session = model.getSession(); JFileChooser chooser = new JFileChooser(model.getOptionsParam().getUserDirectory()); // ZAP: set session name as file name proposal File fileproposal = new File(session.getSessionName()); if (session.getFileName() != null && session.getFileName().trim().length() > 0) { // if there is already a file name, use it fileproposal = new File(session.getFileName()); } chooser.setSelectedFile(fileproposal); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().endsWith(".session")) { return true; } return false; } @Override public String getDescription() { // ZAP: Rebrand return Constant.messages.getString("file.format.zap.session"); } }); File file = null; int rc = chooser.showSaveDialog(view.getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file == null) { return; } model.getOptionsParam().setUserDirectory(chooser.getCurrentDirectory()); String fileName = file.getAbsolutePath(); if (!fileName.endsWith(".session")) { fileName += ".session"; } try { waitMessageDialog = view .getWaitMessageDialog(Constant.messages.getString("menu.file.savingSession")); // ZAP: i18n control.saveSession(fileName, this); log.info("save as session file " + session.getFileName()); waitMessageDialog.setVisible(true); } catch (Exception e) { log.error(e.getMessage(), e); } } }