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

Last change on this file since 3083 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

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