You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/05/27 13:30:35 UTC
svn commit: r1681985 - in /directory/studio/trunk/plugins:
templateeditor/src/main/java/org/apache/directory/studio/templateeditor/
templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/
valueeditors/src/main/java/org/a...
Author: elecharny
Date: Wed May 27 11:30:35 2015
New Revision: 1681985
URL: http://svn.apache.org/r1681985
Log:
o Make sure that the Image are disposed
o Fixed some Sonar warning
Modified:
directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java
directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorFileChooser.java
directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorImage.java
directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java
directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
Modified: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java?rev=1681985&r1=1681984&r2=1681985&view=diff
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java (original)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/EntryTemplatePlugin.java Wed May 27 11:30:35 2015
@@ -116,10 +116,15 @@ public class EntryTemplatePlugin extends
if ( key != null )
{
URL url = FileLocator.find( getBundle(), new Path( key ), null );
+
if ( url != null )
+ {
return ImageDescriptor.createFromURL( url );
+ }
else
+ {
return null;
+ }
}
else
{
@@ -136,22 +141,24 @@ public class EntryTemplatePlugin extends
* Note: Don't dispose the returned SWT Image. It is disposed
* automatically when the plugin is stopped.
*
- * @param key
- * The key (relative path to the image in filesystem)
+ * @param key The key (relative path to the image in filesystem)
* @return The SWT Image or null
*/
public Image getImage( String key )
{
Image image = getImageRegistry().get( key );
+
if ( image == null )
{
ImageDescriptor id = getImageDescriptor( key );
+
if ( id != null )
{
image = id.createImage();
getImageRegistry().put( key, image );
}
}
+
return image;
}
Modified: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorFileChooser.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorFileChooser.java?rev=1681985&r1=1681984&r2=1681985&view=diff
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorFileChooser.java (original)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorFileChooser.java Wed May 27 11:30:35 2015
@@ -46,7 +46,6 @@ import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormToolkit;
-
import org.apache.directory.studio.templateeditor.EntryTemplatePlugin;
import org.apache.directory.studio.templateeditor.EntryTemplatePluginConstants;
import org.apache.directory.studio.templateeditor.EntryTemplatePluginUtils;
@@ -80,17 +79,17 @@ public class EditorFileChooser extends E
/** The file data as bytes array */
private byte[] fileBytes;
+
+ /** The icon Image we might have to create */
+ private Image iconImage;
/**
* Creates a new instance of EditorFileChooser.
*
- * @param editor
- * the associated editor
- * @param templateFileChooser
- * the associated template file chooser
- * @param toolkit
- * the associated toolkit
+ * @param editor the associated editor
+ * @param templateFileChooser the associated template file chooser
+ * @param toolkit the associated toolkit
*/
public EditorFileChooser( IEntryEditor editor, TemplateFileChooser templateFileChooser, FormToolkit toolkit )
{
@@ -119,10 +118,8 @@ public class EditorFileChooser extends E
/**
* Creates and initializes the widget UI.
*
- * @param parent
- * the parent composite
- * @return
- * the associated composite
+ * @param parent the parent composite
+ * @return the associated composite
*/
private Composite initWidget( Composite parent )
{
@@ -145,6 +142,7 @@ public class EditorFileChooser extends E
// Getting the icon (if available)
ImageData iconData = null;
String icon = getWidget().getIcon();
+
if ( ( icon != null ) && ( !icon.equals( "" ) ) ) //$NON-NLS-1$
{
try
@@ -160,7 +158,8 @@ public class EditorFileChooser extends E
// Assigning the icon
if ( iconData != null )
{
- iconLabel.setImage( new Image( PlatformUI.getWorkbench().getDisplay(), iconData ) );
+ iconImage = new Image( PlatformUI.getWorkbench().getDisplay(), iconData );
+ iconLabel.setImage( iconImage );
}
else
{
@@ -212,8 +211,7 @@ public class EditorFileChooser extends E
/**
* Gets the number of columns needed for the layout.
*
- * @return
- * the number of columns needed
+ * @return the number of columns needed
*/
private int getLayoutNumberOfColumns()
{
@@ -224,6 +222,7 @@ public class EditorFileChooser extends E
{
numberOfColumns++;
}
+
// Toolbar
if ( needsToolbar() )
{
@@ -237,9 +236,8 @@ public class EditorFileChooser extends E
/**
* Indicates if the widget needs a toolbar for actions.
*
- * @return
- * <code>true</code> if the widget needs a toolbar for actions,
- * <code>false</code> if not
+ * @return<code>true</code> if the widget needs a toolbar for actions,
+ * <code>false</code> if not
*/
private boolean needsToolbar()
{
@@ -270,6 +268,7 @@ public class EditorFileChooser extends E
{
// Getting the file bytes in the attribute
IAttribute attribute = getAttribute();
+
if ( ( attribute != null ) && ( attribute.isBinary() ) && ( attribute.getValueSize() > 0 ) )
{
fileBytes = attribute.getBinaryValues()[0];
@@ -343,6 +342,7 @@ public class EditorFileChooser extends E
if ( fileBytes != null )
{
int length = fileBytes.length;
+
if ( length > 1000000 )
{
return NLS.bind( Messages.getString( "EditorFileChooser.MB" ), new Object[] //$NON-NLS-1$
@@ -374,10 +374,12 @@ public class EditorFileChooser extends E
// Launching a FileDialog to select where to save the file
FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE );
String selected = fd.open();
+
if ( selected != null )
{
// Getting the selected file
File selectedFile = new File( selected );
+
if ( ( !selectedFile.exists() ) || ( selectedFile.canWrite() ) )
{
try
@@ -436,24 +438,45 @@ public class EditorFileChooser extends E
// Launching a FileDialog to select the file to load
FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN );
String selected = fd.open();
+
if ( selected != null )
{
// Getting the selected file
File selectedFile = new File( selected );
+
if ( ( selectedFile.exists() ) && ( selectedFile.canRead() ) )
{
try
{
- FileInputStream fis = new FileInputStream( selectedFile );
- ByteArrayOutputStream baos = new ByteArrayOutputStream( ( int ) selectedFile.length() );
- byte[] buf = new byte[4096];
- int len;
- while ( ( len = fis.read( buf ) ) > 0 )
+ FileInputStream fis = null;
+ ByteArrayOutputStream baos = null;
+
+ try
{
- baos.write( buf, 0, len );
+ fis = new FileInputStream( selectedFile );
+ baos = new ByteArrayOutputStream( ( int ) selectedFile.length() );
+ byte[] buf = new byte[4096];
+ int len;
+
+ while ( ( len = fis.read( buf ) ) > 0 )
+ {
+ baos.write( buf, 0, len );
+ }
+
+ fileBytes = baos.toByteArray();
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ fis.close();
+ }
+
+ if ( baos != null )
+ {
+ baos.close();
+ }
}
-
- fileBytes = baos.toByteArray();
}
catch ( Exception e )
{
@@ -501,6 +524,7 @@ public class EditorFileChooser extends E
{
// Getting the attribute
IAttribute attribute = getAttribute();
+
if ( attribute == null )
{
if ( ( fileBytes != null ) && ( fileBytes.length != 0 ) )
@@ -581,6 +605,9 @@ public class EditorFileChooser extends E
*/
public void dispose()
{
- // Nothing to do
+ if ( iconImage != null )
+ {
+ iconImage.dispose();
+ }
}
}
Modified: directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorImage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorImage.java?rev=1681985&r1=1681984&r2=1681985&view=diff
==============================================================================
--- directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorImage.java (original)
+++ directory/studio/trunk/plugins/templateeditor/src/main/java/org/apache/directory/studio/templateeditor/editor/widgets/EditorImage.java Wed May 27 11:30:35 2015
@@ -509,24 +509,44 @@ public class EditorImage extends EditorW
// Launching a FileDialog to select the file to load
FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN );
String selected = fd.open();
+
if ( selected != null )
{
// Getting the selected file
File selectedFile = new File( selected );
+
if ( ( selectedFile.exists() ) && ( selectedFile.canRead() ) )
{
try
{
- FileInputStream fis = new FileInputStream( selectedFile );
- ByteArrayOutputStream baos = new ByteArrayOutputStream( ( int ) selectedFile.length() );
- byte[] buf = new byte[4096];
- int len;
- while ( ( len = fis.read( buf ) ) > 0 )
+ FileInputStream fis = null;
+ ByteArrayOutputStream baos = null;
+
+ try
{
- baos.write( buf, 0, len );
+ fis = new FileInputStream( selectedFile );
+ baos = new ByteArrayOutputStream( ( int ) selectedFile.length() );
+ byte[] buf = new byte[4096];
+ int len;
+ while ( ( len = fis.read( buf ) ) > 0 )
+ {
+ baos.write( buf, 0, len );
+ }
+
+ imageBytes = baos.toByteArray();
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ fis.close();
+ }
+
+ if ( baos != null )
+ {
+ baos.close();
+ }
}
-
- imageBytes = baos.toByteArray();
}
catch ( Exception e )
{
@@ -628,7 +648,7 @@ public class EditorImage extends EditorW
*/
public void dispose()
{
- // Nothing to do
+ image.dispose();
}
Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java?rev=1681985&r1=1681984&r2=1681985&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java (original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/ValueEditorsActivator.java Wed May 27 11:30:35 2015
@@ -88,8 +88,7 @@ public class ValueEditorsActivator exten
* Use this method to get SWT images. Use the IMG_ constants from
* ValueEditorConstants for the key.
*
- * @param key
- * The key (relative path to the image im filesystem)
+ * @param key The key (relative path to the image im filesystem)
* @return The image discriptor or null
*/
public ImageDescriptor getImageDescriptor( String key )
@@ -97,10 +96,15 @@ public class ValueEditorsActivator exten
if ( key != null )
{
URL url = FileLocator.find( getBundle(), new Path( key ), null );
+
if ( url != null )
+ {
return ImageDescriptor.createFromURL( url );
+ }
else
+ {
return null;
+ }
}
else
{
@@ -117,23 +121,25 @@ public class ValueEditorsActivator exten
* Note: Don't dispose the returned SWT Image. It is disposed
* automatically when the plugin is stopped.
*
- * @param key
- * The key (relative path to the image im filesystem)
+ * @param key The key (relative path to the image im filesystem)
* @return The SWT Image or null
* @see ValueEditorsConstants
*/
public Image getImage( String key )
{
Image image = getImageRegistry().get( key );
+
if ( image == null )
{
ImageDescriptor id = getImageDescriptor( key );
+
if ( id != null )
{
image = id.createImage();
getImageRegistry().put( key, image );
}
}
+
return image;
}
Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java?rev=1681985&r1=1681984&r2=1681985&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java (original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/image/ImageDialog.java Wed May 27 11:30:35 2015
@@ -29,6 +29,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.directory.api.util.Strings;
import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
import org.apache.directory.studio.connection.ui.ConnectionUIPlugin;
import org.apache.directory.studio.valueeditors.ValueEditorsActivator;
@@ -75,11 +76,13 @@ public class ImageDialog extends Dialog
/** The maximum width for the image */
private static final int MAX_WIDTH = 400;
+
/** The maximum height for the image */
private static final int MAX_HEIGHT = 400;
/** The current image tab item */
private static final int CURRENT_TAB = 0;
+
/** The new image tab item */
private static final int NEW_TAB = 1;
@@ -146,13 +149,13 @@ public class ImageDialog extends Dialog
public boolean close()
{
// Disposing the current image
- if ( currentImage != null && !currentImage.isDisposed() )
+ if ( ( currentImage != null ) && !currentImage.isDisposed() )
{
currentImage.dispose();
}
// Disposing the new image
- if ( newImage != null && !newImage.isDisposed() )
+ if ( ( newImage != null ) && !newImage.isDisposed() )
{
newImage.dispose();
}
@@ -178,6 +181,7 @@ public class ImageDialog extends Dialog
try
{
ImageData imageData = new ImageData( new ByteArrayInputStream( newImageRawData ) );
+
if ( imageData.type != requiredImageType )
{
// Converting the new image in the required format
@@ -251,13 +255,9 @@ public class ImageDialog extends Dialog
protected Control createDialogArea( Composite parent )
{
Composite composite = ( Composite ) super.createDialogArea( parent );
- // GridData compositeGridData = new GridData( SWT.FILL, SWT.FILL, true, true );
- // compositeGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
- // compositeGridData.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH );
- // composite.setLayoutData( compositeGridData );
-
tabFolder = new TabFolder( composite, SWT.TOP );
tabFolder.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
tabFolder.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
@@ -290,6 +290,7 @@ public class ImageDialog extends Dialog
GridData gd = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL );
dummyLabel.setLayoutData( gd );
currentImageSaveButton = createButton( currentImageSaveContainer, Messages.getString( "ImageDialog.Save" ) ); //$NON-NLS-1$
+
currentImageSaveButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
@@ -299,6 +300,7 @@ public class ImageDialog extends Dialog
fileDialog.setFilterExtensions( new String[]
{ "*.jpg" } ); //$NON-NLS-1$
String returnedFileName = fileDialog.open();
+
if ( returnedFileName != null )
{
try
@@ -333,7 +335,6 @@ public class ImageDialog extends Dialog
newTab.setText( Messages.getString( "ImageDialog.NewImage" ) ); //$NON-NLS-1$
newImageContainer = createTabItemComposite();
-
newImageLabel = createImageLabel( newImageContainer );
Composite newImageInfoContainer = createImageInfoContainer( newImageContainer );
@@ -346,6 +347,7 @@ public class ImageDialog extends Dialog
newImageFilenameText = new Text( newImageSelectContainer, SWT.SINGLE | SWT.BORDER );
GridData gd = new GridData( SWT.FILL, SWT.CENTER, true, false );
newImageFilenameText.setLayoutData( gd );
+
newImageFilenameText.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
@@ -353,7 +355,9 @@ public class ImageDialog extends Dialog
updateNewImageGroup();
}
} );
+
newImageBrowseButton = createButton( newImageSelectContainer, Messages.getString( "ImageDialog.Browse" ) ); //$NON-NLS-1$
+
newImageBrowseButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent event )
@@ -364,6 +368,7 @@ public class ImageDialog extends Dialog
fileDialog.setFilterPath( new File( newImageFilenameText.getText() ).getParent() );
String returnedFileName = fileDialog.open();
+
if ( returnedFileName != null )
{
newImageFilenameText.setText( returnedFileName );
@@ -372,8 +377,8 @@ public class ImageDialog extends Dialog
} );
newTab.setControl( newImageContainer );
-
applyDialogFont( composite );
+
return composite;
}
@@ -411,14 +416,13 @@ public class ImageDialog extends Dialog
Composite labelComposite = new Composite( parent, SWT.BORDER );
labelComposite.setLayout( new GridLayout() );
GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
- // gd.widthHint = MAX_WIDTH;
- // gd.heightHint = MAX_HEIGHT;
labelComposite.setLayoutData( gd );
labelComposite.setBackground( getShell().getDisplay().getSystemColor( SWT.COLOR_WIDGET_NORMAL_SHADOW ) );
Label imageLabel = new Label( labelComposite, SWT.CENTER );
gd = new GridData( SWT.CENTER, SWT.CENTER, true, true );
imageLabel.setLayoutData( gd );
+
return imageLabel;
}
@@ -430,7 +434,7 @@ public class ImageDialog extends Dialog
{
if ( currentTab != null )
{
- if ( currentImage != null && !currentImage.isDisposed() )
+ if ( ( currentImage != null ) && !currentImage.isDisposed() )
{
currentImage.dispose();
currentImage = null;
@@ -485,25 +489,29 @@ public class ImageDialog extends Dialog
*/
private void updateNewImageGroup()
{
- if ( newImage != null && !newImage.isDisposed() )
+ if ( ( newImage != null ) && !newImage.isDisposed() )
{
newImage.dispose();
newImage = null;
}
- if ( !"".equals( newImageFilenameText.getText() ) ) //$NON-NLS-1$
+ String newImageFileName = newImageFilenameText.getText();
+
+ if ( !Strings.isEmpty( newImageFileName ) ) //$NON-NLS-1$
{
try
{
- File file = new File( newImageFilenameText.getText() );
+ File file = new File( newImageFileName );
FileInputStream in = new FileInputStream( file );
ByteArrayOutputStream out = new ByteArrayOutputStream( ( int ) file.length() );
byte[] buf = new byte[4096];
int len;
+
while ( ( len = in.read( buf ) ) > 0 )
{
out.write( buf, 0, len );
}
+
newImageRawData = out.toByteArray();
out.close();
in.close();
@@ -541,7 +549,7 @@ public class ImageDialog extends Dialog
newImageHeightText.setText( "-" ); //$NON-NLS-1$
}
- if ( newImageRawData != null && newImageRawData.length > 0 )
+ if ( ( newImageRawData != null ) && ( newImageRawData.length > 0 ) )
{
try
{
@@ -549,6 +557,7 @@ public class ImageDialog extends Dialog
newImage = new Image( getShell().getDisplay(), resizeImage( imageData ) );
newImageLabel.setImage( newImage );
newImageTypeText.setText( getImageType( imageData.type ) );
+
if ( imageData.type != requiredImageType )
{
newImageTypeText
@@ -557,6 +566,7 @@ public class ImageDialog extends Dialog
.bind(
Messages.getString( "ImageDialog.WillBeConverted" ), new String[] { getImageType( requiredImageType ) } ) ); //$NON-NLS-1$
}
+
newImageSizeText.setText( getSizeString( newImageRawData.length ) );
newImageWidthText.setText( NLS.bind( Messages.getString( "ImageDialog.Pixel" ), imageData.width ) ); //$NON-NLS-1$
newImageHeightText.setText( NLS.bind( Messages.getString( "ImageDialog.Pixel" ), imageData.height ) ); //$NON-NLS-1$
@@ -593,15 +603,17 @@ public class ImageDialog extends Dialog
{
currentImageSaveButton.setFocus();
}
+
updateCurrentImageGroup();
}
if ( newImageBrowseButton != null )
{
- if ( tabFolder.getSelectionIndex() == NEW_TAB || currentImageSaveButton == null )
+ if ( ( tabFolder.getSelectionIndex() == NEW_TAB ) || ( currentImageSaveButton == null ) )
{
newImageBrowseButton.setFocus();
}
+
updateNewImageGroup();
}
}
@@ -618,6 +630,7 @@ public class ImageDialog extends Dialog
{
// Computing the width scale factor
double widthScaleFactor = 1.0;
+
if ( imageData.width > MAX_WIDTH )
{
widthScaleFactor = ( double ) MAX_WIDTH / imageData.width;
@@ -625,6 +638,7 @@ public class ImageDialog extends Dialog
// Computing the height scale factor
double heightScaleFactor = 1.0;
+
if ( imageData.height > MAX_HEIGHT )
{
heightScaleFactor = ( double ) MAX_HEIGHT / imageData.height;
@@ -650,25 +664,32 @@ public class ImageDialog extends Dialog
private ImageData resize( ImageData imageData, int width, int height )
{
Image image = new Image( Display.getDefault(), imageData );
-
Image resizedImage = new Image( Display.getDefault(), width, height );
- GC gc = new GC( resizedImage );
-
try
{
- gc.setAntialias( SWT.ON );
- gc.setInterpolation( SWT.HIGH );
- gc.drawImage( image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, width, height );
+ GC gc = new GC( resizedImage );
+
+ try
+ {
+ gc.setAntialias( SWT.ON );
+ gc.setInterpolation( SWT.HIGH );
+ gc.drawImage( image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, width, height );
+ }
+ finally
+ {
+ gc.dispose();
+ }
+
+ ImageData resizedImageData = resizedImage.getImageData();
+
+ return resizedImageData;
}
finally
{
- gc.dispose();
+ image.dispose();
+ resizedImage.dispose();
}
-
- image.dispose();
-
- return resizedImage.getImageData();
}
@@ -686,6 +707,7 @@ public class ImageDialog extends Dialog
gl.marginHeight = gl.marginWidth = 0;
imageInfoContainer.setLayout( gl );
imageInfoContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+
return imageInfoContainer;
}
@@ -702,6 +724,7 @@ public class ImageDialog extends Dialog
{
BaseWidgetUtils.createLabel( parent, label, 1 );
Text text = BaseWidgetUtils.createLabeledText( parent, "", 1 ); //$NON-NLS-1$
+
return text;
}
@@ -717,6 +740,7 @@ public class ImageDialog extends Dialog
private Button createButton( Composite parent, String label )
{
Button button = BaseWidgetUtils.createButton( parent, label, 1 );
+
return button;
}
@@ -756,7 +780,6 @@ public class ImageDialog extends Dialog
*/
public static String getImageInfo( byte[] imageRawData )
{
-
if ( imageRawData == null )
{
return "NULL"; //$NON-NLS-1$
@@ -768,8 +791,11 @@ public class ImageDialog extends Dialog
ByteArrayInputStream bais = new ByteArrayInputStream( imageRawData );
ImageData imageData = new ImageData( bais );
String typePrefix = getImageType( imageData.type );
- if ( !"".equals( typePrefix ) ) //$NON-NLS-1$
+
+ if ( !Strings.isEmpty( typePrefix ) ) //$NON-NLS-1$
+ {
typePrefix += "-"; //$NON-NLS-1$
+ }
text = NLS
.bind(
@@ -779,6 +805,7 @@ public class ImageDialog extends Dialog
{
text = NLS.bind( Messages.getString( "ImageDialog.InvalidImage" ), new Object[] { imageRawData.length } ); //$NON-NLS-1$
}
+
return text;
}
@@ -792,31 +819,29 @@ public class ImageDialog extends Dialog
*/
private static String getImageType( int swtCode )
{
- String type = ""; //$NON-NLS-1$
-
- if ( swtCode == SWT.IMAGE_JPEG )
- {
- type = "JPEG"; //$NON-NLS-1$
- }
- else if ( swtCode == SWT.IMAGE_GIF )
- {
- type = "GIF"; //$NON-NLS-1$
- }
- else if ( swtCode == SWT.IMAGE_PNG )
- {
- type = "PNG"; //$NON-NLS-1$
- }
- else if ( swtCode == SWT.IMAGE_BMP || swtCode == SWT.IMAGE_BMP_RLE )
+ switch ( swtCode )
{
- type = "BMP"; //$NON-NLS-1$
+ case SWT.IMAGE_JPEG :
+ return "JPEG"; //$NON-NLS-1$
+
+ case SWT.IMAGE_GIF :
+ return "GIF"; //$NON-NLS-1$
+
+ case SWT.IMAGE_PNG :
+ return "PNG"; //$NON-NLS-1$
+
+ case SWT.IMAGE_BMP :
+ case SWT.IMAGE_BMP_RLE :
+ return "BMP"; //$NON-NLS-1$
+
+ default :
+ return "";
}
-
- return type;
}
/**
- * Gets the iimage data in required format.
+ * Gets the image data in required format.
*
* @return Returns the image data in required format or null.
*/