Ejemplo n.º 1
0
 private void paintWorld(Graphics2D g) {
   for (String country : this.country2shape.keySet()) {
     Shape shape = country2shape.get(country);
     float color = 0;
     if (seen.count(country) != 0) {
       color = 1f - (float) (Math.log(seen.count(country)) / Math.log((double) seen.getTotal()));
     }
     g.setColor(seen.count(country) == 0 ? Color.WHITE : new Color(color, 0f, 0f));
     g.fill(shape);
   }
   for (String country : this.country2shape.keySet()) {
     Shape shape = country2shape.get(country);
     g.setColor(Color.BLACK);
     g.draw(shape);
   }
 }
Ejemplo n.º 2
0
  private void scan(Graphics2D g, InputStream input) throws IOException {
    Set<String> unknownC = new HashSet<String>();
    Pattern tab = Pattern.compile("[\t]");
    LineIterator in = new LineIteratorImpl(LineReaderUtil.fromBufferedStream(input));
    while (in.hasNext()) {
      String line = in.next();
      String tokens[] = tab.split(line, 5);
      if (tokens.length < 4) {
        warning("Ignoring " + line);
        continue;
      }
      SAMSequenceRecord rec = this.context.getDictionary().getSequence(tokens[0]);
      if (rec == null) {
        warning("unknown chromosome " + tokens[0]);
        continue;
      }
      String country = tokens[3].toLowerCase().replaceAll("[ ]", "");
      Shape shape = this.country2shape.get(country);
      if (shape == null) {
        if (!unknownC.contains(country)) {
          unknownC.add(country);
          warning("unknown country " + country);
        }
        continue;
      }
      seen.incr(country);
      int midpos = (Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2])) / 2;
      // country center
      Point2D.Double pt1 =
          new Point2D.Double(shape.getBounds2D().getCenterX(), shape.getBounds2D().getCenterY());
      // circle point
      Point2D pt3 = this.context.convertPositionToPoint(tokens[0], midpos, getRadiusInt());
      double angle = this.context.convertPositionToRadian(rec, midpos);
      double angle2 = angle -= Math.PI / 10.0;

      double distance13 =
          context
              .getCenter()
              .distance(
                  new Point2D.Double(
                      (pt1.getX() + pt3.getX()) / 2.0, (pt1.getY() + pt3.getY()) / 2.0));
      // mid point
      Point2D pt2 =
          new Point2D.Double(
              context.getCenterX() + distance13 * Math.cos(angle2),
              context.getCenterX() + distance13 * Math.sin(angle2));

      Composite old = g.getComposite();
      Stroke olds = g.getStroke();
      g.setStroke(new BasicStroke(0.8f));
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.02f));
      g.setColor(Color.DARK_GRAY);
      GeneralPath p = new GeneralPath();
      p.moveTo(pt1.getX(), pt1.getY());
      p.quadTo(pt2.getX(), pt2.getY(), pt3.getX(), pt3.getY());
      p.closePath();
      g.draw(p);
      g.setComposite(old);
      g.setStroke(olds);
    }
    CloserUtil.close(in);
  }