Search in sources :

Example 1 with ConditionalStyleModel

use of org.freeplane.features.styles.ConditionalStyleModel in project freeplane by freeplane.

the class ManageMapConditionalStylesAction method getConditionalStyleModel.

@Override
public ConditionalStyleModel getConditionalStyleModel() {
    final Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    final MapStyleModel styleModel = MapStyleModel.getExtension(map);
    final ConditionalStyleModel conditionalStyleModel = styleModel.getConditionalStyleModel();
    return conditionalStyleModel;
}
Also used : MapStyleModel(org.freeplane.features.styles.MapStyleModel) ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) MapModel(org.freeplane.features.map.MapModel) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) Controller(org.freeplane.features.mode.Controller)

Example 2 with ConditionalStyleModel

use of org.freeplane.features.styles.ConditionalStyleModel in project freeplane by freeplane.

the class ManageNodeConditionalStylesAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    final Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
    Component pane = createConditionalStylePane(map, conditionalStyleModel);
    final ModeController modeController = Controller.getCurrentModeController();
    modeController.startTransaction();
    try {
        final int confirmed = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), pane, TextUtils.getText(TextUtils.removeMnemonic("ManageNodeConditionalStylesAction.text")), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (JOptionPane.OK_OPTION == confirmed) {
            modeController.commit();
            final IMapSelection selection = controller.getSelection();
            final NodeModel selected = selection.getSelected();
            modeController.getMapController().nodeChanged(selected, NodeModel.UNKNOWN_PROPERTY, null, null);
            for (NodeModel otherSelectedNode : selection.getSelection()) if (selected != otherSelectedNode) {
                otherSelectedNode.putExtension(conditionalStyleModel.clone());
                modeController.getMapController().nodeChanged(otherSelectedNode, NodeModel.UNKNOWN_PROPERTY, null, null);
            }
        } else {
            modeController.rollback();
        }
    } catch (RuntimeException ex) {
        ex.printStackTrace();
        modeController.rollback();
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) IMapSelection(org.freeplane.features.map.IMapSelection) ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) Component(java.awt.Component)

Example 3 with ConditionalStyleModel

use of org.freeplane.features.styles.ConditionalStyleModel 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 4 with ConditionalStyleModel

use of org.freeplane.features.styles.ConditionalStyleModel in project freeplane by freeplane.

the class ManageMapConditionalStylesAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    final Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    final ConditionalStyleModel conditionalStyleModel = getConditionalStyleModel();
    Component pane = createConditionalStylePane(map, conditionalStyleModel);
    Controller.getCurrentModeController().startTransaction();
    try {
        final int confirmed = JOptionPane.showConfirmDialog(controller.getMapViewManager().getMapViewComponent(), pane, TextUtils.getText(TextUtils.removeMnemonic("ManageConditionalStylesAction.text")), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (JOptionPane.OK_OPTION == confirmed) {
            LogicalStyleController.getController().refreshMap(map);
            Controller.getCurrentModeController().commit();
        } else {
            Controller.getCurrentModeController().rollback();
        }
    } catch (RuntimeException ex) {
        ex.printStackTrace();
        Controller.getCurrentModeController().rollback();
    }
}
Also used : ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) MapModel(org.freeplane.features.map.MapModel) LogicalStyleController(org.freeplane.features.styles.LogicalStyleController) Controller(org.freeplane.features.mode.Controller) Component(java.awt.Component)

Example 5 with ConditionalStyleModel

use of org.freeplane.features.styles.ConditionalStyleModel in project freeplane by freeplane.

the class ManageNodeConditionalStylesAction method getConditionalStyleModel.

@Override
public ConditionalStyleModel getConditionalStyleModel() {
    final Controller controller = Controller.getCurrentController();
    final NodeModel node = controller.getSelection().getSelected();
    ConditionalStyleModel conditionalStyleModel = (ConditionalStyleModel) node.getExtension(ConditionalStyleModel.class);
    if (conditionalStyleModel == null) {
        conditionalStyleModel = new ConditionalStyleModel();
        node.addExtension(conditionalStyleModel);
    }
    return conditionalStyleModel;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) ConditionalStyleModel(org.freeplane.features.styles.ConditionalStyleModel) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController)

Aggregations

ConditionalStyleModel (org.freeplane.features.styles.ConditionalStyleModel)5 Controller (org.freeplane.features.mode.Controller)4 MapModel (org.freeplane.features.map.MapModel)3 Component (java.awt.Component)2 NodeModel (org.freeplane.features.map.NodeModel)2 ModeController (org.freeplane.features.mode.ModeController)2 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)2 MapStyleModel (org.freeplane.features.styles.MapStyleModel)2 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Box (javax.swing.Box)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 TableModel (javax.swing.table.TableModel)1 FilterComposerDialog (org.freeplane.features.filter.FilterComposerDialog)1 ASelectableCondition (org.freeplane.features.filter.condition.ASelectableCondition)1 IMapSelection (org.freeplane.features.map.IMapSelection)1