我有一个 Swing 应用程序,地图上有一个玻璃窗格。
它在某些位置绘制点。当我单击地图上的某个位置时,玻璃窗格收到消息CONTROLLER_NEW_POLYGON_MARK
,我希望在事件数据中指定的位置显示一个额外的点(请参阅 参考资料MyGlassPane.propertyChange
)。
玻璃窗格类称为MyGlassPane
。使用我验证过的调试器,addPointToMark
它实际上是在propertyChange
.
但屏幕上没有出现额外的点。
如何更改代码以便在触发PointSetMarkingGlassPane.paintComponent
事件 () 时调用它?IEventBus.CONTROLLER_NEW_POLYGON_MARK
public class PointSetMarkingGlassPane extends JComponent implements IGlassPane {
private final ILatLongToScreenCoordinatesConverter latLongToScreenCoordinatesConverter;
private final List<Point.Double> pointsToMark = new LinkedList<Point.Double>();
public PointSetMarkingGlassPane(final ILatLongToScreenCoordinatesConverter aConverter) {
this.latLongToScreenCoordinatesConverter = aConverter;
}
protected void addPointToMark(final Point.Double aPoint)
{
if (aPoint != null)
{
pointsToMark.add(aPoint);
}
}
@Override
protected void paintComponent(final Graphics aGraphics) {
for (final Point.Double pointToMark : pointsToMark)
{
final Point positionInScreenCoords = latLongToScreenCoordinatesConverter.getScreenCoordinates(pointToMark);
drawCircle(aGraphics, positionInScreenCoords, Color.red);
}
}
private void drawCircle(Graphics g, Point point, Color color) {
g.setColor(color);
g.fillOval(point.x, point.y, 10, 10);
}
}
public class MyGlassPane extends PointSetMarkingGlassPane implements PropertyChangeListener {
public MyGlassPane(ILatLongToScreenCoordinatesConverter aConverter) {
super(aConverter);
addPointToMark(DemoGlassPane.ARTYOM);
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (IEventBus.CONTROLLER_NEW_POLYGON_MARK.equals(evt.getPropertyName()))
{
addPointToMark((Point.Double)evt.getNewValue());
invalidate();
}
}
}