001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io.imagery; 003 004import java.awt.image.BufferedImage; 005 006import org.openstreetmap.josm.data.imagery.GeorefImage.State; 007import org.openstreetmap.josm.gui.layer.WMSLayer.PrecacheTask; 008 009public 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 private WMSException exception; 022 023 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch) { 024 this(xIndex, yIndex, pixelPerDegree, real, allowPartialCacheMatch, null); 025 } 026 027 public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch, PrecacheTask precacheTask) { 028 this.xIndex = xIndex; 029 this.yIndex = yIndex; 030 this.pixelPerDegree = pixelPerDegree; 031 this.real = real; 032 this.precacheTask = precacheTask; 033 this.allowPartialCacheMatch = allowPartialCacheMatch; 034 } 035 036 public void finish(State state, BufferedImage image, WMSException exception) { 037 this.state = state; 038 this.image = image; 039 this.exception = exception; 040 } 041 042 public int getXIndex() { 043 return xIndex; 044 } 045 046 public int getYIndex() { 047 return yIndex; 048 } 049 050 public double getPixelPerDegree() { 051 return pixelPerDegree; 052 } 053 054 @Override 055 public int hashCode() { 056 final int prime = 31; 057 int result = 1; 058 long temp; 059 temp = Double.doubleToLongBits(pixelPerDegree); 060 result = prime * result + (int) (temp ^ (temp >>> 32)); 061 result = prime * result + xIndex; 062 result = prime * result + yIndex; 063 return result; 064 } 065 066 @Override 067 public boolean equals(Object obj) { 068 if (this == obj) 069 return true; 070 if (obj == null) 071 return false; 072 if (getClass() != obj.getClass()) 073 return false; 074 WMSRequest other = (WMSRequest) obj; 075 if (Double.doubleToLongBits(pixelPerDegree) != Double 076 .doubleToLongBits(other.pixelPerDegree)) 077 return false; 078 if (xIndex != other.xIndex) 079 return false; 080 if (yIndex != other.yIndex) 081 return false; 082 if (allowPartialCacheMatch != other.allowPartialCacheMatch) 083 return false; 084 return true; 085 } 086 087 public void setPriority(int priority) { 088 this.priority = priority; 089 } 090 091 public int getPriority() { 092 return priority; 093 } 094 095 @Override 096 public int compareTo(WMSRequest o) { 097 return priority - o.priority; 098 } 099 100 /** 101 * Replies the resulting state. 102 * @return the resulting state 103 */ 104 public State getState() { 105 return state; 106 } 107 108 /** 109 * Replies the resulting image, if any. 110 * @return the resulting image, or {@code null} 111 */ 112 public BufferedImage getImage() { 113 return image; 114 } 115 116 /** 117 * Replies the resulting exception, if any. 118 * @return the resulting exception, or {@code null} 119 * @since 7425 120 */ 121 public WMSException getException() { 122 return exception; 123 } 124 125 @Override 126 public String toString() { 127 return "WMSRequest [xIndex=" + xIndex + ", yIndex=" + yIndex 128 + ", pixelPerDegree=" + pixelPerDegree + "]"; 129 } 130 131 public boolean isReal() { 132 return real; 133 } 134 135 public boolean isPrecacheOnly() { 136 return precacheTask != null; 137 } 138 139 public PrecacheTask getPrecacheTask() { 140 return precacheTask; 141 } 142 143 public boolean isAllowPartialCacheMatch() { 144 return allowPartialCacheMatch; 145 } 146 147 public boolean hasExactMatch() { 148 return hasExactMatch; 149 } 150 151 public void setHasExactMatch(boolean hasExactMatch) { 152 this.hasExactMatch = hasExactMatch; 153 } 154}