diff --git a/com/gallery/GalleryRemote/model/Gallery.java b/com/gallery/GalleryRemote/model/Gallery.java index 8a61e02..61dd69c 100644 --- a/com/gallery/GalleryRemote/model/Gallery.java +++ b/com/gallery/GalleryRemote/model/Gallery.java @@ -1,23 +1,23 @@ /* - * Gallery Remote - a File Upload Utility for Gallery - * - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2001 Bharat Mediratta - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ +* Gallery Remote - a File Upload Utility for Gallery +* +* Gallery - a web based photo album viewer and editor +* Copyright (C) 2000-2001 Bharat Mediratta +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ package com.gallery.GalleryRemote.model; import java.net.MalformedURLException; @@ -25,9 +25,7 @@ import java.util.*; import java.io.Serializable; -import javax.swing.ComboBoxModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; +import javax.swing.*; import com.gallery.GalleryRemote.*; import com.gallery.GalleryRemote.prefs.PropertiesFile; @@ -40,7 +38,7 @@ *@created 17 août 2002 */ -public class Gallery implements ComboBoxModel, Serializable, PreferenceNames { +public class Gallery extends GalleryAbstractListModel implements ComboBoxModel, Serializable, PreferenceNames { public static final String MODULE="Gallery"; String stUrlString = null; @@ -54,9 +52,6 @@ public class Gallery implements ComboBoxModel, Serializable, PreferenceNames { transient GalleryComm comm = null; - // ListModel - transient Vector listeners = null; - transient StatusUpdate su; transient private int prefsIndex; @@ -73,26 +68,26 @@ public Gallery(StatusUpdate su) { } /* - * **** Gallery online management **** - */ + * **** Gallery online management **** + */ public void uploadFiles( StatusUpdate su ) { getComm( su ).uploadFiles( su, true ); } - + public void fetchAlbums( StatusUpdate su ) { //albumList = null; getComm( su ).fetchAlbums( su, true ); } - + public void newAlbum( Album a, StatusUpdate su) { Log.log(Log.INFO, MODULE, "Creating new album " + a.toString()); // create album synchronously getComm( su ).newAlbum( su, a.getParentAlbum(), a.getName(), a.getTitle(), a.getCaption(), false ); - + // refresh album list asynchronously fetchAlbums( su ); } @@ -109,14 +104,14 @@ public void logOut() { } /* - * **** Gallery contents handling **** - */ + * **** Gallery contents handling **** + */ public void setAlbumList( ArrayList albumList ) { if ( albumList == null ) { throw new IllegalArgumentException( "Must supply non-null album list." ); } - + ArrayList oldList = this.albumList; this.albumList = albumList; if ( albumList.size() > 0 ) { @@ -125,12 +120,12 @@ public void setAlbumList( ArrayList albumList ) { if (oldList != null) { for (Iterator i = oldList.iterator(); i.hasNext(); ) { Album a = (Album) i.next(); - + Log.log(Log.TRACE, MODULE, a.toString()); if (! a.getPicturesVector().isEmpty()) { Log.log(Log.TRACE, MODULE, "Album " + a + " had pictures"); int j = albumList.indexOf(a); - + if (j != -1) { Album newAlbum = (Album) albumList.get(j); newAlbum.setPicturesVector(a.getPicturesVector()); @@ -138,10 +133,10 @@ public void setAlbumList( ArrayList albumList ) { } } } - + notifyListeners(); } - + /** * Adds an album to the gallery and selects the first one added. */ @@ -149,23 +144,23 @@ public synchronized void addAlbum( Album a ) { if ( a == null ) { throw new IllegalArgumentException( "Must supply non-null album." ); } - + // when the first album becomes available, make sure to select // it in the list boolean firstAlbum = false; - + // lazy allocation if ( this.albumList == null ) { this.albumList = new ArrayList(); firstAlbum = true; } - + albumList.add( a ); - + if ( firstAlbum ) { selectedAlbum = (Album) this.albumList.get(0); } - + notifyListeners(); } @@ -210,10 +205,10 @@ public ArrayList getAllPictureFiles() { /* - * **** Gallery URL management **** - */ + * **** Gallery URL management **** + */ - public static String reformatUrlString(String urlString, boolean trailingSlash) throws MalformedURLException { + public static String reformatUrlString(String urlString, boolean trailingSlash) { if ( urlString == null ) { throw new IllegalArgumentException( "urlString must not be null" ); } @@ -366,12 +361,12 @@ boolean replace(StringBuffer sb, String token, String value) { /* - * **** Gallery properties management **** - */ + * **** Gallery properties management **** + */ public void setUsername( String username ) { if ( username != null && username.length() > 0 - && ! username.equals( this.username ) ) { + && ! username.equals( this.username ) ) { this.username = username; @@ -384,7 +379,7 @@ public void setUsername( String username ) { public void setPassword( String password ) { //Log.log(Log.TRACE, MODULE, "setpassword: " + password); if ( password != null && password.length() > 0 - && ! password.equals( this.password ) ) { + && ! password.equals( this.password ) ) { this.password = password; @@ -504,55 +499,31 @@ public String toString() { if (tmp == null) { tmp = "http://"; } - + return tmp; } public Album getSelectedAlbum() { return selectedAlbum; } - - - /* - * ListModel Implementation - */ - public int getSize() { - if (albumList != null) { - return albumList.size(); - } else { - return 0; - } - } - public Object getElementAt( int index ) { - return albumList.get( index ); + public void setSelectedItem(Object anObject) { + if ((selectedAlbum != null && !selectedAlbum.equals( anObject )) || + selectedAlbum == null && anObject != null) { + selectedAlbum = (Album) anObject; + fireContentsChanged(this, -1, -1); + } } - public void setSelectedItem(Object anItem) { - selectedAlbum = (Album) anItem; - } - public Object getSelectedItem() { return selectedAlbum; } - - public void addListDataListener( ListDataListener ldl ) { - if (listeners == null) listeners = new Vector(1); - - listeners.addElement( ldl ); - } - public void removeListDataListener( ListDataListener ldl ) { - if (listeners != null) { - listeners.removeElement( ldl ); - } - } - /* - * Miscelaneous - */ + * Miscelaneous + */ /** * Lazy instantiation for the GalleryComm instance. @@ -560,41 +531,58 @@ public void removeListDataListener( ListDataListener ldl ) { public GalleryComm getComm(StatusUpdate su) { if ( comm == null && stUrlString != null ) { comm = GalleryComm.getCommInstance(su, getGalleryUrl(""), this); - + if (comm == null) { Log.log(Log.ERROR, MODULE, "No protocol implementation found"); su.error("Gallery Remote can find no protocol implementation at the URL " - + stUrlString.toString() + "\nCheck with a web browser that " - + stUrlString.toString() + "gallery_remote.php is a valid URL"); + + stUrlString.toString() + "\nCheck with a web browser that " + + stUrlString.toString() + "gallery_remote.php is a valid URL"); } } - + return comm; } - + public boolean hasComm() { return comm != null; } void notifyListeners() { - ListDataEvent lde; + //ListDataEvent lde; if (albumList != null) { - lde = new ListDataEvent( com.gallery.GalleryRemote.GalleryRemote.getInstance().mainFrame, ListDataEvent.CONTENTS_CHANGED, 0, albumList.size() ); + //lde = new ListDataEvent( this, ListDataEvent.CONTENTS_CHANGED, 0, albumList.size() ); + fireContentsChanged( this, 0, albumList.size() ); } else { - lde = new ListDataEvent( com.gallery.GalleryRemote.GalleryRemote.getInstance().mainFrame, ListDataEvent.CONTENTS_CHANGED, 0, 0 ); - } - - notifyListeners(lde); - } - - void notifyListeners(ListDataEvent 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 ); - } + //lde = new ListDataEvent( this, ListDataEvent.CONTENTS_CHANGED, 0, 0 ); + fireContentsChanged( this, 0, 0 ); } + + //notifyListeners(lde); } + + /* + * ListModel Implementation + */ + public int getSize() { + if (albumList != null) { + return albumList.size(); + } else { + return 0; + } + } + + public Object getElementAt( int index ) { + return albumList.get( index ); + } + +// void notifyListeners(ListDataEvent 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