Пример #1
0
    def __init__(self, figure):
        FigureCanvasAgg.__init__(self, figure)
        self.__ref_id, self.__ref = javabridge.create_jref(self)
        self.__cpython = javabridge.make_instance(
            'org/cellprofiler/javabridge/CPython', '()V')

        paint_script = (
            'import javabridge\n'
            'self = javabridge.redeem_jref("%s")\n'
            'self.draw(javabridge.JWrapper(graphics))\n') % self.__ref_id

        component = javabridge.run_script(
            """
        new javax.swing.JComponent() {
            paintComponent: function(graphics) {
                locals = new java.util.Hashtable();
                locals.put("graphics", graphics);
                cpython.exec(script, locals, locals);
            }
        }
        """, dict(cpython=self.__cpython, script=paint_script))
        self.__component = javabridge.JWrapper(component)
        self.__event_queue_class = None
        self.__component_listener = javabridge.JProxy(
            'java.awt.event.ComponentListener',
            dict(componentHidden=self._on_component_hidden,
                 componentMoved=self._on_component_moved,
                 componentResized=self._on_component_resized,
                 componentShown=self._on_component_shown))
        self.__component.addComponentListener(self.__component_listener.o)
        self.__key_event_cls = javabridge.JClassWrapper(
            'java.awt.event.KeyEvent')
        self.__key_listener = javabridge.JProxy(
            'java.awt.event.KeyListener',
            dict(keyPressed=self._on_key_pressed,
                 keyReleased=self._on_key_released,
                 keyTyped=self._on_key_typed))
        self.__component.addKeyListener(self.__key_listener.o)
        self.__component.setFocusable(True)
        self.__mouse_listener = javabridge.JProxy(
            'java.awt.event.MouseListener',
            dict(mouseClicked=self._on_mouse_clicked,
                 mouseEntered=self._on_mouse_entered,
                 mouseExited=self._on_mouse_exited,
                 mousePressed=self._on_mouse_pressed,
                 mouseReleased=self._on_mouse_released))
        self.__component.addMouseListener(self.__mouse_listener.o)
        self.__mouse_motion_listener = javabridge.JProxy(
            'java.awt.event.MouseMotionListener',
            dict(mouseDragged=self._on_mouse_dragged,
                 mouseMoved=self._on_mouse_moved))
        self.__component.addMouseMotionListener(self.__mouse_motion_listener.o)
Пример #2
0
    def test_01_01_init(self):
        def whatever():
            pass

        proxy = J.JProxy('java.lang.Runnable', dict(run=whatever))
        # <AK> added
        J.JWrapper(proxy.o).run()
Пример #3
0
    def test_01_02_runnable(self):
        magic = []

        def whatever(magic=magic):
            magic.append("bus")

        runnable = J.JProxy('java.lang.Runnable', dict(run=whatever))
        J.JWrapper(runnable.o).run()
        self.assertEqual(magic[0], "bus")
Пример #4
0
    def test_01_04_args(self):
        my_observable = J.make_instance("java/util/Observable", "()V")

        def update(observable, obj):
            self.assertTrue(J.JWrapper(observable).equals(my_observable))
            self.assertTrue(J.JWrapper(obj).equals("bar"))

        proxy = J.JProxy('java.util.Observer', dict(update=update))
        J.JWrapper(proxy.o).update(my_observable, "bar")
Пример #5
0
    def test_01_01_init(self):
        def whatever():
            pass

        J.JProxy('java.lang.Runnable', dict(run=whatever))
Пример #6
0
    def test_01_05_return_value(self):
        def call():
            return "foo"

        proxy = J.JProxy('java.util.concurrent.Callable', dict(call=call))
        self.assertEquals(J.JWrapper(proxy.o).call(), "foo")