<commit_before>//
// TransformLink.java
//

/*
VisBio application for visualization of multidimensional
biological image data. Copyright (C) 2002-2004 <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.visbio.view;

import java.rmi.RemoteException;

import java.util.Vector;

import loci.visbio.VisBioFrame;

import loci.visbio.data.*;

import loci.visbio.state.Dynamic;

import loci.visbio.util.VisUtil;

import visad.*;

import visad.util.Util;

/** Represents a link between a data transform and a display. */
public class TransformLink
  implements DisplayListener, Dynamic, Runnable, TransformListener
{

  // -- Fields --

  /** Associated transform handler. */
  protected TransformHandler handler;

  /** Data transform linked to the display. */
  protected DataTransform trans;

  /** Data reference linking data to the display. */
  protected DataReferenceImpl ref;

  /** Data renderer for toggling data's visibility and other parameters. */
  protected DataRenderer rend;

  /** Separate thread for managing full-resolution burn-in. */
  protected Thread burnThread;

  /** Next clock time a full-resolution burn-in should occur. */
  protected long burnTime;

  /** Whether this link is still active. */
  protected boolean alive = true;

  /** Status message, to be displayed in bottom left corner. */
  protected VisADException status;

  /**
   * Range values for current cursor location,
   * to be displayed in bottom left corner.
   */
  protected VisADException[] cursor;

  /** Whether a TRANSFORM_DONE event should clear the status message. */
  protected boolean clearWhenDone;


  // -- Fields - initial state --

  /** Whether data transform is visible onscreen. */
  protected boolean visible;


  // -- Constructor --

  /** Constructs an uninitialized transform link. */
  public TransformLink(TransformHandler h) { handler = h; }

  /**
   * Creates a link between the given data transform and
   * the specified transform handler's display.
   */
  public TransformLink(TransformHandler h, DataTransform t) {
    handler = h;
    trans = t;
    visible = true;
    initState(null);
  }


  // -- TransformLink API methods --

  /** Gets the link's data transform. */
  public DataTransform getTransform() { return trans; }

  /** Gets the link's reference. */
  public DataReferenceImpl getReference() { return ref; }

  /** Gets the link's renderer. */
  public DataRenderer getRenderer() { return rend; }

  /** Links this transform into the display. */
  public void link() {
    try { handler.getWindow().getDisplay().addReferences(rend, ref); }
    catch (VisADException exc) { exc.printStackTrace(); }
    catch (RemoteException exc) { exc.printStackTrace(); }
  }

  /** Frees resources being consumed by this transform link. */
  public void destroy() { alive = false; }

  /** Toggles visibility of the transform. */
  public void setVisible(boolean vis) { rend.toggle(vis); }

  /** Gets visibility of the transform. */
  public boolean isVisible() {
    return rend == null ? visible : rend.getEnabled();
  }

  /** Sets status messages displayed in display's bottom left-hand corner. */
  public void setMessage(String msg) {
    status = msg == null ? null :
      new VisADException(trans.getName() + ": " + msg);
    doMessages(false);
  }


  // -- TransformLink API methods - state logic --

  /** Writes the current state. */
  public void saveState(DisplayWindow window, String attrName) {
    VisBioFrame bio = handler.getWindow().getVisBio();
    DataManager dm = (DataManager) bio.getManager(DataManager.class);
    Vector dataList = dm.getDataList();
    int ndx = dataList.indexOf(trans);
    window.setAttr(attrName + "_dataIndex", "" + ndx);
    window.setAttr(attrName + "_visible", "" + isVisible());
  }

  /** Restores the current state. */
  public void restoreState(DisplayWindow window, String attrName) {
    VisBioFrame bio = handler.getWindow().getVisBio();
    DataManager dm = (DataManager) bio.getManager(DataManager.class);
    Vector dataList = dm.getDataList();
    int dataIndex = Integer.parseInt(window.getAttr(attrName + "_dataIndex"));
    trans = (DataTransform) dataList.elementAt(dataIndex);
    visible = window.getAttr(attrName + "_visible").equalsIgnoreCase("true");
  }


  // -- DisplayListener API methods --

  /** Ensures status messages stay visible. */
  public void displayChanged(DisplayEvent e) {
    int id = e.getId();
    if (id == DisplayEvent.FRAME_DONE) {
      computeCursor();
      doMessages(true);
    }
    else if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
      if (clearWhenDone) {
        setMessage(null);
        clearWhenDone = false;
      }
      else doMessages(false);
    }
  }<commit_msg>Notify data transform whenever user gestures with the mouse in a linked display (so that transform can provide user interaction).<commit_after>//
// TransformLink.java
//

/*
VisBio application for visualization of multidimensional
biological image data. Copyright (C) 2002-2004 <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.visbio.view;

import java.rmi.RemoteException;

import java.util.Vector;

import loci.visbio.VisBioFrame;

import loci.visbio.data.*;

import loci.visbio.state.Dynamic;

import loci.visbio.util.VisUtil;

import visad.*;

import visad.util.Util;

/** Represents a link between a data transform and a display. */
public class TransformLink
  implements DisplayListener, Dynamic, Runnable, TransformListener
{

  // -- Fields --

  /** Associated transform handler. */
  protected TransformHandler handler;

  /** Data transform linked to the display. */
  protected DataTransform trans;

  /** Data reference linking data to the display. */
  protected DataReferenceImpl ref;

  /** Data renderer for toggling data's visibility and other parameters. */
  protected DataRenderer rend;

  /** Separate thread for managing full-resolution burn-in. */
  protected Thread burnThread;

  /** Next clock time a full-resolution burn-in should occur. */
  protected long burnTime;

  /** Whether this link is still active. */
  protected boolean alive = true;

  /** Status message, to be displayed in bottom left corner. */
  protected VisADException status;

  /**
   * Range values for current cursor location,
   * to be displayed in bottom left corner.
   */
  protected VisADException[] cursor;

  /** Whether a TRANSFORM_DONE event should clear the status message. */
  protected boolean clearWhenDone;


  // -- Fields - initial state --

  /** Whether data transform is visible onscreen. */
  protected boolean visible;


  // -- Constructor --

  /** Constructs an uninitialized transform link. */
  public TransformLink(TransformHandler h) { handler = h; }

  /**
   * Creates a link between the given data transform and
   * the specified transform handler's display.
   */
  public TransformLink(TransformHandler h, DataTransform t) {
    handler = h;
    trans = t;
    visible = true;
    initState(null);
  }


  // -- TransformLink API methods --

  /** Gets the link's data transform. */
  public DataTransform getTransform() { return trans; }

  /** Gets the link's reference. */
  public DataReferenceImpl getReference() { return ref; }

  /** Gets the link's renderer. */
  public DataRenderer getRenderer() { return rend; }

  /** Links this transform into the display. */
  public void link() {
    try { handler.getWindow().getDisplay().addReferences(rend, ref); }
    catch (VisADException exc) { exc.printStackTrace(); }
    catch (RemoteException exc) { exc.printStackTrace(); }
  }

  /** Frees resources being consumed by this transform link. */
  public void destroy() { alive = false; }

  /** Toggles visibility of the transform. */
  public void setVisible(boolean vis) { rend.toggle(vis); }

  /** Gets visibility of the transform. */
  public boolean isVisible() {
    return rend == null ? visible : rend.getEnabled();
  }

  /** Sets status messages displayed in display's bottom left-hand corner. */
  public void setMessage(String msg) {
    status = msg == null ? null :
      new VisADException(trans.getName() + ": " + msg);
    doMessages(false);
  }


  // -- TransformLink API methods - state logic --

  /** Writes the current state. */
  public void saveState(DisplayWindow window, String attrName) {
    VisBioFrame bio = handler.getWindow().getVisBio();
    DataManager dm = (DataManager) bio.getManager(DataManager.class);
    Vector dataList = dm.getDataList();
    int ndx = dataList.indexOf(trans);
    window.setAttr(attrName + "_dataIndex", "" + ndx);
    window.setAttr(attrName + "_visible", "" + isVisible());
  }

  /** Restores the current state. */
  public void restoreState(DisplayWindow window, String attrName) {
    VisBioFrame bio = handler.getWindow().getVisBio();
    DataManager dm = (DataManager) bio.getManager(DataManager.class);
    Vector dataList = dm.getDataList();
    int dataIndex = Integer.parseInt(window.getAttr(attrName + "_dataIndex"));
    trans = (DataTransform) dataList.elementAt(dataIndex);
    visible = window.getAttr(attrName + "_visible").equalsIgnoreCase("true");
  }


  // -- DisplayListener API methods --

  /** Handles VisAD display events. */
  public void displayChanged(DisplayEvent e) {
    // ensure status messages stay visible
    int id = e.getId();
    if (id == DisplayEvent.FRAME_DONE) {
      computeCursor();
      doMessages(true);
    }
    else if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
      if (clearWhenDone) {
        setMessage(null);
        clearWhenDone = false;
      }
      else doMessages(false);
    }

    // pass along DisplayEvents to linked transform
    trans.displayChanged(e);
  }
{'fraction_non_alphanumeric': 0.10473929321523148, 'fraction_numerical': 0.004200529631997078, 'mean_word_length': 3.398393574297189, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6120248', 'n_tokens_mistral': 3072, 'n_tokens_neox': 2887, 'n_words': 1078}