Ignore:
Timestamp:
2012-01-21T23:04:50+01:00 (12 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/gui/preferences
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • 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.