[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/eyes/tools/java/de/tub/eyes/diagram JDiagramViewer.java, 1.5, 1.6

Till Wimmer twimmer at users.sourceforge.net
Mon Apr 24 07:20:09 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/eyes/tools/java/de/tub/eyes/diagram
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2757

Modified Files:
	JDiagramViewer.java 
Log Message:
added zoom handling; changed resize behaviour for srolling ability; get map props from new Map class

Index: JDiagramViewer.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/eyes/tools/java/de/tub/eyes/diagram/JDiagramViewer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** JDiagramViewer.java	11 Jan 2006 14:32:59 -0000	1.5
--- JDiagramViewer.java	24 Apr 2006 14:20:07 -0000	1.6
***************
*** 20,23 ****
--- 20,24 ----
  import de.tub.eyes.gui.customelements.NodeListViewer;
  import de.tub.eyes.components.ConfigComponent;
+ import de.tub.eyes.gis.*;
  
  /**
***************
*** 40,46 ****
      private boolean mouseIsPressed = false;
      private int mapNo = -1;
      private static ConfigComponent cc = Demonstrator.getConfigComponent();
      private static int uartAddr = Integer.parseInt(Demonstrator.getProps().getProperty("uartAddr", "126"));
!     private Image [] maps;
      
      /**
--- 41,64 ----
      private boolean mouseIsPressed = false;
      private int mapNo = -1;
+     private int zoom = 1;
      private static ConfigComponent cc = Demonstrator.getConfigComponent();
      private static int uartAddr = Integer.parseInt(Demonstrator.getProps().getProperty("uartAddr", "126"));
!     private Maps maps;
!     public static final float [] zoomFactor = new float[6];
!     {
!         zoomFactor[0] = 0.75f;         
!         zoomFactor[1] = 1.0f; 
!         zoomFactor[2] = 1.25f; 
!         zoomFactor[3] = 1.5f; 
!         zoomFactor[4] = 1.75f; 
!         zoomFactor[5] = 2.0f;
!     }
!     
!     public static final int DEFAULT_WIDTH = 580;
!     public static final int DEFAULT_HEIGHT = 580;
!     private int baseSizeX=DEFAULT_WIDTH, baseSizeY=DEFAULT_HEIGHT;
!     private int sizeX=baseSizeX, sizeY=baseSizeY;
!     private JScrollPane pane = null;
!     
      
      /**
***************
*** 52,58 ****
          diagram = new Diagram();
          diagram.setViewer(this);        
-         Dimension dim = this.getMinimumSize();
   
!         maps = loadImages();
          
          random = new Random();
--- 70,75 ----
          diagram = new Diagram();
          diagram.setViewer(this);        
   
!         maps = new Maps(Demonstrator.getProps());
          
          random = new Random();
***************
*** 309,317 ****
          }
          
!         if (mapNo > -1 && maps != null && mapNo < maps.length ) {
              Dimension d = getSize();
              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
!             g2.drawImage(maps[mapNo],0,0,(int)d.getWidth(),(int)d.getHeight(),null);
          }
      }
--- 326,337 ----
          }
          
!         if (mapNo > -1 && mapNo < maps.getCnt() ) {
              Dimension d = getSize();
+             int sizeX = (int)(maps.getWidth(mapNo)*zoomFactor[zoom]);
+             int sizeY = (int)(maps.getHeight(mapNo)*zoomFactor[zoom]);
              g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
!             //g2.drawImage(maps[mapNo],0,0,(int)d.getWidth(),(int)d.getHeight(),null);
!             g2.drawImage(maps.getMap(mapNo),0,0,sizeX,sizeY,null);
          }
      }
***************
*** 349,352 ****
--- 369,375 ----
                      if ( n.getId() == uartAddr ) // no coloring for UART
                        continue;
+                     
+                     if ( !n.getVisible())
+                         continue;
                    
                      if (n instanceof NodePS && ((NodePS)n).readingExists(bgAttrib)) {
***************
*** 496,522 ****
      public void setMap(int mapNo) {
          this.mapNo = mapNo;
      }
      
!     private void doResize (double oldWidth, double oldHeight, double newWidth, double newHeight) {
!         if (Math.abs(oldWidth - newWidth) < 10.0 && Math.abs(oldHeight - newHeight) < 10.0)
!             return;
!         diagram.resize(newWidth/oldWidth, newHeight/oldHeight);
!     }
!     
!     private Image[] loadImages() { 
          Properties props = Demonstrator.getProps();
!         int len = Integer.parseInt(props.getProperty("cntRoomMaps", "0"));
!         
!         if ( len == 0)
!             return null;
          
!         Image ar[] = new Image[len];
          
!         for(int i=0;i<len;i++) {
!             String name = props.getProperty("roomMap_"+i);        
!             ar[i] = (new ImageIcon(name)).getImage();
!         }
!    
!         return(ar);
!     }    
  }
--- 519,571 ----
      public void setMap(int mapNo) {
          this.mapNo = mapNo;
+         
+         if (mapNo == -1) {
+             baseSizeX = DEFAULT_WIDTH;
+             baseSizeY = DEFAULT_HEIGHT;
+         }
+         else {
+             baseSizeX = maps.getWidth(mapNo);
+             baseSizeY = maps.getHeight(mapNo);            
+         }
+         sizeX = baseSizeX;
+         sizeY = baseSizeY;
+         
+         float oldX = (float)getWidth();
+         float oldY = (float)getHeight();
+         
+         diagram.resize(baseSizeX/oldX, baseSizeY/oldY);
+         if (pane != null)
+             pane.setViewportView(this); // ugly, but it works!
      }
      
!     public void setZoom(int zoom) {
!         this.zoom = zoom;
          Properties props = Demonstrator.getProps();
!         int newSizeX = (int)(baseSizeX*zoomFactor[zoom]);
!         int newSizeY = (int)(baseSizeY*zoomFactor[zoom]);
!         diagram.resize(newSizeX/(float)sizeX,newSizeY/(float)sizeY);
!         sizeX = newSizeX;
!         sizeY = newSizeY;
          
!         if (pane != null)
!             pane.setViewportView(this); // ugly, but it works!                   
          
!     }
!     
!     private void doResize (double oldWidth, double oldHeight, double newWidth, double newHeight) {
!     //    if (Math.abs(oldWidth - newWidth) < 10.0 && Math.abs(oldHeight - newHeight) < 10.0)
!     //        return;
!     //    diagram.resize(newWidth/oldWidth, newHeight/oldHeight);
!     }
!     
!     public Dimension getPreferredSize() {
!         if (sizeX > -1 && sizeY > -1) 
!             return new Dimension(sizeX,sizeY);
!         else
!             return getSize();
!     }
!     
!     public void setScrollPane(JScrollPane pane) {
!         this.pane = pane;
!     }
  }



More information about the Tinyos-contrib-commits mailing list