Changeset 4840 in josm for trunk/src


Ignore:
Timestamp:
2012-01-21T23:04:50+01:00 (8 years ago)
Author:
bastiK
Message:

expert mode rework:

  • toggling of expert mode does not require restart
  • checkbox at a more prominent places (MainMenu > View and in the preference dialog at the bottom)
Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
9 edited

Legend:

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

    r4609 r4840  
    99 */
    1010interface HideableButton {
    11     public void applyButtonHiddenPreferences();
    12     public void setButtonHidden(boolean b);
    13     public void showButton();
    14     public void hideButton();
    15     public String getActionName();
    16     public Icon getIcon();
    17     public boolean isButtonVisible();
    18     public void setShowHideButtonListener(ShowHideButtonListener l);
     11    void applyButtonHiddenPreferences();
     12    void setButtonHidden(boolean b);
     13    void showButton();
     14    void hideButton();
     15    String getActionName();
     16    Icon getIcon();
     17    boolean isButtonVisible();
     18    void setShowHideButtonListener(ShowHideButtonListener l);
    1919}
  • trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java

    r4835 r4840  
    1313
    1414import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.actions.ExpertToggleAction;
     16import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
    1517import org.openstreetmap.josm.tools.Destroyable;
    1618
     
    2123 * @author imi, akks
    2224 */
    23 public class IconToggleButton extends JToggleButton implements HideableButton, PropertyChangeListener, Destroyable {
     25public class IconToggleButton extends JToggleButton implements HideableButton, PropertyChangeListener, Destroyable, ExpertModeChangeListener {
    2426
    2527    public boolean groupbutton;
    2628    private ShowHideButtonListener listener;
    27     private boolean hideIfDisabled=false;
    28     private boolean hiddenByDefault;
     29    private boolean hideIfDisabled = false;
     30    private boolean isExpert;
    2931
    3032    /**
     
    3840     * Construct the toggle button with the given action.
    3941     */
    40     public IconToggleButton(Action action, boolean hiddenByDefault) {
     42    public IconToggleButton(Action action, boolean isExpert) {
    4143        super(action);
    42         this.hiddenByDefault = hiddenByDefault;
     44        this.isExpert = isExpert;
    4345        setText(null);
    4446
     
    5557            }
    5658        });
     59
     60        ExpertToggleAction.addExpertModeChangeListener(this);
    5761    }
    5862
     
    7579        }
    7680    }
    77    
     81
    7882    String getPreferenceKey() {
    7983        String s = (String) getSafeActionValue("toolbar");
    80         if (s==null) {
    81             if (getAction()!=null) s=getAction().getClass().getName();
     84        if (s == null) {
     85            if (getAction()!=null) {
     86                s = getAction().getClass().getName();
     87            }
    8288        }
    8389        return "sidetoolbar.hidden."+s;
    84        
     90
    8591    }
    86    
     92
     93    @Override
     94    public void expertChanged(boolean isExpert) {
     95        applyButtonHiddenPreferences();
     96    }
     97
    8798    @Override
    8899    public void applyButtonHiddenPreferences() {
    89100        boolean alwaysHideDisabled = Main.pref.getBoolean("sidetoolbar.hideDisabledButtons", false);
    90         boolean hiddenFlag = Main.pref.getBoolean(getPreferenceKey(), hiddenByDefault);
    91         if (!isEnabled() && (hideIfDisabled || alwaysHideDisabled))
    92                 setVisible(false);  // hide because of disabled button
    93             else
    94                 setVisible( !hiddenFlag ); // show or hide, do what preferences say 
     101        if (!isEnabled() && (hideIfDisabled || alwaysHideDisabled)) {
     102            setVisible(false);  // hide because of disabled button
     103        } else {
     104            boolean hiddenFlag = false;
     105            String hiddenFlagStr = Main.pref.get(getPreferenceKey(), null);
     106            if (hiddenFlagStr == null) {
     107                if (isExpert && !Main.main.menu.expert.isSelected()) {
     108                    hiddenFlag = true;
     109                }
     110            } else {
     111                hiddenFlag = Boolean.parseBoolean(hiddenFlagStr);
     112            }
     113            setVisible( !hiddenFlag ); // show or hide, do what preferences say
     114        }
    95115    }
    96116
     
    101121            if (!b) listener.buttonShown(); else listener.buttonHidden();
    102122        }
    103         Main.pref.put(getPreferenceKey(), b);
     123        if ((b && isExpert && !Main.main.menu.expert.isSelected()) ||
     124            (!b && isExpert && Main.main.menu.expert.isSelected())) {
     125            Main.pref.put(getPreferenceKey(), null);
     126        } else {
     127            Main.pref.put(getPreferenceKey(), b);
     128        }
    104129    }
    105    
    106     /* 
     130
     131    /*
    107132     * This fuction should be called for plugins that want to enable auto-hiding
    108133     * custom buttons when they are disabled (because of incorrect layer, for example)
    109134     */
    110135    public void setAutoHideDisabledButton(boolean b) {
    111         hideIfDisabled=b;
    112         if (b && !isEnabled()) setVisible(false);
     136        hideIfDisabled = b;
     137        if (b && !isEnabled()) {
     138            setVisible(false);
     139        }
    113140    }
    114    
     141
    115142    @Override
    116143    public void showButton() {
    117144        setButtonHidden(false);
    118145    }
    119    
     146
    120147    @Override
    121148    public void hideButton() {
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r4733 r4840  
    3939import org.openstreetmap.josm.actions.DuplicateAction;
    4040import org.openstreetmap.josm.actions.ExitAction;
     41import org.openstreetmap.josm.actions.ExpertToggleAction;
    4142import org.openstreetmap.josm.actions.FollowLineAction;
    4243import org.openstreetmap.josm.actions.FullscreenToggleAction;
     
    158159    public final HistoryInfoAction historyinfo = new HistoryInfoAction();
    159160    public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction();
     161    public final ExpertToggleAction expert = new ExpertToggleAction();
    160162
    161163    /* Tools menu */
     
    445447        add(viewMenu, infoweb);
    446448        add(viewMenu, historyinfo);
    447                 add(viewMenu, historyinfoweb);
     449        add(viewMenu, historyinfoweb);
     450        viewMenu.addSeparator();
     451        // -- expert mode toggle action
     452        final JCheckBoxMenuItem expertItem = new JCheckBoxMenuItem(expert);
     453        viewMenu.add(expertItem);
     454        expert.addButtonModel(expertItem.getModel());
    448455
    449456        add(presetsMenu, presetSearchAction);
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r4835 r4840  
    137137        new FileDrop(mapView);
    138138
    139         // show menu entry
    140         Main.main.menu.viewMenu.setVisible(true);
    141 
    142139        // toolbar
    143140        toolBarActions.setFloatable(false);
     
    145142        addMapMode(new IconToggleButton(new DrawAction(this)));
    146143        addMapMode(new IconToggleButton(new ZoomAction(this)));
    147         addMapMode(new IconToggleButton(new DeleteAction(this), !Main.pref.getBoolean("expert", false)));
    148         addMapMode(new IconToggleButton(new ExtrudeAction(this), !Main.pref.getBoolean("expert", false)));
    149         addMapMode(new IconToggleButton(new ParallelWayAction(this), !Main.pref.getBoolean("expert", false)));
     144        addMapMode(new IconToggleButton(new DeleteAction(this), true));
     145        addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
     146        addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
    150147
    151148        toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
     
    241238            }
    242239        }
    243 
    244         // remove menu entries
    245         Main.main.menu.viewMenu.setVisible(false);
    246240
    247241        // MapFrame gets destroyed when the last layer is removed, but the status line background
     
    410404    }
    411405
    412         class ListAllButtonsAction extends AbstractAction {
     406    class ListAllButtonsAction extends AbstractAction {
    413407
    414408        private JButton button;
     
    439433                    @Override
    440434                    public void actionPerformed(ActionEvent e) {
    441                         if ((Boolean) getValue(SELECTED_KEY)) t.showButton(); else t.hideButton();
     435                        if ((Boolean) getValue(SELECTED_KEY)) {
     436                            t.showButton();
     437                        } else {
     438                            t.hideButton();
     439                        }
    442440                        validateToolBarsVisibility();
    443441                    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r4767 r4840  
    1717
    1818import org.openstreetmap.josm.Main;
     19import org.openstreetmap.josm.actions.ExpertToggleAction;
     20import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
    1921import org.openstreetmap.josm.tools.GBC;
    2022
    21 public class DrawingPreference implements PreferenceSetting {
     23public class DrawingPreference implements PreferenceSetting, ExpertModeChangeListener {
    2224
    2325    public static class Factory implements PreferenceSettingFactory {
     
    3739
    3840    // Options that affect performance
     41    private JLabel performanceLabel = new JLabel(tr("Options that affect drawing performance"));
    3942    private JCheckBox useHighlighting = new JCheckBox(tr("Highlight target ways and nodes"));
    4043    private JCheckBox drawHelperLine = new JCheckBox(tr("Draw rubber-band helper line"));
    4144    private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)"));
    4245    private JCheckBox outlineOnly = new JCheckBox(tr("Draw only outlines of areas"));
    43    
     46
    4447    public void addGui(PreferenceTabbedPane gui) {
    4548        gui.display.setPreferredSize(new Dimension(400,600));
     
    116119        outlineOnly.setToolTipText(tr("This option suppresses the filling of areas, overriding anything specified in the selected style."));
    117120
    118         if (Main.pref.getBoolean("expert", false)) {
    119             panel.add(new JLabel(tr("Options that affect drawing performance")),GBC.eop().insets(5,10,0,0));
    120             panel.add(useAntialiasing, GBC.eop().insets(20,5,0,0));
    121             panel.add(useHighlighting, GBC.eop().insets(20,0,0,0));
    122             panel.add(outlineOnly, GBC.eol().insets(20,0,0,5));
    123         }
    124        
     121        panel.add(performanceLabel, GBC.eop().insets(5,10,0,0));
     122        panel.add(useAntialiasing, GBC.eop().insets(20,5,0,0));
     123        panel.add(useHighlighting, GBC.eop().insets(20,0,0,0));
     124        panel.add(outlineOnly, GBC.eol().insets(20,0,0,5));
     125
    125126        panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
    126127        scrollpane = new JScrollPane(panel);
    127128        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
    128129        gui.displaycontent.addTab(tr("OSM Data"), scrollpane);
     130
     131        ExpertToggleAction.addExpertModeChangeListener(this, true);
     132    }
     133
     134    @Override
     135    public void expertChanged(boolean isExpert) {
     136        performanceLabel.setVisible(isExpert);
     137        useAntialiasing.setVisible(isExpert);
     138        useHighlighting.setVisible(isExpert);
     139        outlineOnly.setVisible(isExpert);
    129140    }
    130141
  • trunk/src/org/openstreetmap/josm/gui/preferences/LafPreference.java

    r4828 r4840  
    2121
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.actions.ExpertToggleAction;
     24import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
    2325import org.openstreetmap.josm.tools.GBC;
    2426
    25 public class LafPreference implements PreferenceSetting {
     27public class LafPreference implements PreferenceSetting, ExpertModeChangeListener {
    2628
    2729    public static class Factory implements PreferenceSettingFactory {
     
    4042    private JCheckBox showLocalizedName = new JCheckBox(tr("Show localized name in selection lists"));
    4143    private JCheckBox modeless = new JCheckBox(tr("Modeless working (Potlatch style)"));
    42     private JCheckBox expert = new JCheckBox(tr("Expert mode"));
    4344    private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
    4445
     
    9596
    9697        panel.add(showID, GBC.eop().insets(20, 0, 0, 0));
    97         if (Main.pref.getBoolean("expert", false)) {
    98             panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
    99             panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
    100         }
     98        panel.add(showLocalizedName, GBC.eop().insets(20, 0, 0, 0));
     99        panel.add(modeless, GBC.eop().insets(20, 0, 0, 0));
    101100
    102101        dynamicButtons.setToolTipText(tr("Display buttons in right side menus only when mouse is inside the element"));
    103102        dynamicButtons.setSelected(Main.pref.getBoolean("dialog.dynamic.buttons", true));
    104103        panel.add(dynamicButtons, GBC.eop().insets(20, 0, 0, 0));
    105 
    106         expert.setToolTipText(tr("The expert mode shows a lot of additional settings hidden from normal user"));
    107         expert.setSelected(Main.pref.getBoolean("expert", false));
    108         panel.add(expert, GBC.eop().insets(20, 0, 0, 0));
    109104
    110105        panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
     
    117112        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
    118113        gui.displaycontent.addTab(tr("Look and Feel"), scrollpane);
     114
     115        ExpertToggleAction.addExpertModeChangeListener(this, true);
     116    }
     117
     118    @Override
     119    public void expertChanged(boolean isExpert) {
     120        showLocalizedName.setVisible(isExpert);
     121        modeless.setVisible(isExpert);
    119122    }
    120123
     
    125128        Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected());
    126129        Main.pref.put("modeless", modeless.isSelected());
    127         if(Main.pref.put("expert", expert.isSelected()))
    128             mod = true;
    129130        Main.pref.put("dialog.dynamic.buttons", dynamicButtons.isSelected());
    130         if(Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()))
    131             mod = true;
     131        mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
    132132        return mod;
    133133    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r4586 r4840  
    99import java.awt.Dimension;
    1010import java.awt.FlowLayout;
     11import java.awt.GridBagLayout;
    1112import java.awt.Insets;
    1213import java.awt.Toolkit;
    1314import java.awt.event.ActionEvent;
     15import java.awt.event.ActionListener;
    1416import java.awt.event.KeyEvent;
    1517import java.awt.event.WindowAdapter;
     
    1820import javax.swing.AbstractAction;
    1921import javax.swing.BorderFactory;
     22import javax.swing.JCheckBox;
    2023import javax.swing.JComponent;
    2124import javax.swing.JDialog;
     
    2427import javax.swing.KeyStroke;
    2528
     29import org.openstreetmap.josm.Main;
    2630import org.openstreetmap.josm.gui.SideButton;
    2731import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    2832import org.openstreetmap.josm.gui.help.HelpUtil;
    2933import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
     34import org.openstreetmap.josm.tools.GBC;
    3035import org.openstreetmap.josm.tools.ImageProvider;
    3136import org.openstreetmap.josm.tools.WindowGeometry;
     
    3742
    3843    protected JPanel buildActionPanel() {
    39         JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
    40         pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    41         pnl.add(new SideButton(new OKAction()));
    42         pnl.add(new SideButton(new CancelAction()));
    43         pnl.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Action/Preferences"))));
     44        JPanel pnl = new JPanel(new GridBagLayout());
     45
     46        JCheckBox expert = new JCheckBox(tr("Expert mode"));
     47        expert.setSelected(Main.main.menu.expert.isSelected());
     48        expert.addActionListener(new ActionListener() {
     49            public void actionPerformed(ActionEvent e) {
     50                Main.main.menu.expert.actionPerformed(null);
     51            }
     52        });
     53
     54        JPanel btns = new JPanel(new FlowLayout(FlowLayout.CENTER));
     55        btns.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     56        btns.add(new SideButton(new OKAction()));
     57        btns.add(new SideButton(new CancelAction()));
     58        btns.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Action/Preferences"))));
     59        pnl.add(expert, GBC.std().insets(5,0,0,0));
     60        pnl.add(btns, GBC.std().fill(GBC.HORIZONTAL));
    4461        return pnl;
    4562    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r4634 r4840  
    2828
    2929import org.openstreetmap.josm.Main;
     30import org.openstreetmap.josm.actions.ExpertToggleAction;
     31import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
    3032import org.openstreetmap.josm.gui.preferences.advanced.AdvancedPreference;
    3133import org.openstreetmap.josm.plugins.PluginDownloadTask;
     
    4244 * @author imi
    4345 */
    44 public class PreferenceTabbedPane extends JTabbedPane implements MouseWheelListener {
     46public class PreferenceTabbedPane extends JTabbedPane implements MouseWheelListener, ExpertModeChangeListener {
    4547    /**
    4648     * Allows PreferenceSettings to do validation of entered values when ok was pressed.
     
    5658    }
    5759
     60    private class TabData {
     61        public String icon;
     62        public JComponent tab;
     63        public String toolTip;
     64        public boolean isExpert;
     65    }
     66
    5867    // all created tabs
    59     private final Map<String,Component> tabs = new HashMap<String,Component>();
     68    private final List<TabData> tabs = new ArrayList<TabData>();
    6069    private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>();
    6170    private final List<PreferenceSetting> settings = new ArrayList<PreferenceSetting>();
     
    94103    public JPanel createPreferenceTab(String icon, String title, String desc) {
    95104        return createPreferenceTab(icon, title, desc, false);
     105    }
     106
     107    public JPanel createPreferenceTab(String icon, String title, String desc, boolean inScrollPane) {
     108        return createPreferenceTab(icon, title, desc, inScrollPane, false);
    96109    }
    97110
     
    107120     * @return The created panel ready to add other controls.
    108121     */
    109     public JPanel createPreferenceTab(String icon, String title, String desc, boolean inScrollPane) {
     122    public JPanel createPreferenceTab(String icon, String title, String desc, boolean inScrollPane, boolean isExpert) {
    110123        JPanel p = new JPanel(new GridBagLayout());
    111124        p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     
    121134            tab = sp;
    122135        }
    123         tabs.put(icon,tab);
    124         addTab(null, ImageProvider.get("preferences", icon), tab);
    125         setToolTipTextAt(getTabCount()-1, "<html>"+desc+"</html>");
     136        TabData data = new TabData();
     137        data.icon = icon;
     138        data.tab = tab;
     139        data.isExpert = isExpert;
     140        data.toolTip = "<html>"+desc+"</html>";
     141        tabs.add(data);
    126142        return p;
    127143    }
    128    
     144
    129145    public void selectTabByName(String name) {
    130         Component c = tabs.get(name);
    131         if (c!=null) setSelectedComponent(c);
     146        for (TabData data : tabs) {
     147            if (data.icon.equals(name)) {
     148                Component c = data.tab;
     149                if (c != null) {
     150                    setSelectedComponent(c);
     151                }
     152                return;
     153            }
     154        }
    132155    }
    133156
     
    227250        super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
    228251        super.addMouseWheelListener(this);
     252        ExpertToggleAction.addExpertModeChangeListener(this);
    229253    }
    230254
     
    250274            }
    251275        }
     276        addGUITabs(false);
     277    }
     278
     279    private void addGUITabs(boolean clear) {
     280        boolean expert = Main.main.menu.expert.isSelected();
     281        Component sel = getSelectedComponent();
     282        if (clear) {
     283            removeAll();
     284        }
     285        for (TabData data : tabs) {
     286            if (expert || !data.isExpert) {
     287                addTab(null, ImageProvider.get("preferences", data.icon), data.tab, data.toolTip);
     288            }
     289        }
     290        try {
     291            setSelectedComponent(sel);
     292        } catch (IllegalArgumentException e) {}
     293    }
     294
     295    @Override
     296    public void expertChanged(boolean isExpert) {
     297        addGUITabs(true);
    252298    }
    253299
     
    288334        PluginHandler.getPreferenceSetting(settingsFactory);
    289335
    290         if(Main.pref.getBoolean("expert", false)) {
    291             // always the last: advanced tab
    292             settingsFactory.add(new AdvancedPreference.Factory());
    293         }
     336        // always the last: advanced tab
     337        settingsFactory.add(new AdvancedPreference.Factory());
    294338    }
    295339
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r4634 r4840  
    115115    public void addGui(final PreferenceTabbedPane gui) {
    116116        JPanel p = gui.createPreferenceTab("advanced", tr("Advanced Preferences"),
    117                 tr("Setting Preference entries directly. Use with caution!"), false);
     117                tr("Setting Preference entries directly. Use with caution!"), false, true);
    118118
    119119        txtFilter = new JTextField();
Note: See TracChangeset for help on using the changeset viewer.