Ejemplo n.º 1
0
  @Override
  public JComponent createControl() {
    layerCanvasModelChangeChangeHandler = new LayerCanvasModelChangeHandler();
    productNodeChangeHandler = createProductNodeListener();
    cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp());

    final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    scaleFormat = new DecimalFormat("#####.##", decimalFormatSymbols);
    scaleFormat.setGroupingUsed(false);
    scaleFormat.setDecimalSeparatorAlwaysShown(false);

    zoomInButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ZoomIn24.gif"), false);
    zoomInButton.setToolTipText("Zoom in."); /*I18N*/
    zoomInButton.setName("zoomInButton");
    zoomInButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            zoom(getCurrentView().getZoomFactor() * 1.2);
          }
        });

    zoomOutButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ZoomOut24.gif"), false);
    zoomOutButton.setName("zoomOutButton");
    zoomOutButton.setToolTipText("Zoom out."); /*I18N*/
    zoomOutButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            zoom(getCurrentView().getZoomFactor() / 1.2);
          }
        });

    zoomDefaultButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ZoomPixel24.gif"), false);
    zoomDefaultButton.setToolTipText("Actual Pixels (image pixel = view pixel)."); /*I18N*/
    zoomDefaultButton.setName("zoomDefaultButton");
    zoomDefaultButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            zoomToPixelResolution();
          }
        });

    zoomAllButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ZoomAll24.gif"), false);
    zoomAllButton.setName("zoomAllButton");
    zoomAllButton.setToolTipText("Zoom all."); /*I18N*/
    zoomAllButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            zoomAll();
          }
        });

    syncViewsButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SyncViews24.png"), true);
    syncViewsButton.setToolTipText("Synchronise compatible product views."); /*I18N*/
    syncViewsButton.setName("syncViewsButton");
    syncViewsButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            maybeSynchronizeCompatibleProductViews();
          }
        });

    syncCursorButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SyncCursor24.png"), true);
    syncCursorButton.setToolTipText("Synchronise cursor position."); /*I18N*/
    syncCursorButton.setName("syncCursorButton");
    syncCursorButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            cursorSynchronizer.setEnabled(syncCursorButton.isSelected());
          }
        });

    AbstractButton helpButton =
        ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help24.gif"), false);
    helpButton.setToolTipText("Help."); /*I18N*/
    helpButton.setName("helpButton");

    final JPanel eastPane = GridBagUtils.createPanel();
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;

    gbc.gridy = 0;
    eastPane.add(zoomInButton, gbc);

    gbc.gridy++;
    eastPane.add(zoomOutButton, gbc);

    gbc.gridy++;
    eastPane.add(zoomDefaultButton, gbc);

    gbc.gridy++;
    eastPane.add(zoomAllButton, gbc);

    gbc.gridy++;
    eastPane.add(syncViewsButton, gbc);

    gbc.gridy++;
    eastPane.add(syncCursorButton, gbc);

    gbc.gridy++;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.VERTICAL;
    eastPane.add(new JLabel(" "), gbc); // filler
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;

    gbc.gridy++;
    eastPane.add(helpButton, gbc);

    zoomFactorField = new JTextField();
    zoomFactorField.setColumns(8);
    zoomFactorField.setHorizontalAlignment(JTextField.CENTER);
    zoomFactorField.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            handleZoomFactorFieldUserInput();
          }
        });
    zoomFactorField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(final FocusEvent e) {
            handleZoomFactorFieldUserInput();
          }
        });

    rotationAngleSpinner = new JSpinner(new SpinnerNumberModel(0.0, -1800.0, 1800.0, 5.0));
    final JSpinner.NumberEditor editor = (JSpinner.NumberEditor) rotationAngleSpinner.getEditor();
    rotationAngleField = editor.getTextField();
    final DecimalFormat rotationFormat;
    rotationFormat = new DecimalFormat("#####.##", decimalFormatSymbols);
    rotationFormat.setGroupingUsed(false);
    rotationFormat.setDecimalSeparatorAlwaysShown(false);
    rotationAngleField.setFormatterFactory(
        new JFormattedTextField.AbstractFormatterFactory() {
          @Override
          public JFormattedTextField.AbstractFormatter getFormatter(JFormattedTextField tf) {
            return new NumberFormatter(rotationFormat);
          }
        });
    rotationAngleField.setColumns(6);
    rotationAngleField.setEditable(true);
    rotationAngleField.setHorizontalAlignment(JTextField.CENTER);
    rotationAngleField.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            handleRotationAngleFieldUserInput();
          }
        });
    rotationAngleField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            handleRotationAngleFieldUserInput();
          }
        });
    rotationAngleField.addPropertyChangeListener(
        "value",
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            handleRotationAngleFieldUserInput();
          }
        });

    zoomSlider = new JSlider(JSlider.HORIZONTAL);
    zoomSlider.setValue(0);
    zoomSlider.setMinimum(MIN_SLIDER_VALUE);
    zoomSlider.setMaximum(MAX_SLIDER_VALUE);
    zoomSlider.setPaintTicks(false);
    zoomSlider.setPaintLabels(false);
    zoomSlider.setSnapToTicks(false);
    zoomSlider.setPaintTrack(true);
    zoomSlider.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(final ChangeEvent e) {
            if (!inUpdateMode) {
              zoom(sliderValueToZoomFactor(zoomSlider.getValue()));
            }
          }
        });

    final JPanel zoomFactorPane = new JPanel(new BorderLayout());
    zoomFactorPane.add(zoomFactorField, BorderLayout.WEST);

    final JPanel rotationAnglePane = new JPanel(new BorderLayout());
    rotationAnglePane.add(rotationAngleSpinner, BorderLayout.EAST);
    rotationAnglePane.add(new JLabel(" "), BorderLayout.CENTER);

    final JPanel sliderPane = new JPanel(new BorderLayout(2, 2));
    sliderPane.add(zoomFactorPane, BorderLayout.WEST);
    sliderPane.add(zoomSlider, BorderLayout.CENTER);
    sliderPane.add(rotationAnglePane, BorderLayout.EAST);

    canvas = createNavigationCanvas();
    canvas.setBackground(new Color(138, 133, 128)); // image background
    canvas.setForeground(new Color(153, 153, 204)); // slider overlay

    final JPanel centerPane = new JPanel(new BorderLayout(4, 4));
    centerPane.add(BorderLayout.CENTER, canvas);
    centerPane.add(BorderLayout.SOUTH, sliderPane);

    final JPanel mainPane = new JPanel(new BorderLayout(8, 8));
    mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPane.add(centerPane, BorderLayout.CENTER);
    mainPane.add(eastPane, BorderLayout.EAST);

    mainPane.setPreferredSize(new Dimension(320, 320));

    if (getDescriptor().getHelpId() != null) {
      HelpSys.enableHelpOnButton(helpButton, getDescriptor().getHelpId());
      HelpSys.enableHelpKey(mainPane, getDescriptor().getHelpId());
    }

    setCurrentView(VisatApp.getApp().getSelectedProductSceneView());

    updateState();

    // Add an internal frame listener to VISAT so that we can update our
    // navigation window with the information of the currently activated
    // product scene view.
    //
    VisatApp.getApp().addInternalFrameListener(new NavigationIFL());

    return mainPane;
  }