mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-04-05 14:35:58 +00:00
Linux building under maven
This commit is contained in:
parent
294629a312
commit
b2fd759065
78 changed files with 418 additions and 297 deletions
1
coreAPI/.gitignore
vendored
1
coreAPI/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
|||
/build.number
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
This file modified last on 06/06/2003 by Jeff Kesselman
|
||||
|
||||
This is the source tree for the core input API.
|
||||
|
||||
Directory Organization:
|
||||
|
||||
The root contains a master ANT build.xml.
|
||||
After a successful build of the project you will have the following sub directories:
|
||||
-- apidocs Where the javadocs get built to
|
||||
-- lib Where dependant libraries are kept.
|
||||
-- bin Where the actual API is built to
|
||||
-- src The source files.
|
||||
-- src/test Execution directories and data for tests.
|
||||
|
||||
Build instructions:
|
||||
|
||||
To clean: ant clean
|
||||
To build: ant all (or just ant)
|
||||
To build docs: ant javadoc
|
||||
To test:
|
||||
Textest: A simple discovery test that dumps
|
||||
the data about the discovered controllers to stdout
|
||||
To run: ant textest
|
||||
Readtest: A test that creates a window for each discovered
|
||||
controller (or sub-controller) which displays the
|
||||
current state of all the controller's axiis.
|
||||
(Note: The windows currrently all open at the same
|
||||
place on the screen so yo uwill have to move them to
|
||||
see them all.)
|
||||
To run: ant readtest
|
||||
|
||||
|
||||
Release Info:
|
||||
Initial Release: This release contains an implementation of the input
|
||||
API designed by Mike Martak of Sun and Thomas (?) of Sony CEA for
|
||||
the WIn32 platform. All the code in src/input is cross platform. The
|
||||
Win32 code is segregated to the DirectX plugin (src/DXplugin) which
|
||||
depends on DirectInput from DX7 (or later).
|
||||
|
||||
05/09/2003: A number of bugs and problems with the DXPlugin are fixed in this
|
||||
release. This release also brings the code up to date using the DI8
|
||||
interface. This thus is the first release that requries Peter Puck's
|
||||
DX8 bindings to compile with MinGW.
|
||||
|
||||
05/09/2003 (second update):
|
||||
This version adds a new standard value type to the API.
|
||||
Axis.POV holds standard definitions for values for POV (hat) switches
|
||||
-- Axis.POV.CENTER and Axis.POV.OFF are synonmous and are
|
||||
the center position.
|
||||
-- Axis.POV.UP, Axis.POV.DOWN, Axis.POV.LEFT and Axis.POV.RIGHT
|
||||
should be self explainatory.
|
||||
Any hat that claims to be "normalized" will return these values. (It is
|
||||
recommended that all hats be normalized by the systemn specific plugins.)
|
||||
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<project name="Game Input API" basedir="." default="all">
|
||||
<target name="init">
|
||||
<property name="utils" location="../lib/jutils.jar"/>
|
||||
<mkdir dir="apidocs"/>
|
||||
<mkdir dir="classes"/>
|
||||
<mkdir dir="bin"/>
|
||||
<mkdir dir="build"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init">
|
||||
<javac srcdir="src/java" destdir="classes" debug="true" deprecation="true" source="1.4" target="1.4">
|
||||
<include name="net/**"/>
|
||||
<exclude name="**/Version.java"/>
|
||||
<!-- To add something to the classpath: -->
|
||||
<classpath>
|
||||
<pathelement location="${utils}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
<buildnumber/>
|
||||
<copy file="src/java/net/java/games/input/Version.java"
|
||||
todir="build/src/java/net/java/games/input/" overwrite="true">
|
||||
<filterset>
|
||||
<filter token="BUILD_NUMBER" value="${build.number}"/>
|
||||
<filter token="API_VERSION" value="${api.version}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
<javac srcdir="build/src/java" destdir="classes" debug="true" deprecation="true" source="1.4" target="1.4">
|
||||
<include name="net/**" />
|
||||
</javac>
|
||||
<echo message="Build version class for ${api.version} build ${build.number}"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="init,compile">
|
||||
<jar jarfile="bin/jinput-core.jar" compress="true" basedir="classes">
|
||||
<include name="net/java/games/input/*class"/>
|
||||
</jar>
|
||||
<jar jarfile="bin/jinput-test.jar" compress="true" basedir="classes">
|
||||
<include name="net/java/games/input/test/*class"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="init" description="Javadoc for my API.">
|
||||
<javadoc packagenames="net.java.games.input.*"
|
||||
destdir="apidocs"
|
||||
additionalparam="-source 1.4"
|
||||
excludepackagenames="net.java.games.input.example.*,net.java.games.input.test.*">
|
||||
<sourcepath>
|
||||
<pathelement location="src/java"/>
|
||||
</sourcepath>
|
||||
<classpath>
|
||||
<pathelement location="${utils}"/>
|
||||
</classpath>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="init" description="Clean all build products.">
|
||||
<delete dir="classes"/>
|
||||
<delete dir="bin"/>
|
||||
<delete dir="apidocs"/>
|
||||
<delete dir="build"/>
|
||||
</target>
|
||||
|
||||
<target name="all" depends="init,jar" description="Build everything.">
|
||||
<echo message="JInput has been built and jinput.jar is located in the bin directory."/>
|
||||
</target>
|
||||
</project>
|
||||
31
coreAPI/pom.xml
Normal file
31
coreAPI/pom.xml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>coreapi</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>JInput - core API</name>
|
||||
|
||||
<parent>
|
||||
<groupId>net.java.jinput</groupId>
|
||||
<artifactId>jinput-parent</artifactId>
|
||||
<version>2.0.8-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.java.jutils</groupId>
|
||||
<artifactId>jutils</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
package net.java.games.input.example;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.Event;
|
||||
import net.java.games.input.EventQueue;
|
||||
|
||||
/**
|
||||
* This class shows how to use the event queue system in JInput. It will show
|
||||
* how to get the controllers, how to get the event queue for a controller, and
|
||||
* how to read and process events from the queue.
|
||||
*
|
||||
* @author Endolf
|
||||
*/
|
||||
public class ReadAllEvents {
|
||||
|
||||
public ReadAllEvents() {
|
||||
while (true) {
|
||||
/* Get the available controllers */
|
||||
Controller[] controllers = ControllerEnvironment
|
||||
.getDefaultEnvironment().getControllers();
|
||||
if (controllers.length == 0) {
|
||||
System.out.println("Found no controllers.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < controllers.length; i++) {
|
||||
/* Remember to poll each one */
|
||||
controllers[i].poll();
|
||||
|
||||
/* Get the controllers event queue */
|
||||
EventQueue queue = controllers[i].getEventQueue();
|
||||
|
||||
/* Create an event object for the underlying plugin to populate */
|
||||
Event event = new Event();
|
||||
|
||||
/* For each object in the queue */
|
||||
while (queue.getNextEvent(event)) {
|
||||
|
||||
/*
|
||||
* Create a strug buffer and put in it, the controller name,
|
||||
* the time stamp of the event, the name of the component
|
||||
* that changed and the new value.
|
||||
*
|
||||
* Note that the timestamp is a relative thing, not
|
||||
* absolute, we can tell what order events happened in
|
||||
* across controllers this way. We can not use it to tell
|
||||
* exactly *when* an event happened just the order.
|
||||
*/
|
||||
StringBuffer buffer = new StringBuffer(controllers[i]
|
||||
.getName());
|
||||
buffer.append(" at ");
|
||||
buffer.append(event.getNanos()).append(", ");
|
||||
Component comp = event.getComponent();
|
||||
buffer.append(comp.getName()).append(" changed to ");
|
||||
float value = event.getValue();
|
||||
|
||||
/*
|
||||
* Check the type of the component and display an
|
||||
* appropriate value
|
||||
*/
|
||||
if (comp.isAnalog()) {
|
||||
buffer.append(value);
|
||||
} else {
|
||||
if (value == 1.0f) {
|
||||
buffer.append("On");
|
||||
} else {
|
||||
buffer.append("Off");
|
||||
}
|
||||
}
|
||||
System.out.println(buffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sleep for 20 milliseconds, in here only so the example doesn't
|
||||
* thrash the system.
|
||||
*/
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ReadAllEvents();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
package net.java.games.input.example;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.test.ControllerTextTest;
|
||||
|
||||
/**
|
||||
* This class shows how to read the values in a polling loop for the first mouse
|
||||
* detected. It will show how to get the available controllers, how to check the
|
||||
* type of the controller, how to read the components of the controller, and how
|
||||
* to get the data from the component.
|
||||
*
|
||||
* @author Endolf
|
||||
*/
|
||||
public class ReadFirstMouse {
|
||||
|
||||
public ReadFirstMouse() {
|
||||
/* Get the available controllers */
|
||||
Controller[] controllers = ControllerEnvironment
|
||||
.getDefaultEnvironment().getControllers();
|
||||
|
||||
/*
|
||||
* Loop through the controllers, check the type of each one, and save
|
||||
* the first mouse we find.
|
||||
*/
|
||||
Controller firstMouse = null;
|
||||
for (int i = 0; i < controllers.length && firstMouse == null; i++) {
|
||||
if (controllers[i].getType() == Controller.Type.MOUSE) {
|
||||
// Found a mouse
|
||||
firstMouse = controllers[i];
|
||||
}
|
||||
}
|
||||
if (firstMouse == null) {
|
||||
// Couldn't find a mouse
|
||||
System.out.println("Found no mouse");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
System.out.println("First mouse is: " + firstMouse.getName());
|
||||
|
||||
while (true) {
|
||||
/* Poll the controller */
|
||||
firstMouse.poll();
|
||||
|
||||
/* Get all the axis and buttons */
|
||||
Component[] components = firstMouse.getComponents();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
/* For each component, get it's name, and it's current value */
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(", ");
|
||||
}
|
||||
buffer.append(components[i].getName());
|
||||
buffer.append(": ");
|
||||
if (components[i].isAnalog()) {
|
||||
/* Get the value at the last poll of this component */
|
||||
buffer.append(components[i].getPollData());
|
||||
} else {
|
||||
if (components[i].getPollData() == 1.0f) {
|
||||
buffer.append("On");
|
||||
} else {
|
||||
buffer.append("Off");
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(buffer.toString());
|
||||
|
||||
/*
|
||||
* Sleep for 20 millis, this is just so the example doesn't thrash
|
||||
* the system.
|
||||
*/
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ReadFirstMouse();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,301 +0,0 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistribution in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materails provided with the distribution.
|
||||
*
|
||||
* Neither the name Sun Microsystems, Inc. or the names of the contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind.
|
||||
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
|
||||
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
|
||||
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
|
||||
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
|
||||
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* You acknowledge that this software is not designed or intended for us in
|
||||
* the design, construction, operation or maintenance of any nuclear facility
|
||||
*
|
||||
*****************************************************************************/
|
||||
package net.java.games.input.test;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.EventQueue;
|
||||
import net.java.games.input.Event;
|
||||
import net.java.games.input.Version;
|
||||
|
||||
public class ControllerEventTest extends JFrame{
|
||||
private static abstract class AxisPanel extends JPanel{
|
||||
Component axis;
|
||||
float data;
|
||||
|
||||
public AxisPanel(Component ax){
|
||||
axis = ax;
|
||||
setLayout(new BorderLayout());
|
||||
add(new JLabel(ax.getName()+"("+ax.getIdentifier()+")"),
|
||||
BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
public void setPollData(float data){
|
||||
this.data = data;
|
||||
renderData();
|
||||
}
|
||||
|
||||
public Component getAxis() {
|
||||
return axis;
|
||||
}
|
||||
|
||||
protected abstract void renderData();
|
||||
}
|
||||
|
||||
private static class DigitalAxisPanel extends AxisPanel {
|
||||
JLabel digitalState = new JLabel("<unread>");
|
||||
|
||||
public DigitalAxisPanel(Component ax) {
|
||||
super(ax);
|
||||
add(digitalState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
if (data == 0.0f){
|
||||
digitalState.setBackground(getBackground());
|
||||
digitalState.setText("OFF");
|
||||
} else if ( data == 1.0f) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("ON");
|
||||
}else { // shoudl never happen
|
||||
digitalState.setBackground(Color.red);
|
||||
digitalState.setText("ERR:"+data);
|
||||
}
|
||||
digitalState.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DigitalHatPanel extends AxisPanel {
|
||||
JLabel digitalState = new JLabel("<unread>");
|
||||
|
||||
public DigitalHatPanel(Component ax) {
|
||||
super(ax);
|
||||
add(digitalState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
if (data == Component.POV.OFF){
|
||||
digitalState.setBackground(getBackground());
|
||||
digitalState.setText("OFF");
|
||||
} else if ( data == Component.POV.UP) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP");
|
||||
} else if ( data == Component.POV.UP_RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP+RIGHT");
|
||||
} else if ( data == Component.POV.RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("RIGHT");
|
||||
} else if ( data == Component.POV.DOWN_RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN+RIGHT");
|
||||
} else if ( data == Component.POV.DOWN) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN");
|
||||
} else if ( data == Component.POV.DOWN_LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN+LEFT");
|
||||
} else if ( data == Component.POV.LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("LEFT");
|
||||
} else if ( data == Component.POV.UP_LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP+LEFT");
|
||||
}else { // shoudl never happen
|
||||
digitalState.setBackground(Color.red);
|
||||
digitalState.setText("ERR:"+data);
|
||||
}
|
||||
digitalState.repaint();
|
||||
}
|
||||
}
|
||||
private static class AnalogAxisPanel extends AxisPanel {
|
||||
JLabel analogState = new JLabel("<unread>");
|
||||
|
||||
public AnalogAxisPanel(Component ax) {
|
||||
super(ax);
|
||||
add(analogState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
String extra = "";
|
||||
if (getAxis().getDeadZone() >= Math.abs(data))
|
||||
extra = " (DEADZONE)";
|
||||
analogState.setText(""+data+extra);
|
||||
analogState.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class ControllerWindow extends JFrame {
|
||||
Controller ca;
|
||||
Map axes_to_panels = new HashMap();
|
||||
boolean disabled = false;
|
||||
|
||||
public ControllerWindow(JFrame frame,Controller ca){
|
||||
super(ca.getName());
|
||||
this.setName(ca.getName());
|
||||
this.ca = ca;
|
||||
Container c = this.getContentPane();
|
||||
c.setLayout(new BorderLayout());
|
||||
Component[] components = ca.getComponents();
|
||||
System.out.println("Component count = "+components.length);
|
||||
if (components.length>0) {
|
||||
int width = (int)Math.ceil(Math.sqrt(components.length));
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new GridLayout(width,0));
|
||||
for(int j=0;j<components.length;j++){
|
||||
addAxis(p,components[j]);
|
||||
}
|
||||
c.add(new JScrollPane(p),BorderLayout.CENTER);
|
||||
}
|
||||
setSize(400,400);
|
||||
setLocation(50,50);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public boolean disabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
private void setDisabled(boolean b){
|
||||
disabled = b;
|
||||
if (!disabled){
|
||||
this.setTitle(ca.getName());
|
||||
System.out.println(ca.getName()+" enabled");
|
||||
} else {
|
||||
this.setTitle(ca.getName()+" DISABLED!");
|
||||
System.out.println(ca.getName()+" disabled");
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void addAxis(JPanel p, Component ax){
|
||||
JPanel p2;
|
||||
if (ax.isAnalog()) {
|
||||
p2 = new AnalogAxisPanel(ax);
|
||||
} else {
|
||||
if (ax.getIdentifier() == Component.Identifier.Axis.POV) {
|
||||
p2 = new DigitalHatPanel(ax);
|
||||
} else {
|
||||
p2 = new DigitalAxisPanel(ax);
|
||||
}
|
||||
}
|
||||
p.add(p2);
|
||||
axes_to_panels.put(ax, p2);
|
||||
}
|
||||
|
||||
public void poll(){
|
||||
if (!ca.poll()) {
|
||||
if (!disabled()){
|
||||
setDisabled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (disabled()){
|
||||
setDisabled(false);
|
||||
}
|
||||
EventQueue event_queue = ca.getEventQueue();
|
||||
Event event = new Event();
|
||||
while (event_queue.getNextEvent(event)) {
|
||||
AxisPanel panel = (AxisPanel)axes_to_panels.get(event.getComponent());
|
||||
panel.setPollData(event.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final long HEARTBEATMS =100; // 10th of a second
|
||||
List controllers = new ArrayList();
|
||||
|
||||
public ControllerEventTest() {
|
||||
super("Controller Event Test. Version: " + Version.getVersion());
|
||||
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
|
||||
Controller[] ca = ce.getControllers();
|
||||
for(int i =0;i<ca.length;i++){
|
||||
makeController(ca[i]);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run(){
|
||||
try {
|
||||
while(true){
|
||||
for(Iterator i=controllers.iterator();i.hasNext();){
|
||||
try {
|
||||
ControllerWindow cw = (ControllerWindow)i.next();
|
||||
cw.poll();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Thread.sleep(HEARTBEATMS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
pack();
|
||||
setSize(400,400);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void makeController(Controller c) {
|
||||
Controller[] subControllers = c.getControllers();
|
||||
if (subControllers.length == 0 ) {
|
||||
createControllerWindow(c);
|
||||
} else {
|
||||
for(int i=0;i<subControllers.length;i++){
|
||||
makeController(subControllers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createControllerWindow(Controller c){
|
||||
controllers.add(new ControllerWindow(this,c));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new ControllerEventTest().setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,305 +0,0 @@
|
|||
/*
|
||||
* ConrtollerReadTest.java
|
||||
*
|
||||
* Created on May 5, 2003, 3:15 PM
|
||||
*/
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistribution in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materails provided with the distribution.
|
||||
*
|
||||
* Neither the name Sun Microsystems, Inc. or the names of the contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind.
|
||||
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
|
||||
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
|
||||
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
|
||||
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
|
||||
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* You acknowledge that this software is not designed or intended for us in
|
||||
* the design, construction, operation or maintenance of any nuclear facility
|
||||
*
|
||||
*****************************************************************************/
|
||||
package net.java.games.input.test;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import net.java.games.input.Component;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.Version;
|
||||
|
||||
public class ControllerReadTest extends JFrame{
|
||||
private abstract static class AxisPanel extends JPanel{
|
||||
Component axis;
|
||||
float data;
|
||||
|
||||
public AxisPanel(Component ax){
|
||||
axis = ax;
|
||||
setLayout(new BorderLayout());
|
||||
add(new JLabel(ax.getName()+"("+ax.getIdentifier()+")"),
|
||||
BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
public void poll(){
|
||||
data = axis.getPollData();
|
||||
renderData();
|
||||
}
|
||||
|
||||
public Component getAxis() {
|
||||
return axis;
|
||||
}
|
||||
|
||||
protected abstract void renderData();
|
||||
}
|
||||
|
||||
private static class DigitalAxisPanel extends AxisPanel {
|
||||
JLabel digitalState = new JLabel("<unread>");
|
||||
|
||||
public DigitalAxisPanel(Component ax) {
|
||||
super(ax);
|
||||
add(digitalState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
if (data == 0.0f){
|
||||
digitalState.setBackground(getBackground());
|
||||
digitalState.setText("OFF");
|
||||
} else if ( data == 1.0f) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("ON");
|
||||
}else { // shoudl never happen
|
||||
digitalState.setBackground(Color.red);
|
||||
digitalState.setText("ERR:"+data);
|
||||
}
|
||||
digitalState.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private static class DigitalHatPanel extends AxisPanel {
|
||||
JLabel digitalState = new JLabel("<unread>");
|
||||
|
||||
public DigitalHatPanel(Component ax) {
|
||||
super(ax);
|
||||
add(digitalState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
if (data == Component.POV.OFF){
|
||||
digitalState.setBackground(getBackground());
|
||||
digitalState.setText("OFF");
|
||||
} else if ( data == Component.POV.UP) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP");
|
||||
} else if ( data == Component.POV.UP_RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP+RIGHT");
|
||||
} else if ( data == Component.POV.RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("RIGHT");
|
||||
} else if ( data == Component.POV.DOWN_RIGHT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN+RIGHT");
|
||||
} else if ( data == Component.POV.DOWN) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN");
|
||||
} else if ( data == Component.POV.DOWN_LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("DOWN+LEFT");
|
||||
} else if ( data == Component.POV.LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("LEFT");
|
||||
} else if ( data == Component.POV.UP_LEFT) {
|
||||
digitalState.setBackground(Color.green);
|
||||
digitalState.setText("UP+LEFT");
|
||||
}else { // shoudl never happen
|
||||
digitalState.setBackground(Color.red);
|
||||
digitalState.setText("ERR:"+data);
|
||||
}
|
||||
digitalState.repaint();
|
||||
}
|
||||
}
|
||||
private static class AnalogAxisPanel extends AxisPanel {
|
||||
JLabel analogState = new JLabel("<unread>");
|
||||
|
||||
public AnalogAxisPanel(Component ax) {
|
||||
super(ax);
|
||||
add(analogState,BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
protected void renderData(){
|
||||
String extra = "";
|
||||
if (getAxis().getDeadZone() >= Math.abs(data))
|
||||
extra = " (DEADZONE)";
|
||||
analogState.setText(""+data+extra);
|
||||
analogState.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class ControllerWindow extends JFrame {
|
||||
Controller ca;
|
||||
List axisList = new ArrayList();
|
||||
boolean disabled = false;
|
||||
|
||||
public ControllerWindow(JFrame frame,Controller ca){
|
||||
super(ca.getName());
|
||||
this.setName(ca.getName());
|
||||
this.ca = ca;
|
||||
Container c = this.getContentPane();
|
||||
c.setLayout(new BorderLayout());
|
||||
Component[] components = ca.getComponents();
|
||||
System.out.println("Component count = "+components.length);
|
||||
if (components.length>0) {
|
||||
int width = (int)Math.ceil(Math.sqrt(components.length));
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new GridLayout(width,0));
|
||||
for(int j=0;j<components.length;j++){
|
||||
addAxis(p,components[j]);
|
||||
}
|
||||
c.add(new JScrollPane(p),BorderLayout.CENTER);
|
||||
}
|
||||
setSize(400,400);
|
||||
setLocation(50,50);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public boolean disabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
private void setDisabled(boolean b){
|
||||
disabled = b;
|
||||
if (!disabled){
|
||||
this.setTitle(ca.getName());
|
||||
System.out.println(ca.getName()+" enabled");
|
||||
} else {
|
||||
this.setTitle(ca.getName()+" DISABLED!");
|
||||
System.out.println(ca.getName()+" disabled");
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void addAxis(JPanel p, Component ax){
|
||||
JPanel p2;
|
||||
if (ax.isAnalog()) {
|
||||
p2 = new AnalogAxisPanel(ax);
|
||||
} else {
|
||||
if (ax.getIdentifier() == Component.Identifier.Axis.POV) {
|
||||
p2 = new DigitalHatPanel(ax);
|
||||
} else {
|
||||
p2 = new DigitalAxisPanel(ax);
|
||||
}
|
||||
}
|
||||
p.add(p2);
|
||||
axisList.add(p2);
|
||||
//ax.setPolling(true);
|
||||
}
|
||||
|
||||
public void poll(){
|
||||
if (!ca.poll()) {
|
||||
if (!disabled()){
|
||||
setDisabled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (disabled()){
|
||||
setDisabled(false);
|
||||
}
|
||||
//System.out.println("Polled "+ca.getName());
|
||||
for(Iterator i =axisList.iterator();i.hasNext();){
|
||||
try {
|
||||
((AxisPanel)i.next()).poll();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final long HEARTBEATMS =100; // 10th of a second
|
||||
List controllers = new ArrayList();
|
||||
|
||||
public ControllerReadTest() {
|
||||
super("Controller Read Test. Version: " + Version.getVersion());
|
||||
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
|
||||
Controller[] ca = ce.getControllers();
|
||||
for(int i =0;i<ca.length;i++){
|
||||
makeController(ca[i]);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run(){
|
||||
try {
|
||||
while(true){
|
||||
for(Iterator i=controllers.iterator();i.hasNext();){
|
||||
try {
|
||||
ControllerWindow cw = (ControllerWindow)i.next();
|
||||
cw.poll();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Thread.sleep(HEARTBEATMS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
pack();
|
||||
setSize(400,400);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void makeController(Controller c) {
|
||||
Controller[] subControllers = c.getControllers();
|
||||
if (subControllers.length == 0 ) {
|
||||
createControllerWindow(c);
|
||||
} else {
|
||||
for(int i=0;i<subControllers.length;i++){
|
||||
makeController(subControllers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createControllerWindow(Controller c){
|
||||
controllers.add(new ControllerWindow(this,c));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new ControllerReadTest().setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* ControllerScanner.java
|
||||
*
|
||||
* Created on April 14, 2003, 3:45 PM
|
||||
*/
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistribution in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materails provided with the distribution.
|
||||
*
|
||||
* Neither the name Sun Microsystems, Inc. or the names of the contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* This software is provided "AS IS," without a warranty of any kind.
|
||||
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
|
||||
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
|
||||
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
|
||||
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
|
||||
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
|
||||
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
|
||||
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
|
||||
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
|
||||
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
|
||||
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* You acknowledge that this software is not designed or intended for us in
|
||||
* the design, construction, operation or maintenance of any nuclear facility
|
||||
*
|
||||
*****************************************************************************/
|
||||
package net.java.games.input.test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author administrator
|
||||
*/
|
||||
import net.java.games.input.*;
|
||||
|
||||
public class ControllerTextTest {
|
||||
ControllerEnvironment ce;
|
||||
/** Creates a new instance of ControllerScanner */
|
||||
public ControllerTextTest() {
|
||||
ce = ControllerEnvironment.getDefaultEnvironment();
|
||||
System.out.println("JInput version: " + Version.getVersion());
|
||||
System.out.println("Controller Env = "+ce.toString());
|
||||
|
||||
|
||||
Controller[] ca = ce.getControllers();
|
||||
for(int i =0;i<ca.length;i++){
|
||||
System.out.println(ca[i].getName());
|
||||
System.out.println("Type: "+ca[i].getType().toString());
|
||||
Component[] components = ca[i].getComponents();
|
||||
System.out.println("Component Count: "+components.length);
|
||||
for(int j=0;j<components.length;j++){
|
||||
System.out.println("Component "+j+": "+components[j].getName());
|
||||
System.out.println(" Identifier: "+
|
||||
components[j].getIdentifier().getName());
|
||||
System.out.print(" ComponentType: ");
|
||||
if (components[j].isRelative()) {
|
||||
System.out.print("Relative");
|
||||
} else {
|
||||
System.out.print("Absolute");
|
||||
}
|
||||
if (components[j].isAnalog()) {
|
||||
System.out.print(" Analog");
|
||||
} else {
|
||||
System.out.print(" Digital");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("---------------------------------");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new ControllerTextTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* RumbleTest.java
|
||||
*
|
||||
* Created on 01 December 2003, 23:02
|
||||
*/
|
||||
package net.java.games.input.test;
|
||||
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.Rumbler;
|
||||
import net.java.games.input.Version;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jeremy
|
||||
*/
|
||||
public class RumbleTest {
|
||||
|
||||
/** Creates a new instance of RumbleTest */
|
||||
public RumbleTest() {
|
||||
ControllerEnvironment ca = ControllerEnvironment.getDefaultEnvironment();
|
||||
System.out.println("JInput version: " + Version.getVersion());
|
||||
Controller[] controllers = ca.getControllers();
|
||||
for(int i=0;i<controllers.length;i++) {
|
||||
System.out.println("Scanning " + controllers[i].getName());
|
||||
Rumbler[] rumblers = controllers[i].getRumblers();
|
||||
System.out.println("Found " + rumblers.length + " rumblers");
|
||||
for(int j=0;j<rumblers.length;j++) {
|
||||
System.out.println("Rumbler " + rumblers[j].getAxisName() + " on axis " + rumblers[j].getAxisIdentifier());
|
||||
System.out.println("Rumbling with intensity: " + 0.5f);
|
||||
rumblers[j].rumble(0.5f);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
System.out.println("Rumbling with intensity: " + 1.0f);
|
||||
rumblers[j].rumble(1f);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
System.out.println("Fading rumble to -1");
|
||||
for(float k=1.0f;k>-1.0f;) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
rumblers[j].rumble(k);
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
k-=((float)(System.currentTimeMillis() - startTime))/1000f;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
System.out.println("Rumbling with intensity: " + 0.0f);
|
||||
rumblers[j].rumble(0f);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new RumbleTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package net.java.games.input.test;
|
||||
|
||||
import net.java.games.input.Version;
|
||||
|
||||
public class VersionTest {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("JInput version: " + Version.getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue