Skip to content

Commit

Permalink
2005-12-22 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b8)
Browse files Browse the repository at this point in the history
	* Fixed slideshow threading issues.
  • Loading branch information
Pierre-Luc Paour committed Dec 22, 2005
1 parent e81e9bf commit b06876e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 60 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2005-12-22 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b8)

* Fixed slideshow threading issues.

2005-12-18 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b7)

* Explicitly disabling keep-alive for the GR protocol
Expand Down
70 changes: 31 additions & 39 deletions com/gallery/GalleryRemote/PreviewFrame.java
Expand Up @@ -41,9 +41,9 @@ public class PreviewFrame extends JFrame implements PreferenceNames {
public static final String MODULE = "PreviewFrame";

SmartHashtable imageIcons = new SmartHashtable();
ImageIcon currentImage = null;
Picture loadPicture = null;
Picture currentPicture = null;
ImageIcon imageShowNow = null;
Picture pictureShowWant = null;
Picture pictureShowNow = null;
PreviewLoader previewLoader = new PreviewLoader();
int previewCacheSize = 10;
boolean ignoreIMFailure = false;
Expand Down Expand Up @@ -82,40 +82,33 @@ public void hide() {

public void flushMemory() {
imageIcons.clear();
if (currentPicture != null) {
loadPicture = null;
currentImage = null;
displayPicture(currentPicture, true);
currentPicture = null;
if (pictureShowNow != null) {
pictureShowWant = null;
imageShowNow = null;
displayPicture(pictureShowNow, true);
pictureShowNow = null;
}
}

public void displayPicture(Picture picture, boolean async) {
if (picture == null) {
loadPicture = null;
pictureShowWant = null;
imageRect = null;

pictureReady(null, null);
} else {
//String filename = picture.getSource().getPath();

if (picture != loadPicture) {
//currentImageFile = filename;
loadPicture = picture;
if (picture != pictureShowWant) {
pictureShowWant = picture;

ImageIcon r = (ImageIcon) imageIcons.get(picture);
if (r != null) {
Log.log(Log.LEVEL_TRACE, MODULE, "Cache hit: " + picture);
//currentImage = r;
//currentPicture = picture;
pictureReady(r, picture);
} else {
Log.log(Log.LEVEL_TRACE, MODULE, "Cache miss: " + picture);
if (async) {
previewLoader.loadPreview(picture, true);
} else {
//currentImage = getSizedIconForce(picture);
//currentPicture = picture;
ImageIcon sizedIcon = getSizedIconForce(picture);
if (sizedIcon != null) {
pictureReady(sizedIcon, picture);
Expand Down Expand Up @@ -172,11 +165,10 @@ public void paintComponent(Graphics g) {
g.setColor(getBackground());
}
g.fillRect(0, 0, getSize().width, getSize().height);
//g.clearRect(0, 0, getSize().width, getSize().height);

if (currentImage != null && loadPicture != null) {
ImageIcon tmpImage = ImageUtils.rotateImageIcon(currentImage, loadPicture.getAngle(),
loadPicture.isFlipped(), this);
if (imageShowNow != null && pictureShowWant != null) {
ImageIcon tmpImage = ImageUtils.rotateImageIcon(imageShowNow, pictureShowWant.getAngle(),
pictureShowWant.isFlipped(), this);

imageRect = new Rectangle(getLocation().x + (getWidth() - tmpImage.getIconWidth()) / 2,
getLocation().y + (getHeight() - tmpImage.getIconHeight()) / 2,
Expand Down Expand Up @@ -326,8 +318,8 @@ public void shrink() {
}

public void pictureReady(ImageIcon image, Picture picture) {
currentImage = image;
currentPicture = picture;
imageShowNow = image;
pictureShowNow = picture;
repaint();
}

Expand Down Expand Up @@ -370,20 +362,20 @@ public CropGlassPane() {
public void paint(Graphics g) {
oldRect = null;

if (localCurrentPicture != currentPicture) {
if (localCurrentPicture != pictureShowNow) {
cacheRect = null;
localCurrentPicture = currentPicture;
localCurrentPicture = pictureShowNow;
}

if (currentPicture == null || currentImage == null || currentPicture.isOnline()) {
if (pictureShowNow == null || imageShowNow == null || pictureShowNow.isOnline()) {
cacheRect = null;
return;
}

if (imageRect != null && start != null && end != null) {
Rectangle ct = currentPicture.getCropTo();
Rectangle ct = pictureShowNow.getCropTo();
if (ct != null) {
AffineTransform t = ImageUtils.createTransform(getBounds(), imageRect, currentPicture.getDimension(), currentPicture.getAngle(), currentPicture.isFlipped());
AffineTransform t = ImageUtils.createTransform(getBounds(), imageRect, pictureShowNow.getDimension(), pictureShowNow.getAngle(), pictureShowNow.isFlipped());

try {
cacheRect = getRect(t.inverseTransform(ct.getLocation(), null),
Expand Down Expand Up @@ -419,7 +411,7 @@ public void paint(Graphics g) {
public void paintInfo(Graphics g) {
String message = null;

Rectangle cropTo = currentPicture.getCropTo();
Rectangle cropTo = pictureShowNow.getCropTo();
if (! inDrag) {
if (cropTo == null) {
message = GRI18n.getString(MODULE, "noCrop");
Expand Down Expand Up @@ -454,11 +446,11 @@ public void updateRect() {
}

public void mouseClicked(MouseEvent e) {
if (currentPicture == null) {
if (pictureShowNow == null) {
return;
}

currentPicture.setCropTo(null);
pictureShowNow.setCropTo(null);
cacheRect = null;
repaint();
}
Expand All @@ -468,7 +460,7 @@ public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {
if (currentPicture == null || imageRect == null || currentPicture.isOnline()) {
if (pictureShowNow == null || imageRect == null || pictureShowNow.isOnline()) {
return;
}

Expand Down Expand Up @@ -510,25 +502,25 @@ public void mousePressed(MouseEvent e) {
break;
}

currentPicture.setCropTo(null);
pictureShowNow.setCropTo(null);
repaint();
}

public void mouseReleased(MouseEvent e) {
inDrag = false;
centerMode = false;

if (currentPicture == null || oldRect == null || currentPicture.isOnline()) {
if (pictureShowNow == null || oldRect == null || pictureShowNow.isOnline()) {
return;
}

AffineTransform t = ImageUtils.createTransform(getBounds(), imageRect, currentPicture.getDimension(), currentPicture.getAngle(), currentPicture.isFlipped());
//currentPicture.setCropTo(getRect(t.transform(start, null), t.transform(end, null)));
AffineTransform t = ImageUtils.createTransform(getBounds(), imageRect, pictureShowNow.getDimension(), pictureShowNow.getAngle(), pictureShowNow.isFlipped());
//pictureShowNow.setCropTo(getRect(t.transform(start, null), t.transform(end, null)));

Rectangle tmpRect = new Rectangle();
tmpRect.setFrameFromDiagonal(t.transform(oldRect.getLocation(), null),
t.transform(new Point(oldRect.x + oldRect.width, oldRect.y + oldRect.height), null));
currentPicture.setCropTo(tmpRect);
pictureShowNow.setCropTo(tmpRect);

setCursor(Cursor.getDefaultCursor());

Expand Down Expand Up @@ -629,7 +621,7 @@ public void mouseDragged(MouseEvent e) {
}

public void mouseMoved(MouseEvent e) {
if (currentPicture == null || currentImage == null || currentPicture.isOnline() || cacheRect == null) {
if (pictureShowNow == null || imageShowNow == null || pictureShowNow.isOnline() || cacheRect == null) {
movingEdge = 0;
setCursor(Cursor.getDefaultCursor());
return;
Expand Down
58 changes: 39 additions & 19 deletions com/gallery/GalleryRemote/SlideshowFrame.java
Expand Up @@ -45,6 +45,7 @@ public class SlideshowFrame extends PreviewFrame
String progress = null;
String extra = null;
String url = null;
String skipping = null;

public static final int STATE_NONE = 0;
public static final int STATE_DOWNLOADING = 1;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void showSlideshow() {
// unfortunately, this doesn't work on Mac 1.4.2...
// gd.setFullScreenWindow(this);
} else {*/
DialogUtil.maxSize(this);
DialogUtil.maxSize(this);
//setBounds(600, 100, 500, 500);
setVisible(true);
//}
Expand Down Expand Up @@ -192,7 +193,7 @@ public void keyPressed(KeyEvent e) {
}
updateFeedback(FEEDBACK_PAUSE_PLAY);

updateProgress(currentPicture, STATE_NONE);
updateProgress(pictureShowNow, STATE_NONE);

break;
}
Expand Down Expand Up @@ -283,13 +284,26 @@ public void run() {
}

public boolean next(boolean user) {
if (loadPicture != null && wantDownloaded.contains(loadPicture) && (loadPicture != userPicture || user)) {
if (pictureShowWant != null && wantDownloaded.contains(pictureShowWant) && (pictureShowWant != userPicture || user)) {
// we no longer want the current picture
wantDownloaded.remove(loadPicture);
wantDownloaded.remove(pictureShowWant);
}

Picture picture;
if (userPicture != null && !user) {
// automatic move trying to move away from user-chosen picture
// add delay to prevent endless loop
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
return true;
}
synchronized(this) {
if (userPicture != null && !user) {
// don't delay in critical section
return true;
}

wantIndex++;

if (wantIndex >= pictures.size()) {
Expand Down Expand Up @@ -320,14 +334,6 @@ public boolean next(boolean user) {
Log.log(Log.LEVEL_TRACE, MODULE, "User skipped again, not even loading " + picture);
return true;
}
} else if (userPicture != null && userPicture != picture) {
// automatic move trying to move away from user-chosen picture

// add delay to prevent endless loop
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
return true;
}

wantDownloaded.add(picture);
Expand All @@ -344,9 +350,9 @@ public boolean next(boolean user) {
}

public boolean previous(boolean user) {
if (loadPicture != null && wantDownloaded.contains(loadPicture) && (loadPicture != userPicture || user)) {
if (pictureShowWant != null && wantDownloaded.contains(pictureShowWant) && (pictureShowWant != userPicture || user)) {
// we no longer want the current picture
wantDownloaded.remove(loadPicture);
wantDownloaded.remove(pictureShowWant);
}

Picture picture;
Expand Down Expand Up @@ -404,9 +410,9 @@ public void pictureReady(ImageIcon image, Picture picture) {
userPicture = null;
}

if (picture != loadPicture) {
Log.log(Log.LEVEL_TRACE, MODULE, "We wanted " + loadPicture + ": ignoring");
updateProgress(loadPicture, STATE_NEXTREADY);
if (picture != pictureShowWant) {
Log.log(Log.LEVEL_TRACE, MODULE, "We wanted " + pictureShowWant + ": ignoring");
updateProgress(pictureShowWant, STATE_NEXTREADY);
return;
}

Expand All @@ -432,13 +438,13 @@ public void pictureReady(ImageIcon image, Picture picture) {
}

public void pictureStartDownload(Picture picture) {
if (picture == loadPicture || picture == userPicture) {
if (picture == pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_DOWNLOADING);
}
}

public void pictureStartProcessing(Picture picture) {
if (picture == loadPicture || picture == userPicture) {
if (picture == pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_PROCESSING);
}
}
Expand Down Expand Up @@ -475,6 +481,7 @@ private void updateProgress(Picture picture, int state) {

case STATE_SKIPPING:
progress = GRI18n.getString(MODULE, "skipping", params);
skipping = GRI18n.getString(MODULE, "skippingController", params);
break;
}

Expand Down Expand Up @@ -602,12 +609,16 @@ public void paint(Graphics g) {

if (feedback != FEEDBACK_NONE || controllerUntil > System.currentTimeMillis()) {
paintController(g);
} else {
skipping = null;
}

paintInfo(g);
}

private void paintController(Graphics g) {
Log.log(Log.LEVEL_TRACE, MODULE, "paintController");

Dimension d = getSize();
int width = 475;
int height = 150;
Expand Down Expand Up @@ -659,6 +670,15 @@ private void paintController(Graphics g) {
g.fillPolygon(new int[] {x, x, x + 30, x + 70, x + 100, x + 100, x + 70, x + 30},
new int[] {y + 55, y + 95, y + 125, y + 125, y + 95, y + 55, y + 25, y + 25}, 8);
drawText(g, hilight, fm, x + 50, y + 160, GRI18n.getString(MODULE, "controller.escape"));

if (skipping != null) {
x = d.width / 2;
g.setFont(g.getFont().deriveFont(48.0F));
fm = g.getFontMetrics();
g.setColor(hilight);
Rectangle2D bounds = fm.getStringBounds(skipping, g);
g.drawString(skipping, (int) (x - bounds.getWidth() / 2), y + 210);
}
}

public void paintInfo(Graphics g) {
Expand Down
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/resources/GRResources.properties
Expand Up @@ -522,6 +522,7 @@ SlideFrame.paused = Showing {0} ({1, number, integer} / {2, number, integer}) (p
SlideFrame.downloading = Downloading picture {0} ({1, number, integer} / {2, number, integer})
SlideFrame.processing = Processing picture {0} ({1, number, integer} / {2, number, integer})
SlideFrame.skipping = Skipping to {0} ({1, number, integer} / {2, number, integer})
SlideFrame.skippingController = {1, number, integer} / {2, number, integer}
SlideFrame.controller.left = Left arrow
SlideFrame.controller.right = Right arrow
SlideFrame.controller.mousewheel = Mouse wheel
Expand Down
4 changes: 2 additions & 2 deletions defaults.properties
Expand Up @@ -308,6 +308,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p
#
# --- Do not edit below this line ---
#
version=1.5.1-b7
releaseDate=2005/12/18
version=1.5.1-b8
releaseDate=2005/12/22
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\nSeth Ladd\n \n \nArtwork by Ross A. Reyman\n \n \nBundled software:\n \nImageMagick\nJava look and feel Graphics Repository icons\njpegtran, Guido Vollbeding's version\nMetadataExtractor

0 comments on commit b06876e

Please sign in to comment.