From ebff852d4807750082edb9dc52f3cf31804486e3 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Thu, 26 Feb 2004 23:29:46 +0000 Subject: [PATCH] 2004-02-26 Pierre-Luc Paour (1.4-b1) * Attempt to make the tree render correctly by moving to DefaultTreeModel and DefaultMutableTreeNodes. This is still unsuccessful and I need help. * Diabled Protocol 1, since it's incompatible with sophisticated tree handling. * Much improved model classes, through a major refactoring. Some functionality broken, DO NOT USE THIS VERSION, stay on BRANCH_GR_1_3 --- ChangeLog | 11 + com/gallery/GalleryRemote/AlbumInspector.java | 4 +- com/gallery/GalleryRemote/CoreUtils.java | 2 +- com/gallery/GalleryRemote/GRAppletMini.java | 4 +- .../GalleryAbstractListModel.java | 16 +- com/gallery/GalleryRemote/GalleryComm.java | 8 +- com/gallery/GalleryRemote/GalleryComm1.java | 365 ------------------ com/gallery/GalleryRemote/GalleryComm2.java | 49 ++- com/gallery/GalleryRemote/MainFrame.java | 131 ++++--- .../GalleryRemote/MoveAlbumDialog.java | 45 ++- com/gallery/GalleryRemote/NewAlbumDialog.java | 62 +-- .../GalleryRemote/PictureInspector.java | 8 +- com/gallery/GalleryRemote/model/Album.java | 198 +++++++--- com/gallery/GalleryRemote/model/Gallery.java | 320 +++++++-------- .../GalleryRemote/model/GalleryItem.java | 106 +++++ com/gallery/GalleryRemote/model/Picture.java | 95 ++--- defaults.properties | 4 +- 17 files changed, 638 insertions(+), 790 deletions(-) delete mode 100644 com/gallery/GalleryRemote/GalleryComm1.java create mode 100644 com/gallery/GalleryRemote/model/GalleryItem.java diff --git a/ChangeLog b/ChangeLog index 858a683..94e1ad1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-02-26 Pierre-Luc Paour (1.4-b1) + + * Attempt to make the tree render correctly by moving to + DefaultTreeModel and DefaultMutableTreeNodes. This is still + unsuccessful and I need help. + * Diabled Protocol 1, since it's incompatible with sophisticated + tree handling. + * Much improved model classes, through a major refactoring. + + Some functionality broken, DO NOT USE THIS VERSION, stay on BRANCH_GR_1_3 + 2004-02-25 Pierre-Luc Paour (1.3.2-b6) * Solved a very long-standing problem where I didn't know how diff --git a/com/gallery/GalleryRemote/AlbumInspector.java b/com/gallery/GalleryRemote/AlbumInspector.java index 3906159..29e6b5a 100644 --- a/com/gallery/GalleryRemote/AlbumInspector.java +++ b/com/gallery/GalleryRemote/AlbumInspector.java @@ -241,7 +241,9 @@ public void actionPerformed(ActionEvent e) { } else if (source == jApply) { // todo } else if (source == jMove) { - new MoveAlbumDialog(mf, album.getGallery(), album); + //MoveAlbumDialog mad = new MoveAlbumDialog(mf, album.getGallery(), album); + //album.moveAlbumTo(GalleryRemote._().getCore().getMainStatusUpdate(), mad.getNewParent()); + album.moveAlbumTo(null, null); } else if (source == jSlideshow) { mf.slideshow(); } else { diff --git a/com/gallery/GalleryRemote/CoreUtils.java b/com/gallery/GalleryRemote/CoreUtils.java index 13ed5f8..59a1d59 100644 --- a/com/gallery/GalleryRemote/CoreUtils.java +++ b/com/gallery/GalleryRemote/CoreUtils.java @@ -152,7 +152,7 @@ public Component getListCellRendererComponent( Picture p = currentAlbum.getPicture(index); if (p.isOnline()) { - if (p.getAlbum() != p.getAlbumOnServer() + if (p.getParentAlbum() != p.getAlbumOnServer() || p.getIndex() != p.getIndexOnServer()) { setForeground(Color.red); } else { diff --git a/com/gallery/GalleryRemote/GRAppletMini.java b/com/gallery/GalleryRemote/GRAppletMini.java index 39e650d..4c92d32 100644 --- a/com/gallery/GalleryRemote/GRAppletMini.java +++ b/com/gallery/GalleryRemote/GRAppletMini.java @@ -81,7 +81,7 @@ public void startup() { album = new Album(gallery); album.setSuppressEvents(true); album.setName(info.albumName); - gallery.addAlbum(album); + //gallery.addAlbum(album); jPicturesList.setModel(album); jPicturesList.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null); @@ -229,7 +229,7 @@ public void actionPerformed(ActionEvent e) { hasHadPictures = true; } } else if (e.getSource() == jUpload) { - gallery.uploadFiles(new UploadProgress(DialogUtil.findParentWindow(this))); + gallery.doUploadFiles(new UploadProgress(DialogUtil.findParentWindow(this))); } } } diff --git a/com/gallery/GalleryRemote/GalleryAbstractListModel.java b/com/gallery/GalleryRemote/GalleryAbstractListModel.java index b74022d..7514542 100644 --- a/com/gallery/GalleryRemote/GalleryAbstractListModel.java +++ b/com/gallery/GalleryRemote/GalleryAbstractListModel.java @@ -89,7 +89,7 @@ public ListDataListener[] getListDataListeners() { * @see EventListenerList * @see DefaultListModel */ - protected void fireContentsChanged(Object source, int index0, int index1) { + public void fireContentsChanged(Object source, int index0, int index1) { if (listenerList == null) listenerList = new EventListenerList(); Object[] listeners = listenerList.getListenerList(); ListDataEvent e = null; @@ -119,7 +119,7 @@ protected void fireContentsChanged(Object source, int index0, int index1) { * @see EventListenerList * @see DefaultListModel */ - protected void fireIntervalAdded(Object source, int index0, int index1) { + public void fireIntervalAdded(Object source, int index0, int index1) { if (listenerList == null) listenerList = new EventListenerList(); Object[] listeners = listenerList.getListenerList(); ListDataEvent e = null; @@ -149,7 +149,7 @@ protected void fireIntervalAdded(Object source, int index0, int index1) { * @see EventListenerList * @see DefaultListModel */ - protected void fireIntervalRemoved(Object source, int index0, int index1) { + public void fireIntervalRemoved(Object source, int index0, int index1) { if (listenerList == null) listenerList = new EventListenerList(); Object[] listeners = listenerList.getListenerList(); ListDataEvent e = null; @@ -259,7 +259,7 @@ public TreeModelListener[] getTreeModelListeners() { * @param children the changed elements * @see javax.swing.event.EventListenerList */ - protected void fireTreeNodesChanged(Object source, Object[] path, + public void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) { // Guaranteed to return a non-null array @@ -290,7 +290,7 @@ protected void fireTreeNodesChanged(Object source, Object[] path, * @param children the new elements * @see javax.swing.event.EventListenerList */ - protected void fireTreeNodesInserted(Object source, Object[] path, + public void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) { // Guaranteed to return a non-null array @@ -321,7 +321,7 @@ protected void fireTreeNodesInserted(Object source, Object[] path, * @param children the removed elements * @see javax.swing.event.EventListenerList */ - protected void fireTreeNodesRemoved(Object source, Object[] path, + public void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) { // Guaranteed to return a non-null array @@ -352,7 +352,7 @@ protected void fireTreeNodesRemoved(Object source, Object[] path, * @param children the affected elements * @see javax.swing.event.EventListenerList */ - protected void fireTreeStructureChanged(Object source, Object[] path, + public void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) { // Guaranteed to return a non-null array @@ -381,7 +381,7 @@ protected void fireTreeStructureChanged(Object source, Object[] path, * @param path the path to the root node * @see EventListenerList */ - protected void fireTreeStructureChanged(Object source, TreePath path) { + public void fireTreeStructureChanged(Object source, TreePath path) { // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); TreeModelEvent e = null; diff --git a/com/gallery/GalleryRemote/GalleryComm.java b/com/gallery/GalleryRemote/GalleryComm.java index fa16e18..d48dd9e 100644 --- a/com/gallery/GalleryRemote/GalleryComm.java +++ b/com/gallery/GalleryRemote/GalleryComm.java @@ -125,7 +125,7 @@ public void fetchAlbumImages(StatusUpdate su, Album a, boolean recusive, boolean throw new RuntimeException("This method is not available on this protocol"); } - public void moveAlbum(StatusUpdate su, Album a, Album newParent, boolean async) { + public boolean moveAlbum(StatusUpdate su, Album a, Album newParent, boolean async) { throw new RuntimeException("This method is not available on this protocol"); } @@ -203,10 +203,12 @@ public static GalleryComm getCommInstance(StatusUpdate su, URL url, Gallery g) { Log.log(Log.LEVEL_TRACE, MODULE, "Trying protocol 1 for " + url); // Test GalleryComm1 // BUT: only if first try was not status code 401 = authorization failure - String urlPath1 = urlPath + ((urlPath.endsWith("/")) ? GalleryComm1.SCRIPT_NAME : "/" + GalleryComm1.SCRIPT_NAME); + String scriptName = "gallery_remote.php"; + String urlPath1 = urlPath + ((urlPath.endsWith("/")) ? scriptName : "/" + scriptName); if (lastRespCode != 401 && tryComm(su, mConnection, urlPath1)) { Log.log(Log.LEVEL_TRACE, MODULE, "Server has protocol 1"); - return new GalleryComm1(g); + + // todo: Alert, we don't support protocol 1 any more. } } else { // if Gallery is embedded, only support protocol 2 diff --git a/com/gallery/GalleryRemote/GalleryComm1.java b/com/gallery/GalleryRemote/GalleryComm1.java deleted file mode 100644 index ce134f1..0000000 --- a/com/gallery/GalleryRemote/GalleryComm1.java +++ /dev/null @@ -1,365 +0,0 @@ -/* - * 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; - -import HTTPClient.*; -import com.gallery.GalleryRemote.model.Album; -import com.gallery.GalleryRemote.model.Gallery; -import com.gallery.GalleryRemote.model.Picture; -import com.gallery.GalleryRemote.util.GRI18n; -import com.gallery.GalleryRemote.util.HTMLEscaper; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.StringTokenizer; - -public class GalleryComm1 extends GalleryComm implements GalleryCommCapabilities { - private static final String MODULE = "GalComm1"; - - - public static final String PROTOCAL_VERSION = "1"; - public static final String SCRIPT_NAME = "gallery_remote.php"; - - protected Gallery g = null; - - protected GalleryComm1(Gallery g) { - this.g = g; - - capabilities = new int[]{CAPA_UPLOAD_FILES, CAPA_FETCH_ALBUMS}; - Arrays.sort(capabilities); - } - - void doTask(GalleryTask task, boolean async) { - if (async) { - Thread t = new Thread(task); - t.start(); - } else { - task.run(); - } - } - - public void uploadFiles(StatusUpdate su, boolean async) { - doTask(new UploadTask(su), async); - } - - public void fetchAlbums(StatusUpdate su, boolean async) { - doTask(new AlbumListTask(su), async); - } - - - //------------------------------------------------------------------------- - //-- GalleryTask - //------------------------------------------------------------------------- - abstract class GalleryTask implements Runnable { - HTTPConnection mConnection; - StatusUpdate su; - boolean interrupt = false; - - public GalleryTask(StatusUpdate su) { - if (su == null) { - this.su = new StatusUpdateAdapter() { - }; - } else { - this.su = su; - } - } - - public void run() { - su.setInProgress(true); - if (!isLoggedIn) { - if (!login()) { - su.setInProgress(false); - return; - } - - isLoggedIn = true; - } else { - Log.log(Log.LEVEL_TRACE, MODULE, "Still logged in to " + g.toString()); - } - - runTask(); - su.setInProgress(false); - } - - public void interrupt() { - interrupt = true; - } - - abstract void runTask(); - - private boolean login() { - Object[] params = {g.toString()}; - - status(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "logging", params)); - - try { - URL url = g.getGalleryUrl(SCRIPT_NAME); - String urlPath = url.getFile(); - Log.log(Log.LEVEL_TRACE, MODULE, "Url: " + url); - - NVPair form_data[] = { - new NVPair("cmd", "login"), - new NVPair("protocal_version", PROTOCAL_VERSION), - new NVPair("uname", g.getUsername()), - new NVPair("password", g.getPassword()) - }; - Log.log(Log.LEVEL_TRACE, MODULE, "login parameters: " + Arrays.asList(form_data)); - - triedLogin = true; - - HTTPConnection mConnection = new HTTPConnection(url); - HTTPResponse rsp = mConnection.Post(urlPath, form_data); - - if (rsp.getStatusCode() >= 300 && rsp.getStatusCode() < 400) { - // retry, the library will have fixed the URL - status(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "redirect")); - - rsp = mConnection.Post(urlPath, form_data); - } - - if (rsp.getStatusCode() >= 300) { - Object[] params2 = {new Integer(rsp.getStatusCode()), rsp.getReasonLine()}; - error(GRI18n.getString(MODULE, "httpErr", params2)); - return false; - } else { - String response = new String(rsp.getData()).trim(); - Log.log(Log.LEVEL_TRACE, MODULE, response); - - if (response.indexOf("SUCCESS") >= 0) { - status(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "loggedIn")); - return true; - } else { - Object[] params2 = {response}; - error(GRI18n.getString(MODULE, "logErr", params2)); - return false; - } - } - } catch (IOException ioe) { - Log.logException(Log.LEVEL_ERROR, MODULE, ioe); - Object[] params3 = {ioe.toString()}; - status(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "error", params3)); - } catch (ModuleException me) { - Log.logException(Log.LEVEL_ERROR, MODULE, me); - Object[] params3 = {me.getMessage()}; - status(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "errReq", params3)); - } - - return false; - } - - void status(int level, String message) { - Log.log(Log.LEVEL_INFO, MODULE, message); - su.updateProgressStatus(level, message); - } - - void error(String message) { - su.error(message); - status(StatusUpdate.LEVEL_GENERIC, message); - } - - void trace(String message) { - Log.log(Log.LEVEL_TRACE, MODULE, message); - } - } - - class UploadTask extends GalleryTask { - UploadTask(StatusUpdate su) { - super(su); - } - - void runTask() { - ArrayList pictures = g.getAllPictures(); - - su.startProgress(StatusUpdate.LEVEL_UPLOAD_PROGRESS, 0, pictures.size(), GRI18n.getString(MODULE, "uploadingPic"), false); - - // upload each file, one at a time - boolean allGood = true; - int uploadedCount = 0; - Iterator iter = pictures.iterator(); - while (iter.hasNext() && allGood && !interrupt) { - Picture p = (Picture) iter.next(); - - Object[] params = {p.toString(), new Integer((uploadedCount + 1)), new Integer(pictures.size())}; - su.updateProgressStatus(StatusUpdate.LEVEL_UPLOAD_PROGRESS, GRI18n.getString(MODULE, "uploadingStat", params)); - - allGood = uploadPicture(p); - - su.updateProgressValue(StatusUpdate.LEVEL_UPLOAD_PROGRESS, uploadedCount++); - - p.getAlbum().removePicture(p); - } - - if (allGood) { - su.stopProgress(StatusUpdate.LEVEL_UPLOAD_PROGRESS, GRI18n.getString(MODULE, "upldComplete")); - } else { - su.stopProgress(StatusUpdate.LEVEL_UPLOAD_PROGRESS, GRI18n.getString(MODULE, "upldFailed")); - } - } - - boolean uploadPicture(Picture p) { - try { - URL url = g.getGalleryUrl(SCRIPT_NAME); - String urlPath = url.getFile(); - Log.log(Log.LEVEL_TRACE, MODULE, "Url: " + url); - - NVPair[] opts = { - new NVPair("set_albumName", p.getAlbum().getName()), - new NVPair("cmd", "add-item"), - new NVPair("protocal_version", PROTOCAL_VERSION) - }; - Log.log(Log.LEVEL_TRACE, MODULE, "add-item parameters: " + Arrays.asList(opts)); - - NVPair[] afile = {new NVPair("userfile", p.getUploadSource().getAbsolutePath())}; - NVPair[] hdrs = new NVPair[1]; - byte[] data = Codecs.mpFormDataEncode(opts, afile, hdrs); - HTTPConnection mConnection = new HTTPConnection(url); - HTTPResponse rsp = mConnection.Post(urlPath, data, hdrs); - - if (rsp.getStatusCode() >= 300 && rsp.getStatusCode() < 400) { - // retry, the library will have fixed the URL - status(StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "redirect")); - - rsp = mConnection.Post(urlPath, data, hdrs); - } - - if (rsp.getStatusCode() >= 300) { - Object[] params2 = {new Integer(rsp.getStatusCode()), rsp.getReasonLine()}; - error(GRI18n.getString(MODULE, "httpErr", params2)); - return false; - } else { - String response = new String(rsp.getData()).trim(); - Log.log(Log.LEVEL_TRACE, MODULE, response); - - if (response.indexOf("SUCCESS") >= 0) { - trace(GRI18n.getString(MODULE, "upldSucc")); - return true; - } else { - Object[] params = {response}; - error(GRI18n.getString(MODULE, "upldErr", params)); - return false; - } - } - } catch (IOException ioe) { - Log.logException(Log.LEVEL_ERROR, MODULE, ioe); - Object[] params3 = {ioe.toString()}; - error(GRI18n.getString(MODULE, "error", params3)); - } catch (ModuleException me) { - Log.logException(Log.LEVEL_ERROR, MODULE, me); - Object[] params3 = {me.getMessage()}; - error(GRI18n.getString(MODULE, "errReq", params3)); - } - - return false; - } - } - - class AlbumListTask extends GalleryTask { - AlbumListTask(StatusUpdate su) { - super(su); - } - - void runTask() { - Object[] params = {g.toString()}; - su.startProgress(StatusUpdate.LEVEL_BACKGROUND, 0, 10, GRI18n.getString(MODULE, "ftchngAlbm", params), true); - - try { - URL url = g.getGalleryUrl(SCRIPT_NAME); - String urlPath = url.getFile(); - Log.log(Log.LEVEL_TRACE, MODULE, "Url: " + url); - - NVPair form_data[] = { - new NVPair("cmd", "fetch-albums"), - new NVPair("protocal_version", PROTOCAL_VERSION), - new NVPair("uname", g.getUsername()), - new NVPair("password", g.getPassword()) - }; - Log.log(Log.LEVEL_TRACE, MODULE, "fetchAlbums parameters: " + Arrays.asList(form_data)); - - mConnection = new HTTPConnection(url); - HTTPResponse rsp = mConnection.Post(urlPath, form_data); - - if (rsp.getStatusCode() >= 300 && rsp.getStatusCode() < 400) { - // retry, the library will have fixed the URL - status(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "redirect")); - - rsp = mConnection.Post(urlPath, form_data); - } - - if (rsp.getStatusCode() >= 300) { - Object[] params2 = {new Integer(rsp.getStatusCode()), rsp.getReasonLine()}; - error(GRI18n.getString(MODULE, "httpErr", params2)); - return; - } else { - String response = new String(rsp.getData()).trim(); - Log.log(Log.LEVEL_TRACE, MODULE, response); - - if (response.indexOf("SUCCESS") >= 0) { - ArrayList mAlbumList = new ArrayList(); - - // build the list of hashtables here... - StringTokenizer lineT = new StringTokenizer(response, "\n"); - while (lineT.hasMoreTokens()) { - StringTokenizer colT = new StringTokenizer(lineT.nextToken(), "\t"); - - if (colT.countTokens() == 2) { - Album a = new Album(g); - a.setSuppressEvents(true); - - a.setName(colT.nextToken()); - a.setTitle(HTMLEscaper.unescape(colT.nextToken())); - - mAlbumList.add(a); - - a.setParentAlbum(null); - a.setSuppressEvents(false); - } - } - - status(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "ftchdAlbm")); - - g.setAlbumList(mAlbumList); - } else { - Object[] params2 = {response}; - error(GRI18n.getString(MODULE, "error", params2)); - } - } - } catch (IOException ioe) { - Log.logException(Log.LEVEL_ERROR, MODULE, ioe); - Object[] params2 = {ioe.toString()}; - status(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "error", params2)); - } catch (ModuleException me) { - Log.logException(Log.LEVEL_ERROR, MODULE, me); - Object[] params2 = {me.toString()}; - status(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "error", params2)); - } catch (Exception ee) { - Log.logException(Log.LEVEL_ERROR, MODULE, ee); - Object[] params2 = {ee.toString()}; - status(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "error", params2)); - } - - su.stopProgress(StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "ftchComplt")); - } - } -} diff --git a/com/gallery/GalleryRemote/GalleryComm2.java b/com/gallery/GalleryRemote/GalleryComm2.java index eb75551..d333dc8 100644 --- a/com/gallery/GalleryRemote/GalleryComm2.java +++ b/com/gallery/GalleryRemote/GalleryComm2.java @@ -198,9 +198,11 @@ public void fetchAlbumImages(StatusUpdate su, Album a, boolean recusive, boolean doTask(fetchAlbumImagesTask, async); } - public void moveAlbum(StatusUpdate su, Album a, Album newParent, boolean async) { + public boolean moveAlbum(StatusUpdate su, Album a, Album newParent, boolean async) { MoveAlbumTask moveAlbumTask = new MoveAlbumTask(su, a, newParent); doTask(moveAlbumTask, async); + + return moveAlbumTask.getSuccess(); } public void login(StatusUpdate su) { @@ -577,7 +579,7 @@ public void actionPerformed(ActionEvent e) { su.updateProgressValue(StatusUpdate.LEVEL_UPLOAD_PROGRESS, ++uploadedCount); if (allGood) { - p.getAlbum().removePicture(p); + p.getParentAlbum().removePicture(p); } } @@ -614,7 +616,7 @@ boolean uploadPicture(Picture p) { NVPair[] opts = { new NVPair("cmd", "add-item"), new NVPair("protocol_version", PROTOCOL_VERSION), - new NVPair("set_albumName", p.getAlbum().getName()), + new NVPair("set_albumName", p.getParentAlbum().getName()), new NVPair("caption", caption), new NVPair("force_filename", p.getSource().getName()), null @@ -706,6 +708,9 @@ void runTask() { list22(); } + // tell the tree to reload + g.reload(); + Log.log(Log.LEVEL_INFO, MODULE, "execution time for AlbumList: " + (System.currentTimeMillis() - startTime)); } catch (GR2Exception gr2e) { Log.logException(Log.LEVEL_ERROR, MODULE, gr2e); @@ -742,6 +747,9 @@ private void list20() throws IOException, ModuleException { // System.err.println( "### albumCount = " + albumCount ); HashMap ref2parKey = new HashMap(); HashMap ref2album = new HashMap(); + + Album rootAlbum = g.createRootAlbum(); + for (int i = 1; i < albumCount + 1; i++) { Album a = new Album(g); a.setSuppressEvents(true); @@ -778,7 +786,7 @@ private void list20() throws IOException, ModuleException { if (parentRef != 0) { ref2parKey.put("" + i, parentRefS); } else { - a.setParentAlbum(null); + rootAlbum.add(a); } } @@ -789,14 +797,14 @@ private void list20() throws IOException, ModuleException { Album a = (Album) ref2album.get("" + i); if (a != null) { Album pa = (Album) ref2album.get(parentKey); - a.setParentAlbum(pa); + pa.add(a); } } } status(su, StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "ftchdAlbms")); - g.setAlbumList(mAlbumList); + //g.setAlbumList(mAlbumList); } else { Object[] params = {p.getProperty("status_text")}; error(su, GRI18n.getString(MODULE, "error", params)); @@ -821,6 +829,9 @@ private void list22() throws IOException, ModuleException { // System.err.println( "### albumCount = " + albumCount ); HashMap name2parentName = new HashMap(); HashMap name2album = new HashMap(); + + Album rootAlbum = g.createRootAlbum(); + for (int i = 1; i < albumCount + 1; i++) { Album a = new Album(g); a.setSuppressEvents(true); @@ -850,15 +861,24 @@ private void list22() throws IOException, ModuleException { albums.add(a); - // map album names to parent albums + // map album names to albums name2album.put(name, a); // map album refs to parent refs String parentName = p.getProperty(parentKey); + + if (parentName.equals(name)) { + Log.log(Log.LEVEL_ERROR, MODULE, "Gallery error: the album " + name + + " is its own parent. You should delete it, the album database " + + "is corrupted because of it."); + + parentName = null; + } + if (parentName != null && parentName.length() > 0 && !parentName.equals("0")) { name2parentName.put(name, parentName); } else { - a.setParentAlbum(null); + rootAlbum.add(a); } } @@ -873,7 +893,7 @@ private void list22() throws IOException, ModuleException { Album parent = (Album) name2album.get(parentName); if (child != null && parent != null) { - child.setParentAlbum(parent); + parent.add(child); } } @@ -943,7 +963,7 @@ private void list22() throws IOException, ModuleException { status(su, StatusUpdate.LEVEL_BACKGROUND, GRI18n.getString(MODULE, "ftchdAlbms")); - g.setAlbumList(orderedAlbums); + //g.setAlbumList(orderedAlbums); } else { Object[] params = {p.getProperty("status_text")}; error(su, GRI18n.getString(MODULE, "error", params)); @@ -1152,7 +1172,7 @@ private void fetch(Album a, String albumName, ArrayList newPictures) if (subAlbumName != null) { fetch(a, subAlbumName, newPictures); } else { - Picture picture = new Picture(); + Picture picture = new Picture(g); picture.setOnline(true); picture.setUrlFull(new URL(baseUrl + p.getProperty("image.name." + i))); width = p.getIntProperty("image.raw_width." + i, 0); @@ -1218,6 +1238,7 @@ private void fetch(Album a, String albumName, ArrayList newPictures) class MoveAlbumTask extends GalleryTask { Album a; Album newParent; + boolean success = false; MoveAlbumTask(StatusUpdate su, Album a, Album newParent) { super(su); @@ -1256,6 +1277,8 @@ void runTask() { if (p.getProperty("status").equals(GR_STAT_SUCCESS)) { status(su, StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "moveAlbumDone")); + + success = true; } else { error(su, "Error: " + p.getProperty("status_text")); } @@ -1274,6 +1297,10 @@ void runTask() { error(su, GRI18n.getString(MODULE, "error", params2)); } } + + public boolean getSuccess() { + return success; + } } boolean isTrue(String s) { diff --git a/com/gallery/GalleryRemote/MainFrame.java b/com/gallery/GalleryRemote/MainFrame.java index 52ebab0..693bce8 100644 --- a/com/gallery/GalleryRemote/MainFrame.java +++ b/com/gallery/GalleryRemote/MainFrame.java @@ -122,11 +122,11 @@ public class MainFrame extends JFrame JButton jNewAlbumButton = new JButton(); JMenu jMenuFile = new JMenu(); - JMenuItem jMenuItemNew = new JMenuItem(); + //JMenuItem jMenuItemNew = new JMenuItem(); JMenuItem jMenuItemOpen = new JMenuItem(); JMenuItem jMenuItemSave = new JMenuItem(); JMenuItem jMenuItemSaveAs = new JMenuItem(); - JMenuItem jMenuItemClose = new JMenuItem(); + //JMenuItem jMenuItemClose = new JMenuItem(); JMenuItem jMenuItemQuit = new JMenuItem(); // Create a Vector to store the MRU menu items. They @@ -176,7 +176,7 @@ public void initMainFrame() { if (g == null) { break; } - g.addListDataListener(this); + //g.addListDataListener(this); galleries.addElement(g); } catch (Exception e) { Log.log(Log.LEVEL_ERROR, MODULE, "Error trying to load Gallery profile " + i); @@ -320,7 +320,7 @@ private void setGalleries(DefaultComboBoxModel galleries) { jGalleryCombo.setModel(galleries); galleries.addListDataListener(this); - updateGalleryParams(); + selectedGalleryChanged(); // We've been initalized, we are now clean. setDirtyFlag(false); @@ -454,12 +454,12 @@ public void run() { jNewGalleryButton.setEnabled(!inProgress); // Disable New, Open, and Close - jMenuItemNew.setEnabled(!inProgress); + //jMenuItemNew.setEnabled(!inProgress); jMenuItemOpen.setEnabled(!inProgress); jMenuItemSave.setEnabled(!inProgress); jMenuItemSaveAs.setEnabled(!inProgress); - jMenuItemClose.setEnabled(!inProgress - && null != lastOpenedFile); + //jMenuItemClose.setEnabled(!inProgress + // && null != lastOpenedFile); // in the event the library we use to save is missing, dim the menus try { @@ -479,7 +479,7 @@ public void run() { jLoginButton.setText(GRI18n.getString(MODULE, "Log_in")); } - jAlbumTree.setEnabled(!inProgress && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1); + jAlbumTree.setEnabled(!inProgress && jAlbumTree.getModel().getRoot() != null && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1); // if the selected album is uploading, disable everything boolean enabled = !inProgress && currentAlbum != null && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1; @@ -545,35 +545,32 @@ public void run() { } - private void updateGalleryParams() { - Log.log(Log.LEVEL_TRACE, MODULE, "updateGalleryParams: current gallery: " + getCurrentGallery()); - - updateAlbumCombo(); - } - - - private void updateAlbumCombo() { + private void selectedGalleryChanged() { Gallery currentGallery = getCurrentGallery(); - Log.log(Log.LEVEL_TRACE, MODULE, "updateAlbumCombo: current gallery: " + currentGallery); + Log.log(Log.LEVEL_TRACE, MODULE, "updateGalleryParams: current gallery: " + currentGallery); - if (currentGallery != null && jAlbumTree.getModel() != currentGallery) { + if (currentGallery != null /*&& jAlbumTree.getModel() != currentGallery*/) { jAlbumTree.setModel(currentGallery); - currentGallery.addListDataListener(this); + //currentGallery.addListDataListener(this); } - if (currentGallery == null || currentGallery.getSize() < 1) { + if (currentGallery == null || currentGallery.getRoot() == null) { jAlbumTree.setEnabled(false); jPicturesList.setEnabled(false); - - updatePicturesList(); } else { jAlbumTree.setEnabled(!inProgress); - - updatePicturesList(); } + + updatePicturesList(); } + /*private void updateAlbumCombo() { + Gallery currentGallery = getCurrentGallery(); + Log.log(Log.LEVEL_TRACE, MODULE, "updateAlbumCombo: current gallery: " + currentGallery); + }*/ + + private void updatePicturesList() { Album currentAlbum = getCurrentAlbum(); Log.log(Log.LEVEL_TRACE, MODULE, "updatePicturesList: current album: " + currentAlbum); @@ -703,7 +700,7 @@ public void uploadPictures() { saveState(f); - getCurrentGallery().uploadFiles(new UploadProgress(this)); + getCurrentGallery().doUploadFiles(new UploadProgress(this)); } @@ -724,11 +721,12 @@ public void sortPictures() { public void fetchAlbums() { Log.log(Log.LEVEL_INFO, MODULE, "fetchAlbums starting"); - getCurrentGallery().fetchAlbums(jStatusBar); + getCurrentGallery().doFetchAlbums(jStatusBar); //updateAlbumCombo(); - if (jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) > 0) { + Object root = jAlbumTree.getModel().getRoot(); + if (root != null && jAlbumTree.getModel().getChildCount(root) > 0) { jAlbumTree.setSelectionPath(null); } } @@ -741,13 +739,21 @@ public void fetchAlbumImages() { public void newAlbum() { NewAlbumDialog dialog = new NewAlbumDialog(this, getCurrentGallery(), getCurrentAlbum()); - final String newAlbumName = dialog.getNewAlbumName(); + //String newAlbumName = dialog.getNewAlbumName(); + + Album newAlbum = dialog.getNewAlbum(); + //Album parentAlbum = dialog.getParentAlbum(); - if (newAlbumName == null || newAlbumName.length() == 0) { + if (newAlbum == null) { return; } - Log.log(Log.LEVEL_TRACE, MODULE, "Album '" + newAlbumName + "' created."); + String newAlbumName = getCurrentGallery().doNewAlbum(newAlbum, GalleryRemote._().getCore().getMainStatusUpdate()); + if (newAlbumName.equals(newAlbum.getName())) { + newAlbum.setName(newAlbumName); + } + + Log.log(Log.LEVEL_TRACE, MODULE, "Album '" + newAlbum + "' created."); // there is probably a better way... this is needed to give the UI time to catch up // and load the combo up with the reloaded album list //new Thread() { @@ -760,13 +766,14 @@ public void newAlbum() { //SwingUtilities.invokeLater(new Runnable() { // public void run() { - Log.log(Log.LEVEL_TRACE, MODULE, "Selecting " + newAlbumName); + Log.log(Log.LEVEL_TRACE, MODULE, "Selecting " + newAlbum); - TreePath path = getCurrentGallery().getPathForAlbum(getCurrentGallery().getAlbumByName(newAlbumName)); + TreePath path = new TreePath(newAlbum.getPath());//new TreePath(getCurrentGallery().getPathToRoot(newAlbum)); //jAlbumTree.expandPath(path.getParentPath()); // todo: this call doesn't seem to have any effect - jAlbumTree.makeVisible(path); + //jAlbumTree.makeVisible(path); + jAlbumTree.scrollPathToVisible(path); jAlbumTree.setSelectionPath(path); //jAlbumTree.repaint(); @@ -932,10 +939,10 @@ private void jbInit() jMenuFile.setText(GRI18n.getString(MODULE, "menuFile")); - jMenuItemNew.setText(GRI18n.getString(MODULE, "menuNew")); + /*jMenuItemNew.setText(GRI18n.getString(MODULE, "menuNew")); jMenuItemNew.setActionCommand("File.New"); jMenuItemNew.setIcon(GalleryRemote.iNew); - jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, GalleryRemote.ACCELERATOR_MASK)); + jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, GalleryRemote.ACCELERATOR_MASK));*/ jMenuItemOpen.setText(GRI18n.getString(MODULE, "menuOpen")); jMenuItemOpen.setActionCommand("File.Open"); @@ -950,13 +957,13 @@ private void jbInit() jMenuItemSaveAs.setText(GRI18n.getString(MODULE, "menuSaveAs")); jMenuItemSaveAs.setActionCommand("File.SaveAs"); - jMenuItemClose.setText(GRI18n.getString(MODULE, "menuClose")); + /*jMenuItemClose.setText(GRI18n.getString(MODULE, "menuClose")); jMenuItemClose.setActionCommand("File.Close"); if (GalleryRemote.IS_MAC_OS_X) { jMenuItemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, GalleryRemote.ACCELERATOR_MASK)); } else { jMenuItemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, GalleryRemote.ACCELERATOR_MASK)); - } + }*/ jMenuItemQuit.setText(GRI18n.getString(MODULE, "menuQuit")); jMenuItemQuit.setActionCommand("File.Quit"); @@ -1046,11 +1053,11 @@ private void jbInit() jMenuBar1.add(jMenuHelp); } - jMenuFile.add(jMenuItemNew); + //jMenuFile.add(jMenuItemNew); jMenuFile.add(jMenuItemOpen); jMenuFile.add(jMenuItemSave); jMenuFile.add(jMenuItemSaveAs); - jMenuFile.add(jMenuItemClose); + //jMenuFile.add(jMenuItemClose); jMenuFile.addSeparator(); @@ -1100,11 +1107,11 @@ private void jbInitEvents() { jAlbumTree.addTreeSelectionListener(this); jMenuItemPrefs.addActionListener(this); jMenuItemClearCache.addActionListener(this); - jMenuItemNew.addActionListener(this); + //jMenuItemNew.addActionListener(this); jMenuItemOpen.addActionListener(this); jMenuItemSave.addActionListener(this); jMenuItemSaveAs.addActionListener(this); - jMenuItemClose.addActionListener(this); + //jMenuItemClose.addActionListener(this); jMenuItemQuit.addActionListener(this); jMenuItemAbout.addActionListener(this); jMenuItemCut.addActionListener(this); @@ -1207,14 +1214,14 @@ public void actionPerformed(ActionEvent e) { if (command.equals("File.Quit")) { thisWindowClosing(null); - } else if (command.equals("File.New")) { + /*} else if (command.equals("File.New")) { int response = saveOnPermission("OK_toSaveBeforeClose"); if (JOptionPane.CANCEL_OPTION == response) { return; } - resetState(); + resetState();*/ } else if (command.equals("File.Open")) { openState(MRUFileName); } else if (command.equals("File.Save")) { @@ -1226,14 +1233,14 @@ public void actionPerformed(ActionEvent e) { } } else if (command.equals("File.SaveAs")) { saveAsState(); - } else if (command.equals("File.Close")) { + /*} else if (command.equals("File.Close")) { int response = saveOnPermission("OK_toSaveBeforeClose"); if (JOptionPane.CANCEL_OPTION == response) { return; } - resetState(); + resetState();*/ } else if (command.equals("Edit.Cut")) { doCut(); } else if (command.equals("Edit.Copy")) { @@ -1341,7 +1348,7 @@ public String getDescription() { * file). We assume that the UI portion has already asked the user * if this is OK. */ - private void resetState() { + /*private void resetState() { getCurrentGallery().deleteAllPictures(); lastOpenedFile = null; @@ -1351,7 +1358,7 @@ private void resetState() { updateAlbumCombo(); resetUIState(); - } + }*/ private void saveAsState() { @@ -1563,13 +1570,13 @@ public void run() { newGalleries.addElement(gallery); //galleryArray[i].checkTransients(); - gallery.addListDataListener(MainFrame.this); + //gallery.addListDataListener(MainFrame.this); ArrayList pictures = gallery.getAllPictures(); preloadThumbnails(pictures.iterator()); if (pictures.size() > 0) { - gallery.fetchAlbums(jStatusBar, false); + gallery.doFetchAlbums(jStatusBar, false); if (selectGallery == null) { selectGallery = gallery; @@ -1674,7 +1681,7 @@ public void valueChanged(ListSelectionEvent e) { */ public void valueChanged(TreeSelectionEvent e) { //jAlbumTree.treeDidChange(); - updateAlbumCombo(); + updatePicturesList(); jAlbumInspector.setAlbum(getCurrentAlbum()); jInspectorCardLayout.show(jInspectorPanel, CARD_ALBUM); @@ -1700,10 +1707,10 @@ public void contentsChanged(ListDataEvent e) { // the list data changes (and nothing remains to be selected), no // selection change events are fired. updatePicturesList(); - } else if (source instanceof Gallery) { - updateAlbumCombo(); + //} else if (source instanceof Gallery) { + // updateAlbumCombo(); } else if (source instanceof DefaultComboBoxModel) { - updateGalleryParams(); + selectedGalleryChanged(); } else { Log.log(Log.LEVEL_ERROR, MODULE, "Unknown source " + source); } @@ -1876,15 +1883,15 @@ public void treeNodesChanged(TreeModelEvent e) { } public void treeNodesInserted(TreeModelEvent e) { - treeNodesChanged(e); + //treeNodesChanged(e); } public void treeNodesRemoved(TreeModelEvent e) { - treeNodesChanged(e); + //treeNodesChanged(e); } public void treeStructureChanged(TreeModelEvent e) { - treeNodesChanged(e); + //treeNodesChanged(e); } class AlbumTreeRenderer extends DefaultTreeCellRenderer { @@ -1940,12 +1947,12 @@ public Component getTreeCellRendererComponent( } public Dimension getPreferredSize() { - Dimension retDimension = super.getPreferredSize(); + Dimension retDimension = super.getPreferredSize(); - if(retDimension != null) - retDimension = new Dimension((int) (retDimension.width * 1.5 + 15), - retDimension.height); - return retDimension; + if(retDimension != null) + retDimension = new Dimension((int) (retDimension.width * 1.5 + 15), + retDimension.height); + return retDimension; } } @@ -1960,7 +1967,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde gallery = (Gallery) value; } - if (gallery != null && gallery.getAlbumList() != null) { + if (gallery != null && gallery.getRoot() != null) { Font font = getFont().deriveFont(Font.BOLD); setFont(font); //list.setFont(font); diff --git a/com/gallery/GalleryRemote/MoveAlbumDialog.java b/com/gallery/GalleryRemote/MoveAlbumDialog.java index a8cd512..8e1e343 100644 --- a/com/gallery/GalleryRemote/MoveAlbumDialog.java +++ b/com/gallery/GalleryRemote/MoveAlbumDialog.java @@ -31,6 +31,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Vector; +import java.util.Iterator; +import java.util.Enumeration; /** * Description of the Class @@ -44,7 +46,7 @@ public class MoveAlbumDialog extends JDialog Gallery gallery = null; Album album = null; - Album rootAlbum = null; + //Album rootAlbum = null; JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); @@ -57,6 +59,8 @@ public class MoveAlbumDialog extends JDialog JButton jOk = new JButton(); JButton jCancel = new JButton(); + Album newParent = null; + /** * Constructor for the NewAlbumDialog object @@ -85,13 +89,16 @@ private void jbInit() { this.setModal(true); this.setTitle(GRI18n.getString(MODULE, "title")); - Vector albums = new Vector(gallery.getAlbumList()); - rootAlbum = new Album(gallery); - rootAlbum.setSuppressEvents(true); - rootAlbum.setTitle(GRI18n.getString(MODULE, "rootAlbmTitle")); - rootAlbum.setName("root.root"); - albums.add(0, rootAlbum); - albums.remove(album); + Vector albums = new Vector(gallery.getFlatAlbumList()); + //rootAlbum = new Album(gallery); + //rootAlbum.setSuppressEvents(true); + //rootAlbum.setTitle(GRI18n.getString(MODULE, "rootAlbmTitle")); + //rootAlbum.setName("root.root"); + Object rootAlbum = gallery.getRoot(); + if (album.getParentAlbum() == rootAlbum) { + albums.remove(rootAlbum); + } + removeChildren(albums, album); jAlbum = new JComboBox(albums); jAlbum.setFont(UIManager.getFont("Label.font")); @@ -123,6 +130,14 @@ private void jbInit() { getRootPane().setDefaultButton(jOk); } + public void removeChildren(Vector albums, Album album) { + for (Enumeration it = album.children(); it.hasMoreElements();) { + Album subAlbum = (Album) it.nextElement(); + removeChildren(albums, subAlbum); + } + + albums.remove(album); + } /** * Description of the Method @@ -136,15 +151,17 @@ public void actionPerformed(ActionEvent e) { if (command.equals("Cancel")) { setVisible(false); } else if (command.equals("OK")) { - Album newParent = (Album) jAlbum.getSelectedItem(); - if (newParent == rootAlbum) { - newParent = null; - } - - album.moveAlbumTo(GalleryRemote._().getCore().getMainStatusUpdate(), newParent); + newParent = (Album) jAlbum.getSelectedItem(); + //if (newParent == rootAlbum) { + // newParent = null; + //} setVisible(false); } } + + public Album getNewParent() { + return newParent; + } } diff --git a/com/gallery/GalleryRemote/NewAlbumDialog.java b/com/gallery/GalleryRemote/NewAlbumDialog.java index c0d796a..4d406c3 100644 --- a/com/gallery/GalleryRemote/NewAlbumDialog.java +++ b/com/gallery/GalleryRemote/NewAlbumDialog.java @@ -42,10 +42,10 @@ public class NewAlbumDialog extends javax.swing.JDialog implements ActionListener { public final static String MODULE = "NewAlbum"; - Gallery gallery = null; Album defaultAlbum = null; - Album rootAlbum = null; + Album newAlbum = null; + Album parentAlbum = null; JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); @@ -61,7 +61,6 @@ public class NewAlbumDialog extends javax.swing.JDialog JButton jOk = new JButton(); JButton jCancel = new JButton(); GridLayout gridLayout1 = new GridLayout(); - private String newAlbumName; /** @@ -91,18 +90,18 @@ private void jbInit() { this.setModal(true); this.setTitle(GRI18n.getString(MODULE, "title")); - Vector albums = new Vector(gallery.getAlbumList()); - rootAlbum = new Album(gallery); - rootAlbum.setSuppressEvents(true); - rootAlbum.setTitle(GRI18n.getString(MODULE, "rootAlbmTitle")); - rootAlbum.setName("root.root"); - albums.add(0, rootAlbum); + Vector albums = new Vector(gallery.getFlatAlbumList()); + //rootAlbum = new Album(gallery); + //rootAlbum.setSuppressEvents(true); + //rootAlbum.setTitle(GRI18n.getString(MODULE, "rootAlbmTitle")); + //rootAlbum.setName("root.root"); + //albums.add(0, rootAlbum); jAlbum = new JComboBox(albums); jAlbum.setFont(UIManager.getFont("Label.font")); if (defaultAlbum == null) { - jAlbum.setSelectedItem(rootAlbum); + jAlbum.setSelectedItem(gallery.getRoot()); } else { jAlbum.setSelectedItem(defaultAlbum); } @@ -170,34 +169,39 @@ public void actionPerformed(ActionEvent e) { if (command.equals("Cancel")) { setVisible(false); } else if (command.equals("OK")) { - Album a = new Album(gallery); - a.setSuppressEvents(true); - a.setName(jName.getText()); - a.setTitle(jTitle.getText()); - a.setCaption(jDescription.getText()); + newAlbum = new Album(gallery); + //newAlbum.setSuppressEvents(true); + newAlbum.setName(jName.getText()); + newAlbum.setTitle(jTitle.getText()); + newAlbum.setCaption(jDescription.getText()); - a.setSuppressEvents(false); + //newAlbum.setSuppressEvents(false); - Album selectedAlbum = (Album) jAlbum.getSelectedItem(); - if (selectedAlbum == rootAlbum) { - Log.log(Log.LEVEL_TRACE, MODULE, "Selected root album"); - a.setParentAlbum(null); - } else { - a.setParentAlbum(selectedAlbum); - } + parentAlbum = (Album) jAlbum.getSelectedItem(); + parentAlbum.getGallery().insertNodeInto(newAlbum, parentAlbum, parentAlbum.getChildCount()); + //if (selectedAlbum == rootAlbum) { + // Log.log(Log.LEVEL_TRACE, MODULE, "Selected root album"); + // a.setParentAlbum(null); + //} else { + //selectedAlbum.add(newAlbum); + //} - newAlbumName = gallery.newAlbum(a, GalleryRemote._().getCore().getMainStatusUpdate()); + //newAlbumName = gallery.doNewAlbum(newAlbum, GalleryRemote._().getCore().getMainStatusUpdate()); - if (newAlbumName == null) { - newAlbumName = jName.getText(); - } + //if (newAlbumName == null) { + // newAlbumName = jName.getText(); + //} setVisible(false); } } - public String getNewAlbumName() { - return newAlbumName; + public Album getNewAlbum() { + return newAlbum; + } + + public Album getParentAlbum() { + return parentAlbum; } } diff --git a/com/gallery/GalleryRemote/PictureInspector.java b/com/gallery/GalleryRemote/PictureInspector.java index 8118830..37f1493 100644 --- a/com/gallery/GalleryRemote/PictureInspector.java +++ b/com/gallery/GalleryRemote/PictureInspector.java @@ -396,8 +396,8 @@ public void setPictures(Object[] pictures) { jIcon.setText(p.getSource().getName()); jPath.setText(p.getSource().getParent()); } - jAlbum.setText(p.getAlbum().getTitle()); - if (p.getAlbum().getGallery().getComm(mf.jStatusBar).hasCapability(mf.jStatusBar, GalleryCommCapabilities.CAPA_UPLOAD_CAPTION)) { + jAlbum.setText(p.getParentAlbum().getTitle()); + if (p.getParentAlbum().getGallery().getComm(mf.jStatusBar).hasCapability(mf.jStatusBar, GalleryCommCapabilities.CAPA_UPLOAD_CAPTION)) { jCaption.setText(p.getCaption()); jCaption.setEditable(true); jCaption.setBackground(UIManager.getColor("TextField.background")); @@ -420,7 +420,7 @@ public void setPictures(Object[] pictures) { jIcon.setText(GRI18n.getString(MODULE, "countElemSel", params)); jIcon.setIcon(ImageUtils.defaultThumbnail); jPath.setText(""); - jAlbum.setText(p.getAlbum().getTitle()); + jAlbum.setText(p.getParentAlbum().getTitle()); jCaption.setText(""); jCaption.setEditable(false); jCaption.setBackground(UIManager.getColor("TextField.inactiveBackground")); @@ -439,7 +439,7 @@ public void setPictures(Object[] pictures) { } void addExtraFields(Picture p) { - ArrayList newExtraFields = p.getAlbum().getExtraFields(); + ArrayList newExtraFields = p.getParentAlbum().getExtraFields(); if (newExtraFields == null) { removeExtraFields(); diff --git a/com/gallery/GalleryRemote/model/Album.java b/com/gallery/GalleryRemote/model/Album.java index 1ff9299..b144bd3 100644 --- a/com/gallery/GalleryRemote/model/Album.java +++ b/com/gallery/GalleryRemote/model/Album.java @@ -21,11 +21,17 @@ package com.gallery.GalleryRemote.model; import com.gallery.GalleryRemote.*; +import com.gallery.GalleryRemote.prefs.PreferenceNames; import com.gallery.GalleryRemote.util.GRI18n; import com.gallery.GalleryRemote.util.ImageUtils; import com.gallery.GalleryRemote.util.NaturalOrderComparator; import javax.swing.*; +import javax.swing.event.ListDataListener; +import javax.swing.event.EventListenerList; +import javax.swing.event.ListDataEvent; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeNode; import java.awt.*; import java.io.File; import java.io.Serializable; @@ -40,7 +46,7 @@ * @created 11 août 2002 */ -public class Album extends Picture implements ListModel, Serializable { +public class Album extends GalleryItem implements ListModel, Serializable, PreferenceNames { /* ------------------------------------------------------------------------- * CONSTANTS */ @@ -56,10 +62,10 @@ public class Album extends Picture implements ListModel, Serializable { /* ------------------------------------------------------------------------- * SERVER INFO */ - Gallery gallery = null; - ArrayList subAlbums = new ArrayList(); + //Gallery gallery = null; + //ArrayList subAlbums = new ArrayList(); - Album parent; // parent Album + //Album parent; // parent Album String title = GRI18n.getString(MODULE, "title"); String name; ArrayList extraFields; @@ -90,7 +96,9 @@ public class Album extends Picture implements ListModel, Serializable { public Album(Gallery gallery) { - this.gallery = gallery; + super(gallery); + + setAllowsChildren(true); } /** @@ -133,6 +141,7 @@ public void fetchAlbumImages(StatusUpdate su, boolean recursive, int maxPictures } public void removeRemotePictures() { + int l = pictures.size(); for (Iterator it = pictures.iterator(); it.hasNext();) { Picture picture = (Picture) it.next(); if (picture.isOnline()) { @@ -140,7 +149,7 @@ public void removeRemotePictures() { } } - notifyListeners(); + fireContentsChanged(this, 0, l - 1); } public void moveAlbumTo(StatusUpdate su, Album newParent) { @@ -151,9 +160,12 @@ public void moveAlbumTo(StatusUpdate su, Album newParent) { } try { - gallery.getComm(su).moveAlbum(su, this, newParent, false); + if (gallery.getComm(su).moveAlbum(su, this, newParent, false)) { + gallery.removeNodeFromParent(this); + gallery.insertNodeInto(this, newParent, newParent.getChildCount()); + } - gallery.fetchAlbums(su); + //gallery.fetchAlbums(su); } catch (RuntimeException e) { Log.log(Log.LEVEL_INFO, MODULE, "Server probably doesn't support move-album"); Log.logException(Log.LEVEL_INFO, MODULE, e); @@ -187,9 +199,9 @@ public int getServerAutoResize() { * * @param gallery The new gallery */ - public void setGallery(Gallery gallery) { + /*public void setGallery(Gallery gallery) { this.gallery = gallery; - } + }*/ /** * Gets the gallery attribute of the Album object @@ -215,10 +227,11 @@ public Iterator getPictures() { * @param p the picture to add. This will change its parent album */ public void addPicture(Picture p) { - p.setAlbum(this); + p.setParent(this); addPictureInternal(p); - notifyListeners(); + int index = pictures.indexOf(p); + fireIntervalAdded(this, index, index); } /** @@ -227,11 +240,12 @@ public void addPicture(Picture p) { * @param file the file to create the picture from */ public Picture addPicture(File file) { - Picture p = new Picture(file); - p.setAlbum(this); + Picture p = new Picture(gallery, file); + p.setParent(this); addPictureInternal(p); - notifyListeners(); + int index = pictures.indexOf(p); + fireIntervalAdded(this, index, index); return p; } @@ -269,8 +283,8 @@ public ArrayList addPictures(File[] files, int index) { for (Iterator it = expandedFiles.iterator(); it.hasNext();) { File f = (File) it.next(); - Picture p = new Picture(f); - p.setAlbum(this); + Picture p = new Picture(gallery, f); + p.setParent(this); if (index == -1) { addPictureInternal(p); } else { @@ -280,7 +294,7 @@ public ArrayList addPictures(File[] files, int index) { pictures.add(p); } - notifyListeners(); + fireContentsChanged(this, 0, pictures.size() - 1); return pictures; } @@ -297,7 +311,7 @@ public void addPictures(List picturesL) { public void addPictures(List picturesL, int index) { for (Iterator it = picturesL.iterator(); it.hasNext();) { Picture p = (Picture) it.next(); - p.setAlbum(this); + p.setParent(this); if (index == -1) { pictures.add(p); } else { @@ -305,7 +319,7 @@ public void addPictures(List picturesL, int index) { } } - notifyListeners(); + fireContentsChanged(this, 0, pictures.size() - 1); } private void addPictureInternal(Picture p) { @@ -333,11 +347,15 @@ private void addPictureInternal(int index, Picture p) { public void sortPicturesAlphabetically() { Collections.sort(pictures, new NaturalOrderComparator()); - notifyListeners(); + fireContentsChanged(this, 0, pictures.size() - 1); } public void sortSubAlbums() { - Collections.sort(subAlbums, new NaturalOrderComparator()); + if (children != null) { + Collections.sort(children, new NaturalOrderComparator()); + } + + fireContentsChanged(this, 0, pictures.size() - 1); } /** @@ -353,9 +371,11 @@ public int sizePictures() { * Remove all the pictures */ public void clearPictures() { + int l = pictures.size() - 1; + pictures.clear(); - notifyListeners(); + fireIntervalRemoved(this, 0, l); } /** @@ -411,7 +431,7 @@ public Picture getPicture(int n) { public void setPicture(int n, Picture p) { pictures.set(n, p); - notifyListeners(); + fireContentsChanged(this, n, n); } /** @@ -473,7 +493,7 @@ public void setTitle(String title) { this.title = title; if (!suppressEvents) { - gallery.albumChanged(this); + gallery.nodeChanged(this); } } @@ -583,37 +603,18 @@ public Object getElementAt(int index) { * * @param ldl Description of Parameter */ - public Album getParentAlbum() { - return parent; - } - - /** - * Description of the Method - * - * @param ldl Description of Parameter - */ - public void setParentAlbum(Album a) { + /*public void setParent(Album a) { // take care of a Gallery bug... if (a == this) { Log.log(Log.LEVEL_ERROR, MODULE, "Gallery error: the album " + name + " is its own parent. You should delete it, the album database " + "is corrupted because of it."); - a = null; + a = (Album) getRoot(); } - parent = a; - - if (a != null) { - if (!a.subAlbums.contains(this)) { - a.subAlbums.add(this); - } - } else { - if (!gallery.rootAlbums.contains(this)) { - gallery.rootAlbums.add(this); - } - } - } + super.setParent(a); + }*/ public ArrayList getExtraFields() { return extraFields; @@ -716,10 +717,10 @@ void setPicturesList(ArrayList pictures) { this.pictures = pictures; for (Iterator e = pictures.iterator(); e.hasNext();) { - ((Picture) e.next()).setAlbum(this); + ((Picture) e.next()).setParent(this); } - notifyListeners(); + fireContentsChanged(this, 0, pictures.size() - 1); } public int getAlbumDepth() throws IllegalArgumentException { @@ -752,19 +753,45 @@ String indentHelper(String indent) { } } - void notifyListeners() { + /*void notifyListeners() { if (!suppressEvents) { fireContentsChanged(this, 0, pictures.size()); if (gallery != null) { gallery.albumChanged(this); } } - } + }*/ - public ArrayList getSubAlbums() { + /*public ArrayList getSubAlbums() { return subAlbums; + }*/ + + /*public void addSubAlbum(Album a) { + subAlbums.add(a); + + if (!suppressEvents) { + //gallery.fireTreeNodesInserted(this, gallery.getObjectArrayForAlbum(this), + // new int[] { subAlbums.indexOf(a) }, + // new Object[] { a }); + gallery.fireTreeStructureChanged(gallery, gallery.getPathForAlbum(this)); + } } + public void removeSubAlbum(Album a) { + int index = subAlbums.indexOf(a); + if (index != -1) { + subAlbums.remove(a); + + if (!suppressEvents) { + //gallery.fireTreeNodesRemoved(this, gallery.getObjectArrayForAlbum(this), + // new int[] { index }, + // new Object[] { a }); + gallery.fireTreeStructureChanged(gallery, gallery.getPathForAlbum(this)); + //gallery.fireTreeStructureChanged(this, new TreePath(gallery.root)); + } + } + }*/ + public Boolean getOverrideResize() { return overrideResize; } @@ -842,8 +869,67 @@ public void setSuppressEvents(boolean suppressEvents) { this.suppressEvents = suppressEvents; } - /*public void checkTransients() { - subAlbums = new ArrayList(); - }*/ + /* + ******************* LIST HANDLING (FOR PICTURES) *************** + */ + + public void addListDataListener(ListDataListener l) { + if (listenerList == null) listenerList = new EventListenerList(); + listenerList.add(ListDataListener.class, l); + } + + + public void removeListDataListener(ListDataListener l) { + if (listenerList == null) listenerList = new EventListenerList(); + listenerList.remove(ListDataListener.class, l); + } + + public void fireContentsChanged(Object source, int index0, int index1) { + if (listenerList == null) listenerList = new EventListenerList(); + Object[] listeners = listenerList.getListenerList(); + ListDataEvent e = null; + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ListDataListener.class) { + if (e == null) { + e = new ListDataEvent(source, ListDataEvent.CONTENTS_CHANGED, index0, index1); + } + ((ListDataListener) listeners[i + 1]).contentsChanged(e); + } + } + } + + public void fireIntervalAdded(Object source, int index0, int index1) { + if (listenerList == null) listenerList = new EventListenerList(); + Object[] listeners = listenerList.getListenerList(); + ListDataEvent e = null; + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ListDataListener.class) { + if (e == null) { + e = new ListDataEvent(source, ListDataEvent.INTERVAL_ADDED, index0, index1); + } + ((ListDataListener) listeners[i + 1]).intervalAdded(e); + } + } + } + + + public void fireIntervalRemoved(Object source, int index0, int index1) { + if (listenerList == null) listenerList = new EventListenerList(); + Object[] listeners = listenerList.getListenerList(); + ListDataEvent e = null; + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ListDataListener.class) { + if (e == null) { + e = new ListDataEvent(source, ListDataEvent.INTERVAL_REMOVED, index0, index1); + } + ((ListDataListener) listeners[i + 1]).intervalRemoved(e); + } + } + } + + transient protected EventListenerList listenerList = new EventListenerList(); } diff --git a/com/gallery/GalleryRemote/model/Gallery.java b/com/gallery/GalleryRemote/model/Gallery.java index dd4d2d5..12ebc56 100644 --- a/com/gallery/GalleryRemote/model/Gallery.java +++ b/com/gallery/GalleryRemote/model/Gallery.java @@ -26,17 +26,16 @@ import com.gallery.GalleryRemote.prefs.PropertiesFile; import javax.swing.*; -import javax.swing.event.TreeModelListener; +import javax.swing.event.*; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.DefaultMutableTreeNode; import java.io.File; import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; +import java.util.*; import java.awt.*; /** @@ -46,7 +45,7 @@ * @created 17 août 2002 */ -public class Gallery extends GalleryAbstractListModel implements ComboBoxModel, Serializable, PreferenceNames, TreeModel { +public class Gallery extends DefaultTreeModel implements Serializable, PreferenceNames { public static final String MODULE = "Gallery"; String stUrlString = null; @@ -56,11 +55,11 @@ public class Gallery extends GalleryAbstractListModel implements ComboBoxModel, String phpnGalleryUrlString = null; String username; String password; - ArrayList albumList = null; - Album selectedAlbum = null; + //ArrayList albumList = null; + //Album selectedAlbum = null; int type = TYPE_STANDALONE; - Album root = new Album(this); - ArrayList rootAlbums = new ArrayList(); + //Album root = null; + //ArrayList rootAlbums = new ArrayList(); transient GalleryComm comm = null; @@ -78,8 +77,28 @@ public class Gallery extends GalleryAbstractListModel implements ComboBoxModel, public static final int TOSTRING_MAXLEN = 40; public Gallery(StatusUpdate su) { + super(null); this.su = su; + // make sure to update flat album list when tree is changed + addTreeModelListener(new TreeModelListener() { + public void treeNodesChanged(TreeModelEvent e) { + flatAlbumList = null; + } + + public void treeNodesInserted(TreeModelEvent e) { + treeNodesChanged(e); + } + + public void treeNodesRemoved(TreeModelEvent e) { + treeNodesChanged(e); + } + + public void treeStructureChanged(TreeModelEvent e) { + treeNodesChanged(e); + } + }); + // when loading from prefs, galleries not yet created. No matter: in that case, the // prefsIndex is forced. if (GalleryRemote._().getMainFrame() != null) { @@ -91,21 +110,19 @@ public Gallery(StatusUpdate su) { * **** Gallery online management **** */ - public void uploadFiles(StatusUpdate su) { + public void doUploadFiles(StatusUpdate su) { getComm(su).uploadFiles(su, true); } - public void fetchAlbums(StatusUpdate su) { - fetchAlbums(su, true); + public void doFetchAlbums(StatusUpdate su) { + doFetchAlbums(su, true); } - public void fetchAlbums(StatusUpdate su, boolean async) { - //albumList = null; - + public void doFetchAlbums(StatusUpdate su, boolean async) { getComm(su).fetchAlbums(su, async); } - public String newAlbum(Album a, StatusUpdate su) { + public String doNewAlbum(Album a, StatusUpdate su) { Log.log(Log.LEVEL_INFO, MODULE, "Creating new album " + a.toString()); // create album synchronously @@ -121,7 +138,7 @@ public String newAlbum(Album a, StatusUpdate su) { a.setName(newAlbumName); } - addAlbum(a); + //addAlbum(a); return newAlbumName; } @@ -129,23 +146,25 @@ public String newAlbum(Album a, StatusUpdate su) { public void logOut() { boolean logout = true; - albumList = null; - selectedAlbum = null; + //albumList = null; + //selectedAlbum = null; if (comm != null) { comm.logOut(); } comm = null; if (logout) { - albumList = null; - rootAlbums.clear(); - selectedAlbum = null; + //albumList = null; + //rootAlbums.clear(); + //selectedAlbum = null; + setRoot(null); + if (comm != null) { comm.logOut(); } comm = null; - notifyListeners(); + //reload(); } } @@ -153,7 +172,7 @@ public void logOut() { * **** Gallery contents handling **** */ - public void setAlbumList(ArrayList albumList) { + /*public void setAlbumList(ArrayList albumList) { if (albumList == null) { throw new IllegalArgumentException("Must supply non-null album list."); } @@ -183,10 +202,10 @@ public void setAlbumList(ArrayList albumList) { refreshRootAlbums(); - notifyListeners(); - } + reload(); + }*/ - public void refreshRootAlbums() { + /*public void refreshRootAlbums() { rootAlbums.clear(); for (Iterator it = albumList.iterator(); it.hasNext();) { @@ -196,12 +215,12 @@ public void refreshRootAlbums() { rootAlbums.add(album); } } - } + }*/ /** * Adds an album to the gallery and selects the first one added. */ - public synchronized void addAlbum(Album a) { + /*public synchronized void addAlbum(Album a) { if (a == null) { throw new IllegalArgumentException("Must supply non-null album."); } @@ -224,21 +243,47 @@ public synchronized void addAlbum(Album a) { //notifyListeners(); if (a.getParentAlbum() == null) { - fireTreeNodesInserted(this, getObjectArrayForAlbum(root), null, new Object[] { a }); + fireTreeNodesInserted(this, getObjectArrayForAlbum(root), + new int[] { rootAlbums.indexOf(a) }, + new Object[] { a }); } else { - fireTreeNodesInserted(this, getObjectArrayForAlbum(a.getParentAlbum()), null, new Object[] { a }); + fireTreeNodesInserted(this, getObjectArrayForAlbum(a.getParentAlbum()), + new int[] { a.getParentAlbum().subAlbums.indexOf(a) }, + new Object[] { a }); } - } + }*/ + + /*public void addRootAlbum(Album a) { + rootAlbums.add(a); + + //fireTreeNodesInserted(this, new Object[] { root }, + // new int[] { rootAlbums.indexOf(a) }, + // new Object[] { a }); + fireTreeStructureChanged(this, new TreePath(root)); + }*/ - public ArrayList getAlbumList() { + /*public void removeRootAlbum(Album a) { + int index = rootAlbums.indexOf(a); + if (index != -1) { + rootAlbums.remove(a); + + //fireTreeNodesRemoved(this, new Object[] { root }, + // new int[] { index }, + // new Object[] { a }); + //fireTreeStructureChanged(this, getPathForAlbum(a)); + fireTreeStructureChanged(this, new TreePath(root)); + } + }*/ + + /*public ArrayList getAlbumList() { return albumList; } public void clearAlbumList() { albumList.clear(); - notifyListeners(); - } + reload(); + }*/ public File getGalleryDefaultFile() { StringBuffer defaultFilePath = new StringBuffer(); @@ -266,6 +311,7 @@ public ArrayList getAllUploadablePictures() { public ArrayList getAllPictures(boolean onlyUploadable) { ArrayList pictures = new ArrayList(); + ArrayList albumList = getFlatAlbumList(); if (albumList != null) { Iterator i = albumList.iterator(); @@ -285,10 +331,12 @@ public ArrayList getAllPictures(boolean onlyUploadable) { /** * Delete all of the pictures from the current gallery without - * effecting the list of albums that are loaded. This is used + * affecting the list of albums that are loaded. This is used * by the "New" function in the UI. */ public void deleteAllPictures() { + ArrayList albumList = getFlatAlbumList(); + if (albumList != null) { Iterator i = albumList.iterator(); while (i.hasNext()) { @@ -300,6 +348,7 @@ public void deleteAllPictures() { public int countAllPictures() { int c = 0; + ArrayList albumList = getFlatAlbumList(); if (albumList != null) { Iterator i = albumList.iterator(); @@ -314,6 +363,8 @@ public int countAllPictures() { } public boolean hasPictures() { + ArrayList albumList = getFlatAlbumList(); + if (albumList != null) { Iterator i = albumList.iterator(); while (i.hasNext()) { @@ -773,12 +824,12 @@ public static void uncacheAmbiguousUrl() { * * @return */ - public Album getSelectedAlbum() { + /*public Album getSelectedAlbum() { return selectedAlbum; - } + }*/ - public void setSelectedItem(Object anObject) { + /*public void setSelectedItem(Object anObject) { if ((selectedAlbum != null && !selectedAlbum.equals(anObject)) || selectedAlbum == null && anObject != null) { selectedAlbum = (Album) anObject; @@ -786,30 +837,40 @@ public void setSelectedItem(Object anObject) { } } - public Object getSelectedItem() { - return selectedAlbum; - } + public void fireContentsChanged(Object source, int index0, int index1) { + if (listenerList == null) listenerList = new EventListenerList(); + Object[] listeners = listenerList.getListenerList(); + ListDataEvent e = null; - public void albumChanged(Album a) { - // this doesn't seem to be effective to get the JTree itself to update - // but it's useful to get the MainFrame to update the album inspector... - fireTreeNodesChanged(this, getObjectArrayForAlbum(a), null, null); - - // this should update the JTree itself, but clears the tree selection - // so we have to save and restore the selection, which sucks - /*Frame mf = GalleryRemote._().getMainFrame(); - if (mf instanceof MainFrame) { - TreePath sel = ((MainFrame) mf).jAlbumTree.getSelectionPath(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ListDataListener.class) { + if (e == null) { + e = new ListDataEvent(source, ListDataEvent.CONTENTS_CHANGED, index0, index1); + } + ((ListDataListener) listeners[i + 1]).contentsChanged(e); + } + } + } - fireTreeStructureChanged(this, new TreePath(root)); + public Object getSelectedItem() { + return selectedAlbum; + }*/ - ((MainFrame) mf).jAlbumTree.setSelectionPath(sel); - }*/ + /*public void albumChanged(Album a) { + if (a == null) { + fireTreeNodesChanged(this, getObjectArrayForAlbum(root), null, null); + } else { + fireTreeNodesChanged(this, getObjectArrayForAlbum(a), null, null); + } } public void albumStructureChanged(Album a) { - fireTreeStructureChanged(this, getPathForAlbum(a)); - } + if (a == null) { + fireTreeStructureChanged(this, getPathForAlbum(root)); + } else { + fireTreeStructureChanged(this, getPathForAlbum(a)); + } + }*/ /* @@ -841,7 +902,7 @@ public boolean hasComm() { return comm != null; } - void notifyListeners() { + /*void notifyListeners() { //ListDataEvent lde; if (albumList != null) { //lde = new ListDataEvent( this, ListDataEvent.CONTENTS_CHANGED, 0, albumList.size() ); @@ -853,12 +914,12 @@ void notifyListeners() { fireTreeStructureChanged(this, new TreePath(root)); //notifyListeners(lde); - } + }*/ /* * ListModel Implementation */ - public int getSize() { + /*public int getSize() { if (albumList != null) { return albumList.size(); } else { @@ -868,9 +929,21 @@ public int getSize() { public Object getElementAt(int index) { return albumList.get(index); + }*/ + + /*public void addListDataListener(ListDataListener l) { + if (listenerList == null) listenerList = new EventListenerList(); + listenerList.add(ListDataListener.class, l); } + + public void removeListDataListener(ListDataListener l) { + if (listenerList == null) listenerList = new EventListenerList(); + listenerList.remove(ListDataListener.class, l); + }*/ + public Album getAlbumByName(String name) { + ArrayList albumList = getFlatAlbumList(); if (albumList == null || name == null) { return null; } @@ -891,123 +964,26 @@ private void setBlockWrites(boolean blockWrites) { this.blockWrites = blockWrites; } - /********** TreeModel interface **********/ - - /** - * Returns the root of the tree. Returns null - * only if the tree has no nodes. - * - * @return the root of the tree - */ - public Object getRoot() { - return root; - } - - /** - * Returns the number of children of parent. - * Returns 0 if the node - * is a leaf or if it has no children. parent must be a node - * previously obtained from this data source. - * - * @param parent a node in the tree, obtained from this data source - * @return the number of children of the node parent - */ - public int getChildCount(Object parent) { - if (parent == root) { - return rootAlbums.size(); - } else { - return ((Album) parent).getSubAlbums().size(); - } - } - - /** - * Returns true if node is a leaf. - * It is possible for this method to return false - * even if node has no children. - * A directory in a filesystem, for example, - * may contain no files; the node representing - * the directory is not a leaf, but it also has no children. - * - * @param node a node in the tree, obtained from this data source - * @return true if node is a leaf - */ - public boolean isLeaf(Object node) { - if (node == root) { - return rootAlbums.size() == 0; - } else { - return ((Album) node).getSubAlbums().size() == 0; - } - } - - /** - * Returns the child of parent at index index - * in the parent's - * child array. parent must be a node previously obtained - * from this data source. This should not return null - * if index - * is a valid index for parent (that is index >= 0 && - * index < getChildCount(parent)). - * - * @param parent a node in the tree, obtained from this data source - * @return the child of parent at index index - */ - public Object getChild(Object parent, int index) { - if (parent == root) { - return rootAlbums.get(index); - } else { - return ((Album) parent).getSubAlbums().get(index); - } - } - - /** - * Returns the index of child in parent. If parent - * is null or child is null, - * returns -1. - * - * @param parent a note in the tree, obtained from this data source - * @param child the node we are interested in - * @return the index of the child in the parent, or -1 if either - * child or parent are null - */ - public int getIndexOfChild(Object parent, Object child) { - if (parent == root) { - return rootAlbums.indexOf(child); - } else { - return ((Album) parent).getSubAlbums().indexOf(child); + ArrayList flatAlbumList = null; + public ArrayList getFlatAlbumList() { + if (flatAlbumList == null) { + if (getRoot() != null) { + flatAlbumList = Collections.list(((Album) getRoot()).breadthFirstEnumeration()); + } else { + flatAlbumList = null; + } } - } - /** - * Messaged when the user has altered the value for the item identified - * by path to newValue. - * If newValue signifies a truly new value - * the model should post a treeNodesChanged event. - * - * @param path path to the node that the user has altered - * @param newValue the new value from the TreeCellEditor - */ - public void valueForPathChanged(TreePath path, Object newValue) { - Log.log(Log.LEVEL_TRACE, MODULE, "valueForPathChanged"); - Log.logStack(Log.LEVEL_TRACE, MODULE); - //To change body of implemented methods use Options | File Templates. + return flatAlbumList; } - public Object[] getObjectArrayForAlbum(Album album) { - LinkedList path = new LinkedList(); - - path.addFirst(album); - - Album parent = null; - while ((parent = album.getParentAlbum()) != null) { - path.addFirst(parent); - album = parent; + public Album createRootAlbum() { + if (getRoot() != null) { + throw new IllegalStateException("Root album already exists"); } - path.addFirst(root); + setRoot(new Album(this)); - return path.toArray(); - } - public TreePath getPathForAlbum(Album album) { - return new TreePath(getObjectArrayForAlbum(album)); + return (Album) getRoot(); } } \ No newline at end of file diff --git a/com/gallery/GalleryRemote/model/GalleryItem.java b/com/gallery/GalleryRemote/model/GalleryItem.java new file mode 100644 index 0000000..811b4e4 --- /dev/null +++ b/com/gallery/GalleryRemote/model/GalleryItem.java @@ -0,0 +1,106 @@ +/* + * Created by IntelliJ IDEA. + * User: paour + * Date: Feb 25, 2004 + * Time: 7:26:45 PM + */ +package com.gallery.GalleryRemote.model; + +import com.gallery.GalleryRemote.util.HTMLEscaper; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.MutableTreeNode; +import java.util.Vector; + +public abstract class GalleryItem extends DefaultMutableTreeNode implements Cloneable { + public static final String MODULE = "GalleryItem"; + + transient Gallery gallery = null; + String caption = null; + + transient String escapedCaption = null; + + public GalleryItem(Gallery gallery) { + this.gallery = gallery; + } + + public Object clone() { + GalleryItem newGalleryItem = null; + + newGalleryItem = (GalleryItem) super.clone(); + + newGalleryItem.caption = caption; + newGalleryItem.gallery = gallery; + + return newGalleryItem; + } + + public Album getParentAlbum() { + return (Album) getParent(); + } + + /*public void setParentAlbum(Album album) { + setParent(album); + }*/ + + public void setCaption(String caption) { + this.caption = caption; + this.escapedCaption = null; + } + + 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; + } + + /* + ****** Overriden methods from DefaultMutableTreeNode to send notifications ****** + */ + + /*public void insert(MutableTreeNode newChild, int childIndex) { + if (!allowsChildren) { + throw new IllegalStateException("node does not allow children"); + } else if (newChild == null) { + throw new IllegalArgumentException("new child is null"); + } else if (isNodeAncestor(newChild)) { + throw new IllegalArgumentException("new child is an ancestor"); + } + + MutableTreeNode oldParent = (MutableTreeNode) newChild.getParent(); + + if (oldParent != null) { + oldParent.remove(newChild); + } + + newChild.setParent(this); + + if (children == null) { + children = new Vector(); + } + + children.insertElementAt(newChild, childIndex); + gallery.nodesWereInserted(this, new int[] {childIndex}); + } + + public void remove(int childIndex) { + MutableTreeNode child = (MutableTreeNode)getChildAt(childIndex); + children.removeElementAt(childIndex); + //gallery.nodesWereRemoved(this, new int[] {childIndex}, new Object[] {child}); + gallery.nodeStructureChanged(this); + child.setParent(null); + }*/ +} \ No newline at end of file diff --git a/com/gallery/GalleryRemote/model/Picture.java b/com/gallery/GalleryRemote/model/Picture.java index 7bda47b..aa82c46 100644 --- a/com/gallery/GalleryRemote/model/Picture.java +++ b/com/gallery/GalleryRemote/model/Picture.java @@ -40,12 +40,10 @@ * @author paour * @created 11 août 2002 */ -public class Picture extends GalleryAbstractListModel implements Serializable, PreferenceNames, Cloneable { +public class Picture extends GalleryItem implements Serializable, PreferenceNames, Cloneable { public static final String MODULE = "Picture"; File source = null; - String caption = null; - Album album = null; HashMap extraFields; @@ -65,13 +63,15 @@ public class Picture extends GalleryAbstractListModel implements Serializable, P int indexOnServer = -1; transient double fileSize = 0; - transient String escapedCaption = null; transient int indexCache = -1; /** * Constructor for the Picture object */ - public Picture() { + public Picture(Gallery gallery) { + super(gallery); + + setAllowsChildren(false); } @@ -80,38 +80,39 @@ public Picture() { * * @param source File the Picture is based on */ - public Picture(File source) { + public Picture(Gallery gallery, File source) { + this(gallery); + setSource(source); } public Object clone() { - Picture clone = new Picture(); - clone.source = source; - clone.caption = caption; - clone.album = album; + Picture newPicture = (Picture) super.clone(); + + newPicture.source = source; - clone.extraFields = extraFields; + newPicture.extraFields = extraFields; - clone.angle = angle; - clone.flipped = flipped; - clone.suppressServerAutoRotate = suppressServerAutoRotate; + newPicture.angle = angle; + newPicture.flipped = flipped; + newPicture.suppressServerAutoRotate = suppressServerAutoRotate; - clone.online = online; - clone.urlFull = urlFull; - clone.sizeFull = sizeFull; - clone.urlResized = urlResized; - clone.sizeResized = sizeResized; - clone.urlThumbnail = urlThumbnail; - clone.sizeThumbnail = sizeThumbnail; + newPicture.online = online; + newPicture.urlFull = urlFull; + newPicture.sizeFull = sizeFull; + newPicture.urlResized = urlResized; + newPicture.sizeResized = sizeResized; + newPicture.urlThumbnail = urlThumbnail; + newPicture.sizeThumbnail = sizeThumbnail; - clone.fileSize = fileSize; - clone.escapedCaption = escapedCaption; - clone.indexCache = indexCache; + newPicture.fileSize = fileSize; + newPicture.escapedCaption = escapedCaption; + newPicture.indexCache = indexCache; - clone.albumOnServer = albumOnServer; - clone.indexOnServer = indexOnServer; + newPicture.albumOnServer = albumOnServer; + newPicture.indexOnServer = indexOnServer; - return clone; + return newPicture; } @@ -146,10 +147,6 @@ public void setSource(File source) { * * @param caption The new caption value */ - public void setCaption(String caption) { - this.caption = caption; - this.escapedCaption = null; - } /** @@ -157,9 +154,9 @@ public void setCaption(String caption) { * * @param album The new album value */ - public void setAlbum(Album album) { + /*public void setAlbum(Album album) { this.album = album; - } + }*/ /** @@ -183,6 +180,7 @@ public File getSource() { */ public File getUploadSource() { File picture = getSource(); + Album album = getParentAlbum(); if (album.getResize()) { Dimension d = album.getResizeDimension(); @@ -225,30 +223,6 @@ public File getUploadSource() { return picture; } - /** - * Gets the caption attribute of the Picture object - * - * @return The caption value - */ - 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 * @@ -276,9 +250,9 @@ public void setFileSize(double fileSize) { * * @return The album */ - public Album getAlbum() { + /*public Album getAlbum() { return album; - } + }*/ public String toString() { if (online) { @@ -341,7 +315,7 @@ public String getExtraFieldsString() { StringBuffer sb = new StringBuffer(); String sep = System.getProperty("line.separator"); - for (Iterator it = album.getExtraFields().iterator(); it.hasNext();) { + for (Iterator it = getParentAlbum().getExtraFields().iterator(); it.hasNext();) { String name = (String) it.next(); String value = (String) extraFields.get(name); @@ -495,6 +469,7 @@ public int getIndexOnServer() { } public int getIndex() { + Album album = getParentAlbum(); if (indexCache == -1 || indexCache >= album.pictures.size() || album.pictures.get(indexCache) != this) { diff --git a/defaults.properties b/defaults.properties index 59ee7f7..d367dfe 100644 --- a/defaults.properties +++ b/defaults.properties @@ -178,6 +178,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p # # --- Do not edit below this line --- # -version=1.3.2-b6 -releaseDate=2004/02/25 +version=1.4-b1 +releaseDate=2004/02/26 aboutText=Gallery Remote\n \n \nA part of the Gallery Open-Source Project\nhttp://gallery.sourceforge.net\n \n \nMaintained by:\n \nPierre-Luc Paour\n \n \nInitial version by Chris Smith\n \n \nContributors:\n \nTim Miller\nDolan Halbrook\nMarkus Cozowicz\nScott Gartner\nAmedeo Paglione\nChris Schwerdt\n \n \nArtwork by Ross A. Reyman\n \n \nBundled software:\n \nImageMagick\nJSX\nJava look and feel Graphics Repository icons\njpegtran, Guido Vollbeding's version\nMetadataExtractor