Skip to content

Commit

Permalink
2003-01-29 Pierre-Luc Paour <gallery@paour.com> (1.3-b25)
Browse files Browse the repository at this point in the history
	* Made Log re-entrant, so that when Applet is restarted within
	  the same VM, the log can keep going.
	* Slideshow applet now pre-fetches the first picture for a faster
	  start.
  • Loading branch information
Pierre-Luc Paour committed Jan 29, 2004
1 parent 996d7a1 commit 680e6b0
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 63 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
2003-01-29 Pierre-Luc Paour <gallery@paour.com> (1.3-b25)

* Made Log re-entrant, so that when Applet is restarted within
the same VM, the log can keep going.
* Slideshow applet now pre-fetches the first picture for a faster
start.

2003-01-29 Pierre-Luc Paour <gallery@paour.com> (1.3-b24)

* Recursive slideshows.
Expand Down
12 changes: 11 additions & 1 deletion com/gallery/GalleryRemote/GRApplet.java
@@ -1,6 +1,7 @@
package com.gallery.GalleryRemote;

import com.gallery.GalleryRemote.util.DialogUtil;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.model.Gallery;

import javax.swing.*;
Expand All @@ -23,9 +24,12 @@ public class GRApplet extends JApplet {
boolean hasStarted = false;
String coreClass = "com.gallery.GalleryRemote.GalleryRemoteMainFrame";

public void init() {}
public void init() {
System.out.println("Applet init");
}

public void start() {
System.out.println("Applet start");
initGalleryRemote();

if (hasStarted) {
Expand Down Expand Up @@ -63,10 +67,16 @@ protected void initGalleryRemote() {
}

public void stop() {
System.out.println("Applet stop");
// don't shutdown the applet if it didn't start...
if (hasStarted && GalleryRemote._() != null) {
GalleryRemote._().getCore().shutdown();
}

ImageUtils.purgeTemp();

Log.log(Log.LEVEL_INFO, MODULE, "Shutting down log");
Log.shutdown();
}

public void hasShutdown() {
Expand Down
33 changes: 28 additions & 5 deletions com/gallery/GalleryRemote/GRAppletSlideshow.java
Expand Up @@ -9,6 +9,8 @@
import com.gallery.GalleryRemote.prefs.SlideshowPanel;

import javax.swing.*;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListDataEvent;
import javax.swing.border.TitledBorder;
import java.applet.Applet;
import java.io.FilePermission;
Expand All @@ -30,10 +32,11 @@
* User: paour
* Date: Oct 30, 2003
*/
public class GRAppletSlideshow extends GRAppletMini implements GalleryRemoteCore, ActionListener {
public class GRAppletSlideshow extends GRAppletMini implements GalleryRemoteCore, ActionListener, ListDataListener {
public static final String MODULE = "AppletSlideshow";
JButton jStart;
SlideshowPanel jSlidePanel;
SlideshowFrame slideshowFrame = null;

public GRAppletSlideshow() {
coreClass = "com.gallery.GalleryRemote.GalleryRemoteMini";
Expand All @@ -50,6 +53,7 @@ public void startup() {

album = new Album(gallery);
album.setName(info.albumName);
album.addListDataListener(this);

album.fetchAlbumImages(jStatusBar, true);
}
Expand All @@ -66,7 +70,7 @@ protected void jbInit() {
getContentPane().add(jSlidePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
getContentPane().add(new JLabel(GRI18n.getString(MODULE, "Disabled")), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 3, 0, 3), 0, 0));
getContentPane().add(jStart, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
getContentPane().add(jStatusBar, new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0
Expand All @@ -89,18 +93,37 @@ public void setInProgress(boolean inProgress) {
public void actionPerformed(ActionEvent e) {
jSlidePanel.writeProperties(GalleryRemote._().properties);

new SlideshowFrame().start(getCurrentAlbum().getPicturesList());
if (slideshowFrame == null) {
slideshowFrame = new SlideshowFrame();
}

slideshowFrame.setVisible(true);
slideshowFrame.start(getCurrentAlbum().getPicturesList());

// null slideshowFrame so that next time the user clicks the button
// they get a black one, in case they changed positioning
slideshowFrame = null;
}

public void shutdown() {
if (hasStarted) {
jSlidePanel.writeProperties(GalleryRemote._().properties);
GalleryRemote._().properties.write();

GalleryRemote.shutdownInstance();
}

super.shutdown();
}

public void contentsChanged(ListDataEvent e) {
// most likely, pictures were just added to the album. Preload the first one.
slideshowFrame = new SlideshowFrame();
if (album.getPicturesList().size() > 0) {
ImageUtils.download((Picture) album.getPicturesList().get(0), getGraphicsConfiguration().getBounds().getSize(), GalleryRemote._().getCore().getMainStatusUpdate(), null);
}
}

public void intervalAdded(ListDataEvent e) {}

public void intervalRemoved(ListDataEvent e) {}

}
9 changes: 6 additions & 3 deletions com/gallery/GalleryRemote/GalleryComm2.java
Expand Up @@ -1107,7 +1107,10 @@ void runTask() {
}

private void fetch(Album a, String albumName, ArrayList newPictures)
throws GR2Exception {
throws GR2Exception {
su.updateProgressStatus(StatusUpdate.LEVEL_GENERIC, GRI18n.getString(MODULE, "fetchAlbImages",
new String[]{albumName}));

try {
// setup the protocol parameters
NVPair[] form_data = new NVPair[] {
Expand Down Expand Up @@ -1138,8 +1141,8 @@ private void fetch(Album a, String albumName, ArrayList newPictures)
Picture picture = new Picture();
picture.setOnline(true);
picture.setUrlFull(new URL(baseUrl + p.getProperty("image.name." + i)));
width = p.getIntProperty("image.raw_width." + i);
height = p.getIntProperty("image.raw_height." + i);
width = p.getIntProperty("image.raw_width." + i, 0);
height = p.getIntProperty("image.raw_height." + i, 0);
picture.setSizeFull(new Dimension(width, height));

String resizedName = p.getProperty("image.resizedName." + i);
Expand Down
3 changes: 3 additions & 0 deletions com/gallery/GalleryRemote/GalleryRemoteMainFrame.java
@@ -1,6 +1,7 @@
package com.gallery.GalleryRemote;

import com.gallery.GalleryRemote.prefs.PropertiesFile;
import com.gallery.GalleryRemote.prefs.PreferenceNames;

import javax.swing.*;
import java.io.File;
Expand Down Expand Up @@ -48,6 +49,8 @@ public void createProperties() {
protected void initializeGR() {
super.initializeGR();

Log.startLog(GalleryRemote._().properties.getIntProperty(PreferenceNames.LOG_LEVEL), GalleryRemote._().properties.getBooleanProperty("toSysOut"));

try {
if (isAppletMode() || !Update.upgrade()) {
mainFrame = new MainFrame();
Expand Down
3 changes: 2 additions & 1 deletion com/gallery/GalleryRemote/GalleryRemoteMini.java
Expand Up @@ -2,6 +2,7 @@

import com.gallery.GalleryRemote.util.DialogUtil;
import com.gallery.GalleryRemote.prefs.PropertiesFile;
import com.gallery.GalleryRemote.prefs.PreferenceNames;

import java.awt.*;
import java.io.File;
Expand All @@ -16,7 +17,7 @@ public class GalleryRemoteMini extends GalleryRemote {
protected void initializeGR() {
super.initializeGR();

Log.setMaxLevel();
Log.startLog(_().properties.getIntProperty(PreferenceNames.LOG_LEVEL), _().properties.getBooleanProperty("toSysOut"));
}

public void createProperties() {
Expand Down
79 changes: 44 additions & 35 deletions com/gallery/GalleryRemote/Log.java
Expand Up @@ -33,7 +33,7 @@
* @author paour
* @created August 18, 2002
*/
public class Log extends Thread implements PreferenceNames {
public class Log implements PreferenceNames, Runnable {
public final static int LEVEL_CRITICAL = 0;
public final static int LEVEL_ERROR = 1;
public final static int LEVEL_INFO = 2;
Expand All @@ -50,28 +50,19 @@ public class Log extends Thread implements PreferenceNames {
public static int maxLevel = LEVEL_TRACE;
public static boolean toSysOut;

Thread loggerThread = null;

static int threadPriority = (Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2;
static Log singleton = new Log();
static boolean started = false;

BufferedWriter writer = null;
List logLines = Collections.synchronizedList(new LinkedList());
boolean running = false;

private Log() {
try {
writer = new BufferedWriter(new FileWriter(new File(System.getProperty("java.io.tmpdir"), "log.txt")));
} catch (IOException e) {
System.err.println("Can't open log file 'log.txt'. Disabling log.");
maxLevel = -1;
}

setPriority(threadPriority);
start();
}

private Log() {}

public static void log(int level, String module, String message) {
if (level <= maxLevel) {
if (level <= maxLevel || !started) {
if (module == null) {
module = emptyModule;
} else {
Expand Down Expand Up @@ -123,7 +114,7 @@ public static void log(String message) {
}

public static void logStack(int level, String module) {
if (level <= maxLevel) {
if (level <= maxLevel || !started) {
CharArrayWriter caw = new CharArrayWriter();
try {
throw new Exception("Dump stack");
Expand All @@ -136,7 +127,7 @@ public static void logStack(int level, String module) {
}

public static void logException(int level, String module, Throwable t) {
if (level <= maxLevel) {
if (level <= maxLevel || !started) {
//log(level, module, t.toString());

CharArrayWriter caw = new CharArrayWriter();
Expand All @@ -160,19 +151,25 @@ public static String getShortClassName(Class c) {
public static void shutdown() {
singleton.running = false;
try {
singleton.join();
singleton.loggerThread.join();
} catch (InterruptedException ee) {
System.err.println("Thread killed for some reason");
}

singleton = new Log();
}


/**
* Main processing method for the Log object
*/
public void run() {
System.out.println("Logger thread running");

BufferedWriter writer = null;
running = true;
try {
writer = new BufferedWriter(new FileWriter(new File(System.getProperty("java.io.tmpdir"), "log.txt")));
while (running) {
Thread.sleep(sleepInterval);
while (!logLines.isEmpty()) {
Expand All @@ -187,34 +184,46 @@ public void run() {

writer.flush();
}

writer.close();
} catch (IOException e) {
System.err.println("Can't write to log file. Disabling log...");
maxLevel = -1;
} catch (InterruptedException e) {
System.err.println("Thread killed for some reason");
System.err.println("Logger thread killed");
} finally {
running = false;
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("Logger thread shutting down");
}

public static void setMaxLevel() {
try {
if (maxLevel != GalleryRemote._().properties.getIntProperty(LOG_LEVEL)) {
maxLevel = GalleryRemote._().properties.getIntProperty(LOG_LEVEL);
singleton.logLines.add(emptyTime + "|"
+ levelName[LEVEL_TRACE] + "|"
+ emptyModule + "|"
+ "Setting Log level to " + levelName[maxLevel]);
}
public static void startLog(int maxLevel, boolean toSysOut) {
//try {
if (Log.maxLevel != maxLevel) {
Log.maxLevel = maxLevel;
singleton.logLines.add(emptyTime + "|"
+ levelName[LEVEL_TRACE] + "|"
+ emptyModule + "|"
+ "Setting Log level to " + levelName[Log.maxLevel]);
}

toSysOut = GalleryRemote._().properties.getBooleanProperty("toSysOut");
} catch (Exception e) {}
}
Log.toSysOut = toSysOut;

static {
setMaxLevel();
singleton.loggerThread = new Thread(singleton);
singleton.loggerThread.setPriority(threadPriority);
singleton.loggerThread.start();
//} catch (Exception e) {e.printStackTrace();}
}

/*static {
startLog(GalleryRemote._().properties.getIntProperty(LOG_LEVEL));
}*/

/*
public static void main( String[] param ) {
try {
Expand Down
7 changes: 4 additions & 3 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -28,6 +28,7 @@
import com.gallery.GalleryRemote.prefs.PreferencesDialog;
import com.gallery.GalleryRemote.prefs.PropertiesFile;
import com.gallery.GalleryRemote.prefs.URLPanel;
import com.gallery.GalleryRemote.prefs.PreferenceNames;
import com.gallery.GalleryRemote.util.GRI18n;
import com.gallery.GalleryRemote.util.ImageUtils;
import com.gallery.GalleryRemote.util.OsShutdown;
Expand Down Expand Up @@ -771,7 +772,9 @@ public void run() {
}

public void slideshow() {
new SlideshowFrame().start(getCurrentAlbum().getPicturesList());
SlideshowFrame sf = new SlideshowFrame();
sf.setVisible(true);
sf.start(getCurrentAlbum().getPicturesList());
}


Expand Down Expand Up @@ -1307,8 +1310,6 @@ public void readPreferences(PropertiesFile op) {
if (!op.getThumbnailSize().equals(p.getThumbnailSize())) {
thumbnailCache.reload();
}

Log.setMaxLevel();
}

static FileFilter galleryFileFilter = new FileFilter() {
Expand Down

0 comments on commit 680e6b0

Please sign in to comment.