public class TextFieldFilter extends IcyTextField {

  /** */
  private static final long serialVersionUID = 1L;

  Image img = ResourceUtil.getAlphaIconAsImage("zoom");

  public TextFieldFilter() {}

  public TextFieldFilter(String name) {
    super(name);
  }

  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g.create();
    int w = getWidth();
    int h = getHeight();

    // set rendering presets
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

    // draw images
    g2.drawImage(img, w - h, 5, h - 10, h - 10, null);
    g2.dispose();
  }
}
  /**
   * @param title
   * @throws HeadlessException
   */
  public IcyExternalFrame(String title) throws HeadlessException {
    super(title);

    getRootPane()
        .addPropertyChangeListener(
            "titlePane",
            new PropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                // invoke later so the titlePane variable is up to date
                ThreadUtil.invokeLater(
                    new Runnable() {
                      @Override
                      public void run() {
                        updateTitlePane();
                      }
                    });
              }
            });

    setIconImages(ResourceUtil.getIcyIconImages());
    setVisible(false);

    systemMenuCallback = null;
    closeItemVisible = true;
    updateTitlePane(LookAndFeelUtil.getTitlePane(this));

    titleBarVisible = true;
    initialized = true;
  }
Пример #3
0
/** @author Stephane */
public class ImageJTask extends RibbonTask implements PropertyChangeListener {
  static final BufferedImage detachForIJ = ResourceUtil.getImage("help/ij_detached.jpg");

  private static class ImageJRibbonBand extends JRibbonBand {
    /** */
    private static final long serialVersionUID = 4431425194428863269L;

    public static final String NAME = "ImageJ";

    // ImageJ instance
    final ImageJWrapper imageJ;

    // internal
    final JRibbonComponent imageJComp;

    public ImageJRibbonBand() {
      super(
          NAME,
          new BasicResizableIcon(ImageUtil.loadImage(ImageJ.class.getResource("/microscope.gif"))));

      // initialize some static ImageJ stuff

      // home directory
      System.setProperty("plugins.dir", "ij");
      // background color
      ImageJ.backgroundColor = LookAndFeelUtil.getBackground(this);

      // create ImageJ wrapper
      imageJ = new ImageJWrapper();
      imageJComp = new JRibbonComponent(imageJ.getSwingPanel());

      // add ImageJ GUI wrapper to ribbon
      addRibbonComponent(imageJComp, 3);

      RibbonUtil.setRestrictiveResizePolicies(this);
    }
  }

  private static class ImageJToolRibbonBand extends JRibbonBand {
    /** */
    private static final long serialVersionUID = -6873081018953405306L;

    public static final String NAME = "Tools";

    /** internals */
    final IcyCommandButton button;

    final IcyCommandToggleButton detachedBtn;
    final CommandToggleButtonGroup detachedGrp;

    boolean toIJ;
    final ActionListener toIJAction;
    final ActionListener toICYAction;

    public ImageJToolRibbonBand() {
      super(NAME, new IcyIcon("brackets"));

      // action to convert to IJ image
      toIJAction =
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              ThreadUtil.bgRun(
                  new Runnable() {
                    @Override
                    public void run() {
                      final Sequence seq = Icy.getMainInterface().getFocusedSequence();

                      if (seq != null) {
                        final ProgressFrame pf = new ProgressFrame("Converting to ImageJ image...");
                        final ImagePlus ip = ImageJUtil.convertToImageJImage(seq, pf);
                        pf.close();

                        ThreadUtil.invokeLater(
                            new Runnable() {
                              @Override
                              public void run() {
                                // show the image
                                ip.show();
                              }
                            });
                      }
                    }
                  });
            }
          };

      // action to convert to ICY sequence
      toICYAction =
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              ThreadUtil.bgRun(
                  new Runnable() {
                    @Override
                    public void run() {
                      final ImagePlus ip = WindowManager.getCurrentImage();

                      if (ip != null) {
                        final ProgressFrame pf = new ProgressFrame("Converting to ImageJ image...");
                        final Sequence seq = ImageJUtil.convertToIcySequence(ip, pf);
                        pf.close();

                        ThreadUtil.invokeLater(
                            new Runnable() {
                              @Override
                              public void run() {
                                // show the sequence
                                new Viewer(seq);
                              }
                            });
                      }
                    }
                  });
            }
          };

      // convert operation
      button = new IcyCommandButton("Convert to ImageJ", new IcyIcon("to_ij"));

      toIJ = false;
      updateAction(true);

      addCommandButton(button, RibbonElementPriority.TOP);

      final RichTooltip richToolTip =
          new RichTooltip(
              "Detached windows",
              "Icy need to be set in detached mode to use ImageJ efficiently and enable image conversion.");
      richToolTip.setMainImage(detachForIJ);
      richToolTip.addDescriptionSection(
          "This button has the same effect as the detached mode button in the top toolbar.");

      // detach windows button
      detachedBtn =
          new IcyCommandToggleButton(
              "Detached mode", new IcyIcon(ResourceUtil.ICON_DETACHED_WINDOW));
      detachedBtn.setActionRichTooltip(richToolTip);
      detachedBtn.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              final boolean value = (detachedGrp.getSelected() == detachedBtn);

              // set detached mode
              Icy.getMainInterface().setDetachedMode(value);
              // and save state
              GeneralPreferences.setMultiWindowMode(value);
            }
          });

      detachedGrp = new CommandToggleButtonGroup();
      detachedGrp.add(detachedBtn);

      addCommandButton(detachedBtn, RibbonElementPriority.TOP);

      RibbonUtil.setPermissiveResizePolicies(this);
    }

    public void updateAction(boolean ij) {
      if (toIJ != ij) {
        final RichTooltip toolTip = new RichTooltip();
        toIJ = ij;

        if (ij) {
          toolTip.setTitle("Convert to ImageJ");
          toolTip.addDescriptionSection("Convert the selected Icy sequence to ImageJ image.");
          toolTip.addFooterSection("Icy needs to be in detached mode to enabled this feature.");

          // convert to IJ image
          button.setText("Convert to IJ");
          // button.setIcon(new IcyIcon("icon_icy_ij_2", false));
          button.setIcon(new IcyIcon("to_ij", true));
          button.setActionRichTooltip(toolTip);
          button.removeActionListener(toICYAction);
          button.addActionListener(toIJAction);
        } else {
          toolTip.setTitle("Convert to Icy");
          toolTip.addDescriptionSection("Convert the selected ImageJ image to Icy sequence.");
          toolTip.addFooterSection("Icy needs to be in detached mode to enabled this feature.");

          // convert to ICY sequence
          button.setText("Convert to Icy");
          // button.setIcon(new IcyIcon("icon_ij_icy_2", false));
          button.setIcon(new IcyIcon("to_icy", true));
          button.setActionRichTooltip(toolTip);
          button.removeActionListener(toIJAction);
          button.addActionListener(toICYAction);
        }
      }
    }

    public void updateEnable(boolean value) {
      button.setEnabled(value);
    }

    public void setDetachedBtnPressed(boolean value) {
      detachedGrp.setSelected(detachedBtn, value);
    }
  }

  public static final String NAME = "ImageJ";

  public ImageJTask() {
    super(NAME, new ImageJRibbonBand(), new ImageJToolRibbonBand());

    getImageJ()
        .addActiveImageListener(
            new ImageJActiveImageListener() {
              @Override
              public void imageActived(ImageWindow iw) {
                ((ImageJToolRibbonBand) getBand(1)).updateAction(iw == null);
              }
            });
  }

  /** Initialization stuff which cannot be done at construction time */
  public void init() {
    // refresh band state
    propertyChange(null);

    final MainFrame mainFrame = Icy.getMainInterface().getMainFrame();
    // we listen detach mode change
    if (mainFrame != null)
      mainFrame.addPropertyChangeListener(MainFrame.PROPERTY_DETACHEDMODE, this);
  }

  /** @return the imageJ */
  public ImageJWrapper getImageJ() {
    return ((ImageJRibbonBand) getBand(0)).imageJ;
  }

  /** Quit imageJ */
  public void quitImageJ() {
    new Executer("Quit", null);
  }

  /** Handle {@link MainFrame#PROPERTY_DETACHEDMODE} property change here. */
  @Override
  public void propertyChange(PropertyChangeEvent evt) {
    final boolean isDetached = Icy.getMainInterface().isDetachedMode();
    final ImageJToolRibbonBand band = (ImageJToolRibbonBand) getBand(1);

    band.setDetachedBtnPressed(isDetached);
    band.updateEnable(isDetached);
  }
}
Пример #4
0
 /**
  * Return the icon resource from given resource name
  *
  * @param resourceName resource name
  */
 public ImageIcon getIconResource(String resourceName) {
   return ResourceUtil.getImageIcon(getImageResource(resourceName));
 }