Changeset 19254 in josm for trunk


Ignore:
Timestamp:
2024-11-06T16:27:33+01:00 (2 weeks ago)
Author:
stoecker
Message:

some small cleanups

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

Legend:

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

    r18601 r19254  
    77import java.awt.EventQueue;
    88import java.awt.Graphics;
     9import java.awt.Point;
     10import java.awt.event.MouseMotionListener;
     11import java.awt.event.MouseEvent;
     12import java.awt.event.MouseListener;
    913import java.io.IOException;
    1014import java.nio.charset.StandardCharsets;
     
    1519import javax.swing.JPanel;
    1620import javax.swing.JScrollPane;
     21import javax.swing.SwingUtilities;
    1722import javax.swing.Timer;
    1823import javax.swing.border.EmptyBorder;
    1924import javax.swing.event.HyperlinkEvent;
    2025import javax.swing.event.HyperlinkListener;
     26import javax.swing.event.MouseInputListener;
    2127
    2228import org.openstreetmap.josm.actions.DownloadAction;
     
    2430import org.openstreetmap.josm.actions.HistoryInfoAction;
    2531import org.openstreetmap.josm.data.Version;
     32import org.openstreetmap.josm.gui.animation.AnimationExtension;
    2633import org.openstreetmap.josm.gui.animation.AnimationExtensionManager;
    2734import org.openstreetmap.josm.gui.datatransfer.OpenTransferHandler;
     
    4855 * contains news about recent major changes, warning in case of outdated versions, etc.
    4956 */
    50 public final class GettingStarted extends JPanel implements ProxyPreferenceListener {
     57public final class GettingStarted extends JPanel implements ProxyPreferenceListener, MouseInputListener {
    5158
    5259    private final LinkGeneral lg;
     
    155162        add(scroller, BorderLayout.CENTER);
    156163
     164        scroller.addMouseMotionListener(this);
     165        scroller.addMouseListener(this);
     166        lg.addMouseMotionListener(this);
     167        lg.addMouseListener(this);
     168
    157169        getMOTD();
    158170
     
    177189
    178190    @Override
     191    public void mouseMoved(MouseEvent e) {
     192        final AnimationExtension extension = AnimationExtensionManager.getExtension();
     193        if (extension instanceof MouseMotionListener) {
     194            ((MouseMotionListener) extension).mouseMoved(e);
     195        }
     196    }
     197
     198    @Override
     199    public void mouseDragged(MouseEvent e) {
     200        // Ignored
     201    }
     202
     203    @Override
     204    public void mousePressed(MouseEvent e) {
     205        final AnimationExtension extension = AnimationExtensionManager.getExtension();
     206        if (extension instanceof MouseListener) {
     207            ((MouseListener) extension).mousePressed(e);
     208        }
     209    }
     210
     211    @Override
     212    public void mouseEntered(MouseEvent e) {
     213        // Ignored
     214    }
     215
     216    @Override
     217    public void mouseExited(MouseEvent e) {
     218        // Ignored
     219    }
     220
     221    @Override
     222    public void mouseReleased(MouseEvent e) {
     223        final AnimationExtension extension = AnimationExtensionManager.getExtension();
     224        if (extension instanceof MouseListener) {
     225            ((MouseListener) extension).mouseReleased(e);
     226        }
     227    }
     228
     229    @Override
     230    public void mouseClicked(MouseEvent e) {
     231        // Ignored
     232    }
     233
     234    @Override
    179235    public void paint(Graphics g) {
    180236        super.paint(g);
    181237        if (isShowing()) {
    182             AnimationExtensionManager.getExtension().adjustForSize(getWidth(), getHeight());
     238            Point p = new Point(0, 0);
     239            SwingUtilities.convertPointToScreen(p, this);
     240            AnimationExtensionManager.getExtension().adjustForSize(getWidth(), getHeight(), p.x, p.y);
    183241            AnimationExtensionManager.getExtension().animate();
    184242            AnimationExtensionManager.getExtension().paint(g);
  • trunk/src/org/openstreetmap/josm/gui/animation/AnimationExtension.java

    r14578 r19254  
    1616     * @param w width
    1717     * @param h height
     18     * @param x x origin of view area
     19     * @param y y origin of view area
    1820     */
    19     void adjustForSize(int w, int h);
     21    void adjustForSize(int w, int h, int x, int y);
    2022
    2123    /**
  • trunk/src/org/openstreetmap/josm/gui/animation/AnimationExtensionManager.java

    r17726 r19254  
    33
    44import java.time.LocalDate;
     5import java.time.Month;
    56import java.time.ZoneId;
    67
     
    2829    public static AnimationExtension getExtension() {
    2930        if (currentExtension == null) {
    30             currentExtension = Boolean.TRUE.equals(PROP_ANIMATION.get()) && isChristmas() ? new ChristmasExtension()
    31                     : new NoExtension();
     31            final boolean isAnimated = Boolean.TRUE.equals(PROP_ANIMATION.get());
     32            if (isAnimated && isChristmas()) {
     33                currentExtension = new ChristmasExtension();
     34            } else if (isAnimated && isBirthday()) {
     35                currentExtension = new BirthdayExtension();
     36            } else {
     37                currentExtension = new NoExtension();
     38            }
    3239        }
    3340        return currentExtension;
     
    4653        return LocalDate.now(ZoneId.systemDefault()).getDayOfYear() > 350;
    4754    }
     55
     56    /**
     57     * The first commit of JOSM to svn (r1) was on 2005-09-27
     58     * @return {@code true} if today is JOSM's birthday
     59     */
     60    private static boolean isBirthday() {
     61        LocalDate l = LocalDate.now(ZoneId.systemDefault());
     62        return l.getMonth() == Month.SEPTEMBER && l.getDayOfMonth() == 27;
     63    }
    4864}
  • trunk/src/org/openstreetmap/josm/gui/animation/ChristmasExtension.java

    r18932 r19254  
    2929
    3030    @Override
    31     public final void adjustForSize(int w, int h) {
     31    public final void adjustForSize(int w, int h, int x, int y) {
    3232        int count = w / (2 * (Star.averageStarWidth + 1));
    3333        while (objs.size() > count) {
  • trunk/src/org/openstreetmap/josm/gui/animation/NoExtension.java

    r14581 r19254  
    1616
    1717    @Override
    18     public void adjustForSize(int w, int h) {
     18    public void adjustForSize(int w, int h, int x, int y) {
    1919        // No-op
    2020    }
Note: See TracChangeset for help on using the changeset viewer.