void moveUp(Layer layer) {
   if (canMove(layer)) {
     final Layer parentLayer = layer.getParent();
     final int layerIndex = layer.getParent().getChildIndex(layer.getId());
     parentLayer.getChildren().remove(layer);
     parentLayer.getChildren().add(layerIndex - 1, layer);
   }
 }
Esempio n. 2
0
  public static void displayImages(
      String title,
      RenderedImage[] images,
      AffineTransform[] imageToModelTransforms,
      int levelCount) {
    final LayerCanvas layerCanvas = new LayerCanvas();
    installLayerCanvasNavigation(layerCanvas);
    final Layer collectionLayer = layerCanvas.getLayer();
    for (int i = 0; i < images.length; i++) {
      final ImageLayer layer = new ImageLayer(images[i], imageToModelTransforms[i], levelCount);
      collectionLayer.getChildren().add(layer);
    }

    openFrame(layerCanvas, title, new Rectangle(0, 0, 512, 512));
  }
Esempio n. 3
0
 public static void displayImage(
     File location, String extension, AffineTransform imageToModelTransform, int levelCount) {
   final LayerCanvas layerCanvas = new LayerCanvas();
   installLayerCanvasNavigation(layerCanvas);
   final Layer collectionLayer = layerCanvas.getLayer();
   final MultiLevelSource source =
       FileMultiLevelSource.create(location, extension, imageToModelTransform, levelCount);
   final ImageLayer layer = new ImageLayer(source);
   collectionLayer.getChildren().add(layer);
   final Rectangle viewportBounds = new Rectangle(0, 0, 640, 480);
   layerCanvas.setPreferredSize(new Dimension(640, 480));
   layerCanvas.getViewport().setViewBounds(viewportBounds);
   layerCanvas.getViewport().zoom(layer.getModelBounds());
   openFrame(layerCanvas, location.getPath(), viewportBounds);
 }
  private synchronized void updateChildren() {

    // Collect all current mask layers
    LayerFilter layerFilter =
        layer -> {
          PropertySet conf = layer.getConfiguration();
          return conf.isPropertyDefined(MaskLayerType.PROPERTY_NAME_MASK)
              && conf.getValue(MaskLayerType.PROPERTY_NAME_MASK) != null;
        };
    List<Layer> maskLayers =
        LayerUtils.getChildLayers(
            LayerUtils.getRootLayer(this), LayerUtils.SEARCH_DEEP, layerFilter);
    HashMap<Mask, Layer> currentLayers = new HashMap<>();
    for (Layer maskLayer : maskLayers) {
      Mask mask = maskLayer.getConfiguration().getValue(MaskLayerType.PROPERTY_NAME_MASK);
      currentLayers.put(mask, maskLayer);
    }

    // Allign mask layers with available masks
    if (raster != null && getProduct() != null) {
      Mask[] availableMasks = getProduct().getMaskGroup().toArray(new Mask[0]);
      HashSet<Layer> unusedLayers = new HashSet<>(maskLayers);
      for (Mask availableMask : availableMasks) {
        // todo add all mask layers as soon as the masks have been scaled to fit the raster
        if (raster.getRasterSize().equals(availableMask.getRasterSize())) {
          Layer layer = currentLayers.get(availableMask);
          if (layer != null) {
            unusedLayers.remove(layer);
          } else {
            layer = createLayer(availableMask);
            getChildren().add(layer);
          }
          layer.setVisible(raster.getOverlayMaskGroup().contains(availableMask));
        }
      }

      // Remove unused layers
      for (Layer layer : unusedLayers) {
        layer.dispose();
        Layer layerParent = layer.getParent();
        if (layerParent != null) {
          layerParent.getChildren().remove(layer);
        }
      }
    }
  }
  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 = SnapApp.getDefault().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;
    }
  }