Skip to content

Commit

Permalink
some small cleanups
Browse files Browse the repository at this point in the history
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19254 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
stoecker committed Nov 6, 2024
1 parent aa41ac1 commit 5d016df
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 7 deletions.
62 changes: 60 additions & 2 deletions src/org/openstreetmap/josm/gui/GettingStarted.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
Expand All @@ -14,15 +18,18 @@
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.MouseInputListener;

import org.openstreetmap.josm.actions.DownloadAction;
import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
import org.openstreetmap.josm.actions.HistoryInfoAction;
import org.openstreetmap.josm.data.Version;
import org.openstreetmap.josm.gui.animation.AnimationExtension;
import org.openstreetmap.josm.gui.animation.AnimationExtensionManager;
import org.openstreetmap.josm.gui.datatransfer.OpenTransferHandler;
import org.openstreetmap.josm.gui.dialogs.MenuItemSearchDialog;
Expand All @@ -47,7 +54,7 @@
* It downloads and displays the so called <em>message of the day</em>, which
* contains news about recent major changes, warning in case of outdated versions, etc.
*/
public final class GettingStarted extends JPanel implements ProxyPreferenceListener {
public final class GettingStarted extends JPanel implements ProxyPreferenceListener, MouseInputListener {

private final LinkGeneral lg;
private String content = "";
Expand Down Expand Up @@ -154,6 +161,11 @@ public GettingStarted() {
scroller.setViewportBorder(new EmptyBorder(10, 100, 10, 100));
add(scroller, BorderLayout.CENTER);

scroller.addMouseMotionListener(this);
scroller.addMouseListener(this);
lg.addMouseMotionListener(this);
lg.addMouseListener(this);

getMOTD();

setTransferHandler(new OpenTransferHandler());
Expand All @@ -175,11 +187,57 @@ public void removeNotify() {
super.removeNotify();
}

@Override
public void mouseMoved(MouseEvent e) {
final AnimationExtension extension = AnimationExtensionManager.getExtension();
if (extension instanceof MouseMotionListener) {
((MouseMotionListener) extension).mouseMoved(e);
}
}

@Override
public void mouseDragged(MouseEvent e) {
// Ignored
}

@Override
public void mousePressed(MouseEvent e) {
final AnimationExtension extension = AnimationExtensionManager.getExtension();
if (extension instanceof MouseListener) {
((MouseListener) extension).mousePressed(e);
}
}

@Override
public void mouseEntered(MouseEvent e) {
// Ignored
}

@Override
public void mouseExited(MouseEvent e) {
// Ignored
}

@Override
public void mouseReleased(MouseEvent e) {
final AnimationExtension extension = AnimationExtensionManager.getExtension();
if (extension instanceof MouseListener) {
((MouseListener) extension).mouseReleased(e);
}
}

@Override
public void mouseClicked(MouseEvent e) {
// Ignored
}

@Override
public void paint(Graphics g) {
super.paint(g);
if (isShowing()) {
AnimationExtensionManager.getExtension().adjustForSize(getWidth(), getHeight());
Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, this);
AnimationExtensionManager.getExtension().adjustForSize(getWidth(), getHeight(), p.x, p.y);
AnimationExtensionManager.getExtension().animate();
AnimationExtensionManager.getExtension().paint(g);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ public interface AnimationExtension {
* Adjusts for size.
* @param w width
* @param h height
* @param x x origin of view area
* @param y y origin of view area
*/
void adjustForSize(int w, int h);
void adjustForSize(int w, int h, int x, int y);

/**
* Paints static contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.openstreetmap.josm.gui.animation;

import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;

import org.openstreetmap.josm.data.preferences.BooleanProperty;
Expand All @@ -27,8 +28,14 @@ private AnimationExtensionManager() {
*/
public static AnimationExtension getExtension() {
if (currentExtension == null) {
currentExtension = Boolean.TRUE.equals(PROP_ANIMATION.get()) && isChristmas() ? new ChristmasExtension()
: new NoExtension();
final boolean isAnimated = Boolean.TRUE.equals(PROP_ANIMATION.get());
if (isAnimated && isChristmas()) {
currentExtension = new ChristmasExtension();
} else if (isAnimated && isBirthday()) {
currentExtension = new BirthdayExtension();
} else {
currentExtension = new NoExtension();
}
}
return currentExtension;
}
Expand All @@ -45,4 +52,13 @@ public static boolean isExtensionEnabled() {
private static boolean isChristmas() {
return LocalDate.now(ZoneId.systemDefault()).getDayOfYear() > 350;
}

/**
* The first commit of JOSM to svn (r1) was on 2005-09-27
* @return {@code true} if today is JOSM's birthday
*/
private static boolean isBirthday() {
LocalDate l = LocalDate.now(ZoneId.systemDefault());
return l.getMonth() == Month.SEPTEMBER && l.getDayOfMonth() == 27;
}
}
Loading

0 comments on commit 5d016df

Please sign in to comment.