JTwain v9 - Lab Asprise! All Rights Reserved.

com.asprise.util.ui
Class JImageDialog

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Dialog
                  extended byjavax.swing.JDialog
                      extended bycom.asprise.util.ui.JImageDialog
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

public final class JImageDialog
extends JDialog

A dialog allows the user to load images and to perform basic image editing tasks.
This component proves to be extremely useful if you need the user to load/browse/edit/specify images in your applications.

Advantages include:

The user can load images from local computer or the web, he or she can also acquire images from digital cammeras and scanners. After the image has been loaded, the user can rotate, clip, flip, and scale the image. The image has been loaded and edited, the user can save the image or select the image - which will be used in your applications.

Sample uses:

1. Modal (synchronous) mode

 JImageDialog dialog = new JImageDialog(frame, "Sample", true); // Modal dialog
 BufferedImage image = dialog.showDialog();
 ... 
 

2. Asynchronous mode

 public class JImageDialogSample extends JPanel implements JImageDialogListener {
 	  ...
   BufferedImage image; 
  
   // Displays selected image if any. 
   public void paintComponent(Graphics g) {
       super.paintComponent(g); // Paint background. 
       if(image != null)
           g.drawImage(image, 0, 0, null);
   }
 
   // Sets image and refreshes the panel.
 	 public void setImage(BufferedImage image) {
       this.image = image;
       setPreferredSize(getPreferredSize());
       revalidate();
       repaint();
   }
 
   // Methods in JImageDialogListener
   // When the user presses cancel button, this method will be called. 
   public void onCancel() { 
       setImage(null);
   }
    
   // When the user presses the selection button, this method will be invoked. 
   public void onImageSet(BufferedImage image) {
       setImage(image);
   }
 }
 
 ...
 JImageDialogSample imagePanel = new JImageDialogSample();
 
 JImageDialog dialog = new JImageDialog();
 dialog.addImageDialogListener(imagePanel);
 dialog.showDialog();
 ...
 

Note: Only the licensed copy allows directly access to image reading and writing functions and other advanced features.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JImageDialog()
          Creates a JImageDialog with default settings.
JImageDialog(Dialog parent, String title, boolean modal)
          Creates an image dialog with parent dialog, title and modal option.
JImageDialog(Frame parent, String title, boolean modal)
          Creates an image dialog with parent frame, title and modal option.
 
Method Summary
 void addImageDialogListener(JImageDialogListener l)
          Add an ImageDialogListener.
 String getDefaultFileExtension()
          Get default file extension.
 void removeImageAcquisitionDialogListener(JImageDialogListener l)
          Remove an ImageAcquisitionDialogListener.
 void setDefaultFileExtension(String defaultExt)
          Set default file extension.
 void setImage(File file)
          Loads the image from file and put it in the editor.
 void setImage(Image image)
          Sets the image to be edited/viewed.
 void setImage(URL url)
          Loads the image from url and put it in the editor.
 void setProxy(String host, int port)
          Set the proxy.
 void setSelectionButtonText(String text)
          Set the selection button text.
 BufferedImage showDialog()
          Brings up the image dialog.
 
Methods inherited from class javax.swing.JDialog
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JImageDialog

public JImageDialog()
Creates a JImageDialog with default settings.


JImageDialog

public JImageDialog(Dialog parent,
                    String title,
                    boolean modal)
Creates an image dialog with parent dialog, title and modal option.

Parameters:
parent -
title -
modal -

JImageDialog

public JImageDialog(Frame parent,
                    String title,
                    boolean modal)
Creates an image dialog with parent frame, title and modal option.

Parameters:
parent -
title -
modal -
Method Detail

setImage

public void setImage(Image image)
Sets the image to be edited/viewed.

Parameters:
image -

setImage

public void setImage(URL url)
Loads the image from url and put it in the editor.

Parameters:
url -

setImage

public void setImage(File file)
Loads the image from file and put it in the editor.

Parameters:
file -

showDialog

public BufferedImage showDialog()
Brings up the image dialog.

Returns:
selected image or null if the user cancels selection.

getDefaultFileExtension

public String getDefaultFileExtension()
Get default file extension. When user just type the file name without suffix, this default file extension will be appended to the file name. Initial value: jpg

Returns:

setDefaultFileExtension

public void setDefaultFileExtension(String defaultExt)
Set default file extension. When user just type the file name without suffix, this default file extension will be appended to the file name.

Parameters:
defaultExt - default extension, samples are jpg(default), png, bmp, etc.

addImageDialogListener

public void addImageDialogListener(JImageDialogListener l)
Add an ImageDialogListener. This method will not throw any exception, even l is null

Parameters:
l -

removeImageAcquisitionDialogListener

public void removeImageAcquisitionDialogListener(JImageDialogListener l)
Remove an ImageAcquisitionDialogListener. This method will not throw any exception, even l is null

Parameters:
l -

setProxy

public void setProxy(String host,
                     int port)
Set the proxy. Proxy may be needed to download image from the web.

Parameters:
host - host name
port - port.

setSelectionButtonText

public void setSelectionButtonText(String text)
Set the selection button text. Default value is 'Use it!'.

Parameters:
text -

JTwain v9 - Lab Asprise! All Rights Reserved.