/** * Displays a modal dialog with the provided information message text. * * @param message The message text to be displayed. */ public static void showInformation(String message) { showInformation(message, null); }
/** * Displays a modal dialog with the provided information message text. * * @param message The message text to be displayed. * @param preferencesKey If not {@code null}, a checkbox is displayed, and if checked the dialog will not be displayed again which lets users store the answer */ public static void showInformation(String message, String preferencesKey) { showInformation(Bundle.LBL_Information(), message, preferencesKey); }
public static void openInBrowser(URI uri) { boolean desktopSupported = Desktop.isDesktopSupported(); boolean browseSupported = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); if (desktopSupported && browseSupported) { try { Desktop.getDesktop().browse(uri); } catch (Throwable t) { Dialogs.showError(String.format("Failed to open URL:\n%s:\n%s", uri, t.getMessage())); } } else { SystemUtils.copyToClipboard(uri.toString()); Dialogs.showInformation("The URL has been copied to your Clipboard\n"); } }
public static boolean checkUniqueParameterName(ToolAdapterOperatorDescriptor operator, String parameterName, ToolParameterDescriptor descriptorToEdit) { int count = operator.getToolParameterDescriptors().size(); for (int i=0; i<count; i++) { ToolParameterDescriptor param = operator.getToolParameterDescriptors().get(i); if (descriptorToEdit != param) { if (param.getName().equals(parameterName)) { Dialogs.showInformation("Duplicate parameter name."); return false; } } } return true; }
private void maybeShowTip() { if (!tipShown) { final String message = "<html>Tip: If you press the SHIFT key while moving the mouse cursor over<br/>" + "an image, " + SnapApp.getDefault().getInstanceName() + " adjusts the diagram axes " + "to the local values at the<br/>" + "current pixel position, if you release the SHIFT key again, then the<br/>" + "min/max are accumulated again.</html>"; Dialogs.showInformation("Spectrum Tip", message, SUPPRESS_MESSAGE_KEY); tipShown = true; } }
/** * Shows an information dialog on top of this dialog. * The shown dialog will contain a user option allowing to not show the message anymore. * * @param infoMessage The message. * @param propertyName The (simple) property name used to store the user option in the application's preferences. */ public void showSuppressibleInformationDialog(String infoMessage, String propertyName) { Dialogs.showInformation(getTitle(), infoMessage, getQualifiedPropertyName(propertyName)); }
@Override protected void onOther() { try { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showOpenDialog(getButton(ID_OTHER)) == JFileChooser.APPROVE_OPTION) { File targetFolder = fileChooser.getSelectedFile(); newOperatorDescriptor.setSource(ToolAdapterOperatorDescriptor.SOURCE_PACKAGE); onOK(); ModulePackager.packModule(newOperatorDescriptor, new File(targetFolder, newOperatorDescriptor.getAlias() + ".nbm")); Dialogs.showInformation(String.format(Bundle.MSG_Export_Complete_Text(), targetFolder.getAbsolutePath()), null); } } catch (IOException e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } }
@Override public void done() { try { get(); Dialogs.showInformation(dialogTitle, "Pixel geo-coding has been attached.", null); } catch (Exception e) { Throwable cause = e; if (e instanceof ExecutionException) { cause = e.getCause(); } String msg = "An internal error occurred:\n" + e.getMessage(); if (cause instanceof IOException) { msg = "An I/O error occurred:\n" + e.getMessage(); } Dialogs.showError(dialogTitle, msg); } finally { UIUtils.setRootFrameDefaultCursor(mainFrame); } } };
private static void exportVectorDataNode(VectorDataNode vectorNode, File file, ProgressMonitor pm) throws Exception { Map<Class<?>, List<SimpleFeature>> featureListMap = createGeometryToFeaturesListMap(vectorNode); if (featureListMap.size() > 1) { final String msg = "The selected geometry contains different types of shapes.\n" + "Each type of shape will be exported as a separate shapefile."; Dialogs.showInformation(Bundle.CTL_ExportGeometryAction_DialogTitle(), msg, ExportGeometryAction.class.getName() + ".exportInfo"); } Set<Map.Entry<Class<?>, List<SimpleFeature>>> entries = featureListMap.entrySet(); pm.beginTask("Writing ESRI Shapefiles...", featureListMap.size()); try { for (Map.Entry<Class<?>, List<SimpleFeature>> entry : entries) { writeEsriShapefile(entry.getKey(), entry.getValue(), file); pm.worked(1); } } finally { pm.done(); } }
Dialogs.showInformation(TITLE, String.format("No geo-coding information for %s.", view.getRaster().getName()), null); return;
@Override protected void onOK() { ToolAdapterOperatorDescriptor[] selection = ((AdapterListModel) this.operatorsTable.getModel()).getSelectedItems(); if (selection.length > 0) { this.descriptor = this.descriptorForm.applyChanges(); final Map<OSFamily, org.esa.snap.core.gpf.descriptor.dependency.Bundle> bundles = this.bundleForm.applyChanges(); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showOpenDialog(getButton(ID_OTHER)) == JFileChooser.APPROVE_OPTION) { File targetFolder = fileChooser.getSelectedFile(); final String nbmName = this.descriptor.getName() + ".nbm"; ProgressWorker worker = new ProgressWorker("Export Module Suite", "Creating NetBeans module suite " + nbmName, () -> { try { ModulePackager.packModules(this.descriptor, new File(targetFolder, nbmName), bundles, selection); Dialogs.showInformation(String.format(Bundle.MSG_Export_Complete_Text(), targetFolder.getAbsolutePath()), null); } catch (IOException e) { SystemUtils.LOG.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } }); worker.executeWithBlocking(); super.onOK(); } } else { Dialogs.showWarning("Please select at least one adapter"); } }
dialog.setBounds(x, y, w, h); Dialogs.showInformation(Bundle.LBL_FilterWindow_Title(), Bundle.TXT_FilterWindow_Hint(), "filterWindow.moreOptions");
@Override public void done() { try { Throwable value; try { value = get(); } catch (Exception e) { value = e; } String dialogTitle = Bundle.CTL_DetachPixelGeoCodingDialogTitle(); if (value != null) { Dialogs.showError(dialogTitle, "An internal error occurred:\n" + value.getMessage()); } else { Dialogs.showInformation(dialogTitle, "Pixel geo-coding has been detached.", null); } } finally { UIUtils.setRootFrameDefaultCursor(SnapApp.getDefault().getMainFrame()); } } };
private void exportToWkt() { SimpleFeatureFigure selectedFeatureFigure = getSimpleFeatureFigure(); if (selectedFeatureFigure == null) { Dialogs.showInformation(DLG_TITLE, "Please select a geometry.", null); return;
final Session session = createSession(sessionFile); SessionIO.getInstance().writeSession(session, sessionFile); Dialogs.showInformation(TITLE, "Session saved.", null); } catch (Exception e) { e.printStackTrace();
@Override public void actionPerformed(ActionEvent e) { ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); final GeoCoding geoCoding = view.getProduct().getSceneGeoCoding(); boolean isGeographic = false; if (geoCoding instanceof MapGeoCoding) { MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding; MapTransformDescriptor transformDescriptor = mapGeoCoding.getMapInfo() .getMapProjection().getMapTransform().getDescriptor(); String typeID = transformDescriptor.getTypeID(); if (typeID.equals(IdentityTransformDescriptor.TYPE_ID)) { isGeographic = true; } } else if (geoCoding instanceof CrsGeoCoding) { isGeographic = CRS.equalsIgnoreMetadata(geoCoding.getMapCRS(), DefaultGeographicCRS.WGS84); } if (isGeographic) { exportImage(view); } else { String message = "Product must be in ''Geographic Lat/Lon'' projection."; Dialogs.showInformation(message, null); } }
/** * Performs the actual "export Mask Pixels" command. */ private void exportVectorDataNode() { SnapApp snapApp = SnapApp.getDefault(); if (vectorDataNode.getFeatureCollection().isEmpty()) { Dialogs.showInformation(Bundle.CTL_ExportGeometryAction_DialogTitle(), "The selected geometry is empty. Nothing to export.", null); return; } final File file = promptForFile(vectorDataNode.getName()); if (file == null) { return; } final SwingWorker<Exception, Object> swingWorker = new ExportVectorNodeSwingWorker(snapApp, vectorDataNode, file); UIUtils.setRootFrameWaitCursor(snapApp.getMainFrame()); snapApp.setStatusBarMessage("Exporting Geometry..."); swingWorker.execute(); }
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) { if (scatterpointsDataset.getItemCount(0) > 1) { final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]); final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line"); final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey()); for (int i = 0; i < regressionData.getItemCount(); i++) { XYDataItem item = regressionData.getDataItem(i); final double x = item.getXValue(); final double y = item.getYValue(); xyIntervalRegression.add(x, x, x, y, y, y); } return xyIntervalRegression; } else { Dialogs.showInformation("Unable to compute regression line.\n" + "At least 2 values are needed to compute regression coefficients."); return null; } }
private boolean editAggregatorItem(AggregatorItem aggregatorItem, int rowIndex) { Product contextProduct = binningFormModel.getContextProduct(); if (contextProduct == null) { Dialogs.showInformation("Please select source products before adding aggregators."); return false; } String[] varNames = getVariableNames(binningFormModel.getVariableConfigs()); String[] bandNames = contextProduct.getBandNames(); String[] tiePointGridNames = contextProduct.getTiePointGridNames(); String[] maskNames = contextProduct.getMaskGroup().getNodeNames(); String[] sourceNames = StringUtils.addArrays(varNames, bandNames); sourceNames = StringUtils.addArrays(sourceNames, tiePointGridNames); sourceNames = StringUtils.addArrays(sourceNames, maskNames); boolean isNewAggregatorItem = rowIndex < 0; ModalDialog aggregatorDialog = new AggregatorItemDialog(SwingUtilities.getWindowAncestor(grid), sourceNames, aggregatorItem, isNewAggregatorItem); int result = aggregatorDialog.show(); if (result == ModalDialog.ID_OK) { if (isNewAggregatorItem) { addDataRow(aggregatorItem); } else { updateDataRow(aggregatorItem, rowIndex); } return true; } return false; }
@Override public void setValue(String newValue) { try { final Product product = raster.getProduct(); final RasterDataNode[] refRasters = BandArithmetic.getRefRasters(newValue, product); if (refRasters.length > 0 && (!BandArithmetic.areRastersEqualInSize(product, newValue) || refRasters[0].getRasterHeight() != raster.getRasterHeight() || refRasters[0].getRasterWidth() != raster.getRasterWidth())) { Dialogs.showInformation("Referenced rasters must all be the same size", null); } else { String oldValue = raster.getValidPixelExpression(); performUndoableProductNodeEdit("Edit Valid-Pixel Expression", raster, node -> { node.setValidPixelExpression(newValue); updateImages(node, true); }, node -> { node.setValidPixelExpression(oldValue); updateImages(node, true); } ); } } catch (ParseException e) { Dialogs.showError("Expression is invalid: " + e.getMessage()); } } }