001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.activities.parameters; 025 026 import java.awt.Rectangle; 027 import java.util.ArrayList; 028 /** 029 * A geographical location is modelled using this class. There may be one or 030 * more location parameters that have this Location as their value. They are all 031 * notified when the location changes value. 032 * 033 * @author olale 034 * 035 */ 036 public class Location { 037 038 private String name; 039 private Rectangle area = new Rectangle(); 040 041 private ArrayList<LocationParameter> locationParams = new ArrayList<LocationParameter>(); 042 043 public Location(String name,LocationParameter param){ 044 this.name=name; 045 locationParams.add(param); 046 } 047 048 public void addParam(LocationParameter param) { 049 locationParams.add(param); 050 } 051 052 public void removeParam(LocationParameter param) { 053 locationParams.remove(param); 054 } 055 056 public double distanceTo(Location loc) { 057 int dx = loc.getArea().x-area.x; 058 int dy = loc.getArea().y-area.y; 059 return Math.sqrt(dx*dx+dy*dy); 060 } 061 062 /** 063 * @return Returns the area. 064 */ 065 public Rectangle getArea() { 066 return area; 067 } 068 /** 069 * @param area 070 * The area to set. 071 */ 072 public void setArea(Rectangle area) { 073 this.area = area; 074 for (LocationParameter parameter : locationParams) { 075 parameter.valueChanged(); 076 } 077 } 078 /** 079 * @return Returns the name. 080 */ 081 public String getName() { 082 return name; 083 } 084 /** 085 * @param name 086 * The name to set. 087 */ 088 public void setName(String name) { 089 this.name = name; 090 } 091 092 /* 093 * (non-Javadoc) 094 * 095 * @see java.lang.Object#equals(java.lang.Object) 096 */ 097 @Override 098 public boolean equals(Object obj) { 099 boolean eq=false; 100 if (obj instanceof Location) { 101 Location loc = (Location) obj; 102 eq=loc.toString().equals(toString()); 103 } 104 return eq; 105 } 106 107 /* 108 * (non-Javadoc) 109 * 110 * @see java.lang.Object#toString() 111 */ 112 @Override 113 public String toString() { 114 return name; 115 } 116 117 118 119 }