Ticket #7450: TopPanelsAndImageryNagging.patch

File TopPanelsAndImageryNagging.patch, 8.1 KB (added by akks, 12 years ago)
  • images/misc/black_x.png

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
  • src/org/openstreetmap/josm/gui/MapFrame.java

    Property changes on: images/misc/black_x.png
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
     
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.awt.BorderLayout;
     7import java.awt.Component;
    78import java.awt.Container;
    89import java.awt.Dimension;
    910import java.awt.Font;
     11import java.awt.GridBagLayout;
    1012import java.awt.Rectangle;
    1113import java.awt.event.ActionEvent;
    1214import java.awt.event.KeyEvent;
     
    6466import org.openstreetmap.josm.gui.layer.Layer;
    6567import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    6668import org.openstreetmap.josm.tools.Destroyable;
     69import org.openstreetmap.josm.tools.GBC;
    6770
    6871/**
    6972 * One Map frame with one dataset behind. This is the container gui class whose
     
    112115     * instead of adding directly to this list.
    113116     */
    114117    private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
     118    private final JPanel leftPanel;
    115119    private final DialogsPanel dialogsPanel;
    116120
    117121    public final ButtonGroup toolGroup = new ButtonGroup();
     
    139143        setSize(400,400);
    140144        setLayout(new BorderLayout());
    141145
     146       
    142147        mapView = new MapView(contentPane);
    143148
    144149        new FileDrop(mapView);
    145 
     150       
     151        leftPanel = new JPanel();
     152        leftPanel.setLayout(new GridBagLayout());
     153       
     154        leftPanel.add(mapView, GBC.std().fill());
     155       
    146156        // toolbar
    147157        toolBarActions.setFloatable(false);
    148158        addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
     
    157167
    158168        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    159169        dialogsPanel = new DialogsPanel(splitPane);
    160         splitPane.setLeftComponent(mapView);
     170        splitPane.setLeftComponent(leftPanel);
    161171        splitPane.setRightComponent(dialogsPanel);
    162172
    163173        /**
     
    498508    public void rememberToggleDialogWidth() {
    499509        Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth());
    500510    }
     511   
     512     /*
     513     * Remove panel from top of MapView by class
     514     */
     515     public void removeTopPanel(Class<?> type) {
     516        int n = leftPanel.getComponentCount();
     517        for (int i=0; i<n; i++) {
     518            Component c = leftPanel.getComponent(i);
     519            if (type.isInstance(c)) {
     520                leftPanel.remove(i);
     521                leftPanel.doLayout();
     522//                repaint();
     523                return;
     524            }
     525        }
     526    }
     527   
     528    /*
     529    * Find panel on top of MapView by class
     530    */
     531    public <T> T getTopPanel(Class<T> type) {
     532        int n = leftPanel.getComponentCount();
     533        for (int i=0; i<n; i++) {
     534            Component c = leftPanel.getComponent(i);
     535            if (type.isInstance(c)) {
     536                return type.cast(c);
     537            }
     538        }
     539        return null;
     540    }
    501541
    502542    /**
     543     * Add component @param c on top of MapView
     544     */
     545    public void addTopPanel(Component c) {
     546        leftPanel.add(c, GBC.eol().fill(GBC.HORIZONTAL), leftPanel.getComponentCount()-1);
     547        leftPanel.doLayout();
     548        c.doLayout();
     549    }
     550
     551    /**
    503552     * Interface to notify listeners of the change of the mapMode.
    504553     */
    505554    public interface MapModeChangeListener {
  • src/org/openstreetmap/josm/gui/actionsupport/AlignImageryPanel.java

     
     1package org.openstreetmap.josm.gui.actionsupport;
     2
     3
     4import java.awt.BorderLayout;
     5import java.awt.Color;
     6import java.awt.Font;
     7import java.awt.Graphics;
     8import java.awt.event.ActionEvent;
     9import java.awt.event.ActionListener;
     10import java.awt.event.MouseEvent;
     11import java.awt.event.MouseListener;
     12import javax.swing.BoxLayout;
     13import javax.swing.JButton;
     14import javax.swing.JLabel;
     15import javax.swing.JPanel;
     16import javax.swing.Box;
     17import javax.swing.JSplitPane;
     18import javax.swing.border.CompoundBorder;
     19import javax.swing.border.EmptyBorder;
     20import javax.swing.border.EtchedBorder;
     21
     22import org.openstreetmap.josm.Main;
     23import static org.openstreetmap.josm.tools.I18n.tr;
     24import org.openstreetmap.josm.tools.ImageProvider;
     25import org.openstreetmap.josm.tools.UrlLabel;
     26
     27
     28/**
     29 * The panel to nag a user ONCE that he/she has to align imagery.
     30 *
     31 * @author zverik
     32 */
     33public class AlignImageryPanel extends JPanel {
     34    private static final String PREF = "imagery.offsetnagging";
     35
     36    public AlignImageryPanel() {
     37        super();
     38       
     39        Font font = getFont().deriveFont(Font.PLAIN, 14.0f);
     40        JLabel nagLabel = new JLabel(tr("Aerial imagery might be misaligned. Please check its offset using GPS tracks!"));
     41        UrlLabel detailsList = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details..."));
     42        nagLabel.setFont(font);
     43        detailsList.setFont(font);
     44       
     45        JButton closeButton = new JButton(ImageProvider.get("misc", "black_x"));
     46        closeButton.setContentAreaFilled(false);
     47        closeButton.setRolloverEnabled(true);
     48        closeButton.setBorderPainted(false);
     49        closeButton.setToolTipText(tr("Hide this message and never show it again"));
     50        closeButton.addActionListener(new ActionListener() {
     51            @Override
     52            public void actionPerformed( ActionEvent e ) {
     53                if (Main.map!=null) {
     54                    Main.map.removeTopPanel(AlignImageryPanel.class);
     55                    Main.pref.put(PREF, false);
     56                }
     57            }
     58        });
     59       
     60        BoxLayout box = new BoxLayout(this, BoxLayout.X_AXIS);
     61        setLayout(box);
     62        add(nagLabel);
     63        add(Box.createHorizontalStrut(12));
     64        add(detailsList);
     65        add(Box.createHorizontalGlue());
     66        add(closeButton);
     67//        setBorder(new EmptyBorder(12, 12, 12, 12));
     68        setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12)));
     69        setBackground(new Color(224, 236, 249));
     70    }
     71
     72    public static void addNagPanelIfNeeded() {
     73        if( Main.map != null && !Main.pref.getBoolean("expert") && Main.pref.getBoolean(PREF, true) ) {
     74            if (Main.map.getTopPanel(AlignImageryPanel.class) == null) {
     75                AlignImageryPanel p = new AlignImageryPanel();
     76                Main.map.addTopPanel(p);
     77            }
     78        }
     79    }
     80   
     81}
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

     
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1212import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
     13import org.openstreetmap.josm.gui.actionsupport.AlignImageryPanel;
    1314import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1415import org.openstreetmap.josm.tools.ImageProvider;
    1516
     
    4344        if (!isEnabled()) return;
    4445        try {
    4546            Main.main.addLayer(ImageryLayer.create(info));
     47            AlignImageryPanel.addNagPanelIfNeeded();
    4648        } catch (IllegalArgumentException ex) {
    4749            if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
    4850                throw ex;