Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix build infrastructure for independent project.
[graphlib_java.git] / DrawingWindow.java
index fe13798..9ec6121 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
 import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Polygon;
+import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
@@ -34,7 +35,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 20141017
+ * @version 20141104
  */
 public class DrawingWindow {
 
@@ -163,7 +164,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 +178,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 +192,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 +212,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 +243,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());
         }
@@ -356,7 +359,9 @@ public class DrawingWindow {
         synchronized (image) {
             graphics.drawPolygon(poly);
         }
-        panel.repaint(poly.getBounds());
+        Rectangle bounds = poly.getBounds();
+        bounds.setSize(bounds.width + 1, bounds.height + 1);
+        panel.repaint(bounds);
     }
 
     /**
@@ -378,6 +383,8 @@ public class DrawingWindow {
             graphics.drawPolygon(poly);
             graphics.fillPolygon(poly);
         }
+        Rectangle bounds = poly.getBounds();
+        bounds.setSize(bounds.width + 1, bounds.height + 1);
         panel.repaint(poly.getBounds());
     }
 
@@ -404,7 +411,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 +421,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 +437,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 +534,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 +550,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 +566,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);
         }
@@ -642,7 +659,6 @@ public class DrawingWindow {
         m.put("lightgray",              new Color(0x00d3d3d3));
         m.put("lightgreen",             new Color(0x0090ee90));
         m.put("lightgrey",              new Color(0x00d3d3d3));
-        m.put("",                       new Color(0000000000));
         m.put("lightpink",              new Color(0x00ffb6c1));
         m.put("lightsalmon",            new Color(0x00ffa07a));
         m.put("lightseagreen",          new Color(0x0020b2aa));