Skip to content

Commit

Permalink
Save and load ready to upload albums (and save a backup before upload…
Browse files Browse the repository at this point in the history
…ing, in case of a problem).

Reformatted many source files using IdeaJ.
  • Loading branch information
Pierre-Luc Paour committed May 7, 2003
1 parent b549dc5 commit 643f9d0
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 63 deletions.
68 changes: 42 additions & 26 deletions com/gallery/GalleryRemote/model/Album.java
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -50,7 +59,7 @@ public class Album extends Picture implements ListModel
/* -------------------------------------------------------------------------
* WORKAROUND FOR LIST SELECTION BUG
*/
ListSelectionModel listSelectionModel;
transient ListSelectionModel listSelectionModel;

/* -------------------------------------------------------------------------
* SERVER INFO
Expand All @@ -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;


/* -------------------------------------------------------------------------
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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 );
}
}

/**
Expand Down Expand Up @@ -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 );
}
}
}
}
Expand Down
52 changes: 31 additions & 21 deletions com/gallery/GalleryRemote/model/Gallery.java
Expand Up @@ -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.*;

Expand All @@ -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";

Expand All @@ -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
*
Expand All @@ -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;
}


Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
}
}


Expand Down Expand Up @@ -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 );
}
}
}
}

}
62 changes: 46 additions & 16 deletions com/gallery/GalleryRemote/model/Picture.java
Expand Up @@ -20,27 +20,32 @@
*/
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
*
*@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
*/
Expand Down Expand Up @@ -80,6 +85,7 @@ public void setSource( File source ) {
*/
public void setCaption( String caption ) {
this.caption = caption;
this.escapedCaption = null;
}


Expand Down Expand Up @@ -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();
}
Expand All @@ -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
*
Expand Down Expand Up @@ -176,7 +206,7 @@ public Album getAlbum() {
*
*/
public int getListIndex() {
return this.listIndex;
return this.listIndex;
}

/** Setter for property listIndex.
Expand Down

0 comments on commit 643f9d0

Please sign in to comment.