示例#1
0
文件: Paths.java 项目: jpollo/rcrss
  private Path getNearestPath(Road road, List<Path> paths) {
    int range = 10000;
    int minDistance = Integer.MAX_VALUE;
    EntityID nearestPath = null;

    while (nearestPath == null) {
      Collection<StandardEntity> entities = world.getObjectsInRange(road, range);

      for (StandardEntity entity : entities) {
        if (entity instanceof Road) {
          EntityID pathId = roadHelper.getPathId(entity.getID());

          if (pathId != null) {
            int distance = Util.distance((Area) entity, road);
            if (distance < minDistance) {
              nearestPath = pathId;
              minDistance = distance;
            }
          }
        }
      }
      range += 10000;
    }

    for (Path path : paths) {
      if (path.getId().equals(nearestPath)) {
        return path;
      }
    }
    return null;
  }
  /**
   * Recursively rebuild the tree nodes.
   *
   * @param root The full abstract path to the root saved layout directory.
   * @param local The current directory relative to root (null if none).
   * @param tnode The current parent tree node.
   */
  private void rebuildTreeModel(Path root, Path local, DefaultMutableTreeNode tnode) {
    TreeSet<Path> subdirs = new TreeSet<Path>();
    TreeSet<String> layouts = new TreeSet<String>();
    {
      Path current = new Path(root, local);
      File files[] = current.toFile().listFiles();
      if (files != null) {
        int wk;
        for (wk = 0; wk < files.length; wk++) {
          String name = files[wk].getName();
          if (files[wk].isDirectory()) subdirs.add(new Path(local, name));
          else if (files[wk].isFile()) layouts.add(name);
        }
      }
    }

    for (Path subdir : subdirs) {
      TreeData data = new TreeData(subdir);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, true);
      tnode.add(child);

      rebuildTreeModel(root, subdir, child);
    }

    for (String lname : layouts) {
      TreeData data = new TreeData(new Path(local, lname), lname);
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(data, false);
      tnode.add(child);
    }
  }
示例#3
0
文件: Paths.java 项目: jpollo/rcrss
 private void setPathIDForRoads(List<Path> paths) {
   for (Path path : paths) {
     for (Road road : path) {
       roadHelper.setPathId(road.getID(), path.getId());
     }
   }
 }
示例#4
0
文件: Paths.java 项目: jpollo/rcrss
 private void addToPath(Road road, EntityID pathId, List<Path> paths) {
   for (Path path : paths) {
     if (path.getId().equals(pathId)) {
       adding(road, path);
       break;
     }
   }
 }
示例#5
0
文件: Paths.java 项目: jpollo/rcrss
 private void adding(Road road, Path path) {
   roadHelper.setPathId(road.getID(), path.getId());
   if (!path.contains(road)) {
     path.add(road);
     if (entrances.contains(road)) {
       path.addEntrance(getEntrance(road));
     }
   }
 }
示例#6
0
    private ArrayList<Path> holeLaufwerkeWindows() {
      ArrayList<Path> laufwerksRoot = new ArrayList<>();

      Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories();

      for (Path path : rootDirectories) {
        laufwerksRoot.add(path.getRoot());
      }
      return laufwerksRoot;
    }
示例#7
0
文件: Paths.java 项目: jpollo/rcrss
 private void addEntrances(Path path, Road road) {
   Entrance entrance;
   for (Road n : roadHelper.getConnectedRoads(road.getID())) {
     if (entrances.contains(n)) {
       roadHelper.setPathId(n.getID(), path.getId());
       if (!path.contains(n) && !added.contains(n)) {
         path.add(n);
         added.add(n);
       }
       entrance = getEntrance(n);
       if (!path.getEntrances().contains(entrance)) {
         path.addEntrance(entrance);
       }
     }
   }
 }
示例#8
0
  public Path finishCircuit(int dispair, Vertex home, Graphics g) {
    visited = true;

    Path bestPath = new Path();
    bestPath.cost = 100000000;

    if (dispair == 0) // Last being visited
    {
      Iterator<Edge> it = edges.iterator();
      Boolean match = false;

      // Looks through all this vertex's edges and find the one that goes home
      while (!match && it.hasNext()) {
        Edge f = it.next();

        if (f.fromVertex.ident == home.ident) {
          Path p = new Path();
          bestPath = p;
          bestPath.add(f);
          match = true;
        }
      }
    } else {
      Iterator<Edge> it = edges.iterator();

      // Finds all possible paths through nodes not visited
      while (it.hasNext()) {
        Edge e = it.next();
        Vertex c = e.fromVertex;

        if (!c.visited) {
          e.drawMe(g, Color.black); // Draws edge
          Path p = c.finishCircuit(dispair - 1, home, g);
          p.add(e);
          e.drawMe(g, Color.green); // Un-draws edge

          if (p.cost < bestPath.cost) // Sets bestPath
          {
            bestPath = p;
          }
        }
      }
    }

    visited = false;
    return bestPath;
  }
  @Override
  public void path(Point start, LineType[] types, Point[][] points) {
    if (types.length != points.length) {
      return;
    }

    Path p = new Path();
    p.setStart(start);

    ArrayList<PathPart> parts = new ArrayList<PathPart>();
    for (int i = 0; i < types.length; ++i) {
      parts.add(new PathPart(types[i], points[i]));
    }
    p.setParts(parts);

    addToShapes(p);
  }
    protected void addContourShapes(
        List<List<Position>> contourList, double value, RenderableLayer layer) {
      String text = this.textForValue(value);
      Color color = this.colorForValue(value, 1.0); // color for value at 100% brightness

      ShapeAttributes attrs = new BasicShapeAttributes();
      attrs.setOutlineMaterial(new Material(color));
      attrs.setOutlineWidth(2);

      for (List<Position> positions : contourList) {
        Path path = new Path(positions);
        path.setAttributes(attrs);
        path.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
        path.setFollowTerrain(true);
        path.setValue(AVKey.DISPLAY_NAME, text);
        layer.addRenderable(path);
      }
    }
示例#11
0
    private int getNumberOfItems(Path quellOrdner) {
      int retValue = 0;

      try {
        DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner);
        for (Path qfile : qstream) {
          if (Files.isDirectory(qfile)) {
            getNumberOfItems(Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()));
          }
          i++;
        }
        qstream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      retValue = i;
      return retValue;
    }
示例#12
0
  public Path dateiAuswählen(Path neuesLaufwerk) {
    JFileChooser fc1 = new JFileChooser();
    fc1.setDialogTitle("SyncOrdner auswählen");
    fc1.setCurrentDirectory(neuesLaufwerk.toFile());
    fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
      return fc1.getSelectedFile().toPath();
    else return null;
  }
示例#13
0
文件: Paths.java 项目: jpollo/rcrss
 private void createPathsNeighbours() {
   Set<Path> neighbours;
   for (Path path : this) {
     neighbours = new FastSet<Path>();
     for (Road road : path) {
       for (EntityID entityID : road.getNeighbours()) {
         if (world.getEntity(entityID) instanceof Road) {
           for (Path p : this) {
             if (!path.equals(p) && p.contains((Road) world.getEntity(entityID))) {
               if (!neighbours.contains(p)) {
                 neighbours.add(p);
               }
             }
           }
         }
       }
     }
     path.setNeighbours(neighbours);
   }
 }
示例#14
0
  /**
   * Update the layouts tree.
   *
   * @param current The name of the current layout or <CODE>null</CODE> if none.
   */
  public void updateLayouts(Path current) throws PipelineException {
    DefaultMutableTreeNode root = null;
    {
      root = new DefaultMutableTreeNode(new TreeData(), true);

      {
        Path path = new Path(PackageInfo.getSettingsPath(), "layouts");
        rebuildTreeModel(path, new Path("/"), root);
      }

      DefaultTreeModel model = (DefaultTreeModel) pTree.getModel();
      model.setRoot(root);

      {
        Enumeration e = root.depthFirstEnumeration();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) e.nextElement();
            pTree.expandPath(new TreePath(tnode.getPath()));
          }
        }
      }
    }

    pTree.clearSelection();
    if (current != null) {
      TreePath tpath = null;
      DefaultMutableTreeNode tnode = root;
      for (String comp : current.getComponents()) {
        DefaultMutableTreeNode next = null;
        Enumeration e = tnode.children();
        if (e != null) {
          while (e.hasMoreElements()) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) e.nextElement();
            TreeData data = (TreeData) child.getUserObject();
            if (data.toString().equals(comp)) {
              tpath = new TreePath(child.getPath());
              next = child;
              break;
            }
          }
        }

        if (next == null) break;

        tnode = next;
      }

      if (tpath != null) {
        pTree.setSelectionPath(tpath);
        pTree.makeVisible(tpath);
      }
    }
  }
示例#15
0
 /**
  * Convert an AWT Shape to an SWT Path.
  *
  * @param shape
  * @return the SWT Path or <code>null</code> if <code>shape == null</code>
  */
 private Path convertToPath(Shape shape) {
   if (shape == null) {
     return null;
   }
   Path path = new Path(_gc.getDevice());
   PathIterator iter = shape.getPathIterator(null);
   float[] coords = new float[6];
   while (!iter.isDone()) {
     int op = iter.currentSegment(coords);
     switch (op) {
       case PathIterator.SEG_MOVETO:
         path.moveTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_LINETO:
         path.lineTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_QUADTO:
         path.quadTo(coords[0], coords[1], coords[2], coords[3]);
         break;
       case PathIterator.SEG_CUBICTO:
         path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
         break;
       case PathIterator.SEG_CLOSE:
         path.close();
         break;
     }
     iter.next();
   }
   return path;
 }
    protected void showSightLines(List<Position[]> sightLines) {
      this.sightLinesLayer.removeAllRenderables();

      // Display the sight lines as green lines.
      ShapeAttributes lineAttributes;
      lineAttributes = new BasicShapeAttributes();
      lineAttributes.setDrawOutline(true);
      lineAttributes.setDrawInterior(false);
      lineAttributes.setOutlineMaterial(Material.GREEN);
      lineAttributes.setOutlineOpacity(0.6);

      for (Position[] pp : sightLines) {
        List<Position> endPoints = new ArrayList<Position>();
        endPoints.add(pp[0]);
        endPoints.add(pp[1]);

        Path path = new Path(endPoints);
        path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
        path.setAttributes(lineAttributes);
        this.sightLinesLayer.addRenderable(path);
      }
    }
示例#17
0
 public void setClip(Shape s) {
   Path path = convertToPath(s);
   if (path == null) {
     _gc.setClipping((Rectangle) null);
   } else {
     _gc.setClipping(path);
   }
   if (_clippingPath != null) {
     _clippingPath.dispose();
   }
   _clippingPath = path;
   _clippingArea = (s == null ? null : new Area(s));
 }
    protected void showGridSightLines(List<Position> grid, Position cPos) {
      this.sightLinesLayer.removeAllRenderables();

      // Display lines from the center to each grid point.
      ShapeAttributes lineAttributes;
      lineAttributes = new BasicShapeAttributes();
      lineAttributes.setDrawOutline(true);
      lineAttributes.setDrawInterior(false);
      lineAttributes.setOutlineMaterial(Material.GREEN);
      lineAttributes.setOutlineOpacity(0.6);

      for (Position p : grid) {
        List<Position> endPoints = new ArrayList<Position>();
        endPoints.add(cPos);
        endPoints.add(new Position(p.getLatitude(), p.getLongitude(), 0));

        Path path = new Path(endPoints);
        path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
        path.setAttributes(lineAttributes);
        this.sightLinesLayer.addRenderable(path);
      }
    }
示例#19
0
文件: Paths.java 项目: jpollo/rcrss
  private List<Path> createThisHeadRoadPaths(Road head) {
    List<Path> paths = new ArrayList<Path>();
    List<Road> headRoadEntrances = new ArrayList<Road>();
    for (Road neighbourRoad : roadHelper.getConnectedRoads(head.getID())) {

      if (added.contains(neighbourRoad)) {
        continue;
      } else if (entrances.contains(neighbourRoad)) {
        added.add(neighbourRoad);
        headRoadEntrances.add(neighbourRoad);
        continue;
      }
      end = false;
      Path path = new Path(world);

      path.add(head);
      added.add(head);

      path.setHeadOfPath(head);
      createAPath(neighbourRoad, path);

      paths.add(path);
      added.remove(head);
    }
    if (!headRoadEntrances.isEmpty() && paths.size() > 0) {
      List<Road> temp = new ArrayList<Road>();
      temp.addAll(paths.get(0));
      paths.get(0).clear();
      for (Road road : headRoadEntrances) {
        paths.get(0).add(road);
        paths.get(0).addEntrance(getEntrance(road));
      }
      paths.get(0).addAll(temp);
    }

    return paths;
  }
示例#20
0
 /** Clean used resources. */
 public void clean() {
   if (_clippingPath != null) {
     _gc.setClipping((Rectangle) null);
     _clippingPath.dispose();
     _clippingPath = null;
     _clippingArea = null;
   }
   if (_color != null) {
     _color.dispose();
     _color = null;
   }
   if (_transform != null) {
     _gc.setTransform(null);
     _transform.dispose();
   }
 }
示例#21
0
  private void laden(Path saveName) throws IOException {
    Properties prop = new Properties();

    FileInputStream in = new FileInputStream(saveName.toString());
    prop.load(in);

    for (int i = 0; prop.containsKey(String.format("quellMenu%d", i)); i++)
      quellListModel.addElement(
          new ListItem(
              Paths.get(prop.getProperty(String.format("quellMenu%d", i))),
              Paths.get(prop.getProperty(String.format("quellMenu%d", i)))));
    for (int i = 0; prop.containsKey(String.format("zielMenu%d", i)); i++)
      zielListModel.addElement(
          new ListItem(
              Paths.get(prop.getProperty(String.format("zielMenu%d", i))),
              Paths.get(prop.getProperty(String.format("zielMenu%d", i)))));

    in.close();
  }
    protected void addPath(RenderableLayer layer, List<Position> positions, String displayName) {
      ShapeAttributes attrs = new BasicShapeAttributes();
      attrs.setOutlineWidth(5);

      Path path = new Path(positions);
      path.setPathType(AVKey.LINEAR);
      path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
      path.setAttributes(attrs);
      path.setValue(AVKey.DISPLAY_NAME, displayName);
      layer.addRenderable(path);

      // Show how to make the colors vary along the paths.
      path.setPositionColors(new ExamplePositionColors());
    }
示例#23
0
文件: Paths.java 项目: jpollo/rcrss
  private void createAPath(Road neighbourRoad, Path path) {
    if (!path.contains(neighbourRoad)) {
      path.add(neighbourRoad);
      added.add(neighbourRoad);
    }

    addEntrances(path, neighbourRoad);

    for (Road road : roadHelper.getConnectedRoads(neighbourRoad.getID())) {
      if (entrances.contains(road) || added.contains(road)) {
        continue;
      }
      if (end || roadHelper.getConnectedRoads(neighbourRoad.getID()).size() == 1) {
        return;
      }
      if (headRoads.contains(road)) {
        if (!end) {
          end = true;
          if (!path.contains(road)) {
            path.add(road);
          }
          path.setEndOfPath(road);
        }
      } else if (!end) {
        createAPath(road, path);
      }
    }
    if (!end) {
      for (Road neighbourR : roadHelper.getConnectedRoads(neighbourRoad.getID())) {
        if (headRoads.contains(neighbourR)) {
          if (!path.contains(neighbourR)) {
            path.add(neighbourR);
          }
          path.setEndOfPath(neighbourR);
          end = true;
        }
      }
    }
  }
示例#24
0
  private void speichern(Path saveName) {
    Properties prop = new Properties();

    if (!quellListModel.isEmpty())
      for (int i = 0; i < quellListModel.getSize(); i++)
        prop.setProperty(
            String.format("quellMenu%d", i),
            quellListModel.getElementAt(i).getValueMember().toString());

    if (!zielListModel.isEmpty())
      for (int i = 0; i < zielListModel.getSize(); i++)
        prop.setProperty(
            String.format("zielMenu%d", i),
            zielListModel.getElementAt(i).getValueMember().toString());

    try {
      FileOutputStream out = new FileOutputStream(saveName.toString());
      prop.store(out, null);
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#25
0
 public void fill(Shape s) {
   Path p = convertToPath(s);
   _gc.fillPath(p);
   p.dispose();
 }
示例#26
0
文件: Paths.java 项目: jpollo/rcrss
 private void setIDForPaths(List<Path> paths) {
   for (Path path : paths) {
     path.setId();
   }
 }
示例#27
0
    public void cnpStart(Path quellOrdner, Path zielOrdner) {
      try {
        DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner);
        for (Path qfile : qstream) {
          Path target = Paths.get(zielOrdner.toString() + "/" + qfile.getFileName());
          if (abbruch) break;
          if (Files.isDirectory(qfile) && !Files.exists(target)) {
            Files.createDirectory(target);
            textArea.append("Verzeichnis: " + qfile + " wurde erstellt" + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          } else if (Files.isDirectory(qfile) && Files.exists(target)) {
            textArea.append("Wechsle in Verzeichnis: " + qfile + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          }
          // Wenn die Datei noch nicht existiert
          else if (!Files.exists(target)) {
            textArea.append(
                "Datei " + target.toString() + " wurde erstellt" + System.lineSeparator());
            Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);

          }
          // Wenn Datei im Zielverzeichnis schon existiert
          else if (Files.exists(target)) {
            if (cAUeSchr) {
              textArea.append(
                  "Datei "
                      + target.toString()
                      + " wird absolut überschrieben"
                      + System.lineSeparator());
              Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
            } else if (cUeSchr) {
              if (checkAlter(
                  Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                  Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()))) {
                textArea.append(
                    target.toString()
                        + " wird mit neuer Datei überschrieben"
                        + System.lineSeparator());
                Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
              } else {
                textArea.append(
                    target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
              }
            } else
              textArea.append(
                  target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
          }
          pbCounter++;
          progressBar.setValue(pbCounter);
        }

        qstream.close();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }
示例#28
0
 private void addZListBoxEintrag(Path zielOrdner) {
   if (zielOrdner == null) return;
   zielListModel.addElement(new ListItem(zielOrdner, zielOrdner.toString()));
   zielJList.setSelectedIndex(zielListModel.getSize() - 1);
 }
示例#29
0
  public boolean isJar() {
    Path pth = Paths.get(System.getProperty("user.dir") + "/Advent.jar");

    if (pth.toFile().exists()) return true;
    return false;
  }