| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.lbl; |
| 18 |
|
| 19 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 20 |
import uk.me.parabola.imgfmt.app.Label; |
| 21 |
import uk.me.parabola.imgfmt.app.trergn.Subdivision; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class City { |
| 30 |
private static final int POINT_REF = 0x8000; |
| 31 |
private static final int REGION_IS_COUNTRY = 0x4000; |
| 32 |
|
| 33 |
private int index = -1; |
| 34 |
|
| 35 |
private final Region region; |
| 36 |
private final Country country; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
private boolean pointRef; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
private Subdivision subdivision; |
| 45 |
private int pointIndex; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private Label label; |
| 51 |
|
| 52 |
public City(Region region) { |
| 53 |
this.region = region; |
| 54 |
this.country = null; |
| 55 |
} |
| 56 |
|
| 57 |
public City(Country country) { |
| 58 |
this.country = country; |
| 59 |
this.region = null; |
| 60 |
} |
| 61 |
|
| 62 |
void write(ImgFileWriter writer) { |
| 63 |
if (pointRef) { |
| 64 |
writer.put1u(pointIndex); |
| 65 |
writer.put2u(subdivision.getNumber()); |
| 66 |
} else { |
| 67 |
writer.put3u(label.getOffset()); |
| 68 |
} |
| 69 |
|
| 70 |
int info; |
| 71 |
if(region != null) |
| 72 |
info = region.getIndex() & 0x3fff; |
| 73 |
else |
| 74 |
info = REGION_IS_COUNTRY | (country.getIndex() & 0x3fff); |
| 75 |
if (pointRef) |
| 76 |
info |= POINT_REF; |
| 77 |
|
| 78 |
writer.put2u(info); |
| 79 |
} |
| 80 |
|
| 81 |
public int getIndex() { |
| 82 |
if (index == -1) |
| 83 |
throw new IllegalStateException("Offset not known yet."); |
| 84 |
return index; |
| 85 |
} |
| 86 |
|
| 87 |
public void setIndex(int index) { |
| 88 |
this.index = index; |
| 89 |
} |
| 90 |
|
| 91 |
public void setLabel(Label label) { |
| 92 |
pointRef = false; |
| 93 |
this.label = label; |
| 94 |
} |
| 95 |
|
| 96 |
public void setPointIndex(int pointIndex) { |
| 97 |
pointRef = true; |
| 98 |
this.pointIndex = pointIndex; |
| 99 |
} |
| 100 |
|
| 101 |
public void setSubdivision(Subdivision subdivision) { |
| 102 |
pointRef = true; |
| 103 |
this.subdivision = subdivision; |
| 104 |
} |
| 105 |
|
| 106 |
public String getName() { |
| 107 |
return label == null ? "" : label.getText(); |
| 108 |
} |
| 109 |
|
| 110 |
public int getLblOffset() { |
| 111 |
return label == null ? 0 : label.getOffset(); |
| 112 |
} |
| 113 |
|
| 114 |
public String toString() { |
| 115 |
String result = ""; |
| 116 |
if(label != null) |
| 117 |
result += label.getText(); |
| 118 |
if (subdivision != null) |
| 119 |
result += " " + subdivision.getNumber() + "/" + pointIndex; |
| 120 |
if(country != null) |
| 121 |
result += " in country " + country.getIndex(); |
| 122 |
if(region != null) |
| 123 |
result += " in region " + region.getIndex(); |
| 124 |
|
| 125 |
return result; |
| 126 |
} |
| 127 |
|
| 128 |
public int getSubdivNumber() { |
| 129 |
return subdivision.getNumber(); |
| 130 |
} |
| 131 |
|
| 132 |
public int getPointIndex() { |
| 133 |
return pointIndex; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public int getRegionCountryNumber() { |
| 142 |
if (region == null) { |
| 143 |
if (country != null) |
| 144 |
return country.getIndex() | 0x4000; |
| 145 |
} else { |
| 146 |
return region.getIndex(); |
| 147 |
} |
| 148 |
return 0; |
| 149 |
} |
| 150 |
|
| 151 |
public int getRegionNumber() { |
| 152 |
return region == null? 0: region.getIndex(); |
| 153 |
} |
| 154 |
|
| 155 |
public int getCountryNumber() { |
| 156 |
return country == null ? 0 : country.getIndex(); |
| 157 |
} |
| 158 |
|
| 159 |
public Label getLabel() { |
| 160 |
return label; |
| 161 |
} |
| 162 |
} |