# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/joshis/NetBeansSources/main-golden/image
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: nbproject/project.xml
--- nbproject/project.xml Base (BASE)
+++ nbproject/project.xml Locally Modified (Based On LOCAL)
@@ -47,6 +47,15 @@
org.netbeans.modules.image
+ org.netbeans.spi.navigator
+
+
+
+ 1
+ 1.12
+
+
+
org.openide.actions
Index: src/org/netbeans/modules/image/Layer.xml
--- src/org/netbeans/modules/image/Layer.xml Base (BASE)
+++ src/org/netbeans/modules/image/Layer.xml Locally Modified (Based On LOCAL)
@@ -154,4 +154,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: src/org/netbeans/modules/image/preview/Bundle.properties
--- src/org/netbeans/modules/image/preview/Bundle.properties Base (BASE)
+++ src/org/netbeans/modules/image/preview/Bundle.properties Locally New
@@ -0,0 +1,3 @@
+OpenIDE-Module-Name=image.preview
+DISPLAY_HINT=Image preview
+DISPLAY_NAME=Image preview
Index: src/org/netbeans/modules/image/preview/ImageNavigatorProvider.java
--- src/org/netbeans/modules/image/preview/ImageNavigatorProvider.java Base (BASE)
+++ src/org/netbeans/modules/image/preview/ImageNavigatorProvider.java Locally New
@@ -0,0 +1,117 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.netbeans.modules.image.preview;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import javax.imageio.ImageIO;
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import org.netbeans.spi.navigator.NavigatorPanel;
+import org.openide.loaders.DataObject;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+
+/**
+ *
+ * @author joshis
+ */
+public class ImageNavigatorProvider implements NavigatorPanel {
+
+ private ImagePanel panelUI;
+ private static final Lookup.Template MY_DATA = new Lookup.Template(Object.class);
+ private Lookup.Result curContext;
+ private LookupListener contextL;
+
+ /** public no arg constructor needed for system to instantiate provider well */
+ public ImageNavigatorProvider() {
+ }
+
+ public String getDisplayHint() {
+ return org.openide.util.NbBundle.getMessage(ImageNavigatorProvider.class, "DISPLAY_HINT");
+ }
+
+ public String getDisplayName() {
+ return org.openide.util.NbBundle.getMessage(ImageNavigatorProvider.class, "DISPLAY_NAME");
+ }
+
+ public JComponent getComponent() {
+ if (panelUI == null) {
+ panelUI = new ImagePanel();
+ }
+ return panelUI;
+ }
+
+ public void panelActivated(Lookup context) {
+ curContext = context.lookup(MY_DATA);
+ curContext.addLookupListener(getContextListener());
+ Collection data = curContext.allInstances();
+ setNewContent(data);
+ }
+
+ public void panelDeactivated() {
+ curContext.removeLookupListener(getContextListener());
+ curContext = null;
+ }
+
+ public Lookup getLookup() {
+ return null;
+ }
+
+ /************* non - public part ************/
+ private void setNewContent(Collection newData) {
+ InputStream is = null;
+ DataObject fo = null;
+ try {
+ while (newData.iterator().hasNext()) {
+ Object o = newData.iterator().next();
+ if (o instanceof DataObject) {
+ fo = (DataObject) o;
+ break;
+ }
+ }
+ if (fo == null) return;
+ is = fo.getPrimaryFile().getInputStream();
+ final BufferedImage bim = ImageIO.read(is);
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ panelUI.setImage(bim);
+ panelUI.revalidate();
+ panelUI.repaint();
+ }
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
+ }
+
+ /** Accessor for listener to context */
+ private LookupListener getContextListener() {
+ if (contextL == null) {
+ contextL = new ContextListener();
+ }
+ return contextL;
+ }
+
+ /** Listens to changes of context and triggers proper action */
+ private class ContextListener implements LookupListener {
+
+ public void resultChanged(LookupEvent ev) {
+ Collection data = ((Lookup.Result) ev.getSource()).allInstances();
+ setNewContent(data);
+ }
+ } // end of ContextListener
+}
Index: src/org/netbeans/modules/image/preview/ImagePanel.java
--- src/org/netbeans/modules/image/preview/ImagePanel.java Base (BASE)
+++ src/org/netbeans/modules/image/preview/ImagePanel.java Locally New
@@ -0,0 +1,43 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.netbeans.modules.image.preview;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import javax.swing.JPanel;
+
+/**
+ *
+ * @author joshis
+ */
+public class ImagePanel extends JPanel {
+
+ BufferedImage image;
+
+ public void setImage(BufferedImage img) {
+ image = img;
+ this.setBackground(Color.white);
+ }
+
+ protected void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ g.setColor(Color.BLACK);
+ if (image != null) {
+ int w = image.getWidth();
+ int h = image.getHeight();
+ if (image.getWidth() > this.getWidth() * 0.9 || image.getHeight() > this.getHeight() * 0.9) {
+ if (image.getWidth() > image.getHeight()) {
+ w = (int) (w * ((double) (this.getWidth()) / (double) (image.getWidth())) * 0.9);
+ h = (int) (h * ((double) (this.getWidth()) / (double) (image.getWidth())) * 0.9);
+ } else {
+ w = (int) (w * ((double) (this.getHeight()) / (double) (image.getHeight())));
+ h = (int) (h * ((double) (this.getHeight()) / (double) (image.getHeight())));
+ }
+ }
+ g.drawImage(image, (this.getWidth() - w) / 2, (this.getHeight() - h) / 2, w, h, this);
+ }
+ }
+}