Linux building under maven

This commit is contained in:
Endolf 2018-04-30 21:31:56 +01:00
parent 294629a312
commit b2fd759065
78 changed files with 418 additions and 297 deletions

32
examples/pom.xml Normal file
View file

@ -0,0 +1,32 @@
<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>examples</artifactId>
<packaging>jar</packaging>
<name>JInput - examples</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.jinput</groupId>
<artifactId>coreapi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,92 @@
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();
}
}

View file

@ -0,0 +1,85 @@
package net.java.games.input.example;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
/**
* 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();
}
}