Move source files to gradle project layout
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Acceleration in a MotionSensingEvent from an expansion.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class AccelerationExpansionEventPanel extends AccelerationPanel {
|
||||
|
||||
@Override
|
||||
public RawAcceleration getRawAccelerationValue(GenericEvent e) {
|
||||
if (e instanceof NunchukEvent) {
|
||||
return ((NunchukEvent) e).getNunchukMotionSensingEvent()
|
||||
.getRawAcceleration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
303
src/main/java/wiiusej/utils/AccelerationPanel.java
Normal file
303
src/main/java/wiiusej/utils/AccelerationPanel.java
Normal file
@@ -0,0 +1,303 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch raw acceleration values from a
|
||||
* MotionSensingEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class AccelerationPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color xColor = Color.RED;
|
||||
private Color yColor = Color.GREEN;
|
||||
private Color zColor = Color.BLUE;
|
||||
private Color backgroundColor = Color.WHITE;
|
||||
private Color lineColor = Color.BLACK;
|
||||
private ArrayList<RawAcceleration> values = new ArrayList<RawAcceleration>();
|
||||
|
||||
/** Creates new form AccelerationPanel */
|
||||
public AccelerationPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the AccelerationPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param xColor
|
||||
* x color.
|
||||
* @param yColor
|
||||
* y color.
|
||||
* @param zColor
|
||||
* z color.
|
||||
* @param lColor
|
||||
* line color.
|
||||
*/
|
||||
public AccelerationPanel(Color bgColor, Color xColor, Color yColor,
|
||||
Color zColor, Color lColor) {
|
||||
backgroundColor = bgColor;
|
||||
this.xColor = xColor;
|
||||
this.yColor = yColor;
|
||||
this.zColor = zColor;
|
||||
lineColor = lColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw medium line
|
||||
int yLine = getHeight() - 25;
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yLine, getWidth(), yLine);
|
||||
|
||||
RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]);
|
||||
|
||||
double unit = yLine / 255.0;
|
||||
int previousX = 0;
|
||||
int previousY = 0;
|
||||
int previousZ = 0;
|
||||
// draw curves
|
||||
for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
|
||||
RawAcceleration acceleration = valuesArray[i];
|
||||
// draw X
|
||||
g2.setPaint(xColor);
|
||||
int yDelta = (int) Math.round(unit * acceleration.getX());
|
||||
int y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousX, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousX = y;
|
||||
// draw Y
|
||||
g2.setPaint(yColor);
|
||||
yDelta = (int) Math.round(unit * acceleration.getY());
|
||||
y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousY, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousY = y;
|
||||
// draw Z
|
||||
g2.setPaint(zColor);
|
||||
yDelta = (int) Math.round(unit * acceleration.getZ());
|
||||
y = -1 * yDelta + yLine;
|
||||
g2.drawLine(i - 1, previousZ, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousZ = y;
|
||||
}
|
||||
|
||||
// draw legend
|
||||
g2.setPaint(xColor);
|
||||
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
|
||||
g2.setPaint(yColor);
|
||||
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
|
||||
g2.setPaint(zColor);
|
||||
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawString("X", 30, getHeight() - 5);
|
||||
g2.drawString("Y", 85, getHeight() - 5);
|
||||
g2.drawString("Z", 145, getHeight() - 5);
|
||||
g2.drawString("0", 2, yLine - 5);
|
||||
g2.drawString("255", 2, 15);
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// Clear points.
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
private void draw(GenericEvent arg0) {
|
||||
if (values.size() >= getWidth()) {
|
||||
// if there are as many values as pixels in the width
|
||||
// clear points
|
||||
values.clear();
|
||||
}
|
||||
RawAcceleration rawAcceleration = getRawAccelerationValue(arg0);
|
||||
if (rawAcceleration != null)
|
||||
values.add(rawAcceleration);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public abstract RawAcceleration getRawAccelerationValue(GenericEvent e);
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
public Color getXColor() {
|
||||
return xColor;
|
||||
}
|
||||
|
||||
public Color getYColor() {
|
||||
return yColor;
|
||||
}
|
||||
|
||||
public Color getZColor() {
|
||||
return zColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setLineColor(Color lineColor) {
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
public void setXColor(Color xColor) {
|
||||
this.xColor = xColor;
|
||||
}
|
||||
|
||||
public void setYColor(Color yColor) {
|
||||
this.yColor = yColor;
|
||||
}
|
||||
|
||||
public void setZColor(Color zColor) {
|
||||
this.zColor = zColor;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Acceleration in a MotionSensingEvent from a wiimote.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class AccelerationWiimoteEventPanel extends AccelerationPanel {
|
||||
|
||||
@Override
|
||||
public RawAcceleration getRawAccelerationValue(GenericEvent e) {
|
||||
if (e instanceof MotionSensingEvent) {
|
||||
return ((MotionSensingEvent) e).getRawAcceleration();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
382
src/main/java/wiiusej/utils/ButtonsEventPanel.java
Normal file
382
src/main/java/wiiusej/utils/ButtonsEventPanel.java
Normal file
@@ -0,0 +1,382 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to see what buttons are pressed on the wiimote. It
|
||||
* displays the result of last ButtonsEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ButtonsEventPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Image wiimoteImage;// image for double buffering
|
||||
private WiimoteButtonsEvent buttons;
|
||||
private Color pressedColor = Color.RED;
|
||||
private Color heldColor = Color.ORANGE;
|
||||
private Color releasedColor = Color.YELLOW;
|
||||
private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13);
|
||||
|
||||
/**
|
||||
* Default constructor. Red : button just pressed. Orange : button held.
|
||||
* Yellow : button just released.
|
||||
*/
|
||||
public ButtonsEventPanel() {
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
java.net.URL url = ButtonsEventPanel.class
|
||||
.getResource("/img/wiimote.png");
|
||||
wiimoteImage = toolkit.createImage(url);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to set colors and shape used.
|
||||
*
|
||||
* @param pressColor
|
||||
* color of a button just pressed.
|
||||
* @param hColor
|
||||
* color of a button held.
|
||||
* @param relColor
|
||||
* color of a button just released.
|
||||
* @param sh
|
||||
* shape draw on the buttons.
|
||||
*/
|
||||
public ButtonsEventPanel(Color pressColor, Color hColor, Color relColor,
|
||||
Shape sh) {
|
||||
pressedColor = pressColor;
|
||||
heldColor = hColor;
|
||||
releasedColor = relColor;
|
||||
shape = sh;
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
wiimoteImage = toolkit.createImage("img\\wiimote.png");
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
// offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw buttons pushed
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (buttons != null) {
|
||||
/* button ONE */
|
||||
if (buttons.isButtonOneJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 353);
|
||||
}
|
||||
if (buttons.isButtonOneHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 353);
|
||||
}
|
||||
if (buttons.isButtonOneJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 353);
|
||||
}
|
||||
|
||||
/* button TWO */
|
||||
if (buttons.isButtonTwoJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 395);
|
||||
}
|
||||
if (buttons.isButtonTwoHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 395);
|
||||
}
|
||||
if (buttons.isButtonTwoJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 395);
|
||||
}
|
||||
|
||||
/* button A */
|
||||
if (buttons.isButtonAJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 150);
|
||||
}
|
||||
if (buttons.isButtonAHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 150);
|
||||
}
|
||||
if (buttons.isButtonAJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 150);
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (buttons.isButtonBJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 16, 149);
|
||||
}
|
||||
if (buttons.isButtonBHeld()) {
|
||||
drawFunction(g2, heldColor, 16, 149);
|
||||
}
|
||||
if (buttons.isButtonBJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 16, 149);
|
||||
}
|
||||
|
||||
/* button LEFT */
|
||||
if (buttons.isButtonLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 33, 77);
|
||||
}
|
||||
if (buttons.isButtonLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 33, 77);
|
||||
}
|
||||
if (buttons.isButtonLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 33, 77);
|
||||
}
|
||||
|
||||
/* button RIGHT */
|
||||
if (buttons.isButtonRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 73, 77);
|
||||
}
|
||||
if (buttons.isButtonRightHeld()) {
|
||||
drawFunction(g2, heldColor, 73, 77);
|
||||
}
|
||||
if (buttons.isButtonRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 73, 77);
|
||||
}
|
||||
|
||||
/* button UP */
|
||||
if (buttons.isButtonUpJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 54, 60);
|
||||
}
|
||||
if (buttons.isButtonUpHeld()) {
|
||||
drawFunction(g2, heldColor, 54, 60);
|
||||
}
|
||||
if (buttons.isButtonUpJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 54, 60);
|
||||
}
|
||||
|
||||
/* button DOWN */
|
||||
if (buttons.isButtonDownJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 54, 97);
|
||||
}
|
||||
if (buttons.isButtonDownHeld()) {
|
||||
drawFunction(g2, heldColor, 54, 97);
|
||||
}
|
||||
if (buttons.isButtonDownJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 54, 97);
|
||||
}
|
||||
|
||||
/* button MINUS */
|
||||
if (buttons.isButtonMinusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 20, 230);
|
||||
}
|
||||
if (buttons.isButtonMinusHeld()) {
|
||||
drawFunction(g2, heldColor, 20, 230);
|
||||
}
|
||||
if (buttons.isButtonMinusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 20, 230);
|
||||
}
|
||||
|
||||
/* button PLUS */
|
||||
if (buttons.isButtonPlusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 86, 230);
|
||||
}
|
||||
if (buttons.isButtonPlusHeld()) {
|
||||
drawFunction(g2, heldColor, 86, 230);
|
||||
}
|
||||
if (buttons.isButtonPlusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 86, 230);
|
||||
}
|
||||
|
||||
/* button HOME */
|
||||
if (buttons.isButtonHomeJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 53, 230);
|
||||
}
|
||||
if (buttons.isButtonHomeHeld()) {
|
||||
drawFunction(g2, heldColor, 53, 230);
|
||||
}
|
||||
if (buttons.isButtonHomeJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 53, 230);
|
||||
}
|
||||
|
||||
buttons = null;
|
||||
}
|
||||
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to factorize code.
|
||||
*
|
||||
* @param g2
|
||||
* where to draw a shape.
|
||||
* @param col
|
||||
* color to use.
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates.
|
||||
*/
|
||||
private void drawFunction(Graphics2D g2, Color col, int x, int y) {
|
||||
g2.setPaint(col);
|
||||
g2.translate(x, y);
|
||||
g2.draw(shape);
|
||||
g2.fill(shape);
|
||||
g2.setTransform(new AffineTransform());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
|
||||
buttons = arg0;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
clearView();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public Color getHeldColor() {
|
||||
return heldColor;
|
||||
}
|
||||
|
||||
public Color getPressedColor() {
|
||||
return pressedColor;
|
||||
}
|
||||
|
||||
public Color getReleasedColor() {
|
||||
return releasedColor;
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setHeldColor(Color heldColor) {
|
||||
this.heldColor = heldColor;
|
||||
}
|
||||
|
||||
public void setPressedColor(Color pressedColor) {
|
||||
this.pressedColor = pressedColor;
|
||||
}
|
||||
|
||||
public void setReleasedColor(Color releasedColor) {
|
||||
this.releasedColor = releasedColor;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
buttons = null;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -0,0 +1,500 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerButtonsEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to display what happens on the classic controller.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ClassicControllerButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Image wiimoteImage;// image for double buffering
|
||||
private ClassicControllerEvent event;
|
||||
private Color pressedColor = Color.RED;
|
||||
private Color heldColor = Color.ORANGE;
|
||||
private Color releasedColor = Color.YELLOW;
|
||||
private Color joystickColor = Color.PINK;
|
||||
private Color shoulderColor = Color.BLUE;
|
||||
private Shape shapeJoystick = new java.awt.geom.Ellipse2D.Double(0, 0, 15, 15);
|
||||
private Shape shapeButton = new java.awt.geom.Ellipse2D.Double(0, 0, 20, 20);
|
||||
private static int xAmplitude = 20;
|
||||
private static int yAmplitude = 20;
|
||||
|
||||
/**
|
||||
* Default constructor. Red : button just pressed. Orange : button held.
|
||||
* Yellow : button just released.
|
||||
*/
|
||||
public ClassicControllerButtonsEventPanel() {
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
java.net.URL url = ButtonsEventPanel.class.getResource("/img/classiccontroller.png");
|
||||
wiimoteImage = toolkit.createImage(url);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to set colors and shape used.
|
||||
*
|
||||
* @param pressColor
|
||||
* color of a button just pressed.
|
||||
* @param hColor
|
||||
* color of a button held.
|
||||
* @param relColor
|
||||
* color of a button just released.
|
||||
* @param jsColor
|
||||
* color of the joysticks.
|
||||
* @param shouldColor
|
||||
* color of the shoulders.
|
||||
* @param js
|
||||
* shape drawn on the joysticks.
|
||||
* @param sh
|
||||
* shape drawn on the buttons.
|
||||
*/
|
||||
public ClassicControllerButtonsEventPanel(Color pressColor, Color hColor, Color relColor,
|
||||
Color jsColor, Color shouldColor, Shape js, Shape sh) {
|
||||
pressedColor = pressColor;
|
||||
heldColor = hColor;
|
||||
releasedColor = relColor;
|
||||
shapeButton = sh;
|
||||
shapeJoystick = js;
|
||||
joystickColor = jsColor;
|
||||
shoulderColor = shouldColor;
|
||||
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
|
||||
wiimoteImage = toolkit.createImage("img\\wiimote.png");
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
// offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
//draw classic controller
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
if (event != null) {
|
||||
// draw buttons pushed
|
||||
ClassicControllerButtonsEvent buttons = event.getButtonsEvent();
|
||||
|
||||
/* button A */
|
||||
if (buttons.isButtonAJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 304, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonAHeld()) {
|
||||
drawFunction(g2, heldColor, 304, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonAJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 304, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (buttons.isButtonBJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 269, 98, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonBHeld()) {
|
||||
drawFunction(g2, heldColor, 269, 98, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonBJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 269, 98, shapeButton);
|
||||
}
|
||||
|
||||
/* button Down */
|
||||
if (buttons.isButtonDownJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 60, 97, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonDownHeld()) {
|
||||
drawFunction(g2, heldColor, 60, 97, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonDownJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 60, 97, shapeButton);
|
||||
}
|
||||
|
||||
/* button FullLeft */
|
||||
if (buttons.isButtonFullLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 55, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 55, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 55, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button FullRight */
|
||||
if (buttons.isButtonFullRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 276, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullRightHeld()) {
|
||||
drawFunction(g2, heldColor, 276, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonFullRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 276, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button Home */
|
||||
if (buttons.isButtonHomeJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 166, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonHomeHeld()) {
|
||||
drawFunction(g2, heldColor, 166, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonHomeJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 166, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Left */
|
||||
if (buttons.isButtonLeftJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 34, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonLeftHeld()) {
|
||||
drawFunction(g2, heldColor, 34, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonLeftJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 34, 75, shapeButton);
|
||||
}
|
||||
|
||||
/* button Minus */
|
||||
if (buttons.isButtonMinusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 140, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonMinusHeld()) {
|
||||
drawFunction(g2, heldColor, 140, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonMinusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 140, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Plus */
|
||||
if (buttons.isButtonPlusJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 191, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonPlusHeld()) {
|
||||
drawFunction(g2, heldColor, 191, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonPlusJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 191, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button Right */
|
||||
if (buttons.isButtonRightJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 86, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonRightHeld()) {
|
||||
drawFunction(g2, heldColor, 86, 75, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonRightJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 86, 353, shapeButton);
|
||||
}
|
||||
|
||||
/* button Up */
|
||||
if (buttons.isButtonUpJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 60, 50, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonUpHeld()) {
|
||||
drawFunction(g2, heldColor, 60, 50, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonUpJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 60, 50, shapeButton);
|
||||
}
|
||||
|
||||
/* button X */
|
||||
if (buttons.isButtonXJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 271, 53, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonXHeld()) {
|
||||
drawFunction(g2, heldColor, 271, 53, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonXJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 271, 53, shapeButton);
|
||||
}
|
||||
|
||||
/* button Y */
|
||||
if (buttons.isButtonYJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 237, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonYHeld()) {
|
||||
drawFunction(g2, heldColor, 237, 76, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonYJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 237, 76, shapeButton);
|
||||
}
|
||||
|
||||
/* button ZL */
|
||||
if (buttons.isButtonZLJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 123, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZLHeld()) {
|
||||
drawFunction(g2, heldColor, 123, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZLJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 123, 4, shapeButton);
|
||||
}
|
||||
|
||||
/* button ZR */
|
||||
if (buttons.isButtonZRJustPressed()) {
|
||||
drawFunction(g2, pressedColor, 208, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZRHeld()) {
|
||||
drawFunction(g2, heldColor, 208, 4, shapeButton);
|
||||
}
|
||||
if (buttons.isButtonZRJustReleased()) {
|
||||
drawFunction(g2, releasedColor, 208, 4, shapeButton);
|
||||
}
|
||||
|
||||
//joysticks
|
||||
int halfWidth = (int) Math.round(shapeJoystick.getBounds().getWidth() / 2);
|
||||
int halfHeight = (int) Math.round(shapeJoystick.getBounds().getHeight() / 2);
|
||||
|
||||
// left joystick
|
||||
JoystickEvent jl = event.getClassicControllerLeftJoystickEvent();
|
||||
int xCenter1 = 121;
|
||||
int yCenter1 = 125;
|
||||
|
||||
double xAng1 = Math.sin(jl.getAngle() * Math.PI / 180.0) * jl.getMagnitude();
|
||||
double yAng1 = Math.cos(jl.getAngle() * Math.PI / 180.0) * jl.getMagnitude();
|
||||
|
||||
int xShift1 = (int) Math.round(xAng1 * xAmplitude);
|
||||
int yShift1 = (int) Math.round(yAng1 * yAmplitude);
|
||||
int x1 = xCenter1 + xShift1 - halfWidth;
|
||||
int y1 = yCenter1 - yShift1 - halfHeight;
|
||||
// draw shape
|
||||
drawFunction(g2, joystickColor, x1, y1, shapeJoystick);
|
||||
|
||||
//Right joystick
|
||||
JoystickEvent jr = event.getClassicControllerRightJoystickEvent();
|
||||
int xCenter2 = 213;
|
||||
int yCenter2 = 125;
|
||||
|
||||
double xAng2 = Math.sin(jr.getAngle() * Math.PI / 180.0) * jr.getMagnitude();
|
||||
double yAng2 = Math.cos(jr.getAngle() * Math.PI / 180.0) * jr.getMagnitude();
|
||||
|
||||
int xShift2 = (int) Math.round(xAng2 * xAmplitude);
|
||||
int yShift2 = (int) Math.round(yAng2 * yAmplitude);
|
||||
int x2 = xCenter2 + xShift2 - halfWidth;
|
||||
int y2 = yCenter2 - yShift2 - halfHeight;
|
||||
// draw shape
|
||||
drawFunction(g2, joystickColor, x2, y2, shapeJoystick);
|
||||
|
||||
event = null;
|
||||
}
|
||||
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to factorize code.
|
||||
*
|
||||
* @param g2
|
||||
* where to draw a shape.
|
||||
* @param col
|
||||
* color to use.
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates.
|
||||
* @param sh
|
||||
* shape to draw.
|
||||
*/
|
||||
private void drawFunction(Graphics2D g2, Color col, int x, int y, Shape sh) {
|
||||
g2.setPaint(col);
|
||||
g2.translate(x, y);
|
||||
g2.draw(sh);
|
||||
g2.fill(sh);
|
||||
g2.setTransform(new AffineTransform());
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof ClassicControllerEvent) {
|
||||
event = (ClassicControllerEvent) arg0;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
|
||||
clearView();
|
||||
}
|
||||
|
||||
public Color getHeldColor() {
|
||||
return heldColor;
|
||||
}
|
||||
|
||||
public Color getJoystickColor() {
|
||||
return joystickColor;
|
||||
}
|
||||
|
||||
public Color getPressedColor() {
|
||||
return pressedColor;
|
||||
}
|
||||
|
||||
public Color getReleasedColor() {
|
||||
return releasedColor;
|
||||
}
|
||||
|
||||
public Color getShoulderColor() {
|
||||
return shoulderColor;
|
||||
}
|
||||
|
||||
public Shape getShapeButton() {
|
||||
return shapeButton;
|
||||
}
|
||||
|
||||
public Shape getShapeJoystick() {
|
||||
return shapeJoystick;
|
||||
}
|
||||
|
||||
public void setHeldColor(Color heldColor) {
|
||||
this.heldColor = heldColor;
|
||||
}
|
||||
|
||||
public void setJoystickColor(Color joystickColor) {
|
||||
this.joystickColor = joystickColor;
|
||||
}
|
||||
|
||||
public void setPressedColor(Color pressedColor) {
|
||||
this.pressedColor = pressedColor;
|
||||
}
|
||||
|
||||
public void setReleasedColor(Color releasedColor) {
|
||||
this.releasedColor = releasedColor;
|
||||
}
|
||||
|
||||
public void setShoulderColor(Color shoulderColor) {
|
||||
this.shoulderColor = shoulderColor;
|
||||
}
|
||||
|
||||
public void setShapeButton(Shape shapeButton) {
|
||||
this.shapeButton = shapeButton;
|
||||
}
|
||||
|
||||
public void setShapeJoystick(Shape shapeJoystick) {
|
||||
this.shapeJoystick = shapeJoystick;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
event = null;
|
||||
repaint();
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
38
src/main/java/wiiusej/utils/GForceExpansionEventPanel.java
Normal file
38
src/main/java/wiiusej/utils/GForceExpansionEventPanel.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display GForce in a MotionSensingEvent from an expansion.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForceExpansionEventPanel extends GForcePanel{
|
||||
|
||||
@Override
|
||||
public GForce getGForceValue(GenericEvent e) {
|
||||
if (e instanceof NunchukEvent){
|
||||
return ((NunchukEvent)e).getNunchukMotionSensingEvent().getGforce();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
304
src/main/java/wiiusej/utils/GForcePanel.java
Normal file
304
src/main/java/wiiusej/utils/GForcePanel.java
Normal file
@@ -0,0 +1,304 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch gravity force values from a MotionSensingEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class GForcePanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color xColor = Color.RED;
|
||||
private Color yColor = Color.GREEN;
|
||||
private Color zColor = Color.BLUE;
|
||||
private Color backgroundColor = Color.WHITE;
|
||||
private Color lineColor = Color.BLACK;
|
||||
private ArrayList<GForce> values = new ArrayList<GForce>();
|
||||
|
||||
/**
|
||||
* Default constructor of the AccelerationPanel.
|
||||
*/
|
||||
public GForcePanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the AccelerationPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param xxColor
|
||||
* color of the acceleration on X axis.
|
||||
* @param yyColor
|
||||
* color of the acceleration on Y axis.
|
||||
* @param zzColor
|
||||
* color of the acceleration on Z axis.
|
||||
* @param lColor
|
||||
* line color.
|
||||
*/
|
||||
public GForcePanel(Color bgColor, Color xxColor, Color yyColor,
|
||||
Color zzColor, Color lColor) {
|
||||
backgroundColor = bgColor;
|
||||
xColor = xxColor;
|
||||
yColor = yyColor;
|
||||
zColor = zzColor;
|
||||
lineColor = lColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
|
||||
GForce[] valuesArray = values.toArray(new GForce[0]);
|
||||
double unit = yMiddleFloat / 5.0;
|
||||
int previousX = 0;
|
||||
int previousY = 0;
|
||||
int previousZ = 0;
|
||||
// draw curves
|
||||
for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
|
||||
GForce gforce = valuesArray[i];
|
||||
// draw X
|
||||
g2.setPaint(xColor);
|
||||
int yDelta = (int) Math.round(unit * gforce.getX());
|
||||
int y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousX, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousX = y;
|
||||
// draw Y
|
||||
g2.setPaint(yColor);
|
||||
yDelta = (int) Math.round(unit * gforce.getY());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousY, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousY = y;
|
||||
// draw Z
|
||||
g2.setPaint(zColor);
|
||||
yDelta = (int) Math.round(unit * gforce.getZ());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousZ, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousZ = y;
|
||||
}
|
||||
|
||||
// draw legend
|
||||
g2.setPaint(xColor);
|
||||
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
|
||||
g2.setPaint(yColor);
|
||||
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
|
||||
g2.setPaint(zColor);
|
||||
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawString("X", 30, getHeight() - 5);
|
||||
g2.drawString("Y", 85, getHeight() - 5);
|
||||
g2.drawString("Z", 145, getHeight() - 5);
|
||||
g2.drawString("0", 2, yMiddle - 5);
|
||||
g2.drawString("5", 2, 10);
|
||||
g2.drawString("-5", 2, getHeight() - 15);
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// Clear points.
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
private void draw(GenericEvent arg0) {
|
||||
if (values.size() >= getWidth()) {
|
||||
// if there are as many values as pixels in the width
|
||||
// clear points
|
||||
values.clear();
|
||||
}
|
||||
GForce gforce = getGForceValue(arg0);
|
||||
if (gforce != null)
|
||||
values.add(gforce);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public abstract GForce getGForceValue(GenericEvent e);
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
public Color getXColor() {
|
||||
return xColor;
|
||||
}
|
||||
|
||||
public Color getYColor() {
|
||||
return yColor;
|
||||
}
|
||||
|
||||
public Color getZColor() {
|
||||
return zColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setLineColor(Color lineColor) {
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
public void setXColor(Color xColor) {
|
||||
this.xColor = xColor;
|
||||
}
|
||||
|
||||
public void setYColor(Color yColor) {
|
||||
this.yColor = yColor;
|
||||
}
|
||||
|
||||
public void setZColor(Color zColor) {
|
||||
this.zColor = zColor;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
37
src/main/java/wiiusej/utils/GForceWiimoteEventPanel.java
Normal file
37
src/main/java/wiiusej/utils/GForceWiimoteEventPanel.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
/**
|
||||
* Panel to display GForce in a MotionSensingEvent from a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForceWiimoteEventPanel extends GForcePanel {
|
||||
|
||||
@Override
|
||||
public GForce getGForceValue(GenericEvent e) {
|
||||
if (e instanceof MotionSensingEvent) {
|
||||
return ((MotionSensingEvent) e).getGforce();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
274
src/main/java/wiiusej/utils/GuitarHero3ButtonsEventPanel.java
Normal file
274
src/main/java/wiiusej/utils/GuitarHero3ButtonsEventPanel.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.GuitarHeroButtonsEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to display what happens on the buttons of the
|
||||
* Guitar Hero 3 controller.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GuitarHero3ButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
|
||||
/** Creates new form GuitarHero3ButtonsEventPanel */
|
||||
public GuitarHero3ButtonsEventPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/** 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() {
|
||||
|
||||
leftPanel = new javax.swing.JPanel();
|
||||
plusButton = new javax.swing.JToggleButton();
|
||||
minusButton = new javax.swing.JToggleButton();
|
||||
strumPanel = new javax.swing.JPanel();
|
||||
strumUpButton = new javax.swing.JToggleButton();
|
||||
strumDownButton = new javax.swing.JToggleButton();
|
||||
RightPanel = new javax.swing.JPanel();
|
||||
coloredButtonsPanel = new javax.swing.JPanel();
|
||||
orangeButton = new javax.swing.JToggleButton();
|
||||
blueButton = new javax.swing.JToggleButton();
|
||||
yellowButton = new javax.swing.JToggleButton();
|
||||
redButton = new javax.swing.JToggleButton();
|
||||
greenButton = new javax.swing.JToggleButton();
|
||||
|
||||
setBackground(new java.awt.Color(0, 0, 0));
|
||||
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS));
|
||||
|
||||
leftPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
leftPanel.setLayout(new javax.swing.BoxLayout(leftPanel, javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
plusButton.setBackground(new java.awt.Color(255, 255, 255));
|
||||
plusButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
plusButton.setText("+");
|
||||
leftPanel.add(plusButton);
|
||||
|
||||
minusButton.setBackground(new java.awt.Color(255, 255, 255));
|
||||
minusButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
minusButton.setText("-");
|
||||
leftPanel.add(minusButton);
|
||||
|
||||
strumPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
strumPanel.setLayout(new javax.swing.BoxLayout(strumPanel, javax.swing.BoxLayout.Y_AXIS));
|
||||
|
||||
strumUpButton.setBackground(new java.awt.Color(255, 255, 255));
|
||||
strumUpButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
strumUpButton.setText("Strum UP");
|
||||
strumPanel.add(strumUpButton);
|
||||
|
||||
strumDownButton.setBackground(new java.awt.Color(255, 255, 255));
|
||||
strumDownButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
strumDownButton.setText("Strum DOWN");
|
||||
strumPanel.add(strumDownButton);
|
||||
|
||||
leftPanel.add(strumPanel);
|
||||
|
||||
add(leftPanel);
|
||||
|
||||
RightPanel.setBackground(new java.awt.Color(0, 0, 0));
|
||||
RightPanel.setLayout(new javax.swing.BoxLayout(RightPanel, javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
coloredButtonsPanel.setLayout(new javax.swing.BoxLayout(coloredButtonsPanel, javax.swing.BoxLayout.LINE_AXIS));
|
||||
|
||||
orangeButton.setBackground(new java.awt.Color(255, 153, 0));
|
||||
orangeButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
orangeButton.setText("O");
|
||||
coloredButtonsPanel.add(orangeButton);
|
||||
|
||||
blueButton.setBackground(new java.awt.Color(0, 0, 204));
|
||||
blueButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
blueButton.setText("O");
|
||||
coloredButtonsPanel.add(blueButton);
|
||||
|
||||
yellowButton.setBackground(new java.awt.Color(255, 255, 0));
|
||||
yellowButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
yellowButton.setText("O");
|
||||
coloredButtonsPanel.add(yellowButton);
|
||||
|
||||
redButton.setBackground(new java.awt.Color(255, 0, 0));
|
||||
redButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
redButton.setText("O");
|
||||
coloredButtonsPanel.add(redButton);
|
||||
|
||||
greenButton.setBackground(new java.awt.Color(51, 255, 0));
|
||||
greenButton.setFont(new java.awt.Font("Arial", 1, 24));
|
||||
greenButton.setText("O");
|
||||
coloredButtonsPanel.add(greenButton);
|
||||
|
||||
RightPanel.add(coloredButtonsPanel);
|
||||
|
||||
add(RightPanel);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
if (arg0 instanceof GuitarHeroEvent) {
|
||||
GuitarHeroEvent guitar = (GuitarHeroEvent) arg0;
|
||||
GuitarHeroButtonsEvent buttons = guitar.getButtonsEvent();
|
||||
|
||||
//orange button
|
||||
if (buttons.isButtonOrangeJustPressed()) {
|
||||
orangeButton.setSelected(true);
|
||||
orangeButton.setText("X");
|
||||
} else if (buttons.isButtonOrangeJustReleased()) {
|
||||
orangeButton.setSelected(false);
|
||||
orangeButton.setText("O");
|
||||
}
|
||||
|
||||
//blue button
|
||||
if (buttons.isButtonBlueJustPressed()) {
|
||||
blueButton.setSelected(true);
|
||||
blueButton.setText("X");
|
||||
} else if (buttons.isButtonBlueJustReleased()) {
|
||||
blueButton.setSelected(false);
|
||||
blueButton.setText("O");
|
||||
}
|
||||
|
||||
//Yellow button
|
||||
if (buttons.isButtonYellowJustPressed()) {
|
||||
yellowButton.setSelected(true);
|
||||
yellowButton.setText("X");
|
||||
} else if (buttons.isButtonYellowJustReleased()) {
|
||||
yellowButton.setSelected(false);
|
||||
yellowButton.setText("O");
|
||||
}
|
||||
|
||||
//Red button
|
||||
if (buttons.isButtonRedJustPressed()) {
|
||||
redButton.setSelected(true);
|
||||
redButton.setText("X");
|
||||
} else if (buttons.isButtonRedJustReleased()) {
|
||||
redButton.setSelected(false);
|
||||
redButton.setText("O");
|
||||
}
|
||||
|
||||
//Green button
|
||||
if (buttons.isButtonGreenJustPressed()) {
|
||||
greenButton.setSelected(true);
|
||||
greenButton.setText("X");
|
||||
} else if (buttons.isButtonGreenJustReleased()) {
|
||||
greenButton.setSelected(false);
|
||||
greenButton.setText("O");
|
||||
}
|
||||
|
||||
//Plus button
|
||||
if (buttons.isButtonPlusJustPressed()) {
|
||||
plusButton.setSelected(true);
|
||||
} else if (buttons.isButtonPlusJustReleased()) {
|
||||
plusButton.setSelected(false);
|
||||
}
|
||||
|
||||
//Minus button
|
||||
if (buttons.isButtonMinusJustPressed()) {
|
||||
minusButton.setSelected(true);
|
||||
} else if (buttons.isButtonMinusJustReleased()) {
|
||||
minusButton.setSelected(false);
|
||||
}
|
||||
|
||||
//Strum up button
|
||||
if (buttons.isButtonStrumUpJustPressed()) {
|
||||
strumUpButton.setSelected(true);
|
||||
} else if (buttons.isButtonStrumUpJustReleased()) {
|
||||
strumUpButton.setSelected(false);
|
||||
}
|
||||
|
||||
//Strum down button
|
||||
if (buttons.isButtonStrumDownJustPressed()) {
|
||||
strumDownButton.setSelected(true);
|
||||
} else if (buttons.isButtonStrumDownJustReleased()) {
|
||||
strumDownButton.setSelected(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
|
||||
//do nothing
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel RightPanel;
|
||||
private javax.swing.JToggleButton blueButton;
|
||||
private javax.swing.JPanel coloredButtonsPanel;
|
||||
private javax.swing.JToggleButton greenButton;
|
||||
private javax.swing.JPanel leftPanel;
|
||||
private javax.swing.JToggleButton minusButton;
|
||||
private javax.swing.JToggleButton orangeButton;
|
||||
private javax.swing.JToggleButton plusButton;
|
||||
private javax.swing.JToggleButton redButton;
|
||||
private javax.swing.JToggleButton strumDownButton;
|
||||
private javax.swing.JPanel strumPanel;
|
||||
private javax.swing.JToggleButton strumUpButton;
|
||||
private javax.swing.JToggleButton yellowButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Guitar Hero 3 controller joystick events.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GuitarHeroJoystickEventPanel extends JoystickEventPanel{
|
||||
|
||||
@Override
|
||||
public JoystickEvent getJoystickEvent(ExpansionEvent e) {
|
||||
if (e instanceof GuitarHeroEvent){
|
||||
return ((GuitarHeroEvent)e).getGuitarHeroJoystickEvent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
275
src/main/java/wiiusej/utils/IRPanel.java
Normal file
275
src/main/java/wiiusej/utils/IRPanel.java
Normal file
@@ -0,0 +1,275 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to see what the IR camera of the wiimote sees.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
|
||||
private static int MAX_NB_POINTS = 4;
|
||||
private Color color = Color.YELLOW;
|
||||
private Color backgroundColor = Color.BLACK;
|
||||
private Color borderColor = Color.BLUE;
|
||||
private Shape shape;
|
||||
private Image mImage;// image for double buffering
|
||||
private int[] xCoordinates;
|
||||
private int[] yCoordinates;
|
||||
private int nbPoints = -1;
|
||||
|
||||
/**
|
||||
* Default constructor for IR Panel. Background color : black. IR sources
|
||||
* color : yellow. Border color of IR sources : blue. Shape of the IR
|
||||
* sources : circle with a diameter of 10.
|
||||
*/
|
||||
public IRPanel() {
|
||||
shape = new java.awt.geom.Ellipse2D.Double(0, 0, 10, 10);
|
||||
initArrays();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to parameterize the IR panel.
|
||||
*
|
||||
* @param bgColor
|
||||
* color.
|
||||
* @param ptColor
|
||||
* IR sources color.
|
||||
* @param bdColor
|
||||
* border color of IR sources.
|
||||
* @param sh
|
||||
* Shape of the IR sources.
|
||||
*/
|
||||
public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) {
|
||||
backgroundColor = bgColor;
|
||||
color = ptColor;
|
||||
borderColor = bdColor;
|
||||
shape = sh;
|
||||
initArrays();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initArrays() {
|
||||
xCoordinates = new int[MAX_NB_POINTS];
|
||||
yCoordinates = new int[MAX_NB_POINTS];
|
||||
for (int i = 0; i < MAX_NB_POINTS; i++) {
|
||||
xCoordinates[i] = -1;
|
||||
yCoordinates[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw points
|
||||
int i = 0;
|
||||
while (i < nbPoints) {
|
||||
double x = xCoordinates[i];
|
||||
double y = yCoordinates[i];
|
||||
|
||||
long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0);
|
||||
long yy = getHeight()
|
||||
- Math.round((double) getHeight() * y / 768.0);
|
||||
g2.translate(xx, yy);
|
||||
|
||||
g2.setPaint(borderColor);
|
||||
g2.draw(shape);
|
||||
g2.setPaint(color);
|
||||
g2.fill(shape);
|
||||
|
||||
g2.setTransform(new AffineTransform());
|
||||
i++;
|
||||
}
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// transfer points
|
||||
wiiusej.values.IRSource[] points = arg0.getIRPoints();
|
||||
nbPoints = points.length;
|
||||
for (int i = 0; i < points.length; i++) {
|
||||
xCoordinates[i] = (int) points[i].getRx();
|
||||
yCoordinates[i] = (int) points[i].getRy();
|
||||
}
|
||||
for (int i = points.length; i < MAX_NB_POINTS; i++) {
|
||||
xCoordinates[i] = -1;
|
||||
yCoordinates[i] = -1;
|
||||
}
|
||||
|
||||
// redraw panel
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// clear previous points
|
||||
for (int i = 0; i < MAX_NB_POINTS; i++) {
|
||||
xCoordinates[i] = -1;
|
||||
yCoordinates[i] = -1;
|
||||
}
|
||||
// redraw panel
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
initArrays();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
248
src/main/java/wiiusej/utils/JoystickEventPanel.java
Normal file
248
src/main/java/wiiusej/utils/JoystickEventPanel.java
Normal file
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* Panel to display joystick events.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class JoystickEventPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color backgroundColor = Color.BLACK;
|
||||
private Color borderColor = Color.RED;
|
||||
private Color pointColor = Color.RED;
|
||||
private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30);
|
||||
private JoystickEvent lastJoystickEvent = null;
|
||||
|
||||
/** Creates new form JoystickPanel */
|
||||
public JoystickEventPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the JoystickPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param pColor
|
||||
* point color.
|
||||
* @param bdColor
|
||||
* border color for the shape.
|
||||
* @param sh
|
||||
* shape of what is drawn.
|
||||
*/
|
||||
public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor,
|
||||
Shape sh) {
|
||||
backgroundColor = bgColor;
|
||||
pointColor = pColor;
|
||||
shape = sh;
|
||||
borderColor = bdColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
// compute center
|
||||
int xCenter = (int) Math.round(d.getWidth() / 2.0);
|
||||
int yCenter = (int) Math.round(d.getHeight() / 2.0);
|
||||
|
||||
// compute coordinates
|
||||
if (lastJoystickEvent != null) {
|
||||
double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI
|
||||
/ 180.0)
|
||||
* lastJoystickEvent.getMagnitude();
|
||||
double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI
|
||||
/ 180.0)
|
||||
* lastJoystickEvent.getMagnitude();
|
||||
int halfWidth = (int) Math.round(shape.getBounds().getWidth() / 2);
|
||||
int halHeight = (int) Math.round(shape.getBounds().getHeight() / 2);
|
||||
int xAmplitude = (int) Math.round(xCenter - shape.getBounds().getWidth());
|
||||
int yAmplitude = (int) Math.round(xCenter - shape.getBounds().getHeight());
|
||||
int xShift = (int) Math.round(xAng * xAmplitude);
|
||||
int yShift = (int) Math.round(yAng * yAmplitude);
|
||||
int x = xCenter + xShift - halfWidth;
|
||||
int y = yCenter - yShift - halHeight;
|
||||
// shape
|
||||
g2.translate(x, y);
|
||||
g2.setPaint(borderColor);
|
||||
g2.draw(shape);
|
||||
g2.setPaint(pointColor);
|
||||
g2.fill(shape);
|
||||
}
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
JoystickEvent joy = getJoystickEvent(arg0);
|
||||
if (joy != null) {
|
||||
lastJoystickEvent = joy;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getPointColor() {
|
||||
return pointColor;
|
||||
}
|
||||
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public Shape getShape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setPointColor(Color pointColor) {
|
||||
this.pointColor = pointColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
public void setShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public abstract JoystickEvent getJoystickEvent(ExpansionEvent e);
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
38
src/main/java/wiiusej/utils/NunchukJoystickEventPanel.java
Normal file
38
src/main/java/wiiusej/utils/NunchukJoystickEventPanel.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display nunchuk joystick events.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class NunchukJoystickEventPanel extends JoystickEventPanel {
|
||||
|
||||
@Override
|
||||
public JoystickEvent getJoystickEvent(ExpansionEvent e) {
|
||||
if (e instanceof NunchukEvent) {
|
||||
return ((NunchukEvent) e).getNunchukJoystickEvent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.Orientation;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Orientation in a MotionSensingEvent from an expansion.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class OrientationExpansionEventPanel extends OrientationPanel {
|
||||
|
||||
@Override
|
||||
public Orientation getOrientationValue(GenericEvent e) {
|
||||
if (e instanceof NunchukEvent) {
|
||||
return ((NunchukEvent) e).getNunchukMotionSensingEvent()
|
||||
.getOrientation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
305
src/main/java/wiiusej/utils/OrientationPanel.java
Normal file
305
src/main/java/wiiusej/utils/OrientationPanel.java
Normal file
@@ -0,0 +1,305 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.Orientation;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiusejevents.utils.WiimoteListener;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch orientation values from a MotionSensingEvent.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class OrientationPanel extends javax.swing.JPanel implements
|
||||
WiimoteListener {
|
||||
|
||||
private Image mImage;// image for double buffering
|
||||
private Color rollColor = Color.RED;
|
||||
private Color pitchColor = Color.GREEN;
|
||||
private Color yawColor = Color.BLUE;
|
||||
private Color backgroundColor = Color.WHITE;
|
||||
private Color lineColor = Color.BLACK;
|
||||
private ArrayList<Orientation> values = new ArrayList<Orientation>();
|
||||
|
||||
/**
|
||||
* Default constructor. Background color : White. Roll color : Red. Pitch
|
||||
* color : Green. Yaw color : Blue.
|
||||
*/
|
||||
public OrientationPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to choose the colors used by the OrientationPanel.
|
||||
*
|
||||
* @param bgColor
|
||||
* background color.
|
||||
* @param rColor
|
||||
* roll color.
|
||||
* @param pColor
|
||||
* pitch color.
|
||||
* @param yColor
|
||||
* yaw color.
|
||||
* @param lColor
|
||||
* line color.
|
||||
*/
|
||||
public OrientationPanel(Color bgColor, Color rColor, Color pColor,
|
||||
Color yColor, Color lColor) {
|
||||
backgroundColor = bgColor;
|
||||
rollColor = rColor;
|
||||
pitchColor = pColor;
|
||||
yawColor = yColor;
|
||||
lineColor = lColor;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Dimension d = getSize();
|
||||
checkOffScreenImage();
|
||||
Graphics offG = mImage.getGraphics();
|
||||
offG.setColor(backgroundColor);
|
||||
offG.fillRect(0, 0, d.width, d.height);
|
||||
Graphics2D g2 = (Graphics2D) mImage.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
|
||||
Orientation[] valuesArray = values.toArray(new Orientation[0]);
|
||||
double unit = yMiddleFloat / 180.0;
|
||||
int previousRoll = 0;
|
||||
int previousPitch = 0;
|
||||
int previousYaw = 0;
|
||||
// draw curves
|
||||
for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
|
||||
Orientation orientation = valuesArray[i];
|
||||
// draw roll
|
||||
g2.setPaint(rollColor);
|
||||
int yDelta = (int) Math.round(unit * orientation.getRoll());
|
||||
int y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousRoll, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousRoll = y;
|
||||
// draw pitch
|
||||
g2.setPaint(pitchColor);
|
||||
yDelta = (int) Math.round(unit * orientation.getPitch());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousPitch, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousPitch = y;
|
||||
// draw yaw
|
||||
g2.setPaint(yawColor);
|
||||
yDelta = (int) Math.round(unit * orientation.getYaw());
|
||||
y = -1 * yDelta + yMiddle;
|
||||
g2.drawLine(i - 1, previousYaw, i, y);
|
||||
g2.setTransform(new AffineTransform());
|
||||
previousYaw = y;
|
||||
}
|
||||
|
||||
// draw legend
|
||||
g2.setPaint(rollColor);
|
||||
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
|
||||
g2.setPaint(pitchColor);
|
||||
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
|
||||
g2.setPaint(yawColor);
|
||||
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawString("Roll", 30, getHeight() - 5);
|
||||
g2.drawString("Pitch", 85, getHeight() - 5);
|
||||
g2.drawString("Yaw", 145, getHeight() - 5);
|
||||
g2.drawString("0", 2, yMiddle - 5);
|
||||
g2.drawString("180", 2, 10);
|
||||
g2.drawString("-180", 2, getHeight() - 15);
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the mImage variable has been initialized. If it's not the case
|
||||
* it initializes it with the dimensions of the panel. mImage is for double
|
||||
* buffering.
|
||||
*/
|
||||
private void checkOffScreenImage() {
|
||||
Dimension d = getSize();
|
||||
if (mImage == null || mImage.getWidth(null) != d.width
|
||||
|| mImage.getHeight(null) != d.height) {
|
||||
mImage = createImage(d.width, d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent arg0) {
|
||||
draw(arg0);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
// Clear points.
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerInsertedEvent(
|
||||
ClassicControllerInsertedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onClassicControllerRemovedEvent(
|
||||
ClassicControllerRemovedEvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
private void draw(GenericEvent arg0) {
|
||||
if (values.size() >= getWidth()) {
|
||||
// if there are as many values as pixels in the width
|
||||
// clear points
|
||||
values.clear();
|
||||
}
|
||||
Orientation orientation = getOrientationValue(arg0);
|
||||
if (orientation != null)
|
||||
values.add(orientation);
|
||||
repaint();
|
||||
}
|
||||
|
||||
public abstract Orientation getOrientationValue(GenericEvent e);
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public Color getLineColor() {
|
||||
return lineColor;
|
||||
}
|
||||
|
||||
public Color getPitchColor() {
|
||||
return pitchColor;
|
||||
}
|
||||
|
||||
public Color getRollColor() {
|
||||
return rollColor;
|
||||
}
|
||||
|
||||
public Color getYawColor() {
|
||||
return yawColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
public void setLineColor(Color lineColor) {
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
public void setPitchColor(Color pitchColor) {
|
||||
this.pitchColor = pitchColor;
|
||||
}
|
||||
|
||||
public void setRollColor(Color rollColor) {
|
||||
this.rollColor = rollColor;
|
||||
}
|
||||
|
||||
public void setYawColor(Color yawColor) {
|
||||
this.yawColor = yawColor;
|
||||
}
|
||||
|
||||
public void clearView() {
|
||||
values.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
|
||||
Short.MAX_VALUE));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(
|
||||
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
|
||||
Short.MAX_VALUE));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.utils;
|
||||
|
||||
import wiiusej.values.Orientation;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
/**
|
||||
* Panel to display Orientation in a MotionSensingEvent from a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class OrientationWiimoteEventPanel extends OrientationPanel {
|
||||
|
||||
@Override
|
||||
public Orientation getOrientationValue(GenericEvent e) {
|
||||
if (e instanceof MotionSensingEvent) {
|
||||
return ((MotionSensingEvent) e).getOrientation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user