checkpoint
[anneal.git] / src / edu / berkeley / qfat / InteractiveMeshViewer.java
index e024d04..d162677 100644 (file)
@@ -11,36 +11,53 @@ import java.util.*;
 import edu.berkeley.qfat.geom.*;
 import edu.berkeley.qfat.geom.Point;
 
-public class InteractiveMeshViewer extends JPanel {
+public class InteractiveMeshViewer extends JPanel implements KeyListener {
 
     public Mesh tile;
     public Mesh goal;
 
-    private MeshViewer mv;
+    private HashSet<MeshViewer> mvs = new HashSet<MeshViewer>();
 
     public InteractiveMeshViewer(JFrame f) {
-        mv = new MeshViewer();
-        setLayout(new BorderLayout());
-        this.add(mv, BorderLayout.CENTER);
+        MeshViewer mv1 = new MeshViewer();
+        MeshViewer mv2 = new MeshViewer();
+        MeshViewer mv3 = new MeshViewer();
+        MeshViewer mv4 = new MeshViewer();
+        mvs.add(mv1);
+        mvs.add(mv2);
+        mvs.add(mv3);
+        mvs.add(mv4);
+        addKeyListener(this);
+        mv1.addKeyListener(this);
+        mv2.addKeyListener(this);
+        mv3.addKeyListener(this);
+        mv4.addKeyListener(this);
+        setLayout(new GridLayout(2,2));
+        this.add(mv1);
+        this.add(mv2);
+        this.add(mv3);
+        this.add(mv4);
         setTile(new Mesh(false));
         setGoal(new Mesh(false));
     }
     public void repaint() {
-        if (mv != null) mv.repaint();
+        if (mvs != null)
+            for(MeshViewer mv : mvs)
+                mv.repaint();
     }
 
 
     public void setTile(Mesh tile) {
-        mv.removeMesh(this.tile);
+        for(MeshViewer mv : mvs) mv.removeMesh(this.tile);
         this.tile = tile;
-        mv.addMesh(this.tile);
+        for(MeshViewer mv : mvs) mv.addMesh(this.tile);
     }
     public void setGoal(Mesh goal) {
-        mv.removeMesh(this.goal);
+        for(MeshViewer mv : mvs) mv.removeMesh(this.goal);
         this.goal = goal;
         goal.option_selectable = false;
         goal.option_wireframe = true;
-        mv.addMesh(this.goal);
+        for(MeshViewer mv : mvs) mv.addMesh(this.goal);
     }
 
     public synchronized void dump() {
@@ -83,10 +100,16 @@ public class InteractiveMeshViewer extends JPanel {
     public int accepts;
     public    int vertss;
 
+    public void keyTyped(KeyEvent e)  { }
+    public void keyReleased(KeyEvent e) { }
     public void keyPressed(KeyEvent e)  {
         //super.keyPressed(e);
         switch(e.getKeyCode()) {
-            case KeyEvent.VK_SPACE: breaks++; force = true; break;
+            case KeyEvent.VK_SPACE:
+                synchronized(this) {
+                    tile.subdivide();
+                }
+                //case KeyEvent.VK_SPACE: breaks++; force = true; break;
             case KeyEvent.VK_UP: temp = temp * 2; break;
             case KeyEvent.VK_ENTER: temp = 10; break;
             case KeyEvent.VK_LEFT: whichNeighbor--; break;