private int editExpression(String[] value, final boolean booleanExpected) { Product product; try { product = mosaicModel.getReferenceProduct(); } catch (IOException ioe) { appContext.handleError(ioe.getMessage(), ioe); return 0; } if (product == null) { final String msg = "No source product specified."; appContext.handleError(msg, new IllegalStateException(msg)); return 0; } final ProductExpressionPane pep; if (booleanExpected) { pep = ProductExpressionPane.createBooleanExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } else { pep = ProductExpressionPane.createGeneralExpressionPane(new Product[]{product}, product, appContext.getPreferences()); } pep.setCode(value[0]); final int i = pep.showModalDialog(appContext.getApplicationWindow(), value[0]); if (i == ModalDialog.ID_OK) { value[0] = pep.getCode(); } return i; }
protected void showOpenInAppInfo() { final String message = MessageFormat.format( "<html>The target product has successfully been created and opened in {0}.<br><br>" + "Actual processing of source to target data will be performed only on demand,<br>" + "for example, if the target product is saved or an image view is opened.", appContext.getApplicationName() ); showSuppressibleInformationDialog(message, "openInAppInfo"); }
private Product[] filterProducts() { List<Product> currentlyOpenedProducts = Arrays.asList(listModel.getSourceProducts()); List<Product> productManagerProducts = Arrays.asList(appContext.getProductManager().getProducts()); ArrayList<Product> result = new ArrayList<>(); for (Product product : productManagerProducts) { if (!currentlyOpenedProducts.contains(product) && productFilter.accept(product)) { result.add(product); } } return result.toArray(new Product[result.size()]); }
private String editExpression(String expression) { final Product product = binningFormModel.getContextProduct(); if (product == null) { return null; } final ProductExpressionPane expressionPane; expressionPane = ProductExpressionPane.createBooleanExpressionPane(new Product[]{product}, product, appContext.getPreferences()); expressionPane.setCode(expression); final int i = expressionPane.showModalDialog(appContext.getApplicationWindow(), "Expression Editor"); if (i == ModalDialog.ID_OK) { return expressionPane.getCode(); } return null; }
@Override public void actionPerformed(ActionEvent e) { PropertyMap preferences = appContext.getPreferences(); String lastDir = preferences.getPropertyString(LAST_OPEN_PLACEMARK_DIR, SystemUtils.getUserHomeDir().getPath()); appContext.handleError(String.format("Error occurred while reading file: %s", selectedFile), ioe); } finally { if (reader != null) {
private File getInputProductDir() { final String path = applicationContext.getPreferences().getPropertyString(INPUT_PRODUCT_DIR_KEY); final File inputProductDir; if (path != null) { inputProductDir = new File(path); } else { inputProductDir = null; } return inputProductDir; } }
protected SingleTargetProductDialog(AppContext appContext, String title, int buttonMask, String helpID, TargetProductSelectorModel model, boolean alwaysWriteOutput) { super(appContext.getApplicationWindow(), title, buttonMask, helpID); this.appContext = appContext; targetProductSelector = new TargetProductSelector(model, alwaysWriteOutput); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); String saveDir = appContext.getPreferences().getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); targetProductSelector.getModel().setProductDir(new File(saveDir)); if (!alwaysWriteOutput) { targetProductSelector.getOpenInAppCheckBox().setText("Open in " + appContext.getApplicationName()); } targetProductSelector.getModel().getValueContainer().addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("saveToFileSelected") || evt.getPropertyName().equals("openInAppSelected")) { updateRunButton(); } }); AbstractButton button = getButton(ID_APPLY); button.setText("Run"); button.setMnemonic('R'); updateRunButton(); }
@Override protected void onApply() { if (!canApply()) { return; } TargetProductSelectorModel model = targetProductSelector.getModel(); String productDirPath = model.getProductDir().getAbsolutePath(); appContext.getPreferences().setPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, productDirPath); try { HashMap<String, Product> sourceProducts = ioParametersPanel.createSourceProductsMap(); Product currentSourceProduct = sourceProducts.get(RECENT_PRODUCT_PROPERTY); Product previousSourceProduct = sourceProducts.get(PREVIOUS_PRODUCT_PROPERTY); ProductManager productManager = appContext.getProductManager(); Component parentComponent = getJDialog(); TargetProductSwingWorker worker = new TargetProductSwingWorker(parentComponent, productManager, model, currentSourceProduct, previousSourceProduct, this.parameterSupport.getParameterMap()); worker.executeWithBlocking(); // start the thread } catch (Throwable t) { handleInitialisationError(t); return; } }
product = mosaicModel.getReferenceProduct(); } catch (IOException ioe) { appContext.handleError(ioe.getMessage(), ioe); return; final BandChooser bandChooser = new BandChooser(appContext.getApplicationWindow(), "Band Chooser", null,
public GraphBuilderDialog(final AppContext theAppContext, final String title, final String helpID, final boolean allowGraphBuilding) { super(theAppContext.getApplicationWindow(), title, 0, helpID); this.allowGraphBuilding = allowGraphBuilding; appContext = theAppContext; graphEx = new GraphExecuter(); graphEx.addObserver(this); String lastDir = SnapApp.getDefault().getPreferences().get(LAST_GRAPH_PATH, ResourceUtils.getGraphFolder("").toFile().getAbsolutePath()); if (new File(lastDir).exists()) { SnapApp.getDefault().getPreferences().put(LAST_GRAPH_PATH, lastDir); } initUI(); }
public void actionPerformed(ActionEvent event) { final String expression = editExpression(validPixelExpressionField.getText()); if (expression != null) { try { binningFormModel.setProperty(BinningFormModel.PROPERTY_KEY_MASK_EXPR, expression); } catch (ValidationException e) { appContext.handleError("Invalid expression", e); } } } });
final Product existingProduct = appContext.getProductManager().getProduct(productName); if (existingProduct != null) { String message = MessageFormat.format( "<html>A product with the name ''{0}'' is already opened in {1}.<br><br>" + "Do you want to continue?", productName, appContext.getApplicationName() ); final int answer = JOptionPane.showConfirmDialog(getJDialog(), message,
public synchronized void initProducts() { productListModel.removeAllElements(); if (enableEmptySelection) { productListModel.addElement(null); } for (Product product : appContext.getProductManager().getProducts()) { addProduct(product); } Product selectedProduct = appContext.getSelectedProduct(); final ProductNode productNode = Utilities.actionsGlobalContext().lookup(ProductNode.class); if (productNode != null) { // user would want to apply operation to the selected productNode rather than the productSceneView selectedProduct = productNode.getProduct(); } if (enableEmptySelection) { productListModel.setSelectedItem(null); } else if (selectedProduct != null && productFilter.accept(selectedProduct)) { productListModel.setSelectedItem(selectedProduct); } appContext.getProductManager().addListener(productManagerListener); }
@Override public int show() { ioForm.addProduct(appContext.getSelectedProduct()); return super.show(); }
private File getInputProductDir() { final String path = applicationContext.getPreferences().getPropertyString(INPUT_PRODUCT_DIR_KEY); final File inputProductDir; if (path != null) { inputProductDir = new File(path); } else { inputProductDir = null; } return inputProductDir; }
@Override public void propertyChange(PropertyChangeEvent evt) { final Product product = (Product) evt.getNewValue(); final TargetProductSelectorModel selectorModel = targetProductSelector.getModel(); if (product != null) { final String formatName = product.getProductReader().getReaderPlugIn().getFormatNames()[0]; final ProductIOPlugInManager ioPlugInManager = ProductIOPlugInManager.getInstance(); final Iterator<ProductWriterPlugIn> writerIterator = ioPlugInManager.getWriterPlugIns(formatName); if (writerIterator.hasNext()) { selectorModel.setFormatName(formatName); } else { final String errMsg = "Cannot write to update product."; final String iseMsg = String.format("No product writer found for format '%s'", formatName); appContext.handleError(errMsg, new IllegalStateException(iseMsg)); } final File fileLocation = product.getFileLocation(); final String fileName = FileUtils.getFilenameWithoutExtension(fileLocation); final File fileDir = fileLocation.getParentFile(); selectorModel.setProductName(fileName); selectorModel.setProductDir(fileDir); } else { selectorModel.setFormatName(ProductIO.DEFAULT_FORMAT_NAME); selectorModel.setProductName("Multi-size Mosaic"); String homeDirPath = SystemUtils.getUserHomeDir().getPath(); final PropertyMap prefs = appContext.getPreferences(); String saveDir = prefs.getPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, homeDirPath); selectorModel.setProductDir(new File(saveDir)); } } }
appContext.getPreferences().setPropertyString(SaveProductAsAction.PREFERENCES_KEY_LAST_PRODUCT_DIR, productDir); worker.executeWithBlocking(); } else if (targetProductSelector.getModel().isOpenInAppSelected()) { appContext.getProductManager().addProduct(targetProduct); showOpenInAppInfo();
final ModalDialog outputParametersDialog = new OutputParametersDialog(appContext.getApplicationWindow(), sourceProduct, workCopy); outputParametersDialog.setContent(form); appContext.handleError("Could not create a 'Coordinate Reference System'.\n" + e.getMessage(), e);
public MultiGraphDialog(final AppContext theAppContext, final String title, final String helpID, final boolean useSourceSelector) { super(theAppContext.getApplicationWindow(), title, ID_APPLY_CLOSE_HELP, helpID); appContext = theAppContext;
protected void handleProcessingError(Throwable t) { String msg; if (t instanceof OperatorCancelException) { return; } if (isInternalException(t)) { msg = MessageFormat.format("An internal error occurred during the target product processing.\n{0}", formatThrowable(t)); } else { msg = MessageFormat.format("A problem occurred during the target product processing.\n{0}", formatThrowable(t)); } appContext.handleError(msg, t); }