Changeset 15725 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-01-19T10:36:30+01:00 (5 years ago)
Author:
GerdP
Message:

fix #11914: Allow to show user name in titlebar

  • implement UserIdentityListener in UserIdentityManager
  • add new checkbox "Show user name in title" in "Look and Feel" preference dialog
  • if enabled and not anonymous, show current user prefixed with "@" in titlebar of main window
Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/UserIdentityManager.java

    r14121 r15725  
    2222import org.openstreetmap.josm.tools.CheckParameterUtil;
    2323import org.openstreetmap.josm.tools.JosmRuntimeException;
     24import org.openstreetmap.josm.tools.ListenerList;
    2425import org.openstreetmap.josm.tools.Logging;
    2526
     
    5758
    5859    private static UserIdentityManager instance;
     60    private final ListenerList<UserIdentityListener> listeners = ListenerList.create();
    5961
    6062    /**
     
    9799        userName = null;
    98100        userInfo = null;
     101        fireUserIdentityChanged();
    99102    }
    100103
     
    115118        this.userName = trimmedUserName;
    116119        userInfo = null;
     120        fireUserIdentityChanged();
    117121    }
    118122
     
    135139        this.userName = trimmedUserName;
    136140        this.userInfo = userInfo;
     141        fireUserIdentityChanged();
    137142    }
    138143
     
    209214     */
    210215    public void initFromPreferences() {
    211         String userName = CredentialsManager.getInstance().getUsername();
     216        String credentialsUserName = CredentialsManager.getInstance().getUsername();
    212217        if (isAnonymous()) {
    213             if (userName != null && !userName.trim().isEmpty()) {
    214                 setPartiallyIdentified(userName);
     218            if (credentialsUserName != null && !credentialsUserName.trim().isEmpty()) {
     219                setPartiallyIdentified(credentialsUserName);
    215220            }
    216221        } else {
    217             if (userName != null && !userName.equals(this.userName)) {
    218                 setPartiallyIdentified(userName);
     222            if (credentialsUserName != null && !credentialsUserName.equals(this.userName)) {
     223                setPartiallyIdentified(credentialsUserName);
    219224            }
    220225            // else: same name in the preferences as JOSM already knows about.
     
    312317        }
    313318    }
     319
     320    /**
     321     * This listener is notified whenever the osm user is changed.
     322     */
     323    @FunctionalInterface
     324    public interface UserIdentityListener {
     325        /**
     326         * The current user was changed.
     327         */
     328        void userIdentityChanged();
     329    }
     330
     331    /**
     332     * Add a listener that listens to changes of the current user.
     333     * @param listener The listener
     334     */
     335    public void addListener(UserIdentityListener listener) {
     336        listeners.addListener(listener);
     337    }
     338
     339    private void fireUserIdentityChanged() {
     340        listeners.fireEvent(UserIdentityListener::userIdentityChanged);
     341    }
    314342}
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r14273 r15725  
    2121import javax.swing.JPanel;
    2222
     23import org.openstreetmap.josm.data.UserIdentityManager;
    2324import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    2425import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     
    103104        MainApplication.getLayerManager().addActiveLayerChangeListener(e -> refreshTitle());
    104105        MainApplication.getLayerManager().addAndFireLayerChangeListener(new ManageLayerListeners());
    105 
     106        UserIdentityManager.getInstance().addListener(this::refreshTitle);
     107        Config.getPref().addKeyPreferenceChangeListener("draw.show-user", e -> refreshTitle());
    106108        refreshTitle();
    107109
     
    166168        boolean dirty = editLayer != null && (editLayer.requiresSaveToFile()
    167169                || (editLayer.requiresUploadToServer() && !editLayer.isUploadDiscouraged()));
    168         setTitle((dirty ? "* " : "") + tr("Java OpenStreetMap Editor"));
     170        String userInfo = UserIdentityManager.getInstance().getUserName();
     171        if (userInfo != null && Config.getPref().getBoolean("draw.show-user", false))
     172            userInfo = tr(" ({0})", "@" + userInfo);
     173        else
     174            userInfo = "";
     175        setTitle((dirty ? "* " : "") + tr("Java OpenStreetMap Editor") + userInfo);
    169176        getRootPane().putClientProperty("Window.documentModified", dirty);
    170177    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java

    r14306 r15725  
    8181    VerticallyScrollablePanel panel;
    8282    private final JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup"));
     83    private final JCheckBox showUser = new JCheckBox(tr("Show user name in title"));
    8384    private final JCheckBox showID = new JCheckBox(tr("Show object ID in selection lists"));
    8485    private final JCheckBox showVersion = new JCheckBox(tr("Show object version in selection lists"));
     
    130131        panel.add(showSplashScreen, GBC.eop().insets(20, 0, 0, 0));
    131132
     133        // Show user name in title
     134        showUser.setToolTipText(tr("Show user name in title"));
     135        showUser.setSelected(Config.getPref().getBoolean("draw.show-user", false));
     136
    132137        // Show ID in selection
    133138        showID.setToolTipText(tr("Show object ID in selection lists"));
     
    151156        ExpertToggleAction.addVisibilitySwitcher(modeless);
    152157
     158        panel.add(showUser, GBC.eop().insets(20, 0, 0, 0));
    153159        panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
    154160        panel.add(showVersion, GBC.eop().insets(20, 0, 0, 0));
     
    216222        boolean mod = false;
    217223        Config.getPref().putBoolean("draw.splashscreen", showSplashScreen.isSelected());
     224        Config.getPref().putBoolean("draw.show-user", showUser.isSelected());
    218225        Config.getPref().putBoolean("osm-primitives.showid", showID.isSelected());
    219226        Config.getPref().putBoolean("osm-primitives.showversion", showVersion.isSelected());
Note: See TracChangeset for help on using the changeset viewer.