source: josm/trunk/src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java@ 2848

Last change on this file since 2848 was 2848, checked in by mjulius, 15 years ago

fix messages for gui/io

File size: 5.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import java.io.File;
5
6import org.openstreetmap.josm.gui.layer.OsmDataLayer;
7import org.openstreetmap.josm.tools.CheckParameterUtil;
8
9import static org.openstreetmap.josm.tools.I18n.tr;
10
11/**
12 * SaveLayerInfo represents the information, user preferences and save/upload states of
13 * a layer which might be uploaded/saved.
14 *
15 */
16class SaveLayerInfo implements Comparable<SaveLayerInfo> {
17
18 /** the osm data layer */
19 private OsmDataLayer layer;
20 private boolean doSaveToFile;
21 private boolean doUploadToServer;
22 private File file;
23 private UploadOrSaveState uploadState;
24 private UploadOrSaveState saveState;
25
26 /**
27 *
28 * @param layer the layer. Must not be null.
29 * @throws IllegalArgumentException thrown if layer is null
30 */
31 public SaveLayerInfo(OsmDataLayer layer) {
32 CheckParameterUtil.ensureParameterNotNull(layer, "layer");
33 this.layer = layer;
34 this.doSaveToFile = layer.requiresSaveToFile();
35 this.doUploadToServer = layer.requiresUploadToServer();
36 this.file = layer.getAssociatedFile();
37 }
38
39 /**
40 * Replies the layer this info objects holds information for
41 *
42 * @return the layer this info objects holds information for
43 */
44 public OsmDataLayer getLayer() {
45 return layer;
46 }
47
48 /**
49 * Replies true if this layer should be saved to a file; false, otherwise
50 *
51 * @return true if this layers should be saved to a file; false, otherwise
52 */
53 public boolean isDoSaveToFile() {
54 return doSaveToFile;
55 }
56
57 /**
58 * Sets whether this layer should be saved to a file
59 *
60 * @param doSaveToFile true to save; false, to skip saving
61 */
62 public void setDoSaveToFile(boolean doSaveToFile) {
63 this.doSaveToFile = doSaveToFile;
64 }
65
66 /**
67 * Replies true if this layer should be uploaded to the server; false, otherwise
68 *
69 * @return true if this layer should be uploaded to the server; false, otherwise
70 */
71 public boolean isDoUploadToServer() {
72 return doUploadToServer;
73 }
74
75 /**
76 * Sets whether this layer should be uploaded to a file
77 *
78 * @param doSaveToFile true to upload; false, to skip uploading
79 */
80
81 public void setDoUploadToServer(boolean doUploadToServer) {
82 this.doUploadToServer = doUploadToServer;
83 }
84
85 /**
86 * Replies true if this layer should be uploaded to the server and saved to file.
87 *
88 * @return true if this layer should be uploaded to the server and saved to file
89 */
90 public boolean isDoSaveAndUpload() {
91 return isDoSaveToFile() && isDoUploadToServer();
92 }
93
94 /**
95 * Replies the name of the layer
96 *
97 * @return the name of the layer
98 */
99 public String getName() {
100 return layer.getName() == null ? "" : layer.getName();
101 }
102
103 /**
104 * Replies the file this layer should be saved to, if {@see #isDoSaveToFile()} is true
105 *
106 * @return the file this layer should be saved to, if {@see #isDoSaveToFile()} is true
107 */
108 public File getFile() {
109 return file;
110 }
111
112 /**
113 * Sets the file this layer should be saved to, if {@see #isDoSaveToFile()} is true
114 *
115 * @param file the file
116 */
117 public void setFile(File file) {
118 this.file = file;
119 }
120
121 public int compareTo(SaveLayerInfo o) {
122 if (isDoSaveAndUpload()) {
123 if (o.isDoSaveAndUpload())
124 return getName().compareTo(o.getName());
125 return -1;
126 } else if (o.isDoSaveAndUpload())
127 return 1;
128 if (isDoUploadToServer()) {
129 if (o.isDoUploadToServer())
130 return getName().compareTo(o.getName());
131 return -1;
132 } else if (o.isDoUploadToServer())
133 return 1;
134 if (isDoSaveToFile()) {
135 if (o.isDoSaveToFile())
136 return getName().compareTo(o.getName());
137 return -1;
138 } else if (o.isDoSaveToFile())
139 return 1;
140 return getName().compareTo(o.getName());
141 }
142
143 /**
144 * Replies the upload state of {@see #getLayer()}.
145 * <ul>
146 * <li>{@see UploadOrSaveState#OK} if {@see #getLayer() was successfully uploaded</li>
147 * <li>{@see UploadOrSaveState#CANCELLED} if uploading {@see #getLayer() was cancelled</li>
148 * <li>{@see UploadOrSaveState#FAILED} if uploading {@see #getLayer() has failed</li>
149 * </ul>
150 *
151 * @return the upload state
152 */
153 public UploadOrSaveState getUploadState() {
154 return uploadState;
155 }
156
157 /**
158 * Sets the upload state for {@see #getLayer()}
159 *
160 * @param uploadState the upload state
161 */
162 public void setUploadState(UploadOrSaveState uploadState) {
163 this.uploadState = uploadState;
164 }
165
166 /**
167 * Replies the save state of {@see #getLayer()}.
168 * <ul>
169 * <li>{@see UploadOrSaveState#OK} if {@see #getLayer() was successfully saved to file</li>
170 * <li>{@see UploadOrSaveState#CANCELLED} if saving {@see #getLayer() was cancelled</li>
171 * <li>{@see UploadOrSaveState#FAILED} if saving {@see #getLayer() has failed</li>
172 * </ul>
173 *
174 * @return the save state
175 */
176 public UploadOrSaveState getSaveState() {
177 return saveState;
178 }
179
180 /**
181 * Sets the save state for {@see #getLayer()}
182 *
183 * @param saveState save the upload state
184 */
185 public void setSaveState(UploadOrSaveState saveState) {
186 this.saveState = saveState;
187 }
188
189 /**
190 * Resets the upload and save state
191 *
192 * @see #setUploadState(UploadOrSaveState)
193 * @see #setSaveState(UploadOrSaveState)
194 * @see #getUploadState()
195 * @see #getSaveState()
196 */
197 public void resetUploadAndSaveState() {
198 this.uploadState = null;
199 this.saveState = null;
200 }
201}
Note: See TracBrowser for help on using the repository browser.