Revision 40984 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/actions/CopyPasteLayersUtils.java
CopyPasteLayersUtils.java | ||
---|---|---|
37 | 37 |
import org.slf4j.LoggerFactory; |
38 | 38 |
|
39 | 39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.PluginsLocator; |
|
40 | 41 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
41 | 42 |
import org.gvsig.app.extension.ProjectExtension; |
42 | 43 |
import org.gvsig.app.project.Project; |
... | ... | |
69 | 70 |
* The file which is used to save the layers |
70 | 71 |
*/ |
71 | 72 |
private static String CLIPBOARD_FILE_NAME = "gvSIG_layers_clipboard.tmp"; |
72 |
private static String CLIPBOARD_FOLDER = |
|
73 |
System.getProperty("user.home") + File.separator + "gvSIG" |
|
74 |
+ File.separator + "clipboard-layers"; |
|
75 |
|
|
76 |
static { |
|
77 |
File f = new File(CLIPBOARD_FOLDER); |
|
78 |
f.mkdirs(); |
|
79 |
} |
|
73 |
private static File clipboardFolder = null; |
|
80 | 74 |
|
81 |
private static/* XML */PersistenceManager persManager = ToolsLocator |
|
82 |
.getPersistenceManager(); |
|
83 |
|
|
84 | 75 |
private CopyPasteLayersUtils() { |
85 | 76 |
} |
86 |
|
|
77 |
|
|
78 |
private static PersistenceManager getPersMan() { |
|
79 |
return ToolsLocator.getPersistenceManager(); |
|
80 |
} |
|
81 |
|
|
82 |
private static File getClipboardFolder() { |
|
83 |
if (clipboardFolder == null) { |
|
84 |
File appf = PluginsLocator.getManager().getApplicationHomeFolder(); |
|
85 |
clipboardFolder = new File(appf, "clipboard-layers"); |
|
86 |
clipboardFolder.mkdirs(); |
|
87 |
} |
|
88 |
return clipboardFolder; |
|
89 |
// |
|
90 |
|
|
91 |
} |
|
87 | 92 |
/** |
88 | 93 |
* Gets the outputstream for writing contents to the |
89 | 94 |
* clipboard |
... | ... | |
92 | 97 |
* @throws IOException |
93 | 98 |
*/ |
94 | 99 |
private static OutputStream getClipboardOStream() throws IOException { |
95 |
String strf = CLIPBOARD_FOLDER+ File.separator + CLIPBOARD_FILE_NAME; |
|
96 |
File f = new File(strf);
|
|
100 |
|
|
101 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
97 | 102 |
if (f.exists()) { |
98 | 103 |
/* |
99 | 104 |
* If file exists, it is removed |
... | ... | |
110 | 115 |
} |
111 | 116 |
|
112 | 117 |
public static void clearClipboard() throws IOException { |
113 |
String strf = CLIPBOARD_FOLDER + File.separator + CLIPBOARD_FILE_NAME; |
|
114 |
File f = new File(strf);
|
|
118 |
|
|
119 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
115 | 120 |
if (f.exists()) { |
116 | 121 |
f.delete(); |
117 | 122 |
} |
... | ... | |
125 | 130 |
* @throws IOException |
126 | 131 |
*/ |
127 | 132 |
private static InputStream getClipboardIStream() throws IOException { |
128 |
String strf = CLIPBOARD_FOLDER + File.separator + CLIPBOARD_FILE_NAME; |
|
129 |
File f = new File(strf);
|
|
133 |
|
|
134 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
130 | 135 |
if (f.exists()) { |
131 | 136 |
return new FileInputStream(f); |
132 | 137 |
} else { |
... | ... | |
154 | 159 |
return null; |
155 | 160 |
} |
156 | 161 |
|
157 |
Object obj = persManager.getObject(is);
|
|
162 |
Object obj = getPersMan().getObject(is);
|
|
158 | 163 |
is.close(); |
159 | 164 |
if (obj instanceof FLayers) { |
160 | 165 |
return (FLayers) obj; |
... | ... | |
181 | 186 |
OutputStream os = null; |
182 | 187 |
try { |
183 | 188 |
os = getClipboardOStream(); |
184 |
persManager.saveState(st, os);
|
|
189 |
getPersMan().saveState(st, os);
|
|
185 | 190 |
os.close(); |
186 | 191 |
if (st.getContext().getErrors() != null) { |
187 | 192 |
throw st.getContext().getErrors(); |
... | ... | |
221 | 226 |
} |
222 | 227 |
|
223 | 228 |
PersistentState state = null; |
224 |
state = persManager.getState(lyrs, true);
|
|
229 |
state = getPersMan().getState(lyrs, true);
|
|
225 | 230 |
|
226 | 231 |
if (state.getContext().getErrors() != null) { |
227 | 232 |
throw state.getContext().getErrors(); |
Also available in: Unified diff