svn-gvsig-desktop / trunk / prototypes / mobile / desktop / extensions / extExportMobile / src / es / prodevelop / gvsig / exportMobile / layerexporters / ExporterSubTask.java @ 19124
History | View | Annotate | Download (2.4 KB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package es.prodevelop.gvsig.exportMobile.layerexporters; |
5 |
|
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.io.File; |
8 |
|
9 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
10 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
11 |
import com.iver.utiles.swing.threads.AbstractMonitorableTask; |
12 |
|
13 |
import es.prodevelop.gvsig.exportMobile.xml.XmlProjectTags; |
14 |
|
15 |
/**
|
16 |
* @author jcarras
|
17 |
*
|
18 |
*/
|
19 |
public abstract class ExporterSubTask{ |
20 |
|
21 |
protected FLayer inLayer;
|
22 |
protected Rectangle2D rect; |
23 |
protected AbstractMonitorableTask parent;
|
24 |
protected int finalStep; |
25 |
protected XmlBuilder xml;
|
26 |
private boolean xmlInited = false; |
27 |
private int currentStep = 0; |
28 |
private boolean isCancelled = false; |
29 |
|
30 |
private ExporterSubTask(){
|
31 |
|
32 |
} |
33 |
|
34 |
public abstract void run(); |
35 |
|
36 |
public ExporterSubTask(AbstractMonitorableTask parentProcess, FLayer layer, Rectangle2D rect, XmlBuilder xml){ |
37 |
this.inLayer=layer;
|
38 |
this.rect=rect;
|
39 |
this.parent=parentProcess;
|
40 |
this.xml=xml;
|
41 |
} |
42 |
|
43 |
public void reportStep(){ |
44 |
currentStep++; |
45 |
parent.reportStep(); |
46 |
} |
47 |
|
48 |
public void reportSteps(int numSteps){ |
49 |
for (int i=0; i<numSteps; i++) |
50 |
reportStep(); |
51 |
} |
52 |
|
53 |
public void setStatusMessage(String statusMessage){ |
54 |
parent.setStatusMessage(statusMessage); |
55 |
} |
56 |
|
57 |
public void setNote(String note){ |
58 |
parent.setNote(note); |
59 |
} |
60 |
|
61 |
public abstract int getFinalStep(); |
62 |
|
63 |
|
64 |
public File getFreeFile(File proposedFile){ |
65 |
if (!proposedFile.exists())
|
66 |
return proposedFile;
|
67 |
else {
|
68 |
String base = proposedFile.getAbsolutePath();
|
69 |
int dotPos = base.lastIndexOf("."); |
70 |
String ext = base.substring(dotPos);
|
71 |
base = base.substring(0, dotPos);
|
72 |
for (int i=0;i<99999;i++){ |
73 |
String newPath = base + "_" + i + ext; |
74 |
File newFile = new File(newPath); |
75 |
if (!newFile.exists())
|
76 |
return newFile;
|
77 |
} |
78 |
} |
79 |
return null; |
80 |
} |
81 |
|
82 |
protected void initXML(){ |
83 |
//<Layer>
|
84 |
xml.openTag(XmlProjectTags.LAYER); |
85 |
xmlInited=true;
|
86 |
} |
87 |
protected void closeXML(){ |
88 |
if (isXmlInited())
|
89 |
xml.closeTag(); |
90 |
//</Layer>
|
91 |
xmlInited=false;
|
92 |
} |
93 |
|
94 |
public boolean isXmlInited() { |
95 |
return xmlInited;
|
96 |
} |
97 |
|
98 |
public int getCurrentStep() { |
99 |
return currentStep;
|
100 |
} |
101 |
|
102 |
protected void reportToEnd(){ |
103 |
while (getCurrentStep()<getFinalStep()){
|
104 |
reportStep(); |
105 |
} |
106 |
} |
107 |
|
108 |
public boolean isCancelled() { |
109 |
return isCancelled;
|
110 |
} |
111 |
|
112 |
public void setCancelled(boolean isCancelled) { |
113 |
this.isCancelled = isCancelled;
|
114 |
} |
115 |
|
116 |
|
117 |
} |