Class AbstractPictureControl<T extends org.eclipse.swt.widgets.Control>

java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Composite
org.eclipse.nebula.widgets.picture.AbstractPictureControl<T>
Type Parameters:
T - the "Modify" Link control used to upload a new image picture.
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, org.eclipse.swt.graphics.Drawable
Direct Known Subclasses:
FormPictureControl, PictureControl

public abstract class AbstractPictureControl<T extends org.eclipse.swt.widgets.Control>
extends org.eclipse.swt.widgets.Composite
implements java.beans.PropertyChangeListener
Picture Control gives you the capability to display an image picture in a SWT Label and change it with "Modify" Link. This class is abstract must be implemented to override methodes whicg create SWT Label, SWT Composite and Link according if you use only SWT (see PictureControl) or SWT Form Toolkit (see FormPictureControl.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String BUNDLE_NAME
    Bundle name constant
    static java.lang.String IMAGE_BYTEARRAY_PROPERTY  
    protected java.util.ResourceBundle resources
    Resources bundle

    Fields inherited from class org.eclipse.swt.widgets.Control

    handle
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
      AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent)
    Constructor for AbstractPictureControl with default SWT styles.
      AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent, int compositeStyle, int labelStyle, int linkStyle)
    Constructor for AbstractPictureControl with given SWT style .
    protected AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent, int compositeStyle, int labelStyle, int linkStyle, boolean createUI)
    Constructor for AbstractPictureControl with given SWT styles.
  • Method Summary

    Modifier and Type Method Description
    protected abstract void addDeleteImageHandler​(T deleteImageLink)
    Add the handler to delete the image to the Link control.
    protected abstract void addModifyImageHandler​(T modifyImageLink)
    Add the handler to open Explorer files to the Link control.
    void addPropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)  
    protected void configure​(org.eclipse.swt.widgets.FileDialog fd)
    Configure the FileDialog to set the file extension, the text, etc.
    protected abstract org.eclipse.swt.widgets.Composite createComposite​(org.eclipse.swt.widgets.Composite parent, int style)
    Create a SWT Composite.
    protected abstract org.eclipse.swt.widgets.Label createLabel​(org.eclipse.swt.widgets.Composite parent, int style)
    Create a SWT Label.
    protected org.eclipse.swt.widgets.Label createLabelImage​(org.eclipse.swt.widgets.Composite parent, int style)
    Create the SWT Label to host the image picture.
    protected abstract T createLink​(org.eclipse.swt.widgets.Composite parent, int style)
    Create a SWT control for the "Modify" Link.
    protected org.eclipse.swt.widgets.Menu createMenu​(org.eclipse.swt.widgets.Control parent)
    Create the menu with "Delete", "Modify" Item.
    protected org.eclipse.swt.widgets.Composite createUI​(int labelStyle, int linkStyle)
    Create the UI picture control composed with Label (for host the image picture)
    void dispose()  
    T getDeleteImageLink()
    Returns the "Delete" Link control used to open Explorer files to change image.
    protected int getFileDialogStyle()
    Returns the FileDialogSWT style.
    byte[] getImageByteArray()
    Returns the byte array of the image picture and null if none picture was setted.
    java.io.InputStream getImageStream()
    Returns the InputStream of the image picture and null if none picture was setted.
    java.lang.Integer getMaxImageHeight()
    Returns the maximum height of the image.
    java.lang.Integer getMaxImageWidth()
    Returns the maximum width of the image.
    T getModifyImageLink()
    Returns the "Modify" Link control used to open Explorer files to change image.
    org.eclipse.swt.widgets.Label getPictureLabel()
    Returns the picture label which hosts the picture image.
    protected org.eclipse.swt.graphics.ImageData getResizedImageData​(org.eclipse.swt.graphics.ImageData imageData)
    Returns the resized ImageData.
    protected void handleDeleteImage()
    Delete the current image picture.
    protected void handleError​(java.lang.Throwable e)
    Handle error when file selected cannot be loaded as Image.
    protected void handleModifyImage()
    Open the Explorer File to select a new image.
    void propertyChange​(java.beans.PropertyChangeEvent arg0)  
    void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)  
    void setDefaultImage​(org.eclipse.swt.graphics.Image defaultImage)
    Set the default image for the picture.
    void setDeleteImageLinkText​(java.lang.String text)
    Set the text of the "Modify" Link.
    void setFilterExtensions​(java.lang.String[] extensions)
    Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.
    void setImageByteArray​(byte[] imageByteArray)
    Set the current byte array of the image picture. null is accepted to delete the image.
    void setImageStream​(java.io.InputStream stream)
    Set the current InputStream of the image picture. null is accepted to delete the image.
    protected abstract void setLinkText​(T link, java.lang.String text)
    Set the text of a Link control.
    void setLocale​(java.util.Locale locale)
    Sets a new locale to use for picture controle.
    void setMaxImageHeight​(java.lang.Integer maxImageHeight)
    Set the maximum height of the image.
    void setMaxImageWidth​(java.lang.Integer maxImageWidth)
    Set the maximum width of the image.
    void setModifyImageLinkText​(java.lang.String text)
    Set the text of the "Modify" Link.

    Methods inherited from class org.eclipse.swt.widgets.Composite

    changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toString

    Methods inherited from class org.eclipse.swt.widgets.Scrollable

    computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar

    Methods inherited from class org.eclipse.swt.widgets.Control

    addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update

    Methods inherited from class org.eclipse.swt.widgets.Widget

    addDisposeListener, addListener, checkWidget, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.swt.graphics.Drawable

    isAutoScalable
  • Field Details

  • Constructor Details

    • AbstractPictureControl

      public AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent)
      Constructor for AbstractPictureControl with default SWT styles.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
    • AbstractPictureControl

      public AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent, int compositeStyle, int labelStyle, int linkStyle)
      Constructor for AbstractPictureControl with given SWT style .
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      compositeStyle - SWT style of the SWT Composite which host Label+Link controls.
      labelStyle - SWT style of the Label control.
      linkStyle - SWT style of the Link control.
    • AbstractPictureControl

      protected AbstractPictureControl​(org.eclipse.swt.widgets.Composite parent, int compositeStyle, int labelStyle, int linkStyle, boolean createUI)
      Constructor for AbstractPictureControl with given SWT styles.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      compositeStyle - SWT style of the SWT Composite which host Label+Link controls.
      labelStyle - SWT style of the Label control.
      linkStyle - SWT style of the Link control.
      createUI - true if UI must be created and false otherwise.
  • Method Details

    • createUI

      protected org.eclipse.swt.widgets.Composite createUI​(int labelStyle, int linkStyle)
      Create the UI picture control composed with Label (for host the image picture)
      Parameters:
      labelStyle - the SWT label style.
      linkStyle - the link style.
    • createLabelImage

      protected org.eclipse.swt.widgets.Label createLabelImage​(org.eclipse.swt.widgets.Composite parent, int style)
      Create the SWT Label to host the image picture.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Returns:
    • createMenu

      protected org.eclipse.swt.widgets.Menu createMenu​(org.eclipse.swt.widgets.Control parent)
      Create the menu with "Delete", "Modify" Item.
      Parameters:
      parent -
      Returns:
    • setModifyImageLinkText

      public void setModifyImageLinkText​(java.lang.String text)
      Set the text of the "Modify" Link.
      Parameters:
      text -
    • setDeleteImageLinkText

      public void setDeleteImageLinkText​(java.lang.String text)
      Set the text of the "Modify" Link.
      Parameters:
      text -
    • handleDeleteImage

      protected void handleDeleteImage()
      Delete the current image picture.
    • setFilterExtensions

      public void setFilterExtensions​(java.lang.String[] extensions)
      Set the file extensions which the dialog will use to filter the files it shows to the argument, which may be null.

      The strings are platform specific. For example, on some platforms, an extension filter string is typically of the form "*.extension", where "*.*" matches all files. For filters with multiple extensions, use semicolon as a separator, e.g. "*.jpg;*.png".

      Parameters:
      extensions - the file extension filter
      See Also:
      to specify the user-friendly names corresponding to the extensions
    • handleModifyImage

      protected void handleModifyImage()
      Open the Explorer File to select a new image.
    • configure

      protected void configure​(org.eclipse.swt.widgets.FileDialog fd)
      Configure the FileDialog to set the file extension, the text, etc. This method can be override to custome the configuration.
      Parameters:
      fd -
    • getFileDialogStyle

      protected int getFileDialogStyle()
      Returns the FileDialogSWT style. This method can be override if the SWT style should be customized.
      Returns:
    • handleError

      protected void handleError​(java.lang.Throwable e)
      Handle error when file selected cannot be loaded as Image.
      Parameters:
      e -
    • getPictureLabel

      public org.eclipse.swt.widgets.Label getPictureLabel()
      Returns the picture label which hosts the picture image.
      Returns:
    • getModifyImageLink

      public T getModifyImageLink()
      Returns the "Modify" Link control used to open Explorer files to change image.
      Returns:
    • getDeleteImageLink

      public T getDeleteImageLink()
      Returns the "Delete" Link control used to open Explorer files to change image.
      Returns:
    • addPropertyChangeListener

      public void addPropertyChangeListener​(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
    • removePropertyChangeListener

      public void removePropertyChangeListener​(java.beans.PropertyChangeListener listener)
    • propertyChange

      public void propertyChange​(java.beans.PropertyChangeEvent arg0)
      Specified by:
      propertyChange in interface java.beans.PropertyChangeListener
    • setImageStream

      public void setImageStream​(java.io.InputStream stream) throws java.io.IOException
      Set the current InputStream of the image picture. null is accepted to delete the image.
      Parameters:
      stream -
      Throws:
      java.io.IOException
    • getImageStream

      public java.io.InputStream getImageStream()
      Returns the InputStream of the image picture and null if none picture was setted.
      Returns:
    • setImageByteArray

      public void setImageByteArray​(byte[] imageByteArray)
      Set the current byte array of the image picture. null is accepted to delete the image.
      Parameters:
      imageByteArray -
    • getResizedImageData

      protected org.eclipse.swt.graphics.ImageData getResizedImageData​(org.eclipse.swt.graphics.ImageData imageData)
      Returns the resized ImageData. This method can be override if scale logic doen't please you.
      Parameters:
      imageData -
      Returns:
    • getImageByteArray

      public byte[] getImageByteArray()
      Returns the byte array of the image picture and null if none picture was setted.
      Returns:
    • setLocale

      public void setLocale​(java.util.Locale locale)
      Sets a new locale to use for picture controle. Locale will choose the well resources bundle.
      Parameters:
      locale - new locale (must not be null)
    • setMaxImageHeight

      public void setMaxImageHeight​(java.lang.Integer maxImageHeight)
      Set the maximum height of the image.
      Parameters:
      maxImageHeight -
    • getMaxImageHeight

      public java.lang.Integer getMaxImageHeight()
      Returns the maximum height of the image.
      Parameters:
      maxImageHeight -
      Returns:
    • setMaxImageWidth

      public void setMaxImageWidth​(java.lang.Integer maxImageWidth)
      Set the maximum width of the image.
      Parameters:
      maxImageWidth -
    • getMaxImageWidth

      public java.lang.Integer getMaxImageWidth()
      Returns the maximum width of the image.
      Parameters:
      maxImageWidth -
      Returns:
    • setDefaultImage

      public void setDefaultImage​(org.eclipse.swt.graphics.Image defaultImage)
      Set the default image for the picture. The default image doesn't store the input stream of the image in this control. It is used just to display an "empty" picture and set the maximum/minimum width of the picture Label.
      Parameters:
      defaultImage -
    • dispose

      public void dispose()
      Overrides:
      dispose in class org.eclipse.swt.widgets.Widget
    • createLabel

      protected abstract org.eclipse.swt.widgets.Label createLabel​(org.eclipse.swt.widgets.Composite parent, int style)
      Create a SWT Label.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Returns:
    • createLink

      protected abstract T createLink​(org.eclipse.swt.widgets.Composite parent, int style)
      Create a SWT control for the "Modify" Link.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Returns:
    • createComposite

      protected abstract org.eclipse.swt.widgets.Composite createComposite​(org.eclipse.swt.widgets.Composite parent, int style)
      Create a SWT Composite.
      Parameters:
      parent - a composite control which will be the parent of the new instance (cannot be null)
      style - the style of control to construct
      Returns:
    • setLinkText

      protected abstract void setLinkText​(T link, java.lang.String text)
      Set the text of a Link control.
      Parameters:
      modifyImageLink -
      text -
    • addModifyImageHandler

      protected abstract void addModifyImageHandler​(T modifyImageLink)
      Add the handler to open Explorer files to the Link control.
      Parameters:
      modifyImageLink -
    • addDeleteImageHandler

      protected abstract void addDeleteImageHandler​(T deleteImageLink)
      Add the handler to delete the image to the Link control.
      Parameters:
      modifyImageLink -