@Override public boolean performFinish(LayerSourcePageContext pageContext) { return pageContext.getCurrentPage().performFinish(); }
@Override public boolean isApplicable(LayerSourcePageContext pageContext) { return layerType.isValidFor(pageContext.getLayerContext()); }
@Override public void itemStateChanged(ItemEvent e) { LayerSourcePageContext context = getContext(); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE, styleList.getSelectedItem()); context.updateState(); updateMap(); } }
private Style getSelectedStyle(Style[] styles) { Style selectedStyle = (Style) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE); if (selectedStyle == null) { selectedStyle = styles[0]; context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE, styles[0]); } return selectedStyle; }
private static void createTransform(LayerSourcePageContext pageContext) { AffineTransform transform = new AffineTransform(); String worldFilePath = (String) pageContext.getPropertyValue(ImageFileLayerSource.PROPERTY_NAME_WORLD_FILE_PATH); if (worldFilePath != null && !worldFilePath.isEmpty()) { try { transform = Tools.loadWorldFile(worldFilePath); } catch (IOException e) { e.printStackTrace(); pageContext.showErrorDialog(e.getMessage()); } } pageContext.setPropertyValue(ImageFileLayerSource.PROPERTY_NAME_WORLD_TRANSFORM, transform); }
@Override public void changedUpdate(DocumentEvent e) { getContext().updateState(); } }
@Override protected void done() { final LayerSourcePageContext context = getContext(); context.getWindow().setCursor(Cursor.getDefaultCursor()); final ProductSceneView sceneView = context.getAppContext().getSelectedProductSceneView(); try { final Layer layer = get(); bounds.getMaxX(), bounds.getMaxY())); Style[] styles = (Style[]) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES); Style selectedStyle = (Style) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE); styleList.setModel(new DefaultComboBoxModel(styles)); styleList.setSelectedItem(selectedStyle); context.updateState();
@Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.addChoosableFileFilter(filter); fileChooser.setCurrentDirectory(getLastDirectory()); LayerSourcePageContext pageContext = getContext(); fileChooser.showOpenDialog(pageContext.getWindow()); if (fileChooser.getSelectedFile() != null) { String filePath = fileChooser.getSelectedFile().getPath(); imageHistoryModel.setSelectedItem(filePath); PropertyMap preferences = pageContext.getAppContext().getPreferences(); preferences.setPropertyString(LAST_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()); onFileSelected(pageContext, filePath); pageContext.updateState(); } }
@Override public AbstractLayerSourceAssistantPage getNextPage() { LayerSourcePageContext pageContext = getContext(); WebMapServer wms = null; WMSCapabilities wmsCapabilities = null; String wmsUrl = wmsUrlBox.getSelectedItem().toString(); if (wmsUrl != null && !wmsUrl.isEmpty()) { try { wms = getWms(pageContext.getWindow(), wmsUrl); wmsCapabilities = wms.getCapabilities(); } catch (Exception e) { e.printStackTrace(); pageContext.showErrorDialog("Failed to access WMS:\n" + e.getMessage()); } } history.copyInto(getContext().getAppContext().getPreferences()); if (wms != null && wmsCapabilities != null) { pageContext.setPropertyValue(WmsLayerSource.PROPERTY_NAME_WMS, wms); pageContext.setPropertyValue(WmsLayerSource.PROPERTY_NAME_WMS_CAPABILITIES, wmsCapabilities); return new WmsAssistantPage2(); } else { return null; } }
@Override public AbstractLayerSourceAssistantPage getNextPage() { final LayerSourcePageContext context = getContext(); fileHistoryModel.getHistory().copyInto(context.getAppContext().getPreferences()); String path = (String) fileHistoryModel.getSelectedItem(); if (path != null && !path.trim().isEmpty()) { try { final String oldPath = (String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH); if (!path.equals(oldPath)) { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH, path); final URL fileUrl = new File(path).toURI().toURL(); final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = FeatureUtils.getFeatureSource(fileUrl); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION, featureSource.getFeatures()); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, null); FeatureCollection fc = (FeatureCollection) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION); final CoordinateReferenceSystem featureCrs = fc.getSchema().getCoordinateReferenceSystem(); if (featureCrs == null) { return new ShapefileAssistantPage2(); } else { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, featureCrs); return new ShapefileAssistantPage3(); context.showErrorDialog("Failed to load ESRI shapefile:\n" + e.getMessage());
@Override protected void done() { try { final Layer layer = get(); ProductSceneView sceneView = getContext().getAppContext().getSelectedProductSceneView(); final Layer rootLayer = getContext().getLayerContext().getRootLayer(); rootLayer.getChildren().add(sceneView.getFirstImageLayerIndex(), layer); } catch (InterruptedException ignored) { } catch (ExecutionException e) { getContext().showErrorDialog("Could not load shape file: \n" + e.getMessage()); e.printStackTrace(); } } }
@Override public Component createPageComponent() { JPanel panel = new JPanel(new BorderLayout(4, 4)); panel.setBorder(new EmptyBorder(4, 4, 4, 4)); panel.add(new JLabel("Available layers:"), BorderLayout.NORTH); LayerSourcePageContext context = getContext(); modelCRS = (CoordinateReferenceSystem) context.getLayerContext().getCoordinateReferenceSystem(); WMSCapabilities wmsCapabilities = (WMSCapabilities) context.getPropertyValue( WmsLayerSource.PROPERTY_NAME_WMS_CAPABILITIES); layerTree = new JTree(new WmsTreeModel(wmsCapabilities.getLayer())); layerTree.setRootVisible(false); layerTree.setShowsRootHandles(true); layerTree.setExpandsSelectedPaths(true); layerTree.setCellRenderer(new MyDefaultTreeCellRenderer()); layerTree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); layerTree.getSelectionModel().addTreeSelectionListener(new LayerTreeSelectionListener()); panel.add(new JScrollPane(layerTree), BorderLayout.CENTER); infoLabel = new JLabel(" "); panel.add(infoLabel, BorderLayout.SOUTH); getContext().setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_LAYER, null); return panel; }
infoLabel.setText("Coordinate system not supported."); } else { RasterDataNode raster = context.getAppContext().getSelectedProductSceneView().getRaster(); AffineTransform g2mTransform = ImageManager.getImageToModelTransform(raster.getGeoCoding()); Rectangle2D bounds = g2mTransform.createTransformedShape( bounds.getMaxX(), bounds.getMaxY()); context.setPropertyValue(WmsLayerSource.PROPERTY_NAME_CRS_ENVELOPE, crsEnvelope); List<StyleImpl> styles = selectedLayer.getStyles(); if (!styles.isEmpty()) { context.setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_STYLE, styles.get(0)); } else { context.setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_STYLE, null); context.setPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_LAYER, selectedLayer); infoLabel.setForeground(Color.DARK_GRAY); infoLabel.setText(getLatLonBoundingBoxText(selectedLayer.getLatLonBoundingBox())); infoLabel.setText(""); context.updateState();
final PropertySet template = wmsType.createLayerConfig(getContext().getLayerContext()); final RasterDataNode raster = getContext().getAppContext().getSelectedProductSceneView().getRaster(); template.setValue(WmsLayerType.PROPERTY_NAME_RASTER, raster); template.setValue(WmsLayerType.PROPERTY_NAME_IMAGE_SIZE, mapImageSize); URL wmsUrl = (URL) context.getPropertyValue(WmsLayerSource.PROPERTY_NAME_WMS_URL); template.setValue(WmsLayerType.PROPERTY_NAME_URL, wmsUrl); StyleImpl selectedStyle = (StyleImpl) context.getPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_STYLE); String styleName = null; if (selectedStyle != null) { WebMapServer wms = (WebMapServer) context.getPropertyValue(WmsLayerSource.PROPERTY_NAME_WMS); final List<Layer> layerList = wms.getCapabilities().getLayerList(); Layer selectedLayer = (Layer) context.getPropertyValue(WmsLayerSource.PROPERTY_NAME_SELECTED_LAYER); template.setValue(WmsLayerType.PROPERTY_NAME_LAYER_INDEX, layerList.indexOf(selectedLayer)); CRSEnvelope crsEnvelope = (CRSEnvelope) context.getPropertyValue(WmsLayerSource.PROPERTY_NAME_CRS_ENVELOPE); template.setValue(WmsLayerType.PROPERTY_NAME_CRS_ENVELOPE, crsEnvelope); final com.bc.ceres.glayer.Layer layer = wmsType.createLayer(getContext().getLayerContext(), template); layer.setName(selectedLayer.getName()); return layer;
@Override public boolean performFinish(LayerSourcePageContext pageContext) { final Product product = pageContext.getAppContext().getSelectedProduct(); final RasterDataNode windu = product.getRasterDataNode(WINDU_NAME); final RasterDataNode windv = product.getRasterDataNode(WINDV_NAME); final WindFieldLayer fieldLayer = WindFieldLayerType.createLayer(windu, windv); pageContext.getLayerContext().getRootLayer().getChildren().add(0, fieldLayer); return true; }
private File getLastDirectory() { PropertyMap preferences = getContext().getAppContext().getPreferences(); String dirPath = preferences.getPropertyString(PROPERTY_LAST_DIR, System.getProperty("user.home")); File lastDir = new File(dirPath); if (!lastDir.isDirectory()) { lastDir = new File(System.getProperty("user.home")); } return lastDir; } }
@Override public AbstractLayerSourceAssistantPage getNextPage() { final LayerSourcePageContext context = getContext(); try { final Product product = context.getAppContext().getSelectedProduct(); final GeoPos referencePos = ProductUtils.getCenterGeoPos(product); final CoordinateReferenceSystem crs = crsSelectionPanel.getCrs(referencePos); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, crs); return new ShapefileAssistantPage3(); } catch (FactoryException e) { e.printStackTrace(); context.showErrorDialog("Could not create CRS:\n" + e.getMessage()); } return null; }
static boolean insertImageLayer(LayerSourcePageContext pageContext) { AffineTransform transform = (AffineTransform) pageContext.getPropertyValue(PROPERTY_NAME_WORLD_TRANSFORM); String imageFilePath = (String) pageContext.getPropertyValue(PROPERTY_NAME_IMAGE_FILE_PATH); try { ProductSceneView sceneView = pageContext.getAppContext().getSelectedProductSceneView(); final ImageFileLayerType type = LayerTypeRegistry.getLayerType(ImageFileLayerType.class); final PropertySet configuration = type.createLayerConfig(sceneView); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_IMAGE_FILE, new File(imageFilePath)); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_WORLD_TRANSFORM, transform); Layer layer = type.createLayer(sceneView, configuration); layer.setName(FileUtils.getFileNameFromPath(imageFilePath)); Layer rootLayer = sceneView.getRootLayer(); rootLayer.getChildren().add(sceneView.getFirstImageLayerIndex(), layer); return true; } catch (Exception e) { pageContext.showErrorDialog(e.getMessage()); return false; } } }
private void updateMap() { if (worker != null && !worker.isDone()) { try { worker.cancel(true); } catch (Throwable ignore) { // ok } } mapLabel.setText("<html><i>Loading map...</i></html>"); addToMapPanel(mapLabel); final LayerSourcePageContext context = getContext(); context.getWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); shapeFileLoaded = false; context.updateState(); worker = new ShapeFilePreviewLoader(context); worker.execute(); }
@Override public boolean validatePage() { String imageFilePath = (String) getContext().getPropertyValue(ImageFileLayerSource.PROPERTY_NAME_IMAGE_FILE_PATH); String worldFilePath = (String) getContext().getPropertyValue(ImageFileLayerSource.PROPERTY_NAME_WORLD_FILE_PATH); if (imageFilePath == null) { return false; } return new File(imageFilePath).exists() && (worldFilePath == null || new File(worldFilePath).exists()); }