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 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;
 }
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

  }
}
  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;
  }