Index: /applications/editors/josm/plugins/utilsplugin2/build.xml
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 27418)
+++ /applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 27419)
@@ -30,5 +30,5 @@
 <project name="utilsplugin2" default="dist" basedir=".">
     <!-- enter the SVN commit message -->
-    <property name="commit.message" value="Utilsplugin2: shortcut confilct removed, fix NPE in OpenCustomURL config, added osm.mapki.com"/>
+    <property name="commit.message" value="Utilsplugin2: OpenCustomURL refactoring"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     <property name="plugin.main.version" value="4549"/>
Index: plications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/ChooseURLAction.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/ChooseURLAction.java	(revision 27418)
+++ 	(revision )
@@ -1,105 +1,0 @@
-package utilsplugin2;
-
-import java.awt.GridBagLayout;
-import java.awt.event.ItemEvent;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.JComboBox;
-import javax.swing.JPanel;
-import javax.swing.event.ListSelectionEvent;
-import org.openstreetmap.josm.gui.ExtendedDialog;
-import org.openstreetmap.josm.tools.GBC;
-import org.openstreetmap.josm.Main;
-import java.awt.event.ActionEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyEvent;
-import javax.swing.JCheckBox;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JTextField;
-import javax.swing.ListSelectionModel;
-import javax.swing.event.ListSelectionListener;
-import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.gui.SelectionManager;
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-public class ChooseURLAction extends JosmAction {
-
-    public ChooseURLAction() {
-        super(tr("Select custom URL"), "selecturl", tr("Select custom URL"),null,true,true);
-         putValue("toolbar", "action/selectURL");
-    }
-
-    @Override
-    public void actionPerformed(ActionEvent e) {
-       showConfigDialog(false);
-    }
-
-    @Override
-    protected void updateEnabledState() {
-        if (getCurrentDataSet() == null) {
-            setEnabled(false);
-        } else {
-            setEnabled(true);
-        }
-    }
-        
-    public static void showConfigDialog(final boolean fast) {
-        JPanel all = new JPanel();
-        GridBagLayout layout = new GridBagLayout();
-        all.setLayout(layout);
-        
-        List<String> items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");
-        int n=items.size()/2 , idxToSelect=-1;
-        final String names[] =new String[n];
-        final String vals[] =new String[n];
-        String addr = Main.pref.get("utilsplugin2.customurl");
-        for (int i=0;i<n;i++) {
-            names[i]=items.get(i*2);
-            vals[i]=items.get(i*2+1);
-            if (vals[i].equals(addr)) idxToSelect=i; 
-        }
-        final JLabel label1=new JLabel(tr("Please select one of custom URLs (configured in Preferences)"));
-        final JList list1=new JList(names);
-        final JTextField editField=new JTextField();
-        final JCheckBox check1=new JCheckBox(tr("Ask every time"));
-        
-        final ExtendedDialog dialog = new ExtendedDialog(Main.parent,
-                tr("Configure custom URL"),
-                new String[] {tr("OK"),tr("Cancel"),}
-        );
-        list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-        list1.addListSelectionListener(new ListSelectionListener() {
-            @Override
-            public void valueChanged(ListSelectionEvent e) {
-                int idx=list1.getSelectedIndex();
-                if (idx>=0) editField.setText(vals[idx]);
-            }
-        });
-        list1.setSelectedIndex(idxToSelect);
-        check1.setSelected(Main.pref.getBoolean("utilsplugin2.askurl",false));
-        
-        editField.setEditable(false);
-        
-        all.add(label1,GBC.eop().fill(GBC.HORIZONTAL).insets(15,5,15,0));
-        all.add(list1,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
-        all.add(editField,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
-        all.add(check1,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
-        
-        
-        dialog.setContent(all, false);
-        dialog.setButtonIcons(new String[] {"ok.png","cancel.png",});
-        dialog.setDefaultButton(1);
-        dialog.showDialog();
-        
-        int idx = list1.getSelectedIndex();
-        if (dialog.getValue() ==1 && idx>=0) {
-           Main.pref.put("utilsplugin2.customurl", vals[idx]);
-           Main.pref.put("utilsplugin2.askurl", check1.isSelected());
-        }
-    }
-
-    
-    
-}
Index: plications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/OpenPageAction.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/OpenPageAction.java	(revision 27418)
+++ 	(revision )
@@ -1,116 +1,0 @@
-// License: GPL. Copyright 2007 by Immanuel Scholz and others
-package utilsplugin2;
-
-import java.io.UnsupportedEncodingException;
-import static org.openstreetmap.josm.tools.I18n.tr;
-import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.net.URLEncoder;
-import java.util.Collection;
-
-import java.util.regex.Matcher;
-
-import java.util.regex.Pattern;
-import javax.swing.JOptionPane;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.data.osm.OsmPrimitive;
-import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
-import org.openstreetmap.josm.tools.OpenBrowser;
-import org.openstreetmap.josm.tools.Shortcut;
-
-/**
- * Mirror the selected ways nodes or ways along line given by two first selected points
- *
- * Note: If a ways are selected, their nodes are mirrored
- *
- * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :)
- */ 
-public final class OpenPageAction extends JosmAction {
-    private final String defaultURL = "http://ru.wikipedia.org/w/index.php?search={name}&fulltext=Search";
-
-    public OpenPageAction() {
-        super(tr("Open custom URL"), "openurl",
-                tr("Opens specified URL browser"),
-                Shortcut.registerShortcut("tools:openurl", tr("Tool: {0}", tr("Open custom URL")),
-                KeyEvent.VK_BACK_SLASH, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
-        putValue("help", ht("/Action/OpenPage"));
-    }
-
-    public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
-        OsmPrimitive p=null;
-        if (sel.size()>=1) {
-            p=sel.iterator().next();
-        }
-        
-        if (Main.pref.getBoolean("utilsplugin2.askurl",false)==true) 
-            ChooseURLAction.showConfigDialog(true);
-        
-        //lat = p.getBBox().getTopLeft().lat();
-        //lon = p.getBBox().getTopLeft().lon();
-        LatLon center = Main.map.mapView.getLatLon(Main.map.mapView.getWidth()/2, Main.map.mapView.getHeight()/2);
-                
-        
-        String addr = Main.pref.get("utilsplugin2.customurl", defaultURL);
-        Pattern pat = Pattern.compile("\\{([^\\}]*)\\}");
-        Matcher m = pat.matcher(addr);
-        String val,key;
-        String keys[]=new String[100],vals[]=new String[100];
-        int i=0;
-        try {
-        while (m.find()) {
-                key=m.group(1); val=null;                
-                if (key.equals("#id")) {
-                    if (p!=null) val=Long.toString(p.getId()); ;
-                } else if (key.equals("#type")) {
-                    if (p!=null) val = OsmPrimitiveType.from(p).getAPIName(); ;
-                } else if (key.equals("#lat")) {
-                    val = Double.toString(center.lat());
-                } else if (key.equals("#lon")) {
-                    val = Double.toString(center.lon());
-                }
-                else {
-                    if (p!=null) {
-                        val =p.get(key);
-                        if (val!=null) val =URLEncoder.encode(p.get(key), "UTF-8"); else return;
-                    }
-                }
-                keys[i]=m.group();
-                if  (val!=null) vals[i]=val;
-                else vals[i]="";
-                i++;
-        }
-        } catch (UnsupportedEncodingException ex) {
-            System.err.println("Encoding error");
-            return;
-        }
-        for (int j=0;j<i;j++){
-            addr = addr.replace(keys[j],vals[j]);
-        }
-        try {
-            OpenBrowser.displayUrl(addr);
-        } catch (Exception ex) {
-            System.err.println("Can not open URL"+addr);
-        }
-        //Collection<Command> cmds = new LinkedList<Command>();
-
-          //  cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr ));
-        //Main.main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds));
-    }
-
-    @Override
-    protected void updateEnabledState() {
-        if (getCurrentDataSet() == null) {
-            setEnabled(false);
-        } else {
-            setEnabled(true);
-        }
-    }
-
-    
-}
Index: /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java	(revision 27418)
+++ /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java	(revision 27419)
@@ -1,4 +1,8 @@
 // License: GPL v2 or later. See LICENSE file for details.
 package utilsplugin2;
+
+import utilsplugin2.customurl.ChooseURLAction;
+import utilsplugin2.customurl.OpenPageAction;
+import utilsplugin2.customurl.UtilsPluginPreferences;
 
 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
Index: plications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPluginPreferences.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPluginPreferences.java	(revision 27418)
+++ 	(revision )
@@ -1,233 +1,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package utilsplugin2;
-
-import java.util.Scanner;
-import java.awt.event.ActionEvent;
-import javax.swing.JButton;
-import java.util.List;
-import javax.swing.table.TableModel;
-import javax.swing.JTable;
-import javax.swing.JLabel;
-import java.awt.GridBagLayout;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.event.TableModelEvent;
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
-import org.openstreetmap.josm.gui.widgets.HtmlPanel;
-import java.awt.GridBagConstraints;
-import java.awt.event.ActionListener;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import javax.swing.JPanel;
-import javax.swing.ListSelectionModel;
-import javax.swing.event.TableModelListener;
-import javax.swing.table.DefaultTableModel;
-import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
-import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
-import org.openstreetmap.josm.tools.GBC;
-
-import static org.openstreetmap.josm.tools.I18n.*;
-
-public class UtilsPluginPreferences  implements PreferenceSetting {
-    private final String defaultURL = "http://ru.wikipedia.org/w/index.php?search={name}&fulltext=Search";
-
-    HistoryComboBox combo1=new HistoryComboBox();
-    JTable table;
-    JButton resetButton;
-    JButton loadButton;
-    JButton saveButton;
-
-    @Override
-    public void addGui(PreferenceTabbedPane gui) {
-        JPanel pp = gui.createPreferenceTab("utils", tr("Utilsplugin2 settings [TESTING]"),
-                tr("Here you can change some preferences of Utilsplugin2 functions"));
-        JPanel all = new JPanel();
-        GridBagLayout layout = new GridBagLayout();
-        all.setLayout(layout);
-        
-        // FIXME: get rid of hardcoded URLS
-        List<String> items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");
-        String addr = Main.pref.get("utilsplugin2.customurl", defaultURL);
-        table=new JTable(new DefaultTableModel(null,new String[]{"Title","URL"}));
-        if (addr==null || items==null || items.isEmpty()) {
-            items = resetURLList();
-        }
-        //System.out.println("pref:"+addr);
-        
-        resetButton = new JButton(tr("Reset"));
-        resetButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                fillRows(resetURLList());
-            }
-        });
-        
-        saveButton = new JButton(tr("Save to file"));
-        saveButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                saveURLList();
-            }
-        });
-        
-        loadButton = new JButton(tr("Load from file"));
-        loadButton.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                fillRows(loadURLList());
-            }
-        });
-        
-        fillRows(items);
-        
-        HtmlPanel help = new HtmlPanel(tr("Please edit custom URLs and select one row to use with the tool<br/>"
-                + " <b>&#123;key&#125;</b> is replaced with the tag value<br/>"
-                + " <b>&#123;#id&#125;</b> is replaced with the element ID<br/>"
-                + " <b>&#123;#type&#125;</b> is replaced with \"node\",\"way\" or \"relation\" <br/>"
-                + " <b>&#123;#lat&#125; , &#123;#lon&#125;</b> is replaced with map center latitude/longitude <br/>"
-                + " Your can manually load settings from file <b>customurl.txt</b> in JOSM folder"));
-        
-        all.add(new JLabel(tr("Custom URL configuration")),GBC.std().insets(5,10,0,0));
-        all.add(resetButton,GBC.std().insets(25,10,0,0));
-        all.add(loadButton,GBC.std().insets(25,10,0,0));
-        all.add(saveButton,GBC.eol().insets(25,10,0,0));
-        all.add(help,GBC.eop().insets(5,10,0,0));
-        
-        table.getColumnModel().getColumn(0).setPreferredWidth(150);
-        table.getColumnModel().getColumn(0).setMaxWidth(300);
-        table.getColumnModel().getColumn(1).setPreferredWidth(300);
-        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-        table.getModel().addTableModelListener(new TableModelListener() {
-            @Override
-            public void tableChanged(TableModelEvent e) {
-                int row = e.getFirstRow();
-                int column = e.getColumn();
-                DefaultTableModel model = (DefaultTableModel)(e.getSource());
-                if (row<0  || column<0) return;
-                String data = (String)model.getValueAt(row, column);
-                if (data!=null && data.length()>0 && row==model.getRowCount()-1) 
-                    model.addRow(new String[]{"",""});
-            }
-        });
-        all.add(table,GBC.eop().fill());
-        
-        pp.add(all, GBC.eol().fill(GridBagConstraints.BOTH));
-    }
-
-    private void fillRows(List<String> items) {
-        if (items==null) return;
-        int p=0,row=0;
-        String name, url;
-        DefaultTableModel model = (DefaultTableModel) table.getModel();
-        model.setRowCount(0);
-        int n=items.size();
-        while (true) {
-            if (p>=n) break;
-            name = items.get(p);
-            //System.out.println("name="+name);
-            p++;
-            if (p>=n) break;
-            url = items.get(p);
-            //System.out.println("url="+url);
-            p++;
-            model.addRow(new String[]{name,url});
-            row++;
-        }
-        model.addRow(new String[]{"",""});
-    }
-
-    @Override
-    public boolean ok() {
-        String addr=combo1.getText();
-        List<String> lst = readItemsFromTable();
-        Main.pref.putCollection("utilsplugin2.urlHistory",lst);
-        try {
-            Main.pref.save();
-        } catch (IOException ex) {
-            Logger.getLogger(UtilsPluginPreferences.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        return false;
-    }
-
-    private List<String> resetURLList() {
-        ArrayList<String> items=new ArrayList<String>();
-            items= new ArrayList<String>();
-            items.add("Wikipedia");
-            items.add("http://en.wikipedia.org/w/index.php?search={name}&fulltext=Search");
-            items.add("Wikipedia RU");
-            items.add(defaultURL);
-            items.add("LatLon buildings");
-            items.add("http://latlon.org/buildings?zoom=17&lat={#lat}&lon={#lon}&layers=B");
-            items.add("AMDMi3 Russian streets");
-            items.add("http://addresses.amdmi3.ru/?zoom=11&lat={#lat}&lon={#lon}&layers=B00");
-            items.add("Mapki - More  History with CT");
-            items.add("http://osm.mapki.com/history/{#type}.php?id={#id}");
-            items.add("Element history [demo, =Ctrl-Shift-H]");
-            items.add("http://www.openstreetmap.org/browse/{#type}/{#id}/history");
-            items.add("Browse element [demo, =Ctrl-Shift-I]");
-            items.add("http://www.openstreetmap.org/browse/{#type}/{#id}");
-        Main.pref.putCollection("utilsplugin2.urlHistory",items);
-        Main.pref.put("utilsplugin2.customurl",items.get(4));
-        return items;
-    }
-    
-    private List<String> loadURLList() {
-        ArrayList<String> items=new ArrayList<String>();
-        BufferedReader fr=null;
-        try {
-        File f = new File (Main.pref.getPreferencesDir(),"customurl.txt");
-        fr = new BufferedReader(new FileReader(f));
-        String s;
-        while ((s = fr.readLine()) !=null ) items.add(s);
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try { if (fr!=null) fr.close(); } catch (Exception e) {}
-        }
-        return items;
-        
-    }
-    
-    private void saveURLList() {
-        List<String> items=readItemsFromTable();
-        File f = new File (Main.pref.getPreferencesDir(),"customurl.txt");
-        PrintWriter fw=null;
-        try {
-        fw=new PrintWriter(f);
-        for (String s : items) {
-            fw.println(s);
-        }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try { if (fw!=null) fw.close(); } catch (Exception e) {}
-        }
-    }
-
-    private List<String> readItemsFromTable() {
-        TableModel model = (table.getModel());
-        String v;
-        ArrayList<String> lst=new ArrayList<String>();
-        int n=model.getRowCount();
-        for (int i=0;i<n;i++) {
-            v=(String) model.getValueAt(i, 0);
-            if (v.length()==0) continue;
-            lst.add(v);
-            v=(String) model.getValueAt(i, 1);
-            lst.add(v);
-        }
-        int row=table.getSelectedRow();
-        if (row!=-1) {
-            v=(String) model.getValueAt(row, 1);
-            Main.pref.put("utilsplugin2.customurl",v);
-        }
-        return lst;
-    }
-}
