Move all files from java subdirectory to project root

This commit is contained in:
2016-08-10 14:37:37 +01:00
parent bb92bb17d1
commit 7a1576eb4d
430 changed files with 3 additions and 3 deletions

27
exec.mimis/build.gradle Normal file
View File

@@ -0,0 +1,27 @@
dependencies {
compile project(':core.mimis')
compile project(':device.wiimote')
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
}
}
jar {
from sourceSets.main.allSource
manifest {
attributes 'Main-Class': 'mimis.Main'
}
dependsOn configurations.runtime
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Mon Jul 11 23:15:35 BST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip

164
exec.mimis/gradlew vendored Normal file
View File

@@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
exec.mimis/gradlew.bat vendored Normal file
View File

@@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -0,0 +1,60 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis;
import base.exception.worker.ActivateException;
import mimis.application.Application;
import mimis.device.Device;
import mimis.input.Task;
import mimis.router.GlobalRouter;
import mimis.util.swing.Dialog;
public class Client extends Main {
public static final String IP = "127.0.0.1";
public static final int PORT = 6789;
public Client(String ip, int port) {
super();
router = new GlobalRouter(ip, port) {
protected boolean target(Task task, Component component) {
switch (task.getTarget()) {
case ALL:
return true;
case MAIN:
case CURRENT:
return component instanceof Main;
case DEVICES:
return component instanceof Device;
case APPLICATIONS:
return component instanceof Application;
default:
return false;
}
}
};
}
public void activate() throws ActivateException {
super.activate();
}
public static void main(String[] args) {
String ip = Dialog.question("Server IP:", IP);
int port = Integer.valueOf(Dialog.question("Server Port:", PORT));
new Client(ip, port).start();
}
}

View File

@@ -0,0 +1,148 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis;
import mimis.input.Button;
import mimis.input.Feedback;
import mimis.input.Input;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.input.state.State;
import mimis.parser.ParserInput;
import mimis.router.Router;
import mimis.state.TaskMap;
import mimis.value.Action;
import base.work.Listen;
import base.worker.Worker;
import base.worker.Worker.Type;
public abstract class Component extends Listen<Input> {
protected static final String TITLE = "Component";
protected String title;
protected Router router;
public Component() {
this(TITLE);
}
public Component(Type type) {
super(type);
}
public Component(String title) {
super(Worker.Type.BACKGROUND);
this.title = title;
}
public void setRouter(Router router) {
this.router = router;
}
public String getTitle() {
return title;
}
public void listen(Class<? extends Input> clazz) {
if (router == null) {
logger.error("Router not set");
} else {
router.listen(this, clazz);
}
}
public void ignore(Class<? extends Input> clazz) {
if (router == null) {
logger.error("Router not set");
} else {
router.ignore(this, clazz);
}
}
public void route(Input input) {
if (router == null) {
logger.error("Router not set");
} else {
if (input instanceof State) {
State state = (State) input;
if (state.getComponent() == null) {
state.setComponent(this);
}
}
router.add(input);
}
}
public void input(Input input) {
if (input instanceof State) {
state((State) input);
} else if (input instanceof Task) {
task((Task) input);
} else if (input instanceof Feedback) {
feedback((Feedback) input);
}
}
protected void state(State state) {
Button button = state.getButton();
if (state instanceof Press) {
press(button);
} else if (state instanceof Release) {
release(button);
}
}
protected void task(Task task) {
Action action = task.getAction();
switch (task.getSignal()) {
case BEGIN:
switch (action) {
case START:
start();
break;
case STOP:
stop();
break;
case EXIT:
exit();
break;
default:
begin(action);
break;
}
break;
case END:
end(action);
break;
default:
action(action);
break;
}
}
protected void press(Button button) {}
protected void release(Button button) {}
protected void feedback(Feedback feedback) {}
protected void action(Action action) {}
protected void begin(Action action) {}
protected void end(Action action) {}
protected void parser(Action action, TaskMap taskMap) {
route(new ParserInput(action, taskMap));
}
}

View File

@@ -0,0 +1,117 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import base.exception.worker.ActivateException;
import mimis.input.Feedback;
import mimis.input.Input;
import mimis.input.Task;
import mimis.manager.ButtonManager;
import mimis.util.Swing;
import mimis.value.Action;
import mimis.value.Target;
public class Gui extends Component {
public static final String ICON = "M.png";
public static final String TITLE = "MIMIS Manager";
protected JFrame frame;
protected Component component;
protected TextArea textArea;
public Gui(final Component component, ButtonManager... buttonManagerArray) {
frame = new JFrame(TITLE) {
protected static final long serialVersionUID = 1L;
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
logger.debug("Window closing");
route(new Task(Action.EXIT, Target.MIMIS));
component.exit();
}
}
};
this.component = component;
frame.setIconImage(Swing.getImage(ICON));
createFrame(buttonManagerArray);
}
public void activate() throws ActivateException {
listen(Feedback.class);
super.activate();
}
public void exit() {
super.exit();
frame.dispose();
}
protected void createFrame(ButtonManager... buttonManagerArray) {
frame.setLayout(new GridLayout(0, 1));
JPanel controlPanel = createControlPanel(buttonManagerArray);
frame.add(controlPanel);
JPanel feedbackPanel = createTextPanel();
frame.add(feedbackPanel);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.pack();
}
protected JPanel createControlPanel(ButtonManager... buttonManagerArray) {
JPanel controlPanel = new JPanel(new GridLayout(1, 0));
for (ButtonManager buttonManager : buttonManagerArray) {
if (buttonManager.count() > 0) {
controlPanel.add(buttonManager.createPanel());
}
}
return controlPanel;
}
protected JPanel createTextPanel() {
JPanel textPanel = new JPanel();
textArea = new TextArea();
textArea.setEditable(false);
textPanel.add(textArea);
return textPanel;
}
public void input(Input input) {
if (input instanceof Feedback) {
writeLine(((Feedback) input).getText());
}
}
public void write(String string) {
textArea.append(string);
}
public void writeLine(String string) {
write(string + "\n");
}
public void clear() {
textArea.setText(null);
}
}

View File

@@ -0,0 +1,119 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis;
import java.util.ArrayList;
import java.util.ServiceLoader;
import javax.swing.UIManager;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import mimis.input.Task;
import mimis.manager.ButtonManager;
import mimis.manager.CurrentButtonManager;
import mimis.value.Action;
public class Main extends Mimis {
protected CurrentButtonManager applicationManager;
protected ButtonManager deviceManager;
protected Gui gui;
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
}
public static Component[] getApplications() {
return getComponents(mimis.application.Application.class);
}
public static Component[] getDevices() {
return getComponents(mimis.device.Device.class);
}
public static Component[] getComponents(Class<?> clazz) {
ArrayList<Component> componentList = new ArrayList<Component>();
for (Object object : ServiceLoader.load(clazz)) {
if (object instanceof Component) {
componentList.add((Component) object);
}
}
return componentList.toArray(new Component[]{});
}
public Main() {
super(getApplications());
/* Create gui from application and device managers */
applicationManager = new CurrentButtonManager(router, componentCycle, "Applications", currentArray);
deviceManager = new ButtonManager("Devices", initialize(false, getDevices()));
gui = new Gui(this, applicationManager, deviceManager);
manager.add(initialize(false, gui));
}
public void activate() throws ActivateException {
super.activate();
listen(Task.class);
/* Start managers */
applicationManager.start();
deviceManager.start();
/* Force display of current component when gui started */
gui.start();
while (!gui.active());
end(Action.CURRENT);
}
public void deactivate() throws DeactivateException {
super.deactivate();
logger.debug("Stop managers");
applicationManager.stop();
deviceManager.stop();
}
public void exit() {
super.exit();
logger.debug("Exit managers");
applicationManager.exit();
deviceManager.exit();
gui.exit();
router.exit();
parser.exit();
}
public void end(Action action) {
super.end(action);
switch (action) {
case CURRENT:
case NEXT:
case PREVIOUS:
applicationManager.currentChanged();
break;
default:
break;
}
}
public static void main(String[] args) {
new Main().start();
}
}

View File

@@ -0,0 +1,118 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis;
import mimis.application.Application;
import mimis.device.Device;
import mimis.input.Feedback;
import mimis.input.Task;
import mimis.manager.Manager;
import mimis.parser.Parser;
import mimis.router.Router;
import mimis.value.Action;
import mimis.value.Target;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.util.ArrayCycle;
import base.worker.Worker;
public abstract class Mimis extends Component {
protected Component[] currentArray;
protected Manager manager;
protected Parser parser;
protected ArrayCycle<Component> componentCycle;
public Mimis(Component... currentArray) {
super(Worker.Type.FOREGROUND);
this.currentArray = initialize(false, currentArray);
componentCycle = new ArrayCycle<Component>(currentArray);
router = new Router() {
protected boolean target(Task task, Component component) {
switch (task.getTarget()) {
case ALL:
return true;
case MAIN:
case CURRENT:
return component instanceof Main;
case DEVICES:
return component instanceof Device;
case APPLICATIONS:
return component instanceof Application;
default:
return false;
}
}
};
parser = new Parser();
manager = new Manager(initialize(true, router, parser));
}
public void activate() throws ActivateException {
manager.start();
super.activate();
}
public void deactivate() throws DeactivateException {
super.deactivate();
manager.stop();
}
public void exit() {
super.exit();
manager.exit();
}
public Component[] initialize(boolean start, Component... componentArray) {
for (Component component : componentArray) {
component.setRouter(router);
if (start) {
component.start();
}
}
return componentArray;
}
public void task(Task task) {
if (task.getTarget().equals(Target.CURRENT)) {
componentCycle.current().add(task);
} else {
super.task(task);
}
}
public void end(Action action) {
switch (action) {
case CURRENT:
route(new Feedback("Current component: " + componentCycle.current().getTitle()));
break;
case NEXT:
logger.debug("Next component");
route(new Feedback("Next component: " + componentCycle.next().getTitle()));
break;
case PREVIOUS:
logger.debug("Previous component");
route(new Feedback("Previous component: " + componentCycle.previous().getTitle()));
break;
case EXIT:
exit();
break;
default:
break;
}
}
}

View File

@@ -0,0 +1,197 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.device.panel;
import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import mimis.Gui;
import mimis.util.Swing;
import mimis.util.swing.HoldButton;
import mimis.util.swing.HoldButtonListener;
import mimis.util.swing.ToggleButton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Panel extends JFrame implements HoldButtonListener {
protected static final long serialVersionUID = 1L;
protected Logger logger = LoggerFactory.getLogger(getClass());
protected final static String TITLE = "MIMIS Panel Device";
protected PanelDevice panelDevice;
protected HoldButton upButton;
protected HoldButton previousButton;
protected HoldButton rewindButton;
protected HoldButton stopButton;
protected ToggleButton playPauseToggleButton;
protected HoldButton forwardButton;
protected HoldButton downButton;
protected HoldButton nextButton;
protected HoldButton volumeDownButton;
protected ToggleButton muteToggleButton;
protected HoldButton volumeUpButton;
protected HoldButton repeatButton;
protected HoldButton shuffleButton;
Panel(PanelDevice panelDevice) {
super(TITLE);
this.panelDevice = panelDevice;
setIconImage(Swing.getImage(Gui.ICON));
createControls();
layoutControls();
pack();
setResizable(false);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
protected HoldButton getButton(String name, String text) {
HoldButton button = new HoldButton(this);
button.setIcon(Swing.getImageIcon(name));
button.setToolTipText(text);
button.setFocusPainted(false);
return button;
}
protected ToggleButton getToggleButton(String firstName, String secondName, String text) {
ImageIcon firstImageIcon = Swing.getImageIcon(firstName);
ImageIcon secondImageIcon = Swing.getImageIcon(secondName);
ToggleButton button = new ToggleButton(this, firstImageIcon, secondImageIcon);
button.setToolTipText(text);
button.setFocusPainted(false);
return button;
}
protected void createControls() {
upButton = getButton("icons/up.png", "Go to previous application");
nextButton = getButton("icons/next.png", "Go to next track");
previousButton = getButton("icons/previous.png", "Go to previous track");
rewindButton = getButton("icons/rewind.png", "Skip backward");
playPauseToggleButton = getToggleButton("icons/play.png", "icons/pause.png", "Play/pause");
forwardButton = getButton("icons/forward.png", "Skip forward");
downButton = getButton("icons/down.png", "Go to next application");
volumeDownButton = getButton("icons/volumeDown.png", "Decrease volume");
muteToggleButton = getToggleButton("icons/mute.png", "icons/unmute.png", "Toggle Mute");
volumeUpButton = getButton("icons/volumeUp.png", "Increase volume");
repeatButton = getButton("icons/repeat.png", "Repeat");
shuffleButton = getButton("icons/shuffle.png", "Shuffle");
}
protected void layoutControls() {
setLayout(new BorderLayout());
layoutControlPanel();
}
protected void layoutControlPanel() {
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new BorderLayout());
JPanel upperControlPanel = new JPanel();
controlPanel.add(upperControlPanel, BorderLayout.NORTH);
upperControlPanel.add(upButton);
upperControlPanel.add(previousButton);
upperControlPanel.add(rewindButton);
upperControlPanel.add(playPauseToggleButton);
upperControlPanel.add(forwardButton);
upperControlPanel.add(nextButton);
JPanel lowerControlPanel = new JPanel();
controlPanel.add(lowerControlPanel, BorderLayout.SOUTH);
lowerControlPanel.add(downButton);
lowerControlPanel.add(repeatButton);
lowerControlPanel.add(volumeDownButton);
lowerControlPanel.add(muteToggleButton);
lowerControlPanel.add(volumeUpButton);
lowerControlPanel.add(shuffleButton);
add(controlPanel, BorderLayout.CENTER);
}
/* Listeners */
public void buttonPressed(HoldButton button) {
if (button.equals(previousButton)) {
panelDevice.buttonPressed(PanelButton.PREVIOUS);
} else if (button.equals(rewindButton)) {
panelDevice.buttonPressed(PanelButton.REWIND);
} else if (button.equals(playPauseToggleButton)) {
panelDevice.buttonPressed(PanelButton.PLAY);
} else if (button.equals(forwardButton)) {
panelDevice.buttonPressed(PanelButton.FORWARD);
} else if (button.equals(nextButton)) {
panelDevice.buttonPressed(PanelButton.NEXT);
} else if (button.equals(volumeDownButton)) {
panelDevice.buttonPressed(PanelButton.VOLUME_DOWN);
} else if (button.equals(muteToggleButton)) {
panelDevice.buttonPressed(PanelButton.MUTE);
} else if (button.equals(volumeUpButton)) {
panelDevice.buttonPressed(PanelButton.VOLUME_UP);
} else if (button.equals(repeatButton)) {
panelDevice.buttonPressed(PanelButton.REPEAT);
} else if (button.equals(shuffleButton)) {
panelDevice.buttonPressed(PanelButton.SHUFFLE);
} else if (button.equals(upButton)) {
panelDevice.buttonPressed(PanelButton.UP);
} else if (button.equals(downButton)) {
panelDevice.buttonPressed(PanelButton.DOWN);
}
}
public void buttonReleased(HoldButton button) {
if (button.equals(previousButton)) {
panelDevice.buttonReleased(PanelButton.PREVIOUS);
} else if (button.equals(rewindButton)) {
panelDevice.buttonReleased(PanelButton.REWIND);
} else if (button.equals(playPauseToggleButton)) {
panelDevice.buttonReleased(PanelButton.PLAY);
playPauseToggleButton.toggle();
} else if (button.equals(forwardButton)) {
panelDevice.buttonReleased(PanelButton.FORWARD);
} else if (button.equals(nextButton)) {
panelDevice.buttonReleased(PanelButton.NEXT);
} else if (button.equals(volumeDownButton)) {
panelDevice.buttonReleased(PanelButton.VOLUME_DOWN);
} else if (button.equals(muteToggleButton)) {
panelDevice.buttonReleased(PanelButton.MUTE);
muteToggleButton.toggle();
} else if (button.equals(volumeUpButton)) {
panelDevice.buttonReleased(PanelButton.VOLUME_UP);
} else if (button.equals(repeatButton)) {
panelDevice.buttonReleased(PanelButton.REPEAT);
} else if (button.equals(shuffleButton)) {
panelDevice.buttonReleased(PanelButton.SHUFFLE);
} else if (button.equals(upButton)) {
panelDevice.buttonReleased(PanelButton.UP);
} else if (button.equals(downButton)) {
panelDevice.buttonReleased(PanelButton.DOWN);
}
}
protected void processWindowEvent(WindowEvent event) {
if (event.getID() == WindowEvent.WINDOW_CLOSING) {
logger.debug("Window closing");
panelDevice.stop();
}
}
}

View File

@@ -0,0 +1,36 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.device.panel;
import mimis.input.Button;
public enum PanelButton implements Button {
PREVIOUS,
REWIND,
STOP,
PAUSE,
PLAY,
FORWARD,
NEXT,
VOLUME_DOWN,
MUTE,
VOLUME_UP,
REPEAT,
SHUFFLE,
UP,
DOWN;
}

View File

@@ -0,0 +1,60 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.device.panel;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import mimis.Component;
import mimis.device.Device;
import mimis.input.state.Press;
import mimis.input.state.Release;
import mimis.value.Action;
public class PanelDevice extends Component implements Device {
protected static final String TITLE = "Panel";
protected Panel panel;
protected PanelTaskMapCycle taskMapCycle;
public PanelDevice() {
super(TITLE);
taskMapCycle = new PanelTaskMapCycle();
}
public void activate() throws ActivateException {
panel = new Panel(this);
parser(Action.ADD, taskMapCycle.player);
super.activate();
}
public boolean active() {
return panel != null;
}
public void deactivate() throws DeactivateException {
super.deactivate();
panel.dispose();
panel = null;
}
public void buttonPressed(PanelButton panelButton) {
route(new Press(panelButton));
}
public void buttonReleased(PanelButton panelButton) {
route(new Release(panelButton));
}
}

View File

@@ -0,0 +1,49 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.device.panel;
import mimis.input.Task;
import mimis.input.state.Press;
import mimis.state.TaskMap;
import mimis.state.TaskMapCycle;
import mimis.value.Action;
import mimis.value.Target;
public class PanelTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap player;
public PanelTaskMapCycle() {
/* Player */
player = new TaskMap();
player.add(new Press(PanelButton.UP), new Task(Action.PREVIOUS, Target.MAIN));
player.add(new Press(PanelButton.PREVIOUS), new Task(Action.PREVIOUS, Target.CURRENT));
player.add(new Press(PanelButton.REWIND), new Task(Action.REWIND, Target.CURRENT));
player.add(new Press(PanelButton.STOP), new Task(Action.STOP, Target.CURRENT));
player.add(new Press(PanelButton.PAUSE), new Task(Action.PAUSE, Target.CURRENT));
player.add(new Press(PanelButton.PLAY), new Task(Action.PLAY, Target.CURRENT));
player.add(new Press(PanelButton.FORWARD), new Task(Action.FORWARD, Target.CURRENT));
player.add(new Press(PanelButton.DOWN), new Task(Action.NEXT, Target.MAIN));
player.add(new Press(PanelButton.NEXT), new Task(Action.NEXT, Target.CURRENT));
player.add(new Press(PanelButton.VOLUME_DOWN), new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(new Press(PanelButton.MUTE), new Task(Action.MUTE, Target.CURRENT));
player.add(new Press(PanelButton.VOLUME_UP), new Task(Action.VOLUME_UP, Target.CURRENT));
player.add(new Press(PanelButton.REPEAT), new Task(Action.REPEAT, Target.CURRENT));
player.add(new Press(PanelButton.SHUFFLE), new Task(Action.SHUFFLE, Target.CURRENT));
add(player);
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.exception;
public class EventException extends Exception {
protected static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,23 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.exception.event.router;
import mimis.exception.EventException;
public class GlobalRouterException extends EventException {
protected static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,92 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.manager;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.border.TitledBorder;
import base.work.Work;
public class ButtonManager extends Manager {
protected static final String TITLE = "Workers";
protected String title;
protected Map<Work, WorkerButton> buttonMap;
public ButtonManager(Work... workArray) {
this(TITLE, workArray);
}
public ButtonManager(String title, Work... workArray) {
super(workArray);
this.title = title;
createButtons();
}
public String getTitle() {
return title;
}
public WorkerButton[] getButtons() {
return buttonMap.values().toArray(new WorkerButton[]{});
}
protected void createButtons() {
buttonMap = new HashMap<Work, WorkerButton>();
for (Work worker : workList) {
WorkerButton button = new WorkerButton(worker);
buttonMap.put(worker, button);
}
}
public JPanel createPanel() {
/* Initialize components */
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints gridBagConstraints = new GridBagConstraints();
JPanel panel = new JPanel(gridBagLayout);
/* Set border */
TitledBorder border = new TitledBorder(getTitle());
border.setTitleJustification(TitledBorder.CENTER);
panel.setBorder(border);
/* Initialize constraints */
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 1;
gridBagConstraints.weighty = 1;
/* Add buttons */
for (JToggleButton button : getButtons()) {
gridBagLayout.setConstraints(button, gridBagConstraints);
panel.add(button);
}
return panel;
}
public void work() {
for (Work worker : workList) {
buttonMap.get(worker).setPressed(worker.active());
}
}
}

View File

@@ -0,0 +1,115 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.manager;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.TitledBorder;
import mimis.Component;
import mimis.input.Task;
import mimis.router.Router;
import mimis.value.Action;
import mimis.value.Signal;
import mimis.value.Target;
import base.util.ArrayCycle;
import base.work.Work;
public class CurrentButtonManager extends ButtonManager implements ActionListener {
protected Router router;
protected ArrayCycle<Component> componentCycle;
protected Map<JRadioButton, Work> radioButtonMap;
public CurrentButtonManager(Router router, ArrayCycle<Component> componentCycle, String title, Work... workArray) {
super(title, workArray);
this.componentCycle = componentCycle;
this.router = router;
radioButtonMap = new HashMap<JRadioButton, Work>();
}
public JPanel createPanel() {
/* Initialize components */
ButtonGroup buttonGroup = new ButtonGroup();
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints gridBagConstraints = new GridBagConstraints();
JPanel panel = new JPanel(gridBagLayout);
/* Set border */
TitledBorder border = new TitledBorder(getTitle());
border.setTitleJustification(TitledBorder.CENTER);
panel.setBorder(border);
/* Initialize constraints */
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1;
for (WorkerButton button : getButtons()) {
/* Add button */
gridBagConstraints.gridwidth = GridBagConstraints.RELATIVE;
gridBagConstraints.weightx = 1;
gridBagLayout.setConstraints(button, gridBagConstraints);
panel.add(button);
/* Add radio button */
JRadioButton radioButton = new JRadioButton();
buttonGroup.add(radioButton);
radioButton.addActionListener(this);
radioButtonMap.put(radioButton, button.work);
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 0;
gridBagLayout.setConstraints(radioButton, gridBagConstraints);
panel.add(radioButton);
}
return panel;
}
public void actionPerformed(ActionEvent event) {
JRadioButton radioButton = (JRadioButton) event.getSource();
if (radioButtonMap.containsKey(radioButton)) {
Work worker = radioButtonMap.get(radioButton);
if (componentCycle.contains(worker)) {
while (!componentCycle.current().equals(worker)) {
componentCycle.next();
}
router.add(new Task(Action.CURRENT, Target.MAIN, Signal.END));
}
}
}
public void currentChanged() {
Work worker = componentCycle.current();
if (radioButtonMap.containsValue(worker)) {
for (Entry<JRadioButton, Work> entry : radioButtonMap.entrySet()) {
if (entry.getValue().equals(worker)) {
JRadioButton radioButton = (JRadioButton) entry.getKey();
radioButton.setSelected(true);
return;
}
}
}
}
}

View File

@@ -0,0 +1,67 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.manager;
import java.util.ArrayList;
import java.util.Arrays;
import base.exception.worker.DeactivateException;
import base.work.Work;
import base.worker.IntervalWork;
public class Manager extends IntervalWork {
protected static final int INTERVAL = 1000;
protected ArrayList<Work> workList;
public Manager(Work... workArray) {
workList = new ArrayList<Work>();
add(workArray);
}
public void add(Work... workArray) {
workList.addAll(Arrays.asList(workArray));
}
public void remove(Work... workArray) {
workList.removeAll(Arrays.asList(workArray));
}
public void deactivate() throws DeactivateException {
super.deactivate();
for (Work worker : workList) {
worker.stop();
}
}
public void exit() {
super.exit();
for (Work worker : workList) {
worker.exit();
}
}
public int count() {
return workList.size();
}
public void work() {
for (Work worker : workList) {
worker.active();
}
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.manager;
public interface Titled {
public String getTitle();
}

View File

@@ -0,0 +1,66 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.manager;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JToggleButton;
import mimis.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import base.work.Work;
public class WorkerButton extends JToggleButton implements MouseListener {
protected static final long serialVersionUID = 1L;
protected Logger logger = LoggerFactory.getLogger(getClass());
protected Work work;
public WorkerButton(Work worker) {
this.work = worker;
setFocusable(false);
addMouseListener(this);
if (worker instanceof Component) {
setText(((Component) worker).getTitle());
}
}
public void mouseClicked(MouseEvent event) {
if (work.active()) {
logger.trace("Stop");
work.stop();
} else {
logger.trace("Start");
work.start();
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void setPressed(boolean pressed) {
if ((!isSelected() && pressed) || (isSelected() && !pressed)) {
doClick();
}
}
}

View File

@@ -0,0 +1,105 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.router;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import mimis.input.Feedback;
import mimis.input.Task;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.work.Work;
public abstract class GlobalRouter extends Router {
protected String ip;
protected int port;
protected Client client;
public GlobalRouter(String ip, int port) {
this.ip = ip;
this.port = port;
}
public void activate() throws ActivateException {
try {
client = new Client(ip, port);
} catch (IOException e) {
logger.error("", e);
throw new ActivateException();
}
super.activate();
}
public void deactivate() throws DeactivateException {
super.deactivate();
client.stop();
}
public void task(Task task) {
try {
client.send(task);
} catch (IOException e) {
logger.error("", e);
}
}
class Client extends Work {
protected Socket socket;
protected ObjectInputStream objectInputStream;
protected ObjectOutputStream objectOutputStream;
public Client(String ip, int port) throws IOException {
socket = new Socket(ip, port);
objectInputStream = new ObjectInputStream(socket.getInputStream());
objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
}
public void work() {
try {
Object object;
do {
object = objectInputStream.readObject();
if (object instanceof Feedback) {
add((Feedback) object);
}
} while (object != null);
} catch (IOException e) {
logger.error("", e);
} catch (ClassNotFoundException e) {
logger.error("", e);
}
}
public void deactivate() throws DeactivateException {
super.deactivate();
try {
objectInputStream.close();
objectOutputStream.close();
socket.close();
} catch (IOException e) {
logger.error("", e);
}
}
public void send(Object object) throws IOException {
objectOutputStream.writeObject(object);
}
}
}

View File

@@ -0,0 +1,45 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.ImageIcon;
public class Swing {
protected static ClassLoader classLoader;
protected static Toolkit toolkit;
static {
classLoader = Swing.class.getClassLoader();
toolkit = Toolkit.getDefaultToolkit();
}
public static URL getResource(String name) {
return classLoader.getResource(name);
}
public static Image getImage(String name) {
return toolkit.getImage(getResource(name));
}
public static ImageIcon getImageIcon(String name) {
return new ImageIcon(getResource(name));
}
}

View File

@@ -0,0 +1,38 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util.swing;
import javax.swing.ImageIcon;
import base.util.ArrayCycle;
public class CycleButton extends HoldButton {
protected static final long serialVersionUID = 1L;
protected ArrayCycle<ImageIcon> imageIconCycle;
public CycleButton(HoldButtonListener holdButtonListener, ArrayCycle<ImageIcon> imageIconCycle) {
super(holdButtonListener);
this.imageIconCycle = imageIconCycle;
cycle();
}
public void cycle() {
setIcon(imageIconCycle.current());
imageIconCycle.next();
}
}

View File

@@ -0,0 +1,34 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util.swing;
import javax.swing.JOptionPane;
public class Dialog {
public static final String TITLE = "MIMIS Dialog";
public static String question(String message, Object initial) {
return question(TITLE, message, initial);
}
public static String question(String title, String message, Object initial) {
return (String) JOptionPane.showInputDialog(
null, message, title,
JOptionPane.QUESTION_MESSAGE,
null, null, initial);
}
}

View File

@@ -0,0 +1,49 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util.swing;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
public class HoldButton extends JButton implements MouseListener {
protected static final long serialVersionUID = 1L;
protected HoldButtonListener holdButtonListener;
public HoldButton(HoldButtonListener holdButtonListener) {
this.holdButtonListener = holdButtonListener;
addMouseListener(this);
}
public void mousePressed(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
holdButtonListener.buttonPressed(this);
}
}
public void mouseReleased(MouseEvent event) {
if (event.getButton() == MouseEvent.BUTTON1) {
holdButtonListener.buttonReleased(this);
}
}
public void mouseClicked(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}

View File

@@ -0,0 +1,22 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util.swing;
public interface HoldButtonListener {
public void buttonPressed(HoldButton button);
public void buttonReleased(HoldButton button);
}

View File

@@ -0,0 +1,33 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.util.swing;
import javax.swing.ImageIcon;
import base.util.ArrayCycle;
public class ToggleButton extends CycleButton {
protected static final long serialVersionUID = 1L;
public ToggleButton(HoldButtonListener holdButtonListener, ImageIcon firstImageIcon, ImageIcon secondImageIcon) {
super(holdButtonListener, new ArrayCycle<ImageIcon>(firstImageIcon, secondImageIcon));
}
public void toggle() {
cycle();
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mimis.value;
public enum Target {
ALL, MAIN, DEVICES, APPLICATIONS, SELF, CURRENT, MIMIS, APPLICATION;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1 @@
mimis.application.itunes.iTunesApplication

View File

@@ -0,0 +1,6 @@
mimis.device.javainput.extreme3d.Extreme3DDevice
mimis.device.javainput.rumblepad.RumblepadDevice
mimis.device.javainput.xbox360.Xbox360Device
mimis.device.jintellitype.JIntellitypeDevice
mimis.device.panel.PanelDevice
mimis.device.wiimote.WiimoteDevice

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

View File

@@ -0,0 +1 @@
#org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -0,0 +1,8 @@
log4j.rootLogger=INFO, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
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