Ignore:
Timestamp:
2013-05-17T20:45:17+02:00 (11 years ago)
Author:
akks
Message:

see #8652 (patch by cmuelle8, part 1, modified): add "toggle panels" action (soon will be on Tab)
rework all toolbar context menus (add "do not hide" item and remove PopupMenuLauncher usage)
fixing minor warnings (@Override, private final)

File:
1 edited

Legend:

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

    r5909 r5965  
    66
    77import java.awt.AWTEvent;
    8 import java.awt.Color;
    98import java.awt.Component;
    109import java.awt.Cursor;
     
    1716import java.awt.Toolkit;
    1817import java.awt.event.AWTEventListener;
     18import java.awt.event.ActionEvent;
    1919import java.awt.event.InputEvent;
    2020import java.awt.event.KeyAdapter;
     
    2929import java.util.List;
    3030
     31import javax.swing.AbstractAction;
    3132import javax.swing.BorderFactory;
     33import javax.swing.JButton;
     34import javax.swing.JCheckBoxMenuItem;
    3235import javax.swing.JLabel;
     36import javax.swing.JMenuItem;
    3337import javax.swing.JPanel;
     38import javax.swing.JPopupMenu;
    3439import javax.swing.JProgressBar;
    3540import javax.swing.JScrollPane;
     
    3742import javax.swing.PopupFactory;
    3843import javax.swing.UIManager;
     44import javax.swing.event.PopupMenuEvent;
     45import javax.swing.event.PopupMenuListener;
    3946
    4047import org.openstreetmap.josm.Main;
     
    4754import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog;
    4855import org.openstreetmap.josm.gui.util.GuiHelper;
     56import org.openstreetmap.josm.gui.widgets.ImageLabel;
     57import org.openstreetmap.josm.gui.widgets.JosmTextField;
    4958import org.openstreetmap.josm.tools.GBC;
    5059import org.openstreetmap.josm.tools.ImageProvider;
    51 import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5260
    5361/**
     
    7280    final Collector collector;
    7381
    74     /**
    75      * A small user interface component that consists of an image label and
    76      * a fixed text content to the right of the image.
    77      */
    78     static class ImageLabel extends JPanel {
    79         static Color backColor = Color.decode("#b8cfe5");
    80         static Color backColorActive = Color.decode("#aaff5e");
    81            
    82         private JLabel tf;
    83         private int chars;
    84         public ImageLabel(String img, String tooltip, int chars) {
    85             super();
    86             setLayout(new GridBagLayout());
    87             setBackground(backColor);
    88             add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
    89             add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
    90             setToolTipText(tooltip);
    91             this.chars = chars;
    92         }
    93         public void setText(String t) {
    94             tf.setText(t);
    95         }
    96         @Override public Dimension getPreferredSize() {
    97             return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
    98         }
    99         @Override public Dimension getMinimumSize() {
    100             return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
    101         }
    102     }
    103 
    10482    public class BackgroundProgressMonitor implements ProgressMonitorDialog {
    10583
     
    11593        }
    11694
     95        @Override
    11796        public void setVisible(boolean visible) {
    11897            progressBar.setVisible(visible);
    11998        }
    12099
     100        @Override
    121101        public void updateProgress(int progress) {
    122102            progressBar.setValue(progress);
     
    125105        }
    126106
     107        @Override
    127108        public void setCustomText(String text) {
    128109            this.customText = text;
     
    130111        }
    131112
     113        @Override
    132114        public void setCurrentAction(String text) {
    133115            this.title = text;
     
    135117        }
    136118
     119        @Override
    137120        public void setIndeterminate(boolean newValue) {
    138121            UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
     
    218201         * Execution function for the Collector.
    219202         */
     203        @Override
    220204        public void run() {
    221205            registerListeners();
     
    281265                                    // Set the text label in the bottom status bar
    282266                                    // "if mouse moved only" was added to stop heap growing
    283                                     if (!mouseNotMoved) statusBarElementUpdate(ms);
     267                                    if (!mouseNotMoved) {
     268                                        statusBarElementUpdate(ms);
     269                                    }
    284270
    285271
     
    363349         * @return popup
    364350         */
    365         private final Popup popupCreatePopup(Component content, MouseState ms) {
     351        private Popup popupCreatePopup(Component content, MouseState ms) {
    366352            Point p = mv.getLocationOnScreen();
    367353            Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();
     
    399385         * @param ms
    400386         */
    401         private final void statusBarElementUpdate(MouseState ms) {
     387        private void statusBarElementUpdate(MouseState ms) {
    402388            final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive.isUsablePredicate, false);
    403389            if (osmNearest != null) {
     
    414400         * @param mods modifiers (i.e. control keys)
    415401         */
    416         private final void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
     402        private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
    417403            DataSet ds = Main.main.getCurrentDataSet();
    418404            // Find some items that are required for cycling through
     
    453439         * Tries to hide the given popup
    454440         */
    455         private final void popupHidePopup() {
     441        private void popupHidePopup() {
    456442            popupLabels = null;
    457443            if(popup == null)
     
    460446            popup = null;
    461447            EventQueue.invokeLater(new Runnable(){
    462                 public void run() { staticPopup.hide(); }});
     448               public void run() {
     449                    staticPopup.hide();
     450                }});
    463451        }
    464452
     
    469457         * @param lbls lables to show (see {@link #popupLabels})
    470458         */
    471         private final void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
     459        private void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
    472460            final Popup staticPopup = newPopup;
    473461            if(this.popup != null) {
     
    476464                final Popup staticOldPopup = this.popup;
    477465                EventQueue.invokeLater(new Runnable(){
    478                     public void run() {
     466                    @Override public void run() {
    479467                        staticPopup.show();
    480468                        staticOldPopup.hide();
     
    484472                // There is no old popup
    485473                EventQueue.invokeLater(new Runnable(){
    486                     public void run() { staticPopup.show(); }});
     474                     @Override public void run() { staticPopup.show(); }});
    487475            }
    488476            this.popupLabels = lbls;
     
    495483         * user clicks on the map instead of the popup.
    496484         */
    497         private final void popupUpdateLabels() {
     485        private void popupUpdateLabels() {
    498486            if(this.popup == null || this.popupLabels == null)
    499487                return;
     
    510498         * @param osm The primitive to derive the colors from
    511499         */
    512         private final void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
     500        private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
    513501            DataSet ds = Main.main.getCurrentDataSet();
    514502            if(ds.isSelected(osm)) {
     
    527515         * @return labels for info popup
    528516         */
    529         private final JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
     517        private JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
    530518            final StringBuilder text = new StringBuilder();
    531519            String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
     
    587575            // can correct this defect.
    588576            l.addMouseMotionListener(new MouseMotionListener() {
    589                 public void mouseMoved(MouseEvent e) {
     577                 @Override public void mouseMoved(MouseEvent e) {
    590578                    l.setBackground(SystemColor.info);
    591579                    l.setForeground(SystemColor.infoText);
    592580                }
    593                 public void mouseDragged(MouseEvent e) {
     581                 @Override public void mouseDragged(MouseEvent e) {
    594582                    l.setBackground(SystemColor.info);
    595583                    l.setForeground(SystemColor.infoText);
     
    614602
    615603    private AWTEventListener awtListener = new AWTEventListener() {
    616         public void eventDispatched(AWTEvent event) {
     604         @Override
     605         public void eventDispatched(AWTEvent event) {
    617606            if (event instanceof InputEvent &&
    618607                    ((InputEvent)event).getComponent() == mv) {
     
    629618
    630619    private MouseMotionListener mouseMotionListener = new MouseMotionListener() {
     620        @Override
    631621        public void mouseMoved(MouseEvent e) {
    632622            synchronized (collector) {
     
    637627        }
    638628
     629        @Override
    639630        public void mouseDragged(MouseEvent e) {
    640631            mouseMoved(e);
     
    686677        this.collector = new Collector(mapFrame);
    687678
    688         lonText.addMouseListener(Main.main.menu.jumpToAct);
    689         latText.addMouseListener(Main.main.menu.jumpToAct);
    690        
     679        // Context menu of status bar
     680        setComponentPopupMenu(new JPopupMenu() {
     681            JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) {
     682                @Override public void actionPerformed(ActionEvent e) {
     683                    boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
     684                    Main.pref.put("statusbar.always-visible", sel);
     685                }
     686            });
     687            JMenuItem jumpButton;
     688            {
     689                jumpButton = add(Main.main.menu.jumpToAct);
     690                addPopupMenuListener(new PopupMenuListener() {
     691                    @Override
     692                    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     693                        Component invoker = ((JPopupMenu)e.getSource()).getInvoker();
     694                        jumpButton.setVisible(invoker == latText || invoker == lonText);
     695                        doNotHide.setSelected(Main.pref.getBoolean("statusbar.always-visible", true));
     696                    }
     697                    @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
     698                    @Override public void popupMenuCanceled(PopupMenuEvent e) {}
     699                });
     700                add(doNotHide);
     701            }
     702        });
     703
    691704        // Listen for mouse movements and set the position text field
    692705        mv.addMouseMotionListener(new MouseMotionListener(){
     706            @Override
    693707            public void mouseDragged(MouseEvent e) {
    694708                mouseMoved(e);
    695709            }
     710            @Override
    696711            public void mouseMoved(MouseEvent e) {
    697712                if (mv.center == null)
     
    709724        setLayout(new GridBagLayout());
    710725        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     726
     727        latText.setInheritsPopupMenu(true);
     728        lonText.setInheritsPopupMenu(true);
     729        headingText.setInheritsPopupMenu(true);
     730        //angleText.setInheritsPopupMenu(true);
     731        distText.setInheritsPopupMenu(true);
     732        nameText.setInheritsPopupMenu(true);
     733        //helpText.setInheritsPopupMenu(true);
     734        //progressBar.setInheritsPopupMenu(true);
    711735
    712736        add(latText, GBC.std());
     
    745769    }
    746770
     771    @Override
    747772    public String helpTopic() {
    748773        return ht("/Statusline");
Note: See TracChangeset for help on using the changeset viewer.