/** * Handle mouse clicks. * * @param event the event to handle */ @SuppressWarnings("ParameterNameDiffersFromOverriddenParameter") @Override public void mouseClicked(@Nullable final MouseEvent event) { if (event != null) { event.getComponent().requestFocusInWindow(); final java.awt.Point eventPoint = event.getPoint(); final VisibleDimensions dimensions = model.getDimensions(); final MapDimensions mapDim = model.getMapDimensions(); final int tileSize = TileViewSize.scaleZoom(model.getZoomLevel(), mapDim.getVersion()); final Point point = PointFactory.point( (eventPoint.y / tileSize) + dimensions.getMinimumRow(), (eventPoint.x / tileSize) + dimensions.getMinimumCol()); if ((point.getRow() < mapDim.getRows()) && (point.getCol() < mapDim.getColumns())) { model.setSelection(point); if (event.isPopupTrigger()) { menu.show(event.getComponent(), event.getX(), event.getY()); } } } }
/** * @param event an event representing the current mouse position * @return a tool-tip message for the tile the mouse is currently over */ @Nullable public String getToolTipText(final MouseEvent event) { final java.awt.Point eventPoint = event.getPoint(); final MapDimensions mapDim = model.getMapDimensions(); final int tileSize = TileViewSize.scaleZoom(model.getZoomLevel(), mapDim.getVersion()); final VisibleDimensions dimensions = model.getDimensions(); final Point point = PointFactory.point( (eventPoint.y / tileSize) + dimensions.getMinimumRow(), (eventPoint.x / tileSize) + dimensions.getMinimumCol()); if ((point.getRow() < mapDim.getRows()) && (point.getCol() < mapDim.getColumns())) { return concat( "<html><body>", point.toString(), ": ", model.getMap().getBaseTerrain(point).toString(), "<br />", getTerrainFixturesAndTop(point), "<br/></body></html>"); } else { return null; } }
/** * @param point a point * @return a HTML-wrapped String (including final newline entity) representing the TerrainFixtures * at that point, and the fixture the user can see as its top fixture. */ private String getTerrainFixturesAndTop(final Point point) { final IMapNG map = model.getMap(); final Collection<TileFixture> fixes = new ArraySet<>(); if (map.isMountainous(point)) { fixes.add(new Mountain()); } final Ground ground = map.getGround(point); if (ground != null) { fixes.add(ground); } final Forest forest = map.getForest(point); if (forest != null) { fixes.add(forest); } final Optional<TileFixture> first = map.streamOtherFixtures(point).findAny(); first.ifPresent(fixes::add); map.streamOtherFixtures(point).filter(TerrainFixture.class::isInstance).forEach(fixes::add); return fixes.stream().map(TileFixture::toString).collect(Collectors.joining("<br />")); }
/** @param mapModel the map model we'll refer to */ public ComponentMouseListener(final IViewerModel mapModel) { model = mapModel; menu = new TerrainChangingMenu(model.getMapDimensions().version, model); model.addSelectionChangeListener(menu); model.addVersionChangeListener(menu); }