use of gen.core.filters.Filter 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());
}
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class Convert20to21 method convertFiltersConfig.
/**
* Convert filters config ('filters.conf') into new format.
*
* @param fromFile
* old config file
* @param toFile
* new config file
* @throws Exception
*/
public static void convertFiltersConfig(final File fromFile, final File toFile) throws Exception {
if (!fromFile.exists()) {
return;
}
String c = read(fromFile);
org.omegat.convert.v20to21.data.Filters filters;
XMLDecoder xmldec = new XMLDecoder(new ByteArrayInputStream(c.getBytes("UTF-8")));
try {
filters = (org.omegat.convert.v20to21.data.Filters) xmldec.readObject();
} finally {
xmldec.close();
}
Filters res = new Filters();
for (org.omegat.convert.v20to21.data.OneFilter f : filters.getFilter()) {
Filter fo = new Filter();
res.getFilters().add(fo);
fo.setClassName(f.getClassName());
fo.setEnabled(f.isOn());
for (org.omegat.convert.v20to21.data.Instance i : f.getInstance()) {
Files io = new Files();
fo.getFiles().add(io);
io.setSourceFilenameMask(i.getSourceFilenameMask());
io.setTargetFilenamePattern(i.getTargetFilenamePattern());
io.setSourceEncoding(i.getSourceEncoding());
io.setTargetEncoding(i.getTargetEncoding());
}
Serializable opts = f.getOptions();
if (opts != null) {
BeanInfo bi = Introspector.getBeanInfo(opts.getClass());
for (PropertyDescriptor prop : bi.getPropertyDescriptors()) {
if ("class".equals(prop.getName())) {
continue;
}
Object value = prop.getReadMethod().invoke(opts);
Filter.Option op = new Filter.Option();
op.setName(prop.getName());
op.setValue(value.toString());
fo.getOption().add(op);
}
}
}
convertTextFilter(res);
convertHTMLFilter2(res);
JAXBContext ctx = JAXBContext.newInstance(Filters.class);
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(res, toFile);
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method getDefaultSettingsFromFilter.
/**
* Create default filter's config.
*
* @param filterClassname
* filter's classname
* @return default filter's config
*/
public static Filter getDefaultSettingsFromFilter(final String filterClassname) {
IFilter f = getFilterInstance(filterClassname);
if (f == null) {
return null;
}
Filter fc = new Filter();
fc.setClassName(f.getClass().getName());
fc.setEnabled(true);
for (Instance ins : f.getDefaultInstances()) {
Files ff = new Files();
ff.setSourceEncoding(ins.getSourceEncoding());
ff.setSourceFilenameMask(ins.getSourceFilenameMask());
ff.setTargetEncoding(ins.getTargetEncoding());
ff.setTargetFilenamePattern(ins.getTargetFilenamePattern());
fc.getFiles().add(ff);
}
return fc;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method cloneConfig.
/**
* Clone config for editing
*
* @return new config instance
*/
public static Filters cloneConfig(Filters orig) {
Filters c = new Filters();
c.setRemoveTags(orig.isRemoveTags());
c.setRemoveSpacesNonseg(orig.isRemoveSpacesNonseg());
c.setPreserveSpaces(orig.isPreserveSpaces());
c.setIgnoreFileContext(orig.isIgnoreFileContext());
for (Filter f : orig.getFilters()) {
c.getFilters().add(cloneFilter(f));
}
return c;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method setOptions.
/**
* Convert options to xml from map.
*
* @param f
* filter
* @param newOptions
* options
*/
public static void setOptions(Filter f, Map<String, String> newOptions) {
f.getOption().clear();
for (Map.Entry<String, String> en : newOptions.entrySet()) {
Filter.Option opt = new Filter.Option();
opt.setName(en.getKey());
opt.setValue(en.getValue());
f.getOption().add(opt);
}
}
Aggregations