Revert "Debugger: Image/Icon viewer based on standard image viewer" appcode/140.2311 clion/140.2310 clion/140.2310.1 idea/140.2309
authornik <Nikolay.Chashnikov@jetbrains.com>
Mon, 9 Feb 2015 08:01:54 +0000 (11:01 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Mon, 9 Feb 2015 08:01:54 +0000 (11:01 +0300)
This reverts commit 0852a82d9f8563c9f74769d6838affdec83ba869.

13 files changed:
images/src/org/intellij/images/editor/ImageEditor.java
images/src/org/intellij/images/editor/ImageZoomModel.java
images/src/org/intellij/images/editor/actionSystem/ImageEditorActionUtil.java
images/src/org/intellij/images/editor/actions/ActualSizeAction.java
images/src/org/intellij/images/editor/actions/ToggleGridAction.java
images/src/org/intellij/images/editor/actions/ZoomInAction.java
images/src/org/intellij/images/editor/actions/ZoomOutAction.java
images/src/org/intellij/images/editor/impl/ImageEditorImpl.java
images/src/org/intellij/images/editor/impl/ImageEditorUI.java
images/src/org/intellij/images/thumbnail/impl/ThumbnailViewImpl.java
images/src/org/intellij/images/ui/ImageComponentDecorator.java
java/debugger/impl/src/com/intellij/debugger/settings/ImageObjectRenderer.java
platform/platform-impl/src/com/intellij/ui/ShowColorPickerAction.java

index 1aa422f3bba51ff16b1b2c8f9b7330902bd8ddb3..a888961b8af0106ac4496b44b56c3cc8c9ffe18f 100644 (file)
@@ -59,4 +59,9 @@ public interface ImageEditor extends Disposable, VirtualFileListener, ImageCompo
      */
     boolean isDisposed();
 
      */
     boolean isDisposed();
 
+    ImageZoomModel getZoomModel();
+
+    void setGridVisible(boolean visible);
+
+    boolean isGridVisible();
 }
 }
index 12216b5d0b04b09a45b6d264527d6c9f15603b69..a8902fd9aa215b1d8cd5371170c6c9dfa431b30e 100644 (file)
@@ -38,38 +38,4 @@ public interface ImageZoomModel {
     boolean canZoomIn();
 
     boolean isZoomLevelChanged();
     boolean canZoomIn();
 
     boolean isZoomLevelChanged();
-
-    ImageZoomModel STUB = new ImageZoomModel() {
-        @Override
-        public double getZoomFactor() {
-            return 1;
-        }
-
-        @Override
-        public void setZoomFactor(double zoomFactor) {
-        }
-
-        @Override
-        public void zoomOut() {
-        }
-
-        @Override
-        public void zoomIn() {
-        }
-
-        @Override
-        public boolean canZoomOut() {
-            return false;
-        }
-
-        @Override
-        public boolean canZoomIn() {
-            return false;
-        }
-
-        @Override
-        public boolean isZoomLevelChanged() {
-            return false;
-        }
-    };
 }
 }
index 4379abfad418e37035aca2ee700ba50183b3e7ff..1f6e6f8e2a400ed6cc7a4989798b539aad366a89 100644 (file)
@@ -17,9 +17,11 @@ package org.intellij.images.editor.actionSystem;
 
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.DataContext;
 
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.fileEditor.FileEditor;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageEditor;
-import org.intellij.images.ui.ImageComponentDecorator;
+import org.intellij.images.editor.ImageFileEditor;
 
 /**
  * Editor actions utility.
 
 /**
  * Editor actions utility.
@@ -36,17 +38,22 @@ public final class ImageEditorActionUtil {
      * @param e Action event
      * @return Current {@link ImageEditor} or <code>null</code>
      */
      * @param e Action event
      * @return Current {@link ImageEditor} or <code>null</code>
      */
-    //public static ImageEditor getValidEditor(AnActionEvent e) {
-    //    ImageEditor editor = getEditor(e);
-    //    if (editor != null && editor.isValid()) {
-    //        return editor;
-    //    }
-    //    return null;
-    //}
+    public static ImageEditor getValidEditor(AnActionEvent e) {
+        ImageEditor editor = getEditor(e);
+        if (editor != null && editor.isValid()) {
+            return editor;
+        }
+        return null;
+    }
 
 
-    public static ImageComponentDecorator getImageComponentDecorator(AnActionEvent e) {
+    public static ImageEditor getEditor(AnActionEvent e) {
         DataContext dataContext = e.getDataContext();
         DataContext dataContext = e.getDataContext();
-        return ImageComponentDecorator.DATA_KEY.getData(dataContext);
+      FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(dataContext);
+        if (editor instanceof ImageFileEditor) {
+            ImageFileEditor fileEditor = (ImageFileEditor) editor;
+            return fileEditor.getImageEditor();
+        }
+        return null;
     }
 
     /**
     }
 
     /**
@@ -56,9 +63,9 @@ public final class ImageEditorActionUtil {
      * @return Enabled value
      */
     public static boolean setEnabled(AnActionEvent e) {
      * @return Enabled value
      */
     public static boolean setEnabled(AnActionEvent e) {
-        ImageComponentDecorator decorator = getImageComponentDecorator(e);
+        ImageEditor editor = getValidEditor(e);
         Presentation presentation = e.getPresentation();
         Presentation presentation = e.getPresentation();
-        presentation.setEnabled(decorator != null);
+        presentation.setEnabled(editor != null);
         return presentation.isEnabled();
     }
 }
         return presentation.isEnabled();
     }
 }
index 9379e86e97b4ec32c44f0fab1690b5908cc66430..60ae407f83744cd99100b6f50f52e489aead8efd 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.openapi.project.DumbAware;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
 
 /**
  * Resize image to actual size.
 
 /**
  * Resize image to actual size.
@@ -32,9 +31,9 @@ import org.intellij.images.ui.ImageComponentDecorator;
  */
 public final class ActualSizeAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
  */
 public final class ActualSizeAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
-        ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-        if (decorator != null) {
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+        ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+        if (editor != null) {
+            ImageZoomModel zoomModel = editor.getZoomModel();
             zoomModel.setZoomFactor(1.0d);
         }
     }
             zoomModel.setZoomFactor(1.0d);
         }
     }
@@ -42,8 +41,8 @@ public final class ActualSizeAction extends AnAction implements DumbAware {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
-            ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+            ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+            ImageZoomModel zoomModel = editor.getZoomModel();
             e.getPresentation().setEnabled(zoomModel.getZoomFactor() != 1.0d);
         }
     }
             e.getPresentation().setEnabled(zoomModel.getZoomFactor() != 1.0d);
         }
     }
index 87d0d284c01133e16998875927749272fb728912..4cd74f8521c3e39e82a1c58465699f3ec345136e 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.openapi.actionSystem.ToggleAction;
 import com.intellij.openapi.project.DumbAware;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
 import com.intellij.openapi.project.DumbAware;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
 
 /**
  * Toggle grid lines over image.
 
 /**
  * Toggle grid lines over image.
@@ -30,14 +29,14 @@ import org.intellij.images.ui.ImageComponentDecorator;
  */
 public final class ToggleGridAction extends ToggleAction implements DumbAware {
   public boolean isSelected(AnActionEvent e) {
  */
 public final class ToggleGridAction extends ToggleAction implements DumbAware {
   public boolean isSelected(AnActionEvent e) {
-    ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-    return decorator != null && decorator.isGridVisible();
+    ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+    return editor != null && editor.isGridVisible();
   }
 
   public void setSelected(AnActionEvent e, boolean state) {
   }
 
   public void setSelected(AnActionEvent e, boolean state) {
-    ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-    if (decorator != null) {
-      decorator.setGridVisible(state);
+    ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+    if (editor != null) {
+      editor.setGridVisible(state);
     }
   }
 
     }
   }
 
index b48702119da3360abfac5079dae95ce3162aa8e2..7461b39ec3609333487da2c41d076cefa3ac9334 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.openapi.project.DumbAware;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
 
 /**
  * Zoom in.
 
 /**
  * Zoom in.
@@ -31,9 +30,9 @@ import org.intellij.images.ui.ImageComponentDecorator;
  */
 public final class ZoomInAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
  */
 public final class ZoomInAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
-        ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-        if (decorator != null) {
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+        ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+        if (editor != null) {
+            ImageZoomModel zoomModel = editor.getZoomModel();
             zoomModel.zoomIn();
         }
     }
             zoomModel.zoomIn();
         }
     }
@@ -41,8 +40,8 @@ public final class ZoomInAction extends AnAction implements DumbAware {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
-            ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+            ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+            ImageZoomModel zoomModel = editor.getZoomModel();
             e.getPresentation().setEnabled(zoomModel.canZoomIn());
         }
     }
             e.getPresentation().setEnabled(zoomModel.canZoomIn());
         }
     }
index 0873e397f584e1be6510e4ef841fb3e26b0db6d3..3f7e709e79993f0d0c721780762fc0124ddc928f 100644 (file)
@@ -21,7 +21,6 @@ import com.intellij.openapi.project.DumbAware;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActionUtil;
-import org.intellij.images.ui.ImageComponentDecorator;
 
 /**
  * Zoom out.
 
 /**
  * Zoom out.
@@ -31,9 +30,9 @@ import org.intellij.images.ui.ImageComponentDecorator;
  */
 public final class ZoomOutAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
  */
 public final class ZoomOutAction extends AnAction implements DumbAware {
     public void actionPerformed(AnActionEvent e) {
-        ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-        if (decorator != null) {
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+        ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+        if (editor != null) {
+            ImageZoomModel zoomModel = editor.getZoomModel();
             zoomModel.zoomOut();
         }
     }
             zoomModel.zoomOut();
         }
     }
@@ -41,8 +40,8 @@ public final class ZoomOutAction extends AnAction implements DumbAware {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
     public void update(AnActionEvent e) {
         super.update(e);
         if (ImageEditorActionUtil.setEnabled(e)) {
-            ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
-            ImageZoomModel zoomModel = decorator.getZoomModel();
+            ImageEditor editor = ImageEditorActionUtil.getValidEditor(e);
+            ImageZoomModel zoomModel = editor.getZoomModel();
             e.getPresentation().setEnabled(zoomModel.canZoomOut());
         }
     }
             e.getPresentation().setEnabled(zoomModel.canZoomOut());
         }
     }
index 8c23b10b0c6e0dbf3512237bd8abb1f18facbb01..581d7bb9b10e6badd5afaaf368085caa3379c1b7 100644 (file)
@@ -22,11 +22,17 @@ import org.intellij.images.editor.ImageDocument;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.fileTypes.ImageFileTypeManager;
 import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.fileTypes.ImageFileTypeManager;
+import org.intellij.images.options.*;
 import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActions;
 import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActions;
+import org.intellij.images.ui.ImageComponent;
 import org.intellij.images.vfs.IfsUtil;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 import org.intellij.images.vfs.IfsUtil;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 
 /**
  * Image viewer implementation.
 
 /**
  * Image viewer implementation.
@@ -34,6 +40,7 @@ import javax.swing.*;
  * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
  */
 final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
  * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
  */
 final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
+    private final PropertyChangeListener optionsChangeListener = new OptionsChangeListener();
     private final Project project;
     private final VirtualFile file;
     private final ImageEditorUI editorUI;
     private final Project project;
     private final VirtualFile file;
     private final ImageEditorUI editorUI;
@@ -43,7 +50,10 @@ final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
         this.project = project;
         this.file = file;
 
         this.project = project;
         this.file = file;
 
-        editorUI = new ImageEditorUI(this);
+        // Options
+        Options options = OptionsManager.getInstance().getOptions();
+        editorUI = new ImageEditorUI(this, options.getEditorOptions());
+        options.addPropertyChangeListener(optionsChangeListener);
 
         VirtualFileManager.getInstance().addVirtualFileListener(this);
 
 
         VirtualFileManager.getInstance().addVirtualFileListener(this);
 
@@ -51,12 +61,34 @@ final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
     }
 
     private void setValue(VirtualFile file) {
     }
 
     private void setValue(VirtualFile file) {
+        ImageDocument document = editorUI.getImageComponent().getDocument();
         try {
         try {
-            editorUI.setImage(IfsUtil.getImage(file), IfsUtil.getFormat(file));
-        }
-        catch (Exception e) {
-            //     Error loading image file
-            editorUI.setImage(null, null);
+            BufferedImage previousImage = document.getValue();
+            BufferedImage image = IfsUtil.getImage(file);
+            document.setValue(image);
+            document.setFormat(IfsUtil.getFormat(file));
+            ImageZoomModel zoomModel = getZoomModel();
+            if (image != null && (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));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // Error loading image file
+            document.setValue(null);
         }
     }
 
         }
     }
 
@@ -119,6 +151,8 @@ final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
     }
 
     public void dispose() {
     }
 
     public void dispose() {
+        Options options = OptionsManager.getInstance().getOptions();
+        options.removePropertyChangeListener(optionsChangeListener);
         editorUI.dispose();
         VirtualFileManager.getInstance().removeVirtualFileListener(this);
         disposed = true;
         editorUI.dispose();
         VirtualFileManager.getInstance().removeVirtualFileListener(this);
         disposed = true;
@@ -154,4 +188,21 @@ final class ImageEditorImpl extends VirtualFileAdapter implements ImageEditor {
             });
         }
     }
             });
         }
     }
+
+    private class OptionsChangeListener implements PropertyChangeListener {
+        public void propertyChange(PropertyChangeEvent evt) {
+            Options options = (Options) evt.getSource();
+            EditorOptions editorOptions = options.getEditorOptions();
+            TransparencyChessboardOptions chessboardOptions = editorOptions.getTransparencyChessboardOptions();
+            GridOptions gridOptions = editorOptions.getGridOptions();
+
+            ImageComponent imageComponent = editorUI.getImageComponent();
+            imageComponent.setTransparencyChessboardCellSize(chessboardOptions.getCellSize());
+            imageComponent.setTransparencyChessboardWhiteColor(chessboardOptions.getWhiteColor());
+            imageComponent.setTransparencyChessboardBlankColor(chessboardOptions.getBlackColor());
+            imageComponent.setGridLineZoomFactor(gridOptions.getLineZoomFactor());
+            imageComponent.setGridLineSpan(gridOptions.getLineSpan());
+            imageComponent.setGridLineColor(gridOptions.getLineColor());
+        }
+    }
 }
 }
index fedca02343083f48d461f1a719fba0e6a6622aa5..b14296626eba09624f4c871664e94696745bf31e 100644 (file)
@@ -38,7 +38,6 @@ import org.intellij.images.editor.ImageEditor;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActions;
 import org.intellij.images.options.*;
 import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActions;
 import org.intellij.images.options.*;
-import org.intellij.images.thumbnail.actionSystem.ThumbnailViewActions;
 import org.intellij.images.ui.ImageComponent;
 import org.intellij.images.ui.ImageComponentDecorator;
 import org.jetbrains.annotations.NonNls;
 import org.intellij.images.ui.ImageComponent;
 import org.intellij.images.ui.ImageComponentDecorator;
 import org.jetbrains.annotations.NonNls;
@@ -58,8 +57,6 @@ import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
 import java.awt.event.MouseWheelListener;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.util.Locale;
 
 import java.io.IOException;
 import java.util.Locale;
 
@@ -68,13 +65,13 @@ import java.util.Locale;
  *
  * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
  */
  *
  * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
  */
-final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider, ImageComponentDecorator {
+final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider {
   @NonNls
   private static final String IMAGE_PANEL = "image";
   @NonNls
   private static final String ERROR_PANEL = "error";
 
   @NonNls
   private static final String IMAGE_PANEL = "image";
   @NonNls
   private static final String ERROR_PANEL = "error";
 
-  private final @Nullable ImageEditor editor;
+  private final ImageEditor editor;
   private final DeleteProvider deleteProvider;
   private final CopyPasteSupport copyPasteSupport;
 
   private final DeleteProvider deleteProvider;
   private final CopyPasteSupport copyPasteSupport;
 
@@ -85,17 +82,10 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
   private final JPanel contentPanel;
   private final JLabel infoLabel;
 
   private final JPanel contentPanel;
   private final JLabel infoLabel;
 
-  private final PropertyChangeListener optionsChangeListener = new OptionsChangeListener();
-
-  ImageEditorUI(@Nullable ImageEditor editor) {
+  ImageEditorUI(ImageEditor editor, EditorOptions editorOptions) {
     this.editor = editor;
     this.editor = editor;
-
-    Options options = OptionsManager.getInstance().getOptions();
-    EditorOptions editorOptions = options.getEditorOptions();
-    options.addPropertyChangeListener(optionsChangeListener);
-
     final PsiActionSupportFactory factory = PsiActionSupportFactory.getInstance();
     final PsiActionSupportFactory factory = PsiActionSupportFactory.getInstance();
-    if (factory != null && editor != null) {
+    if (factory != null) {
       copyPasteSupport =
         factory.createPsiBasedCopyPasteSupport(editor.getProject(), this, new PsiActionSupportFactory.PsiElementSelector() {
           public PsiElement[] getSelectedElements() {
       copyPasteSupport =
         factory.createPsiBasedCopyPasteSupport(editor.getProject(), this, new PsiActionSupportFactory.PsiElementSelector() {
           public PsiElement[] getSelectedElements() {
@@ -178,11 +168,11 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
       ColorModel colorModel = image.getColorModel();
       String format = document.getFormat();
       if (format == null) {
       ColorModel colorModel = image.getColorModel();
       String format = document.getFormat();
       if (format == null) {
-        format = editor != null ? ImagesBundle.message("unknown.format") : "";
+        format = ImagesBundle.message("unknown.format");
       } else {
         format = format.toUpperCase(Locale.ENGLISH);
       }
       } else {
         format = format.toUpperCase(Locale.ENGLISH);
       }
-      VirtualFile file = editor != null ? editor.getFile() : null;
+      VirtualFile file = editor.getFile();
       infoLabel.setText(
         ImagesBundle.message("image.info",
                              image.getWidth(), image.getHeight(), format,
       infoLabel.setText(
         ImagesBundle.message("image.info",
                              image.getWidth(), image.getHeight(), format,
@@ -202,73 +192,16 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
   }
 
   void dispose() {
   }
 
   void dispose() {
-    Options options = OptionsManager.getInstance().getOptions();
-    options.removePropertyChangeListener(optionsChangeListener);
-
     imageComponent.removeMouseWheelListener(wheelAdapter);
     imageComponent.getDocument().removeChangeListener(changeListener);
 
     removeAll();
   }
     imageComponent.removeMouseWheelListener(wheelAdapter);
     imageComponent.getDocument().removeChangeListener(changeListener);
 
     removeAll();
   }
-  @Override
-  public void setTransparencyChessboardVisible(boolean visible) {
-    imageComponent.setTransparencyChessboardVisible(visible);
-  }
-
-  @Override
-  public boolean isTransparencyChessboardVisible() {
-    return imageComponent.isTransparencyChessboardVisible();
-  }
-
-  @Override
-  public boolean isEnabledForActionPlace(String place) {
-    // Disable for thumbnails action
-    return !ThumbnailViewActions.ACTION_PLACE.equals(place);
-  }
-
-
-  @Override
-  public void setGridVisible(boolean visible) {
-    imageComponent.setGridVisible(visible);
-  }
 
 
-  @Override
-  public boolean isGridVisible() {
-    return imageComponent.isGridVisible();
-  }
-
-  public ImageZoomModel getZoomModel() {
+  ImageZoomModel getZoomModel() {
     return zoomModel;
   }
 
     return zoomModel;
   }
 
-  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));
-        }
-      }
-    }
-  }
-
   private final class ImageContainerPane extends JBLayeredPane {
     private final ImageComponent imageComponent;
 
   private final class ImageContainerPane extends JBLayeredPane {
     private final ImageComponent imageComponent;
 
@@ -280,7 +213,7 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
         @Override
         public Point magnify(double scale, Point at) {
           Point locationBefore = imageComponent.getLocation();
         @Override
         public Point magnify(double scale, Point at) {
           Point locationBefore = imageComponent.getLocation();
-          ImageZoomModel model = editor != null ? editor.getZoomModel() : getZoomModel();
+          ImageZoomModel model = editor.getZoomModel();
           double factor = model.getZoomFactor();
           model.setZoomFactor(scale * factor);
           return new Point(((int)((at.x - Math.max(scale > 1.0 ? locationBefore.x : 0, 0)) * scale)), 
           double factor = model.getZoomFactor();
           model.setZoomFactor(scale * factor);
           return new Point(((int)((at.x - Math.max(scale > 1.0 ? locationBefore.x : 0, 0)) * scale)), 
@@ -450,18 +383,18 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
   public Object getData(String dataId) {
 
     if (CommonDataKeys.PROJECT.is(dataId)) {
   public Object getData(String dataId) {
 
     if (CommonDataKeys.PROJECT.is(dataId)) {
-      return editor != null ? editor.getProject() : null;
+      return editor.getProject();
     } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
     } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
-      return editor != null ? editor.getFile() : null;
+      return editor.getFile();
     } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
     } else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
-      return editor != null ? new VirtualFile[]{editor.getFile()} : new VirtualFile[]{};
+      return new VirtualFile[]{editor.getFile()};
     } else if (CommonDataKeys.PSI_FILE.is(dataId)) {
       return getData(CommonDataKeys.PSI_ELEMENT.getName());
     } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
     } else if (CommonDataKeys.PSI_FILE.is(dataId)) {
       return getData(CommonDataKeys.PSI_ELEMENT.getName());
     } else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
-      VirtualFile file = editor != null ? editor.getFile() : null;
+      VirtualFile file = editor.getFile();
       return file != null && file.isValid() ? PsiManager.getInstance(editor.getProject()).findFile(file) : null;
     } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
       return file != null && file.isValid() ? PsiManager.getInstance(editor.getProject()).findFile(file) : null;
     } else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
-      return editor != null ? new PsiElement[]{(PsiElement)getData(CommonDataKeys.PSI_ELEMENT.getName())} : new PsiElement[]{} ;
+      return new PsiElement[]{(PsiElement)getData(CommonDataKeys.PSI_ELEMENT.getName())};
     } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) {
       return this;
     } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) {
     } else if (PlatformDataKeys.COPY_PROVIDER.is(dataId) && copyPasteSupport != null) {
       return this;
     } else if (PlatformDataKeys.CUT_PROVIDER.is(dataId) && copyPasteSupport != null) {
@@ -469,7 +402,7 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
     } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
       return deleteProvider;
     } else if (ImageComponentDecorator.DATA_KEY.is(dataId)) {
     } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
       return deleteProvider;
     } else if (ImageComponentDecorator.DATA_KEY.is(dataId)) {
-      return editor != null ? editor : this;
+      return editor;
     }
 
     return null;
     }
 
     return null;
@@ -517,21 +450,4 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
       return myImage;
     }
   }
       return myImage;
     }
   }
-
-  private class OptionsChangeListener implements PropertyChangeListener {
-    public void propertyChange(PropertyChangeEvent evt) {
-      Options options = (Options) evt.getSource();
-      EditorOptions editorOptions = options.getEditorOptions();
-      TransparencyChessboardOptions chessboardOptions = editorOptions.getTransparencyChessboardOptions();
-      GridOptions gridOptions = editorOptions.getGridOptions();
-
-      imageComponent.setTransparencyChessboardCellSize(chessboardOptions.getCellSize());
-      imageComponent.setTransparencyChessboardWhiteColor(chessboardOptions.getWhiteColor());
-      imageComponent.setTransparencyChessboardBlankColor(chessboardOptions.getBlackColor());
-      imageComponent.setGridLineZoomFactor(gridOptions.getLineZoomFactor());
-      imageComponent.setGridLineSpan(gridOptions.getLineSpan());
-      imageComponent.setGridLineColor(gridOptions.getLineColor());
-    }
-  }
-
 }
 }
index 2b04c8822c980dca9c63ad1aa9bf724863d760e9..445c245b12d9936d1946dd8cf4dee471d72febfb 100644 (file)
 package org.intellij.images.thumbnail.impl;
 
 import com.intellij.openapi.project.Project;
 package org.intellij.images.thumbnail.impl;
 
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowAnchor;
 import com.intellij.openapi.wm.ToolWindowManager;
 import icons.ImagesIcons;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowAnchor;
 import com.intellij.openapi.wm.ToolWindowManager;
 import icons.ImagesIcons;
-import org.intellij.images.editor.ImageZoomModel;
 import org.intellij.images.editor.actionSystem.ImageEditorActions;
 import org.intellij.images.thumbnail.ThumbnailView;
 import org.intellij.images.vfs.IfsUtil;
 import org.intellij.images.editor.actionSystem.ImageEditorActions;
 import org.intellij.images.thumbnail.ThumbnailView;
 import org.intellij.images.vfs.IfsUtil;
@@ -162,26 +160,12 @@ final class ThumbnailViewImpl implements ThumbnailView {
 
   public void dispose() {
     // Dispose UI
 
   public void dispose() {
     // Dispose UI
-    Disposer.dispose(getUI());
+    getUI().dispose();
     // Unregister ToolWindow
     ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
     windowManager.unregisterToolWindow(TOOLWINDOW_ID);
   }
 
     // Unregister ToolWindow
     ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
     windowManager.unregisterToolWindow(TOOLWINDOW_ID);
   }
 
-  @Override
-  public ImageZoomModel getZoomModel() {
-    return ImageZoomModel.STUB;
-  }
-
-  @Override
-  public void setGridVisible(boolean visible) {
-  }
-
-  @Override
-  public boolean isGridVisible() {
-    return false;
-  }
-
   private final class LazyScroller implements Runnable {
     public void run() {
       SwingUtilities.invokeLater(new Runnable() {
   private final class LazyScroller implements Runnable {
     public void run() {
       SwingUtilities.invokeLater(new Runnable() {
index 075065cbbca97dfdabe4ee99fea49157027e8c95..da9ef9215b3a69ba4de1b78276de068a512e7dcc 100644 (file)
@@ -16,7 +16,6 @@
 package org.intellij.images.ui;
 
 import com.intellij.openapi.actionSystem.DataKey;
 package org.intellij.images.ui;
 
 import com.intellij.openapi.actionSystem.DataKey;
-import org.intellij.images.editor.ImageZoomModel;
 
 /**
  * Image Component manager. It can toggle backround transparency, grid, etc.
 
 /**
  * Image Component manager. It can toggle backround transparency, grid, etc.
@@ -37,10 +36,4 @@ public interface ImageComponentDecorator {
    * @return <code>true</code> is decorator is enabled
    */
   boolean isEnabledForActionPlace(String place);
    * @return <code>true</code> is decorator is enabled
    */
   boolean isEnabledForActionPlace(String place);
-
-  ImageZoomModel getZoomModel();
-
-  void setGridVisible(boolean visible);
-
-  boolean isGridVisible();
 }
 }
index 6372092dc2e9c7427396de3584e54921e7afbb70..96f7fbe086a23c8e51c1d90481f171aa95f4a25d 100644 (file)
@@ -25,9 +25,13 @@ import com.intellij.debugger.ui.tree.ValueDescriptor;
 import com.intellij.debugger.ui.tree.render.CompoundReferenceRenderer;
 import com.intellij.debugger.ui.tree.render.DescriptorLabelListener;
 import com.intellij.rt.debugger.ImageSerializer;
 import com.intellij.debugger.ui.tree.render.CompoundReferenceRenderer;
 import com.intellij.debugger.ui.tree.render.DescriptorLabelListener;
 import com.intellij.rt.debugger.ImageSerializer;
+import com.intellij.ui.Gray;
+import com.intellij.ui.JBColor;
+import com.intellij.ui.components.JBLabel;
+import com.intellij.ui.components.JBScrollPane;
+import com.intellij.util.ui.UIUtil;
 import com.intellij.xdebugger.frame.XFullValueEvaluator;
 import com.sun.jdi.*;
 import com.intellij.xdebugger.frame.XFullValueEvaluator;
 import com.sun.jdi.*;
-import org.intellij.images.editor.impl.ImageEditorManagerImpl;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -67,15 +71,24 @@ class ImageObjectRenderer extends CompoundReferenceRenderer implements FullValue
   }
 
   static JComponent createIconViewer(Icon icon) {
   }
 
   static JComponent createIconViewer(Icon icon) {
-    final int w = icon.getIconWidth();
-    final int h = icon.getIconHeight();
-    final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
-      .getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(w, h, Transparency.TRANSLUCENT);
-    final Graphics2D g = image.createGraphics();
-    icon.paintIcon(null, g, 0, 0);
-    g.dispose();
+    return new JBScrollPane(new JBLabel(icon){
+      private BufferedImage myBackgroundImage = UIUtil.createImage(16, 16, BufferedImage.TYPE_INT_ARGB);
+      {
+        Graphics2D g = myBackgroundImage.createGraphics();
+        g.setColor(new JBColor(Gray._255, Gray._135));
+        g.fillRect(0, 0, 17, 17);
+        g.setColor(new JBColor(Gray._191, Gray._83));
+        g.fillRect(0, 0, 8, 8);
+        g.fillRect(8, 8, 8, 8);
+      }
+      @Override
+      public void paint(Graphics g) {
+        ((Graphics2D)g).setPaint(new TexturePaint(myBackgroundImage, new Rectangle(0, 0, 16, 16)));
+        g.fillRect(0, 0, getWidth()+1, getHeight() + 1);
+        super.paint(g);
+      }
+    });
 
 
-    return ImageEditorManagerImpl.createImageEditorUI(image);
   }
 
   @Nullable
   }
 
   @Nullable
index 74af71c52d5465da669b5575929578cbadc75088..5327c84c3c8d6ea669b9cef2ed94e10f5c3ef608 100644 (file)
@@ -18,13 +18,11 @@ package com.intellij.ui;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.wm.IdeFrame;
 import com.intellij.openapi.wm.WindowManager;
 
 import javax.swing.*;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.wm.IdeFrame;
 import com.intellij.openapi.wm.WindowManager;
 
 import javax.swing.*;
-import java.awt.*;
 import java.util.List;
 
 /**
 import java.util.List;
 
 /**
@@ -43,16 +41,6 @@ public class ShowColorPickerAction extends AnAction {
     }
   }
 
     }
   }
 
-  @Override
-  public void update(AnActionEvent e) {
-    Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext());
-    if (component == null || !(SwingUtilities.getWindowAncestor(component) instanceof Frame)) {
-      e.getPresentation().setEnabledAndVisible(false);
-      return;
-    }
-    e.getPresentation().setEnabledAndVisible(true);
-  }
-
   private static JComponent rootComponent(Project project) {
     if (project != null) {
       IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
   private static JComponent rootComponent(Project project) {
     if (project != null) {
       IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);