Ticket #11981: 11981-alpha.patch

File 11981-alpha.patch, 5.3 KB (added by simon04, 11 years ago)
  • src/org/openstreetmap/josm/gui/GettingStarted.java

    diff --git a/src/org/openstreetmap/josm/gui/GettingStarted.java b/src/org/openstreetmap/josm/gui/GettingStarted.java
    index 5ca8b19..a694a64 100644
    a b  
    66import java.awt.BorderLayout;
    77import java.awt.EventQueue;
    88import java.awt.GraphicsEnvironment;
     9import java.awt.GridBagLayout;
    910import java.awt.event.InputEvent;
    1011import java.awt.event.KeyEvent;
    1112import java.io.IOException;
     
    1415import java.util.regex.Matcher;
    1516import java.util.regex.Pattern;
    1617
     18import javax.swing.Action;
     19import javax.swing.JButton;
    1720import javax.swing.JComponent;
     21import javax.swing.JLabel;
    1822import javax.swing.JPanel;
    1923import javax.swing.JScrollPane;
    2024import javax.swing.KeyStroke;
     25import javax.swing.SwingConstants;
    2126import javax.swing.border.EmptyBorder;
    2227import javax.swing.event.HyperlinkEvent;
    2328import javax.swing.event.HyperlinkListener;
    2429
    2530import org.openstreetmap.josm.Main;
     31import org.openstreetmap.josm.actions.DownloadAction;
     32import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
     33import org.openstreetmap.josm.actions.OverpassDownloadAction;
    2634import org.openstreetmap.josm.data.Version;
     35import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
    2736import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
    2837import org.openstreetmap.josm.gui.preferences.server.ProxyPreferenceListener;
    2938import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
    3039import org.openstreetmap.josm.io.CacheCustomContent;
    3140import org.openstreetmap.josm.io.OnlineResource;
     41import org.openstreetmap.josm.tools.GBC;
    3242import org.openstreetmap.josm.tools.LanguageInfo;
    3343import org.openstreetmap.josm.tools.OpenBrowser;
     44import org.openstreetmap.josm.tools.Utils;
    3445import org.openstreetmap.josm.tools.WikiReader;
    3546
    3647public final class GettingStarted extends JPanel implements ProxyPreferenceListener {
    public GettingStarted() {  
    129140        scroller.setViewportBorder(new EmptyBorder(10, 100, 10, 100));
    130141        add(scroller, BorderLayout.CENTER);
    131142
     143        final JPanel commands = new JPanel(new GridBagLayout());
     144        add(commands, BorderLayout.WEST);
     145
     146        for (Action action: new Action[]{
     147                new DownloadAction(),
     148                new OverpassDownloadAction(),
     149                new DownloadPrimitiveAction(),
     150        }) {
     151            final JButton button = new JButton(action);
     152            button.setHorizontalAlignment(SwingConstants.LEFT);
     153            commands.add(button, GBC.eop().fill(GBC.HORIZONTAL    ));
     154        }
     155
     156        //todo refresh list every time the GettingStarted panel is being displayed
     157        commands.add(new JLabel(tr("Open Recent")), GBC.eol());
     158        for (Action recentAction : RecentlyOpenedFilesMenu.getActions()) {
     159            final JButton button = new JButton(recentAction);
     160            button.setToolTipText(button.getText());
     161            button.setText(Utils.shortenString(button.getText(), 32));
     162            button.setHorizontalAlignment(SwingConstants.LEFT);
     163            commands.add(button, GBC.eol().fill(GBC.HORIZONTAL));
     164        }
     165
     166        commands.add(new JPanel(), GBC.std().fill());
     167
    132168        getMOTD();
    133169
    134170        if (!GraphicsEnvironment.isHeadless()) {
  • src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java

    diff --git a/src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java b/src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java
    index 9093f0e..a129b58 100644
    a b  
    66
    77import java.awt.event.ActionEvent;
    88import java.io.File;
     9import java.util.ArrayList;
    910import java.util.Collection;
    1011import java.util.Collections;
     12import java.util.List;
    1113
    1214import javax.swing.AbstractAction;
     15import javax.swing.Action;
    1316import javax.swing.JMenu;
    1417import javax.swing.JMenuItem;
    1518import javax.swing.JSeparator;
     
    2528 */
    2629public class RecentlyOpenedFilesMenu extends JMenu {
    2730    private ClearAction clearAction;
     31    private static final Collection<String> fileHistory = Main.pref.getCollection("file-open.history");
    2832
    2933    public RecentlyOpenedFilesMenu() {
    3034        super(tr("Open Recent"));
    public void menuCanceled(MenuEvent e) {  
    4953        });
    5054    }
    5155
    52     private void rebuild() {
    53         removeAll();
    54         Collection<String> fileHistory = Main.pref.getCollection("file-open.history");
    55 
     56    public static List<Action> getActions() {
     57        final List<Action> actions = new ArrayList<>(fileHistory.size());
    5658        for (final String file : fileHistory) {
    57             add(new AbstractAction() {
     59            actions.add(new AbstractAction() {
    5860                {
    5961                    putValue(NAME, file);
    6062                    putValue("help", ht("/Action/OpenRecent"));
    6163                    putValue("toolbar", Boolean.FALSE);
    6264                }
     65
    6366                @Override
    6467                public void actionPerformed(ActionEvent e) {
    6568                    File f = new File(file);
    public void actionPerformed(ActionEvent e) {  
    6972                }
    7073            });
    7174        }
     75        return actions;
     76    }
     77
     78    private void rebuild() {
     79        removeAll();
     80        for (Action action : getActions()) {
     81            add(action);
     82        }
    7283        add(new JSeparator());
    7384        if (clearAction == null) {
    7485            clearAction = new ClearAction();