From 643f9d0f51267cc95bebbfc4b0de5f0d673014cd Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Wed, 7 May 2003 08:35:41 +0000 Subject: [PATCH] Save and load ready to upload albums (and save a backup before uploading, in case of a problem). Reformatted many source files using IdeaJ. --- com/gallery/GalleryRemote/model/Album.java | 68 ++++++++++++-------- com/gallery/GalleryRemote/model/Gallery.java | 52 +++++++++------ com/gallery/GalleryRemote/model/Picture.java | 62 +++++++++++++----- 3 files changed, 119 insertions(+), 63 deletions(-) diff --git a/com/gallery/GalleryRemote/model/Album.java b/com/gallery/GalleryRemote/model/Album.java index e0cca8c..6bd4722 100644 --- a/com/gallery/GalleryRemote/model/Album.java +++ b/com/gallery/GalleryRemote/model/Album.java @@ -20,12 +20,21 @@ */ package com.gallery.GalleryRemote.model; -import java.io.*; -import java.util.*; -import javax.swing.*; -import javax.swing.event.*; - -import com.gallery.GalleryRemote.*; +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Vector; + +import javax.swing.ListModel; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; + +import com.gallery.GalleryRemote.GalleryCommCapabilities; +import com.gallery.GalleryRemote.Log; +import com.gallery.GalleryRemote.StatusUpdate; +import com.gallery.GalleryRemote.StatusUpdateAdapter; /** * Album model @@ -34,7 +43,7 @@ *@created 11 août 2002 */ -public class Album extends Picture implements ListModel +public class Album extends Picture implements ListModel, Serializable { /* ------------------------------------------------------------------------- * CONSTANTS @@ -50,7 +59,7 @@ public class Album extends Picture implements ListModel /* ------------------------------------------------------------------------- * WORKAROUND FOR LIST SELECTION BUG */ - ListSelectionModel listSelectionModel; + transient ListSelectionModel listSelectionModel; /* ------------------------------------------------------------------------- * SERVER INFO @@ -59,25 +68,26 @@ public class Album extends Picture implements ListModel Album parent; // parent Album String title = "Not yet connected to Gallery"; String name; - int autoResize = 0; + + transient int autoResize = 0; // permissions -- default to true for the sake of old protocols ... - boolean canRead = true; - boolean canAdd = true; - boolean canWrite = true; - boolean canDeleteFrom = true; - boolean canDeleteThisAlbum = true; - boolean canCreateSubAlbum = true; + transient boolean canRead = true; + transient boolean canAdd = true; + transient boolean canWrite = true; + transient boolean canDeleteFrom = true; + transient boolean canDeleteThisAlbum = true; + transient boolean canCreateSubAlbum = true; - boolean hasFetchedInfo = false; + transient boolean hasFetchedInfo = false; /* ------------------------------------------------------------------------- * INSTANCE VARIABLES */ - long pictureFileSize = -1; + transient long pictureFileSize = -1; // ListModel - Vector listeners = new Vector( 1 ); + transient Vector listeners = null; /* ------------------------------------------------------------------------- @@ -461,6 +471,8 @@ public Object getElementAt( int index ) { *@param ldl The feature to be added to the ListDataListener attribute */ public void addListDataListener( ListDataListener ldl ) { + if (listeners == null) listeners = new Vector(1); + listeners.addElement( ldl ); } @@ -470,7 +482,9 @@ public void addListDataListener( ListDataListener ldl ) { *@param ldl Description of Parameter */ public void removeListDataListener( ListDataListener ldl ) { - listeners.removeElement( ldl ); + if (listeners != null) { + listeners.removeElement( ldl ); + } } /** @@ -577,13 +591,15 @@ void notifyListeners() { } void notifyListeners(ListDataEvent lde) { - pictureFileSize = -1; - - Log.log(Log.TRACE, MODULE, "Firing ListDataEvent=" + lde.toString()); - Enumeration e = listeners.elements(); - while ( e.hasMoreElements() ) { - ListDataListener ldl = (ListDataListener) e.nextElement(); - ldl.contentsChanged( lde ); + if (listeners != null) { + pictureFileSize = -1; + + Log.log(Log.TRACE, MODULE, "Firing ListDataEvent=" + lde.toString()); + Enumeration e = listeners.elements(); + while ( e.hasMoreElements() ) { + ListDataListener ldl = (ListDataListener) e.nextElement(); + ldl.contentsChanged( lde ); + } } } } diff --git a/com/gallery/GalleryRemote/model/Gallery.java b/com/gallery/GalleryRemote/model/Gallery.java index 4447c4f..a908dd1 100644 --- a/com/gallery/GalleryRemote/model/Gallery.java +++ b/com/gallery/GalleryRemote/model/Gallery.java @@ -20,11 +20,17 @@ */ package com.gallery.GalleryRemote.model; -import java.io.*; -import java.net.*; -import java.util.*; -import javax.swing.*; -import javax.swing.event.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Vector; +import java.io.Serializable; + +import javax.swing.ComboBoxModel; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; import com.gallery.GalleryRemote.*; @@ -35,7 +41,7 @@ *@created 17 août 2002 */ -public class Gallery implements ComboBoxModel +public class Gallery implements ComboBoxModel, Serializable { public static final String MODULE="Gallery"; @@ -45,19 +51,18 @@ public class Gallery implements ComboBoxModel ArrayList albumList = null; Album selectedAlbum = null; - GalleryComm comm = null; + transient GalleryComm comm = null; // ListModel - Vector listeners = new Vector( 1 ); + transient Vector listeners = null; + + transient StatusUpdate su; /** * Constructor for the Gallery object */ public Gallery() { } - - /*TEMPORARY*/ StatusUpdate su; - /** * Constructor for the Gallery object * @@ -69,7 +74,7 @@ public Gallery( URL url, String username, String password, /*TEMPORARY*/ StatusU setUrl( url ); this.username = username; this.password = password; - /*TEMPORARY*/ this.su = su; + this.su = su; } @@ -88,7 +93,7 @@ public void newAlbum( Album a, StatusUpdate su) { // create album synchronously getComm( su ).newAlbum( su, a.getParentAlbum(), a.getName(), - a.getTitle(), a.getCaption(), false ); + a.getTitle(), a.getCaption(), false ); // refresh album list asynchronously fetchAlbums( su ); @@ -344,12 +349,16 @@ public Object getSelectedItem() { } public void addListDataListener( ListDataListener ldl ) { + if (listeners == null) listeners = new Vector(1); + listeners.addElement( ldl ); } public void removeListDataListener( ListDataListener ldl ) { - listeners.removeElement( ldl ); + if (listeners != null) { + listeners.removeElement( ldl ); + } } @@ -387,12 +396,13 @@ void notifyListeners() { } void notifyListeners(ListDataEvent lde) { - Log.log(Log.TRACE, MODULE, "Firing ListDataEvent=" + lde.toString()); - Enumeration e = listeners.elements(); - while ( e.hasMoreElements() ) { - ListDataListener ldl = (ListDataListener) e.nextElement(); - ldl.contentsChanged( lde ); + if (listeners != null) { + Log.log(Log.TRACE, MODULE, "Firing ListDataEvent=" + lde.toString()); + Enumeration e = listeners.elements(); + while ( e.hasMoreElements() ) { + ListDataListener ldl = (ListDataListener) e.nextElement(); + ldl.contentsChanged( lde ); + } } } -} - +} \ No newline at end of file diff --git a/com/gallery/GalleryRemote/model/Picture.java b/com/gallery/GalleryRemote/model/Picture.java index de8d946..b026a27 100644 --- a/com/gallery/GalleryRemote/model/Picture.java +++ b/com/gallery/GalleryRemote/model/Picture.java @@ -20,13 +20,14 @@ */ package com.gallery.GalleryRemote.model; -import java.io.*; -import java.awt.*; -import java.awt.dnd.*; -import java.awt.datatransfer.*; -import java.util.*; +import java.awt.Dimension; +import java.io.File; +import java.io.Serializable; -import com.gallery.GalleryRemote.*; +import com.gallery.GalleryRemote.GalleryRemote; +import com.gallery.GalleryRemote.util.ImageUtils; +import com.gallery.GalleryRemote.util.HTMLEscaper; +import com.gallery.GalleryRemote.Log; /** * Picture model @@ -34,13 +35,17 @@ *@author paour *@created 11 août 2002 */ -public class Picture { +public class Picture implements Serializable { + public static final String MODULE="Picture"; + File source = null; String caption = null; - double fileSize = -1; Album album = null; private int listIndex; - + + transient double fileSize = -1; + transient String escapedCaption = null; + /** * Constructor for the Picture object */ @@ -80,6 +85,7 @@ public void setSource( File source ) { */ public void setCaption( String caption ) { this.caption = caption; + this.escapedCaption = null; } @@ -127,12 +133,23 @@ public File getUploadSource() { } } } - + + File picture = null; + if ( d != null ) { - return ImageUtils.resize( getSource().getPath(), d ); - } else { - return getSource(); + try { + picture = ImageUtils.resize( getSource().getPath(), d ); + } catch (UnsupportedOperationException e) { + Log.log(Log.ERROR, MODULE, "Couldn't use ImageUtils to resize the image, it will be uploaded at the original size"); + Log.logException(Log.ERROR, MODULE, e); + } } + + if (picture == null) { + picture = getSource(); + } + + return picture; } else { return getSource(); } @@ -146,8 +163,21 @@ public File getUploadSource() { public String getCaption() { return caption; } - - + + /** + * Cache the escapedCaption because the escaping is lengthy and this is called by a frequent UI method + * @return the HTML escaped version of the caption + */ + public String getEscapedCaption() { + if (escapedCaption == null) { + if (caption != null) { + escapedCaption = HTMLEscaper.escape(caption); + } + } + + return escapedCaption; + } + /** * Gets the size of the file * @@ -176,7 +206,7 @@ public Album getAlbum() { * */ public int getListIndex() { - return this.listIndex; + return this.listIndex; } /** Setter for property listIndex.