detect if viewer is selected/deselected: how?

Home Forums Icy Kernel detect if viewer is selected/deselected: how?

  • Frederic Marion-Poll

    Hi all,
    not sure this is the right forum, but I have a Java-Icy programming question. I would like to trap if a viewer is selected or deselected.

    In my application, I generate several kymographs from of a stack of data. I draw polyline2D lines on them (to display the upper and lower limit of a territory) and I can edit these lines. What I would like to achieve is to “unselect” the 2Dpolyline that was currently edited (and selected) so that it will be displayed as a thin line, when the user is selecting another viewer.

    How can I trap this event? (view is un-selected). I suppose I should implement a Listener, but which one is the right one? (ActionListener, ChangeListener, ViewerListener, PropertyChangeListener).

    Thank you in advance,
    Fred

    Stephane Dallongeville

    Hi Frederic,

    Icy has that kind of event so you can actually listen them and react to it:

    Icy.getMainInterface().addActiveViewerListener(new ActiveViewerListener()
    {
      @Override
      public void viewerDeactivated(Viewer viewer)
      {
        // call when viewer just has been de-activated / unfocused
      }
    
      @Override
      public void viewerActivated(Viewer viewer)
      {
        // call when viewer just has been activated / focused
      }
    
      @Override
      public void activeViewerChanged(ViewerEvent event)
      {
        // call when active/focused viewer has changed (Z/T position change for instance)
      }
    });

    Hope that was what you were looking for.

    Best,

    – Stephane

    Frederic Marion-Poll

    Thank you!!!

    fred

    Frederic Marion-Poll

    PS is there a way to trap such event for “a” or a “specific type of” view? I am using 2 types of views, which are attached to 2 different types of sequences. I would like to trap activate/deactivate only for one type of view/sequence. Currently, I am associating these sequences only with the “standard” viewer. Should I derive the standard viewer and associate a specific viewer with each of my sequence types so that it will be easier to test the type of view that is selected / unselected?

    Stephane Dallongeville

    I guess that you use 2 separates Sequence (and so viewer) or you have many of them which can be from one type or another ? In the second case what you can do is to eventually use a specific mark in the Sequence name (or is its metadata ?) so instead of using the viewer event you directly use the sequence event.

    Here’s how you can store an information in Sequence metadata (persitent with the XML file):

    Node myNode = sequence.getNode(“myPluginMetadata”);

    // set type
    XMLUtil.setElementValue(myNode, “type”, “type1”);

    Then how use it for sequence activation event:

    Icy.getMainInterface().addActiveSequenceListener(new ActiveSequenceListener()
    {
    @Override
    public void sequenceDeactivated(Sequence sequence)
    {
    Node myNode = sequence.getNode(“myPluginMetadata”);

    // get sequence ‘type’
    if (XMLUtil.getElementValue(myNode, “type”, “”).equals(“typeA”))
    // do something
    }

    @Override
    public void sequenceActivated(Sequence sequence)
    {
    Node myNode = sequence.getNode(“myPluginMetadata”);

    // get sequence ‘type’
    if (XMLUtil.getElementValue(myNode, “type”, “”).equals(“typeA”))
    // do something
    }

    @Override
    public void activeSequenceChanged(SequenceEvent event)
    {
    // TODO Auto-generated method stub

    }
    });

    Frederic Marion-Poll

    Thank you Stephane! 🙂 yes, this works.

    It is quite simple indeed.

Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘Icy Kernel’ is closed to new topics and replies.