Changeset 8556 in josm for trunk


Ignore:
Timestamp:
2015-07-01T22:06:09+02:00 (9 years ago)
Author:
bastiK
Message:

applied #11636 - Moved cursor management to new class and used java library functions for the cursor stack

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r8554 r8556  
    5252import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    5353import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
     54import org.openstreetmap.josm.gui.util.CursorManager;
    5455import org.openstreetmap.josm.tools.Predicate;
    5556import org.openstreetmap.josm.tools.Utils;
     
    187188
    188189    protected transient ViewportData initialViewport;
     190
     191    protected transient final CursorManager cursorManager = new CursorManager(this);
    189192
    190193    /**
     
    14371440    }
    14381441
    1439     private static class CursorInfo {
    1440         private final Cursor cursor;
    1441         private final Object object;
    1442 
    1443         public CursorInfo(Cursor c, Object o) {
    1444             cursor = c;
    1445             object = o;
    1446         }
    1447     }
    1448 
    1449     private LinkedList<CursorInfo> cursors = new LinkedList<>();
    1450 
    14511442    /**
    14521443     * Set new cursor.
    14531444     */
    14541445    public void setNewCursor(Cursor cursor, Object reference) {
    1455         if (!cursors.isEmpty()) {
    1456             CursorInfo l = cursors.getLast();
    1457             if (l != null && l.cursor == cursor && l.object == reference)
    1458                 return;
    1459             stripCursors(reference);
    1460         }
    1461         cursors.add(new CursorInfo(cursor, reference));
    1462         setCursor(cursor);
     1446        cursorManager.setNewCursor(cursor, reference);
    14631447    }
    14641448
     
    14711455     */
    14721456    public void resetCursor(Object reference) {
    1473         if (cursors.isEmpty()) {
    1474             setCursor(null);
    1475             return;
    1476         }
    1477         CursorInfo l = cursors.getLast();
    1478         stripCursors(reference);
    1479         if (l != null && l.object == reference) {
    1480             if (cursors.isEmpty()) {
    1481                 setCursor(null);
    1482             } else {
    1483                 setCursor(cursors.getLast().cursor);
    1484             }
    1485         }
    1486     }
    1487 
    1488     private void stripCursors(Object reference) {
    1489         LinkedList<CursorInfo> c = new LinkedList<>();
    1490         for (CursorInfo i : cursors) {
    1491             if (i.object != reference) {
    1492                 c.add(i);
    1493             }
    1494         }
    1495         cursors = c;
     1457        cursorManager.resetCursor(reference);
     1458    }
     1459
     1460    /**
     1461     * Gets the cursor manager that is used for this NavigatableComponent.
     1462     * @return The cursor manager.
     1463     */
     1464    public CursorManager getCursorManager() {
     1465        return cursorManager;
    14961466    }
    14971467
Note: See TracChangeset for help on using the changeset viewer.