-/*\r
-GNU Lesser General Public License\r
-\r
-ImageFileChooserPreview\r
-Copyright (C) 2000-2002 Frits Jalvingh & Howard Kistler\r
-\r
-This library is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU Lesser General Public\r
-License as published by the Free Software Foundation; either\r
-version 2.1 of the License, or (at your option) any later version.\r
-\r
-This library is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public\r
-License along with this library; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-*/\r
-\r
-package com.hexidec.ekit.component;\r
-\r
-import java.awt.Dimension;\r
-import java.awt.Graphics;\r
-import java.awt.Image;\r
-import java.io.File;\r
-import javax.swing.ImageIcon;\r
-import javax.swing.JComponent;\r
-import javax.swing.JFileChooser;\r
-import java.beans.PropertyChangeEvent;\r
-import java.beans.PropertyChangeListener;\r
-\r
-/** Class provides a preview window for the selected image file\r
- */\r
-class ImageFileChooserPreview extends JComponent implements PropertyChangeListener\r
-{\r
- private static final int previewWidth = 100;\r
- private static final int previewHeight = 100;\r
-\r
- private ImageIcon imageThumb = null;\r
- private File imageFile = null;\r
-\r
- /** This class requires a file chooser to register with so this class will\r
- * be notified when a new file is selected in the browser.\r
- * @param JFileChooser that this preview window is used in.\r
- */\r
- public ImageFileChooserPreview(JFileChooser parent)\r
- {\r
- setPreferredSize(new Dimension(previewWidth , previewHeight));\r
- parent.addPropertyChangeListener(this);\r
- }\r
-\r
- /** Loads a new image into the preview window, and scales it if necessary.\r
- */\r
- public void loadImage()\r
- {\r
- if(imageFile == null)\r
- {\r
- imageThumb = null;\r
- return;\r
- }\r
- imageThumb = new ImageIcon(imageFile.getPath());\r
-\r
- // Check if thumb requires scaling\r
- if(imageThumb.getIconHeight() < previewHeight && imageThumb.getIconWidth() < previewWidth)\r
- {\r
- return;\r
- }\r
- int w = previewWidth;\r
- int h = previewHeight;\r
- if(imageThumb.getIconHeight() > imageThumb.getIconWidth())\r
- {\r
- w = -1;\r
- }\r
- else\r
- {\r
- h = -1;\r
- }\r
- imageThumb = new ImageIcon(imageThumb.getImage().getScaledInstance(w, h, Image.SCALE_DEFAULT));\r
- }\r
-\r
- /** Callback (event handler) to indicate that a property of the\r
- * JFileChooser has changed. If the selected file has changed cause a new\r
- * thumbnail to load.\r
- */\r
- public void propertyChange(PropertyChangeEvent e)\r
- {\r
- if(e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))\r
- {\r
- imageFile = (File)e.getNewValue();\r
- if(isShowing())\r
- {\r
- loadImage();\r
- repaint();\r
- }\r
- }\r
- }\r
-\r
- /** Paints the icon of the current image, if one's present..\r
- * @param Graphics object to use when painting the component.\r
- */\r
- public void paintComponent(Graphics g)\r
- {\r
- if(imageThumb == null)\r
- {\r
- loadImage();\r
- }\r
- if(imageThumb == null)\r
- {\r
- return;\r
- }\r
- int x = (getWidth() - imageThumb.getIconWidth()) / 2;\r
- int y = (getHeight() - imageThumb.getIconHeight()) / 2;\r
- if(y < 0)\r
- {\r
- y = 0;\r
- }\r
- if(x < 5)\r
- {\r
- x = 5;\r
- }\r
- imageThumb.paintIcon(this, g, x, y);\r
- }\r
-}\r
-\r
+/*
+GNU Lesser General Public License
+
+ImageFileChooserPreview
+Copyright (C) 2000 Frits Jalvingh & Howard Kistler
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+package com.hexidec.ekit.component;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.io.File;
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+/** Class provides a preview window for the selected image file
+ */
+class ImageFileChooserPreview extends JComponent implements PropertyChangeListener
+{
+ private static final int previewWidth = 100;
+ private static final int previewHeight = 100;
+
+ private ImageIcon imageThumb = null;
+ private File imageFile = null;
+
+ /** This class requires a file chooser to register with so this class will
+ * be notified when a new file is selected in the browser.
+ * @param JFileChooser that this preview window is used in.
+ */
+ public ImageFileChooserPreview(JFileChooser parent)
+ {
+ setPreferredSize(new Dimension(previewWidth , previewHeight));
+ parent.addPropertyChangeListener(this);
+ }
+
+ /** Loads a new image into the preview window, and scales it if necessary.
+ */
+ public void loadImage()
+ {
+ if(imageFile == null)
+ {
+ imageThumb = null;
+ return;
+ }
+ imageThumb = new ImageIcon(imageFile.getPath());
+
+ // Check if thumb requires scaling
+ if(imageThumb.getIconHeight() < previewHeight && imageThumb.getIconWidth() < previewWidth)
+ {
+ return;
+ }
+ int w = previewWidth;
+ int h = previewHeight;
+ if(imageThumb.getIconHeight() > imageThumb.getIconWidth())
+ {
+ w = -1;
+ }
+ else
+ {
+ h = -1;
+ }
+ imageThumb = new ImageIcon(imageThumb.getImage().getScaledInstance(w, h, Image.SCALE_DEFAULT));
+ }
+
+ /** Callback (event handler) to indicate that a property of the
+ * JFileChooser has changed. If the selected file has changed cause a new
+ * thumbnail to load.
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if(e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
+ {
+ imageFile = (File)e.getNewValue();
+ if(isShowing())
+ {
+ loadImage();
+ repaint();
+ }
+ }
+ }
+
+ /** Paints the icon of the current image, if one's present..
+ * @param Graphics object to use when painting the component.
+ */
+ public void paintComponent(Graphics g)
+ {
+ if(imageThumb == null)
+ {
+ loadImage();
+ }
+ if(imageThumb == null)
+ {
+ return;
+ }
+ int x = (getWidth() - imageThumb.getIconWidth()) / 2;
+ int y = (getHeight() - imageThumb.getIconHeight()) / 2;
+ if(y < 0)
+ {
+ y = 0;
+ }
+ if(x < 5)
+ {
+ x = 5;
+ }
+ imageThumb.paintIcon(this, g, x, y);
+ }
+}
+