Ejemplo n.º 1
0
  @Override
  public void paint(Graphics2D g2) {
    ImageElement image = view2DPane.getImage();
    if (!visible || image == null) {
      return;
    }

    final Rectangle bound = view2DPane.getBounds();
    float midx = bound.width / 2f;
    float midy = bound.height / 2f;

    g2.setPaint(color);

    final float fontHeight = FontTools.getAccurateFontHeight(g2);
    final float midfontHeight = fontHeight * FontTools.getMidFontHeightFactor();
    float drawY = bound.height - border - 1.5f; // -1.5 for outline

    if (!image.isReadable()) {
      String message = Messages.getString("InfoLayer.error_msg"); // $NON-NLS-1$
      float y = midy;
      GraphicLabel.paintColorFontOutline(
          g2, message, midx - g2.getFontMetrics().stringWidth(message) / 2, y, Color.RED);
      String[] desc = image.getMediaReader().getReaderDescription();
      if (desc != null) {
        for (String str : desc) {
          if (str != null) {
            y += fontHeight;
            GraphicLabel.paintColorFontOutline(
                g2, str, midx - g2.getFontMetrics().stringWidth(str) / 2, y, Color.RED);
          }
        }
      }
    }
    if (image.isReadable() && getDisplayPreferences(SCALE)) {
      drawScale(g2, bound, fontHeight);
    }
    if (image.isReadable() && getDisplayPreferences(LUT)) {
      drawLUT(g2, bound, midfontHeight);
    }

    if (getDisplayPreferences(PIXEL)) {
      String str =
          Messages.getString("InfoLayer.pix") + ": " + pixelInfo; // $NON-NLS-1$ //$NON-NLS-2$
      GraphicLabel.paintFontOutline(g2, str, border, drawY - 1);
      drawY -= fontHeight + 2;
      pixelInfoBound.setBounds(
          border - 2,
          (int) drawY + 3,
          g2.getFontMetrics().stringWidth(str) + 4,
          (int) fontHeight + 2);
      // g2.draw(pixelInfoBound);
    }
    if (getDisplayPreferences(WINDOW_LEVEL)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.win")
              + ": "
              + view2DPane.getActionValue(ActionW.WINDOW.cmd()) // $NON-NLS-1$ //$NON-NLS-2$
              + " "
              + Messages.getString("InfoLayer.level")
              + ": "
              + view2DPane.getActionValue(ActionW.LEVEL.cmd()),
          border,
          drawY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      drawY -= fontHeight;
    }
    if (getDisplayPreferences(ZOOM)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.zoom")
              + ": "
              + DecFormater.twoDecimal(view2DPane.getViewModel().getViewScale() * 100)
              + " "
              + Messages.getString("InfoLayer.percent"),
          border, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          drawY);
      drawY -= fontHeight;
    }
    if (getDisplayPreferences(ROTATION)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.angle")
              + ": "
              + view2DPane.getActionValue(ActionW.ROTATION.cmd())
              + " "
              + Messages.getString("InfoLayer.angle_symb"),
          border,
          drawY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      drawY -= fontHeight;
    }

    if (getDisplayPreferences(FRAME)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.frame") // $NON-NLS-1$
              + ": " //$NON-NLS-1$
              + (view2DPane.getFrameIndex() + 1)
              + " / " //$NON-NLS-1$
              + view2DPane
                  .getSeries()
                  .size(
                      (Filter<ImageElement>)
                          view2DPane.getActionValue(ActionW.FILTERED_SERIES.cmd())),
          border,
          drawY);
      drawY -= fontHeight;
    }

    // if (getDisplayPreferences(ANNOTATIONS)) {
    // MediaSeries<ImageElement> series = view2DPane.getSeries();
    //
    // Boolean synchLink = (Boolean) view2DPane.getActionValue(ActionW.SYNCH_LINK.cmd());
    // String str = synchLink != null && synchLink ? "linked" : "unlinked";
    // paintFontOutline(g2, str, bound.width - g2.getFontMetrics().stringWidth(str) - border,
    // drawY);
    //
    // }

  }
Ejemplo n.º 2
0
public class ImageTool extends PluginTool {

  public static final String BUTTON_NAME = Messages.getString("ImageTool.imgtool"); // $NON-NLS-1$

  public static final Font TITLE_FONT = FontTools.getFont12Bold();
  public static final Color TITLE_COLOR = Color.GRAY;

  private final JScrollPane rootPane = new JScrollPane();
  private final Border spaceY = BorderFactory.createEmptyBorder(10, 3, 0, 3);

  public ImageTool(String pluginName, Icon icon) {
    super(BUTTON_NAME, pluginName, PluginTool.Type.TOOL, 20);
    dockable.setTitleIcon(
        new ImageIcon(ImageTool.class.getResource("/icon/16x16/image.png"))); // $NON-NLS-1$
    setDockableWidth(290);
    jbInit();
  }

  private void jbInit() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(getWindowLevelPanel());
    add(getTransformPanel());
    add(getSlicePanel());
    add(getResetPanel());

    final JPanel panel_1 = new JPanel();
    panel_1.setAlignmentY(Component.TOP_ALIGNMENT);
    panel_1.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel_1.setLayout(new GridBagLayout());
    add(panel_1);
  }

  @Override
  public Component getToolComponent() {
    JViewport viewPort = rootPane.getViewport();
    if (viewPort == null) {
      viewPort = new JViewport();
      rootPane.setViewport(viewPort);
    }
    if (viewPort.getView() != this) {
      viewPort.setView(this);
    }
    return rootPane;
  }

  public JPanel getResetPanel() {
    final JPanel panel_2 = new JPanel();
    panel_2.setAlignmentY(Component.TOP_ALIGNMENT);
    panel_2.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 3));
    panel_2.setBorder(
        BorderFactory.createCompoundBorder(
            spaceY,
            new TitledBorder(
                null,
                Messages.getString("ImageTool.reset"), // $NON-NLS-1$
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION,
                TITLE_FONT,
                TITLE_COLOR)));
    final JComboBox resetComboBox = new JComboBox(ResetTools.values());
    panel_2.add(resetComboBox);

    final JButton resetButton = new JButton();
    resetButton.setText(Messages.getString("ImageTool.reset")); // $NON-NLS-1$
    resetButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            EventManager.getInstance().reset((ResetTools) resetComboBox.getSelectedItem());
          }
        });
    panel_2.add(resetButton);
    ActionState resetAction = EventManager.getInstance().getAction(ActionW.RESET);
    if (resetAction != null) {
      resetAction.registerActionState(resetButton);
    }
    return panel_2;
  }

  public JPanel getSlicePanel() {

    final JPanel framePanel = new JPanel();
    framePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    framePanel.setAlignmentY(Component.TOP_ALIGNMENT);
    framePanel.setLayout(new BoxLayout(framePanel, BoxLayout.Y_AXIS));
    framePanel.setBorder(
        BorderFactory.createCompoundBorder(
            spaceY,
            new TitledBorder(
                null,
                Messages.getString("ImageTool.frame"), // $NON-NLS-1$
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION,
                TITLE_FONT,
                TITLE_COLOR)));

    ActionState sequence = EventManager.getInstance().getAction(ActionW.SCROLL_SERIES);
    if (sequence instanceof SliderCineListener) {
      SliderCineListener cineAction = (SliderCineListener) sequence;
      final JSliderW frameSlider = cineAction.createSlider(4, true);
      framePanel.add(frameSlider.getParent());

      final JPanel panel_3 = new JPanel();
      panel_3.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 3));
      final JLabel speedLabel = new JLabel();
      speedLabel.setText(
          Messages.getString("ImageTool.cine_speed") + StringUtil.COLON); // $NON-NLS-1$
      panel_3.add(speedLabel);

      final JSpinner speedSpinner = new JSpinner(cineAction.getSpeedModel());
      JMVUtils.formatCheckAction(speedSpinner);
      panel_3.add(speedSpinner);
      final JButton startButton = new JButton();
      startButton.setActionCommand(ActionW.CINESTART.cmd());
      startButton.setPreferredSize(JMVUtils.getBigIconButtonSize());
      startButton.setToolTipText(Messages.getString("ImageTool.cine_start")); // $NON-NLS-1$
      startButton.setIcon(
          new ImageIcon(
              MouseActions.class.getResource(
                  "/icon/22x22/media-playback-start.png"))); //$NON-NLS-1$
      startButton.addActionListener(EventManager.getInstance());
      panel_3.add(startButton);
      cineAction.registerActionState(startButton);

      final JButton stopButton = new JButton();
      stopButton.setActionCommand(ActionW.CINESTOP.cmd());
      stopButton.setPreferredSize(JMVUtils.getBigIconButtonSize());
      stopButton.setToolTipText(Messages.getString("ImageTool.cine_stop")); // $NON-NLS-1$
      stopButton.setIcon(
          new ImageIcon(
              MouseActions.class.getResource(
                  "/icon/22x22/media-playback-stop.png"))); //$NON-NLS-1$
      stopButton.addActionListener(EventManager.getInstance());
      panel_3.add(stopButton);
      cineAction.registerActionState(stopButton);
      framePanel.add(panel_3);
    }
    return framePanel;
  }

  public JPanel getWindowLevelPanel() {

    final JPanel winLevelPanel = new JPanel();
    winLevelPanel.setAlignmentY(Component.TOP_ALIGNMENT);
    winLevelPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    winLevelPanel.setLayout(new BoxLayout(winLevelPanel, BoxLayout.Y_AXIS));
    winLevelPanel.setBorder(
        BorderFactory.createCompoundBorder(
            spaceY,
            new TitledBorder(
                null,
                Messages.getString("ImageTool.wl"), // $NON-NLS-1$
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION,
                TITLE_FONT,
                TITLE_COLOR)));
    ActionState winAction = EventManager.getInstance().getAction(ActionW.WINDOW);
    if (winAction instanceof SliderChangeListener) {
      final JSliderW windowSlider = ((SliderChangeListener) winAction).createSlider(4, true);
      // windowSlider.setMajorTickSpacing((largestWindow - smallestWindow) / 4);
      JMVUtils.setPreferredWidth(windowSlider, 100);
      winLevelPanel.add(windowSlider.getParent());
    }
    ActionState levelAction = EventManager.getInstance().getAction(ActionW.LEVEL);
    if (levelAction instanceof SliderChangeListener) {
      final JSliderW levelSlider = ((SliderChangeListener) levelAction).createSlider(4, true);
      levelSlider.setMajorTickSpacing(
          (ImageViewerEventManager.LEVEL_LARGEST - ImageViewerEventManager.LEVEL_SMALLEST) / 4);
      JMVUtils.setPreferredWidth(levelSlider, 100);
      winLevelPanel.add(levelSlider.getParent());
    }
    ActionState presetAction = EventManager.getInstance().getAction(ActionW.PRESET);
    if (presetAction instanceof ComboItemListener) {
      final JPanel panel_3 = new JPanel();
      panel_3.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 3));
      final JLabel presetsLabel = new JLabel();
      panel_3.add(presetsLabel);
      presetsLabel.setText(
          Messages.getString("ImageTool.preset") + StringUtil.COLON); // $NON-NLS-1$
      final JComboBox presetComboBox = ((ComboItemListener) presetAction).createCombo(160);
      presetComboBox.setMaximumRowCount(10);
      panel_3.add(presetComboBox);
      winLevelPanel.add(panel_3);
    }
    ActionState lutAction = EventManager.getInstance().getAction(ActionW.LUT);
    if (lutAction instanceof ComboItemListener) {
      final JPanel panel_4 = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 3));
      final JLabel lutLabel = new JLabel();
      lutLabel.setText(Messages.getString("ImageTool.lut") + StringUtil.COLON); // $NON-NLS-1$
      panel_4.add(lutLabel);
      final JComboBox lutcomboBox = ((ComboItemListener) lutAction).createCombo(140);
      panel_4.add(lutcomboBox);
      ActionState invlutAction = EventManager.getInstance().getAction(ActionW.INVERT_LUT);
      if (invlutAction instanceof ToggleButtonListener) {
        panel_4.add(
            ((ToggleButtonListener) invlutAction)
                .createCheckBox(Messages.getString("ImageTool.inverse"))); // $NON-NLS-1$
      }
      winLevelPanel.add(panel_4);
    }
    ActionState filterAction = EventManager.getInstance().getAction(ActionW.FILTER);
    if (filterAction instanceof ComboItemListener) {
      final JPanel panel_4 = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 3));
      final JLabel lutLabel = new JLabel();
      lutLabel.setText(Messages.getString("ImageTool.filter")); // $NON-NLS-1$
      panel_4.add(lutLabel);
      final JComboBox filtercomboBox = ((ComboItemListener) filterAction).createCombo(160);
      panel_4.add(filtercomboBox);
      winLevelPanel.add(panel_4);
    }
    return winLevelPanel;
  }

  public JPanel getTransformPanel() {
    final JPanel transform = new JPanel();
    transform.setAlignmentY(Component.TOP_ALIGNMENT);
    transform.setAlignmentX(Component.LEFT_ALIGNMENT);
    transform.setLayout(new BoxLayout(transform, BoxLayout.Y_AXIS));
    transform.setBorder(
        BorderFactory.createCompoundBorder(
            spaceY,
            new TitledBorder(
                null,
                Messages.getString("ImageTool.transform"), // $NON-NLS-1$
                TitledBorder.DEFAULT_JUSTIFICATION,
                TitledBorder.DEFAULT_POSITION,
                TITLE_FONT,
                TITLE_COLOR)));
    ActionState zoomAction = EventManager.getInstance().getAction(ActionW.ZOOM);
    if (zoomAction instanceof SliderChangeListener) {
      final JSliderW zoomSlider = ((SliderChangeListener) zoomAction).createSlider(0, true);
      JMVUtils.setPreferredWidth(zoomSlider, 100);
      transform.add(zoomSlider.getParent());
    }
    ActionState rotateAction = EventManager.getInstance().getAction(ActionW.ROTATION);
    if (rotateAction instanceof SliderChangeListener) {
      final JSliderW rotationSlider = ((SliderChangeListener) rotateAction).createSlider(4, true);
      JMVUtils.setPreferredWidth(rotationSlider, 100);
      transform.add(rotationSlider.getParent());
    }
    ActionState flipAction = EventManager.getInstance().getAction(ActionW.FLIP);
    if (flipAction instanceof ToggleButtonListener) {
      JPanel pane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 3));
      pane.add(
          ((ToggleButtonListener) flipAction)
              .createCheckBox(Messages.getString("ImageTool.flip"))); // $NON-NLS-1$
      transform.add(pane);
    }
    return transform;
  }

  @Override
  protected void changeToolWindowAnchor(CLocation clocation) {
    // TODO Auto-generated method stub

  }
}