001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.io.imagery; 003 004 import java.awt.image.BufferedImage; 005 006 import org.openstreetmap.josm.data.imagery.GeorefImage.State; 007 import org.openstreetmap.josm.gui.layer.WMSLayer.PrecacheTask; 008 009 public class WMSRequest implements Comparable<WMSRequest> { 010 private final int xIndex; 011 private final int yIndex; 012 private final double pixelPerDegree; 013 private final boolean real; // Download even if autodownloading is disabled 014 private final PrecacheTask precacheTask; // Download even when wms tile is not currently visible (precache) 015 private final boolean allowPartialCacheMatch; 016 private int priority; 017 private boolean hasExactMatch; 018 // Result 019 private State state; 020 private BufferedImage image; 021 022 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch) { 023 this(xIndex, yIndex, pixelPerDegree, real, allowPartialCacheMatch, null); 024 } 025 026 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch, PrecacheTask precacheTask) { 027 this.xIndex = xIndex; 028 this.yIndex = yIndex; 029 this.pixelPerDegree = pixelPerDegree; 030 this.real = real; 031 this.precacheTask = precacheTask; 032 this.allowPartialCacheMatch = allowPartialCacheMatch; 033 } 034 035 036 public void finish(State state, BufferedImage image) { 037 this.state = state; 038 this.image = image; 039 } 040 041 public int getXIndex() { 042 return xIndex; 043 } 044 045 public int getYIndex() { 046 return yIndex; 047 } 048 049 public double getPixelPerDegree() { 050 return pixelPerDegree; 051 } 052 053 @Override 054 public int hashCode() { 055 final int prime = 31; 056 int result = 1; 057 long temp; 058 temp = Double.doubleToLongBits(pixelPerDegree); 059 result = prime * result + (int) (temp ^ (temp >>> 32)); 060 result = prime * result + xIndex; 061 result = prime * result + yIndex; 062 return result; 063 } 064 065 @Override 066 public boolean equals(Object obj) { 067 if (this == obj) 068 return true; 069 if (obj == null) 070 return false; 071 if (getClass() != obj.getClass()) 072 return false; 073 WMSRequest other = (WMSRequest) obj; 074 if (Double.doubleToLongBits(pixelPerDegree) != Double 075 .doubleToLongBits(other.pixelPerDegree)) 076 return false; 077 if (xIndex != other.xIndex) 078 return false; 079 if (yIndex != other.yIndex) 080 return false; 081 if (allowPartialCacheMatch != other.allowPartialCacheMatch) 082 return false; 083 return true; 084 } 085 086 public void setPriority(int priority) { 087 this.priority = priority; 088 } 089 090 public int getPriority() { 091 return priority; 092 } 093 094 @Override 095 public int compareTo(WMSRequest o) { 096 return priority - o.priority; 097 } 098 099 public State getState() { 100 return state; 101 } 102 103 public BufferedImage getImage() { 104 return image; 105 } 106 107 @Override 108 public String toString() { 109 return "WMSRequest [xIndex=" + xIndex + ", yIndex=" + yIndex 110 + ", pixelPerDegree=" + pixelPerDegree + "]"; 111 } 112 113 public boolean isReal() { 114 return real; 115 } 116 117 public boolean isPrecacheOnly() { 118 return precacheTask != null; 119 } 120 121 public PrecacheTask getPrecacheTask() { 122 return precacheTask; 123 } 124 125 public boolean isAllowPartialCacheMatch() { 126 return allowPartialCacheMatch; 127 } 128 129 public boolean hasExactMatch() { 130 return hasExactMatch; 131 } 132 133 public void setHasExactMatch(boolean hasExactMatch) { 134 this.hasExactMatch = hasExactMatch; 135 } 136 }