Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve tests.
[graphlib_java.git] / DrawingWindow.java
index b292dc7..e7766d0 100644 (file)
@@ -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 <a href="http://www.w3.org/TR/SVG/types.html#ColorKeywords">liste des noms de couleurs</a>
      */
     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,7 +406,8 @@ 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;
     }
 
     /**
@@ -413,9 +416,9 @@ public class DrawingWindow {
      * @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);
@@ -429,9 +432,9 @@ public class DrawingWindow {
      * @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);
     }