/* Copyright (c) 2008, University of Southampton All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of Southampton nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.applet.Applet; import java.awt.*; import java.util.*; public class rhotspotV2 extends Applet { public rhotspotV2() { border = 20; nopaint = -100; fontname = "TimesRoman"; fontsize = 12; } void drawimagemarkeratpoint(Graphics g, Point point, Image image, Dimension dimension) { Point point1 = new Point(point.x - dimension.width / 2, point.y - dimension.height / 2); g.drawImage(image, point1.x, point1.y, this); } public Vector getValues(String name) { String s = readpoints(name); String[] points = s.split(":"); Vector values = new Vector(); // fill vector with tokenized string content for(int i=0; i identifiers = new Vector(); if(markerType.equals("LABELS")) { String interactions = getParameter("interactions"); String[] tmpTokens = interactions.split("::"); // add tokenized interaction names to the vector for(int i=0; i 5) { if(m % 2 == 0) i = startLine - 10; else i = startLine + 10; } else { i = startLine; } // offset the label according to label/interaction row theseLocations[m] = new Point(space * (m + 1), borderLine + i + (spacing * t)); } markerLocation.put(intTokens[t], theseLocations); } } else { for(int j = 0; j < noOfMarkers; j++) { int i; // set the marker's initial positions correctly if(noOfMarkers > 5) { if(j % 2 == 0) i = startLine - 10; else i = startLine + 10; } else { i = startLine; } markerLocations[j] = new Point(space * (j + 1), borderLine + i + spacing); } } } } public boolean mouseDown(Event event, int i, int j) { if(isInfinite) { for(int k = 0; k < markerLocationPoints.size(); k++) { Point point = (Point)markerLocationPoints.elementAt(k); Dimension dimension = currentMarkerSize; movetargettopoint(point, dimension, targetrect); if(targetrect.contains(i, j)) { pickedup = true; currentIndex = k; break; } pickedup = false; } } else { if(markerType.equals("LABELS")) { // for each interaction... for(int t=0; t getSize().width) k = getSize().width - 5; if(i < 0) k = 5; if(j > getSize().height) l = getSize().height - 5; if(j < 0) l = 5; if(isInfinite) { Point point = new Point(k, l); markerLocationPoints.set(currentIndex, point); } else { // update the marker's position if(markerType.equals("LABELS")) { Point[] locations = (Point[])markerLocation.get(intTokens[currentInteraction]); locations[currentIndex].x = k; locations[currentIndex].y = l; markerLocation.put(intTokens[currentInteraction], locations); } else { markerLocations[currentIndex].x = k; markerLocations[currentIndex].y = l; } } repaint(); } return true; } public boolean mouseUp(Event event, int i, int j) { if(!feedback) { Vector values; // display the current interaction's coordinates in the status bar if(markerType.equals("LABELS")) { values = getValues(intTokens[currentInteraction]); String tmp = (String)values.elementAt(0); for(int k=1; k borderLine) { locations[currentIndex].y = borderLine + startLine + (spacing * currentInteraction); markerLocation.put(intTokens[currentInteraction], locations); } } else { if(!isInfinite) { if(markerLocations[currentIndex].y > borderLine) markerLocations[currentIndex].y = startLine; } } // respawn a new point if using an infinite amount if(isInfinite) { if(currentIndex == markerLocationPoints.size()-1) { if(((Point)markerLocationPoints.elementAt(currentIndex)).y <= borderLine) { Point newPoint = new Point(space, startLine); markerLocationPoints.add(newPoint); } // if the last point to be moved is below the line, just reset it // instead of making a new marker else { ((Point)markerLocationPoints.elementAt(currentIndex)).setLocation(space, startLine); } } else { if(((Point)markerLocationPoints.elementAt(currentIndex)).y > borderLine) { int oldX = ((Point)markerLocationPoints.elementAt(currentIndex)).x; ((Point)markerLocationPoints.elementAt(currentIndex)).setLocation(oldX, startLine); } } } repaint(); return true; } void movetargettopoint(Point point, Dimension dimension, Rectangle rectangle) { rectangle.setSize(dimension.width, dimension.height); Point point1 = new Point(point.x - dimension.width / 2, point.y - dimension.height / 2); rectangle.setLocation(point1.x, point1.y); } public void paint(Graphics g) { try { offScreenG.setColor(getBackground()); offScreenG.fillRect(0, 0, getSize().width, getSize().height); offScreenG.setColor(getForeground()); int i = getSize().width; int j = getSize().height; for(int k1 = 1; k1 < noOfImages + 1; k1++) { String s = Imagedetails[k1]; String[] tokens = s.split("::"); String s1 = tokens[0]; String s3 = tokens[1]; String s4 = tokens[2]; String s5 = tokens[3]; String s6 = tokens[4]; borderLine = Integer.parseInt(s6); int k; if(s3.length() == 0) k = 0; else k = Integer.parseInt(s3); int l; if(s4.length() == 0) l = 0; else l = Integer.parseInt(s4); int i1; if(s5.length() == 0) i1 = 0; else i1 = Integer.parseInt(s5); int j1; if(s6.length() == 0) j1 = 0; else j1 = Integer.parseInt(s6); Image image = getImage(getCodeBase(), s1); if(i1 == 0) i1 = image.getWidth(this); if(j1 == 0) j1 = image.getHeight(this); offScreenG.drawImage(image, k, l, i1, j1, this); } if(markerType.equals("STANDARD")) { currentMarkerSize = new Dimension(defaultMarkerPic.getWidth(this), defaultMarkerPic.getHeight(this)); if(isInfinite) { for(int l1 = 0; l1 < markerLocationPoints.size(); l1++) drawimagemarkeratpoint(offScreenG, (Point)markerLocationPoints.elementAt(l1), defaultMarkerPic, currentMarkerSize); } else { for(int l1 = 0; l1 < noOfMarkers; l1++) drawimagemarkeratpoint(offScreenG, markerLocations[l1], defaultMarkerPic, currentMarkerSize); } } if(markerType.equals("LABELS")) { // for each interaction... for(int t=0; t borderLine && returnString != "") returnString = returnString.substring(1); } else { Point point = markerLocations[0]; if(point.y <= borderLine) returnString = String.valueOf(point.x + " " + point.y); for(int i = 1; i < markerLocations.length; i++) { point = markerLocations[i]; if(point.y <= borderLine) returnString = returnString + ":" + String.valueOf(point.x + " " + point.y); } // trim the leading colon if the first value is not to be returned if(markerLocations[0].y > borderLine && returnString != "") returnString = returnString.substring(1); } } else { // find the maximum number of matches String currentInt = name; int matchMax = Integer.parseInt(getParameter("maxChoices:" + currentInt)); Point[] theseLocations = (Point[])markerLocation.get(currentInt); if(theseLocations[0].y <= borderLine) returnString = String.valueOf(theseLocations[0].x) + " " + String.valueOf(theseLocations[0].y); // for each label in the current interaction... for(int m=1; m borderLine && returnString != "") returnString = returnString.substring(1); } return returnString; } public void update(Graphics g) { paint(g); } // instance variables // check for infinite number of points boolean isInfinite; // marker locations in finite select point interaction Point markerLocations[]; // marker locations for position object interaction HashMap markerLocation; // marker locations for infinite select point interaction Vector markerLocationPoints; Rectangle targetrect; Rectangle targetAreas[]; int noOfMarkers; int noOfTargets; int noOfImages; String Imagedetails[]; String targetNames[]; String markerTexts[]; // used to store parameters in position object interaction HashMap markerLabels; HashMap markerPicNames; HashMap markerIDs; HashMap markerTypes; HashMap markermatchMaxs; HashMap markerSizes; HashMap markerPic; Dimension textMarkerSize; Dimension currentMarkerSize; Image defaultMarkerPic; // names of interactions in position object interactions String intTokens[]; String testImage; Image mainPic[]; Image offScreenImg; Graphics offScreenG; String problem; boolean bug; String feedbackInfo; String baseType; String markerType; String settingstr; String valuestr; boolean feedback; boolean pickedup; boolean targetsIdentified; // data about currently-selected object int currentInteraction; int currentIndex; int startLine; int border; int borderLine; int spacing; int space; int nopaint; Font f; String fontname; int fontsize; int strlen; int fontht; int fontdesc; int fontasc; FontMetrics fmetrics; }