Search in sources :

Example 31 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class MClipboardController method pasteStringWithoutRedisplay.

private void pasteStringWithoutRedisplay(final TextFragment[] textFragments, NodeModel parent, final boolean asSibling, final boolean isLeft) {
    final MapModel map = parent.getMap();
    int insertionIndex;
    if (asSibling) {
        NodeModel target = parent;
        parent = parent.getParentNode();
        insertionIndex = parent.getChildPosition(target);
    } else {
        insertionIndex = parent.getChildCount();
    }
    final ArrayList<NodeModel> parentNodes = new ArrayList<NodeModel>();
    final ArrayList<Integer> parentNodesDepths = new ArrayList<Integer>();
    parentNodes.add(parent);
    parentNodesDepths.add(new Integer(-1));
    final MMapController mapController = (MMapController) Controller.getCurrentModeController().getMapController();
    for (int i = 0; i < textFragments.length; ++i) {
        final TextFragment textFragment = textFragments[i];
        String text = textFragment.text;
        final String link = textFragment.link;
        URI uri = null;
        if (link != null) {
            try {
                URI linkUri = new URI(link);
                uri = linkUri;
                File absoluteFile = UrlManager.getController().getAbsoluteFile(map, uri);
                if (absoluteFile != null) {
                    // if ("file".equals(linkUri.getScheme())) {
                    final File mapFile = map.getFile();
                    uri = LinkController.toLinkTypeDependantURI(mapFile, absoluteFile);
                    if (link.equals(text)) {
                        text = uri.toString();
                    }
                }
            } catch (Exception e) {
            }
        }
        final NodeModel node = mapController.newNode(text, map);
        if (uri != null) {
            NodeLinks.createLinkExtension(node).setHyperLink(uri);
        }
        for (int j = parentNodes.size() - 1; j >= 0; --j) {
            if (textFragment.depth > ((Integer) parentNodesDepths.get(j)).intValue()) {
                for (int k = j + 1; k < parentNodes.size(); ++k) {
                    final NodeModel n = (NodeModel) parentNodes.get(k);
                    if (n.getParentNode() == null) {
                        mapController.insertNode(n, parent, insertionIndex++);
                    }
                    parentNodes.remove(k);
                    parentNodesDepths.remove(k);
                }
                final NodeModel target = (NodeModel) parentNodes.get(j);
                node.setLeft(isLeft);
                if (target != parent) {
                    target.setFolded(true);
                    target.insert(node, target.getChildCount());
                }
                parentNodes.add(node);
                parentNodesDepths.add(new Integer(textFragment.depth));
                break;
            }
        }
    }
    {
        for (int k = 0; k < parentNodes.size(); ++k) {
            final NodeModel n = (NodeModel) parentNodes.get(k);
            if (map.getRootNode() != n && n.getParentNode() == null) {
                mapController.insertNode(n, parent, insertionIndex++);
            }
        }
    }
}
Also used : MMapController(org.freeplane.features.map.mindmapmode.MMapController) ArrayList(java.util.ArrayList) MapModel(org.freeplane.features.map.MapModel) URI(java.net.URI) Hint(org.freeplane.features.map.MapWriter.Hint) XMLException(org.freeplane.n3.nanoxml.XMLException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException) NodeModel(org.freeplane.features.map.NodeModel) File(java.io.File)

Example 32 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class AddAttributeAction method selectedAttributeChanged.

protected void selectedAttributeChanged(final Object selectedAttributeName, final JComboBox values) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = attributes.getElement(selectedAttributeName.toString());
        final ComboBoxModel selectedValues = element.getValues();
        values.setModel(new ClonedComboBoxModel(selectedValues));
        try {
            final Object firstValue = selectedValues.getElementAt(0);
            values.setSelectedItem(firstValue);
        } catch (final ArrayIndexOutOfBoundsException ex) {
        }
        values.setEditable(!element.isRestricted());
    } catch (final NoSuchElementException ex) {
        values.setEditable(!selectedAttributeName.toString().equals(""));
    }
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Example 33 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class AssignAttributeDialog method selectedAttributeChanged.

private void selectedAttributeChanged(final Object selectedAttributeName, final JComboBox values) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = attributes.getElement(selectedAttributeName.toString());
        final ComboBoxModel selectedValues = element.getValues();
        values.setModel(new ClonedComboBoxModel(selectedValues));
        try {
            final Object firstValue = selectedValues.getElementAt(0);
            values.setSelectedItem(firstValue);
        } catch (final ArrayIndexOutOfBoundsException ex) {
        }
        values.setEditable(!element.isRestricted());
    } catch (final NoSuchElementException ex) {
        values.setEditable(!selectedAttributeName.toString().equals(""));
    }
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Example 34 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class AttributeManagerDialog method applyChanges.

private void applyChanges() {
    final Object size = this.size.getSelectedItem();
    final int iSize = Integer.parseInt(size.toString());
    model.getAttributeController().performSetFontSize(model, iSize);
    model.applyChanges();
    final MModeController modeController = (MModeController) Controller.getCurrentModeController();
    modeController.delayedCommit();
    final MapController mapController = modeController.getMapController();
    final MapModel map = Controller.getCurrentController().getMap();
    assert (AttributeRegistry.getRegistry(map) == model);
    mapController.setSaved(map, false);
}
Also used : MapModel(org.freeplane.features.map.MapModel) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MapController(org.freeplane.features.map.MapController)

Example 35 with MapModel

use of org.freeplane.features.map.MapModel in project freeplane by freeplane.

the class FilePropertiesAction method actionPerformed.

/**
 * Gets called when File -> Properties is selected
 */
public void actionPerformed(final ActionEvent e) {
    // variables for informations to be displayed
    final String fileNamePath, fileSavedDateTime, fileSize;
    final int fileChangesSinceSave;
    // get informations
    // if file has been saved once
    final MapModel map = Controller.getCurrentController().getMap();
    if (map.getFile() != null) {
        // fileNamePath
        fileNamePath = map.getFile().toString();
        // fleSavedDateTime as formatted string
        final Calendar c = Calendar.getInstance();
        c.setTimeInMillis(map.getFile().lastModified());
        final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
        fileSavedDateTime = df.format(c.getTime());
        // fileSize as formatted string
        final DecimalFormat def = new DecimalFormat();
        def.setGroupingUsed(true);
        fileSize = def.format(map.getFile().length()) + " " + TextUtils.getText("FileRevisionsDialog.file_size");
        // fileChangesSinceSave
        fileChangesSinceSave = map.getNumberOfChangesSinceLastSave();
    } else {
        fileNamePath = TextUtils.getText("FileProperties_NeverSaved");
        fileSavedDateTime = TextUtils.getText("FileProperties_NeverSaved");
        fileSize = TextUtils.getText("FileProperties_NeverSaved");
        fileChangesSinceSave = 0;
    }
    // node statistics
    final NodeModel rootNode = map.getRootNode();
    final int nodeMainBranches = rootNode.getChildCount();
    final ICondition trueCondition = new ICondition() {

        public boolean checkNode(NodeModel node) {
            return true;
        }
    };
    final ICondition isLeafCondition = new ICondition() {

        public boolean checkNode(NodeModel node) {
            return node.isLeaf();
        }
    };
    final int nodeTotalNodeCount = getNodeCount(rootNode, trueCondition);
    final int nodeTotalLeafCount = getNodeCount(rootNode, isLeafCondition);
    final Filter filter = map.getFilter();
    final int nodeTotalFiltered;
    if (filter != null && filter.getCondition() != null) {
        final ICondition matchesFilterCondition = new ICondition() {

            public boolean checkNode(NodeModel node) {
                return filter.matches(node);
            }
        };
        nodeTotalFiltered = getNodeCount(rootNode, matchesFilterCondition);
    } else {
        nodeTotalFiltered = -1;
    }
    // Multiple nodes may be selected
    final Collection<NodeModel> nodes = Controller.getCurrentController().getSelection().getSelection();
    boolean isDescendant = false;
    int nodeRelativeChildCount = 0;
    int nodeRelativeNodeCount = 0;
    int nodeRelativeLeafCount = 0;
    for (final NodeModel n : nodes) {
        nodeRelativeChildCount += n.getChildCount();
        isDescendant = false;
        // Nodes and leaf nodes are only counted once per branch
        for (NodeModel node : nodes) {
            if (n.isDescendantOf(node)) {
                isDescendant = true;
                break;
            }
        }
        if (!isDescendant) {
            nodeRelativeNodeCount += getNodeCount(n, trueCondition);
            nodeRelativeLeafCount += getNodeCount(n, isLeafCondition);
        }
    }
    final int nodeSelectedNodeCount = Controller.getCurrentController().getSelection().getSelection().size();
    // build component
    final JPanel panel = new JPanel();
    final GridBagLayout gridbag = new GridBagLayout();
    panel.setLayout(gridbag);
    panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(5, 0, 5, 0)));
    final GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    c.ipady = 5;
    c.ipadx = 0;
    c.insets = new Insets(0, 10, 0, 10);
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    // fileNamePath
    final URL imageURL = ResourceController.getResourceController().getResource("/images/filenew.png");
    final JLabel fileIcon = new JLabel(ImageIconFactory.getInstance().getImageIcon(imageURL));
    gridbag.setConstraints(fileIcon, c);
    panel.add(fileIcon);
    c.gridx = 1;
    final JLabel fileNamePathText = new JLabel(TextUtils.getText("FileProperties_FileName"));
    gridbag.setConstraints(fileNamePathText, c);
    panel.add(fileNamePathText);
    c.gridx = 2;
    final JLabel fileNamePathLabel = new JLabel(fileNamePath);
    gridbag.setConstraints(fileNamePathLabel, c);
    panel.add(fileNamePathLabel);
    // fileSize
    c.gridy++;
    c.gridx = 1;
    final JLabel fileSizeText = new JLabel(TextUtils.getText("FileProperties_FileSize"));
    gridbag.setConstraints(fileSizeText, c);
    panel.add(fileSizeText);
    c.gridx = 2;
    final JLabel fileSizeLabel = new JLabel(fileSize);
    gridbag.setConstraints(fileSizeLabel, c);
    panel.add(fileSizeLabel);
    // fileSavedDateTime
    c.gridy++;
    c.gridx = 1;
    final JLabel fileSavedDateTimeText = new JLabel(TextUtils.getText("FileProperties_FileSaved"));
    gridbag.setConstraints(fileSavedDateTimeText, c);
    panel.add(fileSavedDateTimeText);
    c.gridx = 2;
    final JLabel fileSavedDateTimeLabel = new JLabel(fileSavedDateTime);
    gridbag.setConstraints(fileSavedDateTimeLabel, c);
    panel.add(fileSavedDateTimeLabel);
    // fileChangesSinceSave
    c.gridy++;
    c.gridx = 1;
    final JLabel fileChangesSinceSaveText = new JLabel(TextUtils.getText("FileProperties_ChangesSinceLastSave"));
    gridbag.setConstraints(fileChangesSinceSaveText, c);
    panel.add(fileChangesSinceSaveText);
    c.gridx = 2;
    final JLabel fileChangesSinceSaveLabel = new JLabel(String.valueOf(fileChangesSinceSave));
    gridbag.setConstraints(fileChangesSinceSaveLabel, c);
    panel.add(fileChangesSinceSaveLabel);
    // Separator
    c.gridy++;
    c.gridx = 0;
    c.insets = new Insets(5, 10, 5, 10);
    c.ipady = 2;
    c.gridwidth = 3;
    final JSeparator js = new JSeparator(SwingConstants.HORIZONTAL);
    js.setLayout(gridbag);
    js.setBorder(BorderFactory.createEtchedBorder());
    js.setPreferredSize(new Dimension(0, 0));
    c.fill = GridBagConstraints.HORIZONTAL;
    gridbag.setConstraints(js, c);
    panel.add(js);
    // nodeTotalNodeCount
    c.gridy++;
    c.insets = new Insets(0, 10, 0, 10);
    c.ipady = 5;
    c.gridwidth = 1;
    c.gridx = 0;
    final URL imageURL2 = ResourceController.getResourceController().getResource("/images/MapStats.png");
    final JLabel MapStatsIcon = new JLabel(ImageIconFactory.getInstance().getImageIcon(imageURL2));
    gridbag.setConstraints(MapStatsIcon, c);
    panel.add(MapStatsIcon);
    c.gridx = 1;
    final JLabel nodeTotalNodeCountText = new JLabel(TextUtils.getText("FileProperties_TotalNodeCount"));
    gridbag.setConstraints(nodeTotalNodeCountText, c);
    panel.add(nodeTotalNodeCountText);
    c.gridx = 2;
    final JLabel nodeTotalNodeCountLabel = new JLabel(String.valueOf(nodeTotalNodeCount));
    gridbag.setConstraints(nodeTotalNodeCountLabel, c);
    panel.add(nodeTotalNodeCountLabel);
    // nodeTotalFiltered
    if (nodeTotalFiltered != -1) {
        c.gridy++;
        c.gridx = 1;
        final JLabel nodeTotalFilteredLabelText = new JLabel(TextUtils.getText("FileProperties_TotalFilteredCount"));
        gridbag.setConstraints(nodeTotalFilteredLabelText, c);
        panel.add(nodeTotalFilteredLabelText);
        c.gridx = 2;
        final JLabel nodeTotalFilteredLabel = new JLabel(String.valueOf(nodeTotalFiltered));
        gridbag.setConstraints(nodeTotalFilteredLabel, c);
        panel.add(nodeTotalFilteredLabel);
    }
    // nodeTotalLeafCount
    c.gridy++;
    c.gridx = 1;
    final JLabel nodeTotalLeafCountText = new JLabel(TextUtils.getText("FileProperties_TotalLeafCount"));
    gridbag.setConstraints(nodeTotalLeafCountText, c);
    panel.add(nodeTotalLeafCountText);
    c.gridx = 2;
    final JLabel nodeTotalLeafCountLabel = new JLabel(String.valueOf(nodeTotalLeafCount));
    gridbag.setConstraints(nodeTotalLeafCountLabel, c);
    panel.add(nodeTotalLeafCountLabel);
    // nodeMainBranches
    c.gridy++;
    c.gridx = 1;
    final JLabel nodeMainBranchesText = new JLabel(TextUtils.getText("FileProperties_MainBranchCount"));
    gridbag.setConstraints(nodeMainBranchesText, c);
    panel.add(nodeMainBranchesText);
    c.gridx = 2;
    final JLabel nodeMainBranchesLabel = new JLabel(String.valueOf(nodeMainBranches));
    gridbag.setConstraints(nodeMainBranchesLabel, c);
    panel.add(nodeMainBranchesLabel);
    // Separator
    c.gridy++;
    c.gridx = 0;
    c.insets = new Insets(5, 10, 5, 10);
    c.ipady = 2;
    c.gridwidth = 3;
    final JSeparator js2 = new JSeparator(SwingConstants.HORIZONTAL);
    js2.setLayout(gridbag);
    js2.setBorder(BorderFactory.createEtchedBorder());
    js2.setPreferredSize(new Dimension(0, 0));
    c.fill = GridBagConstraints.HORIZONTAL;
    gridbag.setConstraints(js2, c);
    panel.add(js2);
    // nodeRelativeNodeCount
    c.gridy++;
    c.insets = new Insets(0, 10, 0, 10);
    c.ipady = 5;
    c.gridwidth = 1;
    c.gridx = 0;
    final URL imageURL3 = ResourceController.getResourceController().getResource("/images/BranchStats.png");
    final JLabel BranchStatsIcon = new JLabel(ImageIconFactory.getInstance().getImageIcon(imageURL3));
    gridbag.setConstraints(BranchStatsIcon, c);
    panel.add(BranchStatsIcon);
    c.gridx = 1;
    final JLabel nodeRelativeNodeCountText = new JLabel(TextUtils.getText("FileProperties_BranchNodeCount"));
    gridbag.setConstraints(nodeRelativeNodeCountText, c);
    panel.add(nodeRelativeNodeCountText);
    c.gridx = 2;
    final JLabel nodeRelativeNodeCountLabel = new JLabel(String.valueOf(nodeRelativeNodeCount));
    gridbag.setConstraints(nodeRelativeNodeCountLabel, c);
    panel.add(nodeRelativeNodeCountLabel);
    // nodeRelativeLeafCount
    c.gridy++;
    c.gridx = 1;
    final JLabel nodeRelativeLeafCountText = new JLabel(TextUtils.getText("FileProperties_BranchLeafCount"));
    gridbag.setConstraints(nodeRelativeLeafCountText, c);
    panel.add(nodeRelativeLeafCountText);
    c.gridx = 2;
    final JLabel nodeRelativeLeafCountLabel = new JLabel(String.valueOf(nodeRelativeLeafCount));
    gridbag.setConstraints(nodeRelativeLeafCountLabel, c);
    panel.add(nodeRelativeLeafCountLabel);
    // nodeRelativeChildCount
    c.gridy++;
    c.gridx = 1;
    final JLabel nodeRelativeChildCountText = new JLabel(TextUtils.getText("FileProperties_NodeChildCount"));
    gridbag.setConstraints(nodeRelativeChildCountText, c);
    panel.add(nodeRelativeChildCountText);
    c.gridx = 2;
    final JLabel nodeRelativeChildCountLabel = new JLabel(String.valueOf(nodeRelativeChildCount));
    gridbag.setConstraints(nodeRelativeChildCountLabel, c);
    panel.add(nodeRelativeChildCountLabel);
    // nodeSelectedNodeCount
    c.gridy++;
    c.gridx = 1;
    final JLabel nodeSelectedNodeCountText = new JLabel(TextUtils.getText("FileProperties_NodeSelectionCount"));
    gridbag.setConstraints(nodeSelectedNodeCountText, c);
    panel.add(nodeSelectedNodeCountText);
    c.gridx = 2;
    final JLabel nodeSelectedNodeCountLabel = new JLabel(String.valueOf(nodeSelectedNodeCount));
    gridbag.setConstraints(nodeSelectedNodeCountLabel, c);
    panel.add(nodeSelectedNodeCountLabel);
    // Show dialog
    JOptionPane.showMessageDialog(UITools.getFrame(), panel, TextUtils.getText("FilePropertiesAction.text"), JOptionPane.PLAIN_MESSAGE);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Calendar(java.util.Calendar) DecimalFormat(java.text.DecimalFormat) JLabel(javax.swing.JLabel) MapModel(org.freeplane.features.map.MapModel) Dimension(java.awt.Dimension) URL(java.net.URL) JSeparator(javax.swing.JSeparator) NodeModel(org.freeplane.features.map.NodeModel) Filter(org.freeplane.features.filter.Filter) DateFormat(java.text.DateFormat) ICondition(org.freeplane.features.filter.condition.ICondition)

Aggregations

MapModel (org.freeplane.features.map.MapModel)161 NodeModel (org.freeplane.features.map.NodeModel)53 ModeController (org.freeplane.features.mode.ModeController)42 Controller (org.freeplane.features.mode.Controller)34 IActor (org.freeplane.core.undo.IActor)31 File (java.io.File)18 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)17 MMapModel (org.freeplane.features.map.mindmapmode.MMapModel)17 IUndoHandler (org.freeplane.core.undo.IUndoHandler)16 URL (java.net.URL)14 MMapController (org.freeplane.features.map.mindmapmode.MMapController)14 IStyle (org.freeplane.features.styles.IStyle)14 LogicalStyleController (org.freeplane.features.styles.LogicalStyleController)14 MapController (org.freeplane.features.map.MapController)12 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)12 IMapViewManager (org.freeplane.features.ui.IMapViewManager)12 MapStyleModel (org.freeplane.features.styles.MapStyleModel)10 IOException (java.io.IOException)9 MalformedURLException (java.net.MalformedURLException)9 URI (java.net.URI)9