Example #1
0
 private void removeBusLine(BusLine aBusLine) {
   if (aBusLine.getMode() == Mode.INSERT) {
     busSelect.getBusLine().remove(aBusLine);
   } else {
     aBusLine.setMode(Mode.DELETE);
   }
   busSelect.setEdited();
   mainFrame.onSelectBus(busSelect);
 }
Example #2
0
  private BusLine findBusLine(PointInfo p1, PointInfo p2) {
    if (busSelect != null) {
      List<BusLine> mapBusLine = busSelect.getBusLine();
      for (int i = 0; mapBusLine != null && i < mapBusLine.size(); i++) {
        BusLine busLine = mapBusLine.get(i);
        if (busLine.getMode() == Mode.DELETE) {
          continue;
        }

        if (busLine.getType() == LineType.BIDIRECT) {
          if ((busLine.getP1Id() == p1.getPId() && busLine.getP2Id() == p2.getPId())
              || (busLine.getP2Id() == p1.getPId() && busLine.getP1Id() == p2.getPId())) {
            return busLine;
          }
        } else if (busLine.getType() == LineType.P1_P2) {
          if (busLine.getP1Id() == p1.getPId() && busLine.getP2Id() == p2.getPId()) {
            return busLine;
          }
        } else if (busLine.getType() == LineType.P2_P1) {
          if (busLine.getP2Id() == p1.getPId() && busLine.getP1Id() == p2.getPId()) {
            return busLine;
          }
        }
      }
    }
    return null;
  }
Example #3
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;
 }
Example #4
0
  private List<BusLine> findBusLines(PointInfo p) {
    List<BusLine> result = new ArrayList<BusLine>();
    if (busSelect != null) {
      List<BusLine> mapBusLine = busSelect.getBusLine();
      for (int i = 0; mapBusLine != null && i < mapBusLine.size(); i++) {
        BusLine busLine = mapBusLine.get(i);
        if (busLine.getMode() == Mode.DELETE) {
          continue;
        }

        if (busLine.getP1Id() == p.getPId() || busLine.getP2Id() == p.getPId()) {
          result.add(busLine);
        }
      }
    }
    return result;
  }
Example #5
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);
      }
    }
  }
Example #6
0
  private void drawBusLine(Graphics2D g2d) {
    if (busSelect != null) {
      Stroke oldStroke = g2d.getStroke();
      BasicStroke lineStroke =
          new BasicStroke(MapConstants.lineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

      Hashtable<Long, Color> hLineColor = new Hashtable<Long, Color>();
      List<BusLine> mapBusLine = busSelect.getBusLine();
      for (int i = 0; i < mapBusLine.size(); i++) {
        BusLine busLine = mapBusLine.get(i);
        if (busLine.getMode() == Mode.DELETE) {
          continue;
        }

        Color hColor = null;
        if (mainFrame.getMapMode() == MapMode.VIEW
            || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
          if (hLineColor.containsKey(busLine.getBusId())) {
            hColor = hLineColor.get(busLine.getBusId());
          } else {
            hColor = MapConstants.lineColor[(hLineColor.size() % MapConstants.lineColor.length)];
            hLineColor.put(busLine.getBusId(), hColor);
          }
        }

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

        switch (busLine.getType()) {
          case BIDIRECT:
            if ((mainFrame.getMapMode() == MapMode.VIEW
                    || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
                && !mainFrame.containsViewType(ViewType.VIEW_TWO_WAY)) {
              break;
            }
            if (mainFrame.getMapMode() == MapMode.VIEW
                || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
              g2d.setColor(hColor);
            } else {
              g2d.setColor(MapConstants.lineColorBiDirect);
            }
            g2d.setStroke(lineStroke);
            g2d.drawLine(x1, y1, x2, y2);
            break;
          case P1_P2:
            if ((mainFrame.getMapMode() == MapMode.VIEW
                    || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
                && !mainFrame.containsViewType(ViewType.VIEW_ONE_WAY)) {
              break;
            }
            if (mainFrame.getMapMode() == MapMode.VIEW
                || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
              g2d.setColor(hColor);
            } else {
              g2d.setColor(MapConstants.lineColorOneWay);
            }
            g2d.setStroke(lineStroke);
            g2d.drawLine(x1, y1, x2, y2);
            drawArrow(g2d, x1, y1, x2, y2, MapConstants.lineSize);
            break;
          case P2_P1:
            if ((mainFrame.getMapMode() == MapMode.VIEW
                    || mainFrame.getMapMode() == MapMode.TEST_ROUTE)
                && !mainFrame.containsViewType(ViewType.VIEW_ONE_WAY)) {
              break;
            }
            if (mainFrame.getMapMode() == MapMode.VIEW
                || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
              g2d.setColor(hColor);
            } else {
              g2d.setColor(MapConstants.lineColorOneWay);
            }
            g2d.setStroke(lineStroke);
            g2d.drawLine(x2, y2, x1, y1);
            drawArrow(g2d, x2, y2, x1, y1, MapConstants.lineSize);
            break;
        }
      }

      g2d.setStroke(oldStroke);
    } else if (busChoices != null && busChoices.size() > 0) {
      Stroke oldStroke = g2d.getStroke();
      BasicStroke lineStroke =
          new BasicStroke(MapConstants.lineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

      BusChoice busChoice = busChoices.get(busChoiceIndex);
      List<ABus> buses = busChoice.getBuses();
      for (int i = 0; i < buses.size(); i++) {
        ABus aBus = buses.get(i);
        List<BusPath> busPaths = aBus.getBusPaths();
        for (int j = 0; j < busPaths.size(); j++) {
          BusPath busPath = busPaths.get(j);

          int x1 = busPath.getX1() - startX;
          int y1 = busPath.getY1() - startY;
          int x2 = busPath.getX2() - startX;
          int y2 = busPath.getY2() - startY;

          g2d.setColor(MapConstants.lineColor[i % MapConstants.lineColor.length]);
          g2d.setStroke(lineStroke);
          g2d.drawLine(x1, y1, x2, y2);
          drawArrow(g2d, x1, y1, x2, y2, MapConstants.lineSize);
        }
      }

      g2d.setStroke(oldStroke);
    }
  }