Skip to content

Commit

Permalink
2003-11-03 Pierre-Luc Paour <gallery@paour.com> (1.2-b13)
Browse files Browse the repository at this point in the history
	* Better memory management for thumbnails and previews. Memory errors
	  should be rarer, and thumbnail/preview generation should be quicker.
	* Added button to sort files alphabetically in an album.
	* GR should now find jpegtran and ImageMagick in that if they are
	  available in the PATH on non-Windows platforms. Added a long-winded
	  warning at the tail-end of the installer about how to install them.
  • Loading branch information
Pierre-Luc Paour committed Nov 4, 2003
1 parent 31cc2c5 commit 2a37313
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 208 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
2003-11-03 Pierre-Luc Paour <gallery@paour.com> (1.2-b13)

* Better memory management for thumbnails and previews. Memory errors
should be rarer, and thumbnail/preview generation should be quicker.
* Added button to sort files alphabetically in an album.
* GR should now find jpegtran and ImageMagick in that if they are
available in the PATH on non-Windows platforms. Added a long-winded
warning at the tail-end of the installer about how to install them.

2003-10-30 Pierre-Luc Paour <gallery@paour.com> (1.2-b12)

* Added warning when logging out or quitting and pictures are left in
Expand Down
2 changes: 2 additions & 0 deletions com/gallery/GalleryRemote/GalleryComm2.java
Expand Up @@ -530,6 +530,8 @@ public void actionPerformed(ActionEvent e) {
GalleryRemote.getInstance().mainFrame.shutdown(true);
}
}

GalleryRemote.getInstance().mainFrame.flushMemory();
} else {
su.stopProgress(StatusUpdate.LEVEL_UPLOAD_PROGRESS, grRes.getString(MODULE, "upFailed"));
}
Expand Down
50 changes: 24 additions & 26 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -101,6 +101,7 @@ public class MainFrame extends javax.swing.JFrame
PictureInspector jPictureInspector = new PictureInspector();
JButton jUploadButton = new JButton();
JButton jBrowseButton = new JButton();
JButton jSortButton = new JButton();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuItemQuit = new JMenuItem();
JMenuItem jMenuItemSave = new JMenuItem();
Expand Down Expand Up @@ -334,6 +335,7 @@ public void run() {
&& getCurrentAlbum().sizePictures() > 0
&& !inProgress
&& jAlbumCombo.getSelectedIndex() >= 0 );
jSortButton.setEnabled(jUploadButton.isEnabled());

Gallery currentGallery = getCurrentGallery();

Expand Down Expand Up @@ -536,6 +538,14 @@ public void uploadPictures() {
}


/**
* Sort the files alphabetically
*/
public void sortPictures() {
getCurrentAlbum().sortPicturesAlphabetically();
}


/**
* Fetch Albums from server and update UI
*/
Expand Down Expand Up @@ -794,16 +804,19 @@ private void jbInit()
jNewAlbumButton.setActionCommand( "NewAlbum" );
jNewAlbumButton.setIcon(iNewAlbum);
jPanel3.setLayout( gridLayout1 );
jUploadButton.setAlignmentX( (float) 2.0 );
//jUploadButton.setAlignmentX( (float) 2.0 );
jUploadButton.setText( grRes.getString(MODULE, "upldBtnTxt") );
jUploadButton.setActionCommand( "Upload" );
jUploadButton.setToolTipText( grRes.getString(MODULE, "upldBtnTip") );
jInspectorDivider.setBorder( new TitledBorder( BorderFactory.createEtchedBorder( Color.white, new Color( 148, 145, 140 ) ), grRes.getString(MODULE, "inspDvdr") ) );
jPanel1.setBorder( new TitledBorder( BorderFactory.createEtchedBorder( Color.white, new Color( 148, 145, 140 ) ), grRes.getString(MODULE, "panel1")) );
jBrowseButton.setAlignmentX( (float) 1.0 );
//jBrowseButton.setAlignmentX( (float) 1.0 );
jBrowseButton.setText( grRes.getString(MODULE, "brwsBtnTxt"));
jBrowseButton.setActionCommand( "Browse" );
jBrowseButton.setToolTipText(grRes.getString(MODULE, "brwsBtnTip"));
jSortButton.setText(grRes.getString(MODULE, "sortBtnTxt"));
jSortButton.setActionCommand( "Sort" );
jSortButton.setToolTipText(grRes.getString(MODULE, "sortBtnTip"));
jGalleryCombo.setActionCommand("Url");
jGalleryCombo.setToolTipText(grRes.getString(MODULE, "gllryCombo"));
gridLayout1.setHgap( 5 );
Expand Down Expand Up @@ -849,6 +862,7 @@ private void jbInit()
this.getContentPane().add( jPanel3, new GridBagConstraints( 0, 2, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 5, 5, 5, 5 ), 0, 0 ) );
jPanel3.add( jBrowseButton, null );
jPanel3.add( jSortButton, null);
jPanel3.add( jUploadButton, null );
this.getContentPane().add( jStatusBar, new GridBagConstraints( 0, 3, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 0, 0, 0, 0 ), 0, 0 ) );
Expand Down Expand Up @@ -902,6 +916,7 @@ private void jbInitEvents() {
jLoginButton.addActionListener( this );
jNewAlbumButton.addActionListener( this );
jUploadButton.addActionListener( this );
jSortButton.addActionListener( this );
jBrowseButton.addActionListener( this );
jNewGalleryButton.addActionListener( this );
//jGalleryCombo.addActionListener( this );
Expand Down Expand Up @@ -963,13 +978,6 @@ public void actionPerformed( ActionEvent e ) {
if (getCurrentGallery().hasComm() && getCurrentGallery().getComm(jStatusBar).isLoggedIn()) {
// we're currently logged in: log out
getCurrentGallery().logOut();
//if (getCurrentAlbum() != null) {
// getCurrentAlbum().clearPictures();
//}
//setCurrentAlbum(null);

//jAlbumCombo.setModel(new Gallery(this));
//resetUIState();
} else {
// login may have failed and caused getComm to be null.
GalleryComm comm = getCurrentGallery().getComm(jStatusBar);
Expand All @@ -985,25 +993,10 @@ public void actionPerformed( ActionEvent e ) {
browseAddPictures();
} else if ( command.equals( "Upload" ) ) {
uploadPictures();
} else if ( command.equals( "Sort" ) ) {
sortPictures();
} else if ( command.equals( "NewGallery" ) ) {
showPreferencesDialog(URLPanel.class.getName());
//} else if ( command.equals( "Url" ) ) {
//Object selectedGallery = jGalleryCombo.getSelectedItem();
//if (selectedGallery != null) {
//Log.log(Log.TRACE, MODULE, "selected: " + selectedGallery.toString()
// + " (" + jGalleryCombo.getSelectedIndex() + ")");

// new url chosen in the popup
// updateGalleryParams();
// } else {
// Log.log(Log.TRACE, MODULE, "Deselected gallery");
// }
//} else if ( command.equals( "Album" ) ) {
//Object selectedAlbum = jAlbumCombo.getSelectedItem();
// Log.log(Log.TRACE, MODULE, "selected: " + selectedAlbum.toString()
// + " (" + jAlbumCombo.getSelectedIndex() + ")");

//updatePicturesList( /*(Album) ( (JComboBox) e.getSource() ).getSelectedItem()*/);
} else {
Log.log(Log.LEVEL_ERROR, MODULE, "Unhandled command " + command );
}
Expand Down Expand Up @@ -1275,6 +1268,11 @@ private void macOSXRegistration() {
}
}

public void flushMemory() {
thumbnailCache.flushMemory();
previewFrame.flushMemory();
}

/**
* Cell renderer
*
Expand Down
47 changes: 38 additions & 9 deletions com/gallery/GalleryRemote/PreviewFrame.java
Expand Up @@ -28,8 +28,7 @@
import java.awt.Graphics;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Hashtable;
import java.util.Vector;
import java.util.*;

import javax.swing.ImageIcon;

Expand All @@ -52,7 +51,7 @@ public void initComponents() {

addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
imageIcons.clear();
flushMemory();
}
});

Expand All @@ -68,6 +67,18 @@ public void paint(Graphics g) {
}
}

public void hide() {
// release memory if no longer necessary
flushMemory();
super.hide();

displayFile(null);
}

public void flushMemory() {
imageIcons.clear();
}

public void displayFile(Picture picture) {
if (picture == null) {
currentImage = null;
Expand Down Expand Up @@ -146,8 +157,8 @@ public void loadPreview(String filename) {
}


public class SmartHashtable extends Hashtable {
Vector touchOrder = new Vector();
public class SmartHashtable extends HashMap {
ArrayList touchOrder = new ArrayList();

public Object put(Object key, Object value) {
touch(key);
Expand All @@ -169,18 +180,37 @@ public Object put(Object key, Object value) {
}

public Object get(Object key) {
return get(key, true);
}

public Object get(Object key, boolean touch) {
Object result = super.get(key);

if (result != null) {
if (result != null && touch) {
touch(key);
}

return result;
}

public void clear() {
Log.log(Log.LEVEL_TRACE, MODULE, Runtime.getRuntime().freeMemory() + " - " + Runtime.getRuntime().totalMemory());

// flush images before clearing hastables for quicker deletion
Iterator it = values().iterator();
while (it.hasNext()) {
ImageIcon i = (ImageIcon) it.next();
if (i != null) {
i.getImage().flush();
}
}

super.clear();
touchOrder.clear();

Runtime.getRuntime().gc();

Log.log(Log.LEVEL_TRACE, MODULE, Runtime.getRuntime().freeMemory() + " - " + Runtime.getRuntime().totalMemory());
}

public void touch(Object key) {
Expand All @@ -201,13 +231,12 @@ public void shrink() {
return;
}

Object key = touchOrder.elementAt(0);
Object key = touchOrder.get(0);
touchOrder.remove(0);

ImageIcon i = (ImageIcon) get(key);
ImageIcon i = (ImageIcon) get(key, false);
if (i != null) {
i.getImage().flush();
i = null;
}

remove(key);
Expand Down
16 changes: 12 additions & 4 deletions com/gallery/GalleryRemote/ThumbnailCache.java
Expand Up @@ -21,9 +21,7 @@
package com.gallery.GalleryRemote;

import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Stack;
import java.util.*;

import javax.swing.ImageIcon;

Expand All @@ -45,7 +43,7 @@ public class ThumbnailCache implements Runnable

boolean stillRunning = false;
Stack toLoad = new Stack();
Hashtable thumbnails = new Hashtable();
HashMap thumbnails = new HashMap();
MainFrame mf;


Expand Down Expand Up @@ -187,6 +185,16 @@ public void reload() {
preloadThumbnailFilenames(e);
}

public void flushMemory() {
Iterator it = thumbnails.values().iterator();
while (it.hasNext()) {
ImageIcon i = (ImageIcon) it.next();
i.getImage().flush();
}

thumbnails.clear();
}


void rerun() {
if ( !stillRunning && GalleryRemote.getInstance().properties.getShowThumbnails() ) {
Expand Down
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/UploadProgress.java
Expand Up @@ -139,6 +139,7 @@ public void stopProgress(int level, String message) {
} catch (Throwable t) {}

if (level == LEVEL_UPLOAD_PROGRESS) {
// we're done...
setVisible(false);
//dispose();
}
Expand Down
6 changes: 6 additions & 0 deletions com/gallery/GalleryRemote/model/Album.java
Expand Up @@ -29,6 +29,7 @@
import com.gallery.GalleryRemote.*;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.util.GRI18n;
import com.gallery.GalleryRemote.util.NaturalOrderComparator;

/**
* Album model
Expand Down Expand Up @@ -225,6 +226,11 @@ private void addPictureInternal(int index, Picture p) {
}
}

public void sortPicturesAlphabetically() {
Collections.sort(pictures, new NaturalOrderComparator());
notifyListeners();
}

/**
* Number of pictures in the album
*
Expand Down
6 changes: 4 additions & 2 deletions com/gallery/GalleryRemote/resources/GRResources.properties
Expand Up @@ -19,6 +19,8 @@ MainFrame.inspDvdr = Pictures to Upload (Drag and Drop files into this panel)
MainFrame.panel1 = Destination Gallery
MainFrame.brwsBtnTxt = Add pictures...
MainFrame.brwsBtnTip = Find images to add to the currently selected album. This button is disabled, if the currently selected album is read-only or you're not logged in.
MainFrame.sortBtnTxt = Sort pictures...
MainFrame.sortBtnTip = Sort the pictures in the current album alphabetically.
MainFrame.gllryCombo = Select a Gallery to which you want to log in
MainFrame.menuFile = File
MainFrame.menuQuit = Quit
Expand Down Expand Up @@ -309,8 +311,8 @@ PictInspec.upBtnTip = Move selected picture up
PictInspec.upBtn = Move up
PictInspec.dnBtnTip = Move selected picture down
PictInspec.dnBtn = Move down
PictInspec.delBtnTip = Remove selected picture(s) from the album
PictInspec.Delete = Delete
PictInspec.delBtnTip = Remove selected picture(s) from the album (doesn't delete the file on disk)
PictInspec.Delete = Remove
PictInspec.icon = icon
PictInspec.rotLtTip = Rotate the selected picture(s) 90° counter-clockwise
PictInspec.rotRtTip = Rotate the selected picture(s) 90° clockwise
Expand Down

0 comments on commit 2a37313

Please sign in to comment.