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

Last change on this file since 2512 was 2512, checked in by stoecker, 15 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

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