1 package jp.go.aist.hrp.joystick.views;
7 import org.eclipse.swt.widgets.*;
8 import org.eclipse.ui.part.*;
9 import org.eclipse.swt.events.*;
10 import org.eclipse.swt.graphics.*;
11 import org.eclipse.swt.SWT;
36 private static Point
pj =
new Point(0,0);
37 private static Point
PC =
pj;
50 System.out.println(
"[Joystick] COMPONENT START");
55 System.out.println(
"Failed to locate the path to configuration file : rtc.conf");
56 System.out.println(
"Joystick Aborted");
58 String[] args = {
"-f", confPath};
64 final Manager
manager = Manager.init(args);
69 manager.setModuleInitProc(joystickComp);
71 if(manager.getPOAManager().get_state().value()!=1) {
73 manager.activateManager();
76 manager.runManager(
true);
82 Point pos =
new Point(pj.x-PC.x,pj.y-PC.y);
88 canvas =
new Canvas(parent, SWT.BORDER | SWT.NO_BACKGROUND);
93 canvas.addPaintListener(
new PaintListener() {
94 public void paintControl(PaintEvent e) {
95 Point p0 = canvas.getLocation();
96 Point p1 = canvas.getSize();
97 Point P0 =
new Point(p0.x,p0.y);
98 Point P1 =
new Point(p0.x+p1.x,p0.y+p1.y);
99 Point pc =
new Point((P0.x+P1.x)/2,(P0.y+P1.y)/2);
102 Color col1 =
new Color(e.display,221,221,221);
103 Color col2 =
new Color(e.display,238,238,238);
104 Color white=
new Color(e.display,255,255,255);
107 Image
image =
new Image(canvas.getDisplay(), canvas.getBounds());
108 GC gcImage =
new GC(image);
110 gcImage.setBackground(e.gc.getBackground());
111 gcImage.fillRectangle(image.getBounds());
113 gcImage.setForeground(white);
115 for(
int i=10;
i>0;
i--) {
116 p0.x = pc.x - pitch *
i;
117 p0.y = pc.y - pitch *
i;
118 p1.x = pc.x + pitch *
i;
119 p1.y = pc.y + pitch *
i;
126 gcImage.setBackground(color);
127 gcImage.fillOval(p0.x,p0.y,p1.x-p0.x,p1.y-p0.y);
128 gcImage.drawOval(p0.x,p0.y,p1.x-p0.x,p1.y-p0.y);
130 gcImage.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
131 gcImage.drawLine(pc.x, P0.y, pc.x, P1.y);
132 gcImage.drawLine(P0.x, pc.y, P1.x, pc.y);
134 gcImage.drawString(
"x", P1.x-20, pc.y+10);
135 gcImage.drawString(
"y", pc.x+10, P0.y);
138 pj =
new Point(pc.x,pc.y);
142 double _r = Math.round(Math.hypot(pos.x, pos.y)*100)/100.0;
143 double _th = Math.round(Math.toDegrees(Math.atan2(pos.y,pos.x))*100)/100.0;
144 gcImage.drawString(
"x: "+pos.x, (pc.x+P1.x)/2-20, P1.y-40);
145 gcImage.drawString(
"y: "+pos.y, (pc.x+P1.x)/2+55, P1.y-40);
146 gcImage.drawString(
"r: "+_r, (pc.x+P1.x)/2-20, P1.y-20);
147 gcImage.drawString(
"th: "+_th, (pc.x+P1.x)/2+50, P1.y-20);
149 gcImage.setBackground(col1);
150 gcImage.drawLine(pc.x, pc.y, pj.x, pj.y);
151 gcImage.fillOval(pj.x-10, pj.y-10, 20, 20);
152 gcImage.drawOval(pj.x-10, pj.y-10, 20, 20);
154 e.gc.drawImage(image, 0, 0);
159 region =
new Region();
160 region.add(
new Rectangle(pj.x-10, pj.y-10, 20, 20));
164 canvas.addMouseListener(
new MouseAdapter() {
165 public void mouseDown(MouseEvent e) {
166 Point ep =
new Point(e.x, e.y);
167 if(region.contains(ep)) {
172 public void mouseUp(MouseEvent e) {
178 canvas.addMouseMoveListener(
new MouseMoveListener() {
179 public void mouseMove(MouseEvent e) {
static Point getJoystickPosition()
void createPartControl(Composite parent)
static String getConfigFilePath()
void execJoystick()
Joystick コンポーネントの立ち上げ
Standalone component Class.