private boolean replayevent(GaudiEvent e) { try { // replay e_i Component w_i = this.hierarchy.findWidget(e.widgetid); if (w_i == null) { System.err.println( "[GAUDI][Replayer] Could not find component: " + e.widgetid + ". Trying again..."); // TODO: fix this processGUI(); sleep(5000); w_i = this.hierarchy.findWidget(e.widgetid); if (w_i == null) { System.err.println("[GAUDI][Replayer] Could not find component again :( exiting....."); // Launcher.shutdownW(); } else System.err.println("[GAUDI][Replayer] Found it!: "); } // Component c = this.hierarchy.findWidget(e.widgetid); if (w_i != null /* && !e.widgetid.equals(lastWidgetClicked)*/) { if (e.id == MouseEvent.MOUSE_PRESSED || e.id == MouseEvent.MOUSE_RELEASED || e.id == MouseEvent.MOUSE_CLICKED) { replayMouseEntered(e, w_i); this.lastWidgetClicked = e.widgetid; } if (w_i instanceof JMenu) replayMousePressed(e, w_i); else if (w_i instanceof JMenuItem) replayMousePressedAndReleased(e, w_i); else if (w_i instanceof JButton) replayMousePressedAndReleased(e, w_i); else if (w_i instanceof JTextArea || w_i.toString().contains("TextArea") || w_i instanceof JTextField) { replayMousePressedAndReleased(e, w_i); replayKeyTyped(e, w_i); } else replayMousePressedAndReleased(e, w_i); } } catch (Throwable t) { t.printStackTrace(); // return true;//TODO: F } return false; }
public String toString() { SampleStringUtility.outStartEnd(this, SampleStringUtility.OUT_START); StringBuffer retSb = new StringBuffer(); // output to component list Component[] coms = getContentPane().getComponents(); for (Component com : coms) { retSb.append("com:" + com.toString()); retSb.append(System.getProperty("line.separator")); } // output toBounds retSb.append("getBounds:" + getBounds().toString()); retSb.append(System.getProperty("line.separator")); retSb.append("getLayout:" + getLayout().getClass().getName().toString()); System.out.println(retSb.toString()); SampleStringUtility.outStartEnd(this, SampleStringUtility.OUT_END); return retSb.toString(); }
public void write(Writer out, Document doc, int pos, int len, Map<String, String> copiedImgs) throws IOException, BadLocationException { Debug.log(9, "SikuliEditorKit.write %d %d", pos, len); DefaultStyledDocument sdoc = (DefaultStyledDocument) doc; int i = pos; String absPath; while (i < pos + len) { Element e = sdoc.getCharacterElement(i); int start = e.getStartOffset(), end = e.getEndOffset(); if (e.getName().equals(StyleConstants.ComponentElementName)) { // A image argument to be filled AttributeSet attr = e.getAttributes(); Component com = StyleConstants.getComponent(attr); out.write(com.toString()); if (copiedImgs != null && (com instanceof EditorPatternButton || com instanceof EditorPatternLabel)) { if (com instanceof EditorPatternButton) { absPath = ((EditorPatternButton) com).getFilename(); } else { absPath = ((EditorPatternLabel) com).getFile(); } String fname = (new File(absPath)).getName(); copiedImgs.put(fname, absPath); Debug.log(3, "save image for copy&paste: " + fname + " -> " + absPath); } } else { if (start < pos) { start = pos; } if (end > pos + len) { end = pos + len; } out.write(doc.getText(start, end - start)); } i = end; } out.close(); }
public static void feedMouseEventToPanel(int x, int y) { Point p = new Point(x, y); SwingUtilities.convertPointFromScreen(p, frame.getContentPane()); System.out.println("x " + x + " y " + y); System.out.println("p.x " + p.x + " p.y " + p.y); if ((p.x > 0 && p.x < frame.getWidth()) && (p.y > 0 && p.y < frame.getHeight())) { Component comp = SwingUtilities.getDeepestComponentAt(frame.getContentPane(), p.x, p.y); System.out.println(comp.toString()); Toolkit.getDefaultToolkit() .getSystemEventQueue() .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_PRESSED, 0, 0, p.x, p.y, 1, false)); Toolkit.getDefaultToolkit() .getSystemEventQueue() .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_RELEASED, 0, 0, p.x, p.y, 1, false)); Toolkit.getDefaultToolkit() .getSystemEventQueue() .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_CLICKED, 0, 0, p.x, p.y, 1, false)); } }
/** * Bewegt eine Spielfigur durch verändern der List<Token> tokens und zeichnet gleichzeitig diesen * Spielzug auf der Oberfläche. * * @param targetPos Ziel */ public void move(Field targetPos) { Component me = this.parent.getLayer().getComponentAt(this.getLocation()); try { this.parent.getLayer().moveToFront(me); } catch (Exception e) { System.out.println("DEBUG: " + e.toString()); System.out.println("DEBUG: " + me.toString()); System.exit(1); } Point oldPos = this.parent.fieldToPoint(this.token.getPos()); Point newPos = this.parent.fieldToPoint(targetPos); // Update token's position synchronized (this.token) { this.token.move(targetPos); } long linearAnimationTime = 6; int linearStepSize = 4; for (int x = oldPos.x; x < newPos.x; x += linearStepSize) { this.setLocation(x, oldPos.y); try { Thread.sleep(linearAnimationTime); } catch (Exception e) { } } for (int x = oldPos.x; x > newPos.x; x -= linearStepSize) { this.setLocation(x, oldPos.y); try { Thread.sleep(linearAnimationTime); } catch (Exception e) { } } for (int y = oldPos.y; y < newPos.y; y += linearStepSize) { this.setLocation(newPos.x, y); try { Thread.sleep(linearAnimationTime); } catch (Exception e) { } } for (int y = oldPos.y; y > newPos.y; y -= linearStepSize) { this.setLocation(newPos.x, y); try { Thread.sleep(linearAnimationTime); } catch (Exception e) { } } // Set token to final position / Fix token's position this.setLocation(newPos); this.parent.getLayer().validate(); this.parent.getLayer().repaint(); }