Beispiel #1
0
 private BusLine addBusLine(PointInfo p1, PointInfo p2) {
   if (p1.equals(p2)) {
     return null;
   }
   BusLine aBusLine = findBusLine(p1, p2);
   if (aBusLine == null) {
     aBusLine =
         new BusLine(
             p1.getPId(),
             p2.getPId(),
             p1.getAxisX(),
             p1.getAxisY(),
             p2.getAxisX(),
             p2.getAxisY(),
             StringUtil.distance(p1.getAxisX(), p1.getAxisY(), p2.getAxisX(), p2.getAxisY()),
             busSelect.getBusId(),
             busSelect.getBusNoTh(),
             busSelect.getBusNoEn(),
             busSelect.getBusPrice(),
             mainFrame.getLineType(),
             "",
             "",
             "",
             "");
     busSelect.getBusLine().add(aBusLine);
     busSelect.setEdited();
     mainFrame.onSelectBus(busSelect);
   }
   return aBusLine;
 }
Beispiel #2
0
  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);
      }
    }
  }