public void actionPerformed(ActionEvent evt) {
    Object src = evt.getSource();

    if (src == btnAdd) {

      LineStyle style = new LineStyle();
      EditorDialog.show(this, new EdgeStyleEditor(style, canvas, true), true);
      if (style.getId() != null) {
        canvas.addEdgeStyle(style);
        jlistModel.addElement(style.getId());
      }
      return;

    } else if (src == btnEdit) {

      int index = jlist.getSelectedIndex();
      if (index == -1) {
        JOptionPane.showMessageDialog(
            this,
            "First select a style from the list",
            "Information",
            JOptionPane.INFORMATION_MESSAGE);
        return;
      }
      LineStyle style = (LineStyle) styles.get(index);
      EditorDialog.show(this, new EdgeStyleEditor(style, canvas, false), true);
      jlistModel.set(index, style.getId());
      canvas.repaint();
      preview.repaint();
      return;

    } else if (src == btnDel) {

      int index = jlist.getSelectedIndex();
      if (index == -1) {
        JOptionPane.showMessageDialog(
            this,
            "First select a style from the list",
            "Information",
            JOptionPane.INFORMATION_MESSAGE);
        return;
      }
      canvas.removeEdgeStyle((LineStyle) styles.get(index));
      jlistModel.remove(index);
      return;
    }
  }
Beispiel #2
0
  /** Dumps the results as a series of KML's..one per trip */
  public void writeKMLandCSV() {

    String csv_header =
        "INDEX,DATE,TIME,SECONDS_SINCE_MIDNIGHT,TRIP_ID,DIR,SPEED,LAT,LONG,ALT,EXITS,ENTRANCES";

    try {
      CSVWriter writer = new CSVWriter(new FileWriter("bus_data.csv"), ',');

      // Write the header
      String[] entries = csv_header.split(",");
      writer.writeNext(entries);

      // Setup some style
      LineStyle lineStyle = new LineStyle();
      lineStyle.setColor("ff005555");
      lineStyle.setWidth(5.0);

      IconStyle peopleIconStyle = new IconStyle();
      // Icon peopleIcon = new Icon();
      // peopleIcon.setHref("http://maps.google.com/mapfiles/kml/man.png");
      peopleIconStyle.setIconHref("http://maps.google.com/mapfiles/kml/shapes/man.png");
      peopleIconStyle.setScale(1.50);

      IconStyle wpIconStyleNorth = new IconStyle();
      // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png");
      // wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png");
      wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/ms/micons/green-dot.png");
      wpIconStyleNorth.setScale(0.50);

      IconStyle wpIconStyleSouth = new IconStyle();
      // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png");
      wpIconStyleSouth.setIconHref("http://maps.google.com/mapfiles/ms/micons/yellow-dot.png");
      wpIconStyleSouth.setScale(0.50);

      Style style_lineStyle = new Style();
      style_lineStyle.setLineStyle(lineStyle);

      Style style_peopleIconStyle = new Style();
      style_peopleIconStyle.setId("peopleIcon");
      style_peopleIconStyle.setIconStyle(peopleIconStyle);

      Style style_wpIconStyleNorth = new Style();
      style_wpIconStyleNorth.setId("wpIconNorth");
      style_wpIconStyleNorth.setIconStyle(wpIconStyleNorth);

      Style style_wpIconStyleSouth = new Style();
      style_wpIconStyleSouth.setId("wpIconSouth");
      style_wpIconStyleSouth.setIconStyle(wpIconStyleSouth);

      Kml[] kml = new Kml[tripCounter];
      Document[] document = new Document[tripCounter];
      Folder[] northFolders = new Folder[tripCounter];
      Folder[] southFolders = new Folder[tripCounter];
      Folder[] peopleFolders = new Folder[tripCounter];
      // Folder[] tracksFolders = new Folder[tripCounter];

      for (int i = 0; i < tripCounter; i++) {
        kml[i] = new Kml();
        kml[i].setXmlIndent(true);
        document[i] = new Document();
        document[i].addStyleSelector(style_lineStyle);
        document[i].addStyleSelector(style_peopleIconStyle);
        document[i].addStyleSelector(style_wpIconStyleNorth);
        document[i].addStyleSelector(style_wpIconStyleSouth);
        kml[i].setFeature(document[i]);

        northFolders[i] = new Folder();
        northFolders[i].setName("North Route");

        southFolders[i] = new Folder();
        southFolders[i].setName("South Route");

        peopleFolders[i] = new Folder();
        peopleFolders[i].setName("People");

        // tracksFolders[i] = new Folder();
        // tracksFolders[i].setName("Tracks");

        document[i].addFeature(northFolders[i]);
        document[i].addFeature(southFolders[i]);
        document[i].addFeature(peopleFolders[i]);
        // document[i].addFeature(tracksFolders[i]);

      }

      double[] lowerKey = new double[1];
      double[] upperKey = new double[1];

      lowerKey[0] = firstTime;
      upperKey[0] = lastTime;

      Object[] foo = geoRecords.range(lowerKey, upperKey);
      for (int i = 0; i < foo.length; i++) {
        GeoRecord nextRecord = (GeoRecord) foo[i];
        int tripNumber = nextRecord.getTripId();
        // System.out.println(foo[i]);
        if (nextRecord.getDirection().equals("N")) {
          northFolders[tripNumber - 1].addFeature(nextRecord.toKML());
        } else {
          southFolders[tripNumber - 1].addFeature(nextRecord.toKML());
        }
        if (nextRecord.getAssociatedPeople().size() > 0) {
          peopleFolders[tripNumber - 1].addFeature(nextRecord.toKMLWithPeople());
        }

        // Write CSV entry
        String csvLine = nextRecord.toCSV();
        String[] entries2 = csvLine.split(",");
        writer.writeNext(entries2);
      }

      // Write the KML files
      for (int i = 0; i < tripCounter; i++) {
        kml[i].createKml("bus_route" + i + ".kml");
      }

      // Close the csv writer
      writer.close();

    } catch (Exception e) {
      System.err.println(e);
    }
  }
Beispiel #3
0
 /**
  * Set the value of the {@link #PROPERTY_LINE_STYLE} property. This is the preferred mutator
  * method for this proeprty.
  *
  * @param lineStyle The line style to use.
  */
 public void setLineStyle(final LineStyle lineStyle) {
   setLineStyle(lineStyle.toString());
 }
  public String draw(String title, Map<String, List<Double>> data, List<String> xLabels) {

    /*
        Scale values
    */
    Double maxValue = Double.MIN_VALUE;
    Double minValue = Double.MAX_VALUE;
    for (List<Double> doubles : data.values()) {
      for (Double d : doubles) {
        maxValue = Math.max(d, maxValue);
        minValue = Math.min(d, minValue);
      }
    }
    double k = 100.0 / maxValue;
    HashMap<String, List<Double>> scaled = new HashMap<>();
    for (Map.Entry<String, List<Double>> entry : data.entrySet()) {
      List<Double> value = new ArrayList<>();
      for (Double next : entry.getValue()) {
        value.add(next * k);
      }
      scaled.put(entry.getKey(), value);
    }
    data = scaled;

    Random rnd = new Random(42);

    // Defining lines
    ArrayList<Line> lines = new ArrayList<>();
    for (Map.Entry<String, List<Double>> entry : data.entrySet()) {
      Color color =
          Color.newColor(
              String.format("%02X%02X%02X", rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
      Line line = Plots.newLine(Data.newData(entry.getValue()), color, entry.getKey());
      line.setLineStyle(LineStyle.newLineStyle(3, 1, 0));
      line.addShapeMarkers(Shape.DIAMOND, color, 12);
      line.addShapeMarkers(Shape.DIAMOND, Color.WHITE, 8);
      lines.add(line);
    }

    // Defining chart.
    LineChart chart = GCharts.newLineChart(lines);
    chart.setSize(600, 450);
    chart.setTitle(title, WHITE, 14);
    int stepCount = 5;
    chart.setGrid(100 / stepCount, 100 / stepCount, 3, 3);

    // Defining axis info and styles

    // Make x axis
    AxisStyle axisStyle = AxisStyle.newAxisStyle(WHITE, 12, AxisTextAlignment.CENTER);
    AxisLabels xAxis = AxisLabelsFactory.newAxisLabels(xLabels);
    xAxis.setAxisStyle(axisStyle);

    // Calculate y axis labels
    List<String> yLabels = new ArrayList<>();
    for (int i = 0; i <= stepCount; i++) {
      yLabels.add(String.valueOf(maxValue / stepCount * i));
    }
    AxisLabels yAxis = AxisLabelsFactory.newAxisLabels(yLabels);
    yAxis.setAxisStyle(axisStyle);

    // Adding axis info to chart.
    chart.addXAxisLabels(xAxis);
    chart.addYAxisLabels(yAxis);

    // Defining background and chart fills.
    chart.setBackgroundFill(Fills.newSolidFill(Color.newColor("1F1D1D")));
    LinearGradientFill fill = Fills.newLinearGradientFill(0, Color.newColor("363433"), 100);
    fill.addColorAndOffset(Color.newColor("2E2B2A"), 0);
    chart.setAreaFill(fill);

    return chart.toURLString();
  }