svn-gvsig-desktop / trunk / prototypes / mobile / desktop / extensions / extExportMobile / src / es / prodevelop / gvsig / exportMobile / layerexporters / ExporterSubTask.java @ 19196
History | View | Annotate | Download (3.36 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 |
*
|
17 |
* This class mother has to be the ancestor of every class
|
18 |
* executable in an ExportProcess
|
19 |
*
|
20 |
* @author jcarras
|
21 |
*
|
22 |
*/
|
23 |
public abstract class ExporterSubTask{ |
24 |
|
25 |
protected FLayer inLayer;
|
26 |
protected Rectangle2D rect; |
27 |
protected AbstractMonitorableTask parent;
|
28 |
protected int finalStep; |
29 |
protected XmlBuilder xml;
|
30 |
private boolean xmlInited = false; |
31 |
private int currentStep = 0; |
32 |
private boolean isCancelled = false; |
33 |
|
34 |
public abstract void run(); |
35 |
|
36 |
/**
|
37 |
* Constructor
|
38 |
*
|
39 |
* @param parentProcess
|
40 |
* @param layer
|
41 |
* @param rect
|
42 |
* @param xml
|
43 |
*/
|
44 |
public ExporterSubTask(AbstractMonitorableTask parentProcess, FLayer layer, Rectangle2D rect, XmlBuilder xml){ |
45 |
this.inLayer=layer;
|
46 |
this.rect=rect;
|
47 |
this.parent=parentProcess;
|
48 |
this.xml=xml;
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* Indicates to the ExportProcess that the task is going on
|
53 |
* reportStep has to be called exactly getFinalStep() times
|
54 |
*/
|
55 |
public void reportStep(){ |
56 |
currentStep++; |
57 |
parent.reportStep(); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* It reports numSteps Steps
|
62 |
* @param numSteps
|
63 |
*/
|
64 |
public void reportSteps(int numSteps){ |
65 |
for (int i=0; i<numSteps; i++) |
66 |
reportStep(); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Changes the status text of the task
|
71 |
* @param statusMessage
|
72 |
*/
|
73 |
public void setStatusMessage(String statusMessage){ |
74 |
parent.setStatusMessage(statusMessage); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Changes the note of the task
|
79 |
* (It is showed on progress dialog)
|
80 |
*
|
81 |
* @param note
|
82 |
*/
|
83 |
public void setNote(String note){ |
84 |
parent.setNote(note); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Any class extending ExporterSubClass has to implement this method
|
89 |
* to comunicate the number of steps it will report
|
90 |
* @return
|
91 |
*/
|
92 |
public abstract int getFinalStep(); |
93 |
|
94 |
/**
|
95 |
* If the proposed file exists, this method returns one not existing
|
96 |
* file similar to the proposed one
|
97 |
*
|
98 |
* @param proposedFile
|
99 |
* @return
|
100 |
*/
|
101 |
public File getFreeFile(File proposedFile){ |
102 |
if (!proposedFile.exists())
|
103 |
return proposedFile;
|
104 |
else {
|
105 |
String base = proposedFile.getAbsolutePath();
|
106 |
int dotPos = base.lastIndexOf("."); |
107 |
String ext = base.substring(dotPos);
|
108 |
base = base.substring(0, dotPos);
|
109 |
for (int i=0;i<99999;i++){ |
110 |
String newPath = base + "_" + i + ext; |
111 |
File newFile = new File(newPath); |
112 |
if (!newFile.exists())
|
113 |
return newFile;
|
114 |
} |
115 |
} |
116 |
return null; |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Starts the XML with the layer heading
|
121 |
*/
|
122 |
protected void initXML(){ |
123 |
//<Layer>
|
124 |
xml.openTag(XmlProjectTags.LAYER); |
125 |
xmlInited=true;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Add the layer footer to the XML
|
130 |
*/
|
131 |
protected void closeXML(){ |
132 |
if (isXmlInited())
|
133 |
xml.closeTag(); |
134 |
//</Layer>
|
135 |
xmlInited=false;
|
136 |
} |
137 |
|
138 |
public boolean isXmlInited() { |
139 |
return xmlInited;
|
140 |
} |
141 |
|
142 |
public int getCurrentStep() { |
143 |
return currentStep;
|
144 |
} |
145 |
|
146 |
protected void reportToEnd(){ |
147 |
while (getCurrentStep()<getFinalStep()){
|
148 |
reportStep(); |
149 |
} |
150 |
} |
151 |
|
152 |
public boolean isCancelled() { |
153 |
return isCancelled;
|
154 |
} |
155 |
|
156 |
public void setCancelled(boolean isCancelled) { |
157 |
this.isCancelled = isCancelled;
|
158 |
} |
159 |
|
160 |
|
161 |
} |