import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; /** * Drawing words to 2D plane. Selecting words. */ public class OntoPanel extends JPanel{ OntoData od; OntoApp oa; double wcx, wcy, pcx, pcy, koef=1; double freeBorder=30; boolean zoomToBoundsWhileCalculating=true; double gpsmapx1, gpsmapy1, gpsmapx2, gpsmapy2; Image gpsmap; public void paintComponent(Graphics g0){ try{ Graphics2D g=(Graphics2D)g0; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); pcx=getWidth()/2; pcy=getHeight()/2; if(zoomToBoundsWhileCalculating){ if(oa.ol.continousCalculating){ calculateKoef(); } } paintMap(g); paintLines(g); paintWords(g); }catch(Exception e){ e.printStackTrace(); } } void loadGpsMap(String filename, double x1, double y1, double x2, double y2){ gpsmap=loadImage(filename); gpsmapx1=x1; gpsmapy1=y1; gpsmapx2=x2; gpsmapy2=y2; } Image loadImage(String filename){ try{ return oa.getImage(oa.getCodeBase(), filename); }catch(Exception e){} return Toolkit.getDefaultToolkit().getImage(filename); } void paintMap(Graphics2D g){ g.drawImage(gpsmap, px(gpsmapx1), py(gpsmapy1), px(gpsmapx2)-px(gpsmapx1), py(gpsmapy2)-py(gpsmapy1), this); } void paintLines(Graphics2D g){ if(oa.od.gps!=null){ for(int j=1; j5){s=s.substring(0, 5);} g.drawString(s, px(od.coordinates[j][0])-25, py(od.coordinates[j][1])); } } } void calculateKoef(){ if(od.coordinates.length==0){return;} if(od.coordinates.length==1){ wcx=od.coordinates[0][0]; wcy=od.coordinates[0][1]; koef=1; return; } double[] koefm=new double[od.coordinates[0].length]; double tkoefx=0, tkoefy=0; for(int i=0; imax){max=od.coordinates[j][i];} } // min=Math.abs(min); if(i==0){ wcx=(max+min)/2; if(Math.abs(max-wcx)>0.01){ tkoefx=(getWidth()/2-freeBorder)/(max-wcx); } else { tkoefx=1; } } if(i==1){ wcy=(max+min)/2; if(Math.abs(max-wcy)>0.00001){ tkoefy=(getHeight()/2-freeBorder)/(max-wcy); } else { tkoefy=1; } } } koef=Math.min(tkoefx, tkoefy); // if(Math.abs(koef)>100){koef=100;} } int px(double wx){ return (int)(pcx+(wx-wcx)*koef); } int py(double wy){ return (int)(pcy-(wy-wcy)*koef); } double wx(int px){ return wcx+(px-pcx)/koef; } double wy(int py){ return wcy+(pcy-py)/koef; } int getWordNr(int px, int py){ int r=15; for(int j=0; j=x0 && px(od.coordinates[j][0])<=x1 && py(od.coordinates[j][1])>=y0 && py(od.coordinates[j][1])<=y1 ){ numbers.add(new Integer(j)); } } int[] answer=new int[numbers.size()]; for(int i=0; i