Snapshot of new files

This commit is contained in:
2016-06-20 11:13:03 +01:00
parent 4d6f71d954
commit 3e9d66286c
7 changed files with 612 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package base.work;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import base.worker.Worker;
public class ReflectiveListen extends Listen<Object> {
public ReflectiveListen() {
super();
}
public ReflectiveListen(Worker.Type workerType) {
super(workerType);
}
public void input(Object object) {
Class<?> clazz = object.getClass();
MethodType methodType = MethodType.methodType(void.class, clazz);
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandle methodHandle;
try {
methodHandle = lookup.findVirtual(getClass(), "input", methodType);
methodHandle.invoke(this, object);
} catch (Exception e) {
logger.error("", e);
} catch (Throwable e) {
logger.error("", e);
}
}
}

View File

@@ -0,0 +1,96 @@
/**
* Copyright (C) 2015 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.application.cmd.windows.lightroom;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.input.Task;
import mimis.value.Action;
import winapi.Amount;
import winapi.Slider;
import winapi.Test;
import base.exception.worker.ActivateException;
import base.util.ArrayCycle;
public class LightroomApplication extends WindowsApplication {
protected final static String PROGRAM = "lightroom.exe";
protected final static String TITLE = "Lightroom";
protected final static String WINDOW = "";
protected static Test test;
protected ArrayCycle<Slider> sliderCycle;
public LightroomApplication() {
super(PROGRAM, TITLE, WINDOW);
detect = false;
running = true;
test = new Test();
try {
test.start();
sliderCycle = new ArrayCycle<Slider>(Slider.values());
test.moveSlider(sliderCycle.current(), Amount.INCREASE_LITTLE);
} catch (Exception e) {
logger.error("", e);
//throw new ActivateException();
}
}
public static void main(String[] args) {
new LightroomApplication();
}
/*public boolean active() {
return true;
}*/
public void activate() throws ActivateException {
listen(Task.class);
super.activate();
}
public void begin(Action action) {
logger.trace("LightroomApplication begin: " + action);
try {
switch (action) {
case NEXT:
test.moveSlider(sliderCycle.current(), Amount.INCREASE_LITTLE);
break;
case PREVIOUS:
test.moveSlider(sliderCycle.current(), Amount.DECREASE_LITTLE);
break;
case VOLUME_UP:
sliderCycle.previous();
break;
case VOLUME_DOWN:
sliderCycle.next();
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
logger.debug("Slider = " + test.getValue(sliderCycle.current()));
}
public void end(Action action) {
logger.trace("LightroomApplication end: " + action);
switch (action) {
default:
break;
}
}
}

View File

@@ -0,0 +1,291 @@
//**********************************************************************************************
// Dipl. Phys. Joerg Plewe, HARDCODE Development
// Created on 27. Dezember 2001, 01:15
//**********************************************************************************************
package mimis.device.javainput;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import de.hardcode.jxinput.Axis;
import de.hardcode.jxinput.Button;
import de.hardcode.jxinput.JXInputDevice;
import de.hardcode.jxinput.JXInputManager;
import de.hardcode.jxinput.keyboard.JXKeyboardInputDevice;
import de.hardcode.jxinput.test.JXInputDevicePanel;
import de.hardcode.jxinput.virtual.JXVirtualInputDevice;
import de.hardcode.jxinput.virtual.VirtualAxis;
/**
* Test dialog showing some features of JXInput.
* @author Herkules
*/
public class JXInputTestDialog extends javax.swing.JDialog
implements ActionListener
{
private JXKeyboardInputDevice mKeyboardDevice = null;
private JXVirtualInputDevice mVirtualDevice = null;
Button mButtonUp;
Button mButtonDown;
Button mButtonLeft;
Button mButtonRight;
Button mButtonFire;
Button mButtonSpace;
/** Creates new form JXInputTestDialog */
public JXInputTestDialog(java.awt.Frame parent, boolean modal)
{
super(parent, modal);
initComponents();
configureKeyboardInputDevice();
configureVirtualInputDevice();
initDevicePanels();
pack();
// Request the focus so that the keyboarddevice can work
mMainPanel.requestFocus();
new Timer( 50, this ).start();
// Uncomment this line as an alternative to the Timer above.
// Don't use both!!
//JXInputEventManager.setTriggerIntervall( 50 );
}
/**
* Implement ActionListener#actionPerformed().
* This is called by the Timer.
*/
public void actionPerformed( ActionEvent e )
{
JXInputManager.updateFeatures();
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
for ( int i = 0; i < mDevicesTabbedPane.getComponentCount(); ++i )
{
((JXInputDevicePanel)mDevicesTabbedPane.getComponent( i )).update();
}
}
}
);
}
/**
* Configure a test JXKeyboardInputdevice.
*/
void configureKeyboardInputDevice()
{
mKeyboardDevice = JXInputManager.createKeyboardDevice();
mKeyboardDevice.createButton( KeyEvent.VK_ESCAPE );
mKeyboardDevice.createButton( KeyEvent.VK_F1 );
mKeyboardDevice.createButton( KeyEvent.VK_F2 );
mKeyboardDevice.createButton( KeyEvent.VK_F3 );
mKeyboardDevice.createButton( KeyEvent.VK_F4 );
mKeyboardDevice.createButton( KeyEvent.VK_LEFT );
mKeyboardDevice.createButton( KeyEvent.VK_RIGHT );
mKeyboardDevice.createButton( KeyEvent.VK_UP );
mKeyboardDevice.createButton( KeyEvent.VK_DOWN );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_UP );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_DOWN );
mButtonSpace = mKeyboardDevice.createButton( KeyEvent.VK_SPACE );
mButtonLeft = mKeyboardDevice.createButton( KeyEvent.VK_A );
mButtonRight = mKeyboardDevice.createButton( KeyEvent.VK_D );
mButtonDown = mKeyboardDevice.createButton( KeyEvent.VK_S );
mButtonUp = mKeyboardDevice.createButton( KeyEvent.VK_W );
// Configure it to make it listen to the main panel.
// I try to keep the kbd focus on it.
mKeyboardDevice.listenTo( mMainPanel );
}
/**
* Configure a test JXVirtualInputdevice.
*/
void configureVirtualInputDevice()
{
mVirtualDevice = JXInputManager.createVirtualDevice();
Button firebutton;
//
// Remember 'fire' button of first device for use
// in the virtual device.
// For we ran configureKeyboardInputDevice() before,
// getJXInputDevice( 0 ) should not return null
//
firebutton = JXInputManager.getJXInputDevice( 0 ).getButton( 0 );
VirtualAxis x = mVirtualDevice.createAxis( Axis.ID_X );
x.setButtons( mButtonRight, mButtonLeft );
x.setName( "x: A-D" );
VirtualAxis y = mVirtualDevice.createAxis( Axis.ID_Y );
y.setButtons( mButtonUp, mButtonDown );
y.setSpringSpeed( 0.0 );
y.setName( "y: S|W" );
VirtualAxis slider = mVirtualDevice.createAxis( Axis.ID_SLIDER0 );
slider.setIncreaseButton( mButtonSpace );
slider.setTimeFor0To1( 2000 );
slider.setName( "<space>" );
slider.setType( Axis.SLIDER );
if ( null != firebutton )
{
slider = mVirtualDevice.createAxis( Axis.ID_SLIDER1 );
slider.setIncreaseButton( firebutton );
slider.setTimeFor0To1( 2000 );
slider.setName( "JoyButton 0" );
}
}
/**
* Initialize one panel for each device available.
*/
void initDevicePanels()
{
int cnt = JXInputManager.getNumberOfDevices();
mLabelNoDevice.setVisible( cnt == 0 );
mDevicesTabbedPane.setVisible( cnt != 0 );
for ( int i = 0; i < cnt; ++i )
{
JXInputDevice dev = JXInputManager.getJXInputDevice( i );
if ( null != dev )
{
//
// Setup an own panel for each device.
//
JPanel panel = new JXInputDevicePanel( dev );
mDevicesTabbedPane.addTab( dev.getName(), panel );
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents()
{
mMainPanel = new javax.swing.JPanel();
mLabelNoDevice = new javax.swing.JLabel();
mDevicesTabbedPane = new javax.swing.JTabbedPane();
mButtonReset = new javax.swing.JButton();
setTitle("JXInput (C) 2001-2006 HARDCODE Dev.");
addWindowListener(new java.awt.event.WindowAdapter()
{
public void windowClosing(java.awt.event.WindowEvent evt)
{
closeDialog(evt);
}
});
mMainPanel.setLayout(new java.awt.BorderLayout(10, 0));
mLabelNoDevice.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
mLabelNoDevice.setText("No JXInputDevice available!");
mLabelNoDevice.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
mMainPanel.add(mLabelNoDevice, java.awt.BorderLayout.NORTH);
mDevicesTabbedPane.addFocusListener(new java.awt.event.FocusAdapter()
{
public void focusGained(java.awt.event.FocusEvent evt)
{
mDevicesTabbedPaneFocusGained(evt);
}
});
mMainPanel.add(mDevicesTabbedPane, java.awt.BorderLayout.CENTER);
mButtonReset.setText("Reset ");
mButtonReset.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
mButtonResetActionPerformed(evt);
}
});
mMainPanel.add(mButtonReset, java.awt.BorderLayout.SOUTH);
getContentPane().add(mMainPanel, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void mButtonResetActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_mButtonResetActionPerformed
{//GEN-HEADEREND:event_mButtonResetActionPerformed
while ( this.mDevicesTabbedPane.getTabCount() > 0 )
this.mDevicesTabbedPane.removeTabAt( 0 );
JXInputManager.reset();
configureKeyboardInputDevice();
configureVirtualInputDevice();
initDevicePanels();
pack();
// Request the focus so that the keyboarddevice can work
mMainPanel.requestFocus();
}//GEN-LAST:event_mButtonResetActionPerformed
private void mDevicesTabbedPaneFocusGained(java.awt.event.FocusEvent evt)//GEN-FIRST:event_mDevicesTabbedPaneFocusGained
{//GEN-HEADEREND:event_mDevicesTabbedPaneFocusGained
// Switch focus back to main panel!
this.mMainPanel.requestFocus();
}//GEN-LAST:event_mDevicesTabbedPaneFocusGained
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
System.exit( 0 );
}//GEN-LAST:event_closeDialog
/**
* Allow the dialog to run standalone.
* @param args the command line arguments
*/
public static void main(String args[])
{
new JXInputTestDialog(new javax.swing.JFrame(), true).setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton mButtonReset;
private javax.swing.JTabbedPane mDevicesTabbedPane;
private javax.swing.JLabel mLabelNoDevice;
private javax.swing.JPanel mMainPanel;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,57 @@
/**
* Copyright (C) 2015 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.javainput.xbox360;
import mimis.exception.button.UnknownButtonException;
import mimis.input.Button;
import de.hardcode.jxinput.event.JXInputButtonEvent;
public enum Xbox360Button implements Button {
GREEN ("Button 0"), // A
RED ("Button 1"), // B
BLUE ("Button 2"), // X
YELLOW ("Button 3"), // Y
LB ("Button 4"),
RB ("Button 5"),
BACK ("Button 6"),
START ("Button 7"),
LEFT_STICK ("Button 8"),
RIGHT_STICK ("Button 9");
protected String code;
private Xbox360Button(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public static Xbox360Button create(String code) throws UnknownButtonException {
for (Xbox360Button button : Xbox360Button.values()) {
if (button.getCode().equals(code)) {
return button;
}
}
throw new UnknownButtonException();
}
public static Xbox360Button create(JXInputButtonEvent event) throws UnknownButtonException {
return create(event.getButton().getName());
}
}

View File

@@ -0,0 +1,62 @@
/**
* Copyright (C) 2015 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.javainput.xbox360;
import mimis.device.javainput.DirectionButton;
import mimis.device.javainput.JavaInputDevice;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.button.UnknownDirectionException;
import mimis.input.Button;
import mimis.router.Router;
import mimis.value.Action;
import base.exception.worker.ActivateException;
import de.hardcode.jxinput.event.JXInputButtonEvent;
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
public class Xbox360Device extends JavaInputDevice {
public static void main(String[] args) {
Xbox360Device device = new Xbox360Device();
Router router = new Router();
router.start();
device.setRouter(router);
device.start();
}
protected static final String TITLE = "Xbox360";
protected static final String NAME = "Controller (XBOX 360 For Windows)";
protected static Xbox360TaskMapCycle taskMapCycle;
public Xbox360Device() {
super(TITLE, NAME);
taskMapCycle = new Xbox360TaskMapCycle();
}
public void activate() throws ActivateException {
super.activate();
parser(Action.ADD, taskMapCycle.mimis);
parser(Action.ADD, taskMapCycle.player);
}
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
return Xbox360Button.create(event);
}
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
return DirectionButton.create(event);
}
}

View File

@@ -0,0 +1,59 @@
/**
* Copyright (C) 2015 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.javainput.xbox360;
import mimis.device.javainput.DirectionButton;
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 Xbox360TaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L;
public TaskMap mimis, player;
public Xbox360TaskMapCycle() {
/* Mimis */
mimis = new TaskMap();
mimis.add(
new Press(Xbox360Button.GREEN),
new Task(Action.PREVIOUS, Target.MAIN));
mimis.add(
new Press(Xbox360Button.RED),
new Task(Action.NEXT, Target.MAIN));
add(mimis);
/* Player */
player = new TaskMap();
player.add(
new Press(DirectionButton.WEST),
new Task(Action.PREVIOUS, Target.CURRENT));
player.add(
new Press(DirectionButton.EAST),
new Task(Action.NEXT, Target.CURRENT));
player.add(
new Press(DirectionButton.SOUTH),
new Task(Action.VOLUME_DOWN, Target.CURRENT));
player.add(
new Press(DirectionButton.NORTH),
new Task(Action.VOLUME_UP, Target.CURRENT));
add(player);
}
}

View File

@@ -0,0 +1,15 @@
package jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class HelloTest {
public interface HelloLibrary extends Library {
public void helloFromC();
}
public static void main(String[] args) {
HelloLibrary ctest = (HelloLibrary) Native.loadLibrary("ctest", HelloLibrary.class);
ctest.helloFromC();
}
}