Compare commits
10 Commits
f45b3ebaf8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c4948c1ff1 | |||
| 45f730d9f3 | |||
| c818598abc | |||
| f228bb4d10 | |||
| d8f4fd4634 | |||
| d6fb64af87 | |||
| 13c0f94db7 | |||
| 58ee08a042 | |||
| db20df3b6f | |||
| 3e91cd1b51 |
@@ -1,5 +0,0 @@
|
|||||||
classes
|
|
||||||
tmp
|
|
||||||
build
|
|
||||||
archiv
|
|
||||||
|
|
||||||
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
build
|
||||||
|
bin
|
||||||
|
.settings
|
||||||
|
.maven
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.gradle
|
||||||
619
LICENSE
Normal file
619
LICENSE
Normal file
@@ -0,0 +1,619 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
21
LICENSE.orig.txt
Normal file
21
LICENSE.orig.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Ivan "StrikerX3" Oliveira
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
52
README.md
Normal file
52
README.md
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
Fork of <http://drts.cvs.sourceforge.net/viewvc/drts/projects/jxinput/>, see <http://www.hardcode.de/jxinput/>.
|
||||||
|
|
||||||
|
----------
|
||||||
|
|
||||||
|
JXInput - Input Devices for Java
|
||||||
|
================
|
||||||
|
|
||||||
|
|
||||||
|
Java as it comes in the common distribution does not provide any means to access typical gaming devices like joysticks, gamepads and such.
|
||||||
|
|
||||||
|
But many people out there are actually using Java for writing games! Imagine a flight simulator without a joystick, a sports game without a gamepad, a racing game without a steering wheel.
|
||||||
|
|
||||||
|
For the Java community is typically very active I was wondering whether there are not [zillions](http://www.hardcode.de/jxinput/jxlinks.html) of extensions contributed by the community. Well, I found a few, but none of them reflected the complexity and the possibilities of state-of-the-art input devices we find today.
|
||||||
|
|
||||||
|
## Technique ##
|
||||||
|
|
||||||
|
As long as JXInput is used in a way that it just uses common Java features (see KeyboardDevice/VirtualDevice), JXInput is a 100% pure Java library.
|
||||||
|
|
||||||
|
But for Java does not support joysticks in a portable fashion, the binding to physical devices has to be done in a platform dependent manner. So system specific libraries come into play and the 100% pure Java beauty is gone. This also means that applications using JXInput then cannot be simple Applets, but always have to take precauti[ons concerning download, installation and security. ](http://www.java.sun.com/cgi-bin/javawebstart-platform.sh?)Sun's WebStart technology is a suitable mechanism to bring even these kind of libraries to the people at home.
|
||||||
|
|
||||||
|
The current implementation connects to devices using Microsoft DirectInput (DirectX8) and reflects the features, but not the design of that commonly used library.
|
||||||
|
This may be extended in the future, because the design of the package is not Win32 specific and it should be quite easy to add other native support libraries e.g. for Linux or MacOS.
|
||||||
|
|
||||||
|
For the platforms that cannot be supported by the DirectInput binding such as MacOS or Linux, JXInput offers means to query the Swing keyboard an emulate the desired joystick functions.
|
||||||
|
|
||||||
|
BTW, the native Win32 library works standalone as well providing an easy-to-use wrapper around DirectInput devices.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Features ##
|
||||||
|
JXInput gives access to any number of DirectInput gaming devices - although it seems to be quite unusual to have more than one connected.
|
||||||
|
Additionally, JXInput allows to interpret each key on the keyboard as interpreted by Swing to be a JXInput button. This gives another source for about 100 additional buttons.
|
||||||
|
|
||||||
|
For computer without a phyisical joystick attached, JXInput offers the possibility to emulate 'virtual' joystick axes with help from a set of buttons. So it is very easy to use a 'virtual' joystick by using the e.g. the cursor keys.
|
||||||
|
|
||||||
|
For each device, the following features are supported:
|
||||||
|
|
||||||
|
- 6 axis (3 translational, 3 rotational)
|
||||||
|
- 2 sliders
|
||||||
|
- 4 directional devices; coolie hats
|
||||||
|
- 256 buttons
|
||||||
|
|
||||||
|
JXInput allows to ask for the features available with a given device and later to query their respective values. This is the way most games work, polling the state of the inputdevice within a loop.
|
||||||
|
|
||||||
|
For event driven applications, JXInput allows to register 'listener' objects with the features. This way, the application is called back by JXInput in case the input device changes it's state.
|
||||||
|
|
||||||
|
There also is a third mode of operation allowing JXInput to be used with Java3D. In order to be able to work in a Java3D environment, JXInput implements the predefined interface javax.media.j3d.InputDevice. So JXInput can be added to existing Java3D projects without breaking the code.
|
||||||
|
|
||||||
|
## Performance ##
|
||||||
|
|
||||||
|
JXInput uses JNI (Java Native Interface) to access the native library. JNI is not known to be too fast, so the number of calls has been minimized: 1. The polling of the devices state is managed by JXInput in a single JNI call.
|
||||||
|
Another possible performance drain is the allocation and deallocation of objects. Therefore, after being setup, JXInput does no longer create any objects at all.
|
||||||
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
168
build.gradle
Normal file
168
build.gradle
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
apply plugin: 'cpp'
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'https://github.com/Boukefalos/jlibloader/raw/mvn-repo/'
|
||||||
|
}
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile 'java3d:j3d-core:1.3.1'
|
||||||
|
compile 'com.github.boukefalos:jlibloader:0.2'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.github.boukefalos'
|
||||||
|
project.archivesBaseName = 'jlibxinput'
|
||||||
|
version = '1.0'
|
||||||
|
|
||||||
|
task wrapper(type: Wrapper) {
|
||||||
|
gradleVersion = '1.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
model {
|
||||||
|
platforms {
|
||||||
|
windows_i386 {
|
||||||
|
architecture 'i386'
|
||||||
|
operatingSystem 'windows'
|
||||||
|
}
|
||||||
|
windows_amd64 {
|
||||||
|
architecture 'amd64'
|
||||||
|
operatingSystem 'windows'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toolChains {
|
||||||
|
visualCpp(VisualCpp)
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
libs(PrebuiltLibraries) {
|
||||||
|
dxguid {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/dxguid.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dinput8 {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/dinput8.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user32 {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/user32.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def jniHeadersDir = file("$buildDir/headers")
|
||||||
|
|
||||||
|
task jniHeaders(dependsOn: compileJava) {
|
||||||
|
def outputFile = file("$jniHeadersDir/de_hardcode_jxinput_directinput_DirectInputDriver.h")
|
||||||
|
inputs.files sourceSets.main.output
|
||||||
|
outputs.file outputFile
|
||||||
|
exec {
|
||||||
|
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
|
||||||
|
args '-o', outputFile
|
||||||
|
args '-classpath', sourceSets.main.output.classesDir
|
||||||
|
args '-classpath', file("$buildDir/../bin")
|
||||||
|
args 'de.hardcode.jxinput.directinput.DirectInputDriver'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libraries {
|
||||||
|
main {
|
||||||
|
baseName project.archivesBaseName
|
||||||
|
}
|
||||||
|
all {
|
||||||
|
binaries.withType(SharedLibraryBinary) { binary ->
|
||||||
|
cppCompiler.define 'JXINPUT_EXPORTS'
|
||||||
|
cppCompiler.args '-I' + jniHeadersDir
|
||||||
|
if (targetPlatform.operatingSystem.macOsX) {
|
||||||
|
cppCompiler.args '-I', "/System/Library/Frameworks/JavaVM.framework/Headers"
|
||||||
|
linker.args '-framework', "JavaVM"
|
||||||
|
} else if (targetPlatform.operatingSystem.linux) {
|
||||||
|
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
|
||||||
|
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
|
||||||
|
} else if (targetPlatform.operatingSystem.windows) {
|
||||||
|
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
|
||||||
|
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
|
||||||
|
}
|
||||||
|
tasks.withType(CppCompile) { task ->
|
||||||
|
task.dependsOn jniHeaders
|
||||||
|
}
|
||||||
|
lib library: 'dxguid', linkage: 'static'
|
||||||
|
lib library: 'dinput8', linkage: 'static'
|
||||||
|
lib library: 'user32', linkage: 'static'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(Upload) {
|
||||||
|
repositories {
|
||||||
|
mavenDeployer {
|
||||||
|
repository(url: uri('.maven'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
jni
|
||||||
|
}
|
||||||
|
|
||||||
|
def deployer = uploadJni.repositories.mavenDeployer
|
||||||
|
|
||||||
|
binaries.withType(SharedLibraryBinary) { binary ->
|
||||||
|
if (!buildable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
def variantName = "${targetPlatform.operatingSystem.name}-${targetPlatform.architecture.name}"
|
||||||
|
def taskName = "jar-${variantName}"
|
||||||
|
def nativeJar = project.tasks.findByName(taskName)
|
||||||
|
if (nativeJar == null) {
|
||||||
|
nativeJar = project.task(taskName, type: Jar) {
|
||||||
|
baseName = "${project.archivesBaseName}-$variantName"
|
||||||
|
}
|
||||||
|
artifacts {
|
||||||
|
jni nativeJar
|
||||||
|
}
|
||||||
|
def jniPom = deployer.addFilter(variantName) { artifact, file ->
|
||||||
|
return file == nativeJar.archivePath
|
||||||
|
}
|
||||||
|
jniPom.groupId = project.group
|
||||||
|
jniPom.artifactId = nativeJar.baseName
|
||||||
|
jniPom.version = project.version
|
||||||
|
jniPom.scopeMappings.mappings.clear()
|
||||||
|
}
|
||||||
|
def builderTask = binary.tasks.builder
|
||||||
|
def libraryDirectory = project.group.replace('.', '/') + "/${project.archivesBaseName}/${variantName}"
|
||||||
|
nativeJar.into(libraryDirectory) { from builderTask.outputFile }
|
||||||
|
nativeJar.dependsOn builderTask
|
||||||
|
}
|
||||||
|
|
||||||
|
def mainPom = uploadArchives.repositories.mavenDeployer.pom
|
||||||
|
mainPom.groupId = project.group
|
||||||
|
mainPom.artifactId = jar.baseName
|
||||||
|
mainPom.version = project.version
|
||||||
|
mainPom.scopeMappings.mappings.clear()
|
||||||
|
mainPom.withXml { provider ->
|
||||||
|
def node = provider.asNode()
|
||||||
|
def deps = node.appendNode('dependencies')
|
||||||
|
['windows-amd64', 'windows-i386'].each { platform ->
|
||||||
|
def dep = deps.appendNode('dependency')
|
||||||
|
dep.appendNode('groupId', project.group)
|
||||||
|
dep.appendNode('artifactId', "${project.archivesBaseName}-${platform}")
|
||||||
|
dep.appendNode('version', project.version)
|
||||||
|
}
|
||||||
|
def dep = deps.appendNode('dependency')
|
||||||
|
dep.appendNode('groupId', 'com.github.boukefalos')
|
||||||
|
dep.appendNode('artifactId', 'jlibloader')
|
||||||
|
dep.appendNode('version', '0.2')
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from sourceSets.main.allSource
|
||||||
|
}
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Created by Herkules.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project basedir="." default="all" name="jxinput">
|
|
||||||
|
|
||||||
<target name="init">
|
|
||||||
<property name="srcdir" value="../java"/>
|
|
||||||
<property name="dstdir" value="../build"/>
|
|
||||||
<property name="tmpdir" value="../tmp"/>
|
|
||||||
<property name="classesdir" value="../classes"/>
|
|
||||||
<property name="docdir" value="${dstdir}/javadoc"/>
|
|
||||||
<property name="jarfile" value="${dstdir}/jxinput.jar"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target depends="init" name="compile">
|
|
||||||
<mkdir dir="${classesdir}"/>
|
|
||||||
<javac debug="true" deprecation="true" destdir="${classesdir}" srcdir="${srcdir}">
|
|
||||||
<classpath>
|
|
||||||
<pathelement location="../../third-party/java3d/win32/lib/ext/j3dcore.jar"/>
|
|
||||||
<pathelement location="../../third-party/java3d/win32/lib/ext/j3dutils.jar"/>
|
|
||||||
<pathelement location="../../third-party/java3d/win32/lib/ext/vecmath.jar"/>
|
|
||||||
</classpath>
|
|
||||||
</javac>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target depends="init,compile" name="jar">
|
|
||||||
<mkdir dir="${dstdir}"/>
|
|
||||||
<jar basedir="${classesdir}" compress="true" jarfile="${jarfile}"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <target depends="init,all" description="Try running it." name="test">
|
|
||||||
<java classname="com.foo.Main" failonerror="true" fork="true">
|
|
||||||
<classpath>
|
|
||||||
<pathelement location="."/>
|
|
||||||
</classpath>
|
|
||||||
<arg value="-myfile"/>
|
|
||||||
<arg file="myfile.txt"/>
|
|
||||||
</java>
|
|
||||||
</target>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<target depends="init" description="Javadoc for my API." name="javadoc">
|
|
||||||
<mkdir dir="${docdir}"/>
|
|
||||||
<javadoc destdir="${docdir}" sourcepath="${srcdir}" packagenames="*">
|
|
||||||
</javadoc>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Clean expects that the jxinput.dll is compiled into the dstdir
|
|
||||||
and may NOT be deleted!
|
|
||||||
-->
|
|
||||||
<target depends="init" description="Clean all build products." name="clean">
|
|
||||||
<delete>
|
|
||||||
<fileset dir="${dstdir}" includes="**/*" excludes="**/*.dll"/>
|
|
||||||
</delete>
|
|
||||||
<delete dir="${tmpdir}"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target depends="init,jar" description="Build everything." name="all">
|
|
||||||
<echo message="Application built."/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
build
|
|
||||||
dist
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!-- You may freely edit this file. See commented blocks below for -->
|
|
||||||
<!-- some examples of how to customize the build. -->
|
|
||||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
|
||||||
<project name="jxinput" default="default" basedir=".">
|
|
||||||
<description>Builds, tests, and runs the project jxinput.</description>
|
|
||||||
<import file="nbproject/build-impl.xml"/>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
There exist several targets which are by default empty and which can be
|
|
||||||
used for execution of your tasks. These targets are usually executed
|
|
||||||
before and after some main targets. They are:
|
|
||||||
|
|
||||||
-pre-init: called before initialization of project properties
|
|
||||||
-post-init: called after initialization of project properties
|
|
||||||
-pre-compile: called before javac compilation
|
|
||||||
-post-compile: called after javac compilation
|
|
||||||
-pre-compile-single: called before javac compilation of single file
|
|
||||||
-post-compile-single: called after javac compilation of single file
|
|
||||||
-pre-compile-test: called before javac compilation of JUnit tests
|
|
||||||
-post-compile-test: called after javac compilation of JUnit tests
|
|
||||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
|
||||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
|
||||||
-pre-jar: called before JAR building
|
|
||||||
-post-jar: called after JAR building
|
|
||||||
-post-clean: called after cleaning build products
|
|
||||||
|
|
||||||
(Targets beginning with '-' are not intended to be called on their own.)
|
|
||||||
|
|
||||||
Example of inserting an obfuscator after compilation could look like this:
|
|
||||||
|
|
||||||
<target name="-post-compile">
|
|
||||||
<obfuscate>
|
|
||||||
<fileset dir="${build.classes.dir}"/>
|
|
||||||
</obfuscate>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
For list of available properties check the imported
|
|
||||||
nbproject/build-impl.xml file.
|
|
||||||
|
|
||||||
|
|
||||||
Another way to customize the build is by overriding existing main targets.
|
|
||||||
The targets of interest are:
|
|
||||||
|
|
||||||
-init-macrodef-javac: defines macro for javac compilation
|
|
||||||
-init-macrodef-junit: defines macro for junit execution
|
|
||||||
-init-macrodef-debug: defines macro for class debugging
|
|
||||||
-init-macrodef-java: defines macro for class execution
|
|
||||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
|
||||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
|
||||||
run: execution of project
|
|
||||||
-javadoc-build: Javadoc generation
|
|
||||||
test-report: JUnit report generation
|
|
||||||
|
|
||||||
An example of overriding the target for project execution could look like this:
|
|
||||||
|
|
||||||
<target name="run" depends="jxinput-impl.jar">
|
|
||||||
<exec dir="bin" executable="launcher.exe">
|
|
||||||
<arg file="${dist.jar}"/>
|
|
||||||
</exec>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
Notice that the overridden target depends on the jar target and not only on
|
|
||||||
the compile target as the regular run target does. Again, for a list of available
|
|
||||||
properties which you can use, check the target you are overriding in the
|
|
||||||
nbproject/build-impl.xml file.
|
|
||||||
|
|
||||||
-->
|
|
||||||
</project>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
X-COMMENT: Main-Class will be added automatically by build
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
private
|
|
||||||
@@ -1,532 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
|
||||||
*** EDIT ../build.xml INSTEAD ***
|
|
||||||
|
|
||||||
For the purpose of easier reading the script
|
|
||||||
is divided into following sections:
|
|
||||||
|
|
||||||
- initialization
|
|
||||||
- compilation
|
|
||||||
- jar
|
|
||||||
- execution
|
|
||||||
- debugging
|
|
||||||
- javadoc
|
|
||||||
- junit compilation
|
|
||||||
- junit execution
|
|
||||||
- junit debugging
|
|
||||||
- applet
|
|
||||||
- cleanup
|
|
||||||
|
|
||||||
-->
|
|
||||||
<project name="jxinput-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
|
||||||
<!--
|
|
||||||
======================
|
|
||||||
INITIALIZATION SECTION
|
|
||||||
======================
|
|
||||||
-->
|
|
||||||
<target name="-pre-init">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-init-private" depends="-pre-init">
|
|
||||||
<property file="nbproject/private/private.properties"/>
|
|
||||||
</target>
|
|
||||||
<target name="-init-user" depends="-pre-init,-init-private">
|
|
||||||
<property file="${user.properties.file}"/>
|
|
||||||
<!-- The two properties below are usually overridden -->
|
|
||||||
<!-- by the active platform. Just a fallback. -->
|
|
||||||
<property name="default.javac.source" value="1.4"/>
|
|
||||||
<property name="default.javac.target" value="1.4"/>
|
|
||||||
</target>
|
|
||||||
<target name="-init-project" depends="-pre-init,-init-private,-init-user">
|
|
||||||
<property file="nbproject/project.properties"/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-init" depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property">
|
|
||||||
<available file="${manifest.file}" property="manifest.available"/>
|
|
||||||
<condition property="manifest.available+main.class">
|
|
||||||
<and>
|
|
||||||
<isset property="manifest.available"/>
|
|
||||||
<isset property="main.class"/>
|
|
||||||
<not>
|
|
||||||
<equals arg1="${main.class}" arg2="" trim="true"/>
|
|
||||||
</not>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<condition property="manifest.available+main.class+mkdist.available">
|
|
||||||
<and>
|
|
||||||
<istrue value="${manifest.available+main.class}"/>
|
|
||||||
<isset property="libs.CopyLibs.classpath"/>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<condition property="have.tests">
|
|
||||||
<or/>
|
|
||||||
</condition>
|
|
||||||
<condition property="have.sources">
|
|
||||||
<or>
|
|
||||||
<available file="${src.dir}"/>
|
|
||||||
</or>
|
|
||||||
</condition>
|
|
||||||
<condition property="netbeans.home+have.tests">
|
|
||||||
<and>
|
|
||||||
<isset property="netbeans.home"/>
|
|
||||||
<isset property="have.tests"/>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<condition property="no.javadoc.preview">
|
|
||||||
<isfalse value="${javadoc.preview}"/>
|
|
||||||
</condition>
|
|
||||||
<property name="run.jvmargs" value=""/>
|
|
||||||
<property name="javac.compilerargs" value=""/>
|
|
||||||
<property name="work.dir" value="${basedir}"/>
|
|
||||||
<condition property="no.deps">
|
|
||||||
<and>
|
|
||||||
<istrue value="${no.dependencies}"/>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<property name="javac.debug" value="true"/>
|
|
||||||
<property name="javadoc.preview" value="true"/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-init">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-init-check" depends="-pre-init,-init-private,-init-user,-init-project,-do-init">
|
|
||||||
<fail unless="src.dir">Must set src.dir</fail>
|
|
||||||
<fail unless="build.dir">Must set build.dir</fail>
|
|
||||||
<fail unless="dist.dir">Must set dist.dir</fail>
|
|
||||||
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
|
|
||||||
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
|
|
||||||
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
|
|
||||||
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
|
|
||||||
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
|
|
||||||
<fail unless="dist.jar">Must set dist.jar</fail>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-property">
|
|
||||||
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<attribute name="name"/>
|
|
||||||
<attribute name="value"/>
|
|
||||||
<sequential>
|
|
||||||
<property name="@{name}" value="${@{value}}"/>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-javac">
|
|
||||||
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
|
|
||||||
<attribute name="srcdir" default="${src.dir}"/>
|
|
||||||
<attribute name="destdir" default="${build.classes.dir}"/>
|
|
||||||
<attribute name="classpath" default="${javac.classpath}"/>
|
|
||||||
<attribute name="debug" default="${javac.debug}"/>
|
|
||||||
<element name="customize" optional="true"/>
|
|
||||||
<sequential>
|
|
||||||
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
|
|
||||||
<classpath>
|
|
||||||
<path path="@{classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
<compilerarg line="${javac.compilerargs}"/>
|
|
||||||
<customize/>
|
|
||||||
</javac>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-junit">
|
|
||||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
|
||||||
<attribute name="includes" default="**/*Test.java"/>
|
|
||||||
<sequential>
|
|
||||||
<junit showoutput="true" fork="true" dir="${basedir}" failureproperty="tests.failed" errorproperty="tests.failed">
|
|
||||||
<batchtest todir="${build.test.results.dir}"/>
|
|
||||||
<classpath>
|
|
||||||
<path path="${run.test.classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
<syspropertyset>
|
|
||||||
<propertyref prefix="test-sys-prop."/>
|
|
||||||
<mapper type="glob" from="test-sys-prop.*" to="*"/>
|
|
||||||
</syspropertyset>
|
|
||||||
<formatter type="brief" usefile="false"/>
|
|
||||||
<formatter type="xml"/>
|
|
||||||
<jvmarg line="${run.jvmargs}"/>
|
|
||||||
</junit>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-nbjpda">
|
|
||||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<attribute name="name" default="${main.class}"/>
|
|
||||||
<attribute name="classpath" default="${debug.classpath}"/>
|
|
||||||
<attribute name="stopclassname" default=""/>
|
|
||||||
<sequential>
|
|
||||||
<nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}">
|
|
||||||
<classpath>
|
|
||||||
<path path="@{classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
</nbjpdastart>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<attribute name="dir" default="${build.classes.dir}"/>
|
|
||||||
<sequential>
|
|
||||||
<nbjpdareload>
|
|
||||||
<fileset includes="${fix.includes}*.class" dir="@{dir}"/>
|
|
||||||
</nbjpdareload>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-debug">
|
|
||||||
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
|
||||||
<attribute name="classname" default="${main.class}"/>
|
|
||||||
<attribute name="classpath" default="${debug.classpath}"/>
|
|
||||||
<element name="customize" optional="true"/>
|
|
||||||
<sequential>
|
|
||||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
|
||||||
<jvmarg value="-Xdebug"/>
|
|
||||||
<jvmarg value="-Xnoagent"/>
|
|
||||||
<jvmarg value="-Djava.compiler=none"/>
|
|
||||||
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
|
||||||
<jvmarg line="${run.jvmargs}"/>
|
|
||||||
<classpath>
|
|
||||||
<path path="@{classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
<syspropertyset>
|
|
||||||
<propertyref prefix="run-sys-prop."/>
|
|
||||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
|
||||||
</syspropertyset>
|
|
||||||
<customize/>
|
|
||||||
</java>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-macrodef-java">
|
|
||||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<attribute name="classname" default="${main.class}"/>
|
|
||||||
<element name="customize" optional="true"/>
|
|
||||||
<sequential>
|
|
||||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
|
||||||
<jvmarg line="${run.jvmargs}"/>
|
|
||||||
<classpath>
|
|
||||||
<path path="${run.classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
<syspropertyset>
|
|
||||||
<propertyref prefix="run-sys-prop."/>
|
|
||||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
|
||||||
</syspropertyset>
|
|
||||||
<customize/>
|
|
||||||
</java>
|
|
||||||
</sequential>
|
|
||||||
</macrodef>
|
|
||||||
</target>
|
|
||||||
<target name="-init-presetdef-jar">
|
|
||||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
|
||||||
<jar jarfile="${dist.jar}" compress="${jar.compress}">
|
|
||||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
|
||||||
</jar>
|
|
||||||
</presetdef>
|
|
||||||
</target>
|
|
||||||
<target name="init" depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar"/>
|
|
||||||
<!--
|
|
||||||
===================
|
|
||||||
COMPILATION SECTION
|
|
||||||
===================
|
|
||||||
-->
|
|
||||||
<target name="deps-jar" depends="init" unless="no.deps"/>
|
|
||||||
<target name="-pre-pre-compile" depends="init,deps-jar">
|
|
||||||
<mkdir dir="${build.classes.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-pre-compile">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile" if="have.sources">
|
|
||||||
<j2seproject3:javac/>
|
|
||||||
<copy todir="${build.classes.dir}">
|
|
||||||
<fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
|
|
||||||
</copy>
|
|
||||||
</target>
|
|
||||||
<target name="-post-compile">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project."/>
|
|
||||||
<target name="-pre-compile-single">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">
|
|
||||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
|
||||||
<j2seproject3:javac>
|
|
||||||
<customize>
|
|
||||||
<patternset includes="${javac.includes}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject3:javac>
|
|
||||||
</target>
|
|
||||||
<target name="-post-compile-single">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="compile-single" depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single"/>
|
|
||||||
<!--
|
|
||||||
====================
|
|
||||||
JAR BUILDING SECTION
|
|
||||||
====================
|
|
||||||
-->
|
|
||||||
<target name="-pre-pre-jar" depends="init">
|
|
||||||
<dirname property="dist.jar.dir" file="${dist.jar}"/>
|
|
||||||
<mkdir dir="${dist.jar.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-pre-jar">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-do-jar-without-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" unless="manifest.available">
|
|
||||||
<j2seproject1:jar/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-jar-with-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" unless="manifest.available+main.class">
|
|
||||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-jar-with-mainclass" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" unless="manifest.available+main.class+mkdist.available">
|
|
||||||
<j2seproject1:jar manifest="${manifest.file}">
|
|
||||||
<j2seproject1:manifest>
|
|
||||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
|
||||||
</j2seproject1:manifest>
|
|
||||||
</j2seproject1:jar>
|
|
||||||
<echo>To run this application from the command line without Ant, try:</echo>
|
|
||||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
|
||||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
|
||||||
<pathconvert property="run.classpath.with.dist.jar">
|
|
||||||
<path path="${run.classpath}"/>
|
|
||||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
|
||||||
</pathconvert>
|
|
||||||
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
|
||||||
</target>
|
|
||||||
<target name="-do-jar-with-libraries" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available">
|
|
||||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
|
||||||
<pathconvert property="run.classpath.without.build.classes.dir">
|
|
||||||
<path path="${run.classpath}"/>
|
|
||||||
<map from="${build.classes.dir.resolved}" to=""/>
|
|
||||||
</pathconvert>
|
|
||||||
<pathconvert property="jar.classpath" pathsep=" ">
|
|
||||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
|
||||||
<chainedmapper>
|
|
||||||
<flattenmapper/>
|
|
||||||
<globmapper from="*" to="lib/*"/>
|
|
||||||
</chainedmapper>
|
|
||||||
</pathconvert>
|
|
||||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" name="copylibs" classpath="${libs.CopyLibs.classpath}"/>
|
|
||||||
<copylibs manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}" jarfile="${dist.jar}" compress="${jar.compress}">
|
|
||||||
<fileset dir="${build.classes.dir}"/>
|
|
||||||
<manifest>
|
|
||||||
<attribute name="Main-Class" value="${main.class}"/>
|
|
||||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
|
||||||
</manifest>
|
|
||||||
</copylibs>
|
|
||||||
<echo>To run this application from the command line without Ant, try:</echo>
|
|
||||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
|
||||||
<echo>java -jar "${dist.jar.resolved}"</echo>
|
|
||||||
</target>
|
|
||||||
<target name="-post-jar">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="jar" depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR."/>
|
|
||||||
<!--
|
|
||||||
=================
|
|
||||||
EXECUTION SECTION
|
|
||||||
=================
|
|
||||||
-->
|
|
||||||
<target name="run" depends="init,compile" description="Run a main class.">
|
|
||||||
<j2seproject1:java>
|
|
||||||
<customize>
|
|
||||||
<arg line="${application.args}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject1:java>
|
|
||||||
</target>
|
|
||||||
<target name="run-single" depends="init,compile-single">
|
|
||||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
|
||||||
<j2seproject1:java classname="${run.class}"/>
|
|
||||||
</target>
|
|
||||||
<!--
|
|
||||||
=================
|
|
||||||
DEBUGGING SECTION
|
|
||||||
=================
|
|
||||||
-->
|
|
||||||
<target name="-debug-start-debugger" if="netbeans.home" depends="init">
|
|
||||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-debug-start-debuggee" depends="init,compile">
|
|
||||||
<j2seproject3:debug>
|
|
||||||
<customize>
|
|
||||||
<arg line="${application.args}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject3:debug>
|
|
||||||
</target>
|
|
||||||
<target name="debug" if="netbeans.home" depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE."/>
|
|
||||||
<target name="-debug-start-debugger-stepinto" if="netbeans.home" depends="init">
|
|
||||||
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
|
|
||||||
</target>
|
|
||||||
<target name="debug-stepinto" if="netbeans.home" depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee"/>
|
|
||||||
<target name="-debug-start-debuggee-single" if="netbeans.home" depends="init,compile-single">
|
|
||||||
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
|
|
||||||
<j2seproject3:debug classname="${debug.class}"/>
|
|
||||||
</target>
|
|
||||||
<target name="debug-single" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single"/>
|
|
||||||
<target name="-pre-debug-fix" depends="init">
|
|
||||||
<fail unless="fix.includes">Must set fix.includes</fail>
|
|
||||||
<property name="javac.includes" value="${fix.includes}.java"/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
|
|
||||||
<j2seproject1:nbjpdareload/>
|
|
||||||
</target>
|
|
||||||
<target name="debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix"/>
|
|
||||||
<!--
|
|
||||||
===============
|
|
||||||
JAVADOC SECTION
|
|
||||||
===============
|
|
||||||
-->
|
|
||||||
<target name="-javadoc-build" depends="init">
|
|
||||||
<mkdir dir="${dist.javadoc.dir}"/>
|
|
||||||
<javadoc destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" additionalparam="${javadoc.additionalparam}" failonerror="true" useexternalfile="true">
|
|
||||||
<classpath>
|
|
||||||
<path path="${javac.classpath}"/>
|
|
||||||
</classpath>
|
|
||||||
<sourcepath>
|
|
||||||
<pathelement location="${src.dir}"/>
|
|
||||||
</sourcepath>
|
|
||||||
<packageset dir="${src.dir}" includes="*/**"/>
|
|
||||||
<fileset dir="${src.dir}" includes="*.java"/>
|
|
||||||
</javadoc>
|
|
||||||
</target>
|
|
||||||
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="init,-javadoc-build">
|
|
||||||
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
|
|
||||||
</target>
|
|
||||||
<target name="javadoc" depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc."/>
|
|
||||||
<!--
|
|
||||||
=========================
|
|
||||||
JUNIT COMPILATION SECTION
|
|
||||||
=========================
|
|
||||||
-->
|
|
||||||
<target name="-pre-pre-compile-test" if="have.tests" depends="init,compile">
|
|
||||||
<mkdir dir="${build.test.classes.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-pre-compile-test">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-do-compile-test" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test">
|
|
||||||
<j2seproject3:javac srcdir="" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}"/>
|
|
||||||
<copy todir="${build.test.classes.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-compile-test">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="compile-test" depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test"/>
|
|
||||||
<target name="-pre-compile-test-single">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="-do-compile-test-single" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single">
|
|
||||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
|
||||||
<j2seproject3:javac srcdir="" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}">
|
|
||||||
<customize>
|
|
||||||
<patternset includes="${javac.includes}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject3:javac>
|
|
||||||
<copy todir="${build.test.classes.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-compile-test-single">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="compile-test-single" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single"/>
|
|
||||||
<!--
|
|
||||||
=======================
|
|
||||||
JUNIT EXECUTION SECTION
|
|
||||||
=======================
|
|
||||||
-->
|
|
||||||
<target name="-pre-test-run" if="have.tests" depends="init">
|
|
||||||
<mkdir dir="${build.test.results.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-test-run" if="have.tests" depends="init,compile-test,-pre-test-run">
|
|
||||||
<j2seproject3:junit/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-test-run" if="have.tests" depends="init,compile-test,-pre-test-run,-do-test-run">
|
|
||||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
|
||||||
</target>
|
|
||||||
<target name="test-report" if="have.tests" depends="init"/>
|
|
||||||
<target name="-test-browse" if="netbeans.home+have.tests" depends="init"/>
|
|
||||||
<target name="test" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests."/>
|
|
||||||
<target name="-pre-test-run-single" if="have.tests" depends="init">
|
|
||||||
<mkdir dir="${build.test.results.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-do-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single">
|
|
||||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
|
||||||
<j2seproject3:junit includes="${test.includes}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single">
|
|
||||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
|
||||||
</target>
|
|
||||||
<target name="test-single" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test."/>
|
|
||||||
<!--
|
|
||||||
=======================
|
|
||||||
JUNIT DEBUGGING SECTION
|
|
||||||
=======================
|
|
||||||
-->
|
|
||||||
<target name="-debug-start-debuggee-test" if="have.tests" depends="init,compile-test">
|
|
||||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
|
||||||
<j2seproject3:debug classname="junit.textui.TestRunner" classpath="${debug.test.classpath}">
|
|
||||||
<customize>
|
|
||||||
<arg line="${test.class}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject3:debug>
|
|
||||||
</target>
|
|
||||||
<target name="-debug-start-debugger-test" if="netbeans.home+have.tests" depends="init,compile-test">
|
|
||||||
<j2seproject1:nbjpdastart name="${test.class}" classpath="${debug.test.classpath}"/>
|
|
||||||
</target>
|
|
||||||
<target name="debug-test" depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test"/>
|
|
||||||
<target name="-do-debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
|
|
||||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix-test"/>
|
|
||||||
<!--
|
|
||||||
=========================
|
|
||||||
APPLET EXECUTION SECTION
|
|
||||||
=========================
|
|
||||||
-->
|
|
||||||
<target name="run-applet" depends="init,compile-single">
|
|
||||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
|
||||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
|
||||||
<customize>
|
|
||||||
<arg value="${applet.url}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject1:java>
|
|
||||||
</target>
|
|
||||||
<!--
|
|
||||||
=========================
|
|
||||||
APPLET DEBUGGING SECTION
|
|
||||||
=========================
|
|
||||||
-->
|
|
||||||
<target name="-debug-start-debuggee-applet" if="netbeans.home" depends="init,compile-single">
|
|
||||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
|
||||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
|
||||||
<customize>
|
|
||||||
<arg value="${applet.url}"/>
|
|
||||||
</customize>
|
|
||||||
</j2seproject3:debug>
|
|
||||||
</target>
|
|
||||||
<target name="debug-applet" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet"/>
|
|
||||||
<!--
|
|
||||||
===============
|
|
||||||
CLEANUP SECTION
|
|
||||||
===============
|
|
||||||
-->
|
|
||||||
<target name="deps-clean" depends="init" unless="no.deps"/>
|
|
||||||
<target name="-do-clean" depends="init">
|
|
||||||
<delete dir="${build.dir}"/>
|
|
||||||
<delete dir="${dist.dir}"/>
|
|
||||||
</target>
|
|
||||||
<target name="-post-clean">
|
|
||||||
<!-- Empty placeholder for easier customization. -->
|
|
||||||
<!-- You can override this target in the ../build.xml file. -->
|
|
||||||
</target>
|
|
||||||
<target name="clean" depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products."/>
|
|
||||||
</project>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
build.xml.data.CRC32=3ba4020f
|
|
||||||
build.xml.script.CRC32=654a06bb
|
|
||||||
build.xml.stylesheet.CRC32=d5b6853a
|
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
|
||||||
nbproject/build-impl.xml.data.CRC32=3ba4020f
|
|
||||||
nbproject/build-impl.xml.script.CRC32=00e7e9f7
|
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=99b91518
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
application.args=
|
|
||||||
build.classes.dir=${build.dir}/classes
|
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
|
||||||
# This directory is removed when the project is cleaned:
|
|
||||||
build.dir=build
|
|
||||||
build.generated.dir=${build.dir}/generated
|
|
||||||
# Only compile against the classpath explicitly listed here:
|
|
||||||
build.sysclasspath=ignore
|
|
||||||
build.test.classes.dir=${build.dir}/test/classes
|
|
||||||
build.test.results.dir=${build.dir}/test/results
|
|
||||||
debug.classpath=\
|
|
||||||
${run.classpath}
|
|
||||||
debug.test.classpath=\
|
|
||||||
${run.test.classpath}
|
|
||||||
# This directory is removed when the project is cleaned:
|
|
||||||
dist.dir=dist
|
|
||||||
dist.jar=${dist.dir}/jxinput.jar
|
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
|
||||||
file.reference.jxinput-java=../../java
|
|
||||||
jar.compress=false
|
|
||||||
javac.classpath=\
|
|
||||||
${libs.Java3D.classpath}
|
|
||||||
# Space-separated list of extra javac options
|
|
||||||
javac.compilerargs=
|
|
||||||
javac.deprecation=false
|
|
||||||
javac.source=1.5
|
|
||||||
javac.target=1.5
|
|
||||||
javac.test.classpath=\
|
|
||||||
${javac.classpath}:\
|
|
||||||
${build.classes.dir}:\
|
|
||||||
${libs.junit.classpath}
|
|
||||||
javadoc.additionalparam=
|
|
||||||
javadoc.author=false
|
|
||||||
javadoc.encoding=
|
|
||||||
javadoc.noindex=false
|
|
||||||
javadoc.nonavbar=false
|
|
||||||
javadoc.notree=false
|
|
||||||
javadoc.private=false
|
|
||||||
javadoc.splitindex=true
|
|
||||||
javadoc.use=true
|
|
||||||
javadoc.version=false
|
|
||||||
javadoc.windowtitle=
|
|
||||||
main.class=de.hardcode.jxinput.test.JXInputTestDialog
|
|
||||||
manifest.file=manifest.mf
|
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
|
||||||
platform.active=default_platform
|
|
||||||
run.classpath=\
|
|
||||||
${javac.classpath}:\
|
|
||||||
${build.classes.dir}
|
|
||||||
# Space-separated list of JVM arguments used when running the project
|
|
||||||
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
|
|
||||||
# or test-sys-prop.name=value to set system properties for unit tests):
|
|
||||||
run.jvmargs=
|
|
||||||
run.test.classpath=\
|
|
||||||
${javac.test.classpath}:\
|
|
||||||
${build.test.classes.dir}
|
|
||||||
src.dir=${file.reference.jxinput-java}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
|
||||||
<type>org.netbeans.modules.java.j2seproject</type>
|
|
||||||
<configuration>
|
|
||||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
|
||||||
<name>jxinput</name>
|
|
||||||
<minimum-ant-version>1.6.5</minimum-ant-version>
|
|
||||||
<source-roots>
|
|
||||||
<root id="src.dir"/>
|
|
||||||
</source-roots>
|
|
||||||
<test-roots/>
|
|
||||||
</data>
|
|
||||||
</configuration>
|
|
||||||
</project>
|
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#Sat Oct 25 22:12:11 BST 2014
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
|
||||||
164
gradlew
vendored
Normal file
164
gradlew
vendored
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn ( ) {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die ( ) {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||||
|
if $cygwin ; then
|
||||||
|
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >&-
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >&-
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
(0) set -- ;;
|
||||||
|
(1) set -- "$args0" ;;
|
||||||
|
(2) set -- "$args0" "$args1" ;;
|
||||||
|
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||||
|
function splitJvmOpts() {
|
||||||
|
JVM_OPTS=("$@")
|
||||||
|
}
|
||||||
|
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||||
|
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||||
|
|
||||||
|
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||||
90
gradlew.bat
vendored
Normal file
90
gradlew.bat
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windowz variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
goto execute
|
||||||
|
|
||||||
|
:4NT_args
|
||||||
|
@rem Get arguments from the 4NT Shell from JP Software
|
||||||
|
set CMD_LINE_ARGS=%$
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -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,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,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,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,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,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 Button 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 Button
|
|
||||||
//
|
|
||||||
//*********************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,15 +0,0 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
||||||
|
|
||||||
<HTML>
|
|
||||||
<HEAD>
|
|
||||||
<TITLE></TITLE>
|
|
||||||
</HEAD>
|
|
||||||
<BODY>
|
|
||||||
JXInput by HARDCODE Dev., Dipl. Phys. Joerg Plewe.
|
|
||||||
<p>
|
|
||||||
JXInput connects gaming input devices like joysticks or gamepads to the Java
|
|
||||||
environment.
|
|
||||||
</p>
|
|
||||||
Comments send to <A href="mailto:jxinput@hardcode.de">jxinput@hardcode.de</A>.
|
|
||||||
</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( "Button " + 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,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,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 run standalone.
|
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String args[])
|
|
||||||
{
|
|
||||||
new JXInputTestDialog(new javax.swing.JFrame(), true).setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
||||||
private javax.swing.JButton mButtonReset;
|
|
||||||
private javax.swing.JTabbedPane mDevicesTabbedPane;
|
|
||||||
private javax.swing.JLabel mLabelNoDevice;
|
|
||||||
private javax.swing.JPanel mMainPanel;
|
|
||||||
// End of variables declaration//GEN-END:variables
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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,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( "Button 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
BIN
lib/windows_amd64/User32.Lib
Normal file
BIN
lib/windows_amd64/User32.Lib
Normal file
Binary file not shown.
BIN
lib/windows_amd64/dinput8.lib
Normal file
BIN
lib/windows_amd64/dinput8.lib
Normal file
Binary file not shown.
BIN
lib/windows_amd64/dxguid.lib
Normal file
BIN
lib/windows_amd64/dxguid.lib
Normal file
Binary file not shown.
BIN
lib/windows_i386/User32.Lib
Normal file
BIN
lib/windows_i386/User32.Lib
Normal file
Binary file not shown.
BIN
lib/windows_i386/dinput8.lib
Normal file
BIN
lib/windows_i386/dinput8.lib
Normal file
Binary file not shown.
BIN
lib/windows_i386/dxguid.lib
Normal file
BIN
lib/windows_i386/dxguid.lib
Normal file
Binary file not shown.
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "JXInputManager.h"
|
#include "JXInputManager.h"
|
||||||
#include "JXInput.h"
|
#include "JXInput.h"
|
||||||
@@ -14,55 +13,55 @@ mhWnd( hWnd ),
|
|||||||
mDeviceCounter( 0 )
|
mDeviceCounter( 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
for ( int i = 0; i < MAX_JXINPUTS; ++i )
|
for ( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||||
{
|
{
|
||||||
mDevices[ i ] = NULL;
|
mDevices[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( FAILED( InitDirectInput( hWnd ) ) )
|
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||||
{
|
{
|
||||||
FreeDirectInput();
|
FreeDirectInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JXInputManager::~JXInputManager()
|
JXInputManager::~JXInputManager()
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < getNumberOfJXInputs(); ++i )
|
for ( int i = 0; i < getNumberOfJXInputs(); ++i )
|
||||||
{
|
{
|
||||||
delete mDevices[ i ];
|
delete mDevices[ i ];
|
||||||
mDevices[ i ] = NULL;
|
mDevices[ i ] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeDirectInput();
|
FreeDirectInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
int JXInputManager::getNumberOfJXInputs() const
|
int JXInputManager::getNumberOfJXInputs() const
|
||||||
{
|
{
|
||||||
return mDeviceCounter;
|
return mDeviceCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
JXInput& JXInputManager::getJXInput( int idx ) const
|
JXInput& JXInputManager::getJXInput( int idx ) const
|
||||||
{
|
{
|
||||||
assert( idx < mDeviceCounter );
|
assert( idx < mDeviceCounter );
|
||||||
return * mDevices[ idx ];
|
return * mDevices[ idx ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int JXInputManager::getMaxNumberOfAxes() const
|
int JXInputManager::getMaxNumberOfAxes() const
|
||||||
{
|
{
|
||||||
return JXINPUT_MAX_AXES;
|
return JXINPUT_MAX_AXES;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JXInputManager::getMaxNumberOfButtons() const
|
int JXInputManager::getMaxNumberOfButtons() const
|
||||||
{
|
{
|
||||||
return JXINPUT_MAX_BUTTONS;
|
return JXINPUT_MAX_BUTTONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JXInputManager::getMaxNumberOfDirectionals() const
|
int JXInputManager::getMaxNumberOfDirectionals() const
|
||||||
{
|
{
|
||||||
return JXINPUT_MAX_DIRECTIONALS;
|
return JXINPUT_MAX_DIRECTIONALS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ HRESULT JXInputManager::InitDirectInput( HWND hWnd )
|
|||||||
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
// Look for a other devices
|
// Look for a other devices
|
||||||
if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_DEVICE,
|
if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_DEVICE,
|
||||||
EnumJoysticksCallback,
|
EnumJoysticksCallback,
|
||||||
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
||||||
@@ -105,9 +104,9 @@ HRESULT JXInputManager::InitDirectInput( HWND hWnd )
|
|||||||
HRESULT JXInputManager::FreeDirectInput()
|
HRESULT JXInputManager::FreeDirectInput()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( NULL != mpDI )
|
if ( NULL != mpDI )
|
||||||
mpDI->Release();
|
mpDI->Release();
|
||||||
mpDI = NULL;
|
mpDI = NULL;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,43 +120,43 @@ BOOL CALLBACK JXInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdi
|
|||||||
VOID* pContext )
|
VOID* pContext )
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
LPDIRECTINPUTDEVICE8 pJoystick;
|
LPDIRECTINPUTDEVICE8 pJoystick;
|
||||||
|
|
||||||
JXInputManager* pThis = (JXInputManager*)pContext;
|
JXInputManager* pThis = (JXInputManager*)pContext;
|
||||||
|
|
||||||
//
|
//
|
||||||
// if the maximum number of devices is already registered,
|
// if the maximum number of devices is already registered,
|
||||||
// issue a warning and stop enumeration.
|
// issue a warning and stop enumeration.
|
||||||
//
|
//
|
||||||
if( MAX_JXINPUTS == pThis->mDeviceCounter )
|
if( MAX_JXINPUTS == pThis->mDeviceCounter )
|
||||||
{
|
{
|
||||||
OutputDebugString( "Max. number of devices exceeded!" );
|
OutputDebugString( "Max. number of devices exceeded!" );
|
||||||
return DIENUM_STOP;
|
return DIENUM_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Obtain an interface to the enumerated joystick.
|
// Obtain an interface to the enumerated joystick.
|
||||||
hr = pThis->mpDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL );
|
hr = pThis->mpDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL );
|
||||||
|
|
||||||
// If it failed, then we can't use this joystick. (Maybe the user unplugged
|
// If it failed, then we can't use this joystick. (Maybe the user unplugged
|
||||||
// it while we were in the middle of enumerating it.)
|
// it while we were in the middle of enumerating it.)
|
||||||
if( FAILED(hr) )
|
if( FAILED(hr) )
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
|
|
||||||
JXInput* pJ = new JXInput( pJoystick, pThis->mhWnd );
|
JXInput* pJ = new JXInput( pJoystick, pThis->mhWnd );
|
||||||
|
|
||||||
//
|
//
|
||||||
// only register useful devices
|
// only register useful devices
|
||||||
//
|
//
|
||||||
if( pJ->getNumberOfAxes() + pJ->getNumberOfButtons() + pJ->getNumberOfDirectionals() > 0 )
|
if( pJ->getNumberOfAxes() + pJ->getNumberOfButtons() + pJ->getNumberOfDirectionals() > 0 )
|
||||||
{
|
{
|
||||||
pThis->addJXInput( pJ );
|
pThis->addJXInput( pJ );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete pJ;
|
delete pJ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
@@ -168,8 +167,8 @@ BOOL CALLBACK JXInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdi
|
|||||||
*/
|
*/
|
||||||
void JXInputManager::addJXInput( JXInput* pJ )
|
void JXInputManager::addJXInput( JXInput* pJ )
|
||||||
{
|
{
|
||||||
assert( mDeviceCounter < MAX_JXINPUTS );
|
assert( mDeviceCounter < MAX_JXINPUTS );
|
||||||
|
|
||||||
if( mDeviceCounter < MAX_JXINPUTS )
|
if( mDeviceCounter < MAX_JXINPUTS )
|
||||||
mDevices[ mDeviceCounter++ ] = pJ;
|
mDevices[ mDeviceCounter++ ] = pJ;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "de_hardcode_jxinput_directinput_DirectInputDriver.h"
|
||||||
|
#include "jxinput.h"
|
||||||
|
#include "JXInputManager.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Globals
|
||||||
|
//
|
||||||
|
extern HINSTANCE g_hInst;
|
||||||
|
|
||||||
|
static JXInputManager* pJXInputManager = NULL;
|
||||||
|
static JXInput* apJXInput[ MAX_JXINPUTS ];
|
||||||
|
static HWND hWndJava;
|
||||||
|
|
||||||
|
//
|
||||||
|
// IDs of the static Java arrays.
|
||||||
|
//
|
||||||
|
static jfieldID sAxesFieldID;
|
||||||
|
static jfieldID sButtonsFieldID;
|
||||||
|
static jfieldID sDirectionsFieldID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all resources allocated by the Java binding.
|
||||||
|
*/
|
||||||
|
void shutdownJavaResources()
|
||||||
|
{
|
||||||
|
if ( NULL != pJXInputManager )
|
||||||
|
delete pJXInputManager;
|
||||||
|
|
||||||
|
if ( NULL != hWndJava )
|
||||||
|
DestroyWindow( hWndJava );
|
||||||
|
|
||||||
|
pJXInputManager = NULL;
|
||||||
|
|
||||||
|
for( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||||
|
apJXInput[ i ] = NULL;
|
||||||
|
|
||||||
|
hWndJava = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||||
|
{
|
||||||
|
return JNI_VERSION_1_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
|
||||||
|
{
|
||||||
|
shutdownJavaResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeinit
|
||||||
|
(JNIEnv * penv, jclass pClazz )
|
||||||
|
{
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a non-visible window as 'owner' of the DI device.
|
||||||
|
//
|
||||||
|
hWndJava = CreateWindowEx(
|
||||||
|
0/*WS_EX_APPWINDOW*/, // DWORD dwExStyle, // extended window style
|
||||||
|
"STATIC", // LPCTSTR lpClassName, // pointer to registered class name
|
||||||
|
NULL, // LPCTSTR lpWindowName, // pointer to window name
|
||||||
|
0/*WS_CAPTION*/, // DWORD dwStyle, // window style
|
||||||
|
0, // int x, // horizontal position of window
|
||||||
|
0, // int y, // vertical position of window
|
||||||
|
0, // int nWidth, // window width
|
||||||
|
0, // int nHeight, // window height
|
||||||
|
NULL, // HWND hWndParent, // handle to parent or owner window
|
||||||
|
NULL, // HMENU hMenu, // handle to menu, or child-window identifier
|
||||||
|
g_hInst, // HINSTANCE hInstance, // handle to application instance
|
||||||
|
NULL // LPVOID lpParam // pointer to window-creation data
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if ( NULL == pJXInputManager )
|
||||||
|
{
|
||||||
|
pJXInputManager = new JXInputManager( hWndJava );
|
||||||
|
|
||||||
|
for( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||||
|
apJXInput[ i ] = NULL;
|
||||||
|
|
||||||
|
for ( int i = 0; i < pJXInputManager->getNumberOfJXInputs(); ++i )
|
||||||
|
{
|
||||||
|
apJXInput[ i ] = & pJXInputManager->getJXInput( i );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeexit
|
||||||
|
(JNIEnv *, jclass )
|
||||||
|
{
|
||||||
|
shutdownJavaResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind my field IDs to the Java variables.
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_bind
|
||||||
|
(JNIEnv * penv, jclass pClazz)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// All fields are static.
|
||||||
|
//
|
||||||
|
sAxesFieldID = penv->GetStaticFieldID( pClazz, "sAxisValues", "[[D" );
|
||||||
|
sButtonsFieldID = penv->GetStaticFieldID( pClazz, "sButtonStates", "[[Z" );
|
||||||
|
sDirectionsFieldID = penv->GetStaticFieldID( pClazz, "sDirectionalValues", "[[I" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDevices
|
||||||
|
(JNIEnv *penv, jclass)
|
||||||
|
{
|
||||||
|
return pJXInputManager->getNumberOfJXInputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getName
|
||||||
|
(JNIEnv *penv, jclass, jint dev)
|
||||||
|
{
|
||||||
|
return penv->NewStringUTF( apJXInput[ dev ]->getName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfAxes
|
||||||
|
(JNIEnv *, jclass, jint dev)
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->getNumberOfAxes();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfButtons
|
||||||
|
(JNIEnv *, jclass, jint dev)
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->getNumberOfButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDirectionals
|
||||||
|
(JNIEnv *, jclass, jint dev)
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->getNumberOfDirectionals();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfAxes
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return pJXInputManager->getMaxNumberOfAxes();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfButtons
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return pJXInputManager->getMaxNumberOfButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfDirectionals
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return pJXInputManager->getMaxNumberOfDirectionals();
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isAxisAvailable
|
||||||
|
(JNIEnv *, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->isAxisAvailable( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisName
|
||||||
|
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return penv->NewStringUTF( apJXInput[ dev ]->getAxisName( idx ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisType
|
||||||
|
(JNIEnv *, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->getAxisType( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isButtonAvailable
|
||||||
|
(JNIEnv *, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->isButtonAvailable( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonName
|
||||||
|
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return penv->NewStringUTF( apJXInput[ dev ]->getButtonName( idx ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonType
|
||||||
|
(JNIEnv *, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->getButtonType( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isDirectionalAvailable
|
||||||
|
(JNIEnv *, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return apJXInput[ dev ]->isDirectionalAvailable( idx );
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getDirectionalName
|
||||||
|
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||||
|
{
|
||||||
|
return penv->NewStringUTF( apJXInput[ dev ]->getDirectionalName( idx ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main update method.
|
||||||
|
* Here, the actual work is done.
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeupdate
|
||||||
|
(JNIEnv * penv, jclass pClazz )
|
||||||
|
{
|
||||||
|
|
||||||
|
static jdouble axes [ MAX_JXINPUTS ][ JXINPUT_MAX_AXES ];
|
||||||
|
static jboolean buttons [ MAX_JXINPUTS ][ JXINPUT_MAX_BUTTONS ];
|
||||||
|
static jint directions [ MAX_JXINPUTS ][ JXINPUT_MAX_DIRECTIONALS ];
|
||||||
|
|
||||||
|
static jobjectArray axisarrayarray;
|
||||||
|
static jobjectArray buttonarrayarray;
|
||||||
|
static jobjectArray directionarrayarray;
|
||||||
|
|
||||||
|
static jdoubleArray axisarray;
|
||||||
|
static jbooleanArray buttonarray;
|
||||||
|
static jintArray directionarray;
|
||||||
|
|
||||||
|
axisarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sAxesFieldID );
|
||||||
|
buttonarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sButtonsFieldID );
|
||||||
|
directionarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sDirectionsFieldID );
|
||||||
|
|
||||||
|
//
|
||||||
|
// For each device....
|
||||||
|
//
|
||||||
|
for ( int dev = 0; dev < pJXInputManager->getNumberOfJXInputs(); ++dev )
|
||||||
|
{
|
||||||
|
// Do the update of the device.
|
||||||
|
apJXInput[ dev ]->update();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Copy all values into my arrays.
|
||||||
|
//
|
||||||
|
for ( int i = 0; i < JXINPUT_MAX_AXES; ++i )
|
||||||
|
axes[ dev ][ i ] = apJXInput[ dev ]->getAxisValue( i );
|
||||||
|
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||||
|
buttons[ dev ][ i ] = apJXInput[ dev ]->isButtonDown( i );
|
||||||
|
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||||
|
directions[ dev ][ i ] = apJXInput[ dev ]->getDirection( i );
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Move my arrays to the Java arrays.
|
||||||
|
//
|
||||||
|
axisarray = (jdoubleArray)penv->GetObjectArrayElement( axisarrayarray, dev );
|
||||||
|
penv->SetDoubleArrayRegion( axisarray, 0, JXINPUT_MAX_AXES, axes[ dev ] );
|
||||||
|
|
||||||
|
buttonarray = (jbooleanArray)penv->GetObjectArrayElement( buttonarrayarray, dev );
|
||||||
|
penv->SetBooleanArrayRegion( buttonarray, 0, JXINPUT_MAX_BUTTONS, buttons[ dev ] );
|
||||||
|
|
||||||
|
directionarray = (jintArray)penv->GetObjectArrayElement( directionarrayarray, dev );
|
||||||
|
penv->SetIntArrayRegion( directionarray, 0, JXINPUT_MAX_DIRECTIONALS, directions[ dev ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
596
src/main/cpp/jxinput.cpp
Normal file
596
src/main/cpp/jxinput.cpp
Normal file
@@ -0,0 +1,596 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "jxinput.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Globals
|
||||||
|
//
|
||||||
|
extern HINSTANCE g_hInst;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor: Connect with DI
|
||||||
|
*/
|
||||||
|
JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
|
||||||
|
mpJoystick( pJoystick ),
|
||||||
|
mSliderCount( 0 ),
|
||||||
|
mPOVCount( 0 ),
|
||||||
|
mButtonCount( 0 )
|
||||||
|
{
|
||||||
|
initAxisConfig();
|
||||||
|
initButtonsConfig();
|
||||||
|
initDirectionalsConfig();
|
||||||
|
|
||||||
|
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||||
|
{
|
||||||
|
FreeDirectInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor:
|
||||||
|
* Free DirectInput.
|
||||||
|
*/
|
||||||
|
JXInput::~JXInput()
|
||||||
|
{
|
||||||
|
FreeDirectInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void JXInput::update()
|
||||||
|
{
|
||||||
|
UpdateInputState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TCHAR * const JXInput::getName() const
|
||||||
|
{
|
||||||
|
return (TCHAR*)mdiDevInfo.tszInstanceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int JXInput::getNumberOfAxes() const
|
||||||
|
{
|
||||||
|
return mdiDevCaps.dwAxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JXInput::getNumberOfButtons() const
|
||||||
|
{
|
||||||
|
return mButtonCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JXInput::getNumberOfDirectionals() const
|
||||||
|
{
|
||||||
|
return mPOVCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double JXInput::getAxisValueHelper( LONG val, int idx ) const
|
||||||
|
{
|
||||||
|
const AxisConfig& cfg = mAxisConfig[ idx ];
|
||||||
|
|
||||||
|
double span = (double)( cfg.mMaxValue - cfg.mMinValue );
|
||||||
|
double ret = (double)(val - cfg.mMinValue) / span;
|
||||||
|
|
||||||
|
if ( TYPE_SLIDER != cfg.mType )
|
||||||
|
return ret*2.0 - 1.0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double JXInput::getX() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lX, ID_X );
|
||||||
|
}
|
||||||
|
double JXInput::getY() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lY, ID_Y );
|
||||||
|
}
|
||||||
|
double JXInput::getZ() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lZ, ID_Z );
|
||||||
|
}
|
||||||
|
double JXInput::getRotX() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lRx, ID_ROTX );
|
||||||
|
}
|
||||||
|
double JXInput::getRotY() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lRy, ID_ROTY );
|
||||||
|
}
|
||||||
|
double JXInput::getRotZ() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.lRz, ID_ROTZ );
|
||||||
|
}
|
||||||
|
double JXInput::getSlider0() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 );
|
||||||
|
}
|
||||||
|
double JXInput::getSlider1() const
|
||||||
|
{
|
||||||
|
return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool JXInput::isAxisAvailable( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_AXES );
|
||||||
|
return mAxisConfig[ idx ].mIsAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
TCHAR * const JXInput::getAxisName( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_AXES );
|
||||||
|
return (char*const)mAxisConfig[ idx ].mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JXInput::getAxisType( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_AXES );
|
||||||
|
return mAxisConfig[ idx ].mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
double JXInput::getAxisValue( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_AXES );
|
||||||
|
|
||||||
|
// Failsafe if called accidentally
|
||||||
|
if ( ! mAxisConfig[ idx ].mIsAvailable )
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
return (this->*mAxisConfig[ idx ].mGetValueMethod)();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool JXInput::isButtonAvailable( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||||
|
return mButtonConfig[ idx ].mIsAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
TCHAR * const JXInput::getButtonName( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||||
|
return (char*const)mButtonConfig[ idx ].mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JXInput::getButtonType( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||||
|
return mButtonConfig[ idx ].mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JXInput::isButtonDown( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||||
|
return 0 != mJS.rgbButtons[ idx ] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool JXInput::isDirectionalAvailable( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||||
|
return mDirectionalConfig[ idx ].mIsAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
TCHAR * const JXInput::getDirectionalName( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||||
|
return (char*const)mDirectionalConfig[ idx ].mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JXInput::getDirection( int idx ) const
|
||||||
|
{
|
||||||
|
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||||
|
return mJS.rgdwPOV[ idx ] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize axis configuration array.
|
||||||
|
*/
|
||||||
|
void JXInput::initAxisConfig()
|
||||||
|
{
|
||||||
|
mAxisConfig[ ID_X ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION;
|
||||||
|
mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_Y ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION;
|
||||||
|
mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_Z ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION;
|
||||||
|
mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_ROTX ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION;
|
||||||
|
mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_ROTY ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION;
|
||||||
|
mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_ROTZ ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION;
|
||||||
|
mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER;
|
||||||
|
mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0;
|
||||||
|
|
||||||
|
mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false;
|
||||||
|
mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER;
|
||||||
|
mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize buttons configuration array.
|
||||||
|
*/
|
||||||
|
void JXInput::initButtonsConfig()
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||||
|
{
|
||||||
|
mButtonConfig[ i ].mIsAvailable = false;
|
||||||
|
mButtonConfig[ i ].mName[ 0 ] = '\0';
|
||||||
|
mButtonConfig[ i ].mType = TYPE_PUSHBUTTON;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize directionals configuration array.
|
||||||
|
*/
|
||||||
|
void JXInput::initDirectionalsConfig()
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||||
|
{
|
||||||
|
mDirectionalConfig[ i ].mIsAvailable = false;
|
||||||
|
mDirectionalConfig[ i ].mName[ 0 ] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: EnumAxesCallback()
|
||||||
|
// Desc: Callback function for enumerating the axes on a joystick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||||
|
VOID* pContext )
|
||||||
|
{
|
||||||
|
JXInput* pThis = (JXInput*)pContext;
|
||||||
|
|
||||||
|
AxisConfig* pAxCfg = NULL;
|
||||||
|
|
||||||
|
// Set the UI to reflect what objects the joystick supports
|
||||||
|
// Code derived from M$ samples, really sucks, eh?
|
||||||
|
if (pdidoi->guidType == GUID_XAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_X ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_YAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_Y ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_ZAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_Z ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_RxAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_ROTX ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_RyAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_ROTY ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_RzAxis)
|
||||||
|
{
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ];
|
||||||
|
}
|
||||||
|
if (pdidoi->guidType == GUID_Slider)
|
||||||
|
{
|
||||||
|
switch( pThis->mSliderCount++ )
|
||||||
|
{
|
||||||
|
case 0 :
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1 :
|
||||||
|
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fail-safe
|
||||||
|
if( NULL == pAxCfg ) // e.g. GUID_Unknown
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Perform config.
|
||||||
|
//
|
||||||
|
|
||||||
|
DIPROPRANGE diprg;
|
||||||
|
diprg.diph.dwSize = sizeof(DIPROPRANGE);
|
||||||
|
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
|
diprg.diph.dwHow = DIPH_BYID;
|
||||||
|
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
|
||||||
|
|
||||||
|
// Get the range for the axis
|
||||||
|
if( FAILED( pThis->mpJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) )
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
|
||||||
|
pAxCfg->mMinValue = diprg.lMin;
|
||||||
|
pAxCfg->mMaxValue = diprg.lMax;
|
||||||
|
|
||||||
|
strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName );
|
||||||
|
pAxCfg->mIsAvailable = true;
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: EnumButtonsCallback()
|
||||||
|
// Desc: Callback function for enumerating the axes on a joystick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||||
|
VOID* pContext )
|
||||||
|
{
|
||||||
|
JXInput* pThis = (JXInput*)pContext;
|
||||||
|
|
||||||
|
//
|
||||||
|
// if the maximum number of buttons is already registered,
|
||||||
|
// issue a warning and stop enumeration.
|
||||||
|
//
|
||||||
|
if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount )
|
||||||
|
{
|
||||||
|
OutputDebugString( "Max. number of buttons exceeded!" );
|
||||||
|
return DIENUM_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ButtonConfig* pBtCfg = NULL;
|
||||||
|
|
||||||
|
if ( pdidoi->guidType == GUID_Button )
|
||||||
|
{
|
||||||
|
assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount );
|
||||||
|
pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// fail-safe
|
||||||
|
if( NULL == pBtCfg ) // e.g. unknown stuff
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
assert( NULL != pBtCfg );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Perform config.
|
||||||
|
//
|
||||||
|
|
||||||
|
strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName );
|
||||||
|
pBtCfg->mIsAvailable = true;
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: EnumPOVsCallback()
|
||||||
|
// Desc: Callback function for enumerating the axes on a joystick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||||
|
VOID* pContext )
|
||||||
|
{
|
||||||
|
JXInput* pThis = (JXInput*)pContext;
|
||||||
|
|
||||||
|
//
|
||||||
|
// if the maximum number of buttons is already registered,
|
||||||
|
// issue a warning and stop enumeration.
|
||||||
|
//
|
||||||
|
if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount )
|
||||||
|
{
|
||||||
|
OutputDebugString( "Max. number of POVs exceeded!" );
|
||||||
|
return DIENUM_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
DirectionalConfig* pDirCfg = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
if (pdidoi->guidType == GUID_POV)
|
||||||
|
{
|
||||||
|
assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount );
|
||||||
|
pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// fail-safe
|
||||||
|
if( NULL == pDirCfg ) // e.g. unknown stuff
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
assert( NULL != pDirCfg );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Perform config.
|
||||||
|
//
|
||||||
|
|
||||||
|
strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName );
|
||||||
|
pDirCfg->mIsAvailable = true;
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: EnumEffectsCallback()
|
||||||
|
// Desc: Callback function for enumerating the effects of a joystick
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
BOOL CALLBACK JXInput::EnumEffectsCallback( const DIEFFECTINFO* pdidoi,
|
||||||
|
VOID* pContext )
|
||||||
|
{
|
||||||
|
//JXInput* pThis = (JXInput*)pContext;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Work on that!!
|
||||||
|
//
|
||||||
|
|
||||||
|
return DIENUM_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: InitDirectInput()
|
||||||
|
// Desc: Initialize the DirectInput variables.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
HRESULT JXInput::InitDirectInput( HWND hWnd )
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
// Make sure we got a joystick
|
||||||
|
if( NULL == mpJoystick )
|
||||||
|
{
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Ask the device for some useful information.
|
||||||
|
//
|
||||||
|
mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE );
|
||||||
|
hr = mpJoystick->GetDeviceInfo( &mdiDevInfo );
|
||||||
|
if( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
// Set the data format to "simple joystick" - a predefined data format
|
||||||
|
//
|
||||||
|
// A data format specifies which controls on a device we are interested in,
|
||||||
|
// and how they should be reported. This tells DInput that we will be
|
||||||
|
// passing a DIJOYSTATE structure to IDirectInputDevice::GetDeviceState().
|
||||||
|
hr = mpJoystick->SetDataFormat( &c_dfDIJoystick2 );
|
||||||
|
if( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
// Set the cooperative level to let DInput know how this device should
|
||||||
|
// interact with the system and with other DInput applications.
|
||||||
|
// hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
|
||||||
|
DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND );
|
||||||
|
hr = mpJoystick->SetCooperativeLevel( hWnd, mode );
|
||||||
|
if( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
// Determine how many axis the joystick has (so we don't error out setting
|
||||||
|
// properties for unavailable axis)
|
||||||
|
mdiDevCaps.dwSize = sizeof(DIDEVCAPS);
|
||||||
|
hr = mpJoystick->GetCapabilities(&mdiDevCaps);
|
||||||
|
if ( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
|
||||||
|
// Enumerate the axes of the joyctick and set the range of each axis. Note:
|
||||||
|
// we could just use the defaults, but we're just trying to show an example
|
||||||
|
// of enumerating device objects (axes, buttons, etc.).
|
||||||
|
mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS );
|
||||||
|
mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON );
|
||||||
|
mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV );
|
||||||
|
|
||||||
|
mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL );
|
||||||
|
|
||||||
|
// For FF sticks, switch on autocenter as long as we do not use real FF
|
||||||
|
SwitchAutoCenter( true );
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: UpdateInputState()
|
||||||
|
// Desc: Get the input device's state and display it.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
HRESULT JXInput::UpdateInputState()
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
if( mpJoystick )
|
||||||
|
{
|
||||||
|
|
||||||
|
// Poll the device to read the current state
|
||||||
|
hr = mpJoystick->Poll();
|
||||||
|
if( FAILED(hr) )
|
||||||
|
{
|
||||||
|
// DInput is telling us that the input stream has been
|
||||||
|
// interrupted. We aren't tracking any state between polls, so
|
||||||
|
// we don't have any special reset that needs to be done. We
|
||||||
|
// just re-acquire and try again.
|
||||||
|
hr = mpJoystick->Acquire();
|
||||||
|
while( hr == DIERR_INPUTLOST )
|
||||||
|
hr = mpJoystick->Acquire();
|
||||||
|
|
||||||
|
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||||
|
// may occur when the app is minimized or in the process of
|
||||||
|
// switching, so just try again later
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the input's device state
|
||||||
|
if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) )
|
||||||
|
return hr; // The device should have been acquired during the Poll()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Name: FreeDirectInput()
|
||||||
|
// Desc: Initialize the DirectInput variables.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
HRESULT JXInput::FreeDirectInput()
|
||||||
|
{
|
||||||
|
// Unacquire and release any DirectInputDevice objects.
|
||||||
|
if( NULL != mpJoystick )
|
||||||
|
{
|
||||||
|
// Unacquire the device one last time just in case
|
||||||
|
// the app tried to exit while the device is still acquired.
|
||||||
|
mpJoystick->Unacquire();
|
||||||
|
|
||||||
|
mpJoystick->Release();
|
||||||
|
mpJoystick = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HRESULT JXInput::SwitchAutoCenter( bool onoff )
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
DIPROPDWORD DIPropAutoCenter;
|
||||||
|
|
||||||
|
DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter);
|
||||||
|
DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
|
DIPropAutoCenter.diph.dwObj = 0;
|
||||||
|
DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;
|
||||||
|
DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF );
|
||||||
|
|
||||||
|
hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph );
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
24
src/main/cpp/main.cpp
Normal file
24
src/main/cpp/main.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
HINSTANCE g_hInst;
|
||||||
|
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain( HANDLE hModule,
|
||||||
|
DWORD ul_reason_for_call,
|
||||||
|
LPVOID lpReserved
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (ul_reason_for_call)
|
||||||
|
{
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
g_hInst = (HINSTANCE)hModule;
|
||||||
|
break;
|
||||||
|
case DLL_THREAD_ATTACH:
|
||||||
|
case DLL_THREAD_DETACH:
|
||||||
|
break;
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
g_hInst = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
33
src/main/headers/JXInputManager.h
Normal file
33
src/main/headers/JXInputManager.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#define MAX_JXINPUTS 10
|
||||||
|
|
||||||
|
class JXInput;
|
||||||
|
|
||||||
|
class JXINPUT_API JXInputManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JXInputManager( HWND hWnd );
|
||||||
|
virtual ~JXInputManager();
|
||||||
|
|
||||||
|
int getNumberOfJXInputs() const;
|
||||||
|
JXInput& getJXInput( int idx ) const;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Numbering methods
|
||||||
|
//
|
||||||
|
int getMaxNumberOfAxes() const;
|
||||||
|
int getMaxNumberOfButtons() const;
|
||||||
|
int getMaxNumberOfDirectionals() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
LPDIRECTINPUT8 mpDI;
|
||||||
|
HWND mhWnd;
|
||||||
|
JXInput* mDevices[ MAX_JXINPUTS ];
|
||||||
|
int mDeviceCounter;
|
||||||
|
|
||||||
|
HRESULT InitDirectInput( HWND hWnd = NULL );
|
||||||
|
HRESULT FreeDirectInput();
|
||||||
|
|
||||||
|
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
||||||
|
VOID* pContext );
|
||||||
|
void addJXInput( JXInput* pJ );
|
||||||
|
};
|
||||||
4417
src/main/headers/dinput.h
Normal file
4417
src/main/headers/dinput.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#define JXINPUT_MAX_AXES 8
|
#define JXINPUT_MAX_AXES 8
|
||||||
#define JXINPUT_MAX_BUTTONS 256
|
#define JXINPUT_MAX_BUTTONS 256
|
||||||
#define JXINPUT_MAX_DIRECTIONALS 4
|
#define JXINPUT_MAX_DIRECTIONALS 4
|
||||||
@@ -12,20 +11,20 @@ class JXINPUT_API JXInput
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef enum AXISTYPE
|
enum AXISTYPE
|
||||||
{
|
{
|
||||||
TYPE_TRANSLATION,
|
TYPE_TRANSLATION,
|
||||||
TYPE_ROTATION,
|
TYPE_ROTATION,
|
||||||
TYPE_SLIDER
|
TYPE_SLIDER
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum BUTTONTYPE
|
enum BUTTONTYPE
|
||||||
{
|
{
|
||||||
TYPE_PUSHBUTTON,
|
TYPE_PUSHBUTTON,
|
||||||
TYPE_TOGGLEBUTTON
|
TYPE_TOGGLEBUTTON
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum AXISID
|
enum AXISID
|
||||||
{
|
{
|
||||||
ID_X, ID_Y, ID_Z,
|
ID_X, ID_Y, ID_Z,
|
||||||
ID_ROTX, ID_ROTY, ID_ROTZ,
|
ID_ROTX, ID_ROTY, ID_ROTZ,
|
||||||
11
src/main/headers/stdafx.h
Normal file
11
src/main/headers/stdafx.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <dinput.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifdef JXINPUT_EXPORTS
|
||||||
|
#define JXINPUT_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JXINPUT_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
72
src/main/java/de/hardcode/jxinput/Axis.java
Normal file
72
src/main/java/de/hardcode/jxinput/Axis.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
35
src/main/java/de/hardcode/jxinput/Button.java
Normal file
35
src/main/java/de/hardcode/jxinput/Button.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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();
|
||||||
|
}
|
||||||
|
|
||||||
45
src/main/java/de/hardcode/jxinput/Directional.java
Normal file
45
src/main/java/de/hardcode/jxinput/Directional.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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,10 +1,10 @@
|
|||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||||
// All rights reserved. Copying, modification,
|
// All rights reserved. Copying, modification,
|
||||||
// distribution or publication without the prior written
|
// distribution or publication without the prior written
|
||||||
// consent of the author is prohibited.
|
// consent of the author is prohibited.
|
||||||
//
|
//
|
||||||
// Created on 27. Dezember 2001, 00:19
|
// Created on 27. Dezember 2001, 00:19
|
||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
package de.hardcode.jxinput;
|
package de.hardcode.jxinput;
|
||||||
|
|
||||||
@@ -24,15 +24,15 @@ package de.hardcode.jxinput;
|
|||||||
*/
|
*/
|
||||||
public abstract interface Feature
|
public abstract interface Feature
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Features may have a name provided e.g. by the driver.
|
* Features may have a name provided e.g. by the driver.
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Denote wether this feature has changed beyond it's resolution since it got last
|
* Denote wether this feature has changed beyond it's resolution since it got last
|
||||||
* updated.
|
* updated.
|
||||||
*/
|
*/
|
||||||
boolean hasChanged();
|
boolean hasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
71
src/main/java/de/hardcode/jxinput/JXInputDevice.java
Normal file
71
src/main/java/de/hardcode/jxinput/JXInputDevice.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
|
||||||
233
src/main/java/de/hardcode/jxinput/JXInputManager.java
Normal file
233
src/main/java/de/hardcode/jxinput/JXInputManager.java
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
70
src/main/java/de/hardcode/jxinput/directinput/DIAxis.java
Normal file
70
src/main/java/de/hardcode/jxinput/directinput/DIAxis.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
55
src/main/java/de/hardcode/jxinput/directinput/DIButton.java
Normal file
55
src/main/java/de/hardcode/jxinput/directinput/DIButton.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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;
|
||||||
|
|
||||||
|
import com.github.boukefalos.jlibloader.Native;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
Native.load("com.github.boukefalos", "jlibxinput");
|
||||||
|
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,8 +1,8 @@
|
|||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||||
// All rights reserved. Copying, modification,
|
// All rights reserved. Copying, modification,
|
||||||
// distribution or publication without the prior written
|
// distribution or publication without the prior written
|
||||||
// consent of the author is prohibited.
|
// consent of the author is prohibited.
|
||||||
//
|
//
|
||||||
// Created on 29. Oktober 2002, 22:57
|
// Created on 29. Oktober 2002, 22:57
|
||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||||
// All rights reserved. Copying, modification,
|
// All rights reserved. Copying, modification,
|
||||||
// distribution or publication without the prior written
|
// distribution or publication without the prior written
|
||||||
// consent of the author is prohibited.
|
// consent of the author is prohibited.
|
||||||
//
|
//
|
||||||
// Created on 31. Januar 2002, 23:33
|
// Created on 31. Januar 2002, 23:33
|
||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
package de.hardcode.jxinput.event;
|
package de.hardcode.jxinput.event;
|
||||||
|
|
||||||
@@ -18,15 +18,15 @@ import de.hardcode.jxinput.Axis;
|
|||||||
public class JXInputAxisEvent
|
public class JXInputAxisEvent
|
||||||
{
|
{
|
||||||
private final Axis mAxis;
|
private final Axis mAxis;
|
||||||
double mDelta;
|
double mDelta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of JXInputEvent.
|
* Creates a new instance of JXInputEvent.
|
||||||
*/
|
*/
|
||||||
JXInputAxisEvent( Axis axis )
|
JXInputAxisEvent( Axis axis )
|
||||||
{
|
{
|
||||||
mAxis = axis;
|
mAxis = axis;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The feature that caused the event.
|
* The feature that caused the event.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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,10 +1,10 @@
|
|||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||||
// All rights reserved. Copying, modification,
|
// All rights reserved. Copying, modification,
|
||||||
// distribution or publication without the prior written
|
// distribution or publication without the prior written
|
||||||
// consent of the author is prohibited.
|
// consent of the author is prohibited.
|
||||||
//
|
//
|
||||||
// Created on 31. Januar 2002, 23:33
|
// Created on 31. Januar 2002, 23:33
|
||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
package de.hardcode.jxinput.event;
|
package de.hardcode.jxinput.event;
|
||||||
|
|
||||||
@@ -18,14 +18,14 @@ import de.hardcode.jxinput.Button;
|
|||||||
public class JXInputButtonEvent
|
public class JXInputButtonEvent
|
||||||
{
|
{
|
||||||
final Button mButton;
|
final Button mButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of JXInputEvent.
|
* Creates a new instance of JXInputEvent.
|
||||||
*/
|
*/
|
||||||
JXInputButtonEvent( Button button )
|
JXInputButtonEvent( Button button )
|
||||||
{
|
{
|
||||||
mButton = button;
|
mButton = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The feature that caused the event.
|
* The feature that caused the event.
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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,10 +1,10 @@
|
|||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
|
||||||
// All rights reserved. Copying, modification,
|
// All rights reserved. Copying, modification,
|
||||||
// distribution or publication without the prior written
|
// distribution or publication without the prior written
|
||||||
// consent of the author is prohibited.
|
// consent of the author is prohibited.
|
||||||
//
|
//
|
||||||
// Created on 31. Januar 2002, 23:33
|
// Created on 31. Januar 2002, 23:33
|
||||||
//**********************************************************************************************
|
//**********************************************************************************************
|
||||||
package de.hardcode.jxinput.event;
|
package de.hardcode.jxinput.event;
|
||||||
|
|
||||||
@@ -18,16 +18,16 @@ import de.hardcode.jxinput.Directional;
|
|||||||
public class JXInputDirectionalEvent
|
public class JXInputDirectionalEvent
|
||||||
{
|
{
|
||||||
private final Directional mDirectional;
|
private final Directional mDirectional;
|
||||||
double mValueDelta;
|
double mValueDelta;
|
||||||
int mDirectionDelta;
|
int mDirectionDelta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of JXInputEvent.
|
* Creates a new instance of JXInputEvent.
|
||||||
*/
|
*/
|
||||||
JXInputDirectionalEvent( Directional directional )
|
JXInputDirectionalEvent( Directional directional )
|
||||||
{
|
{
|
||||||
mDirectional = directional;
|
mDirectional = directional;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The feature that caused the event.
|
* The feature that caused the event.
|
||||||
@@ -45,7 +45,7 @@ public class JXInputDirectionalEvent
|
|||||||
return mValueDelta;
|
return mValueDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the change in direction that caused the event.
|
* Return the change in direction that caused the event.
|
||||||
*/
|
*/
|
||||||
public int getDirectionDelta()
|
public int getDirectionDelta()
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
|
||||||
284
src/main/java/de/hardcode/jxinput/event/JXInputEventManager.java
Normal file
284
src/main/java/de/hardcode/jxinput/event/JXInputEventManager.java
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
src/main/java/de/hardcode/jxinput/j3d/IsActiveCondition.java
Normal file
25
src/main/java/de/hardcode/jxinput/j3d/IsActiveCondition.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
171
src/main/java/de/hardcode/jxinput/j3d/J3DInputDevice.java
Normal file
171
src/main/java/de/hardcode/jxinput/j3d/J3DInputDevice.java
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
94
src/main/java/de/hardcode/jxinput/keyboard/KeyButton.java
Normal file
94
src/main/java/de/hardcode/jxinput/keyboard/KeyButton.java
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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 Button 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 Button
|
||||||
|
//
|
||||||
|
//*********************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
141
src/main/java/de/hardcode/jxinput/keyboard/KeyboardDriver.java
Normal file
141
src/main/java/de/hardcode/jxinput/keyboard/KeyboardDriver.java
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/java/de/hardcode/jxinput/test/AxisListener.java
Normal file
39
src/main/java/de/hardcode/jxinput/test/AxisListener.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//**********************************************************************************************
|
||||||
|
// (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() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user