Example #1
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);
  }
Example #2
0
 public void mousePressed(MouseEvent e) {
   if (e.getButton() == MapConstants.MOUSE_BUTTON_LEFT && e.getClickCount() == 1) {
     if (mainFrame.getMapMode() == MapMode.VIEW || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
       dragX = e.getX();
       dragY = e.getY();
     } else if (mainFrame.getMapMode() == MapMode.ADD_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_BUS
         || mainFrame.getMapMode() == MapMode.COPY_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
       PointInfo aPoint = findPoint(e.getX(), e.getY());
       if (aPoint == null) {
         dragX = e.getX();
         dragY = e.getY();
       } else {
         dragPoint = aPoint;
       }
     }
   }
 }
Example #3
0
  public void mouseReleased(MouseEvent e) {
    if (this.contains(e.getPoint()) == false) {
      MapStatusBar.setCoordinate("");
    }

    if (e.getButton() == MapConstants.MOUSE_BUTTON_LEFT && e.getClickCount() == 1) {
      if (mainFrame.getMapMode() == MapMode.VIEW || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
        dragX = MapConstants.NULL;
        dragY = MapConstants.NULL;
        updateStatusMessage();
      } else if (mainFrame.getMapMode() == MapMode.ADD_BUS
          || mainFrame.getMapMode() == MapMode.EDIT_BUS
          || mainFrame.getMapMode() == MapMode.COPY_BUS
          || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
        dragX = MapConstants.NULL;
        dragY = MapConstants.NULL;
        dragPoint = null;
        updateStatusMessage();
      }
    }
  }
Example #4
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();
      }
    }
  }
Example #5
0
 public void refreshMode() {
   MapMode mode = mainFrame.getMapMode();
   switch (mode) {
     case VIEW:
       pointSelect = null;
       busSelect = null;
       busChoices = null;
       break;
     case TEST_ROUTE:
       pointSelect = null;
       busSelect = null;
       // busChoices = new ArrayList<BusChoice>(); // From Popup Route Select Screen
       break;
     case ADD_BUS:
       pointSelect = null;
       busSelect = new BusInfo();
       busChoices = null;
       break;
     case EDIT_BUS:
       pointSelect = null;
       // busSelect = new BusInfo(); // From Popup Bus Select screen
       busChoices = null;
       break;
     case DEL_BUS:
       pointSelect = null;
       // busSelect = new BusInfo(); // From Popup Bus Select screen
       busChoices = null;
       break;
     case COPY_BUS:
       pointSelect = null;
       // busSelect = new BusInfo(); // From Popup Bus Select screen
       busChoices = null;
       break;
     case EDIT_POINT:
       pointSelect = null;
       busSelect = null;
       busChoices = null;
       break;
   }
   mainFrame.onSelectPoint(pointSelect);
   mainFrame.onSelectBus(busSelect);
   repaint();
 }
Example #6
0
 private void doubleClicked(MouseEvent e) {
   if (e.getButton() == MapConstants.MOUSE_BUTTON_LEFT) {
     if (mainFrame.getMapMode() == MapMode.ADD_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_BUS
         || mainFrame.getMapMode() == MapMode.COPY_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
       mainFrame.onSave();
     }
   } else if (e.getButton() == MapConstants.MOUSE_BUTTON_RIGHT) {
     if (mainFrame.getMapMode() == MapMode.ADD_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_BUS
         || mainFrame.getMapMode() == MapMode.COPY_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
       mainFrame.onReset();
     }
   }
 }
Example #7
0
 private void oneClicked(MouseEvent e) {
   if (e.getButton() == MapConstants.MOUSE_BUTTON_LEFT) {
     if (mainFrame.getMapMode() == MapMode.ADD_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_BUS
         || mainFrame.getMapMode() == MapMode.COPY_BUS) {
       PointInfo aPoint = addPoint(e.getX(), e.getY());
       if (pointSelect == null) {
         pointSelect = aPoint;
       } else {
         addBusLine(pointSelect, aPoint);
         pointSelect = aPoint;
       }
       mainFrame.onSelectPoint(pointSelect);
       repaint();
     } else if (mainFrame.getMapMode() == MapMode.EDIT_POINT
         || mainFrame.getMapMode() == MapMode.VIEW
         || mainFrame.getMapMode() == MapMode.TEST_ROUTE) {
       PointInfo aPoint = findPoint(e.getX(), e.getY());
       if (aPoint != null) {
         pointSelect = aPoint;
         mainFrame.onSelectPoint(pointSelect);
         repaint();
       }
     }
   } else if (e.getButton() == MapConstants.MOUSE_BUTTON_RIGHT) {
     if (mainFrame.getMapMode() == MapMode.ADD_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_BUS
         || mainFrame.getMapMode() == MapMode.COPY_BUS
         || mainFrame.getMapMode() == MapMode.EDIT_POINT) {
       PointInfo aPoint = findPoint(e.getX(), e.getY());
       if (aPoint != null) {
         removePoint(aPoint);
         pointSelect = null;
         mainFrame.onSelectPoint(pointSelect);
         repaint();
       }
     }
   }
 }
Example #8
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 #9
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);
    }
  }