@Override public void layerRemoved(LayerCollectionEvent e) { HashSet<ILayer> newSelection = new HashSet<ILayer>(); newSelection.addAll(Arrays.asList(selectedLayers)); ILayer[] affected = e.getAffected(); for (final ILayer layer : affected) { // Check active if (activeLayer == layer) { setActiveLayer(null); } // Check selection newSelection.remove(layer); layer.removeLayerListenerRecursively(openerListener); if (isOpen()) { try { layer.close(); } catch (LayerException e1) { LOGGER.warn(I18N.tr("Cannot close layer {0}", layer.getName()), e1); } } } setSelectedLayers(newSelection.toArray(new ILayer[newSelection.size()])); // checkIfHasToResetSRID(); }
private OWSContextType createJaxbMapContext() { // Create jaxbcontext data ObjectFactory ows_context_factory = new ObjectFactory(); net.opengis.ows._2.ObjectFactory ows_factory = new net.opengis.ows._2.ObjectFactory(); OWSContextType mapContextSerialisation = ows_context_factory.createOWSContextType(); // GeneralType mapContextSerialisation.setGeneral(ows_context_factory.createGeneralType()); // GeneralType:Bounding Box if (boundingBox != null) { BoundingBoxType bbox = ows_factory.createBoundingBoxType(); bbox.getLowerCorner().add(boundingBox.getMinX()); bbox.getLowerCorner().add(boundingBox.getMinY()); bbox.getUpperCorner().add(boundingBox.getMaxX()); bbox.getUpperCorner().add(boundingBox.getMaxY()); mapContextSerialisation.getGeneral().setBoundingBox(ows_factory.createBoundingBox(bbox)); } // GeneralType:Title Map<Locale, String> titles = description.getTitles(); if (!titles.isEmpty()) { // Take the first one for (Entry<Locale, String> entry : titles.entrySet()) { LanguageStringType title = ows_factory.createLanguageStringType(); title.setLang(LocalizedText.toLanguageTag(entry.getKey())); title.setValue(entry.getValue()); mapContextSerialisation.getGeneral().setTitle(title); break; // Ows-context does not support multi-lingual } } // GeneralType:Abstract Map<Locale, String> abstracts = description.getAbstractTexts(); if (!abstracts.isEmpty()) { // Take the first one for (Entry<Locale, String> entry : abstracts.entrySet()) { LanguageStringType mapAbstract = ows_factory.createLanguageStringType(); mapAbstract.setLang(LocalizedText.toLanguageTag(entry.getKey())); mapAbstract.setValue(entry.getValue()); mapContextSerialisation.getGeneral().setAbstract(mapAbstract); break; // Ows-context does not support multi-lingual } } // ResourceList ResourceListType rs = ows_context_factory.createResourceListType(); mapContextSerialisation.setResourceList(rs); // LayerList if (layerModel != null) { List<LayerType> rootLayerList = rs.getLayer(); ILayer[] rootLayers = layerModel.getChildren(); for (ILayer layer : rootLayers) { if (layer.isSerializable()) { rootLayerList.add(createJAXBFromLayer(layer, this)); } } } return mapContextSerialisation; }
@Override public boolean isLayerModelSpatial() { ILayer[] layers = getLayers(); for (ILayer l : layers) { if (!l.acceptsChilds()) { return true; } } return false; }
/** * Recursive function to parse a layer tree * * @param lt * @param parentLayer */ private void parseJaxbLayer(LayerType lt, ILayer parentLayer) throws LayerException { // Test if lt is a group if (!lt.getLayer().isEmpty() || (lt.getDataURL() == null)) { // it will create a LayerCollection parseJaxbLayerCollection(lt, parentLayer); } else { // it corresponding to a leaf layer // We need to read the data declaration and create the layer URLType dataUrl = lt.getDataURL(); if (dataUrl != null) { OnlineResourceType resType = dataUrl.getOnlineResource(); try { URI layerURI = new URI(resType.getHref()); // The resource is given as relative to MapContext location if (!layerURI.isAbsolute() && getLocation() != null) { try { // Resolve the relative resource ex: new Uri("myFile.shp") layerURI = getLocation().resolve(layerURI); } catch (IllegalArgumentException ex) { LOGGER.warn( "Error while trying to find an absolute path for an external resource", ex); } } // Get table name ILayer leafLayer = createLayer(layerURI); leafLayer.setDescription(new Description(lt)); leafLayer.setVisible(!lt.isHidden()); // Parse styles if (lt.isSetStyleList()) { for (StyleType st : lt.getStyleList().getStyle()) { if (st.isSetSLD()) { if (st.getSLD().isSetAbstractStyle()) { leafLayer.addStyle( new Style( (JAXBElement<net.opengis.se._2_0.core.StyleType>) st.getSLD().getAbstractStyle(), leafLayer)); } } } } parentLayer.addLayer(leafLayer); } catch (URISyntaxException ex) { throw new LayerException( I18N.tr("Unable to parse the href URI {0}.", resType.getHref()), ex); } catch (InvalidStyle ex) { throw new LayerException( I18N.tr("Unable to load the description of the layer {0}", lt.getTitle().toString()), ex); } } } }
@Override public void setSelectedLayers(ILayer[] selectedLayers) { checkIsOpen(); ArrayList<ILayer> filtered = new ArrayList<ILayer>(); for (ILayer layer : selectedLayers) { if (layerModel.getLayerByName(layer.getName()) != null) { filtered.add(layer); } } super.setSelectedLayers(filtered.toArray(new ILayer[filtered.size()])); // DEPRECATED LISTENERS for (MapContextListener listener : listeners) { listener.layerSelectionChanged(this); } }
@Override public String getDisplayModeByPosition(int columnPosition, int rowPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); return underlyingLayer.getDisplayModeByPosition( underlyingColumnPosition, underlyingRowPosition); }
@Override public LabelStack getRegionLabelsByXY(int x, int y) { LabelStack regionLabels = underlyingLayer.getRegionLabelsByXY(x, y); String regionName = getRegionName(); if (regionName != null) { regionLabels.addLabel(regionName); } return regionLabels; }
@Override public boolean doCommand(ILayerCommand command) { if (super.doCommand(command)) { return true; } if (underlyingLayer != null) { return underlyingLayer.doCommand(command); } return false; }
/** * Recursive function to parse a layer tree * * @param lt * @param parentLayer */ private void parseJaxbLayerCollection(LayerType lt, ILayer parentLayer) throws LayerException { LayerCollection layerCollection = new LayerCollection(lt); for (LayerType ltc : lt.getLayer()) { try { parseJaxbLayer(ltc, layerCollection); } catch (LayerException ex) { // The layer is not created if a layer exception is thrown // Create a warning, because the MapContext is loaded LOGGER.warn(I18N.tr("The layer has not been imported"), ex); } } parentLayer.addLayer(layerCollection); }
private static LayerType createJAXBFromLayer(ILayer layer, MapContext mapContext) { ObjectFactory ows_context_factory = new ObjectFactory(); LayerType layerType = ows_context_factory.createLayerType(); Description description = layer.getDescription(); description.initJAXBType(layerType); layerType.setHidden(!layer.isVisible()); ILayer[] childrens = layer.getChildren(); for (ILayer child : childrens) { if (child.isSerializable()) { layerType.getLayer().add(createJAXBFromLayer(child, mapContext)); } } // If not a Layer Collection if (!(layer instanceof LayerCollection) && layer.getStyles() != null) { StyleListType slt = ows_context_factory.createStyleListType(); layerType.setStyleList(slt); for (Style style : layer.getStyles()) { StyleType st = ows_context_factory.createStyleType(); slt.getStyle().add(st); SLDType sltType = ows_context_factory.createSLDType(); st.setSLD(sltType); sltType.setAbstractStyle(style.getJAXBElement()); } } // Serialisation of dataSource as a DataUrl string // Create jaxb instances URLType dataURL = ows_context_factory.createURLType(); if (!(layer instanceof LayerCollection)) { OnlineResourceType resource = ows_context_factory.createOnlineResourceType(); dataURL.setOnlineResource(resource); String resourceSerialisation = ""; URI srcUri = layer.getDataUri(); if (srcUri != null) { // If file, use MapContext relative path if (srcUri.getScheme().equalsIgnoreCase("file") && mapContext.getLocation() != null) { srcUri = URIUtility.relativize(mapContext.getLocation(), srcUri); } resourceSerialisation = srcUri.toString(); } resource.setHref(resourceSerialisation); if (resource.isSetHref()) { layerType.setDataURL(dataURL); } } return layerType; }
public AbstractNeuralNet parse(XmlElement xml) { // Resulting object AbstractNeuralNet result = (AbstractNeuralNet) xml.object(); // Unmarshal input layer result.inputLayer = xml.<InputLayer>get("input-layer"); // Unmarshal hidden layers result.hiddenLayers = xml.<ArrayList<LinkedLayer>>get("hidden-layers"); // Update neuron references ILayer<? extends INeuron> previousLayer = result.inputLayer; for (LinkedLayer hiddenLayer : result.hiddenLayers) { for (int i = 0; i < hiddenLayer.getNofneurons(); i++) { Link[] links = hiddenLayer.getNeuron(i).getLinks(); for (int j = 0; j < links.length; j++) { links[j].setTarget(hiddenLayer.getNeuron(i)); if (!links[j].isBroken() && j < previousLayer.getMaxnofneurons()) links[j].setOrigin(previousLayer.getNeuron(j)); else links[j].setOrigin(null); } } previousLayer = hiddenLayer; } // Unmarshal output layer result.outputLayer = xml.<LinkedLayer>get("output-layer"); // Update neuron references for (int i = 0; i < result.outputLayer.getNofneurons(); i++) { Link[] links = ((LinkedNeuron) result.outputLayer.getNeuron(i)).getLinks(); for (int j = 0; j < links.length; j++) { links[j].setTarget(result.outputLayer.getNeuron(i)); if (!links[j].isBroken() && j < previousLayer.getMaxnofneurons()) links[j].setOrigin(previousLayer.getNeuron(j)); else links[j].setOrigin(null); } } // Return result return result; }
@Override public LayerCell getCellByPosition(int columnPosition, int rowPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); LayerCell cell = underlyingLayer.getCellByPosition(underlyingColumnPosition, underlyingRowPosition); if (cell != null) { cell.updatePosition( this, underlyingToLocalColumnPosition(underlyingLayer, cell.getOriginColumnPosition()), underlyingToLocalRowPosition(underlyingLayer, cell.getOriginRowPosition()), underlyingToLocalColumnPosition(underlyingLayer, cell.getColumnPosition()), underlyingToLocalRowPosition(underlyingLayer, cell.getRowPosition())); } return cell; }
@Override public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); LabelStack configLabels = underlyingLayer.getConfigLabelsByPosition(underlyingColumnPosition, underlyingRowPosition); IConfigLabelAccumulator configLabelAccumulator = getConfigLabelAccumulator(); if (configLabelAccumulator != null) { configLabelAccumulator.accumulateConfigLabels(configLabels, columnPosition, rowPosition); } String regionName = getRegionName(); if (regionName != null) { configLabels.addLabel(regionName); } return configLabels; }
@Override public void layerAdded(LayerCollectionEvent e) { if (isOpen()) { for (final ILayer layer : e.getAffected()) { try { layer.open(); layer.addLayerListenerRecursively(openerListener); // checking & possibly setting SRID // checkSRID(layer); } catch (LayerException ex) { LOGGER.error(I18N.tr("Cannot open layer : {0} ", layer.getName()), ex); try { layer.getParent().remove(layer); } catch (LayerException e1) { LOGGER.error(I18N.tr("Cannot remove the layer {0}", layer.getName()), ex); } } } } }
public int getRowCount() { return underlyingLayer.getRowCount(); }
public int getPreferredRowCount() { return underlyingLayer.getPreferredRowCount(); }
public int getHeight() { return underlyingLayer.getHeight(); }
public int getPreferredHeight() { return underlyingLayer.getPreferredHeight(); }
public int getStartYOfRowPosition(int rowPosition) { int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); return underlyingLayer.getStartYOfRowPosition(underlyingRowPosition); }
public boolean isColumnPositionResizable(int columnPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); return underlyingLayer.isColumnPositionResizable(underlyingColumnPosition); }
/** * Underlying layers <i>must</i> load state first.<br> * If this is not done, {@link IStructuralChangeEvent} from underlying<br> * layers will reset caches after state has been loaded */ @Override public void loadState(String prefix, Properties properties) { super.loadState(prefix, properties); underlyingLayer.loadState(prefix, properties); }
public int getRowHeightByPosition(int rowPosition) { int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); return underlyingLayer.getRowHeightByPosition(underlyingRowPosition); }
public Object getDataValueByPosition(int columnPosition, int rowPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); return underlyingLayer.getDataValueByPosition(underlyingColumnPosition, underlyingRowPosition); }
public int getColumnWidthByPosition(int columnPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); return underlyingLayer.getColumnWidthByPosition(underlyingColumnPosition); }
public boolean isRowPositionResizable(int rowPosition) { int underlyingRowPosition = localToUnderlyingRowPosition(rowPosition); return underlyingLayer.isRowPositionResizable(underlyingRowPosition); }
public int getStartXOfColumnPosition(int columnPosition) { int underlyingColumnPosition = localToUnderlyingColumnPosition(columnPosition); return underlyingLayer.getStartXOfColumnPosition(underlyingColumnPosition); }
public int getColumnPositionByX(int x) { return underlyingLayer.getColumnPositionByX(x); }
@Override public void configure(ConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry) { underlyingLayer.configure(configRegistry, uiBindingRegistry); super.configure(configRegistry, uiBindingRegistry); }
@Override public ILayerPainter getLayerPainter() { return underlyingLayer.getLayerPainter(); }
public int getRowPositionByY(int y) { return underlyingLayer.getRowPositionByY(y); }