Grote aanpassingen gedaan tbv. selector: een worker kan nu active en deactive zijn. Initialise werkt nu anders.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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[])
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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!
|
||||
//
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.apache.log4j.Level;
|
||||
* </ul>
|
||||
* 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 <a href="mailto:sanders@apache.org">Scott Sanders</a>
|
||||
* @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.
|
||||
// ---------------------------------------------------------
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ import org.apache.log4j.helpers.LogLog;
|
||||
request will have a different NDC tag.
|
||||
|
||||
<p>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 <code>remove</code> 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.
|
||||
|
||||
*/
|
||||
|
||||
@@ -158,7 +158,7 @@ public class LF5Appender extends AppenderSkeleton {
|
||||
* exits
|
||||
* the monitor. By default, the <code>LogBrokerMonitor</code> 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 <code>LogBrokerMonitor</code> will call System.exit(0)
|
||||
* and will shut down swing thread and the virtual machine.
|
||||
*
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class LevelRangeFilter extends Filter {
|
||||
|
||||
/**
|
||||
Do we return ACCEPT when a match occurs. Default is
|
||||
<code>false</code>, so that later filters get run by default */
|
||||
<code>false</code>, so that later filters get running by default */
|
||||
boolean acceptOnMatch = false;
|
||||
|
||||
Level levelMin;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<T extends Activatable> extends JFrame {
|
||||
public class Selector<T extends Worker & Selectable> extends JFrame {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected ArrayList<Activatable> activatableArray;
|
||||
//protected ArrayList<T> 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<Activatable> button = new SelectButton<Activatable>(activatable);
|
||||
for (T selectable : activatableArray) {
|
||||
String title = selectable.title();
|
||||
SelectButton<T> button = new SelectButton<T>(selectable);
|
||||
button.setText(title);
|
||||
panel.add(button);
|
||||
log.debug(String.format("Item added: %s", title));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
5
java/src/pm/exception/WorkerException.java
Normal file
5
java/src/pm/exception/WorkerException.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.exception;
|
||||
|
||||
public class WorkerException extends Exception {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
7
java/src/pm/exception/worker/AlreadyActiveException.java
Normal file
7
java/src/pm/exception/worker/AlreadyActiveException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.worker;
|
||||
|
||||
import pm.exception.WorkerException;
|
||||
|
||||
public class AlreadyActiveException extends WorkerException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pm.exception.worker;
|
||||
|
||||
import pm.exception.WorkerException;
|
||||
|
||||
public class AlreadyRunningException extends WorkerException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
7
java/src/pm/exception/worker/NotActiveException.java
Normal file
7
java/src/pm/exception/worker/NotActiveException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.worker;
|
||||
|
||||
import pm.exception.WorkerException;
|
||||
|
||||
public class NotActiveException extends WorkerException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
7
java/src/pm/exception/worker/NotRunningException.java
Normal file
7
java/src/pm/exception/worker/NotRunningException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.worker;
|
||||
|
||||
import pm.exception.WorkerException;
|
||||
|
||||
public class NotRunningException extends WorkerException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
7
java/src/pm/exception/worker/StartException.java
Normal file
7
java/src/pm/exception/worker/StartException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.worker;
|
||||
|
||||
import pm.exception.WorkerException;
|
||||
|
||||
public class StartException extends WorkerException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package pm.selector;
|
||||
|
||||
public interface Activatable {
|
||||
public String title();
|
||||
public boolean active();
|
||||
public void activate();
|
||||
public void deactivate();
|
||||
}
|
||||
@@ -4,9 +4,15 @@ import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import javax.swing.JToggleButton;
|
||||
|
||||
public class SelectButton<T extends Activatable> extends JToggleButton implements ItemListener {
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import pm.Worker;
|
||||
|
||||
public class SelectButton<T extends Worker & Selectable> 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<T extends Activatable> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
java/src/pm/selector/Selectable.java
Normal file
5
java/src/pm/selector/Selectable.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.selector;
|
||||
|
||||
public interface Selectable {
|
||||
public String title();
|
||||
}
|
||||
Reference in New Issue
Block a user