Winamp api (qotsa) verwijderd, want ongebruikt. JXInput (hardcode) source files vervangen voor jar.
This commit is contained in:
BIN
java/lib/jxinput.jar
Normal file
BIN
java/lib/jxinput.jar
Normal file
Binary file not shown.
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* InvalidHandle.java
|
||||
*
|
||||
* Created on 9 de Outubro de 2007, 14:18
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package com.qotsa.exception;
|
||||
|
||||
/**
|
||||
* Exception to throw when Winamp Handle Fails.
|
||||
*
|
||||
* @author Francisco
|
||||
*/
|
||||
public class InvalidHandle extends Exception{
|
||||
|
||||
private static final String defaultMessage = "Invalid Handle. Please Verify if Winamp is running.";
|
||||
|
||||
/**
|
||||
* Creates a new instance of InvalidHandle
|
||||
* @param message Message to print in the stack.
|
||||
*/
|
||||
public InvalidHandle(String message) {
|
||||
|
||||
super(message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of InvalidHandle with the default message
|
||||
*/
|
||||
public InvalidHandle() {
|
||||
|
||||
super(defaultMessage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* InvalidParameter.java
|
||||
*
|
||||
* Created on 11 de Outubro de 2007, 10:53
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package com.qotsa.exception;
|
||||
|
||||
/**
|
||||
* Exception to throw when any parameter is invalid.
|
||||
*
|
||||
* @author Francisco
|
||||
*/
|
||||
public class InvalidParameter extends Exception {
|
||||
|
||||
private static final String defaultMessage = "Invalid Parameter";
|
||||
|
||||
/**
|
||||
* Creates a new instance of NegativeValueException
|
||||
* @param message Message to print in the stack.
|
||||
*/
|
||||
public InvalidParameter(String message) {
|
||||
|
||||
super(message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of NegativeValueException with the default message
|
||||
*/
|
||||
public InvalidParameter() {
|
||||
|
||||
super(defaultMessage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
||||
@(#)package.html 1.60 98/01/27
|
||||
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
Package containing the Exception Class used in the WinampController Class.
|
||||
|
||||
|
||||
<h2>Package Specification</h2>
|
||||
|
||||
<!-- Put @see and @since tags down here. -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* JNIWinamp.java
|
||||
*
|
||||
* Created on 23 de Abril de 2007, 20:41
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package com.qotsa.jni.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francisco Guimar<61>es
|
||||
*/
|
||||
final class JNIWinamp {
|
||||
|
||||
static {
|
||||
System.loadLibrary("wpcom");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if Winamp is started
|
||||
* and if not started, starts it
|
||||
* @return True - if successful running Winamp
|
||||
* False - if not successful running Winamp
|
||||
*/
|
||||
|
||||
protected static native boolean run() throws UnsatisfiedLinkError;
|
||||
|
||||
/*
|
||||
* Exit Winamp
|
||||
* @return True - if successful exit
|
||||
* False - if not successful exit
|
||||
*/
|
||||
protected static native boolean exit() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Play Winamp.
|
||||
*
|
||||
*/
|
||||
protected static native boolean play() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Stop Winamp.
|
||||
*
|
||||
*/
|
||||
protected static native boolean stop() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Resume Winamp.
|
||||
*
|
||||
*/
|
||||
protected static native boolean resume() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Pause Winamp.
|
||||
*
|
||||
*/
|
||||
protected static native boolean pause() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Go to Previous Track.
|
||||
*
|
||||
*/
|
||||
protected static native boolean previousTrack() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Go to Next Track.
|
||||
*
|
||||
*/
|
||||
protected static native boolean nextTrack() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Fowards 5 seconds on the current song.
|
||||
*
|
||||
*/
|
||||
protected static native boolean fwd5Secs() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Rewinds 5 seconds on the current song.
|
||||
*
|
||||
*/
|
||||
protected static native boolean rew5Secs() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Increase Volume.
|
||||
*
|
||||
*/
|
||||
protected static native boolean increaseVolume() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Decrease Volume.
|
||||
*
|
||||
*/
|
||||
protected static native boolean decreaseVolume() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Increase Volume.
|
||||
* @param percent Percent to Increase.
|
||||
*/
|
||||
protected static native boolean increaseVolumePercent(int percent) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Decrease Volume.
|
||||
* @param percent Percent to Decrease.
|
||||
*/
|
||||
protected static native boolean decreaseVolumePercent(int percent) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Adjust Volume
|
||||
* @param pos Position to Set Volume between 0 and 99.
|
||||
*/
|
||||
protected static native boolean setVolume(int pos) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Volume.
|
||||
* @return volume.
|
||||
*/
|
||||
protected static native int getVolume() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Go to a Specified Position in the List.
|
||||
* @param pos Position.
|
||||
*/
|
||||
protected static native boolean setPlaylistPosition(int pos) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Clear List.
|
||||
*
|
||||
*/
|
||||
protected static native boolean clearPlayList() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Refresh List<73>s Cache.
|
||||
*
|
||||
*/
|
||||
protected static native boolean refreshPlayListCache() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Return the PlayListLength.
|
||||
* @return List Length.
|
||||
*/
|
||||
protected static native int getPlayListLength() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Write a Playlist in <winampdir>\\Winamp.m3u.
|
||||
* @return List Position.
|
||||
*/
|
||||
protected static native int writePlayListToFile() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Verify if Shuffle is On.
|
||||
* @return True - On throws UnsatisfiedLinkError; False - Off.
|
||||
*/
|
||||
protected static native int isShuffleStatusOn() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Verify if Repeat is On.
|
||||
* @return True - On throws UnsatisfiedLinkError; False - Off.
|
||||
*/
|
||||
protected static native int isRepeatStatusOn() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Turn on Repeat.
|
||||
* @param True - Turn on Repeat throws UnsatisfiedLinkError; False - Turn off Repeat.
|
||||
*/
|
||||
protected static native boolean setRepeatStatusOn(boolean mode) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Turn on Shuffle.
|
||||
* @param True - Turn on Shuffle throws UnsatisfiedLinkError; False - Turn off Shuffle.
|
||||
*/
|
||||
protected static native boolean setShuffleStatusOn(boolean mode) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Append a File in the List
|
||||
* @param filename FileName to Append.
|
||||
*/
|
||||
protected static native boolean appendToPlayList(String filename) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Winamp Status.
|
||||
* @return STOPPED - Stop
|
||||
* PLAYING - play
|
||||
* PAUSED - Paused
|
||||
*/
|
||||
protected static native int getStatus() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Current List Pos.
|
||||
* @return Current List Position.
|
||||
*/
|
||||
protected static native int getListPos() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Current Track Title
|
||||
* @return Current Track Title
|
||||
*/
|
||||
protected static native String getTitle() throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Track FileName in List<73>s index.
|
||||
* @param index Track Index in the Current PlayList
|
||||
* @return Current Track FileName
|
||||
*/
|
||||
protected static native String getFileNameInList(int index) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get Song Time
|
||||
* @param mode CURRENTTIME - Currently Time in Milliseconds
|
||||
* TIMELENGHT - Song Time Length in seconds
|
||||
* @return Song Time in Seconds
|
||||
*/
|
||||
protected static native int getTime(int mode) throws UnsatisfiedLinkError;
|
||||
|
||||
/**
|
||||
* Get File Name Playing In Winamp.
|
||||
*
|
||||
* @return Current File Name.
|
||||
*/
|
||||
protected static native String getFileNamePlaying() throws UnsatisfiedLinkError;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,592 +0,0 @@
|
||||
/*
|
||||
* WinampController.java
|
||||
*
|
||||
* Created on 9 de Outubro de 2007, 14:06
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Package containing the Controller Class to communicate with Winamp.
|
||||
*
|
||||
* @author Francisco Guimar<61>es
|
||||
*/
|
||||
package com.qotsa.jni.controller;
|
||||
|
||||
import com.qotsa.exception.InvalidHandle;
|
||||
import com.qotsa.exception.InvalidParameter;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* This class is a wrapper to call JNI functions
|
||||
* to send Message to Winamp Window.
|
||||
*
|
||||
* @author Francisco Guimar<61>es
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class WinampController {
|
||||
|
||||
/**
|
||||
* Constant used as return in getTime()
|
||||
* Value = -1
|
||||
*/
|
||||
public static final int ISNOTPLAYING = -1;
|
||||
|
||||
/**
|
||||
* Constant used as parameter in getTime() method
|
||||
* Value = 0
|
||||
*/
|
||||
public static final int CURRENTTIME = 0;
|
||||
|
||||
/**
|
||||
* Constant used as parameter in getTime() method
|
||||
* Value = 1
|
||||
*/
|
||||
public static final int TIMELENGTH = 1;
|
||||
|
||||
/**
|
||||
* Constant used as return in getStatus() method
|
||||
* Value = 0
|
||||
*/
|
||||
public static final int STOPPED = 0;
|
||||
|
||||
/**
|
||||
* Constant used as return in getStatus() method
|
||||
* Value = 1
|
||||
*/
|
||||
public static final int PLAYING = 1;
|
||||
|
||||
/**
|
||||
* Constant used as return in getStatus() method
|
||||
* Value = 3
|
||||
*/
|
||||
public static final int PAUSED = 3;
|
||||
|
||||
|
||||
/**
|
||||
* Verify if Winamp is started
|
||||
* and if not started, starts it.
|
||||
*
|
||||
* @throws java.lang.Exception When the key HKEY_LOCAL_MACHINE\Software\Clients\Media\Winamp\shell\open\command
|
||||
* is not found in the register. This key is used to find Winamp Directory installation to execute it.
|
||||
*/
|
||||
|
||||
public static void run() throws Exception{
|
||||
|
||||
if (!JNIWinamp.run())
|
||||
throw new Exception("Unable to running Winamp. Verify if it is properly installed");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit Winamp.
|
||||
*
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void exit() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.exit())
|
||||
throw new InvalidHandle();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Play current file in Winamp.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void play() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.play())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop current file in Winamp.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void stop() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.stop())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume current file in Winamp.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void resume() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.resume())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause Winamp.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void pause() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.pause())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Go to Previous Track in the play list.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void previousTrack() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.previousTrack())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to Next Track in the play list.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void nextTrack() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.nextTrack())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fowards 5 seconds on the current song.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void fwd5Secs() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.fwd5Secs())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewinds 5 seconds on the current song.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void rew5Secs() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.rew5Secs())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase Volume a little bit.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void increaseVolume() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.increaseVolume())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease Volume a little bit.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void decreaseVolume() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.decreaseVolume())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase Volume.
|
||||
*
|
||||
* @param percent Percent to Increase Volume.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If percent not between 0 and 100
|
||||
*/
|
||||
public static void increaseVolumePercent (int percent) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
if ( (percent < 0) || (percent > 100) )
|
||||
throw new InvalidParameter("percent<EFBFBD>s value must be between 0 and 100");
|
||||
|
||||
if (!JNIWinamp.increaseVolumePercent(percent))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease Volume.
|
||||
*
|
||||
* @param percent Percent to Decrease Volume.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If percent not between 0 and 100
|
||||
*/
|
||||
public static void decreaseVolumePercent(int percent) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
if ( (percent < 0) || (percent > 100) )
|
||||
throw new InvalidParameter("percent<EFBFBD>s value must be between 0 and 100");
|
||||
if (!JNIWinamp.decreaseVolumePercent(percent))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust Volume.
|
||||
* Note that the pos must be between 0(0%) and 255 (100%).
|
||||
*
|
||||
* @param pos Position to Set Volume.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If pos not between 0 and 255
|
||||
*/
|
||||
public static void setVolume(int pos) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
if ( (pos < 0) || (pos > 255) )
|
||||
throw new InvalidParameter("pos value must be between 0 and 255");
|
||||
if (!JNIWinamp.setVolume(pos))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Volume.
|
||||
* @return The volume which is a number between 0 (0%) and 255(100%)
|
||||
* @throws com.qotsa.exception.InvalidHandle
|
||||
*/
|
||||
public static int getVolume() throws InvalidHandle {
|
||||
int volume = JNIWinamp.getVolume();
|
||||
if (volume == -1)
|
||||
throw new InvalidHandle();
|
||||
return volume;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Volume Percent.
|
||||
* @return Volume percent.
|
||||
* @throws com.qotsa.exception.InvalidHandle
|
||||
*/
|
||||
public static int getVolumePercent() throws InvalidHandle {
|
||||
|
||||
int volume = getVolume();
|
||||
int percent = (volume * 100) / 255;
|
||||
return percent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts Winamp.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws java.lang.Exception When failed to restart Winamp.
|
||||
*/
|
||||
public static void restart() throws InvalidHandle, Exception {
|
||||
|
||||
exit();
|
||||
run();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Go to a Specified Position in the List. This method doesn<73>t play.
|
||||
* Just set list position. If you wanna play call play() after set position.
|
||||
* Parameter pos is Zero-based index.
|
||||
* @param pos Position.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If pos is negative or greater than List Length.
|
||||
*/
|
||||
public static void setPlaylistPosition(int pos) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
int listLength = getPlayListLength();
|
||||
if ( (pos < 0) || ( (pos + 1) > listLength) )
|
||||
throw new InvalidParameter("Position is invalid in the list.");
|
||||
if (!JNIWinamp.setPlaylistPosition(pos))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear Winamp's internal playlist.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void clearPlayList() throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.clearPlayList())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the playlist cache buffer.
|
||||
* Call this if you want it to go refetch titles for tracks in the list.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void refreshPlayListCache() throws InvalidHandle{
|
||||
|
||||
if (!JNIWinamp.refreshPlayListCache())
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the PlayListLength.
|
||||
*
|
||||
* @return List Length.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static int getPlayListLength() throws InvalidHandle {
|
||||
|
||||
int length = JNIWinamp.getPlayListLength();
|
||||
if (length == -1)
|
||||
throw new InvalidHandle();
|
||||
return length;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a Playlist in winampDirInstallation\\Winamp.m3u.
|
||||
* This is default Winamp IPC Default. If you wanna change this,
|
||||
* just rename the file you<6F>ve created.
|
||||
*
|
||||
* @return Current List Position.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static int writePlayListToFile() throws InvalidHandle {
|
||||
|
||||
int playListPos = JNIWinamp.writePlayListToFile();
|
||||
if (playListPos == -1)
|
||||
throw new InvalidHandle();
|
||||
return playListPos;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if Shuffle is On.
|
||||
*
|
||||
* @return True - On ; False - Off.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static boolean isShuffleStatusOn() throws InvalidHandle {
|
||||
|
||||
int status = JNIWinamp.isShuffleStatusOn();
|
||||
if (status == -1)
|
||||
throw new InvalidHandle();
|
||||
return (status == 1 ? true : false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if Repeat is On.
|
||||
*
|
||||
* @return True - On ; False - Off.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static boolean isRepeatStatusOn() throws InvalidHandle {
|
||||
|
||||
int status = JNIWinamp.isRepeatStatusOn();
|
||||
if (status == -1)
|
||||
throw new InvalidHandle();
|
||||
return (status == 1 ? true : false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on Repeat.
|
||||
*
|
||||
* @param mode True - Turn on Repeat ; False - Turn off Repeat.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void setRepeatStatusOn(boolean mode) throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.setRepeatStatusOn(mode))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on Shuffle.
|
||||
*
|
||||
* @param mode True - Turn on Shuffle ; False - Turn off Shuffle.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static void setShuffleStatusOn(boolean mode) throws InvalidHandle {
|
||||
|
||||
if (!JNIWinamp.setShuffleStatusOn(mode))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a File into the List.
|
||||
*
|
||||
* @param filename FileName to Append in the list.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If the filename is an invalid path.
|
||||
*/
|
||||
public static void appendToPlayList(String filename) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
File file = new File(filename);
|
||||
if (!file.exists())
|
||||
throw new InvalidParameter("File doesn<73>t exists.");
|
||||
if (!JNIWinamp.appendToPlayList(filename))
|
||||
throw new InvalidHandle();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Winamp Status.
|
||||
*
|
||||
* @return STOPPED - Stop
|
||||
* PLAYING - play
|
||||
* PAUSED - Paused
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static int getStatus() throws InvalidHandle {
|
||||
|
||||
int status = JNIWinamp.getStatus();
|
||||
if (status == -1)
|
||||
throw new InvalidHandle();
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current List Pos.
|
||||
*
|
||||
* @return Current List Position.
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static int getListPos() throws InvalidHandle {
|
||||
|
||||
int pos = JNIWinamp.getListPos();
|
||||
if (pos == -1)
|
||||
throw new InvalidHandle();
|
||||
return pos;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Track Title.
|
||||
*
|
||||
* @return Current Track Title
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
*/
|
||||
public static String getTitle() throws InvalidHandle {
|
||||
|
||||
String title = JNIWinamp.getTitle();
|
||||
if (title == null)
|
||||
throw new InvalidHandle();
|
||||
return title;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Track FileName.
|
||||
* Parameter pos is Zero-based index.
|
||||
*
|
||||
* @return Current Track FileName
|
||||
* @param pos Track Position in the Current PlayList
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter If pos is negative or greater than List Length
|
||||
*/
|
||||
public static String getFileNameInList(int pos) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
int listLength = getPlayListLength();
|
||||
if ( (pos < 0) || (pos > listLength) )
|
||||
throw new InvalidParameter("Position is invalid in the list.");
|
||||
String filename = JNIWinamp.getFileNameInList(pos);
|
||||
if (filename == null)
|
||||
throw new InvalidHandle();
|
||||
return filename;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Song Time.
|
||||
*
|
||||
* @return Time Song (depends on Param mode) or
|
||||
* ISNOTPLAYING if there is no info about time because it not starts to play.
|
||||
* @param mode CURRENTTIME - Currently Time in Milliseconds
|
||||
* TIMELENGHT - Song Time Length in seconds
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter if parameter is not CURRENTTIME or TIMELENGTH.
|
||||
*/
|
||||
public static int getTime(int mode) throws InvalidHandle, InvalidParameter {
|
||||
|
||||
if (mode != CURRENTTIME && mode != TIMELENGTH)
|
||||
throw new InvalidParameter();
|
||||
int time = JNIWinamp.getTime(mode);
|
||||
if (time == -2)
|
||||
throw new InvalidHandle();
|
||||
return time;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fowards n Tracks in Play List.
|
||||
*
|
||||
* @param n Number of Tracks to Foward
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter if n is negative or Zero.
|
||||
*/
|
||||
public static void fwdTracks(int n) throws InvalidParameter, InvalidHandle {
|
||||
|
||||
if (n <= 0)
|
||||
throw new InvalidParameter("Value must be Positive");
|
||||
int pos = getListPos();
|
||||
int lengthList = getPlayListLength();
|
||||
int newPos = pos + n;
|
||||
if (newPos > lengthList ) {
|
||||
setPlaylistPosition(lengthList);
|
||||
play();
|
||||
}
|
||||
else {
|
||||
setPlaylistPosition(newPos);
|
||||
play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewinds n Tracks in Play List.
|
||||
*
|
||||
* @param n Number of Tracks to Rewind
|
||||
* @throws com.qotsa.exception.InvalidHandle When the Winamp Windows is not handle(in most case, it means that winamp is not running)
|
||||
* @throws com.qotsa.exception.InvalidParameter if n is negative or Zero.
|
||||
*/
|
||||
public static void rewTracks(int n) throws InvalidParameter, InvalidHandle {
|
||||
|
||||
if (n <= 0)
|
||||
throw new InvalidParameter("Value must be Positive");
|
||||
int pos = getListPos();
|
||||
int lengthList = getPlayListLength();
|
||||
int newPos = pos - n;
|
||||
if (newPos < 0 ) {
|
||||
setPlaylistPosition(0);
|
||||
play();
|
||||
}
|
||||
else {
|
||||
setPlaylistPosition(newPos);
|
||||
play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get File Name Playing In Winamp.
|
||||
*
|
||||
* @return Current File Name.
|
||||
*/
|
||||
public static String getFileNamePlaying() throws InvalidHandle {
|
||||
|
||||
String fileName = JNIWinamp.getFileNamePlaying();
|
||||
if (fileName == null)
|
||||
throw new InvalidHandle();
|
||||
return fileName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
|
||||
@(#)package.html 1.60 98/01/27
|
||||
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
Package containing the Controller Class to communicate with Winamp.
|
||||
|
||||
|
||||
<h2>Package Specification</h2>
|
||||
|
||||
<!-- Put @see and @since tags down here. -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,72 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 19. Dezember 2001, 21:58
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
/**
|
||||
* The Axis interface describes the most common feature of a joystick or other input devices.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface Axis extends Feature
|
||||
{
|
||||
// Enumeration of axes.
|
||||
final static int ID_X = 0;
|
||||
final static int ID_Y = 1;
|
||||
final static int ID_Z = 2;
|
||||
final static int ID_ROTX = 3;
|
||||
final static int ID_ROTY = 4;
|
||||
final static int ID_ROTZ = 5;
|
||||
final static int ID_SLIDER0 = 6;
|
||||
final static int ID_SLIDER1 = 7;
|
||||
final static int NUMBER_OF_ID = 8;
|
||||
|
||||
// Enumeration of axis types
|
||||
final static int TRANSLATION = 0;
|
||||
final static int ROTATION = 1;
|
||||
final static int SLIDER = 2;
|
||||
|
||||
/**
|
||||
* Retrieve the type of the axis.
|
||||
* The type is describes the meaning and the range of values of the axis.
|
||||
* <p>
|
||||
* <code>TRANSLATION</code> typed axes denote a translational deviation from a center
|
||||
* position. This can be e.g. the common, basic joystick axes.
|
||||
* The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>.
|
||||
* <p>
|
||||
* <code>ROTATION</code> typed axes denote a rotational deviation from a center
|
||||
* position. Something on the stick is turned or twisted.
|
||||
* The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>.
|
||||
* <p>
|
||||
* <code>SLIDER</code> typed axes denote a shifting device without a center position.
|
||||
* A good sample is a throttle control.
|
||||
* The range of <code>getValue()</code> is <code>[0.0,1.0]</code>.
|
||||
*
|
||||
* @return [ TRANSLATION | ROTATION | SLIDER ]
|
||||
*/
|
||||
int getType();
|
||||
|
||||
/**
|
||||
* Returns the current value of the axis.
|
||||
* The range of the result depends on the axis type.
|
||||
*
|
||||
* @return value [-1.0,1.0] or [0.0,1.0]
|
||||
*/
|
||||
double getValue();
|
||||
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the axis.
|
||||
*
|
||||
* @return resolution, e.g. 2^-16
|
||||
*/
|
||||
double getResolution();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 19. Dezember 2001, 21:58
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface Button extends Feature
|
||||
{
|
||||
// Enumeration of button types
|
||||
final static int PUSHBUTTON = 0;
|
||||
final static int TOGGLEBUTTON = 1;
|
||||
|
||||
/**
|
||||
* Retrieve the type of the button.
|
||||
* Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down.
|
||||
* Togglebuttons will change their state once they are pressed and keep that state
|
||||
* until they are pressed again.
|
||||
* @return [ PUSHBUTTON | TOGGLEBUTTON ]
|
||||
*/
|
||||
int getType();
|
||||
|
||||
/**
|
||||
* Tells the state of the button at last update.
|
||||
*/
|
||||
boolean getState();
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 27. Dezember 2001, 23:33
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface Directional extends Feature
|
||||
{
|
||||
/**
|
||||
* If the Directional has a center position where it points to no direction, this
|
||||
* flag is true when this position is reached.
|
||||
*/
|
||||
boolean isCentered();
|
||||
|
||||
/**
|
||||
* Retrieve the direction pointed to.
|
||||
* Value is given in 1/100 degree, [0,36000]
|
||||
*/
|
||||
int getDirection();
|
||||
|
||||
/**
|
||||
* Retrieve the analog value pointing to the angle described by
|
||||
* <code>getDirection()</code>.
|
||||
* For coolie hats this will be either 1,0 for any direction or 0.0
|
||||
* when <code>isCentered()==true</code>.
|
||||
*/
|
||||
double getValue();
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the value returned by <code>getValue()</code>.
|
||||
*
|
||||
* @return resolution, e.g. 1.0 for coolie hats
|
||||
*/
|
||||
double getResolution();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 27. Dezember 2001, 00:19
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
/**
|
||||
* An input device offers a set of features (otherwise it would be pretty useless).
|
||||
* Features in this sense can be axes, buttons and a feature callede <e>directional</e> here.
|
||||
* Coolie hats are typical directionals because they control a direction (to look at e.g.).
|
||||
* <p>
|
||||
* There are no concrete classes directly derived from <code>Feature</code> - it only
|
||||
* provides a basis for other interfaces.
|
||||
*
|
||||
* @see Axis
|
||||
* @see SelectButton
|
||||
* @see Directional
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public abstract interface Feature
|
||||
{
|
||||
/**
|
||||
* Features may have a name provided e.g. by the driver.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
boolean hasChanged();
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 19. Dezember 2001, 21:47
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
/**
|
||||
* The <code>JXInputDevise</code> is the main entrypoint to the jxinput package.
|
||||
* <p>
|
||||
* A JXInputDevice represents one physical device like a joystick, a gamepad or
|
||||
* even some emulation (e.g. using keyboard) that implements the interface.
|
||||
* <p>
|
||||
* The basis task of a <code>JXInputDevise</code> is to maintain a consistent state of all its features.
|
||||
* <br>
|
||||
* It is save to distribute the <code>Feature</code> objects into application without worrying
|
||||
* about someone else performing an <code>update</code> method and thereby destructing the consistent state.
|
||||
* <p>
|
||||
* An additional task is to provide basic device features information like number of axes, buttons
|
||||
* and directional features.
|
||||
*
|
||||
* @see Feature
|
||||
* @see JXInputManager
|
||||
*
|
||||
* @author Herkules
|
||||
* @version 0.2beta
|
||||
*/
|
||||
public interface JXInputDevice
|
||||
{
|
||||
/**
|
||||
* @directed
|
||||
*/
|
||||
/*#Features lnkFeatures;*/
|
||||
|
||||
/**
|
||||
*@link aggregationByValue
|
||||
*/
|
||||
/*#Feature lnkFeature;*/
|
||||
|
||||
/**
|
||||
* Devices may have a name.
|
||||
* This name might be provided by a system dependant driver.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/** Actual number of available axes. */
|
||||
int getNumberOfAxes();
|
||||
|
||||
/** Actual number of available buttons. */
|
||||
int getNumberOfButtons();
|
||||
|
||||
/** Actual number of available directional features. */
|
||||
int getNumberOfDirectionals();
|
||||
|
||||
/** Maximum number of axes as an upper bound for index values. */
|
||||
int getMaxNumberOfAxes();
|
||||
|
||||
/** Maximum number of buttons as an upper bound for index values. */
|
||||
int getMaxNumberOfButtons();
|
||||
|
||||
/** Maximum number of directional features as an upper bound for index values. */
|
||||
int getMaxNumberOfDirectionals();
|
||||
|
||||
Axis getAxis( int idx );
|
||||
Button getButton( int idx );
|
||||
Directional getDirectional( int idx );
|
||||
}
|
||||
|
||||
@@ -1,233 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 29. Dezember 2001, 02:17
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput;
|
||||
|
||||
//
|
||||
// Import driver stuff
|
||||
//
|
||||
import de.hardcode.jxinput.directinput.DirectInputDevice;
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
import de.hardcode.jxinput.keyboard.JXKeyboardInputDevice;
|
||||
import de.hardcode.jxinput.virtual.JXVirtualInputDevice;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.awt.Component;
|
||||
|
||||
|
||||
/**
|
||||
* Manages the available instances of JXInputDevice.
|
||||
* It holds the one central update method which synchronizes with the physical device.
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXInputManager
|
||||
{
|
||||
|
||||
/** Remember when the last update took place. */
|
||||
private static long mTimeOfLastUpdate;
|
||||
|
||||
/** Maintain a list of devices. */
|
||||
private final static ArrayList mDevices = new ArrayList();
|
||||
|
||||
/** Maintain a list of direct input devices. */
|
||||
private final static ArrayList mDIDevices = new ArrayList();
|
||||
|
||||
/** Maintain a list of virtual devices. */
|
||||
private final static ArrayList mVirtualDevices = new ArrayList();
|
||||
|
||||
/** Maintain a list of keyboard devices. */
|
||||
private final static ArrayList mKBDevices = new ArrayList();
|
||||
|
||||
/**
|
||||
* Statically retrieve all DirectInputDevices available.
|
||||
*/
|
||||
static
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @directed
|
||||
*/
|
||||
/*#JXInputDevice lnkJXInputDevice;*/
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXInputManager.
|
||||
* This is prohibited - it only has static members.
|
||||
*/
|
||||
private JXInputManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the number of available input devices.
|
||||
*/
|
||||
public static int getNumberOfDevices()
|
||||
{
|
||||
return mDevices.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivers the JXInputDevice with the desired index.
|
||||
* <p>
|
||||
* Take care that <code>idx < getNumberOfDevices()</code>!
|
||||
*/
|
||||
public static JXInputDevice getJXInputDevice( int idx )
|
||||
{
|
||||
//
|
||||
// Be well-behaved even if idx is out of range.
|
||||
//
|
||||
if ( idx >= mDevices.size() )
|
||||
return null;
|
||||
return (JXInputDevice)mDevices.get( idx );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Master reset for all devices and events.
|
||||
* After calling reset(), better forget all devices created or retrieved.
|
||||
* They are no longer valid.
|
||||
* Event listeners will no longer be called and should be discarded.
|
||||
*/
|
||||
synchronized public static void reset()
|
||||
{
|
||||
JXInputEventManager.reset();
|
||||
|
||||
mDevices.clear();
|
||||
|
||||
mVirtualDevices.clear();
|
||||
mDIDevices.clear();
|
||||
|
||||
DirectInputDevice.reset();
|
||||
|
||||
for ( int i = 0; i < DirectInputDevice.getNumberOfDevices(); ++i )
|
||||
{
|
||||
DirectInputDevice dev = new DirectInputDevice( i );
|
||||
mDevices.add( dev );
|
||||
mDIDevices.add( dev );
|
||||
}
|
||||
|
||||
// I have to call updateFeatures one time here during initialization
|
||||
// bc. I experienced difficulties otherwise while running with the
|
||||
// J3D sensoring stuff!
|
||||
// updateFeatures();
|
||||
DirectInputDevice.update();
|
||||
|
||||
int n = mKBDevices.size();
|
||||
for ( int i = 0; i < n; ++i )
|
||||
((JXKeyboardInputDevice)mKBDevices.get( i )).shutdown();
|
||||
mKBDevices.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the (shared) state of all features in one step.
|
||||
* This method asks the actual device for a consistant state.
|
||||
* After calling this method, all features may have new values.
|
||||
* updateFeatures() is meant to be called e.g. once per frame in a gaming environment.
|
||||
*/
|
||||
public static void updateFeatures()
|
||||
{
|
||||
// Get timing
|
||||
long now = System.currentTimeMillis();
|
||||
long deltaT = now - mTimeOfLastUpdate;
|
||||
|
||||
// Update available driver
|
||||
DirectInputDevice.update();
|
||||
|
||||
//
|
||||
// Update the virtual devices.
|
||||
//
|
||||
Iterator vdevices = mVirtualDevices.iterator();
|
||||
while ( vdevices.hasNext() )
|
||||
{
|
||||
((JXVirtualInputDevice)vdevices.next()).update( deltaT );
|
||||
}
|
||||
|
||||
// Remember time
|
||||
mTimeOfLastUpdate = now;
|
||||
|
||||
// Fire all events.
|
||||
JXInputEventManager.trigger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get time when last update occurred.
|
||||
* @return tickervalue in milliseconds
|
||||
*/
|
||||
public static long getLastUpdateTime()
|
||||
{
|
||||
return mTimeOfLastUpdate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new pseudo-device.
|
||||
*/
|
||||
public static JXKeyboardInputDevice createKeyboardDevice()
|
||||
{
|
||||
JXKeyboardInputDevice d = new JXKeyboardInputDevice();
|
||||
mDevices.add( d );
|
||||
mKBDevices.add( d );
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new pseudo-device listening to a Swing component.
|
||||
* Make sure that the component also has the keyboard focus!!
|
||||
*/
|
||||
public static JXKeyboardInputDevice createKeyboardDevice( Component comp )
|
||||
{
|
||||
JXKeyboardInputDevice d = new JXKeyboardInputDevice( comp );
|
||||
mDevices.add( d );
|
||||
mKBDevices.add( d );
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a keyboard device again e.g. when the corresponding
|
||||
* JComponent gets deleted.
|
||||
*/
|
||||
public static void deleteKeyboardDevice( JXKeyboardInputDevice dev )
|
||||
{
|
||||
mDevices.remove( dev );
|
||||
mKBDevices.remove( dev );
|
||||
((JXKeyboardInputDevice)dev).shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new pseudo-device.
|
||||
*/
|
||||
public static JXVirtualInputDevice createVirtualDevice()
|
||||
{
|
||||
JXVirtualInputDevice d = new JXVirtualInputDevice();
|
||||
mDevices.add( d );
|
||||
mVirtualDevices.add( d );
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a virtual device again.
|
||||
*/
|
||||
public static void deleteVirtualDevice( JXVirtualInputDevice dev )
|
||||
{
|
||||
mDevices.remove( dev );
|
||||
mVirtualDevices.remove( dev );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 27. Dezember 2001, 00:14
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class DIAxis implements Axis
|
||||
{
|
||||
private final int mDeviceIdx;
|
||||
private final int mIdx;
|
||||
|
||||
/**
|
||||
* Creates a new instance of DIAxis.
|
||||
*/
|
||||
DIAxis( int devidx, int idx )
|
||||
{
|
||||
mDeviceIdx = devidx;
|
||||
mIdx = idx;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return DirectInputDriver.getAxisName( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public double getValue()
|
||||
{
|
||||
return DirectInputDriver.getAxisValue( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return DirectInputDriver.getAxisType( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the axis.
|
||||
*
|
||||
* @return resolution, e.g. 2^-16
|
||||
*/
|
||||
public double getResolution()
|
||||
{
|
||||
// extend the driver here!!
|
||||
// Here I assume typical 16 bit resolution
|
||||
return ( getType() == Axis.SLIDER ? 1.0/65536.0 : 2.0/65536.0 ) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 27. Dezember 2001, 00:14
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class DIButton implements Button
|
||||
{
|
||||
private final int mDeviceIdx;
|
||||
private final int mIdx;
|
||||
|
||||
/**
|
||||
* Creates a new instance of DIButton.
|
||||
*/
|
||||
DIButton( int devidx, int idx )
|
||||
{
|
||||
mDeviceIdx = devidx;
|
||||
mIdx = idx;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return DirectInputDriver.getButtonName( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
/**
|
||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return DirectInputDriver.getButtonType( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
public boolean getState()
|
||||
{
|
||||
return DirectInputDriver.getButtonState( mDeviceIdx, mIdx );
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 27. Dezember 2001, 23:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import de.hardcode.jxinput.Directional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class DIDirectional implements Directional
|
||||
{
|
||||
private final int mDeviceIdx;
|
||||
private final int mIdx;
|
||||
|
||||
/**
|
||||
* Creates a new instance of DIDirectional.
|
||||
*/
|
||||
DIDirectional( int devidx, int idx )
|
||||
{
|
||||
mDeviceIdx = devidx;
|
||||
mIdx = idx;
|
||||
}
|
||||
|
||||
/** Features may have a name provided e.g. by the driver. */
|
||||
public String getName()
|
||||
{
|
||||
return DirectInputDriver.getDirectionalName( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
/**
|
||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCentered()
|
||||
{
|
||||
return ( 0xffff == (DirectInputDriver.getDirection( mDeviceIdx, mIdx ) & 0xffff) );
|
||||
}
|
||||
|
||||
public int getDirection()
|
||||
{
|
||||
return isCentered() ? 0 : DirectInputDriver.getDirection( mDeviceIdx, mIdx );
|
||||
}
|
||||
|
||||
public double getValue()
|
||||
{
|
||||
if ( isCentered() )
|
||||
return 0.0;
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the value returned by <code>getValue()</code>.
|
||||
*
|
||||
* @return resolution, e.g. 1.0 for coolie hats
|
||||
*/
|
||||
public double getResolution()
|
||||
{
|
||||
// DI POV always return 0.0 or 1.0, so the resolution is 1.0.
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 26. Dezember 2001, 00:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class DirectInputDevice implements JXInputDevice
|
||||
{
|
||||
int mDeviceIdx;
|
||||
|
||||
private DIAxis[] mAxes;
|
||||
private DIButton[] mButtons;
|
||||
private DIDirectional[] mDirectionals;
|
||||
|
||||
/**
|
||||
* The number of DirectInput devices available with the driver.
|
||||
*/
|
||||
public static int getNumberOfDevices()
|
||||
{
|
||||
if ( DirectInputDriver.isAvailable() )
|
||||
return DirectInputDriver.getNumberOfDevices();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the state of all devices.
|
||||
*/
|
||||
public static void update()
|
||||
{
|
||||
if ( DirectInputDriver.isAvailable() )
|
||||
DirectInputDriver.nativeupdate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of DirectInputDevice.
|
||||
*/
|
||||
public DirectInputDevice( int devidx )
|
||||
{
|
||||
mDeviceIdx = devidx;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the DirectInput connection.
|
||||
*/
|
||||
public static void reset()
|
||||
{
|
||||
if ( DirectInputDriver.isAvailable() )
|
||||
DirectInputDriver.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialisation of fields.
|
||||
*/
|
||||
private final void init()
|
||||
{
|
||||
//
|
||||
// Allocate arrays for max. number of features
|
||||
//
|
||||
mAxes = new DIAxis [ getMaxNumberOfAxes() ];
|
||||
mButtons = new DIButton [ getMaxNumberOfButtons() ];
|
||||
mDirectionals = new DIDirectional [ getMaxNumberOfDirectionals() ];
|
||||
|
||||
//
|
||||
// Fill arrays due to the state of the driver.
|
||||
//
|
||||
for ( int i = 0; i < mAxes.length; ++i )
|
||||
{
|
||||
if ( DirectInputDriver.isAxisAvailable( mDeviceIdx, i ) )
|
||||
mAxes[ i ] = new DIAxis( mDeviceIdx, i );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < mButtons.length; ++i )
|
||||
{
|
||||
if ( DirectInputDriver.isButtonAvailable( mDeviceIdx, i ) )
|
||||
mButtons[ i ] = new DIButton( mDeviceIdx, i );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < mDirectionals.length; ++i )
|
||||
{
|
||||
if ( DirectInputDriver.isDirectionalAvailable( mDeviceIdx, i ) )
|
||||
mDirectionals[ i ] = new DIDirectional( mDeviceIdx, i );
|
||||
}
|
||||
}
|
||||
|
||||
/** Devices may have a name. */
|
||||
public String getName()
|
||||
{
|
||||
String name = DirectInputDriver.getName( mDeviceIdx );
|
||||
if ( null == name )
|
||||
return "Win32 DirectInput Joystick";
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/** Actual number of available buttons. */
|
||||
public int getNumberOfButtons()
|
||||
{
|
||||
return DirectInputDriver.getNumberOfButtons( mDeviceIdx );
|
||||
}
|
||||
|
||||
/** Actual number of available axes. */
|
||||
public int getNumberOfAxes()
|
||||
{
|
||||
return DirectInputDriver.getNumberOfAxes( mDeviceIdx );
|
||||
}
|
||||
|
||||
/** Actual number of available directional features. */
|
||||
public int getNumberOfDirectionals()
|
||||
{
|
||||
return DirectInputDriver.getNumberOfDirectionals( mDeviceIdx );
|
||||
}
|
||||
|
||||
/** Maximum number of buttons as an upper bound for index values. */
|
||||
public int getMaxNumberOfButtons()
|
||||
{
|
||||
return DirectInputDriver.getMaxNumberOfButtons();
|
||||
}
|
||||
|
||||
/** Maximum number of axes as an upper bound for index values. */
|
||||
public int getMaxNumberOfAxes()
|
||||
{
|
||||
return DirectInputDriver.getMaxNumberOfAxes();
|
||||
}
|
||||
|
||||
/** Maximum number of available directional features. */
|
||||
public int getMaxNumberOfDirectionals()
|
||||
{
|
||||
return DirectInputDriver.getMaxNumberOfDirectionals();
|
||||
}
|
||||
|
||||
|
||||
public Axis getAxis(int idx)
|
||||
{
|
||||
return mAxes[ idx ];
|
||||
}
|
||||
|
||||
public Button getButton(int idx)
|
||||
{
|
||||
return mButtons[ idx ];
|
||||
}
|
||||
|
||||
public Directional getDirectional(int idx)
|
||||
{
|
||||
return mDirectionals[ idx ];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 19. Dezember 2001, 22:44
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* DirectInputDriver: the connection to the Win32 joystick.
|
||||
* There is only one allowed, so the layout of this class is merely static.
|
||||
*
|
||||
* History:
|
||||
*
|
||||
* Changes since 0.1beta:
|
||||
* - support of multiple devices addressed by the <code>dev</code> index
|
||||
*
|
||||
*
|
||||
* @author Herkules
|
||||
* @version 0.2beta
|
||||
*/
|
||||
class DirectInputDriver
|
||||
{
|
||||
private final static String NATIVE_LIB_NAME = "jxinput";
|
||||
|
||||
/** Remember wether nativeinit() succeeded. */
|
||||
static boolean sIsOperational = false;
|
||||
|
||||
//
|
||||
// Static arrays to hold the values.
|
||||
//
|
||||
private static double [][] sAxisValues;
|
||||
private static boolean [][] sButtonStates;
|
||||
private static int [][] sDirectionalValues;
|
||||
|
||||
/**
|
||||
* Perform the static initialization.
|
||||
*/
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
// Load the native lib.
|
||||
System.loadLibrary( NATIVE_LIB_NAME );
|
||||
|
||||
init();
|
||||
}
|
||||
catch( SecurityException e )
|
||||
{
|
||||
Log.logger.warning("Native library jxinput not loaded due to a SecurityException.");
|
||||
}
|
||||
catch( UnsatisfiedLinkError e )
|
||||
{
|
||||
Log.logger.info("Native library jxinput not loaded due to an UnsatisfiedLinkError.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static void init()
|
||||
{
|
||||
sIsOperational = false;
|
||||
//
|
||||
// Initialize it.
|
||||
//
|
||||
if ( nativeinit() )
|
||||
{
|
||||
int devs = getNumberOfDevices();
|
||||
sAxisValues = new double [ devs ][ DirectInputDriver.getMaxNumberOfAxes() ];
|
||||
sButtonStates = new boolean [ devs ][ DirectInputDriver.getMaxNumberOfButtons() ];
|
||||
sDirectionalValues = new int [ devs ][ DirectInputDriver.getMaxNumberOfDirectionals() ];
|
||||
|
||||
// Bind the native lib to my variables.
|
||||
bind();
|
||||
|
||||
// Remember I am fine.
|
||||
sIsOperational = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static ctor of DirectInputDriver.
|
||||
* No object will be created due to the static layout.
|
||||
*/
|
||||
private DirectInputDriver()
|
||||
{
|
||||
}
|
||||
|
||||
// Administration
|
||||
private static native boolean nativeinit();
|
||||
private static native void nativeexit();
|
||||
private static native void bind();
|
||||
|
||||
static native int getNumberOfDevices();
|
||||
|
||||
// Configuration
|
||||
static native String getName( int dev );
|
||||
static native int getNumberOfAxes( int dev );
|
||||
static native int getNumberOfButtons( int dev );
|
||||
static native int getNumberOfDirectionals( int dev );
|
||||
static native int getMaxNumberOfAxes();
|
||||
static native int getMaxNumberOfButtons();
|
||||
static native int getMaxNumberOfDirectionals();
|
||||
|
||||
static native boolean isAxisAvailable( int dev, int idx );
|
||||
static native String getAxisName( int dev, int idx );
|
||||
static native int getAxisType( int dev, int idx );
|
||||
|
||||
static native boolean isButtonAvailable( int dev, int idx );
|
||||
static native String getButtonName( int dev, int idx );
|
||||
static native int getButtonType( int dev, int idx );
|
||||
|
||||
static native boolean isDirectionalAvailable( int dev, int idx );
|
||||
static native String getDirectionalName( int dev, int idx );
|
||||
|
||||
// Operation
|
||||
static native void nativeupdate();
|
||||
|
||||
|
||||
public static boolean isAvailable()
|
||||
{
|
||||
return sIsOperational;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shutdown the device and free all Win32 resources.
|
||||
* It is not a good idea to access any joystick features after
|
||||
* <code>shutdown()</code>.
|
||||
*/
|
||||
static void shutdown()
|
||||
{
|
||||
nativeexit();
|
||||
sAxisValues = null;
|
||||
sButtonStates = null;
|
||||
sDirectionalValues = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset the device and free all Win32 resources.
|
||||
*/
|
||||
static void reset()
|
||||
{
|
||||
shutdown();
|
||||
init();
|
||||
}
|
||||
|
||||
static double getAxisValue( int dev, int idx )
|
||||
{
|
||||
return sAxisValues[ dev ][ idx ];
|
||||
}
|
||||
|
||||
static boolean getButtonState( int dev, int idx )
|
||||
{
|
||||
return sButtonStates[ dev ][ idx ];
|
||||
}
|
||||
|
||||
static int getDirection( int dev, int idx )
|
||||
{
|
||||
return sDirectionalValues[ dev ][ idx ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main (String args[])
|
||||
{
|
||||
|
||||
if ( ! sIsOperational )
|
||||
return;
|
||||
|
||||
for( int i = 0; i < 5000; ++i )
|
||||
nativeupdate();
|
||||
|
||||
shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 29. Oktober 2002, 22:57
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.directinput;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class Log
|
||||
{
|
||||
public final static Logger logger = Logger.getLogger( Log.class.getPackage().getName() );
|
||||
|
||||
// static
|
||||
// {
|
||||
// logger.setLevel( Level.ALL );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Creates a new instance of Log.
|
||||
*/
|
||||
private Log()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:33
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
/**
|
||||
* Represents an event coming from an axis.
|
||||
* @author Joerg Plewe
|
||||
*/
|
||||
public class JXInputAxisEvent
|
||||
{
|
||||
private final Axis mAxis;
|
||||
double mDelta;
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXInputEvent.
|
||||
*/
|
||||
JXInputAxisEvent( Axis axis )
|
||||
{
|
||||
mAxis = axis;
|
||||
}
|
||||
|
||||
/**
|
||||
* The feature that caused the event.
|
||||
*/
|
||||
public final Axis getAxis()
|
||||
{
|
||||
return mAxis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the change in value that caused the event.
|
||||
*/
|
||||
public double getDelta()
|
||||
{
|
||||
return mDelta;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:54
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface JXInputAxisEventListener
|
||||
{
|
||||
void changed( JXInputAxisEvent ev );
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:33
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
/**
|
||||
* Represents event coming from a button.
|
||||
* @author Joerg Plewe
|
||||
*/
|
||||
public class JXInputButtonEvent
|
||||
{
|
||||
final Button mButton;
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXInputEvent.
|
||||
*/
|
||||
JXInputButtonEvent( Button button )
|
||||
{
|
||||
mButton = button;
|
||||
}
|
||||
|
||||
/**
|
||||
* The feature that caused the event.
|
||||
*/
|
||||
public final Button getButton()
|
||||
{
|
||||
return mButton;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:54
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface JXInputButtonEventListener
|
||||
{
|
||||
void changed( JXInputButtonEvent ev );
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:33
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
|
||||
/**
|
||||
* Represents an event coming from an axis.
|
||||
* @author Joerg Plewe
|
||||
*/
|
||||
public class JXInputDirectionalEvent
|
||||
{
|
||||
private final Directional mDirectional;
|
||||
double mValueDelta;
|
||||
int mDirectionDelta;
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXInputEvent.
|
||||
*/
|
||||
JXInputDirectionalEvent( Directional directional )
|
||||
{
|
||||
mDirectional = directional;
|
||||
}
|
||||
|
||||
/**
|
||||
* The feature that caused the event.
|
||||
*/
|
||||
public final Directional getDirectional()
|
||||
{
|
||||
return mDirectional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the change in value that caused the event.
|
||||
*/
|
||||
public double getValueDelta()
|
||||
{
|
||||
return mValueDelta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the change in direction that caused the event.
|
||||
*/
|
||||
public int getDirectionDelta()
|
||||
{
|
||||
return mDirectionDelta;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:54
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface JXInputDirectionalEventListener
|
||||
{
|
||||
void changed( JXInputDirectionalEvent ev );
|
||||
}
|
||||
|
||||
@@ -1,284 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 31. Januar 2002, 23:42
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.event;
|
||||
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import java.util.Iterator;
|
||||
import de.hardcode.jxinput.Button;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
|
||||
/**
|
||||
* Handles all events and listeners.
|
||||
* <code>JXInputEventManager</code> is layed out a static singleton.
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXInputEventManager
|
||||
{
|
||||
|
||||
private final static ArrayList mAxisEventListeners = new ArrayList();
|
||||
private final static ArrayList mButtonEventListeners = new ArrayList();
|
||||
private final static ArrayList mDirectionalEventListeners = new ArrayList();
|
||||
|
||||
private static autotrigger mAutoTrigger = null;
|
||||
|
||||
/**
|
||||
* Inner class combining a listener with its scheduling parameters.
|
||||
*/
|
||||
private static class axislistener
|
||||
{
|
||||
final JXInputAxisEventListener mListener;
|
||||
final double mTreshold;
|
||||
final JXInputAxisEvent mEvent;
|
||||
double mLastValueFired = 0.0;
|
||||
|
||||
axislistener( JXInputAxisEventListener l, Axis axis, double treshold )
|
||||
{
|
||||
mListener = l;
|
||||
mTreshold = treshold;
|
||||
mEvent = new JXInputAxisEvent( axis );
|
||||
}
|
||||
|
||||
final void checkTrigger()
|
||||
{
|
||||
double curval = mEvent.getAxis().getValue();
|
||||
double delta = curval - mLastValueFired;
|
||||
|
||||
if ( Math.abs( delta ) >= mTreshold )
|
||||
{
|
||||
mLastValueFired = curval;
|
||||
mEvent.mDelta = delta;
|
||||
mListener.changed( mEvent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class combining a listener with its scheduling parameters.
|
||||
*/
|
||||
private static class buttonlistener
|
||||
{
|
||||
final JXInputButtonEventListener mListener;
|
||||
final JXInputButtonEvent mEvent;
|
||||
boolean mLastValueFired = false;
|
||||
|
||||
buttonlistener( JXInputButtonEventListener l, Button button )
|
||||
{
|
||||
mListener = l;
|
||||
mEvent = new JXInputButtonEvent( button );
|
||||
}
|
||||
|
||||
final void checkTrigger()
|
||||
{
|
||||
boolean curstate = mEvent.getButton().getState();
|
||||
if ( curstate != mLastValueFired )
|
||||
{
|
||||
mLastValueFired = curstate;
|
||||
mListener.changed( mEvent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class directionallistener
|
||||
{
|
||||
final JXInputDirectionalEventListener mListener;
|
||||
final double mValueTreshold;
|
||||
final JXInputDirectionalEvent mEvent;
|
||||
double mLastValueFired = 0.0;
|
||||
boolean mLastCenteredFired = true;
|
||||
int mLastDirectionFired = 0;
|
||||
|
||||
directionallistener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold )
|
||||
{
|
||||
mListener = l;
|
||||
mValueTreshold = valuetreshold;
|
||||
mEvent = new JXInputDirectionalEvent( directional );
|
||||
}
|
||||
|
||||
final void checkTrigger()
|
||||
{
|
||||
double curval = mEvent.getDirectional().getValue();
|
||||
int curdir = mEvent.getDirectional().getDirection();
|
||||
boolean curctr = mEvent.getDirectional().isCentered();
|
||||
|
||||
double delta = curval - mLastValueFired;
|
||||
int dirdelta = curdir - mLastDirectionFired;
|
||||
boolean centeredchanged = mLastCenteredFired != curctr;
|
||||
|
||||
if ( Math.abs( delta ) >= mValueTreshold
|
||||
|| Math.abs( dirdelta ) > 0
|
||||
|| centeredchanged )
|
||||
{
|
||||
mLastValueFired = curval;
|
||||
mLastDirectionFired = curdir;
|
||||
mLastCenteredFired = curctr;
|
||||
|
||||
mEvent.mValueDelta = delta;
|
||||
mEvent.mDirectionDelta = dirdelta;
|
||||
mListener.changed( mEvent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXInputEventManager.
|
||||
*/
|
||||
private JXInputEventManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all listeners at once.
|
||||
*/
|
||||
public static void reset()
|
||||
{
|
||||
mAxisEventListeners.clear();
|
||||
mButtonEventListeners.clear();
|
||||
mDirectionalEventListeners.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query devices and fire all occuring events.
|
||||
* <code>trigger()</code> is thought to be called by <code>JXInputManager#updateFeatures()</code>.
|
||||
*/
|
||||
public static void trigger()
|
||||
{
|
||||
int n = mAxisEventListeners.size();
|
||||
for ( int i = 0; i < n; i++ )
|
||||
{
|
||||
axislistener l = (axislistener)mAxisEventListeners.get( i );
|
||||
l.checkTrigger();
|
||||
}
|
||||
|
||||
n = mButtonEventListeners.size();
|
||||
for ( int i = 0; i < n; i++ )
|
||||
{
|
||||
buttonlistener l = (buttonlistener)mButtonEventListeners.get( i );
|
||||
l.checkTrigger();
|
||||
}
|
||||
|
||||
n = mDirectionalEventListeners.size();
|
||||
for ( int i = 0; i < n; i++ )
|
||||
{
|
||||
directionallistener l = (directionallistener)mDirectionalEventListeners.get( i );
|
||||
l.checkTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static class autotrigger extends Thread
|
||||
{
|
||||
boolean mFinish = false;
|
||||
final int mDelay;
|
||||
|
||||
autotrigger( int delay )
|
||||
{
|
||||
mDelay = delay;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
while ( ! mFinish )
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep( mDelay );
|
||||
JXInputManager.updateFeatures();
|
||||
}
|
||||
catch ( InterruptedException ex )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the intervall in ms that is used to check for new values of the features.
|
||||
* Set it to <= 0 to prohibit automatic triggering. Events will then only be fired
|
||||
* when somebody invokes <code>JXInputManager#updateFeatures()</code>.
|
||||
*/
|
||||
public static void setTriggerIntervall( int ms )
|
||||
{
|
||||
//
|
||||
// Kill current thread, if any
|
||||
//
|
||||
if ( null != mAutoTrigger )
|
||||
{
|
||||
mAutoTrigger.mFinish = true;
|
||||
try
|
||||
{
|
||||
mAutoTrigger.join();
|
||||
}
|
||||
catch ( InterruptedException ex )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
mAutoTrigger = null;
|
||||
|
||||
if ( ms > 0 )
|
||||
{
|
||||
mAutoTrigger = new autotrigger( ms );
|
||||
mAutoTrigger.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void addListener( JXInputAxisEventListener l, Axis axis, double treshold )
|
||||
{
|
||||
mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, treshold ) );
|
||||
}
|
||||
|
||||
public static void addListener( JXInputAxisEventListener l, Axis axis )
|
||||
{
|
||||
mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, axis.getResolution() ) );
|
||||
}
|
||||
|
||||
public static void removeListener( JXInputAxisEventListener l )
|
||||
{
|
||||
mAxisEventListeners.remove( l );
|
||||
}
|
||||
|
||||
|
||||
public static void addListener( JXInputButtonEventListener l, Button button )
|
||||
{
|
||||
mButtonEventListeners.add( new JXInputEventManager.buttonlistener( l, button ) );
|
||||
}
|
||||
|
||||
public static void removeListener( JXInputButtonEventListener l )
|
||||
{
|
||||
mButtonEventListeners.remove( l );
|
||||
}
|
||||
|
||||
public static void addListener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold )
|
||||
{
|
||||
mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, valuetreshold ) );
|
||||
}
|
||||
|
||||
public static void addListener( JXInputDirectionalEventListener l, Directional directional )
|
||||
{
|
||||
mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, directional.getResolution() ) );
|
||||
}
|
||||
|
||||
public static void removeListener( JXInputDirectionalEventListener l )
|
||||
{
|
||||
mDirectionalEventListeners.remove( l );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 23. Februar 2002, 14:05
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.j3d;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
|
||||
/**
|
||||
* Connects JXInput with J3DInputDevice.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class DeviceConfiguration
|
||||
{
|
||||
public final static int AXIS_X = 0;
|
||||
public final static int AXIS_Y = 1;
|
||||
public final static int AXIS_Z = 2;
|
||||
|
||||
private final static class axisvalue
|
||||
{
|
||||
private final Axis mAxis;
|
||||
private final IsActiveCondition mIsActive;
|
||||
private final IsActiveCondition mIsIncremental;
|
||||
private final double mScale;
|
||||
private final double mOffset;
|
||||
private double mValue;
|
||||
|
||||
axisvalue( Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
|
||||
{
|
||||
mAxis = axis;
|
||||
mIsActive = active;
|
||||
mIsIncremental = incremental;
|
||||
mValue = mOffset = offset;
|
||||
mScale = scale;
|
||||
}
|
||||
|
||||
double value()
|
||||
{
|
||||
if ( mIsActive.isActive() )
|
||||
{
|
||||
double newval = mAxis.getValue() * mScale;
|
||||
|
||||
if ( mIsIncremental.isActive() )
|
||||
mValue += newval;
|
||||
else
|
||||
mValue = newval + mOffset;
|
||||
}
|
||||
return mValue;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceConfiguration.axisvalue [] mAxisTrans = new DeviceConfiguration.axisvalue[ 3 ];
|
||||
DeviceConfiguration.axisvalue [] mAxisRot = new DeviceConfiguration.axisvalue[ 3 ];
|
||||
|
||||
/**
|
||||
* Creates a new instance of DeviceConfiguration.
|
||||
*/
|
||||
public DeviceConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
double getTranslational( int axisid )
|
||||
{
|
||||
DeviceConfiguration.axisvalue val = mAxisTrans[ axisid ];
|
||||
return null == val ? 0.0 : val.value();
|
||||
}
|
||||
|
||||
double getRotational( int axisid )
|
||||
{
|
||||
DeviceConfiguration.axisvalue val = mAxisRot[ axisid ];
|
||||
return null == val ? 0.0 : val.value();
|
||||
}
|
||||
|
||||
public void setTranslational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
|
||||
{
|
||||
if ( axisid < 0 || axisid > AXIS_Z )
|
||||
throw new IllegalArgumentException();
|
||||
mAxisTrans[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale );
|
||||
}
|
||||
|
||||
public void setRotational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
|
||||
{
|
||||
if ( axisid < 0 || axisid > AXIS_Z )
|
||||
throw new IllegalArgumentException();
|
||||
mAxisRot[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 25. Februar 2002, 22:41
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.j3d;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public interface IsActiveCondition
|
||||
{
|
||||
public final static IsActiveCondition ALWAYS = IsAlwaysActiveCondition.ALWAYS;
|
||||
public final static IsActiveCondition NEVER = IsAlwaysActiveCondition.NEVER;
|
||||
|
||||
/**
|
||||
* Tell wether a certain thing is active.
|
||||
*/
|
||||
boolean isActive();
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 25. Februar 2002, 22:43
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.j3d;
|
||||
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class IsActiveOnButtonCondition implements IsActiveCondition
|
||||
{
|
||||
private final boolean mActiveState;
|
||||
private final Button mButton;
|
||||
|
||||
/**
|
||||
* Creates a new instance of IsAlwayActiveCondition.
|
||||
*/
|
||||
public IsActiveOnButtonCondition( Button button, boolean activestate )
|
||||
{
|
||||
mActiveState = activestate;
|
||||
mButton = button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell wether a certain thing is active.
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return mButton.getState() == mActiveState;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 25. Februar 2002, 22:43
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.j3d;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
final class IsAlwaysActiveCondition implements IsActiveCondition
|
||||
{
|
||||
private final boolean mIsActive;
|
||||
|
||||
public final static IsActiveCondition ALWAYS = new IsAlwaysActiveCondition( true );
|
||||
public final static IsActiveCondition NEVER = new IsAlwaysActiveCondition( false );
|
||||
|
||||
/**
|
||||
* Creates a new instance of IsAlwayActiveCondition.
|
||||
*/
|
||||
private IsAlwaysActiveCondition(boolean isactive)
|
||||
{
|
||||
mIsActive = isactive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell wether a certain thing is active.
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return mIsActive;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 22. Februar 2002, 13:21
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.j3d;
|
||||
|
||||
import javax.media.j3d.InputDevice;
|
||||
import javax.media.j3d.Sensor;
|
||||
import javax.media.j3d.SensorRead;
|
||||
import javax.vecmath.Vector3d;
|
||||
import javax.media.j3d.Transform3D;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of Java3D's InputDevice
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class J3DInputDevice
|
||||
implements InputDevice
|
||||
{
|
||||
private Vector3d mPosition = new Vector3d();
|
||||
private Transform3D mNewTransform = new Transform3D();
|
||||
|
||||
private Transform3D mRotTransX = new Transform3D();
|
||||
private Transform3D mRotTransY = new Transform3D();
|
||||
private Transform3D mRotTransZ = new Transform3D();
|
||||
|
||||
private Vector3d mInitPos = new Vector3d( 0.0, 0.0, 0.0 );
|
||||
|
||||
private Sensor mSensor = new Sensor( this );
|
||||
private SensorRead mSensorRead = new SensorRead();
|
||||
|
||||
private DeviceConfiguration mConfig;
|
||||
|
||||
/**
|
||||
* Creates a new instance of J3DInputDevice.
|
||||
*/
|
||||
public J3DInputDevice( DeviceConfiguration config )
|
||||
{
|
||||
mConfig = config;
|
||||
setNominalPositionAndOrientation();
|
||||
}
|
||||
|
||||
|
||||
public void close()
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve processing mode.
|
||||
* For this device, it always is NON_BLOCKING.
|
||||
*/
|
||||
public int getProcessingMode()
|
||||
{
|
||||
return InputDevice.NON_BLOCKING;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Don't care for the index, I only support one sensor.
|
||||
* And I deliver that.
|
||||
*/
|
||||
public Sensor getSensor( int param )
|
||||
{
|
||||
return mSensor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell the world about the only one sensor I support.
|
||||
*/
|
||||
public int getSensorCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Well - initialize!
|
||||
* Nothing to do here.
|
||||
*/
|
||||
public boolean initialize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main update method.
|
||||
*/
|
||||
public void pollAndProcessInput()
|
||||
{
|
||||
JXInputManager.updateFeatures();
|
||||
|
||||
mSensorRead.setTime( JXInputManager.getLastUpdateTime() );
|
||||
|
||||
mRotTransX.rotX( mConfig.getRotational( DeviceConfiguration.AXIS_X ) );
|
||||
mRotTransY.rotY( mConfig.getRotational( DeviceConfiguration.AXIS_Y ) );
|
||||
mRotTransZ.rotZ( mConfig.getRotational( DeviceConfiguration.AXIS_Z ) );
|
||||
|
||||
mPosition.set(
|
||||
mConfig.getTranslational( DeviceConfiguration.AXIS_X ),
|
||||
mConfig.getTranslational( DeviceConfiguration.AXIS_Y ),
|
||||
mConfig.getTranslational( DeviceConfiguration.AXIS_Z )
|
||||
);
|
||||
|
||||
mNewTransform.set( mPosition );
|
||||
|
||||
mNewTransform.mul( mRotTransX );
|
||||
mNewTransform.mul( mRotTransY );
|
||||
mNewTransform.mul( mRotTransZ );
|
||||
|
||||
mSensorRead.set( mNewTransform );
|
||||
mSensor.setNextSensorRead( mSensorRead );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Not called by current j3d implementation.
|
||||
*/
|
||||
public void processStreamInput()
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset state.
|
||||
*/
|
||||
public void setNominalPositionAndOrientation()
|
||||
{
|
||||
mSensorRead.setTime( JXInputManager.getLastUpdateTime() );
|
||||
|
||||
mRotTransX.rotX( 0.0 );
|
||||
mRotTransY.rotY( 0.0 );
|
||||
mRotTransZ.rotZ( 0.0 );
|
||||
|
||||
mPosition.set( mInitPos );
|
||||
|
||||
mNewTransform.set( mPosition );
|
||||
|
||||
mNewTransform.mul( mRotTransX );
|
||||
mNewTransform.mul( mRotTransY );
|
||||
mNewTransform.mul( mRotTransZ );
|
||||
|
||||
mSensorRead.set( mNewTransform );
|
||||
mSensor.setNextSensorRead( mSensorRead );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the processing mode.
|
||||
* Only NON_BLOCKING is allowed!
|
||||
*/
|
||||
public void setProcessingMode(int param)
|
||||
{
|
||||
if ( param != InputDevice.NON_BLOCKING )
|
||||
throw new IllegalArgumentException("Processing mode must be NON_BLOCKING");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE></TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
Connecting JXInput to Java3D by implementing the interface
|
||||
javax.media.j3d.InputDevice.
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -1,205 +0,0 @@
|
||||
|
||||
/*
|
||||
* @(#)HelloUniverse.java 1.15 02/02/07 14:48:36
|
||||
*
|
||||
* Copyright (c) 1996-2002 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:
|
||||
*
|
||||
* - Redistributions 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 materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* Neither the name of Sun Microsystems, Inc. or the names of
|
||||
* 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 WARRANTY OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
|
||||
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THE 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 OR INABILITY TO USE SOFTWARE,
|
||||
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* You acknowledge that Software is not designed,licensed or intended
|
||||
* for use in the design, construction, operation or maintenance of
|
||||
* any nuclear facility.
|
||||
*/
|
||||
|
||||
package de.hardcode.jxinput.j3d.test;
|
||||
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import com.sun.j3d.utils.applet.MainFrame;
|
||||
import com.sun.j3d.utils.geometry.ColorCube;
|
||||
import com.sun.j3d.utils.universe.*;
|
||||
import javax.media.j3d.*;
|
||||
import javax.vecmath.*;
|
||||
import de.hardcode.jxinput.j3d.DeviceConfiguration;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
import de.hardcode.jxinput.j3d.IsActiveCondition;
|
||||
import de.hardcode.jxinput.j3d.J3DInputDevice;
|
||||
import de.hardcode.jxinput.j3d.IsActiveOnButtonCondition;
|
||||
|
||||
|
||||
public class HelloUniverse extends Applet
|
||||
{
|
||||
|
||||
private SimpleUniverse u = null;
|
||||
TransformGroup objTrans;
|
||||
|
||||
public BranchGroup createSceneGraph()
|
||||
{
|
||||
BranchGroup objRoot = new BranchGroup();
|
||||
objTrans = new TransformGroup();
|
||||
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
||||
objRoot.addChild(objTrans);
|
||||
objTrans.addChild(new ColorCube(0.4));
|
||||
|
||||
// Transform3D yAxis = new Transform3D();
|
||||
// Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
|
||||
// 0, 0,
|
||||
// 4000, 0, 0,
|
||||
// 0, 0, 0);
|
||||
// RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis,
|
||||
// 0.0f, (float) Math.PI*2.0f);
|
||||
// BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
|
||||
// rotator.setSchedulingBounds(bounds);
|
||||
// objTrans.addChild(rotator);
|
||||
return objRoot;
|
||||
}
|
||||
|
||||
|
||||
public HelloUniverse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
// These are the string arguments given to the VirtualInputDevice
|
||||
// constructor. These are settable parameters. Look in the
|
||||
// VirtualInputDevice constructor for a complete list.
|
||||
String[] args = new String[10];
|
||||
args[0] = "printvalues";
|
||||
args[1] = "true";
|
||||
args[2] = "yscreeninitloc";
|
||||
args[3] = "50";
|
||||
args[4] = null;
|
||||
|
||||
|
||||
// now create the HelloUniverse Canvas
|
||||
setLayout(new BorderLayout());
|
||||
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
|
||||
|
||||
Canvas3D c = new Canvas3D(config);
|
||||
add("Center", c);
|
||||
|
||||
// Create a simple scene and attach it to the virtual universe
|
||||
BranchGroup scene = createSceneGraph();
|
||||
u = new SimpleUniverse(c);
|
||||
|
||||
//
|
||||
// Use the inputdevice
|
||||
//
|
||||
InputDevice device = createInputDevice();
|
||||
|
||||
// Register the VirtualInputDevice with Java 3D
|
||||
u.getViewer().getPhysicalEnvironment().addInputDevice( device );
|
||||
|
||||
// TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform();
|
||||
|
||||
// Put the behavoir to teh object
|
||||
SensorBehavior s = new SensorBehavior( objTrans, device.getSensor(0) );
|
||||
s.setSchedulingBounds( new BoundingSphere( new Point3d(0.0,0.0,0.0), Float.MAX_VALUE ) );
|
||||
objTrans.addChild( s );
|
||||
|
||||
u.getViewingPlatform().setNominalViewingTransform();
|
||||
u.addBranchGraph(scene);
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
u.removeAllLocales();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup an input device.
|
||||
*/
|
||||
private InputDevice createInputDevice()
|
||||
{
|
||||
IsActiveCondition button1down = new IsActiveOnButtonCondition(JXInputManager.getJXInputDevice( 0 ).getButton( 0 ), true );
|
||||
IsActiveCondition button1up = new IsActiveOnButtonCondition(JXInputManager.getJXInputDevice( 0 ).getButton( 0 ), false );
|
||||
|
||||
Axis xaxis = JXInputManager.getJXInputDevice( 0 ).getAxis( Axis.ID_X );
|
||||
Axis yaxis = JXInputManager.getJXInputDevice( 0 ).getAxis( Axis.ID_Y );
|
||||
|
||||
DeviceConfiguration cnf = new DeviceConfiguration();
|
||||
|
||||
//
|
||||
// Setup the configuration to use joysticks x/y for rotation is not button is pressed
|
||||
// and for translation if button1 is pressed.
|
||||
//
|
||||
cnf.setRotational(
|
||||
DeviceConfiguration.AXIS_Y,
|
||||
xaxis,
|
||||
button1up,
|
||||
IsActiveCondition.NEVER,
|
||||
0.0, Math.PI
|
||||
);
|
||||
|
||||
cnf.setRotational(
|
||||
DeviceConfiguration.AXIS_X,
|
||||
yaxis,
|
||||
button1up,
|
||||
IsActiveCondition.NEVER,
|
||||
0.0, Math.PI
|
||||
);
|
||||
|
||||
cnf.setTranslational(
|
||||
DeviceConfiguration.AXIS_Z,
|
||||
yaxis,
|
||||
button1down,
|
||||
IsActiveCondition.NEVER,
|
||||
-5.0, 4.0
|
||||
);
|
||||
cnf.setTranslational(
|
||||
DeviceConfiguration.AXIS_X,
|
||||
xaxis,
|
||||
button1down,
|
||||
IsActiveCondition.NEVER,
|
||||
0.0, 4.0
|
||||
);
|
||||
|
||||
// We have the config, create the device...
|
||||
J3DInputDevice d = new J3DInputDevice( cnf );
|
||||
|
||||
// The InputDevice must be initialized before registering it
|
||||
// with the PhysicalEnvironment object.
|
||||
d.initialize();
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new MainFrame(new HelloUniverse(), 350, 350);
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package de.hardcode.jxinput.j3d.test;
|
||||
|
||||
/*
|
||||
* @(#)SensorBehavior.java 1.8 02/02/07 14:48:34
|
||||
*
|
||||
* Copyright (c) 1996-2002 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:
|
||||
*
|
||||
* - Redistributions 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 materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* Neither the name of Sun Microsystems, Inc. or the names of
|
||||
* 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 WARRANTY OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
|
||||
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THE 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 OR INABILITY TO USE SOFTWARE,
|
||||
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*
|
||||
* You acknowledge that Software is not designed,licensed or intended
|
||||
* for use in the design, construction, operation or maintenance of
|
||||
* any nuclear facility.
|
||||
*/
|
||||
|
||||
import javax.media.j3d.*;
|
||||
import java.util.*;
|
||||
|
||||
public class SensorBehavior extends Behavior
|
||||
{
|
||||
private WakeupOnElapsedFrames conditions = new WakeupOnElapsedFrames(0);
|
||||
private TransformGroup transformGroup;
|
||||
private Sensor sensor;
|
||||
private Transform3D transform = new Transform3D();
|
||||
|
||||
public SensorBehavior( TransformGroup tg, Sensor sensor )
|
||||
{
|
||||
transformGroup = tg;
|
||||
this.sensor = sensor;
|
||||
}
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
wakeupOn( conditions );
|
||||
}
|
||||
|
||||
public void processStimulus( Enumeration criteria )
|
||||
{
|
||||
sensor.getRead( transform );
|
||||
transformGroup.setTransform( transform );
|
||||
wakeupOn( conditions );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 16. April 2002, 23:31
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.keyboard;
|
||||
|
||||
/**
|
||||
* Exeception to be thrown if keycode is not in then range [0,255].
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class InvalidKeyCodeException
|
||||
extends IllegalArgumentException
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of InvalidKeyCodeException.
|
||||
*/
|
||||
public InvalidKeyCodeException()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of InvalidKeyCodeException.
|
||||
*/
|
||||
public InvalidKeyCodeException( String s )
|
||||
{
|
||||
super( s );
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.keyboard;
|
||||
|
||||
|
||||
import de.hardcode.jxinput.*;
|
||||
import java.awt.Component;
|
||||
|
||||
|
||||
/**
|
||||
* Virtual input device treating a AWT keyboard as a source for Buttons.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXKeyboardInputDevice
|
||||
implements JXInputDevice
|
||||
{
|
||||
private static final String DEVICENAME = "Swing Keyboard";
|
||||
|
||||
/** The driver doing all the real work. */
|
||||
private final KeyboardDriver mDriver = new KeyboardDriver();
|
||||
|
||||
/** The Component I am listening to. */
|
||||
private Component mComponent = null;
|
||||
|
||||
/** Hold the biggest keycode for which a button has been created. */
|
||||
private int mMaxIdxCreated = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXKeyboardInputDevice.
|
||||
*/
|
||||
public JXKeyboardInputDevice()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXKeyboardInputDevice
|
||||
* immediately listening to a JComponent.
|
||||
*/
|
||||
public JXKeyboardInputDevice( Component comp )
|
||||
{
|
||||
listenTo( comp );
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes this device listen to a certain JComponent.
|
||||
*/
|
||||
public final void listenTo( Component comp )
|
||||
{
|
||||
shutdown();
|
||||
mComponent = comp;
|
||||
mComponent.addKeyListener( mDriver );
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down. No longer listen to my JComponent.
|
||||
*/
|
||||
public final void shutdown()
|
||||
{
|
||||
if ( null != mComponent )
|
||||
mComponent.removeKeyListener( mDriver );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a button object for a certain keycode.
|
||||
*/
|
||||
public Button createButton( int keycode )
|
||||
{
|
||||
if ( 0 > keycode || 0x100 < keycode )
|
||||
throw new InvalidKeyCodeException();
|
||||
|
||||
KeyButton b;
|
||||
if ( null == (b = mDriver.getButton( keycode ) ) )
|
||||
{
|
||||
b = new KeyButton( keycode );
|
||||
mDriver.registerKeyButton( b );
|
||||
if ( keycode > mMaxIdxCreated )
|
||||
mMaxIdxCreated = keycode;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
public void removeButton( Button b )
|
||||
{
|
||||
mDriver.unregisterKeyButton( (KeyButton) b );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement JXInputDevice
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
public Axis getAxis(int idx)
|
||||
{
|
||||
// No axes on keyboard.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Button getButton(int idx)
|
||||
{
|
||||
// idx is interpreted as the keycode
|
||||
return mDriver.getButton( idx );
|
||||
}
|
||||
|
||||
public Directional getDirectional(int idx)
|
||||
{
|
||||
// No directionals on keyboard.
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Maximum number of axes as an upper bound for index values. */
|
||||
public int getMaxNumberOfAxes()
|
||||
{
|
||||
// No axes on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Maximum number of buttons as an upper bound for index values. */
|
||||
public int getMaxNumberOfButtons()
|
||||
{
|
||||
// Return biggest keycode (inclusive).
|
||||
return mMaxIdxCreated + 1;
|
||||
}
|
||||
|
||||
/** Maximum number of directional features as an upper bound for index values. */
|
||||
public int getMaxNumberOfDirectionals()
|
||||
{
|
||||
// No directionals on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devices may have a name.
|
||||
* This name might be provided by a system dependant driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return DEVICENAME;
|
||||
}
|
||||
|
||||
/** Actual number of available axes. */
|
||||
public int getNumberOfAxes()
|
||||
{
|
||||
// No axes on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Actual number of available buttons. */
|
||||
public int getNumberOfButtons()
|
||||
{
|
||||
return mDriver.getNumberOfButtons();
|
||||
}
|
||||
|
||||
/** Actual number of available directional features. */
|
||||
public int getNumberOfDirectionals()
|
||||
{
|
||||
// No directionals on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:51
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.keyboard;
|
||||
|
||||
import de.hardcode.jxinput.Button;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Associates a keycode with a SelectButton and handles the current state of that button.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class KeyButton
|
||||
implements Button
|
||||
{
|
||||
private final int mKeyCode;
|
||||
private boolean mIsPressed;
|
||||
private boolean mHasChanged;
|
||||
|
||||
/**
|
||||
* Creates a new instance of KeyButton.
|
||||
*/
|
||||
public KeyButton( int keycode )
|
||||
{
|
||||
mKeyCode = keycode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the keycode assigned with this button.
|
||||
*/
|
||||
public final int getKeyCode()
|
||||
{
|
||||
return mKeyCode;
|
||||
}
|
||||
|
||||
final void setIsPressed( boolean flag )
|
||||
{
|
||||
mIsPressed = flag;
|
||||
}
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement SelectButton
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
|
||||
/**
|
||||
* Features may have a name provided e.g. by the driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return KeyEvent.getKeyText( mKeyCode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the state of the button at last update.
|
||||
*/
|
||||
public boolean getState()
|
||||
{
|
||||
return mIsPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the type of the button.
|
||||
* Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down.
|
||||
* Togglebuttons will change their state once they are pressed and keep that state
|
||||
* until they are pressed again.
|
||||
* @return [ PUSHBUTTON | TOGGLEBUTTON ]
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return Button.PUSHBUTTON;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:43
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.keyboard;
|
||||
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.HashMap;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Listen to a JComponent handle handle all associated button objects.
|
||||
* This is the main worker class for JXKeyboardInputDevice.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class KeyboardDriver implements KeyListener
|
||||
{
|
||||
// HashMap mKeysToObserveMap = new HashMap();
|
||||
|
||||
int mNumberOfKeysObserved = 0;
|
||||
KeyButton [] mKeysObserved = new KeyButton [ 0x100 ];
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of KeyboardDriver.
|
||||
*/
|
||||
public KeyboardDriver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many buttons are registered?
|
||||
*/
|
||||
final int getNumberOfButtons()
|
||||
{
|
||||
return mNumberOfKeysObserved;
|
||||
// return mKeysToObserveMap.size();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Place a new button under my observation.
|
||||
*/
|
||||
final boolean registerKeyButton( KeyButton b )
|
||||
{
|
||||
final int keycode = b.getKeyCode();
|
||||
|
||||
if ( 0 > keycode || 0x100 < keycode )
|
||||
throw new InvalidKeyCodeException();
|
||||
|
||||
if ( null == mKeysObserved[ keycode ] )
|
||||
{
|
||||
mKeysObserved[ keycode ] = b;
|
||||
mNumberOfKeysObserved++;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Integer code = new Integer( b.getKeyCode() );
|
||||
// if ( ! mKeysToObserveMap.containsKey( code ) )
|
||||
// {
|
||||
// mKeysToObserveMap.put( code, b );
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
final void unregisterKeyButton( KeyButton b )
|
||||
{
|
||||
final int keycode = b.getKeyCode();
|
||||
|
||||
if ( 0 > keycode || 0x100 < keycode )
|
||||
throw new InvalidKeyCodeException();
|
||||
|
||||
if ( null != mKeysObserved[ b.getKeyCode() ] )
|
||||
{
|
||||
mKeysObserved[ keycode ] = null;
|
||||
mNumberOfKeysObserved--;
|
||||
}
|
||||
|
||||
// Integer code = new Integer( b.getKeyCode() );
|
||||
// mKeysToObserveMap.remove( code );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the button from its keycode.
|
||||
*/
|
||||
final KeyButton getButton( int keycode )
|
||||
{
|
||||
if ( 0 > keycode || 0x100 < keycode )
|
||||
throw new InvalidKeyCodeException();
|
||||
|
||||
return mKeysObserved[ keycode ];
|
||||
|
||||
// Integer code = new Integer( keycode );
|
||||
// return (KeyButton)mKeysToObserveMap.get( code );
|
||||
}
|
||||
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement KeyListener
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
public void keyPressed( KeyEvent keyEvent )
|
||||
{
|
||||
KeyButton b = getButton( keyEvent.getKeyCode() );
|
||||
if ( null != b )
|
||||
b.setIsPressed( true );
|
||||
}
|
||||
|
||||
public void keyReleased( KeyEvent keyEvent )
|
||||
{
|
||||
KeyButton b = getButton( keyEvent.getKeyCode() );
|
||||
if ( null != b )
|
||||
b.setIsPressed( false );
|
||||
}
|
||||
|
||||
public void keyTyped( KeyEvent keyEvent )
|
||||
{
|
||||
// Intentionally empty.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>de.hardcode.jxinput.keyboard</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
Connects Swing keyboard handling to the JXInput infrastructure.
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -1,39 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 20. Februar 2002, 22:19
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.test;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
/**
|
||||
* Example listener to an axis.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class AxisListener
|
||||
implements JXInputAxisEventListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of AxisListener.
|
||||
*/
|
||||
public AxisListener( Axis axis )
|
||||
{
|
||||
JXInputEventManager.addListener( this, axis, 0.1 );
|
||||
}
|
||||
|
||||
|
||||
public void changed( JXInputAxisEvent ev )
|
||||
{
|
||||
System.out.println( "Axis " + ev.getAxis().getName() + " changed : value=" + ev.getAxis().getValue() + ", event causing delta=" + ev.getDelta() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 20. Februar 2002, 22:19
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.test;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
/**
|
||||
* Sample button listener.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class ButtonListener implements JXInputButtonEventListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of AxisListener.
|
||||
*/
|
||||
public ButtonListener( Button button )
|
||||
{
|
||||
JXInputEventManager.addListener( this, button );
|
||||
}
|
||||
|
||||
|
||||
public void changed( JXInputButtonEvent ev )
|
||||
{
|
||||
System.out.println( "SelectButton " + ev.getButton().getName() + " changed : state=" + ev.getButton().getState() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 20. Februar 2002, 22:19
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.test;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
|
||||
/**
|
||||
* Sample directional listener.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class DirectionalListener implements JXInputDirectionalEventListener
|
||||
{
|
||||
/**
|
||||
* Creates a new instance of AxisListener.
|
||||
*/
|
||||
public DirectionalListener( Directional directional )
|
||||
{
|
||||
JXInputEventManager.addListener( this, directional, 1.0 );
|
||||
}
|
||||
|
||||
|
||||
public void changed( JXInputDirectionalEvent ev )
|
||||
{
|
||||
System.out.println( "Directional " + ev.getDirectional().getName() + " changed : direction=" + ev.getDirectional().getDirection() + ", value=" + ev.getDirectional().getValue() + ", event causing delta=" + ev.getDirectionDelta() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Events>
|
||||
<EventHandler event="componentShown" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="OnShow"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout">
|
||||
<Property name="horizontalGap" type="int" value="2"/>
|
||||
<Property name="verticalGap" type="int" value="2"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="mAxesPanelContainer">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
|
||||
<BevelBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="mAxesPanel">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="North"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="1"/>
|
||||
<Property name="rows" type="int" value="1"/>
|
||||
<Property name="verticalGap" type="int" value="20"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="mDirectionalPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
|
||||
<BevelBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="South"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="1"/>
|
||||
<Property name="rows" type="int" value="1"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Container class="javax.swing.JScrollPane" name="mButtonScrollPane">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="East"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="mButtonsPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
|
||||
<BevelBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="1"/>
|
||||
<Property name="rows" type="int" value="1"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
@@ -1,296 +0,0 @@
|
||||
/*
|
||||
* JXInputDevicePanel.java
|
||||
*
|
||||
* Created on 23. Januar 2002, 22:19
|
||||
*/
|
||||
package de.hardcode.jxinput.test;
|
||||
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXInputDevicePanel extends javax.swing.JPanel
|
||||
{
|
||||
private static final Font AXIS_SLIDER_FONT = new Font( "Verdana", Font.PLAIN, 9 );
|
||||
|
||||
private final JXInputDevice mDev;
|
||||
private final ArrayList mAxisSliders = new ArrayList();
|
||||
private final ArrayList mButtonCheckboxes = new ArrayList();
|
||||
private final ArrayList mDirectionalLabels = new ArrayList();
|
||||
|
||||
|
||||
/** Creates new form JXInputDevicePanel */
|
||||
public JXInputDevicePanel( JXInputDevice dev )
|
||||
{
|
||||
mDev = dev;
|
||||
initComponents();
|
||||
initFromDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class connecting a JSlider with an Axis.
|
||||
*/
|
||||
private class AxisSlider extends JSlider
|
||||
{
|
||||
Axis mAxis;
|
||||
AxisSlider( Axis axis )
|
||||
{
|
||||
super( ( Axis.SLIDER == axis.getType() ? 0 : -100 ), 100 );
|
||||
this.setMajorTickSpacing( Axis.SLIDER == axis.getType() ? 25 : 50 );
|
||||
this.setMinorTickSpacing( 5 );
|
||||
this.setPaintTicks( true );
|
||||
this.setPaintLabels( true );
|
||||
this.setEnabled( false );
|
||||
|
||||
Dictionary labeldict = this.getLabelTable();
|
||||
Enumeration labels = labeldict.elements();
|
||||
while ( labels.hasMoreElements() )
|
||||
{
|
||||
JLabel label = (JLabel)labels.nextElement();
|
||||
label.setFont( AXIS_SLIDER_FONT );
|
||||
label.setSize( 32, 12 );
|
||||
label.setHorizontalAlignment( SwingConstants.LEFT );
|
||||
}
|
||||
|
||||
mAxis = axis;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
int ax = (int)(mAxis.getValue() * 100.0);
|
||||
|
||||
//
|
||||
// Only if value really changes
|
||||
//
|
||||
if ( ax != this.getValue() )
|
||||
{
|
||||
this.setValue( ax );
|
||||
this.setToolTipText( mAxis.getName() + ": " + Double.toString( mAxis.getValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class ButtonCheckbox extends JCheckBox
|
||||
{
|
||||
Button mButton;
|
||||
ButtonCheckbox( Button button )
|
||||
{
|
||||
super( button.getName() );
|
||||
this.setEnabled( false );
|
||||
mButton = button;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
boolean state = mButton.getState();
|
||||
|
||||
//
|
||||
// Only if value really changes
|
||||
//
|
||||
if ( state != this.isSelected() )
|
||||
{
|
||||
this.setSelected( state );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class DirectionalLabel extends JLabel
|
||||
{
|
||||
Directional mDirectional;
|
||||
int mCurrent = 0;
|
||||
|
||||
DirectionalLabel( Directional directional )
|
||||
{
|
||||
super( directional.getName() );
|
||||
mDirectional = directional;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
int dir = mDirectional.getDirection();
|
||||
|
||||
//
|
||||
// Only if value really changes
|
||||
//
|
||||
if ( dir != mCurrent )
|
||||
{
|
||||
this.setText( mDirectional.getName() + ": " + ( mDirectional.isCentered() ? "-" : Integer.toString( dir ) ) );
|
||||
mCurrent = dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup the dialogs content from the JXInputDevice.
|
||||
*/
|
||||
void initFromDevice()
|
||||
{
|
||||
if ( null != mDev )
|
||||
{
|
||||
((GridLayout)mAxesPanel.getLayout()).setRows( mDev.getNumberOfAxes() );
|
||||
|
||||
for ( int i = 0; i < mDev.getMaxNumberOfAxes(); ++i )
|
||||
{
|
||||
if ( null != mDev.getAxis( i ) )
|
||||
{
|
||||
AxisSlider slider = new AxisSlider( mDev.getAxis( i ) );
|
||||
|
||||
JLabel name = new JLabel( mDev.getAxis( i ).getName() );
|
||||
name.setVerticalAlignment( SwingConstants.TOP );
|
||||
name.setHorizontalAlignment( SwingConstants.CENTER );
|
||||
name.setPreferredSize( new java.awt.Dimension( 90, 0 ) );
|
||||
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout( new BorderLayout() );
|
||||
|
||||
p.add( name, BorderLayout.WEST );
|
||||
p.add( slider, BorderLayout.CENTER );
|
||||
|
||||
mAxesPanel.add( p );
|
||||
|
||||
// Add to list of all AxisSlider controls
|
||||
mAxisSliders.add( slider );
|
||||
|
||||
// Add an event listener:
|
||||
new AxisListener( mDev.getAxis( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
((GridLayout)mButtonsPanel.getLayout()).setRows( mDev.getNumberOfButtons() );
|
||||
for ( int i = 0; i < mDev.getMaxNumberOfButtons(); ++i )
|
||||
{
|
||||
if ( null != mDev.getButton( i ) )
|
||||
{
|
||||
ButtonCheckbox chk = new ButtonCheckbox( mDev.getButton( i ) );
|
||||
mButtonCheckboxes.add( chk );
|
||||
mButtonsPanel.add( chk );
|
||||
|
||||
// Add an event listener:
|
||||
new ButtonListener( mDev.getButton( i ) );
|
||||
}
|
||||
}
|
||||
|
||||
((GridLayout)mDirectionalPanel.getLayout()).setRows( mDev.getNumberOfDirectionals() / 2 );
|
||||
for ( int i = 0; i < mDev.getMaxNumberOfDirectionals(); ++i )
|
||||
{
|
||||
if ( null != mDev.getDirectional( i ) )
|
||||
{
|
||||
DirectionalLabel lbl = new DirectionalLabel( mDev.getDirectional( i ) );
|
||||
mDirectionalLabels.add( lbl );
|
||||
mDirectionalPanel.add( lbl );
|
||||
|
||||
// Add an event listener:
|
||||
new DirectionalListener( mDev.getDirectional( i ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void update()
|
||||
{
|
||||
Iterator it = mAxisSliders.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
((AxisSlider)it.next()).update();
|
||||
}
|
||||
|
||||
it = mButtonCheckboxes.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
((ButtonCheckbox)it.next()).update();
|
||||
}
|
||||
|
||||
it = mDirectionalLabels.iterator();
|
||||
while ( it.hasNext() )
|
||||
{
|
||||
((DirectionalLabel)it.next()).update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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()
|
||||
{
|
||||
mAxesPanelContainer = new javax.swing.JPanel();
|
||||
mAxesPanel = new javax.swing.JPanel();
|
||||
mDirectionalPanel = new javax.swing.JPanel();
|
||||
mButtonScrollPane = new javax.swing.JScrollPane();
|
||||
mButtonsPanel = new javax.swing.JPanel();
|
||||
|
||||
setLayout(new java.awt.BorderLayout(2, 2));
|
||||
|
||||
addComponentListener(new java.awt.event.ComponentAdapter()
|
||||
{
|
||||
public void componentShown(java.awt.event.ComponentEvent evt)
|
||||
{
|
||||
OnShow(evt);
|
||||
}
|
||||
});
|
||||
|
||||
mAxesPanelContainer.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
mAxesPanelContainer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
mAxesPanel.setLayout(new java.awt.GridLayout(1, 1, 0, 20));
|
||||
|
||||
mAxesPanelContainer.add(mAxesPanel, java.awt.BorderLayout.NORTH);
|
||||
|
||||
add(mAxesPanelContainer, java.awt.BorderLayout.CENTER);
|
||||
|
||||
mDirectionalPanel.setLayout(new java.awt.GridLayout(1, 1));
|
||||
|
||||
mDirectionalPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
add(mDirectionalPanel, java.awt.BorderLayout.SOUTH);
|
||||
|
||||
mButtonsPanel.setLayout(new java.awt.GridLayout(1, 1));
|
||||
|
||||
mButtonsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
mButtonScrollPane.setViewportView(mButtonsPanel);
|
||||
|
||||
add(mButtonScrollPane, java.awt.BorderLayout.EAST);
|
||||
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void OnShow(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_OnShow
|
||||
{//GEN-HEADEREND:event_OnShow
|
||||
// Commented: the focus is held by a parent component
|
||||
// System.out.println("OnShow");
|
||||
// this.requestFocus();
|
||||
}//GEN-LAST:event_OnShow
|
||||
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel mAxesPanel;
|
||||
private javax.swing.JPanel mAxesPanelContainer;
|
||||
private javax.swing.JScrollPane mButtonScrollPane;
|
||||
private javax.swing.JPanel mButtonsPanel;
|
||||
private javax.swing.JPanel mDirectionalPanel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="title" type="java.lang.String" value="JXInput (C) 2001-2006 HARDCODE Dev."/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
</SyntheticProperties>
|
||||
<Events>
|
||||
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="closeDialog"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="mMainPanel">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout">
|
||||
<Property name="horizontalGap" type="int" value="10"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="mLabelNoDevice">
|
||||
<Properties>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="No JXInputDevice available!"/>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.SoftBevelBorderInfo">
|
||||
<BevelBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="North"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Container class="javax.swing.JTabbedPane" name="mDevicesTabbedPane">
|
||||
<Events>
|
||||
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="mDevicesTabbedPaneFocusGained"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="mButtonReset">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Reset "/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mButtonResetActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="South"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
@@ -1,286 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// Created on 27. Dezember 2001, 01:15
|
||||
//**********************************************************************************************
|
||||
|
||||
package de.hardcode.jxinput.test;
|
||||
|
||||
import de.hardcode.jxinput.*;
|
||||
import de.hardcode.jxinput.event.*;
|
||||
import de.hardcode.jxinput.keyboard.JXKeyboardInputDevice;
|
||||
import de.hardcode.jxinput.virtual.JXVirtualInputDevice;
|
||||
import de.hardcode.jxinput.virtual.VirtualAxis;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
|
||||
/**
|
||||
* 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 running 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
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 17. April 2002, 23:24
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.util;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class LatestChangedValueAxis implements Axis
|
||||
{
|
||||
private final Axis mAxis1;
|
||||
private final Axis mAxis2;
|
||||
private Axis mAxisInUse;
|
||||
|
||||
private double mSaved1;
|
||||
private double mSaved2;
|
||||
|
||||
/**
|
||||
* Creates a new instance of MeanValueAxis.
|
||||
*/
|
||||
public LatestChangedValueAxis(Axis a1, Axis a2)
|
||||
{
|
||||
mAxis1 = a1;
|
||||
mAxis2 = a2;
|
||||
mAxisInUse = a1;
|
||||
|
||||
mSaved1 = a1.getValue();
|
||||
mSaved2 = a2.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Features may have a name provided e.g. by the driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return mAxis1.getName();
|
||||
}
|
||||
|
||||
/** Inform about the resolution of the axis.
|
||||
*
|
||||
* @return resolution, e.g. 2^-16
|
||||
*/
|
||||
public double getResolution()
|
||||
{
|
||||
return mAxis1.getResolution();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the type of the axis.
|
||||
*
|
||||
* @return [ TRANSLATION | ROTATION | SLIDER ]
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return mAxis1.getType();
|
||||
}
|
||||
|
||||
/** Returns the current value of the axis.
|
||||
* The range of the result depends on the axis type.
|
||||
*s
|
||||
* @return value [-1.0,1.0] or [0.0,1.0]
|
||||
*/
|
||||
public double getValue()
|
||||
{
|
||||
double v1 = mAxis1.getValue();
|
||||
double v2 = mAxis2.getValue();
|
||||
|
||||
if ( Math.abs( v2 - mSaved2 ) > 0.2 )
|
||||
{
|
||||
mAxisInUse = mAxis2;
|
||||
mSaved2 = v2;
|
||||
}
|
||||
if ( Math.abs( v1 - mSaved1 ) > 0.2 )
|
||||
{
|
||||
mAxisInUse = mAxis1;
|
||||
mSaved1 = v1;
|
||||
}
|
||||
|
||||
return mAxisInUse.getValue();
|
||||
}
|
||||
|
||||
/** Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 23. Dezember 2002, 19:21
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.util;
|
||||
|
||||
import de.hardcode.jxinput.Button;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class OrButton implements Button
|
||||
{
|
||||
private final Button mButton1;
|
||||
private final Button mButton2;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of OrButton.
|
||||
*/
|
||||
public OrButton( Button b1, Button b2 )
|
||||
{
|
||||
mButton1 = b1;
|
||||
mButton2 = b2;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return mButton1.getName();
|
||||
}
|
||||
|
||||
public boolean getState()
|
||||
{
|
||||
return mButton1.getState() || mButton2.getState();
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return mButton1.getType();
|
||||
}
|
||||
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return mButton1.hasChanged() || mButton2.hasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
|
||||
import de.hardcode.jxinput.*;
|
||||
|
||||
|
||||
/**
|
||||
* Virtual input device.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
public class JXVirtualInputDevice implements JXInputDevice
|
||||
{
|
||||
private static final String DEVICENAME = "Virtual Device";
|
||||
|
||||
/** The driver doing all the real work. */
|
||||
private final VirtualDriver mDriver = new VirtualDriver();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of JXKeyboardInputDevice.
|
||||
*/
|
||||
public JXVirtualInputDevice()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The virtual input device needs to be updated regularly.
|
||||
*/
|
||||
public final void update( long deltaT )
|
||||
{
|
||||
//
|
||||
// Delegate the update call to the driver.
|
||||
//
|
||||
mDriver.update( deltaT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a virtual axis object with a certain ID, e.g. Axis.ID_X.
|
||||
*/
|
||||
public VirtualAxis createAxis( int id )
|
||||
{
|
||||
VirtualAxis a;
|
||||
a = new VirtualAxis( id );
|
||||
mDriver.registerVirtualAxis( id, a );
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
public void removeAxis( VirtualAxis a )
|
||||
{
|
||||
mDriver.unregisterVirtualAxis( a );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement JXInputDevice
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
public Axis getAxis(int idx)
|
||||
{
|
||||
return mDriver.getAxis( idx );
|
||||
}
|
||||
|
||||
|
||||
public Button getButton(int idx)
|
||||
{
|
||||
// No virtual buttons.
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Directional getDirectional(int idx)
|
||||
{
|
||||
// No virtual directionals.
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Maximum number of axes as an upper bound for index values. */
|
||||
public int getMaxNumberOfAxes()
|
||||
{
|
||||
return Axis.NUMBER_OF_ID;
|
||||
}
|
||||
|
||||
/** Maximum number of buttons as an upper bound for index values. */
|
||||
public int getMaxNumberOfButtons()
|
||||
{
|
||||
// No virtual buttons.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Maximum number of directional features as an upper bound for index values. */
|
||||
public int getMaxNumberOfDirectionals()
|
||||
{
|
||||
// No virtual directionals.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devices may have a name.
|
||||
* This name might be provided by a system dependant driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return DEVICENAME;
|
||||
}
|
||||
|
||||
/** Actual number of available axes. */
|
||||
public int getNumberOfAxes()
|
||||
{
|
||||
// No axes on keyboard.
|
||||
return mDriver.getNumberOfAxes();
|
||||
}
|
||||
|
||||
/** Actual number of available buttons. */
|
||||
public int getNumberOfButtons()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Actual number of available directional features. */
|
||||
public int getNumberOfDirectionals()
|
||||
{
|
||||
// No directionals on keyboard.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 11. April 2002, 23:40
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Button;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author J<>rg Plewe
|
||||
*/
|
||||
public class VirtualAxis
|
||||
implements Axis
|
||||
{
|
||||
|
||||
private int mType = Axis.TRANSLATION;
|
||||
private final int mID;
|
||||
private String mName = "VirtualAxis";
|
||||
private double mCurrentValue = 0;
|
||||
|
||||
private Button mButtonIncrease = null;
|
||||
private Button mButtonDecrease = null;
|
||||
private double mSpeed = 1.0 / 500.0;
|
||||
private double mSpringSpeed = 1.0 / 500.0;
|
||||
|
||||
/**
|
||||
* Creates a new instance of VirtualAxis.
|
||||
*/
|
||||
public VirtualAxis( int id )
|
||||
{
|
||||
mID = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the type of this axis to be either <code>Axis.ROTATION</code>,
|
||||
* <code>Axis.TRANSLATION</code> or <code>Axis.SLIDER</code>.
|
||||
*/
|
||||
public void setType( int type )
|
||||
{
|
||||
if ( Axis.ROTATION != type
|
||||
&& Axis.TRANSLATION != type
|
||||
&& Axis.SLIDER != type
|
||||
)
|
||||
throw new InvalidParameterException( "Invalid type for axis!" );
|
||||
|
||||
mType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update features under my control.
|
||||
*/
|
||||
final void update( long deltaT )
|
||||
{
|
||||
double change = mSpeed * deltaT;
|
||||
double springchange = mSpringSpeed * deltaT;
|
||||
boolean doincrease = ( null != mButtonIncrease && mButtonIncrease.getState() );
|
||||
boolean dodecrease = ( null != mButtonDecrease && mButtonDecrease.getState() );
|
||||
boolean iscontrolled = doincrease || dodecrease;
|
||||
|
||||
double controlledchange = 0.0;
|
||||
if ( doincrease )
|
||||
controlledchange += change;
|
||||
if ( dodecrease )
|
||||
controlledchange -= change;
|
||||
|
||||
mCurrentValue += controlledchange;
|
||||
|
||||
if ( mCurrentValue > 0.0 && ! doincrease )
|
||||
{
|
||||
springchange = Math.min( mCurrentValue, springchange );
|
||||
mCurrentValue -= springchange;
|
||||
}
|
||||
if ( mCurrentValue < 0.0 && ! dodecrease )
|
||||
{
|
||||
springchange = Math.min( -mCurrentValue, springchange );
|
||||
mCurrentValue += springchange;
|
||||
}
|
||||
|
||||
//
|
||||
// Hold value within range
|
||||
//
|
||||
if ( mCurrentValue > 1.0 )
|
||||
mCurrentValue = 1.0;
|
||||
double lowerlimit = Axis.SLIDER == mType ? 0.0 : -1.0;
|
||||
if ( mCurrentValue < lowerlimit )
|
||||
mCurrentValue = lowerlimit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the button to increase the axis for a single button axis.
|
||||
*/
|
||||
public final void setIncreaseButton( Button b )
|
||||
{
|
||||
if ( null == b )
|
||||
throw new InvalidParameterException( "SelectButton may not be null!" );
|
||||
|
||||
mButtonIncrease = b;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the buttons to increase and descrease the axis.
|
||||
*/
|
||||
public final void setButtons( Button increase, Button decrease )
|
||||
{
|
||||
if ( null == increase || null == decrease )
|
||||
throw new InvalidParameterException( "Buttons may not be null!" );
|
||||
|
||||
mButtonIncrease = increase;
|
||||
mButtonDecrease = decrease;
|
||||
}
|
||||
|
||||
|
||||
public final void setSpeed( double speed )
|
||||
{
|
||||
mSpeed = speed;
|
||||
}
|
||||
|
||||
public final void setSpringSpeed( double springspeed )
|
||||
{
|
||||
mSpringSpeed = springspeed;
|
||||
}
|
||||
|
||||
|
||||
public final void setTimeFor0To1( int ms )
|
||||
{
|
||||
if ( 0 >= ms )
|
||||
mSpeed = 0.0;
|
||||
else
|
||||
mSpeed = 1.0/ ms;
|
||||
}
|
||||
public final void setTimeFor1To0( int ms )
|
||||
{
|
||||
if ( 0 >= ms )
|
||||
mSpringSpeed = 0.0;
|
||||
else
|
||||
mSpringSpeed = 1.0/ ms;
|
||||
}
|
||||
|
||||
|
||||
public final void setName( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
//*********************************************************************************************
|
||||
//
|
||||
// Implement Axis
|
||||
//
|
||||
//*********************************************************************************************
|
||||
|
||||
/**
|
||||
* Features may have a name provided e.g. by the driver.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform about the resolution of the axis.
|
||||
*
|
||||
* @return resolution, e.g. 2^-16
|
||||
*/
|
||||
public double getResolution()
|
||||
{
|
||||
return 1.0/65536.0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the type of the axis.
|
||||
* @return [ TRANSLATION | ROTATION | SLIDER ]
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
/** Returns the current value of the axis.
|
||||
* The range of the result depends on the axis type.
|
||||
*
|
||||
* @return value [-1.0,1.0] or [0.0,1.0]
|
||||
*/
|
||||
public double getValue()
|
||||
{
|
||||
return mCurrentValue;
|
||||
}
|
||||
|
||||
/** Denote wether this feature has changed beyond it's resolution since it got last
|
||||
* updated.
|
||||
*/
|
||||
public boolean hasChanged()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
//**********************************************************************************************
|
||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||
// All rights reserved. Copying, modification,
|
||||
// distribution or publication without the prior written
|
||||
// consent of the author is prohibited.
|
||||
//
|
||||
// Created on 9. April 2002, 22:43
|
||||
//**********************************************************************************************
|
||||
package de.hardcode.jxinput.virtual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import de.hardcode.jxinput.Axis;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is the main worker class for JXVirtualInputDevice.
|
||||
*
|
||||
* @author Herkules
|
||||
*/
|
||||
class VirtualDriver
|
||||
{
|
||||
|
||||
private final VirtualAxis[] mVAxes = new VirtualAxis[ Axis.NUMBER_OF_ID ];
|
||||
|
||||
/**
|
||||
* Creates a new instance of KeyboardDriver.
|
||||
*/
|
||||
VirtualDriver()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update features under my control.
|
||||
*/
|
||||
final void update( long deltaT )
|
||||
{
|
||||
//
|
||||
// Delegate the update call to the axes in use.
|
||||
//
|
||||
for ( int i = 0; i < mVAxes.length; i++ )
|
||||
{
|
||||
if ( null != mVAxes[ i ] )
|
||||
mVAxes[ i ].update( deltaT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many axes are registered?
|
||||
*/
|
||||
final int getNumberOfAxes()
|
||||
{
|
||||
int ctr = 0;
|
||||
for ( int i = 0; i < mVAxes.length; i++ )
|
||||
{
|
||||
if ( null != mVAxes[ i ] )
|
||||
ctr++;
|
||||
}
|
||||
return ctr;
|
||||
}
|
||||
|
||||
Axis getAxis(int idx)
|
||||
{
|
||||
return mVAxes[ idx ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Place a new axis under my observation.
|
||||
*/
|
||||
final void registerVirtualAxis( int id, VirtualAxis a )
|
||||
{
|
||||
mVAxes[ id ] = a;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an axis from my control.
|
||||
*/
|
||||
final void unregisterVirtualAxis( VirtualAxis a )
|
||||
{
|
||||
for ( int i = 0; i < mVAxes.length; ++i )
|
||||
{
|
||||
if ( mVAxes[ i ] == a )
|
||||
{
|
||||
mVAxes[ i ] = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>de.hardcode.jxinput.virtual</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
Allows to define virtual axes that are not derived from any device
|
||||
but from other JXInput feature objects.
|
||||
</BODY>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user