Skip to content

Generate fiji url links and process them: in progress #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: link
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/java/bdv/tools/links/LinkActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import static bdv.tools.links.ClipboardUtils.getFromClipboard;

import java.io.UnsupportedEncodingException;

import org.scijava.plugin.Plugin;
import org.scijava.ui.behaviour.io.gui.CommandDescriptionProvider;
import org.scijava.ui.behaviour.io.gui.CommandDescriptions;
Expand All @@ -53,9 +55,11 @@ public class LinkActions

public static final String COPY_VIEWER_STATE = "copy viewer state";
public static final String PASTE_VIEWER_STATE = "paste viewer state";
public static final String GENERATE_LINK_VIEWER_STATE = "generate link viewer state";

public static final String[] COPY_VIEWER_STATE_KEYS = new String[] { "ctrl C", "meta C" };
public static final String[] PASTE_VIEWER_STATE_KEYS = new String[] { "ctrl V", "meta V" };
public static final String[] GENERATE_LINK_VIEWER_STATE_KEYS = new String[] { "ctrl L", "meta L" };

/*
* Command descriptions for all provided commands
Expand All @@ -73,6 +77,7 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )
{
descriptions.add( COPY_VIEWER_STATE, COPY_VIEWER_STATE_KEYS, "Copy the current viewer state as a string." );
descriptions.add( PASTE_VIEWER_STATE, PASTE_VIEWER_STATE_KEYS, "Paste the current viewer state from a string." );
descriptions.add( GENERATE_LINK_VIEWER_STATE, GENERATE_LINK_VIEWER_STATE_KEYS, "Generate a fiji uri link to the current viewer state and copy it to the clipboard." );
}
}

Expand All @@ -85,6 +90,22 @@ private static void copyViewerState(
ClipboardUtils.copyToClipboard( json.toString() );
}

private static void generateLinkViewerState(
final AbstractViewerPanel panel,
final ConverterSetups converterSetups,
final ResourceManager resources )
{
final JsonElement json = Links.copyJson( panel, converterSetups, resources );
try{
final String link = Links.generateLink( json );
ClipboardUtils.copyToClipboard( link);
LOG.debug( "Generated link: {}", link );
}
catch (final UnsupportedEncodingException e) {
LOG.debug( "couldn't generate link from JSON:\n\"{}\"", json, e );
}
}

private static void pasteViewerState(
final AbstractViewerPanel panel,
final ConverterSetups converterSetups,
Expand Down Expand Up @@ -133,5 +154,8 @@ public static void install(
COPY_VIEWER_STATE, COPY_VIEWER_STATE_KEYS );
actions.runnableAction( () -> pasteViewerState( panel, converterSetups, pasteSettings, resources ),
PASTE_VIEWER_STATE, PASTE_VIEWER_STATE_KEYS );
actions.runnableAction( () -> generateLinkViewerState( panel, converterSetups, resources ),
GENERATE_LINK_VIEWER_STATE, GENERATE_LINK_VIEWER_STATE_KEYS );

}
}
11 changes: 11 additions & 0 deletions src/main/java/bdv/tools/links/Links.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import static bdv.tools.links.PasteSettings.SourceMatchingMethod.BY_INDEX;
import static bdv.tools.links.PasteSettings.SourceMatchingMethod.BY_SPEC_LOAD_MISSING;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -41,6 +44,8 @@ class Links
{
private static final Logger LOG = LoggerFactory.getLogger( Links.class );

final static String BASE_URL = "fiji://bdv?";

static JsonElement copyJson(
final AbstractViewerPanel panel,
final ConverterSetups converterSetups,
Expand Down Expand Up @@ -413,5 +418,11 @@ public JsonElement serialize(
}
}
}

public static String generateLink(JsonElement json) throws UnsupportedEncodingException{
final String jsonString = json.toString();
return BASE_URL + java.net.URLEncoder.encode(jsonString, java.nio.charset.StandardCharsets.UTF_8.name());
}

}

6 changes: 5 additions & 1 deletion src/main/resources/bdv/ui/keymap/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,8 @@
- !mapping
action: paste viewer state
contexts: [bdv]
triggers: [ctrl V, meta V]
triggers: [ctrl V, meta V]
- !mapping
action: generate link viewer state
contexts: [bdv]
triggers: [ctrl L, meta L]