Anchor ID Problems

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Anchor ID Problems

Felix Natter
Administrator
hi Blair,

in b26ee7024e8e0b59b664133b31be658455a90fe2 you applied this change
(among other changes, see "git show
b26ee7024e8e0b59b664133b31be658455a90fe2"):

- public MLinkController() {
+ public MLinkController(ModeController modeController) {
  super();
+ this.modeController = modeController;
+ this.anchorID = "";
  }

However, setting anchorID="" by default yields problems in
org.freeplane.features.link.mindmapmode.MLinkController.getAnchorIDforNode(NodeModel):

---------------------------
        public String getAnchorIDforNode(final NodeModel node) {
            String targetID = getAnchorID();
            final String link;
                // check if anchorID is valid, then set link in current node
                if (targetID != null && ! targetID.matches("\\w+://")) {

                        // extract fileName from target map
                        final String targetMapFileName = targetID.substring( targetID.indexOf("/") +1, targetID.indexOf("#") );
  [...]
---------------------------
(the substring fails at:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1911)
        at org.freeplane.features.link.mindmapmode.MLinkController.getAnchorIDforNode(MLinkController.java:1111)
        at org.freeplane.features.link.mindmapmode.MakeLinkToAnchorAction.actionPerformed(MakeLinkToAnchorAction.java:48))

If there is an important reason for initializing anchorID:="" (instead
of null) in the ctor, then we need to check for isAnchored() in
getAnchorIDForNode() and change isAnchored() such that it also checks
whether anchorID.equals(""). Here is a proposed patch:

-- a/freeplane/src/org/freeplane/features/link/mindmapmode/MLinkController.java
+++ b/freeplane/src/org/freeplane/features/link/mindmapmode/MLinkController.java
@@ -1098,14 +1098,14 @@ public class MLinkController extends LinkController {
        }
 
        public boolean isAnchored() {
-               return anchorID != null;
+               return anchorID != null && !anchorID.isEmpty();
        }
 
        public String getAnchorIDforNode(final NodeModel node) {
            String targetID = getAnchorID();
            final String link;
                // check if anchorID is valid, then set link in current node
-               if (targetID != null && ! targetID.matches("\\w+://")) {
+               if (isAnchored() && ! targetID.matches("\\w+://")) {
 
                        // extract fileName from target map
                        final String targetMapFileName = targetID.substring( targetID.indexOf("/") +1, targetID.indexOf("#") );

Is this ok?

Thanks and Best Regards,
--
Felix Natter
Reply | Threaded
Open this post in threaded view
|

Re: Anchor ID Problems

BArchibald
Hi Felix,

I can't remember why I set it to "" - I guess I just thought it should have an initial value while I was refactoring the ctor (not a huge fan of passing nulls around!).

Your patch looks great and solves the "" vs null problem!

Many thanks,
Blair


On 4 February 2014 20:08, Felix Natter [via Freeplane Developer] <[hidden email]> wrote:
hi Blair,

in b26ee7024e8e0b59b664133b31be658455a90fe2 you applied this change
(among other changes, see "git show
b26ee7024e8e0b59b664133b31be658455a90fe2"):

- public MLinkController() {
+ public MLinkController(ModeController modeController) {
  super();
+ this.modeController = modeController;
+ this.anchorID = "";
  }

However, setting anchorID="" by default yields problems in
org.freeplane.features.link.mindmapmode.MLinkController.getAnchorIDforNode(NodeModel):

---------------------------
        public String getAnchorIDforNode(final NodeModel node) {
            String targetID = getAnchorID();
            final String link;
                // check if anchorID is valid, then set link in current node
                if (targetID != null && ! targetID.matches("\\w+://")) {

                        // extract fileName from target map
                        final String targetMapFileName = targetID.substring( targetID.indexOf("/") +1, targetID.indexOf("#") );
  [...]
---------------------------
(the substring fails at:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1911)
        at org.freeplane.features.link.mindmapmode.MLinkController.getAnchorIDforNode(MLinkController.java:1111)
        at org.freeplane.features.link.mindmapmode.MakeLinkToAnchorAction.actionPerformed(MakeLinkToAnchorAction.java:48))

If there is an important reason for initializing anchorID:="" (instead
of null) in the ctor, then we need to check for isAnchored() in
getAnchorIDForNode() and change isAnchored() such that it also checks
whether anchorID.equals(""). Here is a proposed patch:

-- a/freeplane/src/org/freeplane/features/link/mindmapmode/MLinkController.java
+++ b/freeplane/src/org/freeplane/features/link/mindmapmode/MLinkController.java
@@ -1098,14 +1098,14 @@ public class MLinkController extends LinkController {
        }
 
        public boolean isAnchored() {
-               return anchorID != null;
+               return anchorID != null && !anchorID.isEmpty();
        }
 
        public String getAnchorIDforNode(final NodeModel node) {
            String targetID = getAnchorID();
            final String link;
                // check if anchorID is valid, then set link in current node
-               if (targetID != null && ! targetID.matches("\\w+://")) {
+               if (isAnchored() && ! targetID.matches("\\w+://")) {
 
                        // extract fileName from target map
                        final String targetMapFileName = targetID.substring( targetID.indexOf("/") +1, targetID.indexOf("#") );

Is this ok?

Thanks and Best Regards,
--
Felix Natter



If you reply to this email, your message will be added to the discussion below:
http://freeplane-developer.996965.n3.nabble.com/Anchor-ID-Problems-tp118.html
To start a new topic under Freeplane Developer, email [hidden email]
To unsubscribe from Freeplane Developer, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Anchor ID Problems

Felix Natter
Administrator
"BArchibald [via Freeplane Developer]"
<[hidden email]> writes:

> Hi Felix,

hello Blair,

> I can't remember why I set it to "" - I guess I just thought it should have an initial
> value while I was refactoring the ctor (not a huge fan of passing nulls around!).
>
> Your patch looks great and solves the "" vs null problem!

Pushed :-)

BTW: Do you happen to have time for discussing stack traces this week?
=> this got a little easier with the indexFile addon where you can
easily annotate the *.log files in a mindmap :-)

Best Regards,
--
Felix Natter
Reply | Threaded
Open this post in threaded view
|

Re: Anchor ID Problems

BArchibald
Hi Felix,

I'll be able to look at stack traces this week but it will probably be in small blocks at a time.

Send them over and let me know how this .log annotations are meant to work :)

Many thanks,
Blair


On 5 February 2014 19:06, Felix Natter [via Freeplane Developer] <[hidden email]> wrote:
"BArchibald [via Freeplane Developer]"
<[hidden email]> writes:

> Hi Felix,

hello Blair,

> I can't remember why I set it to "" - I guess I just thought it should have an initial
> value while I was refactoring the ctor (not a huge fan of passing nulls around!).
>
> Your patch looks great and solves the "" vs null problem!

Pushed :-)

BTW: Do you happen to have time for discussing stack traces this week?
=> this got a little easier with the indexFile addon where you can
easily annotate the *.log files in a mindmap :-)

Best Regards,
--
Felix Natter



If you reply to this email, your message will be added to the discussion below:
http://freeplane-developer.996965.n3.nabble.com/Anchor-ID-Problems-tp118p121.html
To start a new topic under Freeplane Developer, email [hidden email]
To unsubscribe from Freeplane Developer, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Anchor ID Problems

Felix Natter
Administrator
"BArchibald [via Freeplane Developer]"
<[hidden email]> writes:

> Hi Felix,

hello Blair,

> I'll be able to look at stack traces this week but it will probably be in small blocks
> at a time.

I hope I'll be done with (most of) the stack traces tomorrow, then I
will send you the mindmap with the annotated reports.

>
> Send them over and let me know how this .log annotations are meant to
> work :)

Great, thanks.

Best Regards,
--
Felix Natter