Search in sources :

Example 21 with IFilter

use of org.omegat.filters2.IFilter in project omegat by omegat-org.

the class FiltersCustomizerController method initGui.

private void initGui() {
    panel = new FiltersCustomizerPanel();
    panel.filtersTable.setDefaultRenderer(String.class, new FilterFormatCellRenderer());
    panel.filtersTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
        if (lsm.isSelectionEmpty()) {
            panel.editButton.setEnabled(false);
            panel.optionsButton.setEnabled(false);
        } else {
            panel.editButton.setEnabled(true);
            Filter currFilter = getFilterAtRow(panel.filtersTable.getSelectedRow());
            IFilter f = FilterMaster.getFilterInstance(currFilter.getClassName());
            panel.optionsButton.setEnabled(f != null && f.hasOptions());
        }
    });
    panel.filtersTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent me) {
            if (me.getClickCount() == 2 && me.getButton() == MouseEvent.BUTTON1) {
                doEdit(panel.filtersTable.rowAtPoint(me.getPoint()));
            }
        }
    });
    TableColumnSizer.autoSize(panel.filtersTable, 0, true);
    if (!isProjectSpecific) {
        panel.projectSpecificCB.setVisible(false);
    }
    panel.projectSpecificCB.addActionListener(e -> updateEnabledness());
    panel.cbRemoveTags.addActionListener(e -> editableFilters.setRemoveTags(panel.cbRemoveTags.isSelected()));
    panel.cbRemoveSpacesNonseg.addActionListener(e -> editableFilters.setRemoveSpacesNonseg(panel.cbRemoveSpacesNonseg.isSelected()));
    panel.cbPreserveSpaces.addActionListener(e -> editableFilters.setPreserveSpaces(panel.cbPreserveSpaces.isSelected()));
    panel.cbIgnoreFileContext.addActionListener(e -> editableFilters.setIgnoreFileContext(panel.cbIgnoreFileContext.isSelected()));
    panel.optionsButton.addActionListener(e -> {
        Filter currFilter = getFilterAtRow(panel.filtersTable.getSelectedRow());
        IFilter f = FilterMaster.getFilterInstance(currFilter.getClassName());
        if (f != null) {
            // new options handling
            Map<String, String> newConfig = f.changeOptions(SwingUtilities.windowForComponent(panel), FilterMaster.forFilter(currFilter.getOption()));
            if (newConfig != null) {
                FilterMaster.setOptions(currFilter, newConfig);
            }
        }
    });
    panel.editButton.addActionListener(e -> doEdit(panel.filtersTable.getSelectedRow()));
    if (Core.getProject().isProjectLoaded()) {
        inUseFilters = Core.getProject().getProjectFiles().stream().map(info -> info.filterFileFormatName).collect(Collectors.toSet());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) Filter(gen.core.filters.Filter) IFilter(org.omegat.filters2.IFilter) IFilter(org.omegat.filters2.IFilter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

IFilter (org.omegat.filters2.IFilter)19 File (java.io.File)8 Files (gen.core.filters.Files)5 ArrayList (java.util.ArrayList)5 FilterContext (org.omegat.filters2.FilterContext)5 IParseCallback (org.omegat.filters2.IParseCallback)5 Filter (gen.core.filters.Filter)4 Test (org.junit.Test)4 ProtectedPart (org.omegat.core.data.ProtectedPart)4 IAlignCallback (org.omegat.filters2.IAlignCallback)4 IOException (java.io.IOException)3 AbstractFilter (org.omegat.filters2.AbstractFilter)3 TranslationException (org.omegat.filters2.TranslationException)3 OneFilterTableModel (org.omegat.filters2.master.OneFilterTableModel)2 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 RandomAccessFile (java.io.RandomAccessFile)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1