diff --git a/java/src/com/qotsa/jni/controller/JNIWinamp.java b/java/src/com/qotsa/jni/controller/JNIWinamp.java index f40c50e..7d2ea27 100644 --- a/java/src/com/qotsa/jni/controller/JNIWinamp.java +++ b/java/src/com/qotsa/jni/controller/JNIWinamp.java @@ -24,8 +24,8 @@ final class JNIWinamp { /** * Verify if Winamp is started * and if not started, starts it - * @return True - if successful run Winamp - * False - if not successful run Winamp + * @return True - if successful running Winamp + * False - if not successful running Winamp */ protected static native boolean run() throws UnsatisfiedLinkError; diff --git a/java/src/com/qotsa/jni/controller/WinampController.java b/java/src/com/qotsa/jni/controller/WinampController.java index 0f1aa60..0b1e939 100644 --- a/java/src/com/qotsa/jni/controller/WinampController.java +++ b/java/src/com/qotsa/jni/controller/WinampController.java @@ -76,7 +76,7 @@ public class WinampController { public static void run() throws Exception{ if (!JNIWinamp.run()) - throw new Exception("Unable to run Winamp. Verify if it is properly installed"); + throw new Exception("Unable to running Winamp. Verify if it is properly installed"); } diff --git a/java/src/de/hardcode/jxinput/test/JXInputTestDialog.java b/java/src/de/hardcode/jxinput/test/JXInputTestDialog.java index 3829aa2..cf1354f 100644 --- a/java/src/de/hardcode/jxinput/test/JXInputTestDialog.java +++ b/java/src/de/hardcode/jxinput/test/JXInputTestDialog.java @@ -267,7 +267,7 @@ public class JXInputTestDialog extends javax.swing.JDialog }//GEN-LAST:event_closeDialog /** - * Allow the dialog to run standalone. + * Allow the dialog to running standalone. * @param args the command line arguments */ public static void main(String args[]) diff --git a/java/src/javazoom/jlgui/basicplayer/BasicPlayer.java b/java/src/javazoom/jlgui/basicplayer/BasicPlayer.java index e71407d..e587bb7 100644 --- a/java/src/javazoom/jlgui/basicplayer/BasicPlayer.java +++ b/java/src/javazoom/jlgui/basicplayer/BasicPlayer.java @@ -636,7 +636,7 @@ public class BasicPlayer implements BasicController, Runnable } catch (IOException e) { - log.error("Thread cannot run()", e); + log.error("Thread cannot running()", e); m_status = STOPPED; notifyEvent(BasicPlayerEvent.STOPPED, getEncodedStreamPosition(), -1, null); } diff --git a/java/src/org/apache/commons/logging/LogFactory.java b/java/src/org/apache/commons/logging/LogFactory.java index 526137e..f8b8955 100644 --- a/java/src/org/apache/commons/logging/LogFactory.java +++ b/java/src/org/apache/commons/logging/LogFactory.java @@ -1344,10 +1344,10 @@ public abstract class LogFactory { } /** - * Applets may run in an environment where accessing resources of a loader is + * Applets may running in an environment where accessing resources of a loader is * a secure operation, but where the commons-logging library has explicitly * been granted permission for that operation. In this case, we need to - * run the operation using an AccessController. + * running the operation using an AccessController. */ private static InputStream getResourceAsStream(final ClassLoader loader, final String name) @@ -1801,8 +1801,8 @@ public abstract class LogFactory { // // Note that this block must come after any variable declarations used // by any methods called from this block, as we want any static initialiser - // associated with the variable to run first. If static initialisers for - // variables run after this code, then (a) their value might be needed + // associated with the variable to running first. If static initialisers for + // variables running after this code, then (a) their value might be needed // by methods called from here, and (b) they might *override* any value // computed here! // diff --git a/java/src/org/apache/commons/logging/impl/Log4JLogger.java b/java/src/org/apache/commons/logging/impl/Log4JLogger.java index d609c0c..56d421e 100644 --- a/java/src/org/apache/commons/logging/impl/Log4JLogger.java +++ b/java/src/org/apache/commons/logging/impl/Log4JLogger.java @@ -39,7 +39,7 @@ import org.apache.log4j.Level; * * Log4J1.3 is expected to change Level so it no longer extends Priority, which is * a non-binary-compatible change. The class generated by compiling this code against - * log4j 1.2 will therefore not run against log4j 1.3. + * log4j 1.2 will therefore not running against log4j 1.3. * * @author Scott Sanders * @author Rod Waldhoff @@ -135,7 +135,7 @@ public class Log4JLogger implements Log, Serializable { // Logger class) in version 1.3 has methods that take both Priority and // Level objects. This means that if we use Level here, and compile // against log4j 1.3 then calls would be bound to the versions of - // methods taking Level objects and then would fail to run against + // methods taking Level objects and then would fail to running against // version 1.2 of log4j. // --------------------------------------------------------- diff --git a/java/src/org/apache/log4j/NDC.java b/java/src/org/apache/log4j/NDC.java index d374225..2b8b8be 100644 --- a/java/src/org/apache/log4j/NDC.java +++ b/java/src/org/apache/log4j/NDC.java @@ -81,7 +81,7 @@ import org.apache.log4j.helpers.LogLog; request will have a different NDC tag.

Heavy duty systems should call the {@link #remove} method when - leaving the run method of a thread. This ensures that the memory + leaving the running method of a thread. This ensures that the memory used by the thread can be freed by the Java garbage collector. There is a mechanism to lazily remove references to dead threads. In practice, this means that you can be a little sloppy @@ -367,7 +367,7 @@ public class NDC { practice, this means that you can be a little sloppy and occasionally forget to call {@link #remove} before exiting a thread. However, you must call remove sometime. If - you never call it, then your application is sure to run out of + you never call it, then your application is sure to running out of memory. */ diff --git a/java/src/org/apache/log4j/lf5/LF5Appender.java b/java/src/org/apache/log4j/lf5/LF5Appender.java index e98e9bd..c466f3a 100644 --- a/java/src/org/apache/log4j/lf5/LF5Appender.java +++ b/java/src/org/apache/log4j/lf5/LF5Appender.java @@ -158,7 +158,7 @@ public class LF5Appender extends AppenderSkeleton { * exits * the monitor. By default, the LogBrokerMonitor will hide * itself when the log window is exited, and the swing thread will - * continue to run in the background. If this property is + * continue to running in the background. If this property is * set to true, the LogBrokerMonitor will call System.exit(0) * and will shut down swing thread and the virtual machine. * diff --git a/java/src/org/apache/log4j/lf5/util/LogFileParser.java b/java/src/org/apache/log4j/lf5/util/LogFileParser.java index 656d4b6..ee4592d 100644 --- a/java/src/org/apache/log4j/lf5/util/LogFileParser.java +++ b/java/src/org/apache/log4j/lf5/util/LogFileParser.java @@ -88,7 +88,7 @@ public class LogFileParser implements Runnable { /** * Starts a new thread to parse the log file and create a LogRecord. - * See run(). + * See running(). * @param monitor LogBrokerMonitor */ public void parse(LogBrokerMonitor monitor) throws RuntimeException { diff --git a/java/src/org/apache/log4j/varia/LevelRangeFilter.java b/java/src/org/apache/log4j/varia/LevelRangeFilter.java index 9dfacb1..40994d3 100644 --- a/java/src/org/apache/log4j/varia/LevelRangeFilter.java +++ b/java/src/org/apache/log4j/varia/LevelRangeFilter.java @@ -54,7 +54,7 @@ public class LevelRangeFilter extends Filter { /** Do we return ACCEPT when a match occurs. Default is - false, so that later filters get run by default */ + false, so that later filters get running by default */ boolean acceptOnMatch = false; Level levelMin; diff --git a/java/src/pm/Application.java b/java/src/pm/Application.java index 62ba052..4a39985 100644 --- a/java/src/pm/Application.java +++ b/java/src/pm/Application.java @@ -1,9 +1,9 @@ package pm; import pm.event.EventHandler; -import pm.selector.Activatable; +import pm.selector.Selectable; -public abstract class Application extends EventHandler implements Activatable { +public abstract class Application extends EventHandler implements Selectable { protected String title; protected boolean active; @@ -16,22 +16,8 @@ public abstract class Application extends EventHandler implements Activatable { return title; } - public boolean active() { - return active; - } - - public void activate() { - start(); - active = true; - } - - public void deactivate() { - stop(); - active = false; - } - public void exit() { deactivate(); stop(); - } + } } \ No newline at end of file diff --git a/java/src/pm/Device.java b/java/src/pm/Device.java index 4187a23..43cdfa8 100644 --- a/java/src/pm/Device.java +++ b/java/src/pm/Device.java @@ -10,9 +10,9 @@ import pm.macro.State; import pm.macro.state.Hold; import pm.macro.state.Press; import pm.macro.state.Release; -import pm.selector.Activatable; +import pm.selector.Selectable; -public abstract class Device extends EventHandler implements Activatable { +public abstract class Device extends EventHandler implements Selectable { protected String title; protected boolean active; protected SequenceListener sequenceListener; @@ -82,20 +82,6 @@ public abstract class Device extends EventHandler implements Activatable { public String title() { return title; } - - public boolean active() { - return active; - } - - public void activate() { - start(); - active = true; - } - - public void deactivate() { - stop(); - active = false; - } public void exit() { deactivate(); diff --git a/java/src/pm/Manager.java b/java/src/pm/Manager.java index 4c4940f..c18779a 100644 --- a/java/src/pm/Manager.java +++ b/java/src/pm/Manager.java @@ -29,15 +29,15 @@ public abstract class Manager extends EventHandler { public void start() { initialise(); - Device[] deviceArray = new Device[] { - new WiimoteDevice(), - new PanelDevice(), - new JIntellitypeDevice(), - new PlayerDevice(), - new RumblepadDevice(), - new Extreme3DDevice(), - new NetworkDevice()}; - deviceSelector = new DeviceSelector(deviceArray); + Device[] deviceArray = new Device[] { + new WiimoteDevice(), + new PanelDevice(), + new JIntellitypeDevice(), + new PlayerDevice(), + new RumblepadDevice(), + new Extreme3DDevice(), + new NetworkDevice()}; + deviceSelector = new DeviceSelector(deviceArray); } public void exit() { diff --git a/java/src/pm/Selector.java b/java/src/pm/Selector.java index 5b9ee71..bfa9820 100644 --- a/java/src/pm/Selector.java +++ b/java/src/pm/Selector.java @@ -1,7 +1,6 @@ package pm; import java.awt.GridLayout; -import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JPanel; @@ -9,29 +8,29 @@ import javax.swing.JPanel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import pm.selector.Activatable; import pm.selector.SelectButton; +import pm.selector.Selectable; -public class Selector extends JFrame { +public class Selector extends JFrame { protected Log log = LogFactory.getLog(getClass()); protected static final long serialVersionUID = 1L; - protected ArrayList activatableArray; + //protected ArrayList activatableArray; - public Selector(Activatable[] activatableArray) { + public Selector(T[] activatableArray) { createPanel(activatableArray); - //setUndecorated(true); + setUndecorated(true); pack(); setResizable(false); setVisible(true); log.debug("Selector constructed"); } - protected void createPanel(Activatable[] activatableArray) { + protected void createPanel(T[] activatableArray) { JPanel panel = new JPanel(new GridLayout(0, 1)); - for (Activatable activatable : activatableArray) { - String title = activatable.title(); - SelectButton button = new SelectButton(activatable); + for (T selectable : activatableArray) { + String title = selectable.title(); + SelectButton button = new SelectButton(selectable); button.setText(title); panel.add(button); log.debug(String.format("Item added: %s", title)); diff --git a/java/src/pm/Worker.java b/java/src/pm/Worker.java index e1aafaf..0e32e8d 100644 --- a/java/src/pm/Worker.java +++ b/java/src/pm/Worker.java @@ -1,18 +1,27 @@ package pm; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public abstract class Worker implements Runnable { + protected Log log = LogFactory.getLog(getClass()); + protected static final boolean THREAD = true; protected static final int SLEEP = 100; - protected boolean run; + protected boolean running = false; + protected boolean active = false; + + protected Object lock; public void start(boolean thread) { - run = true; + running = true; if (thread) { new Thread(this).start(); } else { run(); } + activate(); } public void start() { @@ -20,7 +29,8 @@ public abstract class Worker implements Runnable { } public void stop() { - run = false; + running = false; + deactivate(); } protected void sleep(int time) { @@ -28,10 +38,55 @@ public abstract class Worker implements Runnable { if (time > 0) { Thread.sleep(time); } - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + log.info(e); + } } protected void sleep() { sleep(SLEEP); } + + public boolean active() { + return active; + } + + public void activate() { + if (!running) { + start(); + } + synchronized (this) { + notify(); + } + active = true; + } + + public void deactivate() { + active = false; + } + + public void deactivate(boolean stop) { + deactivate(); + if (stop && running) { + stop(); + } + } + + public final void run() { + while (running) { + if (active) { + work(); + } else { + try { + synchronized (this) { + wait(); + } + } catch (InterruptedException e) { + log.info(e); + } + } + } + } + + protected abstract void work(); } diff --git a/java/src/pm/application/cmd/CMDApplication.java b/java/src/pm/application/cmd/CMDApplication.java index 016baba..d9ae780 100644 --- a/java/src/pm/application/cmd/CMDApplication.java +++ b/java/src/pm/application/cmd/CMDApplication.java @@ -18,7 +18,7 @@ public abstract class CMDApplication extends Application { this.title = title; } - public void initialise() { + protected void initialise() { String key = String.format("%s\\%s", REGISTRY, program); // Check of naam is gevonden in register String path = Native.getValue(key); @@ -32,10 +32,17 @@ public abstract class CMDApplication extends Application { } } - public void exit() { + public void activate() { + if (!active) { + initialise(); + } + super.activate(); + } + + public void deactivate() { if (process != null) { process.destroy(); } - super.exit(); + super.deactivate(); } } diff --git a/java/src/pm/application/itunes/iTunesApplication.java b/java/src/pm/application/itunes/iTunesApplication.java index 460c8de..8bd8ca3 100644 --- a/java/src/pm/application/itunes/iTunesApplication.java +++ b/java/src/pm/application/itunes/iTunesApplication.java @@ -11,7 +11,7 @@ import com.dt.iTunesController.iTunesEventsInterface; public class iTunesApplication extends Application implements iTunesEventsInterface { protected static final String TITLE = "iTunes"; - + protected static final int POSTION_CHANGE_RATE = 1; protected static final int VOLUME_CHANGE_RATE = 5; protected static final String PLAYLIST_LIKE = "Like"; @@ -20,23 +20,27 @@ public class iTunesApplication extends Application implements iTunesEventsInterf protected iTunes iTunes; public iTunesApplication() { - super(TITLE); - iTunes = new iTunes(); + super(TITLE); + iTunes = new iTunes(); } public void activate() { - iTunes.connect(); - iTunes.addEventHandler(this); + synchronized (iTunes) { + iTunes.connect(); + iTunes.addEventHandler(this); + } + super.activate(); } - public void exit() { - System.out.println("Exit iTunesApplication"); - super.exit(); + public void deactivate() { try { - iTunes.quit(); // Todo: wachten totdat ook daadwerkelijk gestart? Anders wordt iTunes niet afgesloten. + synchronized (iTunes) { + iTunes.quit(); + } } catch (Exception e) { - //throw new ApplicationExitException(); + log.info("Unexpected deactivation exception", e); } + super.deactivate(); } protected void action(Action action) { diff --git a/java/src/pm/device/network/NetworkDevice.java b/java/src/pm/device/network/NetworkDevice.java index 6aefdb3..fd25ca3 100644 --- a/java/src/pm/device/network/NetworkDevice.java +++ b/java/src/pm/device/network/NetworkDevice.java @@ -66,7 +66,7 @@ public class NetworkDevice extends Device { } public void run() { - while (run) { + while (running) { System.out.println("Server is waiting for clients"); try { Socket socket = serverSocket.accept(); diff --git a/java/src/pm/event/EventHandler.java b/java/src/pm/event/EventHandler.java index 280f762..aedbb83 100644 --- a/java/src/pm/event/EventHandler.java +++ b/java/src/pm/event/EventHandler.java @@ -34,7 +34,7 @@ public abstract class EventHandler extends EventListener { action(action); continuous.nextIteration(); sleep(continuous.getSleep()); - } while (run && !continuous.getStop()); + } while (running && !continuous.getStop()); continuous.reset(); } else { action(action); @@ -42,4 +42,9 @@ public abstract class EventHandler extends EventListener { } protected void action(Action action) {} + + public void activate() { + super.activate(); + add(new Feedback()); + } } \ No newline at end of file diff --git a/java/src/pm/event/EventListener.java b/java/src/pm/event/EventListener.java index abcee97..62172fc 100644 --- a/java/src/pm/event/EventListener.java +++ b/java/src/pm/event/EventListener.java @@ -21,18 +21,16 @@ public abstract class EventListener extends Worker { } } - public final void run() { - while (run) { - while (eventQueue.isEmpty()) { - synchronized (available) { - try { - available.wait(); - } catch (InterruptedException e) {} - } + public final void work() { + while (eventQueue.isEmpty()) { + synchronized (available) { + try { + available.wait(); + } catch (InterruptedException e) {} } - event(eventQueue.poll()); - } - } + } + event(eventQueue.poll()); + } public abstract void event(Event event); } \ No newline at end of file diff --git a/java/src/pm/exception/WorkerException.java b/java/src/pm/exception/WorkerException.java new file mode 100644 index 0000000..88ef429 --- /dev/null +++ b/java/src/pm/exception/WorkerException.java @@ -0,0 +1,5 @@ +package pm.exception; + +public class WorkerException extends Exception { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/exception/worker/AlreadyActiveException.java b/java/src/pm/exception/worker/AlreadyActiveException.java new file mode 100644 index 0000000..d6a6af4 --- /dev/null +++ b/java/src/pm/exception/worker/AlreadyActiveException.java @@ -0,0 +1,7 @@ +package pm.exception.worker; + +import pm.exception.WorkerException; + +public class AlreadyActiveException extends WorkerException { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/exception/worker/AlreadyRunningException.java b/java/src/pm/exception/worker/AlreadyRunningException.java new file mode 100644 index 0000000..5add419 --- /dev/null +++ b/java/src/pm/exception/worker/AlreadyRunningException.java @@ -0,0 +1,7 @@ +package pm.exception.worker; + +import pm.exception.WorkerException; + +public class AlreadyRunningException extends WorkerException { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/exception/worker/NotActiveException.java b/java/src/pm/exception/worker/NotActiveException.java new file mode 100644 index 0000000..8304712 --- /dev/null +++ b/java/src/pm/exception/worker/NotActiveException.java @@ -0,0 +1,7 @@ +package pm.exception.worker; + +import pm.exception.WorkerException; + +public class NotActiveException extends WorkerException { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/exception/worker/NotRunningException.java b/java/src/pm/exception/worker/NotRunningException.java new file mode 100644 index 0000000..6d52738 --- /dev/null +++ b/java/src/pm/exception/worker/NotRunningException.java @@ -0,0 +1,7 @@ +package pm.exception.worker; + +import pm.exception.WorkerException; + +public class NotRunningException extends WorkerException { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/exception/worker/StartException.java b/java/src/pm/exception/worker/StartException.java new file mode 100644 index 0000000..a96adad --- /dev/null +++ b/java/src/pm/exception/worker/StartException.java @@ -0,0 +1,7 @@ +package pm.exception.worker; + +import pm.exception.WorkerException; + +public class StartException extends WorkerException { + protected static final long serialVersionUID = 1L; +} diff --git a/java/src/pm/selector/Activatable.java b/java/src/pm/selector/Activatable.java deleted file mode 100644 index 2d44632..0000000 --- a/java/src/pm/selector/Activatable.java +++ /dev/null @@ -1,8 +0,0 @@ -package pm.selector; - -public interface Activatable { - public String title(); - public boolean active(); - public void activate(); - public void deactivate(); -} diff --git a/java/src/pm/selector/SelectButton.java b/java/src/pm/selector/SelectButton.java index b6d22ca..420cbe9 100644 --- a/java/src/pm/selector/SelectButton.java +++ b/java/src/pm/selector/SelectButton.java @@ -4,9 +4,15 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JToggleButton; -public class SelectButton extends JToggleButton implements ItemListener { +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import pm.Worker; + +public class SelectButton extends JToggleButton implements ItemListener { + protected Log log = LogFactory.getLog(getClass()); + protected static final long serialVersionUID = 1L; - protected T activatable; public SelectButton(T activatable) { @@ -20,9 +26,8 @@ public class SelectButton extends JToggleButton implement System.out.println("Selected"); activatable.activate(); } else { - System.out.println("Deselected"); - activatable.deactivate(); - } - //System.out.println(itemEvent.getSource()); + System.out.println("Deselected"); + activatable.deactivate(); + } } } diff --git a/java/src/pm/selector/Selectable.java b/java/src/pm/selector/Selectable.java new file mode 100644 index 0000000..8160f21 --- /dev/null +++ b/java/src/pm/selector/Selectable.java @@ -0,0 +1,5 @@ +package pm.selector; + +public interface Selectable { + public String title(); +}