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); } }
/** Creates new form JMainFrame */ public JMainFrame() { initComponents(); splMain.setDividerLocation(0.5f); splMain.setResizeWeight(0.5f); _mapView = createMapView(); layeredPane.setLayout(new OverlayLayout(layeredPane)); layeredPane.add(_mapView, JLayeredPane.DEFAULT_LAYER); lblError = new JLabel(); lblError.setForeground(Color.RED); lblError.setFont(lblError.getFont().deriveFont(Font.BOLD)); layeredPane.add(lblError, JLayeredPane.POPUP_LAYER); lblError.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25)); lblError.setText(""); _editorPane = createCodeTextPane(); pnlCode.setLayout(new BorderLayout()); pnlCode.add(_editorPane.getContainerWithLines(), BorderLayout.CENTER); refreshUI(); // 50.636311, 5.570565 MapFile mf = new MapFile(Constants.MAP_FILE); double lat = mf.boundingBox().getCenterPoint().latitude; double lng = mf.boundingBox().getCenterPoint().longitude; _mapView.getModel().mapViewPosition.setCenter(new LatLong(lat, lng)); _mapView.getModel().mapViewPosition.setZoomLevel((byte) 15); }
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 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 CodeEditorPane createCodeTextPane() { CodeEditorPane pane = new CodeEditorPane(); pane.setStyledDocument(new DefaultStyledDocument()); HashMap<String, Color> keywords = new RegExpHashMap(); // keywords.put("<", Color.blue); keywords.put("rule", Color.blue); keywords.put("line", Color.blue); keywords.put("pathText", Color.blue); keywords.put("area", Color.blue); keywords.put("rendertheme", Color.blue); pane.setKeywordColor(keywords); pane.setVerticalLineAtPos(80); /*HashMap<String, String> helps = new HashMap<>(); helps.put("rule", "Hello World Rule !"); helps.put("line", "Hello World Line !"); pane.setKeywordHelp(helps);*/ return pane; }
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); } }
@Override public void caretUpdate(CaretEvent e) { if (_editorPane.getText().hashCode() != _openedDocument.getContent().hashCode()) refreshUI(); }
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(); } }