Ejemplo n.º 1
0
  public void setImage(BufferedImage image, String format) {
    ImageDocument document = imageComponent.getDocument();
    BufferedImage previousImage = document.getValue();
    document.setValue(image);
    if (image == null) return;
    document.setFormat(format);
    ImageZoomModel zoomModel = getZoomModel();
    if (previousImage == null || !zoomModel.isZoomLevelChanged()) {
      // Set smart zooming behaviour on open
      Options options = OptionsManager.getInstance().getOptions();
      ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
      // Open as actual size
      zoomModel.setZoomFactor(1.0d);

      if (zoomOptions.isSmartZooming()) {
        Dimension prefferedSize = zoomOptions.getPrefferedSize();
        if (prefferedSize.width > image.getWidth() && prefferedSize.height > image.getHeight()) {
          // Resize to preffered size
          // Calculate zoom factor

          double factor =
              (prefferedSize.getWidth() / (double) image.getWidth()
                      + prefferedSize.getHeight() / (double) image.getHeight())
                  / 2.0d;
          zoomModel.setZoomFactor(Math.ceil(factor));
        }
      }
    }
  }
Ejemplo n.º 2
0
 public void mouseWheelMoved(MouseWheelEvent e) {
   Options options = OptionsManager.getInstance().getOptions();
   EditorOptions editorOptions = options.getEditorOptions();
   ZoomOptions zoomOptions = editorOptions.getZoomOptions();
   if (zoomOptions.isWheelZooming() && e.isControlDown()) {
     if (e.getWheelRotation() < 0) {
       zoomModel.zoomOut();
     } else {
       zoomModel.zoomIn();
     }
     e.consume();
   }
 }