From b06876ef2ce9f14d39c64a0dfd87fe9e3898335e Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Thu, 22 Dec 2005 09:35:17 +0000 Subject: [PATCH] 2005-12-22 Pierre-Luc Paour (1.5.1-b8) * Fixed slideshow threading issues. --- ChangeLog | 4 ++ com/gallery/GalleryRemote/PreviewFrame.java | 70 ++++++++----------- com/gallery/GalleryRemote/SlideshowFrame.java | 58 ++++++++++----- .../resources/GRResources.properties | 1 + defaults.properties | 4 +- 5 files changed, 77 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 75e8b4b..6a3d413 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-12-22 Pierre-Luc Paour (1.5.1-b8) + + * Fixed slideshow threading issues. + 2005-12-18 Pierre-Luc Paour (1.5.1-b7) * Explicitly disabling keep-alive for the GR protocol diff --git a/com/gallery/GalleryRemote/PreviewFrame.java b/com/gallery/GalleryRemote/PreviewFrame.java index 7eec7fa..7328fc6 100755 --- a/com/gallery/GalleryRemote/PreviewFrame.java +++ b/com/gallery/GalleryRemote/PreviewFrame.java @@ -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; @@ -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); @@ -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, @@ -326,8 +318,8 @@ public void shrink() { } public void pictureReady(ImageIcon image, Picture picture) { - currentImage = image; - currentPicture = picture; + imageShowNow = image; + pictureShowNow = picture; repaint(); } @@ -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), @@ -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"); @@ -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(); } @@ -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; } @@ -510,7 +502,7 @@ public void mousePressed(MouseEvent e) { break; } - currentPicture.setCropTo(null); + pictureShowNow.setCropTo(null); repaint(); } @@ -518,17 +510,17 @@ 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()); @@ -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; diff --git a/com/gallery/GalleryRemote/SlideshowFrame.java b/com/gallery/GalleryRemote/SlideshowFrame.java index a55d912..326f9aa 100644 --- a/com/gallery/GalleryRemote/SlideshowFrame.java +++ b/com/gallery/GalleryRemote/SlideshowFrame.java @@ -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; @@ -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); //} @@ -192,7 +193,7 @@ public void keyPressed(KeyEvent e) { } updateFeedback(FEEDBACK_PAUSE_PLAY); - updateProgress(currentPicture, STATE_NONE); + updateProgress(pictureShowNow, STATE_NONE); break; } @@ -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()) { @@ -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); @@ -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; @@ -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; } @@ -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); } } @@ -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; } @@ -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; @@ -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) { diff --git a/com/gallery/GalleryRemote/resources/GRResources.properties b/com/gallery/GalleryRemote/resources/GRResources.properties index 1f5a863..6dfcbfe 100644 --- a/com/gallery/GalleryRemote/resources/GRResources.properties +++ b/com/gallery/GalleryRemote/resources/GRResources.properties @@ -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 diff --git a/defaults.properties b/defaults.properties index d222767..dbeeafb 100644 --- a/defaults.properties +++ b/defaults.properties @@ -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