Merge branch 'develop-java' into develop
This commit is contained in:
@@ -10,5 +10,6 @@
|
|||||||
<classpathentry kind="lib" path="wiiusej.jar"/>
|
<classpathentry kind="lib" path="wiiusej.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
|
<classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -2,3 +2,7 @@ log4j.rootLogger=TRACE, CA
|
|||||||
log4j.appender.CA=org.apache.log4j.ConsoleAppender
|
log4j.appender.CA=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
|
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||||
|
log4j.appender.CUSTOM=test.CustomAppender
|
||||||
|
log4j.appender.CUSTOM.Bla=1234
|
||||||
|
log4j.appender.CUSTOM.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.CUSTOM.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n
|
||||||
BIN
java/client.jar
BIN
java/client.jar
Binary file not shown.
BIN
java/main.jar
BIN
java/main.jar
Binary file not shown.
BIN
java/mimis.exe
Normal file
BIN
java/mimis.exe
Normal file
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
package mimis;
|
package mimis;
|
||||||
|
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
|
import mimis.router.GlobalRouter;
|
||||||
import mimis.util.swing.Dialog;
|
import mimis.util.swing.Dialog;
|
||||||
|
|
||||||
public class Client extends Main {
|
public class Client extends Main {
|
||||||
@@ -9,7 +10,7 @@ public class Client extends Main {
|
|||||||
|
|
||||||
public Client(String ip, int port) {
|
public Client(String ip, int port) {
|
||||||
super();
|
super();
|
||||||
//eventRouter = new GlobalRouter(ip, port);
|
router = new GlobalRouter(ip, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import java.util.ServiceLoader;
|
|||||||
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import mimis.application.Application;
|
|
||||||
import mimis.device.Device;
|
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.input.Task;
|
import mimis.input.Task;
|
||||||
@@ -28,20 +26,18 @@ public class Main extends Mimis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Component[] getApplications() {
|
public static Component[] getApplications() {
|
||||||
ArrayList<Component> componentList = new ArrayList<Component>();
|
return getComponents(mimis.application.Application.class);
|
||||||
for (Application application : ServiceLoader.load(mimis.application.Application.class)) {
|
|
||||||
if (application instanceof Component) {
|
|
||||||
componentList.add((Component) application);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return componentList.toArray(new Component[]{});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component[] getDevices() {
|
public static Component[] getDevices() {
|
||||||
|
return getComponents(mimis.device.Device.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component[] getComponents(Class<?> clazz) {
|
||||||
ArrayList<Component> componentList = new ArrayList<Component>();
|
ArrayList<Component> componentList = new ArrayList<Component>();
|
||||||
for (Device device : ServiceLoader.load(mimis.device.Device.class)) {
|
for (Object object : ServiceLoader.load(clazz)) {
|
||||||
if (device instanceof Component) {
|
if (object instanceof Component) {
|
||||||
componentList.add((Component) device);
|
componentList.add((Component) object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return componentList.toArray(new Component[]{});
|
return componentList.toArray(new Component[]{});
|
||||||
@@ -95,6 +91,8 @@ public class Main extends Mimis {
|
|||||||
case PREVIOUS:
|
case PREVIOUS:
|
||||||
applicationManager.currentChanged();
|
applicationManager.currentChanged();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ public abstract class Mimis extends Component {
|
|||||||
case EXIT:
|
case EXIT:
|
||||||
exit();
|
exit();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ package mimis.manager;
|
|||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -70,12 +69,8 @@ public class ButtonManager extends Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void work() {
|
protected void work() {
|
||||||
long before = Calendar.getInstance().getTimeInMillis();
|
|
||||||
for (Worker worker : workerList) {
|
for (Worker worker : workerList) {
|
||||||
buttonMap.get(worker).setPressed(worker.active());
|
buttonMap.get(worker).setPressed(worker.active());
|
||||||
}
|
}
|
||||||
long after = Calendar.getInstance().getTimeInMillis();
|
|
||||||
int sleep = INTERVAL - (int) (after - before);
|
|
||||||
sleep(sleep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package mimis.manager;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
|
import mimis.worker.IntervalWorker;
|
||||||
import mimis.worker.Worker;
|
import mimis.worker.Worker;
|
||||||
|
|
||||||
public class Manager extends Worker {
|
public class Manager extends IntervalWorker {
|
||||||
protected static final int INTERVAL = 1000;
|
protected static final int INTERVAL = 1000;
|
||||||
|
|
||||||
protected ArrayList<Worker> workerList;
|
protected ArrayList<Worker> workerList;
|
||||||
@@ -44,12 +44,8 @@ public class Manager extends Worker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void work() {
|
protected void work() {
|
||||||
long before = Calendar.getInstance().getTimeInMillis();
|
|
||||||
for (Worker worker : workerList) {
|
for (Worker worker : workerList) {
|
||||||
worker.active();
|
worker.active();
|
||||||
}
|
}
|
||||||
long after = Calendar.getInstance().getTimeInMillis();
|
|
||||||
int sleep = INTERVAL - (int) (after - before);
|
|
||||||
sleep(sleep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import mimis.exception.worker.ActivateException;
|
|||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.input.Feedback;
|
import mimis.input.Feedback;
|
||||||
import mimis.input.Task;
|
import mimis.input.Task;
|
||||||
import mimis.worker.Component;
|
|
||||||
import mimis.worker.Worker;
|
import mimis.worker.Worker;
|
||||||
|
|
||||||
public class GlobalRouter extends Component {
|
public class GlobalRouter extends Router {
|
||||||
protected String ip;
|
protected String ip;
|
||||||
protected int port;
|
protected int port;
|
||||||
protected Client client;
|
protected Client client;
|
||||||
|
|||||||
81
java/src/mimis/worker/IntervalWorker.java
Normal file
81
java/src/mimis/worker/IntervalWorker.java
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package mimis.worker;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import mimis.exception.worker.ActivateException;
|
||||||
|
import mimis.exception.worker.DeactivateException;
|
||||||
|
|
||||||
|
public class IntervalWorker extends Worker {
|
||||||
|
protected static final boolean THREAD = true;
|
||||||
|
protected static final int INTERVAL = 500;
|
||||||
|
|
||||||
|
protected Timer timer;
|
||||||
|
|
||||||
|
public synchronized void start(boolean thread) {
|
||||||
|
if (!active) {
|
||||||
|
activate = true;
|
||||||
|
timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
IntervalWorker.this.run();
|
||||||
|
}}, 0, INTERVAL);
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
if (!thread) {
|
||||||
|
try {
|
||||||
|
synchronized (this) {
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.info(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void stop() {
|
||||||
|
if (active) {
|
||||||
|
timer.cancel();
|
||||||
|
deactivate = true;
|
||||||
|
run();
|
||||||
|
notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
if (activate && !active) {
|
||||||
|
try {
|
||||||
|
super.activate();
|
||||||
|
} catch (ActivateException e) {
|
||||||
|
log.error(e);
|
||||||
|
} finally {
|
||||||
|
activate = false;
|
||||||
|
}
|
||||||
|
} else if (deactivate && active) {
|
||||||
|
try {
|
||||||
|
super.deactivate();
|
||||||
|
} catch (DeactivateException e) {
|
||||||
|
log.error(e);
|
||||||
|
} finally {
|
||||||
|
deactivate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (active) {
|
||||||
|
work();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void work() {
|
||||||
|
System.out.println("(-:");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
IntervalWorker intervalWorker = new IntervalWorker();
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
intervalWorker.start(false);
|
||||||
|
System.out.println("--");
|
||||||
|
intervalWorker.sleep(200);
|
||||||
|
intervalWorker.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,23 +9,24 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
public abstract class Worker implements Runnable {
|
public abstract class Worker implements Runnable {
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected static final boolean THREAD = false;
|
protected static final boolean THREAD = true;
|
||||||
protected static final int SLEEP = 100;
|
protected static final int SLEEP = 100;
|
||||||
|
|
||||||
protected boolean thread = true;
|
protected boolean thread = true;
|
||||||
protected boolean interrupt;
|
|
||||||
protected boolean run = false;
|
protected boolean run = false;
|
||||||
protected boolean active = false;
|
protected boolean active = false;
|
||||||
protected boolean activate = false;
|
protected boolean activate = false;
|
||||||
protected boolean deactivate = false;
|
protected boolean deactivate = false;
|
||||||
|
|
||||||
public Worker() {}
|
|
||||||
|
|
||||||
public Worker(boolean thread) {
|
public Worker(boolean thread) {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized final void start(boolean thread) {
|
public Worker() {
|
||||||
|
this(THREAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void start(boolean thread) {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
activate = true;
|
activate = true;
|
||||||
}
|
}
|
||||||
@@ -43,11 +44,11 @@ public abstract class Worker implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized final void start() {
|
public synchronized void start() {
|
||||||
start(thread);
|
start(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized final void stop() {
|
public synchronized void stop() {
|
||||||
if (active) {
|
if (active) {
|
||||||
deactivate = true;
|
deactivate = true;
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,7 @@ public abstract class Worker implements Runnable {
|
|||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void run() {
|
public void run() {
|
||||||
while (run || deactivate) {
|
while (run || deactivate) {
|
||||||
if (activate && !active) {
|
if (activate && !active) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
27
java/src/test/CustomAppender.java
Normal file
27
java/src/test/CustomAppender.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import org.apache.log4j.AppenderSkeleton;
|
||||||
|
import org.apache.log4j.spi.LoggingEvent;
|
||||||
|
|
||||||
|
public class CustomAppender extends AppenderSkeleton {
|
||||||
|
protected int bla = 9999;
|
||||||
|
|
||||||
|
public void setBla(int bla) {
|
||||||
|
this.bla = bla;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBla() {
|
||||||
|
return bla;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean requiresLayout() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {}
|
||||||
|
|
||||||
|
protected void append(LoggingEvent loggingEvent) {
|
||||||
|
System.out.print(layout.format(loggingEvent));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
BIN
java/wiiusej.jar
Normal file
BIN
java/wiiusej.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user