Search in sources :

Example 11 with FilterMaster

use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.

the class AlignPanelController method show.

/**
 * Display the align tool. The tool is not modal, so this call will return immediately.
 *
 * @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() & Java8Compat.getMenuShortcutKeyMaskEx()) != 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, Java8Compat.getMenuShortcutKeyMaskEx() | KeyEvent.SHIFT_DOWN_MASK));
    frame.realignPendingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Java8Compat.getMenuShortcutKeyMaskEx()));
    frame.saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Java8Compat.getMenuShortcutKeyMaskEx()));
    frame.closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Java8Compat.getMenuShortcutKeyMaskEx()));
    // 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);
}
Also used : Color(java.awt.Color) DropLocation(javax.swing.JTable.DropLocation) Arrays(java.util.Arrays) SRX(org.omegat.core.segmentation.SRX) Cursor(java.awt.Cursor) Styles(org.omegat.util.gui.Styles) MatteBorder(javax.swing.border.MatteBorder) TableCellRenderer(javax.swing.table.TableCellRenderer) StyledDocument(javax.swing.text.StyledDocument) Border(javax.swing.border.Border) FiltersCustomizer(org.omegat.gui.filters2.FiltersCustomizer) Matcher(java.util.regex.Matcher) StringUtil(org.omegat.util.StringUtil) Core(org.omegat.core.Core) CalculatorType(org.omegat.gui.align.Aligner.CalculatorType) Filters(gen.core.filters.Filters) MouseAdapter(java.awt.event.MouseAdapter) CompoundBorder(javax.swing.border.CompoundBorder) SwingWorker(javax.swing.SwingWorker) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JFileChooser(javax.swing.JFileChooser) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AttributeSet(javax.swing.text.AttributeSet) CounterType(org.omegat.gui.align.Aligner.CounterType) KeyStroke(javax.swing.KeyStroke) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) CancellationException(java.util.concurrent.CancellationException) Font(java.awt.Font) ComparisonMode(org.omegat.gui.align.Aligner.ComparisonMode) MissingResourceException(java.util.MissingResourceException) FilterMaster(org.omegat.filters2.master.FilterMaster) ComponentEvent(java.awt.event.ComponentEvent) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) SegmentationCustomizer(org.omegat.gui.segmentation.SegmentationCustomizer) JCheckBox(javax.swing.JCheckBox) JTable(javax.swing.JTable) EmptyBorder(javax.swing.border.EmptyBorder) RoundedCornerBorder(org.omegat.util.gui.RoundedCornerBorder) Pattern(java.util.regex.Pattern) Preferences(org.omegat.util.Preferences) WindowConstants(javax.swing.WindowConstants) FilenameUtils(org.apache.commons.io.FilenameUtils) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) ActionListener(java.awt.event.ActionListener) DataFlavor(java.awt.datatransfer.DataFlavor) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Log(org.omegat.util.Log) Transferable(java.awt.datatransfer.Transferable) StyleConstants(javax.swing.text.StyleConstants) ProjectUICommands(org.omegat.gui.main.ProjectUICommands) ArrayList(java.util.ArrayList) SwingUtilities(javax.swing.SwingUtilities) TransferHandler(javax.swing.TransferHandler) OStrings(org.omegat.util.OStrings) AbstractTableModel(javax.swing.table.AbstractTableModel) JTextPane(javax.swing.JTextPane) AbstractButton(javax.swing.AbstractButton) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) Segmenter(org.omegat.core.segmentation.Segmenter) JButton(javax.swing.JButton) TableColumn(javax.swing.table.TableColumn) IOException(java.io.IOException) Language(org.omegat.util.Language) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ComponentAdapter(java.awt.event.ComponentAdapter) DelegatingComboBoxRenderer(org.omegat.util.gui.DelegatingComboBoxRenderer) AlgorithmClass(org.omegat.gui.align.Aligner.AlgorithmClass) Java8Compat(org.omegat.util.Java8Compat) JLabel(javax.swing.JLabel) Status(org.omegat.gui.align.MutableBead.Status) ListSelectionListener(javax.swing.event.ListSelectionListener) Collections(java.util.Collections) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) WindowAdapter(java.awt.event.WindowAdapter) Font(java.awt.Font) ComparisonMode(org.omegat.gui.align.Aligner.ComparisonMode) AlgorithmClass(org.omegat.gui.align.Aligner.AlgorithmClass) ComponentAdapter(java.awt.event.ComponentAdapter) TableCellRenderer(javax.swing.table.TableCellRenderer) CounterType(org.omegat.gui.align.Aligner.CounterType) AbstractButton(javax.swing.AbstractButton) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) MouseAdapter(java.awt.event.MouseAdapter) Segmenter(org.omegat.core.segmentation.Segmenter) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) CancellationException(java.util.concurrent.CancellationException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) ListSelectionListener(javax.swing.event.ListSelectionListener) SegmentationCustomizer(org.omegat.gui.segmentation.SegmentationCustomizer) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) WindowEvent(java.awt.event.WindowEvent) FilterMaster(org.omegat.filters2.master.FilterMaster) JTable(javax.swing.JTable) ComponentEvent(java.awt.event.ComponentEvent) CalculatorType(org.omegat.gui.align.Aligner.CalculatorType) File(java.io.File) FiltersCustomizer(org.omegat.gui.filters2.FiltersCustomizer)

Example 12 with FilterMaster

use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.

the class AlignFilePickerController method main.

/**
 * Entry point for debugging or standalone use. Optionally accepts four arguments to pre-fill the picker:
 * <ol>
 * <li>Source language
 * <li>Source file path
 * <li>Target language
 * <li>Target file path
 * </ol>
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    Preferences.init();
    PluginUtils.loadPlugins(Collections.emptyMap());
    Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig()));
    Core.setSegmenter(new Segmenter(SRX.getDefault()));
    AlignFilePickerController picker = new AlignFilePickerController();
    if (args.length == 4) {
        picker.sourceLanguage = new Language(args[0]);
        picker.sourceFile = args[1];
        picker.targetLanguage = new Language(args[2]);
        picker.targetFile = args[3];
    }
    picker.show(null);
}
Also used : Language(org.omegat.util.Language) FilterMaster(org.omegat.filters2.master.FilterMaster) Segmenter(org.omegat.core.segmentation.Segmenter)

Example 13 with FilterMaster

use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.

the class AlignFilePickerController method updatePicker.

private void updatePicker(final AlignFilePicker picker) {
    if (sourceFile == null || targetFile == null || sourceLanguage == null || targetLanguage == null) {
        picker.messageTextArea.setText(null);
        picker.okButton.setEnabled(false);
        return;
    }
    final File srcFile = new File(sourceFile);
    final File trgFile = new File(targetFile);
    if (!srcFile.isFile() || !trgFile.isFile() || srcFile.equals(trgFile)) {
        picker.messageTextArea.setText(null);
        picker.okButton.setEnabled(false);
        return;
    }
    new SwingWorker<boolean[], Void>() {

        @Override
        protected boolean[] doInBackground() throws Exception {
            FilterMaster fm = Core.getFilterMaster();
            return new boolean[] { fm.isFileSupported(srcFile, false), fm.isFileSupported(trgFile, false) };
        }

        @Override
        protected void done() {
            boolean enabled = false;
            String message = null;
            try {
                boolean[] results = get();
                enabled = results[0] && results[1];
                if (!results[0] && results[1]) {
                    message = OStrings.getString("ALIGNER_FILEPICKER_ERROR_ONE_FILE", srcFile.getName());
                } else if (results[0] && !results[1]) {
                    message = OStrings.getString("ALIGNER_FILEPICKER_ERROR_ONE_FILE", trgFile.getName());
                } else if (!results[0] && !results[1]) {
                    message = OStrings.getString("ALIGNER_FILEPICKER_ERROR_BOTH_FILES");
                }
            } catch (CancellationException e) {
            // Ignore
            } catch (Exception e) {
                Log.log(e);
                message = e.getLocalizedMessage();
            }
            picker.okButton.setEnabled(enabled);
            picker.messageTextArea.setText(message);
        }
    }.execute();
}
Also used : CancellationException(java.util.concurrent.CancellationException) FilterMaster(org.omegat.filters2.master.FilterMaster) File(java.io.File) CancellationException(java.util.concurrent.CancellationException)

Example 14 with FilterMaster

use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.

the class TestFilterBase method setUpFilterBase.

@Before
public final void setUpFilterBase() throws Exception {
    Core.initializeConsole(Collections.emptyMap());
    Core.setFilterMaster(new FilterMaster(FilterMaster.createDefaultFiltersConfig()));
    Core.setProject(new TestProject(new ProjectPropertiesTest()));
    outFile = new File("build/testdata/OmegaT_test-" + getClass().getName() + "-" + name.getMethodName());
    outFile.getParentFile().mkdirs();
}
Also used : FilterMaster(org.omegat.filters2.master.FilterMaster) File(java.io.File) Before(org.junit.Before)

Example 15 with FilterMaster

use of org.omegat.filters2.master.FilterMaster in project omegat by omegat-org.

the class RealProject method loadFilterSettings.

/**
 * Load filter settings, either from the project or from global options
 */
private void loadFilterSettings() {
    // Set project specific file filters if they exist, or defaults otherwise.
    // This MUST happen before calling loadTranslations() because the setting to ignore file context
    // for alt translations is a filter setting, and it affects how alt translations are hashed.
    Filters filters = Optional.ofNullable(config.getProjectFilters()).orElse(Preferences.getFilters());
    Core.setFilterMaster(new FilterMaster(filters));
}
Also used : Filters(gen.core.filters.Filters) FilterMaster(org.omegat.filters2.master.FilterMaster)

Aggregations

FilterMaster (org.omegat.filters2.master.FilterMaster)16 File (java.io.File)9 Segmenter (org.omegat.core.segmentation.Segmenter)7 IOException (java.io.IOException)4 Before (org.junit.Before)4 FilterContext (org.omegat.filters2.FilterContext)4 RandomAccessFile (java.io.RandomAccessFile)3 Filters (gen.core.filters.Filters)2 CancellationException (java.util.concurrent.CancellationException)2 NotLoadedProject (org.omegat.core.data.NotLoadedProject)2 ISpellChecker (org.omegat.core.spellchecker.ISpellChecker)2 SpellChecker (org.omegat.core.spellchecker.SpellChecker)2 TagValidationTool (org.omegat.core.tagvalidation.TagValidationTool)2 SaveThread (org.omegat.core.threads.SaveThread)2 CommentsTextArea (org.omegat.gui.comments.CommentsTextArea)2 DictionariesTextArea (org.omegat.gui.dictionaries.DictionariesTextArea)2 EditorController (org.omegat.gui.editor.EditorController)2 ComesFromAutoTMMarker (org.omegat.gui.editor.mark.ComesFromAutoTMMarker)2 FontFallbackMarker (org.omegat.gui.editor.mark.FontFallbackMarker)2 NBSPMarker (org.omegat.gui.editor.mark.NBSPMarker)2