From 73aaf4bdb7323cc6681de45f44284af9d71579cb Mon Sep 17 00:00:00 2001 From: adamhutchings Date: Tue, 25 Aug 2020 10:30:20 -0700 Subject: [PATCH 1/2] Move mouse to Render and key to Input --- src/org/qme/vis/QInputScreen.java | 80 +---------------------------- src/org/qme/vis/QRenderScreen.java | 82 +++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 80 deletions(-) diff --git a/src/org/qme/vis/QInputScreen.java b/src/org/qme/vis/QInputScreen.java index 02a69214..ee3624d7 100644 --- a/src/org/qme/vis/QInputScreen.java +++ b/src/org/qme/vis/QInputScreen.java @@ -4,8 +4,6 @@ import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.ConcurrentModificationException; import javax.swing.JFrame; @@ -22,7 +20,7 @@ * @see org.qme.vis.QRenderScreen */ @SuppressWarnings("serial") -public class QInputScreen extends JFrame implements KeyListener, MouseListener { +public class QInputScreen extends JFrame implements KeyListener { QApplication app; @@ -73,79 +71,12 @@ public QInputScreen(QApplication qa) { setVisible(true); pack(); super.setDefaultCloseOperation(EXIT_ON_CLOSE); - addMouseListener(this); addKeyListener(this); xOffset = 0; yOffset = 0; setResizable(false); app = qa; } - - @Override - /** - * This method dispatches click events to all the - * UIComponent objects. - * @author adamhutchings - * @since pre0 - */ - public void mousePressed(MouseEvent e) { - - UIComponent uc; // For internal use - Point p; // same as above - - try { - - for (QObject qo : a.objects) { - if (qo instanceof UIComponent && qo.active) { - - uc = (UIComponent) qo; - - p = app.qrscreen.getMousePosition(); - - if (uc.clickIsIn( - p.x, p.y - )) { - qo.clicked = true; - uc.mouseClickOn(); - } - - } - } - } catch (ConcurrentModificationException cme) {} - - } - - @Override - /** - * This method dispatches click events to all the - * UIComponent objects. - * @author adamhutchings - * @since pre0 - */ - public void mouseReleased(MouseEvent e) { - - UIComponent uc; // For internal use - - try { - - for (QObject qo : a.objects) { - if (qo instanceof UIComponent && qo.active) { - - uc = (UIComponent) qo; - - if (qo.clicked) { - qo.clicked = false; - uc.mouseClickOff(); - } - - } - } - - } catch (ConcurrentModificationException cme) { - - } - - } /** * This method dispatches hovers to all the @@ -233,15 +164,6 @@ public void keyPressed(KeyEvent e) { // Useless stub methods - @Override - public void mouseClicked(MouseEvent e) {} - - @Override - public void mouseEntered(MouseEvent e) {} - - @Override - public void mouseExited(MouseEvent e) {} - @Override public void keyTyped(KeyEvent e) {} diff --git a/src/org/qme/vis/QRenderScreen.java b/src/org/qme/vis/QRenderScreen.java index f93a2279..cfb13b4d 100644 --- a/src/org/qme/vis/QRenderScreen.java +++ b/src/org/qme/vis/QRenderScreen.java @@ -2,11 +2,16 @@ import java.awt.Color; import java.awt.Graphics; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ConcurrentModificationException; import javax.swing.JPanel; import org.qme.main.QApplication; import org.qme.main.QObject; +import org.qme.vis.ui.UIComponent; /** * This represents where objects get drawn onto @@ -16,7 +21,7 @@ * @see org.qme.main.QApplication */ @SuppressWarnings("serial") -public class QRenderScreen extends JPanel { +public class QRenderScreen extends JPanel implements MouseListener { /** * The "owner" of this object. @@ -31,6 +36,7 @@ public class QRenderScreen extends JPanel { */ public QRenderScreen(QApplication a) { app = a; + addMouseListener(this); } /** @@ -54,5 +60,79 @@ public void paint(Graphics g) { } } + + @Override + /** + * This method dispatches click events to all the + * UIComponent objects. + * @author adamhutchings + * @since pre0 + */ + public void mousePressed(MouseEvent e) { + + UIComponent uc; // For internal use + + try { + + for (QObject qo : app.objects) { + if (qo instanceof UIComponent && qo.active) { + + uc = (UIComponent) qo; + + if (uc.clickIsIn( + e.getX(), e.getY() + )) { + qo.clicked = true; + uc.mouseClickOn(); + } + + } + } + } catch (ConcurrentModificationException cme) {} + + } + + @Override + /** + * This method dispatches click events to all the + * UIComponent objects. + * @author adamhutchings + * @since pre0 + */ + public void mouseReleased(MouseEvent e) { + + UIComponent uc; // For internal use + + try { + + for (QObject qo : app.objects) { + if (qo instanceof UIComponent && qo.active) { + + uc = (UIComponent) qo; + + if (qo.clicked) { + qo.clicked = false; + uc.mouseClickOff(); + } + + } + } + + } catch (ConcurrentModificationException cme) { + + } + + } + + // Useless stub methods + + @Override + public void mouseClicked(MouseEvent e) {} + + @Override + public void mouseEntered(MouseEvent e) {} + + @Override + public void mouseExited(MouseEvent e) {} } From 344bea3f669e0f54e655c4a75bacaa1b8824fc0c Mon Sep 17 00:00:00 2001 From: adamhutchings Date: Tue, 25 Aug 2020 10:32:06 -0700 Subject: [PATCH 2/2] Remove unused import --- src/org/qme/vis/QRenderScreen.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/qme/vis/QRenderScreen.java b/src/org/qme/vis/QRenderScreen.java index cfb13b4d..abebc191 100644 --- a/src/org/qme/vis/QRenderScreen.java +++ b/src/org/qme/vis/QRenderScreen.java @@ -2,7 +2,6 @@ import java.awt.Color; import java.awt.Graphics; -import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ConcurrentModificationException;