private void onRgbaExpressionChanged() { if (settingRgbaExpressions) { return; } final ProfileItem profileItem = getSelectedProfileItem(); if (profileItem != null) { if (isSelectedProfileModified()) { profileBox.revalidate(); profileBox.repaint(); } } final String[] rgbaExpressions = getRgbaExpressions(); final int defaultProductIndex = ArrayUtils.getElementIndex(product, openedProducts); try { if (!BandArithmetic.areRastersEqualInSize(openedProducts, defaultProductIndex, rgbaExpressions)) { referencedRastersAreCompatibleLabel.setText("Referenced rasters are not of the same size"); referencedRastersAreCompatibleLabel.setForeground(warnMsgColor); } else { referencedRastersAreCompatibleLabel.setText("Expressions are valid"); referencedRastersAreCompatibleLabel.setForeground(okMsgColor); } } catch (ParseException e) { referencedRastersAreCompatibleLabel.setText("Expressions are invalid"); referencedRastersAreCompatibleLabel.setForeground(warnMsgColor); } updateUIState(); }
@Override protected JPanel createPanel(BindingContext context) { return new RGBImageProfilePane(new DefaultPropertyMap()); }
public void addProfiles(RGBImageProfile[] profiles) { for (RGBImageProfile profile : profiles) { addNewProfile(profile); } setRgbaExpressionsFromSelectedProfile(); }
private boolean isSelectedProfileModified() { final ProfileItem profileItem = getSelectedProfileItem(); final String[] profileRgbaExpressions = profileItem.getProfile().getRgbaExpressions(); final String[] userRgbaExpressions = getRgbaExpressions(); for (int i = 0; i < profileRgbaExpressions.length; i++) { final String userRgbaExpression = userRgbaExpressions[i]; final String profileRgbaExpression = profileRgbaExpressions[i]; if (!profileRgbaExpression.equals(userRgbaExpression)) { return true; } } return false; }
profileBox.setEditable(false); profileBox.setName("profileBox"); setPreferredWidth(profileBox, 200); rgbaExprBoxes[i] = createRgbaBox(bandNames); rgbaExprBoxes[i].setName("rgbExprBox_" + i); for (int i = 0; i < n; i++) { c3.gridy = i; addColorComponentRow(p3, c3, i); layout.setRowWeightY(3, 1.0); layout.setTablePadding(10, 10); setLayout(layout); add(p1); add(p3); layout.setCellFill(2, 0, TableLayout.Fill.NONE); layout.setCellAnchor(2, 0, TableLayout.Anchor.NORTHEAST); add(referencedRastersAreCompatibleLabel); add(storeInProductCheck); add(layout.createVerticalSpacer()); addProfiles(registeredProfiles); if (this.product != null) { final RGBImageProfile productProfile = RGBImageProfile.getCurrentProfile(this.product); if (productProfile.isValid()) { final RGBImageProfile similarProfile = findMatchingProfile(productProfile); if (similarProfile != null) { selectProfile(similarProfile);
public void openProductSceneViewRGB(Product rgbProduct, final String helpId) { final Product[] openedProducts = SnapApp.getDefault().getProductManager().getProducts(); final int[] defaultBandIndices = getDefaultBandIndices(rgbProduct); final RGBImageProfilePane profilePane = new RGBImageProfilePane(SnapApp.getDefault().getPreferencesPropertyMap(), rgbProduct, openedProducts, defaultBandIndices); final String title = "Select RGB-Image Channels"; final boolean ok = profilePane.showDialog(SnapApp.getDefault().getMainFrame(), title, helpId); if (!ok) { return; } final String[] rgbaExpressions = profilePane.getRgbaExpressions(); if (profilePane.getStoreProfileInProduct()) { RGBImageProfile.storeRgbaExpressions(rgbProduct, rgbaExpressions); } final String sceneName = createSceneName(rgbProduct, profilePane.getSelectedProfile(), "RGB"); openProductSceneViewRGB(sceneName, rgbProduct, rgbaExpressions); }
@Test public void testSelectProfile_6() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[0]; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNull(profile); }
private void invokeExpressionEditor(final int colorIndex) { final Window window = SwingUtilities.getWindowAncestor(this); final String title = "Edit " + getComponentName(colorIndex) + " Expression"; if (product != null) { final ExpressionPane pane; final Product[] products = getCompatibleProducts(product, openedProducts); pane = ProductExpressionPane.createGeneralExpressionPane(products, product, preferences); pane.setCode(getExpression(colorIndex)); int status = pane.showModalDialog(window, title); if (status == ModalDialog.ID_OK) { setExpression(colorIndex, pane.getCode()); } } else { final JTextArea textArea = new JTextArea(8, 48); textArea.setFont(EXPRESSION_FONT); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setText(getExpression(colorIndex)); final ModalDialog modalDialog = new ModalDialog(window, title, ModalDialog.ID_OK_CANCEL, ""); final JPanel panel = new JPanel(new BorderLayout(2, 2)); panel.add(new JLabel("Expression:"), BorderLayout.NORTH); panel.add(new JScrollPane(textArea), BorderLayout.CENTER); modalDialog.setContent(panel); final int status = modalDialog.show(); if (status == ModalDialog.ID_OK) { setExpression(colorIndex, textArea.getText()); } } }
private void performSaveAs() { File file = promptForSaveFile(); if (file == null) { return; String[] rgbaExpressions = getRgbaExpressions(); Set<Integer> productRefs = new HashSet<>(); for (String expression : rgbaExpressions) { addNewProfile(profile);
private void performOpen() { final SnapFileChooser snapFileChooser = new SnapFileChooser(getProfilesDir()); snapFileChooser.setFileFilter( new SnapFileFilter("RGB-PROFILE", RGBImageProfile.FILENAME_EXTENSION, "RGB-Image Profile Files")); return; addNewProfile(profile);
public RGBImageProfile findMatchingProfile(RGBImageProfile profile) { // search in internal profiles first... RGBImageProfile matchingProfile = findMatchingProfile(profile, true); if (matchingProfile == null) { // ...then in non-internal profiles matchingProfile = findMatchingProfile(profile, false); } return matchingProfile; }
@Test public void testNoDescriptionSet() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription(null); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); } }
@Test public void testSelectProfile_1() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), new RGBImageProfile("p2", new String[]{"", "", ""}, new String[]{"some_different_type", "*name_*3", null}), new RGBImageProfile("p3", new String[]{"", "", ""}, new String[]{"*me_ty*", "*name_*3", null}), new RGBImageProfile("p4", new String[]{"", "", ""}, new String[]{"*me_ty*", "*name_*3", "*s some*"}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); assertSame(rgbImageProfiles[3], profile); // all patterns match }
@Test public void testSelectProfile_4() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), new RGBImageProfile("p2", new String[]{"", "", ""}, new String[]{"some_different_type", "*name_*3", null}), new RGBImageProfile("p3", new String[]{"", "", ""}, new String[]{"strange type", "*name_*3", null}), new RGBImageProfile("p4", new String[]{"", "", ""}, new String[]{"strange type", "*name_*3", "*s some*"}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); assertSame(rgbImageProfiles[3], profile); // name and description match }
@Test public void testSelectProfile_2() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), new RGBImageProfile("p2", new String[]{"", "", ""}, new String[]{"some_different_type", "*name_*3", null}), new RGBImageProfile("p3", new String[]{"", "", ""}, new String[]{"*me_ty*", null, null}), new RGBImageProfile("p4", new String[]{"", "", ""}, new String[]{null, "*name_*3", "*s some*"}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); assertSame(rgbImageProfiles[2], profile); // type matches }
@Test public void testSelectProfile_3() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), new RGBImageProfile("p2", new String[]{"", "", ""}, new String[]{"some_different_type", "*name_*3", null}), new RGBImageProfile("p3", new String[]{"", "", ""}, new String[]{null, "*name_*3", null}), new RGBImageProfile("p4", new String[]{"", "", ""}, new String[]{null, "*name_*3", "*s some*"}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); assertSame(rgbImageProfiles[3], profile); // name and description match }
@Test public void testSelectProfile_5() throws Exception { RGBImageProfile[] rgbImageProfiles = new RGBImageProfile[] { new RGBImageProfile("p1", new String[]{"", "", ""}, new String[]{"matches", "not at", "all"}), new RGBImageProfile("p2", new String[]{"", "", ""}, new String[]{"some_different_type", "*name_*3", null}), new RGBImageProfile("p3", new String[]{"", "", ""}, new String[]{"*me_ty*", "*name_*3", null}), new RGBImageProfile("p4", new String[]{"", "", ""}, new String[]{"*me_ty*", "*name_*3", null}), }; Product product = new Product("some_name_123", "some_type_123", 1, 1); product.setDescription("This is some description text."); RGBImageProfile profile = RGBImageProfilePane.findProfileForProductPattern(rgbImageProfiles, product); assertNotNull(profile); assertSame(rgbImageProfiles[2], profile); // equal, so earlier profile is chosen }