Search in sources :

Example 11 with ASelectableCondition

use of org.freeplane.features.filter.condition.ASelectableCondition in project freeplane by freeplane.

the class SlideEditorController method createSetFilterToggleButton.

private JToggleButton createSetFilterToggleButton() {
    final JToggleButton tglbtnSetFilter = createToggleButtonWithIconAndLabel("SetFilterSlideContent.icon", "slide.setfilter");
    tglbtnSetFilter.setAlignmentX(Component.CENTER_ALIGNMENT);
    tglbtnSetFilter.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (filterComposerDialog == null)
                filterComposerDialog = new FilterComposerDialog();
            ASelectableCondition oldCondition = slide.getFilterCondition();
            if (oldCondition != null) {
                filterComposerDialog.addCondition(oldCondition);
                filterComposerDialog.setSelectedItem(oldCondition);
                UndoableSlide.of(slide).setFilterCondition(null);
            } else {
                filterComposerDialog.show();
                List<ASelectableCondition> conditions = filterComposerDialog.getConditions();
                if (filterComposerDialog.isSuccess()) {
                    ASelectableCondition newCondition = conditions.isEmpty() ? null : conditions.get(0);
                    UndoableSlide.of(slide).setFilterCondition(newCondition);
                }
            }
            tglbtnSetFilter.setSelected(slide.getFilterCondition() != null);
        }
    });
    return tglbtnSetFilter;
}
Also used : JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FilterComposerDialog(org.freeplane.features.filter.FilterComposerDialog) List(java.util.List) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Example 12 with ASelectableCondition

use of org.freeplane.features.filter.condition.ASelectableCondition in project freeplane by freeplane.

the class UndoableSlide method setFilterCondition.

public void setFilterCondition(final ASelectableCondition filterCondition) {
    final ASelectableCondition oldFilterCondition = slide.getFilterCondition();
    if (filterCondition == oldFilterCondition)
        return;
    IActor actor = new IActor() {

        @Override
        public String getDescription() {
            return "setFilterCondition";
        }

        @Override
        public void act() {
            slide.setFilterCondition(filterCondition);
        }

        @Override
        public void undo() {
            slide.setFilterCondition(oldFilterCondition);
        }
    };
    controller.execute(actor, mapModel);
}
Also used : IActor(org.freeplane.core.undo.IActor) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Example 13 with ASelectableCondition

use of org.freeplane.features.filter.condition.ASelectableCondition in project freeplane by freeplane.

the class AManageConditionalStylesAction method createConditionalStylePane.

protected Component createConditionalStylePane(final MapModel map, final ConditionalStyleModel conditionalStyleModel) {
    final JPanel pane = new JPanel(new BorderLayout());
    final MapStyleModel styles = MapStyleModel.getExtension(map);
    final TableModel tableModel = MLogicalStyleController.getController().getConditionalStyleModelAsTableModel(map, conditionalStyleModel);
    final ConditionalStyleTable conditionalStyleTable = new ConditionalStyleTable(styles, tableModel);
    if (conditionalStyleTable.getRowCount() > 0) {
        conditionalStyleTable.setRowSelectionInterval(0, 0);
    }
    JScrollPane scrollPane = new JScrollPane(conditionalStyleTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final int tablePreferredWidth = scrollPane.getViewport().getViewSize().width;
    scrollPane.setPreferredSize(new Dimension(tablePreferredWidth, 400));
    pane.add(scrollPane, BorderLayout.CENTER);
    final Box buttons = Box.createVerticalBox();
    JButton create = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(create, TextUtils.getRawText("new"));
    create.setMaximumSize(UITools.MAX_BUTTON_DIMENSION);
    create.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int row = conditionalStyleTable.getRowCount();
            final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
            ((MLogicalStyleController) LogicalStyleController.getController()).addConditionalStyle(map, conditionalStyleModel, true, null, MapStyleModel.DEFAULT_STYLE, false);
            conditionalStyleTable.setRowSelectionInterval(row, row);
        }
    });
    JButton edit = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(edit, TextUtils.getRawText("edit"));
    edit.setMaximumSize(UITools.MAX_BUTTON_DIMENSION);
    edit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int selectedRow = conditionalStyleTable.getSelectedRow();
            if (selectedRow == -1) {
                return;
            }
            final FilterComposerDialog filterComposerDialog = new FilterComposerDialog();
            filterComposerDialog.addCondition(null);
            filterComposerDialog.setConditionRenderer(ConditionalStyleTable.createConditionRenderer());
            for (int i = 0; i < conditionalStyleTable.getRowCount(); i++) {
                final ASelectableCondition condition = (ASelectableCondition) conditionalStyleTable.getValueAt(i, 1);
                filterComposerDialog.addCondition(condition);
            }
            final ASelectableCondition value = (ASelectableCondition) conditionalStyleTable.getValueAt(selectedRow, 1);
            final ASelectableCondition newCondition = filterComposerDialog.editCondition(value);
            conditionalStyleTable.setValueAt(newCondition, selectedRow, 1);
        }
    });
    JButton delete = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(delete, TextUtils.getRawText("delete"));
    delete.setMaximumSize(UITools.MAX_BUTTON_DIMENSION);
    delete.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int selectedRow = conditionalStyleTable.getSelectedRow();
            if (selectedRow == -1) {
                return;
            }
            final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
            ((MLogicalStyleController) LogicalStyleController.getController()).removeConditionalStyle(map, conditionalStyleModel, selectedRow);
            if (conditionalStyleTable.getRowCount() == selectedRow) {
                selectedRow--;
            }
            if (selectedRow == -1) {
                return;
            }
            conditionalStyleTable.setRowSelectionInterval(selectedRow, selectedRow);
        }
    });
    JButton up = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(up, TextUtils.getRawText("up"));
    up.setMaximumSize(UITools.MAX_BUTTON_DIMENSION);
    up.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int selectedRow = conditionalStyleTable.getSelectedRow();
            if (selectedRow <= 0) {
                return;
            }
            final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
            ((MLogicalStyleController) LogicalStyleController.getController()).moveConditionalStyleUp(map, conditionalStyleModel, selectedRow);
            selectedRow--;
            conditionalStyleTable.setRowSelectionInterval(selectedRow, selectedRow);
        }
    });
    JButton down = new JButton();
    LabelAndMnemonicSetter.setLabelAndMnemonic(down, TextUtils.getRawText("down"));
    down.setMaximumSize(UITools.MAX_BUTTON_DIMENSION);
    down.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int selectedRow = conditionalStyleTable.getSelectedRow();
            if (selectedRow == -1 || selectedRow == conditionalStyleTable.getRowCount() - 1) {
                return;
            }
            final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
            ((MLogicalStyleController) LogicalStyleController.getController()).moveConditionalStyleDown(map, conditionalStyleModel, selectedRow);
            selectedRow++;
            conditionalStyleTable.setRowSelectionInterval(selectedRow, selectedRow);
        }
    });
    buttons.add(Box.createVerticalStrut(BUTTON_GAP));
    buttons.add(create);
    buttons.add(Box.createVerticalStrut(BUTTON_GAP));
    buttons.add(edit);
    buttons.add(Box.createVerticalStrut(BUTTON_GAP));
    buttons.add(delete);
    buttons.add(Box.createVerticalStrut(BUTTON_GAP));
    buttons.add(up);
    buttons.add(Box.createVerticalStrut(BUTTON_GAP));
    buttons.add(down);
    buttons.add(Box.createVerticalGlue());
    pane.add(buttons, BorderLayout.EAST);
    UITools.focusOn(conditionalStyleTable);
    return pane;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MapStyleModel(org.freeplane.features.styles.MapStyleModel) ActionEvent(java.awt.event.ActionEvent) FilterComposerDialog(org.freeplane.features.filter.FilterComposerDialog) JButton(javax.swing.JButton) ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) Box(javax.swing.Box) Dimension(java.awt.Dimension) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) TableModel(javax.swing.table.TableModel)

Example 14 with ASelectableCondition

use of org.freeplane.features.filter.condition.ASelectableCondition in project freeplane by freeplane.

the class FilterConditionEditor method getCondition.

public ASelectableCondition getCondition() {
    ASelectableCondition newCond;
    Object value;
    if (values.isEditable()) {
        value = values.getEditor().getItem();
    } else {
        value = values.getSelectedItem();
    }
    if (value == null) {
        value = "";
    }
    final TranslatedObject simpleCond = (TranslatedObject) elementaryConditions.getSelectedItem();
    final boolean matchCase = caseSensitive.isSelected();
    final boolean matchApproximately = approximateMatching.isSelected();
    ResourceController.getResourceController().setProperty(PROPERTY_FILTER_MATCH_CASE, matchCase);
    final Object selectedItem = filteredPropertiesComponent.getSelectedItem();
    newCond = filterController.getConditionFactory().createCondition(selectedItem, simpleCond, value, matchCase, matchApproximately);
    if (values.isEditable()) {
        if (!value.equals("")) {
            DefaultComboBoxModel list = (DefaultComboBoxModel) values.getModel();
            int indexOfValue = list.getIndexOf(value);
            if (indexOfValue > 0)
                list.removeElementAt(indexOfValue);
            if (indexOfValue == -1 || list.getIndexOf(value) != indexOfValue) {
                values.insertItemAt(value, 0);
                values.setSelectedIndex(0);
            } else if (indexOfValue != -1) {
                values.setSelectedIndex(indexOfValue);
            }
            if (values.getItemCount() >= 10) {
                values.removeItemAt(9);
            }
        }
    }
    return newCond;
}
Also used : TranslatedObject(org.freeplane.core.resources.TranslatedObject) TranslatedObject(org.freeplane.core.resources.TranslatedObject) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Example 15 with ASelectableCondition

use of org.freeplane.features.filter.condition.ASelectableCondition in project freeplane by freeplane.

the class FilterController method saveConditions.

void saveConditions(final DefaultComboBoxModel filterConditionModel, final String pathToFilterFile) throws IOException {
    final XMLElement saver = new XMLElement();
    saver.setName("filter_conditions");
    final Writer writer = new FileWriter(pathToFilterFile);
    for (int i = 0; i < filterConditionModel.getSize(); i++) {
        final ASelectableCondition cond = (ASelectableCondition) filterConditionModel.getElementAt(i);
        if (cond != null && !(cond instanceof NoFilteringCondition)) {
            cond.toXml(saver);
        }
    }
    final XMLWriter xmlWriter = new XMLWriter(writer);
    xmlWriter.write(saver, true);
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) NoFilteringCondition(org.freeplane.features.filter.condition.NoFilteringCondition) XMLElement(org.freeplane.n3.nanoxml.XMLElement) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) Writer(java.io.Writer) FileWriter(java.io.FileWriter) XMLWriter(org.freeplane.n3.nanoxml.XMLWriter) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition)

Aggregations

ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)21 XMLElement (org.freeplane.n3.nanoxml.XMLElement)5 NodeModel (org.freeplane.features.map.NodeModel)4 IOException (java.io.IOException)3 IMapSelection (org.freeplane.features.map.IMapSelection)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 LinkedHashSet (java.util.LinkedHashSet)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 JComponent (javax.swing.JComponent)2 FilterComposerDialog (org.freeplane.features.filter.FilterComposerDialog)2 ConditionFactory (org.freeplane.features.filter.condition.ConditionFactory)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 Window (java.awt.Window)1 WindowEvent (java.awt.event.WindowEvent)1 WindowFocusListener (java.awt.event.WindowFocusListener)1 BufferedInputStream (java.io.BufferedInputStream)1