private void setupDirectorySelection(JPanel panel) { JLabel lblScriptsDirectory = new JLabel(OStrings.getString("SCW_SCRIPTS_FOLDER")); panel.add(lblScriptsDirectory); m_txtScriptsDir = new JTextField(); panel.add(m_txtScriptsDir); if (m_scriptsDirectory != null) { m_txtScriptsDir.setText(m_scriptsDirectory.getPath()); } m_txtScriptsDir.setColumns(40); m_txtScriptsDir.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { directoryTextFieldActionPerformed(evt); } }); JButton btnBrowse = new JButton(); Mnemonics.setLocalizedText(btnBrowse, OStrings.getString("SCW_SCRIPTS_FOLDER_CHOOSE")); btnBrowse.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { directoryChooserButtonActionPerformed(evt); } }); panel.add(btnBrowse); }
/** Displays the filters setup dialog to allow customizing file filters in detail. */ public void optionsSetupFileFiltersMenuItemActionPerformed() { FiltersCustomizer dlg = new FiltersCustomizer( mainWindow, false, FilterMaster.createDefaultFiltersConfig(), FilterMaster.loadConfig(StaticUtils.getConfigDir()), null); dlg.setVisible(true); if (dlg.getReturnStatus() == FiltersCustomizer.RET_OK) { // saving config FilterMaster.saveConfig(dlg.result, StaticUtils.getConfigDir()); if (Core.getProject().isProjectLoaded()) { if (FilterMaster.loadConfig(Core.getProject().getProjectProperties().getProjectInternal()) != null) { // project specific filters are in place. No need to reload project when // non-project-specific filters are changed return; } // asking to reload a project int res = JOptionPane.showConfirmDialog( mainWindow, OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) ProjectUICommands.projectReload(); } } }
public String getName() { if (mvYandexKey == null) { return OStrings.getString("MT_ENGINE_YANDEX_KEY_NOTFOUND"); } else { return OStrings.getString("MT_ENGINE_YANDEX"); } }
/** Quits OmegaT */ public void projectExitMenuItemActionPerformed() { boolean projectModified = false; if (Core.getProject().isProjectLoaded()) projectModified = Core.getProject().isProjectModified(); // RFE 1302358 // Add Yes/No Warning before OmegaT quits if (projectModified || Preferences.isPreference(Preferences.ALWAYS_CONFIRM_QUIT)) { if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog( mainWindow, OStrings.getString("MW_QUIT_CONFIRM"), OStrings.getString("CONFIRM_DIALOG_TITLE"), JOptionPane.YES_NO_OPTION)) { return; } } flushExportedSegments(); new SwingWorker<Object, Void>() { @Override protected Object doInBackground() throws Exception { if (Core.getProject().isProjectLoaded()) { // Save the list of learned and ignore words ISpellChecker sc = Core.getSpellChecker(); sc.saveWordLists(); try { Core.getProject().saveProject(); } catch (KnownException ex) { // hide exception on shutdown } } CoreEvents.fireApplicationShutdown(); PluginUtils.unloadPlugins(); return null; } @Override protected void done() { try { get(); MainWindowUI.saveScreenLayout(mainWindow); Preferences.save(); System.exit(0); } catch (Exception ex) { Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } } }.execute(); }
private void mapDeleteButtonActionPerformed( java.awt.event.ActionEvent evt) // GEN-FIRST:event_mapDeleteButtonActionPerformed { // GEN-HEADEREND:event_mapDeleteButtonActionPerformed commitTableEdits(); MappingRulesModel model = (MappingRulesModel) mapTable.getModel(); String set = model.getValueAt(mapTable.getSelectedRow(), 0).toString(); String title = OStrings.getString("CONFIRM_DIALOG_TITLE"); String message = StringUtil.format(OStrings.getString("SEG_CONFIRM_REMOVE_SENTSEG_SET"), set); if (JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) model.removeRow(mapTable.getSelectedRow()); } // GEN-LAST:event_mapDeleteButtonActionPerformed
private void runQuickScript(int index) { if (m_quickScripts[index] == null) { logResult(OStrings.getString("SCW_NO_SCRIPT_SELECTED")); return; } logResult(StaticUtils.format(OStrings.getString("SCW_QUICK_RUN"), (index + 1))); ScriptItem scriptFile = new ScriptItem(new File(m_scriptsDirectory, m_quickScripts[index])); executeScriptFile(scriptFile, true); }
public void executeScriptFile( ScriptItem scriptItem, boolean forceFromFile, Map<String, Object> additionalBindings) { ScriptLogger scriptLogger = new ScriptLogger(m_txtResult); ScriptEngine scriptEngine = manager.getEngineByExtension(getFileExtension(scriptItem.getName())); if (scriptEngine == null) { scriptEngine = manager.getEngineByName(DEFAULT_SCRIPT); } // logResult(StaticUtils.format(OStrings.getString("SCW_SELECTED_LANGUAGE"), // scriptEngine.getFactory().getEngineName())); SimpleBindings bindings = new SimpleBindings(); bindings.put(VAR_PROJECT, Core.getProject()); bindings.put(VAR_EDITOR, Core.getEditor()); bindings.put(VAR_GLOSSARY, Core.getGlossary()); bindings.put(VAR_MAINWINDOW, Core.getMainWindow()); bindings.put(VAR_CONSOLE, scriptLogger); bindings.put(VAR_RESOURCES, scriptItem.getResourceBundle()); if (additionalBindings != null) { bindings.putAll(additionalBindings); } // evaluate JavaScript code from String try { String scriptString; if (forceFromFile) { scriptString = scriptItem.getText(); } else if ("".equals(m_txtScriptEditor.getText().trim())) { scriptString = scriptItem.getText(); m_txtScriptEditor.setText(scriptString); } else { scriptString = m_txtScriptEditor.getText(); } if (!scriptString.endsWith("\n")) { scriptString += "\n"; } Object eval = scriptEngine.eval(scriptString, bindings); if (eval != null) { logResult(OStrings.getString("SCW_SCRIPT_RESULT")); logResult(eval.toString()); } } catch (Throwable e) { logResult(OStrings.getString("SCW_SCRIPT_ERROR")); logResult(e.getMessage()); // e.printStackTrace(); } }
/** * Reads next line from the input and: * * <ul> * <li>Converts ascii-encoded \\uxxxx chars to normal characters. * <li>Converts \r, \n and \t to CR, line feed and tab. * <li>But! Keeps a backspace in '\ ', '\=', '\:' etc (non-trimmable space or * non-key-value-breaking :-) equals). * <ul> * Change from BufferedReader to LinebreakPreservingReader was part of fix for bug 1462566 */ protected String getNextLine(LinebreakPreservingReader reader) throws IOException, TranslationException { String ascii = reader.readLine(); if (ascii == null) { return null; } StringBuilder result = new StringBuilder(); for (int cp, len = ascii.length(), i = 0; i < len; i += Character.charCount(cp)) { cp = ascii.codePointAt(i); if (cp == '\\' && ascii.codePointCount(i, len) > 1) { i += Character.charCount(cp); cp = ascii.codePointAt(i); if (cp != 'u') { if (cp == 'n') { cp = '\n'; } else if (cp == 'r') { cp = '\r'; } else if (cp == 't') { cp = '\t'; } else { result.append('\\'); } } else if (dontUnescapeULiterals) { // Put back the \ we swallowed result.append('\\'); } else { // checking if the string is long enough if (ascii.codePointCount(i, len) < 1 + 4) { throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE")); } int uStart = ascii.offsetByCodePoints(i, 1); int uEnd = ascii.offsetByCodePoints(uStart, 4); String uStr = ascii.substring(uStart, uEnd); try { cp = Integer.parseInt(uStr, 16); if (!Character.isValidCodePoint(cp)) { throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE")); } i = uEnd - Character.charCount(cp); } catch (NumberFormatException ex) { throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE"), ex); } } } result.appendCodePoint(cp); } return result.toString(); }
/** Prompt the user to reload the current project */ public static void promptReload() { if (!Core.getProject().isProjectLoaded()) { return; } // asking to reload a project int res = JOptionPane.showConfirmDialog( Core.getMainWindow().getApplicationFrame(), OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { projectReload(); } }
private void addScriptCommandToOmegaT() { JMenu toolsMenu = Core.getMainWindow().getMainMenu().getToolsMenu(); toolsMenu.add(new JSeparator()); JMenuItem scriptMenu = new JMenuItem(); Mnemonics.setLocalizedText(scriptMenu, OStrings.getString("TF_MENU_TOOLS_SCRIPTING")); scriptMenu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ScriptingWindow.this.setVisible(true); } }); toolsMenu.add(scriptMenu); for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) { JMenuItem menuItem = new JMenuItem(); m_quickMenus[i] = menuItem; String scriptName = Preferences.getPreferenceDefault("scripts_quick_" + scriptKey(i), null); if (scriptName != null || "".equals(scriptName)) { setQuickScriptMenu(new ScriptItem(new File(m_scriptsDirectory, scriptName)), i); } else { unsetQuickScriptMenu(i); } // Since the script is run while editing a segment, the shortcut should not interfere // with the segment content, so we set it to a Function key. m_quickMenus[i].setAccelerator(KeyStroke.getKeyStroke("shift ctrl F" + (i + 1))); toolsMenu.add(menuItem); } }
/** Displays the external TMX dialog to allow customizing the external TMX options. */ public void optionsExtTMXMenuItemActionPerformed() { ExternalTMXMatchesDialog externalTMXOptions = new ExternalTMXMatchesDialog(mainWindow); externalTMXOptions.setVisible(true); if (externalTMXOptions.getReturnStatus() == ExternalTMXMatchesDialog.RET_OK && Core.getProject().isProjectLoaded()) { // asking to reload a project int res = JOptionPane.showConfirmDialog( mainWindow, OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) ProjectUICommands.projectReload(); } }
private void unsetQuickScriptMenu(int index) { m_quickScripts[index] = null; removeAllQuickScriptActionListenersFrom(m_quickMenus[index]); m_quickMenus[index].setEnabled(false); Mnemonics.setLocalizedText( m_quickMenus[index], "&" + scriptKey(index) + " - " + OStrings.getString("SCW_SCRIPTS_NONE")); }
/** * This is a pane that displays notes on translation units. * * @author Martin Fleurke * @author Aaron Madlon-Kay */ @SuppressWarnings("serial") public class NotesTextArea extends EntryInfoPane<String> implements INotes { private static final String EXPLANATION = OStrings.getString("GUI_NOTESWINDOW_explanation"); SourceTextEntry ste; /** Creates new Notes Text Area Pane */ public NotesTextArea(MainWindow mw) { super(true); String title = OStrings.getString("GUI_NOTESWINDOW_SUBWINDOWTITLE_Notes"); Core.getMainWindow().addDockable(new DockableScrollPane("NOTES", title, this, true)); setEditable(false); setText(EXPLANATION); setMinimumSize(new Dimension(100, 50)); JTextPaneLinkifier.linkify(this); } @Override protected void onProjectOpen() { clear(); } @Override protected void onProjectClose() { clear(); setText(EXPLANATION); } /** Clears up the pane. */ public void clear() { UIThreadsUtil.mustBeSwingThread(); setText(""); setEditable(false); ste = null; } public void setNoteText(String text) { UIThreadsUtil.mustBeSwingThread(); setText(text); setEditable(true); } public String getNoteText() { UIThreadsUtil.mustBeSwingThread(); String text = getText(); // Disallow empty note. Use null to indicate lack of note. return text.isEmpty() ? null : text; } }
private void runScript() { if (m_currentScriptItem == null) { logResult(OStrings.getString("SCW_NO_SCRIPT_SELECTED")); return; } if (!m_currentScriptItem.canRead()) { logResult(OStrings.getString("SCW_CANNOT_READ_SCRIPT")); return; } m_txtResult.setText(""); logResult( StaticUtils.format( OStrings.getString("SCW_RUNNING_SCRIPT"), m_currentScriptItem.getAbsolutePath())); executeScriptFile(m_currentScriptItem, false); }
private void constructor(boolean projectSpecific, SRX defaultSRX, SRX userSRX, SRX projectSRX) { this.isProjectSpecific = projectSpecific; this.defaultSRX = defaultSRX; this.userSRX = userSRX; this.projectSRX = projectSRX; this.editableSRX = isProjectSpecific && projectSRX != null ? projectSRX.clone() : userSRX.clone(); StaticUIUtils.setEscapeAction( this, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancelButtonActionPerformed(null); } }); initComponents(); getRootPane().setDefaultButton(okButton); mapTable.getSelectionModel().addListSelectionListener(this); ruleTable.getSelectionModel().addListSelectionListener(this); MappingRulesModel model = (MappingRulesModel) mapTable.getModel(); model.addExceptionListener( new ExceptionListener() { @Override public void exceptionThrown(Exception e) { mapErrorsLabel.setText(e.getLocalizedMessage()); } }); if (isProjectSpecific) { setTitle(OStrings.getString("GUI_SEGMENTATION_TITLE_PROJECTSPECIFIC")); // NOI18N } else { projectSpecificCB.setVisible(false); } if (projectSpecific && projectSRX == null) { mapTable.setEnabled(false); mapTable.setFocusable(false); mapInsertButton.setEnabled(false); toDefaultsButton.setEnabled(false); } else { if (projectSpecific) projectSpecificCB.setSelected(true); mapTable.setEnabled(true); mapTable.setFocusable(true); mapInsertButton.setEnabled(true); toDefaultsButton.setEnabled(true); } pack(); setSize(getWidth() * 5 / 4, getHeight() * 5 / 4); DockingUI.displayCentered(this); }
/** * Displays the segmentation setup dialog to allow customizing the segmentation rules in detail. */ public void optionsSentsegMenuItemActionPerformed() { SegmentationCustomizer segment_window = new SegmentationCustomizer(mainWindow, false, SRX.getDefault(), Preferences.getSRX(), null); segment_window.setVisible(true); if (segment_window.getReturnStatus() == SegmentationCustomizer.RET_OK) { Preferences.setSRX(segment_window.getSRX()); if (Core.getProject().isProjectLoaded() && Core.getProject().getProjectProperties().getProjectSRX() == null) { // asking to reload a project int res = JOptionPane.showConfirmDialog( mainWindow, OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) ProjectUICommands.projectReload(); } } }
private void directoryChooserButtonActionPerformed(java.awt.event.ActionEvent evt) { // open a dialog box to choose the directory m_fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); m_fileChooser.setDialogTitle(OStrings.getString("SCW_SCRIPTS_FOLDER_CHOOSE_TITLE")); int result = m_fileChooser.showOpenDialog(ScriptingWindow.this); if (result == JFileChooser.APPROVE_OPTION) { // we should write the result into the directory text field File file = m_fileChooser.getSelectedFile(); setScriptsDirectory(file); } }
/** Does wikiread */ public static void doWikiImport() { String remote_url = JOptionPane.showInputDialog( Core.getMainWindow().getApplicationFrame(), OStrings.getString("TF_WIKI_IMPORT_PROMPT"), OStrings.getString("TF_WIKI_IMPORT_TITLE"), JOptionPane.OK_CANCEL_OPTION); String projectsource = Core.getProject().getProjectProperties().getSourceRoot(); if (remote_url == null || remote_url.trim().isEmpty()) { // [1762625] Only try to get MediaWiki page if a string has been entered return; } try { WikiGet.doWikiGet(remote_url, projectsource); projectReload(); } catch (Exception ex) { Log.log(ex); Core.getMainWindow().displayErrorRB(ex, "TF_WIKI_IMPORT_FAILED"); } }
private void onListSelectionChanged() { if (m_scriptList.isSelectionEmpty()) { return; } try { m_currentScriptItem = (ScriptItem) m_scriptList.getSelectedValue(); m_txtScriptEditor.setText(m_currentScriptItem.getText()); m_txtScriptEditor.setCaretPosition(0); } catch (IOException e) { logResult(OStrings.getString("SCW_CANNOT_READ_SCRIPT")); } }
/** Imports the file/files/folder into project's source files. */ public static void doPromptImportSourceFiles() { OmegaTFileChooser chooser = new OmegaTFileChooser(); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setDialogTitle(OStrings.getString("TF_FILE_IMPORT_TITLE")); int result = chooser.showOpenDialog(Core.getMainWindow().getApplicationFrame()); if (result == OmegaTFileChooser.APPROVE_OPTION) { File[] selFiles = chooser.getSelectedFiles(); projectImportFiles(Core.getProject().getProjectProperties().getSourceRoot(), selFiles); } }
/** Creates new Notes Text Area Pane */ public NotesTextArea(MainWindow mw) { super(true); String title = OStrings.getString("GUI_NOTESWINDOW_SUBWINDOWTITLE_Notes"); Core.getMainWindow().addDockable(new DockableScrollPane("NOTES", title, this, true)); setEditable(false); setText(EXPLANATION); setMinimumSize(new Dimension(100, 50)); JTextPaneLinkifier.linkify(this); }
/** Create translated documents. */ public void projectCompileMenuItemActionPerformed() { if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { List<ErrorReport> stes = Core.getTagValidation().listInvalidTags(); if (stes != null) { Core.getTagValidation() .displayTagValidationErrors(stes, OStrings.getString("TF_MESSAGE_COMPILE")); return; } } ProjectUICommands.projectCompile(); }
/** * Displays the tag validation setup dialog to allow customizing the diverse tag validation * options. */ public void optionsTagValidationMenuItemActionPerformed() { TagProcessingOptionsDialog tagProcessingOptionsDialog = new TagProcessingOptionsDialog(mainWindow); tagProcessingOptionsDialog.setVisible(true); if (tagProcessingOptionsDialog.getReturnStatus() == TagProcessingOptionsDialog.RET_OK && Core.getProject().isProjectLoaded()) { // Redisplay according to new view settings Core.getEditor().getSettings().updateTagValidationPreferences(); // asking to reload a project int res = JOptionPane.showConfirmDialog( mainWindow, OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { ProjectUICommands.projectReload(); } } }
@Override public Map<String, String> changeOptions(Dialog parent, Map<String, String> config) { try { ResourceBundleOptionsDialog dialog = new ResourceBundleOptionsDialog(parent, config); dialog.setVisible(true); if (ResourceBundleOptionsDialog.RET_OK == dialog.getReturnStatus()) return dialog.getOptions(); else return null; } catch (Exception e) { Log.log(OStrings.getString("RB_FILTER_EXCEPTION")); Log.log(e); return null; } }
private StringBuilder listScriptEngine() { StringBuilder sb = new StringBuilder(OStrings.getString("SCW_LIST_ENGINES") + "\n"); for (ScriptEngineFactory engine : manager.getEngineFactories()) { sb.append(" - "); sb.append(engine.getEngineName()); sb.append(" "); sb.append(engine.getLanguageName()); sb.append(" v."); sb.append(engine.getLanguageVersion()); sb.append(" (").append(OStrings.getString("SCW_EXTENSIONS")).append(" "); boolean hasMore = false; for (String ext : engine.getExtensions()) { if (hasMore) { sb.append(", "); } sb.append(ext); hasMore = true; } sb.append(")"); sb.append("\n"); } return sb; }
/** Create current translated document. */ public void projectSingleCompileMenuItemActionPerformed() { String midName = Core.getEditor().getCurrentFile(); if (StringUtil.isEmpty(midName)) { return; } String sourcePattern = StaticUtils.escapeNonRegex(midName); if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { List<ErrorReport> stes = Core.getTagValidation().listInvalidTags(sourcePattern); if (stes != null) { Core.getTagValidation() .displayTagValidationErrors(stes, OStrings.getString("TF_MESSAGE_COMPILE")); return; } } ProjectUICommands.projectSingleCompile(sourcePattern); }
public ScriptingWindow() { setTitle(OStrings.getString("SCW_TITLE")); OmegaTIcons.setIconImages(this); StaticUIUtils.setEscapeClosable(this); setScriptsDirectory( Preferences.getPreferenceDefault(Preferences.SCRIPTS_DIRECTORY, DEFAULT_SCRIPTS_DIR)); addScriptCommandToOmegaT(); addRunShortcutToOmegaT(); initWindowLayout(); monitor = new ScriptsMonitor(this, m_scriptList, getAvailableScriptExtensions()); if (m_scriptsDirectory != null) { monitor.start(m_scriptsDirectory); } logResult(listScriptEngine().toString()); }
public static void projectEditProperties() { UIThreadsUtil.mustBeSwingThread(); if (!Core.getProject().isProjectLoaded()) { return; } // commit the current entry first Core.getEditor().commitAndLeave(); // displaying the dialog to change paths and other properties ProjectPropertiesDialog prj = new ProjectPropertiesDialog( Core.getMainWindow().getApplicationFrame(), Core.getProject().getProjectProperties(), Core.getProject().getProjectProperties().getProjectName(), ProjectPropertiesDialog.Mode.EDIT_PROJECT); prj.setVisible(true); final ProjectProperties newProps = prj.getResult(); prj.dispose(); if (newProps == null) { return; } int res = JOptionPane.showConfirmDialog( Core.getMainWindow().getApplicationFrame(), OStrings.getString("MW_REOPEN_QUESTION"), OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { return; } new SwingWorker<Object, Void>() { int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber(); protected Object doInBackground() throws Exception { Core.executeExclusively( true, () -> { Core.getProject().saveProject(true); ProjectFactory.closeProject(); ProjectFactory.loadProject(newProps, true); }); return null; } protected void done() { try { get(); // Make sure to update Editor title SwingUtilities.invokeLater( () -> { // activate entry later - after project will be loaded Core.getEditor().gotoEntry(previousCurEntryNum); Core.getEditor().requestFocus(); }); } catch (Exception ex) { processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); } } }.execute(); }
private void setupRunButtons(JPanel panel) { m_btnRunScript = new JButton(); Mnemonics.setLocalizedText(m_btnRunScript, OStrings.getString("SCW_RUN_SCRIPT")); m_btnRunScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnRunScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnRunScript.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent a) { runScript(); } }); panel.add(m_btnRunScript); for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) { final int index = i; final int scriptKey = scriptKey(index); m_quickScriptButtons[i] = new JButton("" + scriptKey + ""); String scriptName = Preferences.getPreferenceDefault("scripts_quick_" + scriptKey, null); if (scriptName != null || "".equals(scriptName)) { m_quickScriptButtons[i].setToolTipText(scriptName); m_quickScriptButtons[i].setText("<" + scriptKey + ">"); } else { m_quickScriptButtons[i].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET")); } // Run a script from the quick button bar m_quickScriptButtons[i].addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent a) { if (Preferences.existsPreference("scripts_quick_" + scriptKey)) { runQuickScript(index); } else { logResult(StaticUtils.format(OStrings.getString("SCW_NO_SCRIPT_BOUND"), scriptKey)); } } }); JPopupMenu quickScriptPopup = new JPopupMenu(); // Add a script to the quick script button bar final JMenuItem addQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_ADD_SCRIPT")); addQuickScriptMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { ScriptItem scriptItem = (ScriptItem) m_scriptList.getSelectedValue(); Preferences.setPreference("scripts_quick_" + scriptKey, scriptItem.getName()); m_quickScriptButtons[index].setToolTipText(scriptItem.getToolTip()); m_quickScriptButtons[index].setText("<" + scriptKey + ">"); setQuickScriptMenu(scriptItem, index); logResult( StaticUtils.format( OStrings.getString("SCW_SAVE_QUICK_SCRIPT"), scriptItem, scriptKey)); } }); quickScriptPopup.add(addQuickScriptMenuItem); // Remove a script from the button bar final JMenuItem removeQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_REMOVE_SCRIPT")); removeQuickScriptMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String scriptName = Preferences.getPreferenceDefault("scripts_quick_" + scriptKey, "(unknown)"); logResult( StaticUtils.format( OStrings.getString("SCW_REMOVED_QUICK_SCRIPT"), scriptName, scriptKey)); Preferences.setPreference("scripts_quick_" + scriptKey, ""); m_quickScriptButtons[index].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET")); m_quickScriptButtons[index].setText(" " + scriptKey + " "); unsetQuickScriptMenu(index); } }); quickScriptPopup.add(removeQuickScriptMenuItem); quickScriptPopup.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // Disable add a script command if script selection empty addQuickScriptMenuItem.setEnabled(!m_scriptList.isSelectionEmpty()); // Disable remove a script command if the quick run button is not bounded String scriptName = Preferences.getPreferenceDefault("scripts_quick_" + scriptKey, null); removeQuickScriptMenuItem.setEnabled(!StringUtil.isEmpty(scriptName)); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // do nothing } @Override public void popupMenuCanceled(PopupMenuEvent e) { // do nothing } }); m_quickScriptButtons[i].setComponentPopupMenu(quickScriptPopup); panel.add(m_quickScriptButtons[i]); } }
private void initWindowLayout() { loadPreferences(); getContentPane().setLayout(new BorderLayout(0, 0)); JPanel panelNorth = new JPanel(); FlowLayout fl_panelNorth = (FlowLayout) panelNorth.getLayout(); fl_panelNorth.setAlignment(FlowLayout.LEFT); getContentPane().add(panelNorth, BorderLayout.NORTH); setupDirectorySelection(panelNorth); m_scriptList = new JList(); JScrollPane scrollPaneList = new JScrollPane(m_scriptList); m_scriptList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { onListSelectionChanged(); } } }); m_txtResult = new JEditorPane(); JScrollPane scrollPaneResults = new JScrollPane(m_txtResult); m_txtScriptEditor = new JTextArea(); // m_txtScriptEditor.setEditable(false); JPopupMenu editorPopUp = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(OStrings.getString("SCW_SAVE_SCRIPT")); menuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); menuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { m_currentScriptItem.setText(m_txtScriptEditor.getText()); logResult( StaticUtils.format( OStrings.getString("SCW_SAVE_OK"), m_currentScriptItem.getAbsolutePath())); } catch (IOException e) { logResult(OStrings.getString("SCW_SAVE_ERROR")); logResult(e.getMessage()); } } }); editorPopUp.add(menuItem); m_txtScriptEditor.setComponentPopupMenu(editorPopUp); m_txtScriptEditor.setFont( new Font(Font.MONOSPACED, Font.PLAIN, m_txtScriptEditor.getFont().getSize())); JScrollPane scrollPaneEditor = new JScrollPane(m_txtScriptEditor); JSplitPane splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPaneEditor, scrollPaneResults); splitPane1.setOneTouchExpandable(true); splitPane1.setDividerLocation(430); Dimension minimumSize1 = new Dimension(100, 50); scrollPaneEditor.setMinimumSize(minimumSize1); scrollPaneResults.setMinimumSize(minimumSize1); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPaneList, splitPane1); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); Dimension minimumSize = new Dimension(100, 50); scrollPaneList.setMinimumSize(minimumSize); scrollPaneResults.setMinimumSize(minimumSize); getContentPane().add(splitPane, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); FlowLayout fl_panelSouth = (FlowLayout) panelSouth.getLayout(); fl_panelSouth.setAlignment(FlowLayout.LEFT); getContentPane().add(panelSouth, BorderLayout.SOUTH); setupRunButtons(panelSouth); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); }