svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / report / LayoutReportActionImpl.java @ 1607
History | View | Annotate | Download (25 KB)
1 |
package org.gvsig.app.project.documents.layout.report; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.geom.Point2D; |
7 |
import java.io.ByteArrayInputStream; |
8 |
import java.io.File; |
9 |
import java.io.InputStream; |
10 |
import java.util.ArrayList; |
11 |
import java.util.List; |
12 |
import java.util.Objects; |
13 |
import java.util.logging.Level; |
14 |
import java.util.logging.Logger; |
15 |
import javax.json.JsonNumber; |
16 |
import javax.json.JsonObject; |
17 |
import javax.swing.JComponent; |
18 |
import javax.swing.JOptionPane; |
19 |
import javax.swing.SwingUtilities; |
20 |
import org.apache.commons.codec.DecoderException; |
21 |
import org.apache.commons.codec.binary.Hex; |
22 |
import org.apache.commons.io.IOUtils; |
23 |
import org.apache.commons.lang3.StringUtils; |
24 |
import org.cresques.cts.ICoordTrans; |
25 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
26 |
import org.gvsig.app.ApplicationLocator; |
27 |
import org.gvsig.app.ApplicationManager; |
28 |
import org.gvsig.app.gui.styling.SymbolSelector; |
29 |
import org.gvsig.app.project.documents.Document; |
30 |
import org.gvsig.app.project.documents.layout.LayoutContext; |
31 |
import org.gvsig.app.project.documents.layout.fframes.FFrameView; |
32 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
33 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
34 |
import static org.gvsig.app.project.documents.layout.report.LayoutReportActionFactory.LAYOUT_REPORT_ACTION_NAME; |
35 |
import org.gvsig.app.project.documents.view.ViewDocument; |
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
37 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
38 |
import org.gvsig.desktopopen.DesktopOpen; |
39 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
40 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
41 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
42 |
import org.gvsig.expressionevaluator.MutableSymbolTable; |
43 |
import org.gvsig.fmap.dal.DALLocator; |
44 |
import org.gvsig.fmap.dal.exception.DataException; |
45 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureSymbolTable; |
46 |
import org.gvsig.fmap.dal.feature.Feature; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
48 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
49 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
50 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
51 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
52 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
53 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
54 |
import org.gvsig.fmap.dal.swing.report.AbstractReportAction; |
55 |
import org.gvsig.fmap.dal.swing.report.ReportActionFactory; |
56 |
import org.gvsig.fmap.geom.Geometry; |
57 |
import org.gvsig.fmap.geom.GeometryLocator; |
58 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
59 |
import org.gvsig.fmap.geom.primitive.Envelope; |
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
61 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
62 |
import org.gvsig.fmap.mapcontext.ViewPort; |
63 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
64 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
65 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
66 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
67 |
import org.gvsig.json.Json; |
68 |
import org.gvsig.pdf.lib.api.PDFDocument; |
69 |
import org.gvsig.pdf.lib.api.PDFLocator; |
70 |
import org.gvsig.pdf.lib.api.PDFManager; |
71 |
import org.gvsig.pdf.swing.api.PDFSwingLocator; |
72 |
import org.gvsig.pdf.swing.api.PDFSwingManager; |
73 |
import org.gvsig.pdf.swing.api.PDFViewer; |
74 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
75 |
import org.gvsig.tools.ToolsLocator; |
76 |
import org.gvsig.tools.dispose.DisposeUtils; |
77 |
import org.gvsig.tools.exception.BaseException; |
78 |
import org.gvsig.tools.i18n.I18nManager; |
79 |
import org.gvsig.tools.locator.LocatorException; |
80 |
import org.gvsig.tools.persistence.PersistenceManager; |
81 |
import org.gvsig.tools.persistence.PersistentState; |
82 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
83 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
84 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
85 |
import org.gvsig.tools.swing.api.task.JTaskStatus; |
86 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
87 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
88 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
89 |
import org.gvsig.tools.task.SimpleTaskStatus; |
90 |
import org.gvsig.tools.util.ToolsUtilLocator; |
91 |
|
92 |
/**
|
93 |
*
|
94 |
* @author jjdelcerro
|
95 |
*/
|
96 |
@SuppressWarnings("UseSpecificCatch") |
97 |
public class LayoutReportActionImpl extends AbstractReportAction implements LayoutReportAction { |
98 |
|
99 |
public static LayoutReportActionImpl createFakeLayoutReportAction(Document doc) { |
100 |
ApplicationManager application = ApplicationLocator.getApplicationManager(); |
101 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
102 |
Feature f = null;
|
103 |
FeatureStore theStore = null;
|
104 |
ReportActionFactory theFactory = dataSwingManager.getReportActionFactory(LAYOUT_REPORT_ACTION_NAME); |
105 |
try {
|
106 |
IWindow activeView = application.getActiveWindow(ViewDocument.class); |
107 |
ViewDocument viewdoc = (ViewDocument) ((IView)activeView).getDocument(); |
108 |
FLyrVect layer = viewdoc.getMapContext().getLayers().getFirstActiveVectorLayer(); |
109 |
theStore = layer.getFeatureStore(); |
110 |
if( theStore.isFeatureSelectionEmpty() ) {
|
111 |
f = theStore.first(); |
112 |
} else {
|
113 |
f = theStore.getFeatureSelection().first(); |
114 |
} |
115 |
} catch(Throwable t) { |
116 |
LOGGER.debug("Can't retrieve test feature",t);
|
117 |
} |
118 |
LayoutReportActionImpl report = new LayoutReportActionImpl(theFactory, theStore, f);
|
119 |
report.getSymbolTable().setVar("$LAYOUT", doc);
|
120 |
report.getSymbolTable().setVar("$PAGE", 1); |
121 |
report.getSymbolTable().setVar("$PAGES", 1); |
122 |
return report;
|
123 |
} |
124 |
|
125 |
|
126 |
private final JsonObject json; |
127 |
private final FeatureStore store; |
128 |
private FeatureQuery query;
|
129 |
private FeatureSet selection;
|
130 |
private Feature current_row;
|
131 |
private MutableSymbolTable symbolTable;
|
132 |
private FeatureSymbolTable fSymbolTable;
|
133 |
private boolean centerToCurrentRow; |
134 |
private boolean zoomToCurrentRow; |
135 |
private double bufferSize; |
136 |
private boolean useInternalPdfViewer; |
137 |
private Iterable<Feature> set; |
138 |
private int featuresCount; |
139 |
private String viewTag; |
140 |
private boolean highlightRecord; |
141 |
private ISymbol highlightSymbol;
|
142 |
// private Color fillColor;
|
143 |
// private Color lineColor;
|
144 |
|
145 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
146 |
private LayoutReportActionImpl(ReportActionFactory factory, FeatureStore store, JsonObject json) {
|
147 |
super(factory, null); |
148 |
this.json = json;
|
149 |
this.store = store;
|
150 |
this.selection = null; |
151 |
this.query = null; |
152 |
this.current_row = null; |
153 |
|
154 |
this.setReportName(this.json.getString(LAYOUT_REPORT_NAME, store.getName())); |
155 |
this.setReportLabel(this.json.getString(LAYOUT_REPORT_LABEL, this.getReportName())); |
156 |
this.highlightRecord = this.json.getBoolean(LAYOUT_REPORT_HIGHLIGHT_RECORD, true); |
157 |
this.highlightSymbol = createSymbol(this.json.getString(LAYOUT_REPORT_HIGHLIGHT_SYMBOL, null)); |
158 |
// this.fillColor = new Color(this.json.getInt(LAYOUT_REPORT_FILL_COLOR, Color.WHITE.getRGB()&(0x2F<<24)));
|
159 |
// this.lineColor = new Color(this.json.getInt(LAYOUT_REPORT_LINE_COLOR, Color.WHITE.getRGB()));
|
160 |
this.setCenterToCurrentRow(this.json.getBoolean(LAYOUT_REPORT_CENTER_TO_CURRENT_ROW, true)); |
161 |
this.setZoomToCurrentRow(this.json.getBoolean(LAYOUT_REPORT_ZOOM_TO_CURRENT_ROW, true)); |
162 |
this.setBufferSize(0.0); |
163 |
if(this.json.containsKey(LAYOUT_REPORT_BUFFER_SIZE)){ |
164 |
JsonNumber theSize = this.json.getJsonNumber(LAYOUT_REPORT_BUFFER_SIZE);
|
165 |
if(theSize != null){ |
166 |
this.setBufferSize(theSize.doubleValue());
|
167 |
} |
168 |
} |
169 |
this.setViewTag(this.json.getString(LAYOUT_REPORT_VIEW_TAG, null)); |
170 |
this.setUseInternalPdfViewer(this.json.getBoolean(LAYOUT_REPORT_USE_INTERNAL_PDF_VIEWER, true)); |
171 |
|
172 |
} |
173 |
|
174 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
175 |
private LayoutReportActionImpl(ReportActionFactory factory, FeatureStore store, Feature feature) {
|
176 |
// Fake layoutReportAction constructor
|
177 |
this(
|
178 |
factory, |
179 |
store, |
180 |
Json.createObjectBuilder() |
181 |
.add(LAYOUT_REPORT_NAME, store.getName()) |
182 |
.add(LAYOUT_REPORT_TYPE, LAYOUT_REPORT_ACTION_NAME) |
183 |
.add(LAYOUT_REPORT_LABEL, store.getName()) |
184 |
.build() |
185 |
); |
186 |
try {
|
187 |
this.selection = store.createFeatureSelection();
|
188 |
((FeatureSelection)this.selection).select(feature);
|
189 |
} catch(Throwable t) { |
190 |
LOGGER.debug("Can't initialize selection",t);
|
191 |
} |
192 |
this.query = store.createFeatureQuery(feature.createFilter());
|
193 |
this.current_row = feature;
|
194 |
|
195 |
} |
196 |
|
197 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
198 |
public LayoutReportActionImpl(ReportActionFactory factory, FeatureStore store, FeatureQuery query, FeatureSet selection, final JsonObject json) { |
199 |
this(factory, store, json);
|
200 |
|
201 |
this.selection = selection;
|
202 |
this.query = query;
|
203 |
} |
204 |
|
205 |
public Feature row() {
|
206 |
return this.current_row; |
207 |
} |
208 |
|
209 |
private Iterable<Feature> features() { |
210 |
if( this.set == null ) { |
211 |
if(this.selection == null){ |
212 |
try {
|
213 |
FeatureSet fset = store.getFeatureSet(query); |
214 |
this.featuresCount = fset.size();
|
215 |
this.set = fset;
|
216 |
} catch (DataException ex) {
|
217 |
throw new RuntimeException("Can't create dynamic-text report.", ex); |
218 |
} |
219 |
} else {
|
220 |
this.featuresCount = this.selection.size(); |
221 |
if(this.selection instanceof FeatureSelection){ |
222 |
this.set = this.store.getFeaturesIterable(((FeatureSelection)this.selection).referenceIterator()); |
223 |
} else {
|
224 |
this.set = this.selection; |
225 |
DisposeUtils.bind(this.set);
|
226 |
} |
227 |
} |
228 |
} |
229 |
return this.set; |
230 |
} |
231 |
|
232 |
|
233 |
@Override
|
234 |
public void actionPerformed(ActionEvent e) { |
235 |
if (!this.isEnabled()) { |
236 |
return;
|
237 |
} |
238 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
239 |
final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
|
240 |
final JTaskStatus taskStatusPanel = ToolsSwingLocator.getTaskStatusSwingManager().createJTaskStatus();
|
241 |
final LayoutReportAction report = this; |
242 |
|
243 |
SimpleTaskStatus theStatus = this.getStatus();
|
244 |
theStatus.setIndeterminate(); |
245 |
taskStatusPanel.setShowRemoveTaskButton(false);
|
246 |
taskStatusPanel.bind(theStatus); |
247 |
ToolsSwingUtils.ensureRowsCols(taskStatusPanel, 4, 100, 5, 200); |
248 |
|
249 |
windowManager.showWindow( |
250 |
taskStatusPanel.asJComponent(), |
251 |
i18n.getTranslation("_Creating_report")+" '" + this.getReportLabel() + "'...", |
252 |
WindowManager.MODE.TOOL |
253 |
); |
254 |
|
255 |
Thread task = new Thread(() -> { |
256 |
List<File> singlePdfFiles = new ArrayList(); |
257 |
Iterable<Feature> features = null; |
258 |
try {
|
259 |
String title = this.getReportLabel(); |
260 |
String creator = "gvSIG-desktop"; |
261 |
String subject = "Layout report"; |
262 |
|
263 |
File pdfFile = ToolsLocator.getFoldersManager().getUniqueTemporaryFile("report.pdf"); |
264 |
int pag = 0; |
265 |
features = features(); |
266 |
theStatus.setRangeOfValues(1, featuresCount);
|
267 |
theStatus.message(i18n.getTranslation("_Building_pages"));
|
268 |
for (Feature feature : features) {
|
269 |
if( theStatus.isCancellationRequested() ) {
|
270 |
theStatus.cancel(); |
271 |
return;
|
272 |
} |
273 |
File f = printReport(feature, ++pag);
|
274 |
singlePdfFiles.add(f); |
275 |
theStatus.incrementCurrentValue(); |
276 |
} |
277 |
|
278 |
theStatus.message(i18n.getTranslation("_Building_pdf"));
|
279 |
PDFManager pdfManager = PDFLocator.getPDFManager(); |
280 |
pdfManager.merge(singlePdfFiles, pdfFile, title, creator, subject, theStatus); |
281 |
|
282 |
if (this.isUseInternalPdfViewer()) { |
283 |
this.showEmbedded(pdfFile);
|
284 |
} else {
|
285 |
this.showExternal(pdfFile);
|
286 |
} |
287 |
|
288 |
theStatus.terminate(); |
289 |
SwingUtilities.invokeLater(() -> {
|
290 |
taskStatusPanel.setVisible(false);
|
291 |
}); |
292 |
|
293 |
} catch (Throwable t) { |
294 |
LOGGER.warn("Can't create layout report.", t);
|
295 |
theStatus.abort(); |
296 |
} finally {
|
297 |
for (File singlePdfFile : singlePdfFiles) { |
298 |
singlePdfFile.delete(); |
299 |
} |
300 |
DisposeUtils.disposeQuietly(features); |
301 |
|
302 |
} |
303 |
}, "Report_" + report.getReportName());
|
304 |
task.start(); |
305 |
|
306 |
} |
307 |
|
308 |
private File printReport(Feature feature, int page) throws Exception { |
309 |
this.current_row = feature;
|
310 |
final LayoutPanel layout = this.loadTemplate(); |
311 |
final LayoutContext context = layout.getLayoutContext();
|
312 |
final Document document = layout.getDocument(); |
313 |
|
314 |
this.getSymbolTable();
|
315 |
fSymbolTable.setFeature(current_row); |
316 |
this.symbolTable.setVar("$LAYOUT", document); |
317 |
this.symbolTable.setVar("$PAGE", page); |
318 |
this.symbolTable.setVar("$PAGES", this.featuresCount); |
319 |
|
320 |
File pdfFile = null; |
321 |
Object previous_report = document.getProperty("$REPORT"); |
322 |
try {
|
323 |
document.setProperty("$REPORT", this); |
324 |
/*
|
325 |
TODO: Aqui podriamos consultar en el json para ver si hacemos:
|
326 |
x zoom al envelope de la geometria de current_row,
|
327 |
x si le aplicamos un buffer antes a ese envelop,
|
328 |
X si la seleccionamos...
|
329 |
- asi como con que vista tenemos que hacerlo. ????
|
330 |
*/
|
331 |
int count = 1; |
332 |
MapContext mapContext = null;
|
333 |
MapContext mapContextCandidate = null;
|
334 |
for (IFFrame frame : context.getAllFFrames()) {
|
335 |
if (frame instanceof FFrameView) { |
336 |
if (mapContextCandidate == null) { |
337 |
mapContextCandidate = ((FFrameView) frame).getMapContext(); |
338 |
} |
339 |
String frameTag = frame.getTag();
|
340 |
String countTag = "#" + count; |
341 |
if (StringUtils.equalsIgnoreCase(this.getViewTag(), frameTag) |
342 |
|| StringUtils.equalsIgnoreCase(this.getViewTag(), countTag)) {
|
343 |
mapContext = ((FFrameView) frame).getMapContext(); |
344 |
break;
|
345 |
} |
346 |
} |
347 |
} |
348 |
if (mapContext == null) { |
349 |
mapContext = mapContextCandidate; |
350 |
}; |
351 |
|
352 |
FeatureStore storeInLayout = this.store;
|
353 |
if (mapContext != null) { |
354 |
mapContext.setPrintGraphicsLayer(this.isHighlightRecord());
|
355 |
ICoordTrans ct = null;
|
356 |
for (FLayer layer : mapContext.getLayers().getLayers(null)) { |
357 |
if (layer instanceof FLyrVect) { |
358 |
FeatureStore layerStore = ((FLyrVect) layer).getFeatureStore(); |
359 |
if (layerStore != null) { |
360 |
if (layerStore.getParameters().isTheSameStore(this.store.getParameters())) { |
361 |
storeInLayout = layerStore; |
362 |
ct = ((FLyrVect) layer).getCoordTrans(); |
363 |
break;
|
364 |
} |
365 |
} |
366 |
} |
367 |
} |
368 |
Geometry geom = this.current_row.getDefaultGeometry();
|
369 |
if (geom != null) { |
370 |
geom = geom.cloneGeometry(); |
371 |
if (ct != null && ct.getPOrig().equals(geom.getProjection())) { |
372 |
geom.reProject(ct); |
373 |
} else if (!geom.getProjection().equals(mapContext.getProjection())) { |
374 |
ct = geom.getProjection().getCT(mapContext.getProjection()); |
375 |
geom.reProject(ct); |
376 |
} |
377 |
if (isZoomToCurrentRow()) {
|
378 |
|
379 |
Envelope envelope = geom |
380 |
.getEnvelope().getGeometry().buffer(getBufferSize()).getEnvelope(); |
381 |
mapContext.getViewPort().setEnvelope(envelope); |
382 |
|
383 |
} else if (isCenterToCurrentRow()) { |
384 |
|
385 |
Envelope envelope = geom |
386 |
.getEnvelope().getGeometry().buffer(getBufferSize()).getEnvelope(); |
387 |
center(mapContext, envelope); |
388 |
|
389 |
} else {
|
390 |
//DO NOTHING ??
|
391 |
} |
392 |
if(this.isHighlightRecord()){ |
393 |
GraphicLayer graphicsLayer = mapContext.getGraphicsLayer(); |
394 |
graphicsLayer.clear(); |
395 |
int idSymbol = graphicsLayer.addSymbol(this.highlightSymbol); |
396 |
//TODO: Decidir si aplicamos el simbolo a la geometr?a o al resto
|
397 |
// geom = mapContext.getViewPort().getAdjustedEnvelope().getGeometry().difference(geom);
|
398 |
graphicsLayer.addGraphic("", geom, idSymbol);
|
399 |
} |
400 |
} |
401 |
} |
402 |
|
403 |
context.fullRefresh(); |
404 |
layout.getLayoutControl().getLayoutDraw().initialize(); |
405 |
|
406 |
pdfFile = ToolsLocator.getFoldersManager().getUniqueTemporaryFile("report.pdf");
|
407 |
layout.layoutToPDF(pdfFile); |
408 |
} finally {
|
409 |
document.setProperty("$REPORT", previous_report);
|
410 |
} |
411 |
|
412 |
return pdfFile;
|
413 |
} |
414 |
|
415 |
private void center(MapContext mapContext, Envelope envelope) throws LocatorException, CreateEnvelopeException { |
416 |
ViewPort viewPort = mapContext.getViewPort(); |
417 |
Envelope oldExtent = viewPort.getAdjustedEnvelope(); |
418 |
double oldCenterX = oldExtent.getCenter(0); |
419 |
double oldCenterY = oldExtent.getCenter(1); |
420 |
double centerX = envelope.getCenter(0); |
421 |
double centerY = envelope.getCenter(1); |
422 |
Point2D.Double center = new Point2D.Double(centerX, centerY); |
423 |
double movX = centerX - oldCenterX;
|
424 |
double movY = centerY - oldCenterY;
|
425 |
|
426 |
double minx = oldExtent.getMinimum(0) + movX; |
427 |
double miny = oldExtent.getMinimum(1) + movY; |
428 |
double maxX = oldExtent.getMaximum(0) + movX; |
429 |
double maxY = oldExtent.getMaximum(1) + movY; |
430 |
Envelope extent = GeometryLocator.getGeometryManager().createEnvelope( |
431 |
minx, miny, |
432 |
maxX, maxY, |
433 |
Geometry.SUBTYPES.GEOM2D); |
434 |
viewPort.setEnvelope(extent); |
435 |
} |
436 |
|
437 |
private void showEmbedded(File pdfFile) { |
438 |
if (!SwingUtilities.isEventDispatchThread()) { |
439 |
SwingUtilities.invokeLater(() -> {
|
440 |
showEmbedded(pdfFile); |
441 |
}); |
442 |
return;
|
443 |
} |
444 |
try {
|
445 |
final WindowManager windowManager = ToolsSwingLocator.getWindowManager();
|
446 |
final PDFSwingManager pdfSwingManager = PDFSwingLocator.getPDFSwingManager();
|
447 |
final PDFManager pdfManager = PDFLocator.getPDFManager();
|
448 |
|
449 |
final PDFDocument pdfdoc = pdfManager.createPDFDocument(pdfFile);
|
450 |
PDFViewer viewer = pdfSwingManager.createPDFViewer(); |
451 |
viewer.put(pdfdoc); |
452 |
viewer.setMode(PDFViewer.MODE_LIGHT); |
453 |
|
454 |
JComponent comp = viewer.asJComponent();
|
455 |
Dimension size = ToolsSwingUtils.ensureRowsCols(comp.getPreferredSize(), 20, 100, 40, 150); |
456 |
comp.setSize(size); |
457 |
|
458 |
String title = "Report: " + this.getLabel(); |
459 |
windowManager.showWindow( |
460 |
comp, |
461 |
title, |
462 |
WindowManager.MODE.WINDOW |
463 |
); |
464 |
} catch (Exception ex) { |
465 |
LOGGER.warn("Can't show pdf file '" + Objects.toString(pdfFile) + "'", ex); |
466 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
467 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
468 |
dialogs.messageDialog( |
469 |
i18n.getTranslation("_Cant_show_pdf_file")+" (" + Objects.toString(pdfFile) + ")\n\n"+BaseException.getMessageStack(ex, 0), |
470 |
"Creating report '" + this.getReportLabel() + "'", |
471 |
JOptionPane.WARNING_MESSAGE
|
472 |
); |
473 |
} |
474 |
} |
475 |
|
476 |
private void showExternal(File pdfFile) { |
477 |
if (!SwingUtilities.isEventDispatchThread()) { |
478 |
SwingUtilities.invokeLater(() -> {
|
479 |
showExternal(pdfFile); |
480 |
}); |
481 |
return;
|
482 |
} |
483 |
DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen(); |
484 |
desktop.open(pdfFile); |
485 |
} |
486 |
|
487 |
private LayoutPanel loadTemplate() throws Exception { |
488 |
ResourcesStorage resources = store.getResourcesStorage(); |
489 |
if (resources == null) { |
490 |
return null; |
491 |
} |
492 |
String templateName = this.json.getString(LAYOUT_REPORT_TEMPLATE_NAME, LAYOUT_REPORT_DEFAULT_TEMPLATE_NAME); // "1.layout"... |
493 |
ResourcesStorage.Resource resource = resources.getResource(templateName); |
494 |
InputStream is = null; |
495 |
try {
|
496 |
is = resource.asInputStream(); |
497 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
498 |
PersistentState persistentState = persistenceManager.loadState(is); |
499 |
|
500 |
LayoutPanel layout = (LayoutPanel) persistenceManager.create(persistentState); |
501 |
|
502 |
return layout;
|
503 |
} finally {
|
504 |
IOUtils.closeQuietly(is); |
505 |
} |
506 |
} |
507 |
|
508 |
public MutableSymbolTable getSymbolTable() {
|
509 |
if( this.symbolTable == null ) { |
510 |
this.symbolTable = ExpressionUtils.createSymbolTable();
|
511 |
fSymbolTable = DALLocator.getDataManager().createFeatureSymbolTable(); |
512 |
fSymbolTable.setFeature(current_row); |
513 |
this.symbolTable.addSymbolTable(fSymbolTable);
|
514 |
this.symbolTable.setVar("$REPORT", this); |
515 |
} |
516 |
return this.symbolTable; |
517 |
} |
518 |
|
519 |
@Override
|
520 |
public String evaluateDynamicText(String s) { |
521 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager(); |
522 |
if( !manager.isDynamicText(s) ) {
|
523 |
return s;
|
524 |
} |
525 |
String x = manager.evaluateDynamicText(
|
526 |
this.getSymbolTable(),
|
527 |
s, |
528 |
null,
|
529 |
this.store.getResourcesStorage()
|
530 |
); |
531 |
return x;
|
532 |
} |
533 |
|
534 |
@Override
|
535 |
public boolean isCenterToCurrentRow() { |
536 |
return this.centerToCurrentRow; |
537 |
} |
538 |
|
539 |
@Override
|
540 |
public void setCenterToCurrentRow(boolean centerToCurrentRow) { |
541 |
this.centerToCurrentRow = centerToCurrentRow;
|
542 |
} |
543 |
|
544 |
@Override
|
545 |
public boolean isZoomToCurrentRow() { |
546 |
return this.zoomToCurrentRow; |
547 |
} |
548 |
|
549 |
@Override
|
550 |
public void setZoomToCurrentRow(boolean zoomToCurrentRow) { |
551 |
this.zoomToCurrentRow = zoomToCurrentRow;
|
552 |
} |
553 |
|
554 |
@Override
|
555 |
public double getBufferSize() { |
556 |
return bufferSize;
|
557 |
} |
558 |
|
559 |
@Override
|
560 |
public void setBufferSize(double bufferSize) { |
561 |
this.bufferSize = bufferSize;
|
562 |
} |
563 |
|
564 |
@Override
|
565 |
public String getViewTag() { |
566 |
return viewTag;
|
567 |
} |
568 |
|
569 |
@Override
|
570 |
public void setViewTag(String viewTag) { |
571 |
this.viewTag = viewTag;
|
572 |
} |
573 |
|
574 |
public boolean isUseInternalPdfViewer() { |
575 |
return useInternalPdfViewer;
|
576 |
} |
577 |
|
578 |
@Override
|
579 |
public void setUseInternalPdfViewer(boolean useInternalPdfViewer) { |
580 |
this.useInternalPdfViewer = useInternalPdfViewer;
|
581 |
} |
582 |
|
583 |
@Override
|
584 |
public boolean isHighlightRecord() { |
585 |
return this.highlightRecord; |
586 |
} |
587 |
|
588 |
@Override
|
589 |
public void setHighlightRecord(boolean b) { |
590 |
this.highlightRecord = b;
|
591 |
} |
592 |
|
593 |
private ISymbol createSymbol(String s) { |
594 |
FeatureAttributeDescriptor geomAttr = this.store.getDefaultFeatureTypeQuietly().getDefaultGeometryAttribute();
|
595 |
if (geomAttr == null) { |
596 |
return null; |
597 |
} |
598 |
int geomType = geomAttr.getGeomType().getType();
|
599 |
|
600 |
try {
|
601 |
if (StringUtils.isBlank(s)) {
|
602 |
return MapContextLocator.getMapContextManager().createSymbol(geomType);
|
603 |
} |
604 |
|
605 |
byte[] bytes = Hex.decodeHex(s.toCharArray()); |
606 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
607 |
InputStream in = new ByteArrayInputStream(bytes); |
608 |
ISymbol symbol = (ISymbol) persistenceManager.getObject(in); |
609 |
return symbol;
|
610 |
} catch (DecoderException ex) {
|
611 |
return MapContextLocator.getMapContextManager().createSymbol(geomType);
|
612 |
} |
613 |
|
614 |
} |
615 |
|
616 |
} |