X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib_java.git/blobdiff_plain/5bb657301359fbd1d141b15cb68d2e9adb9bf617..df5920b2b548f1887c85a41ebc0ef87b2bd42372:/DrawingWindow.java diff --git a/DrawingWindow.java b/DrawingWindow.java index 9fb03b5..e7766d0 100644 --- a/DrawingWindow.java +++ b/DrawingWindow.java @@ -34,7 +34,7 @@ import javax.swing.JPanel; * possible de fermer la fenêtre via le gestionnaire de fenêtres. * * @author Arnaud Giersch <arnaud.giersch@univ-fcomte.fr> - * @version 20141014 + * @version 20141021b */ public class DrawingWindow { @@ -163,7 +163,7 @@ public class DrawingWindow { * @see #setBgColor(String) * @see #setBgColor(float, float, float) * @see #setColor(Color) - * @see #clearGraph() + * @see #clearGraph */ public void setBgColor(Color color) { bgColor = color; @@ -177,7 +177,7 @@ public class DrawingWindow { * @see #setBgColor(float, float, float) * @see #setColor(int) * @see #getPointColor - * @see #clearGraph() + * @see #clearGraph */ public void setBgColor(int rgb) { setBgColor(new Color(rgb)); @@ -191,7 +191,7 @@ public class DrawingWindow { * @see #setBgColor(int) * @see #setBgColor(float, float, float) * @see #setColor(String) - * @see #clearGraph() + * @see #clearGraph * @see liste des noms de couleurs */ public void setBgColor(String name) { @@ -211,7 +211,7 @@ public class DrawingWindow { * @see #setBgColor(int) * @see #setBgColor(String) * @see #setColor(float, float, float) - * @see #clearGraph() + * @see #clearGraph */ public void setBgColor(float red, float green, float blue) { setBgColor(new Color(red, green, blue)); @@ -242,6 +242,8 @@ public class DrawingWindow { * @see #setColor */ public void drawPoint(int x, int y) { + if (x < 0 || y < 0 || x >= width || y >= height) + return; synchronized (image) { image.setRGB(x, y, graphics.getColor().getRGB()); } @@ -404,18 +406,19 @@ public class DrawingWindow { * @see #setBgColor(int) */ public int getPointColor(int x, int y) { - return image.getRGB(x, y); + return (x < 0 || y < 0 || x >= width || y >= height) ? + 0 : image.getRGB(x, y) & 0x00ffffff; } /** * Attend l'appui sur un des boutons de la souris. * - * @return #true si un bouton a été pressé + * @return vrai (true) si un bouton a été pressé * * @see #waitMousePress(long) - * @see #getMouseX() - * @see #getMouseY() - * @see #getMouseButton() + * @see #getMouseX + * @see #getMouseY + * @see #getMouseButton */ public boolean waitMousePress() { return waitMousePress(-1); @@ -426,12 +429,12 @@ public class DrawingWindow { * * @param timeout temps maximal d'attente (millisecondes) * - * @return #true si un bouton a été pressé + * @return vrai (true) si un bouton a été pressé * * @see #waitMousePress() - * @see #getMouseX() - * @see #getMouseY() - * @see #getMouseButton() + * @see #getMouseX + * @see #getMouseY + * @see #getMouseButton */ public boolean waitMousePress(long timeout) { boolean result = false; @@ -526,8 +529,11 @@ public class DrawingWindow { * Suspend l'exécution pendant un certain temps. * * @param secs temps d'attente en seconde + * + * @see #msleep + * @see #usleep */ - static void sleep(long secs) { + public static void sleep(long secs) { try { Thread.sleep(secs * 1000); } @@ -539,8 +545,11 @@ public class DrawingWindow { * Suspend l'exécution pendant un certain temps. * * @param msecs temps d'attente en millisecondes + * + * @see #sleep + * @see #usleep */ - static void msleep(long msecs) { + public static void msleep(long msecs) { try { Thread.sleep(msecs); } @@ -552,8 +561,11 @@ public class DrawingWindow { * Suspend l'exécution pendant un certain temps. * * @param usecs temps d'attente en microsecondes + * + * @see #sleep + * @see #msleep */ - static void usleep(long usecs) { + public static void usleep(long usecs) { try { Thread.sleep(usecs / 1000, (int)(usecs % 1000) * 1000); } @@ -743,7 +755,7 @@ public class DrawingWindow { frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new DWWindowHandler()); frame.addKeyListener(new DWKeyHandler()); - frame.addMouseListener(new DWMouseHandler()); + panel.addMouseListener(new DWMouseHandler()); frame.setLocationByPlatform(true); frame.setVisible(true); }