diff options
Diffstat (limited to 'src/classes/com/sun/javafx/newt/Window.java')
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Window.java | 149 |
1 files changed, 145 insertions, 4 deletions
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index c9437a196..2bfcf1265 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -33,6 +33,9 @@ package com.sun.javafx.newt; +import java.util.ArrayList; +import java.util.Iterator; + public abstract class Window { /** OpenKODE window type */ public static final String KD = "KD"; @@ -47,7 +50,7 @@ public abstract class Window { public static final String MACOSX = "MacOSX"; /** Creates a Window of the default type for the current operating system. */ - public static Window create() { + public static Window create(long visualID) { String osName = System.getProperty("os.name"); String osNameLowerCase = osName.toLowerCase(); String windowType; @@ -58,7 +61,9 @@ public abstract class Window { } else { windowType = X11; } - return create(windowType); + Window window = create(windowType); + window.initNative(visualID); + return window; } @@ -82,13 +87,149 @@ public abstract class Window { } } - protected Window() { - } + protected abstract void initNative(long visualID); + public abstract void setVisible(boolean visible); public abstract void setSize(int width, int height); + public abstract void setPosition(int x, int y); + public abstract boolean isVisible(); public abstract int getWidth(); public abstract int getHeight(); + public abstract int getX(); + public abstract int getY(); public abstract boolean setFullscreen(boolean fullscreen); + public abstract boolean isFullscreen(); + public abstract int getDisplayWidth(); + public abstract int getDisplayHeight(); public abstract long getWindowHandle(); public abstract void pumpMessages(); + + // + // MouseListener Support + // + + public synchronized void addMouseListener(MouseListener l) { + if(l == null) { + return; + } + mouseListener.add(l); + } + + public synchronized void removeMouseListener(MouseListener l) { + if (l == null) { + return; + } + mouseListener.remove(l); + } + + public synchronized MouseListener[] getMouseListeners() { + return (MouseListener[]) mouseListener.toArray(); + } + + private ArrayList mouseListener = new ArrayList(); + private long lastMousePressed = 0; + private int lastMouseClickCount = 0; + public static final int ClickTimeout = 200; + + private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) { + long when = System.currentTimeMillis(); + MouseEvent eClicked = null; + MouseEvent e = null; + + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { + if(when-lastMousePressed<ClickTimeout) { + lastMouseClickCount++; + } else { + lastMouseClickCount=1; + } + lastMousePressed=when; + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, lastMouseClickCount, button); + } else if(MouseEvent.EVENT_MOUSE_RELEASED==eventType) { + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, lastMouseClickCount, button); + if(when-lastMousePressed<ClickTimeout) { + eClicked = new MouseEvent(true, MouseEvent.EVENT_MOUSE_CLICKED, this, when, + modifiers, x, y, lastMouseClickCount, button); + } + lastMouseClickCount=0; + lastMousePressed=0; + } else if(MouseEvent.EVENT_MOUSE_MOVED==eventType && + 1==lastMouseClickCount) { + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, 1, button); + } else { + e = new MouseEvent(true, eventType, this, when, + modifiers, x, y, 0, button); + } + + for(Iterator i = mouseListener.iterator(); i.hasNext(); ) { + switch(eventType) { + case MouseEvent.EVENT_MOUSE_ENTERED: + ((MouseListener)i.next()).mouseEntered(e); + break; + case MouseEvent.EVENT_MOUSE_EXITED: + ((MouseListener)i.next()).mouseExited(e); + break; + case MouseEvent.EVENT_MOUSE_PRESSED: + ((MouseListener)i.next()).mousePressed(e); + break; + case MouseEvent.EVENT_MOUSE_RELEASED: + ((MouseListener)i.next()).mouseReleased(e); + if(null!=eClicked) { + ((MouseListener)i.next()).mouseClicked(eClicked); + } + break; + case MouseEvent.EVENT_MOUSE_MOVED: + ((MouseListener)i.next()).mouseMoved(e); + break; + case MouseEvent.EVENT_MOUSE_DRAGGED: + ((MouseListener)i.next()).mouseDragged(e); + break; + } + } + } + + // + // KeyListener Support + // + + public synchronized void addKeyListener(KeyListener l) { + if(l == null) { + return; + } + keyListener.add(l); + } + + public synchronized void removeKeyListener(KeyListener l) { + if (l == null) { + return; + } + keyListener.remove(l); + } + + public synchronized KeyListener[] getKeyListeners() { + return (KeyListener[]) keyListener.toArray(); + } + + private ArrayList keyListener = new ArrayList(); + + private void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(), + modifiers, keyCode, keyChar); + for(Iterator i = keyListener.iterator(); i.hasNext(); ) { + switch(eventType) { + case KeyEvent.EVENT_KEY_PRESSED: + ((KeyListener)i.next()).keyPressed(e); + break; + case KeyEvent.EVENT_KEY_RELEASED: + ((KeyListener)i.next()).keyReleased(e); + break; + case KeyEvent.EVENT_KEY_TYPED: + ((KeyListener)i.next()).keyTyped(e); + break; + } + } + } } + |