wiiusej 0.12 clean1 before release

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@158 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-06-01 09:50:30 +00:00
parent 2fb184eda3
commit b2c8a6d87d
35 changed files with 1219 additions and 1080 deletions

View File

@@ -37,188 +37,195 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/**
* Panel to display joystick events.
* @author guiguito
*
* @author guiguito
*/
public abstract class JoystickEventPanel extends javax.swing.JPanel implements WiimoteListener {
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;
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();
}
/** 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();
}
/**
* 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());
@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 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 dx = (int) Math.round(shape.getBounds().getWidth() / 2);
int dy = (int) Math.round(shape.getBounds().getHeight() / 2);
double xTemp = xAng * (xCenter - dx * 2);
double yTemp = yAng * (yCenter - dy * 2);
int x = xCenter - dx + (int) xTemp;
int y = yCenter - dy - (int) yTemp;
// System.out.println("--------------------------------------------------------------------");
// System.out.println(lastJoystickEvent);
// System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter);
// System.out.println("xAng, yAng : "+xAng+" , "+yAng);
// System.out.println("dx, dy : "+dx+" , "+dy);
// System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp);
// System.out.println("x, y : "+x+" , "+y);
//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);
}
// 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 dx = (int) Math.round(shape.getBounds().getWidth() / 2);
int dy = (int) Math.round(shape.getBounds().getHeight() / 2);
double xTemp = xAng * (xCenter - dx * 2);
double yTemp = yAng * (yCenter - dy * 2);
int x = xCenter - dx + (int) xTemp;
int y = yCenter - dy - (int) yTemp;
// System.out.println("--------------------------------------------------------------------");
// System.out.println(lastJoystickEvent);
// System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter);
// System.out.println("xAng, yAng : "+xAng+" , "+yAng);
// System.out.println("dx, dy : "+dx+" , "+dy);
// System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp);
// System.out.println("x, y : "+x+" , "+y);
// 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);
}
}
/**
* 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 onButtonsEvent(WiimoteButtonsEvent arg0) {
// nothing
}
public void onIrEvent(IREvent arg0) {
//nothing
}
public void onIrEvent(IREvent arg0) {
// nothing
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
// nothing
}
public void onExpansionEvent(ExpansionEvent arg0) {
JoystickEvent joy = getJoystikEvent(arg0);
if (joy != null) {
lastJoystickEvent = joy;
}
repaint();
}
public void onExpansionEvent(ExpansionEvent arg0) {
JoystickEvent joy = getJoystikEvent(arg0);
if (joy != null) {
lastJoystickEvent = joy;
}
repaint();
}
public void onStatusEvent(StatusEvent arg0) {
//nothing
}
public void onStatusEvent(StatusEvent arg0) {
// nothing
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
//nothing
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// nothing
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
//nothing
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
// nothing
}
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
//nothing
}
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing
}
public Color getBackgroundColor() {
return backgroundColor;
}
public Color getBackgroundColor() {
return backgroundColor;
}
public Color getPointColor() {
return pointColor;
}
public Color getPointColor() {
return pointColor;
}
public Color getBorderColor() {
return borderColor;
}
public Color getBorderColor() {
return borderColor;
}
public Shape getShape() {
return shape;
}
public Shape getShape() {
return shape;
}
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
public void setPointColor(Color pointColor) {
this.pointColor = pointColor;
}
public void setPointColor(Color pointColor) {
this.pointColor = pointColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
public void setShape(Shape shape) {
this.shape = shape;
}
public void setShape(Shape shape) {
this.shape = shape;
}
public abstract JoystickEvent getJoystikEvent(ExpansionEvent e);
public abstract JoystickEvent getJoystikEvent(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() {
/**
* 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
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
}