/** * DistancePanel.java * * copyright 2004, Daniel Heller * * latest version may be found at either: * http://www.cs.tufts.edu/~dheller/distanceviewer * or * http://www.dan-is-online.com/software/distanceviewer * * This program is free software; * you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; * either version 2 of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. * See the GNU General Public License * at http://www.gnu.org/copyleft/gpl.html for more details. * **/ import java.awt.Color; import java.awt.Graphics; import java.awt.Point; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JPanel; public class DistancePanel extends JPanel { private Vector points = new Vector(); private int type = 0; private int displayType = 0; private int threshold = 3; public DistancePanel(JFrame viewer) { addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e) { points.addElement(new Point(e.getX(),e.getY())); repaint(); } }); viewer.addKeyListener(new KeyAdapter(){ public void keyPressed(KeyEvent e) { if(e.getKeyChar()=='1') { type = 0; threshold = 3; } if(e.getKeyChar()=='2') { type = 1; threshold = 3; } if(e.getKeyChar()=='3') { type = 2; threshold = 100; } if(e.getKeyChar()=='a') displayType = 0; if(e.getKeyChar()=='b') displayType = 1; repaint(); } }); } public void paintComponent(Graphics g) { Color oldColor = g.getColor(); g.setColor(Color.white); g.fillRect(0,0,getWidth(),getHeight()); g.setColor(oldColor); if(displayType==0) { for(int i=0;i