Пример #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;
 }
Пример #2
0
 private void updateStatusMessage() {
   String msg = "";
   if (dragX != MapConstants.NULL && dragY != MapConstants.NULL) {
     msg =
         "Moving the map to ("
             + StringUtil.toNumString(startX)
             + " : "
             + StringUtil.toNumString(startY)
             + " - "
             + StringUtil.toNumString(endX)
             + " : "
             + StringUtil.toNumString(endY)
             + ") of ("
             + StringUtil.toNumString(MAP_MAX_WIDTH)
             + " : "
             + StringUtil.toNumString(MAP_MAX_HEIGHT)
             + ")";
   } else if (dragPoint != null) {
     msg =
         "Moving the point to ("
             + StringUtil.toNumString(dragPoint.getAxisX())
             + " : "
             + StringUtil.toNumString(dragPoint.getAxisY())
             + ")";
   } else if (pointSelect != null) {
     if (pointSelect.getType() == PointType.LINK) {
       msg =
           "Linked Point ("
               + StringUtil.toNumString(pointSelect.getAxisX())
               + " : "
               + StringUtil.toNumString(pointSelect.getAxisY())
               + ")";
     } else if (pointSelect.getType() == PointType.NAME) {
       msg =
           "Named Point ("
               + StringUtil.toNumString(pointSelect.getAxisX())
               + " : "
               + StringUtil.toNumString(pointSelect.getAxisY())
               + ")";
     }
   } else {
     msg =
         "Now showing ("
             + StringUtil.toNumString(startX)
             + " : "
             + StringUtil.toNumString(startY)
             + " - "
             + StringUtil.toNumString(endX)
             + " : "
             + StringUtil.toNumString(endY)
             + ") of ("
             + StringUtil.toNumString(MAP_MAX_WIDTH)
             + " : "
             + StringUtil.toNumString(MAP_MAX_HEIGHT)
             + ")";
   }
   MapStatusBar.setMessage(msg);
 }
Пример #3
0
  private void movingMap(int x, int y) {
    MapStatusBar.setCoordinate(StringUtil.toNumString(x) + " : " + StringUtil.toNumString(y));

    if (mainFrame.getMapMode() == MapMode.VIEW
        || mainFrame.getMapMode() == MapMode.TEST_ROUTE
        || mainFrame.getMapMode() == MapMode.ADD_BUS
        || mainFrame.getMapMode() == MapMode.EDIT_BUS
        || mainFrame.getMapMode() == MapMode.COPY_BUS
        || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
      if (dragX != MapConstants.NULL && dragY != MapConstants.NULL) {
        int diffX = x - dragX;
        int diffY = y - dragY;
        dragX = x;
        dragY = y;

        startX -= diffX;
        startY -= diffY;
        repaint();
      }
    }
    if (mainFrame.getMapMode() == MapMode.ADD_BUS
        || mainFrame.getMapMode() == MapMode.EDIT_BUS
        || mainFrame.getMapMode() == MapMode.COPY_BUS
        || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
      if (dragPoint != null) {
        List<PointInfo> oldMapPoint = selectMapPoint(dragPoint.getAxisX(), dragPoint.getAxisY());

        dragPoint.setAxisX(x + startX);
        dragPoint.setAxisY(y + startY);
        dragPoint.setEdited();
        if (dragPoint.equals(pointSelect)) {
          mainFrame.onSelectPoint(pointSelect);
        }

        List<PointInfo> newMapPoint = selectMapPoint(dragPoint.getAxisX(), dragPoint.getAxisY());
        if (!oldMapPoint.equals(newMapPoint)) {
          oldMapPoint.remove(dragPoint);
          newMapPoint.add(dragPoint);
        }

        List<BusLine> busLines = findBusLines(dragPoint);
        for (int i = 0; i < busLines.size(); i++) {
          BusLine busLine = busLines.get(i);
          if (busLine.getP1Id() == dragPoint.getPId()) {
            busLine.setX1(dragPoint.getAxisX());
            busLine.setY1(dragPoint.getAxisY());
          } else if (busLine.getP2Id() == dragPoint.getPId()) {
            busLine.setX2(dragPoint.getAxisX());
            busLine.setY2(dragPoint.getAxisY());
          }
        }
        repaint();
      }
    }
  }
Пример #4
0
  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);
  }
Пример #5
0
 private void removePoint(PointInfo aPoint) {
   List<BusLine> busLines = findBusLines(aPoint);
   if (busLines.size() > 0) {
     for (int i = 0; i < busLines.size(); i++) {
       BusLine busLine = busLines.get(i);
       removeBusLine(busLine);
     }
   } else {
     if (aPoint.getMode() == Mode.INSERT) {
       List<PointInfo> points = selectMapPoint(aPoint.getAxisX(), aPoint.getAxisY());
       points.remove(aPoint);
     } else {
       aPoint.setMode(Mode.DELETE);
     }
   }
 }
Пример #6
0
  private PointInfo findPoint(int x, int y) {
    List<PointInfo> points = selectMapPoint(x + startX, y + startY);
    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;
      int area = MapConstants.pointSizeOut / 2;

      if ((p_x - area) <= x && x <= (p_x + area) && (p_y - area) <= y && y <= (p_y + area)) {
        return pointInfo;
      }
    }
    return null;
  }