/** * Finds all entities of a type on the map. * * @param entityType a type of entity * @return the list of the entities of this kind on the map */ public List<MapEntity> getEntitiesOfType(EntityType entityType) { List<MapEntity> list = new LinkedList<MapEntity>(); for (Layer layer : Layer.values()) { list.addAll(allEntities[layer.getId()].getEntitiesOfType(entityType)); } return list; }
/** Initializes the object. */ private void initialize() { this.allEntities = new MapEntities[3]; for (Layer layer : Layer.values()) { this.allEntities[layer.getId()] = new MapEntities(); } this.entitySelection = new MapEntitySelection(this); this.history = new MapEditorHistory(); }
/** * Sets the entities of the map. * * @param allEntities an array of 3 MapEntity sets: a set for each layer (this array is copied) */ public void setAllEntities(MapEntities[] allEntities) { for (Layer layer : Layer.values()) { this.allEntities[layer.getId()] = new MapEntities(allEntities[layer.getId()]); } setChanged(); notifyObservers(); }
/** * Returns the total number of active entities of the map. * * @return the total number of active entities of the map. */ public int getNbDynamicEntities() { int nbDynamicEntities = 0; // count the dynamic entities of each layer for (Layer layer : Layer.values()) { nbDynamicEntities += allEntities[layer.getId()].getNbDynamicEntities(); } return nbDynamicEntities; }
/** * Returns the total number of entities of the map. * * @return the total number of entities of the map. */ public int getNbEntities() { int nbEntities = 0; // count the entities of each layer for (Layer layer : Layer.values()) { nbEntities += allEntities[layer.getId()].size(); } return nbEntities; }
/** * Returns an entity, specifying its type and its name. * * @param type the type of entity * @param name the name of the entity * @return the entity, or null if there is no entity with this name */ public MapEntity getEntityWithName(EntityType type, String name) { for (Layer layer : Layer.values()) { MapEntity entity = allEntities[layer.getId()].getEntityWithName(type, name); if (entity != null) { return entity; } } return null; }
/** * Returns the highest layer where a specified rectangle overlaps an existing entity. * * @param rectangle a rectangle * @return the highest layer where an entity exists in this rectangle, or Layer.LOW if there is * nothing here */ public Layer getLayerInRectangle(Rectangle rectangle) { Layer[] layers = {Layer.HIGH, Layer.INTERMEDIATE, Layer.LOW}; for (Layer layer : layers) { for (MapEntity entity : allEntities[layer.getId()]) { if (rectangle.intersects(entity.getPositionInMap())) { return layer; } } } return Layer.LOW; }
/** * Changes the layer of an entity. You should call this method instead of calling directly * MapEntity.setLayer(), because the entity of the 3 layers are stored in 3 different structures. * If the entity is not known by the map (yet), this method just calls MapEntity.setLayer(). * * @param entity the entity to change the layer * @param layer the new layer */ public void setEntityLayer(MapEntity entity, Layer layer) { Layer oldLayer = entity.getLayer(); if (layer != oldLayer) { entity.setLayer(layer); if (allEntities[oldLayer.getId()].remove(entity)) { allEntities[layer.getId()].add(entity); } setChanged(); notifyObservers(); } }
public Layer addInternalActiveLayer(Layer layer) { // Internal Active layers are not shown in the layer tree but are shown in the active layers // list layer.setValue(Constants.ACTIVE_LAYER, true); return addLayer(layer, Constants.INTERNAL_LAYER); }
/** * Changes the tileset of the map. * * @param tilesetId id of the new tileset, or an empty string to set no tileset * @return true if the tileset was loaded successfuly, false if some tiles could not be loaded in * this tileset * @throws MapException if this tileset could be applied */ public boolean setTileset(String tilesetId) throws ZSDXException { this.badTiles = false; // if the tileset is removed if (tilesetId.length() == 0 && this.tilesetId.length() != 0) { this.tilesetId = tilesetId; this.tileset = null; setChanged(); notifyObservers(); } // if the tileset is changed else if (!tilesetId.equals(this.tilesetId)) { this.tileset = new Tileset(tilesetId); for (Layer layer : Layer.values()) { LinkedList<MapEntity> entitiesToRemove = new LinkedList<MapEntity>(); for (MapEntity entity : allEntities[layer.getId()]) { try { entity.setTileset(tileset); } catch (NoSuchTilePatternException ex) { // the entity is not valid anymore, we should remove it from the map entitiesToRemove.add(entity); badTiles = true; } } for (MapEntity entity : entitiesToRemove) { allEntities[layer.getId()].remove(entity); } } this.tilesetId = tilesetId; setChanged(); notifyObservers(tileset); } return !badTiles; }
private Layer addLayer(Layer layer, String layerType) { if (layer != null) { layer.setValue(layerType, true); this.getWWPanel().addLayer(layer); } return layer; }
/** * Brings the specified entities to the front, keeping their layer. The order of the specified * entities in the map is unchanged. * * @param entities the entities to move */ public void bringToFront(List<MapEntity> entities) { List<MapEntity> sortedEntities = getSortedEntities(entities); // bring to front each entity from sortedEntities ListIterator<MapEntity> iterator = sortedEntities.listIterator(0); while (iterator.hasNext()) { MapEntity entity = iterator.next(); Layer layer = entity.getLayer(); allEntities[layer.getId()].remove(entity); allEntities[layer.getId()].addLast(entity); } setChanged(); notifyObservers(); }
/** * Brings the specified entities to the back, keeping their layer. The order of the specified * entities in the map is unchanged. * * @param entities the entities to move */ public void bringToBack(List<MapEntity> entities) { List<MapEntity> sortedEntities = getSortedEntities(entities); // bring to back each entity from sortedEntities ListIterator<MapEntity> iterator = sortedEntities.listIterator(sortedEntities.size()); while (iterator.hasPrevious()) { MapEntity entity = iterator.previous(); Layer layer = entity.getLayer(); allEntities[layer.getId()].remove(entity); allEntities[layer.getId()].addFirst(entity); } setChanged(); notifyObservers(); }
/** * Returns the specified entities, sorted in the order of the map. The first entity is the lowest * one, the last entity is the highest one. * * @param entities the entities to sort * @return the same entities, sorted as they are in the map */ public List<MapEntity> getSortedEntities(List<MapEntity> entities) { List<MapEntity> sortedEntities = new LinkedList<MapEntity>(); // sort the entities so that they have the same order as in the map for (Layer layer : Layer.values()) { for (MapEntity entity : allEntities[layer.getId()]) { if (entities.contains(entity)) { sortedEntities.add(entity); } } } // now sortedEntities contains all entities of the list, // sorted in the same order as in the map return sortedEntities; }
/** * Returns the entities located in a rectangle defined by two points. * * @param x1 x coordinate of the first point * @param y1 y coordinate of the first point * @param x2 x coordinate of the second point * @param y2 y coordinate of the second point */ public List<MapEntity> getEntitiesInRectangle(int x1, int y1, int x2, int y2) { List<MapEntity> entitiesInRectangle = new LinkedList<MapEntity>(); int x = Math.min(x1, x2); int width = Math.abs(x2 - x1); int y = Math.min(y1, y2); int height = Math.abs(y2 - y1); Rectangle rectangle = new Rectangle(x, y, width, height); for (Layer layer : Layer.values()) { for (MapEntity entity : allEntities[layer.getId()]) { if (rectangle.contains(entity.getPositionInMap())) { entitiesInRectangle.add(entity); } } } return entitiesInRectangle; }
/** * Returns the first entity under a point of the map, in the specified layer. * * @param layer the layer * @param x x of the point * @param y y of the point * @return the entity found, or null if there is no entity here */ public MapEntity getEntityAt(Layer layer, int x, int y) { MapEntities entities = allEntities[layer.getId()]; ListIterator<MapEntity> iterator = entities.listIterator(entities.size()); while (iterator.hasPrevious()) { MapEntity entity = iterator.previous(); if (entity.containsPoint(x, y)) { return entity; } } return null; }
public static void legendAction() { try { LegendColorTable.countTable = 0; Layer layer = content.layers().get(content.layers().size() - 1); SimpleFeatureSource featureSource = (SimpleFeatureSource) layer.getFeatureSource(); String fieldName = getFieldForColour(featureSource); if (fieldName != null && fieldName.length() > 0) { Style style = createStyle(featureSource, fieldName); content.removeLayer(layer); Layer newLayer = new FeatureLayer(featureSource, style); content.addLayer(newLayer); } else throw new NullPointerException("Error occured during making legend"); } catch (ArrayIndexOutOfBoundsException ex) { JOptionPane.showMessageDialog(null, "No layers are added !"); } catch (Exception ex) { ex.printStackTrace(); // JOptionPane.showMessageDialog(null, ex.getMessage()); } }
private void connect(Layer ly1, Synapse syn, Layer ly2) { ly1.addOutputSynapse(syn); ly2.addInputSynapse(syn); }
@Override public void execute() { if (USE_OMETA) { try { exportWithOmeta(); } catch (Exception e) { e.printStackTrace(); } return; } try { File dir = new File("/Users/josh/projects/Leo/t2"); File html = new File(dir, "foo.html"); File templatedir = new File("resources/"); if (useRandomFile) { } else { // get a file to write to if (document.getExportFile() != null) { html = document.getExportFile(); dir = html.getParentFile(); } else { java.awt.FileDialog fd = new java.awt.FileDialog((Frame) null); fd.setMode(FileDialog.SAVE); fd.setVisible(true); if (fd.getFile() == null) { return; } String filename = fd.getFile(); if (!filename.toLowerCase().endsWith(".html")) { filename += ".html"; } html = new File(fd.getDirectory(), filename); dir = html.getParentFile(); } } // File file = File.createTempFile("foo",".html"); // file.deleteOnExit(); StringWriter treeContent = new StringWriter(); PrintWriter treeOut = new PrintWriter(treeContent); PropWriter treeWriter = new PropWriter(treeOut); StringWriter setupContent = new StringWriter(); for (Layer layer : page.children()) { treeWriter.p("//layer"); treeWriter.indent(); for (SketchNode node : layer.children()) { DynamicNode dnode = (DynamicNode) node; exportNode(treeWriter, dnode, true, dir); if (node.isVisual() && AminoAdapter.shouldAddToScene(node, document.getBindings())) { setupContent.append("root.add(" + node.getId() + ");\n"); } if (AminoAdapter.useSetup(dnode)) { setupContent.append(node.getId() + ".setup(root);\n"); } doExtensions(setupContent, dnode); } treeWriter.outdent(); } for (Binding binding : document.getBindings()) { exportBinding(new PrintWriter(setupContent), binding); } treeOut.close(); setupContent.close(); Map<String, String> subs = new HashMap<String, String>(); subs.put("tree", treeContent.toString()); subs.put("setup", setupContent.toString()); if (!html.exists()) { StringUtils.applyTemplate(new File(templatedir, "index_template.html"), html, subs); } File js = new File(dir, "generated.js"); StringUtils.applyTemplate(new File(templatedir, "generated_template.js"), js, subs); StringUtils.copyFile(new File(templatedir, "amino.js"), new File(dir, "amino.js")); StringUtils.copyFile(new File(templatedir, "jquery.js"), new File(dir, "jquery.js")); StringUtils.copyFile(new File(templatedir, "controls.js"), new File(dir, "controls.js")); File trimfile = new File("/Users/josh/"); String partialPath = dir.getAbsolutePath().substring((int) trimfile.getAbsolutePath().length()); OSUtil.openBrowser("http://localhost/~josh/" + partialPath + "/" + html.getName()); document.setExportFile(html); } catch (Exception e) { e.printStackTrace(); } }
/** * Saves the map into its file. * * @throws ZSDXException if the file could not be written for various reasons */ public void save() throws ZSDXException { // check that the map is valid checkValidity(); try { // open the map file File mapFile = Project.getMapFile(mapId); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(mapFile))); // print the map general info // syntax: width height world floor x y small_keys_variable tileset_id music_id out.print(size.width); out.print('\t'); out.print(size.height); out.print('\t'); out.print(world); out.print('\t'); out.print(floor); out.print('\t'); out.print(location.x); out.print('\t'); out.print(location.y); out.print('\t'); out.print(smallKeysVariable); out.print('\t'); out.print(tilesetId); out.print('\t'); out.print(musicId); out.println(); for (Layer layer : Layer.values()) { MapEntities entities = allEntities[layer.getId()]; // print the entities for (MapEntity entity : entities) { out.print(entity.toString()); out.println(); } } out.close(); history.setSaved(); // also update the map name in the global resource list Resource mapResource = Project.getResource(ResourceType.MAP); mapResource.setElementName(mapId, name); Project.getResourceDatabase().save(); // upate the dungeon elements of this map if (isInDungeon()) { Dungeon.saveMapInfo(this); } // create a script for the map if necessary File scriptFile = Project.getMapScriptFile(mapId); if (!scriptFile.exists()) { scriptFile.createNewFile(); } } catch (IOException ex) { throw new MapException(ex.getMessage()); } }
/** * Returns the entities of the map on a given layer. * * @param layer the layer * @return the entities placed on that layer */ public MapEntities getEntities(Layer layer) { return allEntities[layer.getId()]; }