コード例 #1
0
ファイル: MapPanel.java プロジェクト: chai4d/mBusMap
  private void drawPoint(Graphics2D g2d) {
    int mapPointX1 = (startX / MAP_POINT_WIDTH) + 1;
    int mapPointX2 = (endX / MAP_POINT_WIDTH) + 1;
    int mapPointY1 = (startY / MAP_POINT_HEIGHT) + 1;
    int mapPointY2 = (endY / MAP_POINT_HEIGHT) + 1;

    Stroke oldStroke = g2d.getStroke();

    for (int y = mapPointY1; y <= mapPointY2; y++) {
      for (int x = mapPointX1; x <= mapPointX2; x++) {
        String mapPointKey = (x < 10 ? "0" + x : "" + x) + (y < 10 ? "0" + y : "" + y);

        List<PointInfo> points = null;
        if (mapPoint.containsKey(mapPointKey)) {
          points = mapPoint.get(mapPointKey);
        } else {
          points = MapDbBean.loadMapPoint(x, y);
          mapPoint.put(mapPointKey, points);
        }

        for (int i = 0; i < points.size(); i++) {
          PointInfo pointInfo = points.get(i);
          if (pointInfo.getMode() == Mode.DELETE) {
            continue;
          }

          int p_x = pointInfo.getAxisX() - startX;
          int p_y = pointInfo.getAxisY() - startY;

          if (pointInfo.getType() == PointType.LINK) {
            if (!((mainFrame.getMapMode() == MapMode.VIEW
                    || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
                && !mainFrame.containsViewType(ViewType.VIEW_POINT_LINK))) {
              drawPointOut(g2d, p_x, p_y, pointInfo);
            }
          } else if (pointInfo.getType() == PointType.NAME) {
            if (!((mainFrame.getMapMode() == MapMode.VIEW
                    || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
                && !mainFrame.containsViewType(ViewType.VIEW_POINT_NAME))) {
              drawPointOut(g2d, p_x, p_y, pointInfo);
              drawPointIn(g2d, p_x, p_y);
            }
          }
        }
      }
    }

    g2d.setStroke(oldStroke);
  }
コード例 #2
0
ファイル: MapPanel.java プロジェクト: chai4d/mBusMap
  private void drawBusNo(Graphics2D g2d) {
    if (busSelect != null
        && (mainFrame.getMapMode() == MapMode.VIEW || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
        && mainFrame.containsViewType(ViewType.VIEW_BUS_NO)) {
      LinkedHashMap<String, String> hLabel = new LinkedHashMap<String, String>();
      Hashtable<Long, BusInfo> hBusNo = new Hashtable<Long, BusInfo>();
      List<BusLine> mapBusLine = busSelect.getBusLine();
      for (int i = 0; i < mapBusLine.size(); i++) {
        BusLine busLine = mapBusLine.get(i);
        if (busLine.getMode() == Mode.DELETE) {
          continue;
        }

        BusInfo busInfo = null;
        if (hBusNo.containsKey(busLine.getBusId())) {
          busInfo = hBusNo.get(busLine.getBusId());
        } else {
          busInfo = MapDbBean.loadBusInfoById(busLine.getBusId());
          hBusNo.put(busLine.getBusId(), busInfo);
        }

        int x1 = Math.min(busLine.getX1(), busLine.getX2()) - startX;
        int y1 = Math.min(busLine.getY1(), busLine.getY2()) - startY;
        int x2 = Math.max(busLine.getX1(), busLine.getX2()) - startX;
        int y2 = Math.max(busLine.getY1(), busLine.getY2()) - startY;

        String sBus = null;
        if (busInfo.getBusNoTh().equals(busInfo.getBusNoEn())) {
          sBus = busInfo.getBusNoTh();
        } else {
          sBus = busInfo.getBusNoTh() + "/" + busInfo.getBusNoEn();
        }
        int x = x1 + ((x2 - x1) / 2);
        int y = y1 + ((y2 - y1) / 2);

        String key = x + "|" + y;
        String label = null;
        if (hLabel.containsKey(key)) {
          label = hLabel.get(key) + "," + sBus;
        } else {
          label = sBus;
        }
        hLabel.put(key, label);
      }

      g2d.setFont(new Font("Tahoma", Font.PLAIN, 12));

      Iterator<String> it = hLabel.keySet().iterator();
      while (it.hasNext()) {
        String key = it.next();
        String label = hLabel.get(key);

        StringTokenizer token = new StringTokenizer(key, "|");
        int x = Integer.parseInt(token.nextToken());
        int y = Integer.parseInt(token.nextToken());

        int w = g2d.getFontMetrics().stringWidth(label);
        int h = (int) g2d.getFontMetrics().getLineMetrics(label, g2d).getHeight();

        g2d.setColor(MapConstants.labelBG);
        g2d.fillRect(x - (w / 2) - 1, y - h + 2, w + 2, h);

        g2d.setColor(MapConstants.labelFG);
        g2d.drawString(label, x - (w / 2), y);
      }
    }
  }