/* * NudgeNavigate.java * * Created on November 15, 2001, 2:01 PM */ package uk.ac.leeds.ccg.widgets; import java.awt.*; import uk.ac.leeds.ccg.geotools.*; /** * * @author jamesm */ public class NudgeNavigate extends java.awt.Panel { Viewer view; Image inIcon = null; Image outIcon = null; /** Creates new form NudgeNavigate */ public NudgeNavigate(Viewer v) { initComponents(); view = v; } public NudgeNavigate(Viewer v,Image in,Image out) { initComponents(); view = v; inIcon = in; outIcon = out; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents setLayout(new java.awt.GridBagLayout()); java.awt.GridBagConstraints gridBagConstraints1; addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { clicked(evt); } }); }//GEN-END:initComponents public static final int NW=0,N=1,NE=2,OUT=3,W=10,C=11,E=12,BLANK=13,SW=20,S=21,SE=22,IN=23; private void clicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clicked int x = evt.getX(); int y= evt.getY(); int w = Math.min(getBounds().width,getBounds().height); int col = x/(w/4); int row = y/(w/3); System.out.println("["+col+":"+row+"]"); int id = col+10*row; double oldPercent = view.getZoomAsPercent(); GeoRectangle oldBounds = view.scale.getMapExtent(); GeoPoint center = new GeoPoint(oldBounds.x+oldBounds.width/2,oldBounds.y+oldBounds.height/2); switch(id){ case NW: System.out.println("North West"); center.y+=oldBounds.height/3d; center.x-=oldBounds.width/3d; break; case N: System.out.println("North"); center.y+=oldBounds.height/3d; break; case NE: System.out.println("North East"); center.y+=oldBounds.height/3d; center.x+=oldBounds.width/3d; break; case W: System.out.println("West"); center.x-=oldBounds.width/3d; break; case E: System.out.println("East"); center.x+=oldBounds.width/3d; break; case SW: System.out.println("South West"); center.y-=oldBounds.height/3d; center.x-=oldBounds.width/3d; break; case S: System.out.println("South"); center.y-=oldBounds.height/3d; break; case SE: System.out.println("South East"); center.y-=oldBounds.height/3d; center.x+=oldBounds.width/3d; break; case IN: System.out.println("Zoom In"); view.zoomPercent(oldPercent+oldPercent/2d); break; case OUT: System.out.println("Zoom Out"); view.zoomPercent(oldPercent-oldPercent/2d); break; default: System.out.println("Null"); } view.centerOnPoint(center); }//GEN-LAST:event_clicked public void paint(Graphics g){ int w = this.getSize().width; int h = this.getSize().height; w = Math.min(w,h); h = Math.min(w,h); int wgap = w/4; int hgap = h/3; int step = 0; g.drawRect(0,0,w,h); for(int i=1;i<5;i++){ g.drawLine(wgap*i,0,wgap*i,h); } for(int i=1;i<4;i++){ g.drawLine(0,hgap*i,w,hgap*i); //this.drawArrow(g,wgap*(i-1)+wgap/2,100,i,100); //this.drawArrow(g,wgap*(i-1)+wgap/2,400,i+4,100); } drawArrow(g,wgap/2,hgap/2,3,wgap);//nw drawArrow(g,wgap+wgap/2,hgap/2,4,wgap);//n drawArrow(g,wgap*2+wgap/2,hgap/2,5,wgap);//ne drawArrow(g,wgap/2,hgap/2+hgap,2,wgap);//w drawArrow(g,wgap*2+wgap/2,hgap/2+hgap,6,wgap);//e drawArrow(g,wgap/2,hgap*2+hgap/2,1,wgap);//sw drawArrow(g,wgap+wgap/2,hgap*2+hgap/2,8,wgap);//s drawArrow(g,wgap*2+wgap/2,hgap*2+hgap/2,7,wgap);//se if(inIcon !=null && outIcon!=null){ g.drawImage(outIcon,wgap*3+1,1,wgap-2,hgap-2,null); g.drawImage(inIcon,wgap*3+1,hgap*2+1,wgap-2,hgap-2,null); } } public Dimension getPreferredSize(){ return new Dimension(60,40); } public void drawArrow(Graphics g,int x,int y,int step,int size){ size=size/2; double xp[] = {0,-.57,.57,0}; double yp[] = {.66,-0.33,-.33,.66}; //System.out.println(Math.cos(Math.PI/4))); int xi[] = new int[4]; int yi[] = new int[4]; double change = Math.cos(Math.PI/4d); for(int i=0;i<4;i++){ for(int j=0;j