Can't get tag list for gs:mouse-released event...

Started by oofoe, October 06, 2012, 09:01:42 PM

Previous topic - Next topic

oofoe

Hi!



According to the documentation, specifying gs:mouse-released with a third argument of "true" will provide a list of tags whose member's bounding boxes intersect the mouse cursor position. However, this doesn't seem to actually work (see example code below). If the "true" argument is removed, then you will see little red circles where you click. Otherwise nada.



Any ideas what's wrong? Thanks in advance!



(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(gs:init)

(gs:frame 'main  100 100  800 800  "Demo")
(gs:set-border-layout 'main)

(gs:canvas 'main-canvas)
(gs:set-background 'main-canvas gs:gray)
(gs:add-to 'main 'main-canvas "center")
(gs:set-visible 'main true)

;; This is the affected line:
(gs:mouse-released 'main-canvas 'canvas-clicking true)

(define (canvas-clicking x y)
  (println (args))
  (gs:draw-circle 'C x y 8 gs:red)
  (gs:update)
  )

(gs:listen)
Testing can show the presence of bugs, but not their absence.

oofoe

#1
OK, some more data points about the problem:



 * Using NewLisp v.10.4.4

 * Using latest x86 Java from Oracle (jre7, platform 1.7, product 1.7.0_07)

 * The "true" flag is not working for other functions -- for instance, there's no feedback

    when I set "(gs:set-trace true)" or trace messages either.

 * Since I couldn't use gs:set-trace, I added this line above the set-trace net-send call:
   (println (string "set-trace System " flag "n"))
   It prints:
   set-trace System true
   Which should be right, right?



The button-demo.lsp program works, but doesn't output the trace messages, so I don't think it's just my program.



Thanks!
Testing can show the presence of bugs, but not their absence.

oofoe

#2
OK, I figured that if the flag for tracing GUI calls wasn't working, I'd just recompile %guiserver.jar and force it to print out.



So, I dragged down the latest source and added a new line to %java/Dispatcher.exe:

if(guiserver.debug) System.out.println("-> " + command);
System.out.println("F> " + command); // F for forced... josh 2012-10-07


I recompiled and pointed Newlisp's %guiserver.lsp to my new %guiserver.jar. I figured this way, I'd be sure to see something. And I don't.



As long as I just want to draw pictures with no true/false flags I'm OK. Beyond that... I'm stumped.
Testing can show the presence of bugs, but not their absence.

oofoe

Alright! Figured out the guiserver trace problem -- I had "Javaw" associated to %.jar files, not "Java". Javaw is not attached to a console, so it's GUI only. I was able to start my program directly from Java with:



Java -jar ..guiserver.jar 47011 program.lsp


Now I have tracing! So, I can now see what happens when I attempt to set the event handler for mouse-released:



-> mouse-released MAIN:main-canvas MAIN:canvas-clicking true
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)
        at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
        at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
        at javax.swing.JComponent.getFontMetrics(Unknown Source)
        at TextShape.hasPoint(TextShape.java:86)
        at CanvasWidget$MyCanvas.getTagsFromPoint(CanvasWidget.java:675)
        at CanvasWidget$MyCanvas.mouseReleased(CanvasWidget.java:754)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)


This appears to be some sort of nasty with Java itself. Any ideas?



Thanks very much!
Testing can show the presence of bugs, but not their absence.

oofoe

#4
OK, found it. In my original code (not the small snippet I posted), I had this line:


(gs:draw-text 'T "Click to create a node..." 20 30 gs:white)

Commenting that out and tag return works. So, some problem with how I did the text. Have to go finish building a USB typewriter, so I'll investigate that more later, since it's a problem not to be able to do text too...
Testing can show the presence of bugs, but not their absence.

oofoe

#5
OK, seems the actual problem was that I hadn't set the font. Adding:


(gs:set-font 'main-canvas "Lucida Sans" 20 "plain")

Fixes it. I guess the Java stack trace comes from not having a specified type metric for whatever it is that does the collision detection to determine if you've clicked on a canvas item.



I guess it would be nice if some sensible default was set up so that exception wouldn't get triggered. If I have time for it, I might go digging around in the guiserver and see if I can come up with a patch.
Testing can show the presence of bugs, but not their absence.

bairui

#6
Nothing bright to add to this, oofoe, except to say: nice work