private void saveStyle() { if (_openedDocument == null) return; _openedDocument.putContents(_editorPane.getText()); try { if (!_openedDocument.isSaved()) { JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File f = fileChooser.getSelectedFile(); String path = f.getAbsolutePath(); _openedDocument.saveStyle(path); refreshUI(); } } else { _openedDocument.saveStyle(); refreshUI(); } } catch (Exception e) { JOptionPane.showMessageDialog( this, e.toString(), "Error while saving style", JOptionPane.ERROR_MESSAGE); } }
private void openStyle() { try { JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File f = fileChooser.getSelectedFile(); if (!f.exists()) throw new Exception("File doesn't exists!"); String path = f.getAbsolutePath(); // String path = Constants.ROOT_MAPSFORGE_DIR + "\\styles\\default.xml"; if (_openedDocument != null) closeStyle(); refreshUI(); _openedDocument = StyleDocument.loadStyle(path); _editorPane.setText(_openedDocument.getContent()); refreshUI(); _editorPane.addCaretListener(_caretListener); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog( this, e.toString(), "Error while opening style", JOptionPane.ERROR_MESSAGE); } }
private void createStyle() { try { if (_openedDocument != null) closeStyle(); refreshUI(); _openedDocument = new StyleDocument(); String baseFileText = openBaseFileText(); _openedDocument.putContents(baseFileText); _editorPane.setText(_openedDocument.getContent()); refreshUI(); _editorPane.addCaretListener(_caretListener); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog( this, e.toString(), "Error while creating style", JOptionPane.ERROR_MESSAGE); } }
private void closeStyle() { if (_openedDocument == null) return; try { _openedDocument.closeStyle(); _openedDocument = null; refreshUI(); _editorPane.removeCaretListener(_caretListener); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog( this, e.toString(), "Error while closing style", JOptionPane.ERROR_MESSAGE); } }
private void refreshUI() { if (_openedDocument != null) { // _editorPane.setText(_openedDocument.getContent()); String path = _openedDocument.getPath(); Layers layers = _mapView.getLayerManager().getLayers(); layers.clear(); TileCache tc = createTileCache(0); System.out.println("RefreshUI()"); String filePath = Constants.MAP_FILE; String rendererPath = _openedDocument.getPath(); String fileLocation = ""; if (rendererPath != null) fileLocation = new File(rendererPath).getParentFile().getAbsolutePath(); TileRendererLayer layer = createTileRendererLayerWithString( tc, _mapView.getModel().mapViewPosition, false, true, filePath, _editorPane.getText(), fileLocation); layers.add(layer); _openedDocument.putContents(_editorPane.getText()); // TODO final RenderThemeFuture rtf = new RenderThemeFuture( GRAPHIC_FACTORY, new MapsForgeStringXmlRenderTheme(_editorPane.getText(), fileLocation), new DisplayModel()); Thread t = new Thread( new Runnable() { @Override public void run() { rtf.run(); try { rtf.get(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { System.out.println("Dismiss the error!"); // _mapView.setVisible(true); // lblError.setVisible(false); lblError.setText(""); } }); } catch (final Exception e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { System.out.println("Showing an error!"); // _mapView.setVisible(false); // lblError.setVisible(true); lblError.setText("<html>" + e.toString() + "</html>"); } }); } } }); t.start(); } else { Layers layers = _mapView.getLayerManager().getLayers(); layers.clear(); } }