Changeset 168 in josm


Ignore:
Timestamp:
2006-11-25T16:41:58+01:00 (18 years ago)
Author:
imi
Message:
  • added plugin-support for preferences
  • added advanced tab to preferences dialog
Files:
12 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/PreferencesAction.java

    r113 r168  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.GridBagLayout;
    56import java.awt.event.ActionEvent;
    67import java.awt.event.KeyEvent;
    78
    8 import org.openstreetmap.josm.gui.PreferenceDialog;
     9import javax.swing.JDialog;
     10import javax.swing.JOptionPane;
     11import javax.swing.JPanel;
     12
     13import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
     15import org.openstreetmap.josm.tools.GBC;
    916
    1017/**
     
    2633         */
    2734        public void actionPerformed(ActionEvent e) {
    28                 PreferenceDialog dlg = new PreferenceDialog();
     35                PreferenceDialog prefDlg = new PreferenceDialog();
     36                JPanel prefPanel = new JPanel(new GridBagLayout());
     37                prefPanel.add(prefDlg, GBC.eol().fill(GBC.BOTH));
     38               
     39                JOptionPane pane = new JOptionPane(prefPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
     40                JDialog dlg = pane.createDialog(Main.parent, tr("Preferences"));
    2941                dlg.setVisible(true);
     42                if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION)
     43                        prefDlg.ok();
    3044        }
    3145}
  • src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r167 r168  
    1 package org.openstreetmap.josm.gui;
     1package org.openstreetmap.josm.gui.preferences;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.Color;
    6 import java.awt.Component;
    7 import java.awt.Dimension;
    85import java.awt.Font;
    96import java.awt.GridBagLayout;
    107import java.awt.event.ActionEvent;
    118import java.awt.event.ActionListener;
    12 import java.io.File;
    13 import java.util.Arrays;
    149import java.util.Collection;
    15 import java.util.HashMap;
    1610import java.util.LinkedList;
    17 import java.util.Map;
    18 import java.util.StringTokenizer;
    19 import java.util.TreeMap;
    20 import java.util.Vector;
    21 import java.util.Map.Entry;
    2211
    23 import javax.swing.AbstractAction;
    2412import javax.swing.BorderFactory;
    25 import javax.swing.Box;
    26 import javax.swing.DefaultListCellRenderer;
    27 import javax.swing.DefaultListModel;
    28 import javax.swing.JButton;
    29 import javax.swing.JCheckBox;
    30 import javax.swing.JColorChooser;
    31 import javax.swing.JComboBox;
    32 import javax.swing.JDialog;
    3313import javax.swing.JLabel;
    34 import javax.swing.JList;
    3514import javax.swing.JOptionPane;
    3615import javax.swing.JPanel;
    37 import javax.swing.JPasswordField;
    38 import javax.swing.JScrollPane;
    3916import javax.swing.JTabbedPane;
    40 import javax.swing.JTable;
    41 import javax.swing.JTextField;
    42 import javax.swing.ListCellRenderer;
    43 import javax.swing.ListSelectionModel;
    44 import javax.swing.UIManager;
    45 import javax.swing.UIManager.LookAndFeelInfo;
    46 import javax.swing.table.TableCellRenderer;
    4717
    4818import org.openstreetmap.josm.Main;
    49 import org.openstreetmap.josm.data.projection.Projection;
    50 import org.openstreetmap.josm.plugins.PluginInformation;
    51 import org.openstreetmap.josm.tools.ColorHelper;
     19import org.openstreetmap.josm.plugins.PluginProxy;
    5220import org.openstreetmap.josm.tools.GBC;
    5321import org.openstreetmap.josm.tools.ImageProvider;
    54 import org.openstreetmap.josm.tools.UrlLabel;
    5522
    5623/**
     
    5926 * @author imi
    6027 */
    61 public class PreferenceDialog extends JDialog {
     28public class PreferenceDialog extends JTabbedPane {
    6229
    63         private final class RequireRestartAction implements ActionListener {
    64                 public void actionPerformed(ActionEvent e) {
    65                         requiresRestart = true;
    66                 }
    67         }
    68         private RequireRestartAction requireRestartAction = new RequireRestartAction();
     30        public final static Collection<PreferenceSetting> settings = new LinkedList<PreferenceSetting>();
    6931
    70         /**
    71          * Action to take place when user pressed the ok button.
    72          */
    73         class OkAction extends AbstractAction {
    74                 private static final String OKBUTTON_PROP = "OptionPane.okButtonText";
     32        public boolean requiresRestart = false;
     33        public final RequireRestartAction requireRestartAction = new RequireRestartAction();
    7534
    76                 public OkAction() {
    77                         super(UIManager.getString(OKBUTTON_PROP), UIManager.getIcon("OptionPane.okIcon"));
    78                         try {
    79                                 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.okButtonMnemonic")));
    80                         } catch (NumberFormatException e) {
    81                                 // just don't set the mnemonic
    82                         }
    83                 }
    84                 public void actionPerformed(ActionEvent e) {
    85                         Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
    86                         Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName());
    87                         Main.pref.put("osm-server.url", osmDataServer.getText());
    88                         Main.pref.put("osm-server.username", osmDataUsername.getText());
    89                         String pwd = String.valueOf(osmDataPassword.getPassword());
    90                         if (pwd.equals(""))
    91                                 pwd = null;
    92                         Main.pref.put("osm-server.password", pwd);
    93                         Main.pref.put("wms.baseurl", wmsServerBaseUrl.getText());
    94                         Main.pref.put("csv.importstring", csvImportString.getText());
    95                         Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected());
    96                         Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected());
    97                         Main.pref.put("draw.rawgps.large", largeGpsPoints.isSelected());
    98                         Main.pref.put("draw.segment.direction", directionHint.isSelected());
    99 
    100                         if (annotationSources.getModel().getSize() > 0) {
    101                                 StringBuilder sb = new StringBuilder();
    102                                 for (int i = 0; i < annotationSources.getModel().getSize(); ++i)
    103                                         sb.append(";"+annotationSources.getModel().getElementAt(i));
    104                                 Main.pref.put("annotation.sources", sb.toString().substring(1));
    105                         } else
    106                                 Main.pref.put("annotation.sources", null);
    107 
    108                         String plugins = "";
    109                         for (Entry<PluginInformation, Boolean> entry : pluginMap.entrySet())
    110                                 if (entry.getValue())
    111                                         plugins += entry.getKey().name + ",";
    112                         if (plugins.endsWith(","))
    113                                 plugins = plugins.substring(0, plugins.length()-1);
    114                         Main.pref.put("plugins", plugins);
    115 
    116                         for (int i = 0; i < colors.getRowCount(); ++i) {
    117                                 String name = (String)colors.getValueAt(i, 0);
    118                                 Color col = (Color)colors.getValueAt(i, 1);
    119                                 Main.pref.put("color."+name, ColorHelper.color2html(col));
    120                         }
    121 
    122                         if (requiresRestart)
    123                                 JOptionPane.showMessageDialog(PreferenceDialog.this,tr("You have to restart JOSM for some settings to take effect."));
    124                         Main.parent.repaint();
    125                         setVisible(false);
    126                 }
    127         }
    128 
    129         /**
    130          * Action to take place when user pressed the cancel button.
    131          */
    132         class CancelAction extends AbstractAction {
    133                 private static final String CANCELBUTTON_PROP = "OptionPane.cancelButtonText";
    134                 public CancelAction() {
    135                         super(UIManager.getString(CANCELBUTTON_PROP),
    136                                         UIManager.getIcon("OptionPane.cancelIcon"));
    137                         try {
    138                                 putValue(MNEMONIC_KEY, new Integer((String)UIManager.get("OptionPane.cancelButtonMnemonic")));
    139                         } catch (NumberFormatException e) {
    140                                 // just don't set the mnemonic
    141                         }
    142                 }
    143                 public void actionPerformed(ActionEvent e) {
    144                         setVisible(false);
    145                 }
    146         }
    147 
    148         /**
    149          * Indicate, that the application has to be restarted for the settings to take effect.
    150          */
    151         private boolean requiresRestart = false;
    152         /**
    153          * ComboBox with all look and feels.
    154          */
    155         private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
    156         /**
    157          * The main tab panel.
    158          */
    159         private JTabbedPane tabPane = new JTabbedPane(JTabbedPane.LEFT);
    160 
    161         /**
    162          * Editfield for the Base url to the REST API from OSM.
    163          */
    164         private JTextField osmDataServer = new JTextField(20);
    165         /**
    166          * Editfield for the username to the OSM account.
    167          */
    168         private JTextField osmDataUsername = new JTextField(20);
    169         /**
    170          * Passwordfield for the userpassword of the REST API.
    171          */
    172         private JPasswordField osmDataPassword = new JPasswordField(20);
    173         /**
    174          * Base url of the WMS server. Holds everything except the bbox= argument.
    175          */
    176         private JTextField wmsServerBaseUrl = new JTextField(20);
    177         /**
    178          * Comma seperated import string specifier or <code>null</code> if the first
    179          * data line should be interpreted as one.
    180          */
    181         private JTextField csvImportString = new JTextField(20);
    182         /**
    183          * The checkbox stating whether nodes should be merged together.
    184          */
    185         private JCheckBox drawRawGpsLines = new JCheckBox(tr("Draw lines between raw gps points."));
    186         /**
    187          * The checkbox stating whether raw gps lines should be forced.
    188          */
    189         private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported."));
    190         private JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points."));
    191         private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
    192         private JTable colors;
    193 
    194         /**
    195          * Combobox with all projections available
    196          */
    197         private JComboBox projectionCombo = new JComboBox(Projection.allProjections);
    198         private JList annotationSources = new JList(new DefaultListModel());
    199         private Map<PluginInformation, Boolean> pluginMap = new HashMap<PluginInformation, Boolean>();
    200 
    201 
    202         /**
    203          * Create a preference setting dialog from an preferences-file. If the file does not
    204          * exist, it will be created.
    205          * If the dialog is closed with Ok, the preferences will be stored to the preferences-
    206          * file, otherwise no change of the file happens.
    207          */
    208         public PreferenceDialog() {
    209                 super(JOptionPane.getFrameForComponent(Main.parent), tr("Preferences"));
    210 
    211                 // look and feel combo box
    212                 String laf = Main.pref.get("laf");
    213                 for (int i = 0; i < lafCombo.getItemCount(); ++i) {
    214                         if (((LookAndFeelInfo)lafCombo.getItemAt(i)).getClassName().equals(laf)) {
    215                                 lafCombo.setSelectedIndex(i);
    216                                 break;
    217                         }
    218                 }
    219                 final ListCellRenderer oldRenderer = lafCombo.getRenderer();
    220                 lafCombo.setRenderer(new DefaultListCellRenderer(){
    221                         @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    222                                 return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
    223                         }
    224                 });
    225                 lafCombo.addActionListener(requireRestartAction);
    226 
    227                 // projection combo box
    228                 for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
    229                         if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) {
    230                                 projectionCombo.setSelectedIndex(i);
    231                                 break;
    232                         }
    233                 }
    234                 projectionCombo.addActionListener(requireRestartAction);
    235 
    236                 drawRawGpsLines.addActionListener(new ActionListener(){
    237                         public void actionPerformed(ActionEvent e) {
    238                                 if (!drawRawGpsLines.isSelected())
    239                                         forceRawGpsLines.setSelected(false);
    240                                 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
    241                         }
    242                 });
    243 
    244                 osmDataServer.setText(Main.pref.get("osm-server.url"));
    245                 osmDataUsername.setText(Main.pref.get("osm-server.username"));
    246                 osmDataPassword.setText(Main.pref.get("osm-server.password"));
    247                 wmsServerBaseUrl.setText(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&"));
    248                 csvImportString.setText(Main.pref.get("csv.importstring"));
    249                 drawRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines"));
    250                 forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information."));
    251                 forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force"));
    252                 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
    253                 largeGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.large"));
    254                 largeGpsPoints.setToolTipText(tr("Draw larger dots for the GPS points."));
    255                 directionHint.setToolTipText(tr("Draw direction hints for all segments."));
    256                 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction"));
    257 
    258                 String annos = Main.pref.get("annotation.sources");
    259                 StringTokenizer st = new StringTokenizer(annos, ";");
    260                 while (st.hasMoreTokens())
    261                         ((DefaultListModel)annotationSources.getModel()).addElement(st.nextToken());
    262 
    263                 Box pluginPanel = Box.createVerticalBox();
    264                 Collection<PluginInformation> availablePlugins = new LinkedList<PluginInformation>();
    265                 File[] pluginFiles = new File(Main.pref.getPreferencesDir()+"plugins").listFiles();
    266                 if (pluginFiles != null) {
    267                         Arrays.sort(pluginFiles);
    268                         for (File f : pluginFiles)
    269                                 if (f.isFile() && f.getName().endsWith(".jar"))
    270                                         availablePlugins.add(new PluginInformation(f));
    271                 }
    272 
    273                 Collection<String> enabledPlugins = Arrays.asList(Main.pref.get("plugins").split(","));
    274                 for (final PluginInformation plugin : availablePlugins) {
    275                         boolean enabled = enabledPlugins.contains(plugin.name);
    276                         final JCheckBox pluginCheck = new JCheckBox(plugin.name, enabled);
    277                         pluginPanel.add(pluginCheck);
    278 
    279                         pluginCheck.setToolTipText(plugin.file.getAbsolutePath());
    280                         JLabel label = new JLabel("<html><i>"+(plugin.description==null?"no description available":plugin.description)+"</i></html>");
    281                         label.setBorder(BorderFactory.createEmptyBorder(0,20,0,0));
    282                         pluginPanel.add(label);
    283                         pluginPanel.add(Box.createVerticalStrut(5));
    284 
    285                         pluginMap.put(plugin, enabled);
    286                         pluginCheck.addActionListener(new ActionListener(){
    287                                 public void actionPerformed(ActionEvent e) {
    288                                         pluginMap.put(plugin, pluginCheck.isSelected());
    289                                         requiresRestart = true;
    290                                 }
    291                         });
    292                 }
    293                 JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    294                 pluginPane.setBorder(null);
    295 
    296                 Map<String,String> allColors = new TreeMap<String, String>(Main.pref.getAllPrefix("color."));
    297 
    298                 Vector<Vector<Object>> rows = new Vector<Vector<Object>>();
    299                 for (Entry<String,String> e : allColors.entrySet()) {
    300                         Vector<Object> row = new Vector<Object>(2);
    301                         row.add(e.getKey().substring("color.".length()));
    302                         row.add(ColorHelper.html2color(e.getValue()));
    303                         rows.add(row);
    304                 }
    305                 Vector<Object> cols = new Vector<Object>(2);
    306                 cols.add(tr("Color"));
    307                 cols.add(tr("Name"));
    308                 colors = new JTable(rows, cols){
    309                         @Override public boolean isCellEditable(int row, int column) {
    310                                 return false;
    311                         }
    312                 };
    313                 colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    314                 final TableCellRenderer oldColorsRenderer = colors.getDefaultRenderer(Object.class);
    315                 colors.setDefaultRenderer(Object.class, new TableCellRenderer(){
    316                         public Component getTableCellRendererComponent(JTable t, Object o, boolean selected, boolean focus, int row, int column) {
    317                                 if (column == 1) {
    318                                         JLabel l = new JLabel(ColorHelper.color2html((Color)o));
    319                                         l.setBackground((Color)o);
    320                                         l.setOpaque(true);
    321                                         return l;
    322                                 }
    323                                 return oldColorsRenderer.getTableCellRendererComponent(t,tr(o.toString()),selected,focus,row,column);
    324                         }
    325                 });
    326                 colors.getColumnModel().getColumn(1).setWidth(100);
    327 
    328                 JButton colorEdit = new JButton(tr("Choose"));
    329                 colorEdit.addActionListener(new ActionListener(){
    330                         public void actionPerformed(ActionEvent e) {
    331                                 if (colors.getSelectedRowCount() == 0) {
    332                                         JOptionPane.showMessageDialog(PreferenceDialog.this, tr("Please select a color."));
    333                                         return;
    334                                 }
    335                                 int sel = colors.getSelectedRow();
    336                                 JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1));
    337                                 int answer = JOptionPane.showConfirmDialog(PreferenceDialog.this, chooser, tr("Choose a color for {0}", colors.getValueAt(sel, 0)), JOptionPane.OK_CANCEL_OPTION);
    338                                 if (answer == JOptionPane.OK_OPTION)
    339                                         colors.setValueAt(chooser.getColor(), sel, 1);
    340                         }
    341                 });
    342 
    343                 // Annotation source panels
    344                 JButton addAnno = new JButton(tr("Add"));
    345                 addAnno.addActionListener(new ActionListener(){
    346                         public void actionPerformed(ActionEvent e) {
    347                                 String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"));
    348                                 if (source == null)
    349                                         return;
    350                                 ((DefaultListModel)annotationSources.getModel()).addElement(source);
    351                                 requiresRestart = true;
    352                         }
    353                 });
    354 
    355                 JButton editAnno = new JButton(tr("Edit"));
    356                 editAnno.addActionListener(new ActionListener(){
    357                         public void actionPerformed(ActionEvent e) {
    358                                 if (annotationSources.getSelectedIndex() == -1)
    359                                         JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
    360                                 else {
    361                                         String source = JOptionPane.showInputDialog(Main.parent, tr("Annotation preset source"), annotationSources.getSelectedValue());
    362                                         if (source == null)
    363                                                 return;
    364                                         ((DefaultListModel)annotationSources.getModel()).setElementAt(source, annotationSources.getSelectedIndex());
    365                                         requiresRestart = true;
    366                                 }
    367                         }
    368                 });
    369 
    370                 JButton deleteAnno = new JButton(tr("Delete"));
    371                 deleteAnno.addActionListener(new ActionListener(){
    372                         public void actionPerformed(ActionEvent e) {
    373                                 if (annotationSources.getSelectedIndex() == -1)
    374                                         JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."));
    375                                 else {
    376                                         ((DefaultListModel)annotationSources.getModel()).remove(annotationSources.getSelectedIndex());
    377                                         requiresRestart = true;
    378                                 }
    379                         }
    380                 });
    381                 annotationSources.setVisibleRowCount(3);
    382 
    383 
    384 
    385                 // setting tooltips
    386                 osmDataServer.setToolTipText(tr("The base URL to the OSM server (REST API)"));
    387                 osmDataUsername.setToolTipText(tr("Login name (email) to the OSM account."));
    388                 osmDataPassword.setToolTipText(tr("Login password to the OSM account. Leave blank to not store any password."));
    389                 wmsServerBaseUrl.setToolTipText(tr("The base URL to the server retrieving WMS background pictures from."));
    390                 csvImportString.setToolTipText(tr("<html>Import string specification. lat/lon and time are imported.<br>" +
    391                                 "<b>lat</b>: The latitude coordinate<br>" +
    392                                 "<b>lon</b>: The longitude coordinate<br>" +
    393                                 "<b>time</b>: The measured time as string<br>" +
    394                                 "<b>ignore</b>: Skip this field<br>" +
    395                                 "An example: \"ignore ignore lat lon\" will use ' ' as delimiter, skip the first two values and read then lat/lon.<br>" +
    396                 "Other example: \"lat,lon\" will just read lat/lon values comma seperated.</html>"));
    397                 drawRawGpsLines.setToolTipText(tr("If your gps device draw to few lines, select this to draw lines along your way."));
    398                 colors.setToolTipText(tr("Colors used by different objects in JOSM."));
    399                 annotationSources.setToolTipText(tr("The sources (url or filename) of annotation preset definition files. See http://josm.eigenheimstrasse.de/wiki/AnnotationPresets for help."));
    400                 addAnno.setToolTipText(tr("Add a new annotation preset source to the list."));
    401                 deleteAnno.setToolTipText(tr("Delete the selected source from the list."));
    402 
    403                 // creating the gui
    404 
    405                 // Display tab
    406                 JPanel display = createPreferenceTab("display", tr("Display Settings"), tr("Various settings that influence the visual representation of the whole program."));
    407                 display.add(new JLabel(tr("Look and Feel")), GBC.std());
    408                 display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    409                 display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
    410                 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
    411                 display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0));
    412                 display.add(largeGpsPoints, GBC.eop().insets(20,0,0,0));
    413                 display.add(directionHint, GBC.eop().insets(20,0,0,0));
    414                 display.add(new JLabel(tr("Colors")), GBC.eol());
    415                 colors.setPreferredScrollableViewportSize(new Dimension(100,112));
    416                 display.add(new JScrollPane(colors), GBC.eol().fill(GBC.BOTH));
    417                 display.add(colorEdit, GBC.eol().anchor(GBC.EAST));
    418                 //display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    419 
    420                 // Connection tab
    421                 JPanel con = createPreferenceTab("connection", tr("Connection Settings"), tr("Connection Settings to the OSM server."));
    422                 con.add(new JLabel(tr("Base Server URL")), GBC.std());
    423                 con.add(osmDataServer, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    424                 con.add(new JLabel(tr("OSM username (email)")), GBC.std());
    425                 con.add(osmDataUsername, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    426                 con.add(new JLabel(tr("OSM password")), GBC.std());
    427                 con.add(osmDataPassword, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,0));
    428                 JLabel warning = new JLabel(tr("<html>" +
    429                                 "WARNING: The password is stored in plain text in the preferences file.<br>" +
    430                                 "The password is transfered in plain text to the server, encoded in the url.<br>" +
    431                 "<b>Do not use a valuable Password.</b></html>"));
    432                 warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
    433                 con.add(warning, GBC.eop().fill(GBC.HORIZONTAL));
    434                 //con.add(new JLabel("WMS server base url (everything except bbox-parameter)"), GBC.eol());
    435                 //con.add(wmsServerBaseUrl, GBC.eop().fill(GBC.HORIZONTAL));
    436                 //con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    437                 con.add(new JLabel(tr("CSV import specification (empty: read from first line in data)")), GBC.eol());
    438                 con.add(csvImportString, GBC.eop().fill(GBC.HORIZONTAL));
    439                 con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    440 
    441                 // Map tab
    442                 JPanel map = createPreferenceTab("map", tr("Map Settings"), tr("Settings for the map projection and data interpretation."));
    443                 map.add(new JLabel(tr("Projection method")), GBC.std());
    444                 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    445                 map.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,0,0,5));
    446                 map.add(new JLabel(tr("Annotation preset sources")), GBC.eol().insets(0,5,0,0));
    447                 map.add(new JScrollPane(annotationSources), GBC.eol().fill(GBC.BOTH));
    448                 map.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
    449                 map.add(addAnno, GBC.std());
    450                 map.add(editAnno, GBC.std().insets(5,0,5,0));
    451                 map.add(deleteAnno, GBC.std());
    452 
    453                 // I HATE SWING!
    454                 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    455                 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    456                 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    457                 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    458                 map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    459 
    460 
    461                 // Plugin tab
    462                 JPanel plugin = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available Plugins."));
    463                 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
    464                 plugin.add(GBC.glue(0,10), GBC.eol());
    465                 plugin.add(new UrlLabel("http://josm.eigenheimstrasse.de/wiki/Plugins", tr("Get more plugins")), GBC.std().fill(GBC.HORIZONTAL));
    466 
    467                 tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    468 
    469                 // OK/Cancel panel at bottom
    470                 JPanel okPanel = new JPanel(new GridBagLayout());
    471                 okPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    472                 okPanel.add(new JButton(new OkAction()), GBC.std());
    473                 okPanel.add(new JButton(new CancelAction()), GBC.std());
    474                 okPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    475 
    476                 // merging all in the content pane
    477                 getContentPane().setLayout(new GridBagLayout());
    478                 getContentPane().add(tabPane, GBC.eol().fill());
    479                 getContentPane().add(okPanel, GBC.eol().fill(GBC.HORIZONTAL));
    480 
    481                 setModal(true);
    482                 pack();
    483                 if (getHeight() > 400)
    484                         setSize(getWidth(), 400);
    485                 if (getWidth() > 600)
    486                         setSize(600, getHeight());
    487                 setLocationRelativeTo(Main.parent);
    488         }
     35        // some common tabs
     36        public final JPanel display = createPreferenceTab("display", tr("Display Settings"), tr("Various settings that influence the visual representation of the whole program."));
     37        public final JPanel connection = createPreferenceTab("connection", tr("Connection Settings"), tr("Connection Settings to the OSM server."));
     38        public final JPanel map = createPreferenceTab("map", tr("Map Settings"), tr("Settings for the map projection and data interpretation."));
    48939
    49040        /**
     
    49747         * @return The created panel ready to add other controls.
    49848         */
    499         private JPanel createPreferenceTab(String icon, String title, String desc) {
     49        public JPanel createPreferenceTab(String icon, String title, String desc) {
    50050                JPanel p = new JPanel(new GridBagLayout());
    50151                p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     
    50656                p.add(descLabel, GBC.eol().insets(5,0,5,20).fill(GBC.HORIZONTAL));
    50757
    508                 tabPane.addTab(null, ImageProvider.get("preferences", icon), p);
    509                 tabPane.setToolTipTextAt(tabPane.getTabCount()-1, desc);
     58                addTab(null, ImageProvider.get("preferences", icon), p);
     59                setToolTipTextAt(getTabCount()-1, desc);
    51060                return p;
    51161        }
     62
     63
     64
     65
     66        private final class RequireRestartAction implements ActionListener {
     67                public void actionPerformed(ActionEvent e) {
     68                        requiresRestart = true;
     69                }
     70        }
     71
     72        public void ok() {
     73                for (PreferenceSetting setting : settings)
     74                        setting.ok();
     75                if (requiresRestart)
     76                        JOptionPane.showMessageDialog(PreferenceDialog.this,tr("You have to restart JOSM for some settings to take effect."));
     77                Main.parent.repaint();
     78        }
     79
     80        /**
     81         * If the dialog is closed with Ok, the preferences will be stored to the preferences-
     82         * file, otherwise no change of the file happens.
     83         */
     84        public PreferenceDialog() {
     85                super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
     86                for (PreferenceSetting setting : settings)
     87                        setting.addGui(this);
     88        }
     89
     90        static {
     91                // order is important!
     92                settings.add(new LafPreference());
     93                settings.add(new DrawingPreference());
     94                settings.add(new ColorPreference());
     95                settings.add(new ServerAccessPreference());
     96                settings.add(new CsvPreference());
     97                settings.add(new ProjectionPreference());
     98                settings.add(new AnnotationPresetPreference());
     99                settings.add(new PluginPreference());
     100               
     101                for (PluginProxy plugin : Main.plugins) {
     102                        PreferenceSetting p = plugin.getPreferenceSetting();
     103                        if (p != null)
     104                                settings.add(p);
     105                }
     106
     107                // always the last: advanced tab
     108                settings.add(new AdvancedPreference());
     109        }
    512110}
  • src/org/openstreetmap/josm/plugins/Plugin.java

    r159 r168  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.gui.MapFrame;
     13import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    1314
    1415/**
     
    6970
    7071        /**
     72         * Called in the preferences dialog to create a preferences page for the plugin,
     73         * if any available.
     74         */
     75        public PreferenceSetting getPreferenceSetting() {return null;}
     76       
     77       
     78        /**
    7179         * Copies the ressource 'from' to the file in the plugin directory named 'to'.
    7280         */
  • src/org/openstreetmap/josm/plugins/PluginProxy.java

    r154 r168  
    22
    33import org.openstreetmap.josm.gui.MapFrame;
     4import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    45
    56
     
    3031        }
    3132    }
     33
     34        @Override public PreferenceSetting getPreferenceSetting() {
     35                try {
     36                        return (PreferenceSetting)plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
     37                } catch (NoSuchMethodException e) {
     38                        return null;
     39                } catch (Exception e) {
     40                        throw new PluginException(this, info.name, e);
     41                }
     42    }
    3243}
Note: See TracChangeset for help on using the changeset viewer.