Ignore:
Timestamp:
2015-10-13T01:02:51+02:00 (9 years ago)
Author:
donvip
Message:

[josm_osmrec] update OSMRecToggleDialog with latest changes from core PropertiesDialog. This class must be cleaned up after

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java

    r31615 r31618  
    1212import java.awt.event.MouseAdapter;
    1313import java.awt.event.MouseEvent;
    14 import java.io.UnsupportedEncodingException;
    1514import java.net.HttpURLConnection;
    1615import java.net.URI;
    1716import java.net.URISyntaxException;
    18 import java.net.URLEncoder;
    1917import java.util.ArrayList;
    2018import java.util.Arrays;
     
    3432
    3533import javax.swing.AbstractAction;
    36 import static javax.swing.Action.NAME;
    37 import static javax.swing.Action.SHORT_DESCRIPTION;
    38 import static javax.swing.Action.SMALL_ICON;
    3934import javax.swing.JComponent;
    4035import javax.swing.JLabel;
     
    126121 * @author imi
    127122 */
    128 public class OSMRecToggleDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {
     123public class OSMRecToggleDialog extends ToggleDialog
     124implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {
    129125
    130126    /**
     
    162158
    163159    // Popup menu handlers
    164     private final PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu);
    165     private final PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu);
    166     private final PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu);
    167 
    168     private final Map<String, Map<String, Integer>> valueCount = new TreeMap<>();
     160    private final transient PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu);
     161    private final transient PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu);
     162    private final transient PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu);
     163
     164    private final transient Map<String, Map<String, Integer>> valueCount = new TreeMap<>();
    169165    /**
    170166     * This sub-object is responsible for all adding and editing of tags
    171167     */
    172     private final OSMRecPluginHelper editHelper = new OSMRecPluginHelper(tagData, valueCount);
    173 
    174     private final DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
     168    private final transient OSMRecPluginHelper editHelper = new OSMRecPluginHelper(tagData, valueCount);
     169
     170    private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
    175171    private final HelpAction helpAction = new HelpAction();
    176172    private final PasteValueAction pasteValueAction = new PasteValueAction();
     
    191187
    192188    private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction();
    193     private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction();
     189    private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction =
     190                new DownloadSelectedIncompleteMembersAction();
    194191
    195192    private final SelectMembersAction selectMembersAction = new SelectMembersAction(false);
    196193    private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true);
    197194
    198     private final HighlightHelper highlightHelper= new HighlightHelper();
     195    private final transient HighlightHelper highlightHelper= new HighlightHelper();
    199196
    200197    /**
     
    221218            + tr("Select objects or create new objects and get recommendation.") + "</p></html>");
    222219
    223     private final TaggingPresetHandler presetHandler = new TaggingPresetHandler() {
     220    private final transient TaggingPresetHandler presetHandler = new TaggingPresetHandler() {
    224221        @Override public void updateTags(List<Tag> tags) {
    225222            Command command = TaggingPreset.createCommand(getSelection(), tags);
     
    337334                    return this;
    338335                Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    339                 boolean isDisabledAndHidden = (((Relation)table.getValueAt(row, 0))).isDisabledAndHidden();
     336                boolean isDisabledAndHidden = ((Relation) table.getValueAt(row, 0)).isDisabledAndHidden();
    340337                if (c instanceof JLabel) {
    341338                    JLabel label = (JLabel) c;
     
    353350                    boolean isSelected, boolean hasFocus, int row, int column) {
    354351                Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
    355                 boolean isDisabledAndHidden = (((Relation)table.getValueAt(row, 0))).isDisabledAndHidden();
     352                boolean isDisabledAndHidden = ((Relation) table.getValueAt(row, 0)).isDisabledAndHidden();
    356353                if (c instanceof JLabel) {
    357354                    JLabel label = (JLabel)c;
     
    513510     * is the editor's business.
    514511     *
    515      * @param row
     512     * @param row position
    516513     */
    517514    private void editMembership(int row) {
     
    620617        final Map<String, String> tags = new HashMap<>();
    621618        valueCount.clear();
    622         EnumSet<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
     619        Set<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
    623620        for (OsmPrimitive osm : newSel) {
    624621            types.add(TaggingPresetType.forPrimitive(osm));
     
    631628                        v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);
    632629                    } else {
    633                         TreeMap<String, Integer> v = new TreeMap<>();
     630                        Map<String, Integer> v = new TreeMap<>();
    634631                        v.put(value, 1);
    635632                        valueCount.put(key, v);
     
    722719       //end of temp code
    723720       
    724        
    725721        int selectedIndex;
    726722        if (selectedTag != null && (selectedIndex = findRow(tagData, selectedTag)) != -1) {
     
    781777        int row = tagTable.getSelectedRow();
    782778        if (row == -1) return null;
    783         TreeMap<String, Integer> map = (TreeMap<String, Integer>) tagData.getValueAt(row, 1);
     779        Map<String, Integer> map = (TreeMap<String, Integer>) tagData.getValueAt(row, 1);
    784780        return new Tag(
    785781                tagData.getValueAt(row, 0).toString(),
     
    811807     */
    812808    public class MouseClickWatch extends MouseAdapter {
    813         @Override public void mouseClicked(MouseEvent e) {
     809        @Override
     810        public void mouseClicked(MouseEvent e) {
    814811            if (e.getClickCount() < 2) {
    815812                // single click, clear selection in other table not clicked in
     
    819816                    tagTable.clearSelection();
    820817                }
    821             }
    822             // double click, edit or add tag
    823             else if (e.getSource() == tagTable ) {
     818            } else if (e.getSource() == tagTable ) {
     819                // double click, edit or add tag
    824820                int row = tagTable.rowAtPoint(e.getPoint());
    825821                if (row > -1) {
    826                     boolean focusOnKey = (tagTable.columnAtPoint(e.getPoint()) == 0);
     822                    boolean focusOnKey = tagTable.columnAtPoint(e.getPoint()) == 0;
    827823                    editHelper.editTag(row, focusOnKey);
    828824                } else {
     
    835831                    editMembership(row);
    836832                }
    837             }
    838             else {
     833            } else {
    839834                editHelper.addTag();
    840835                btnAdd.requestFocusInWindow();
    841836            }
    842837        }
    843         @Override public void mousePressed(MouseEvent e) {
     838
     839        @Override
     840        public void mousePressed(MouseEvent e) {
    844841            if (e.getSource() == tagTable) {
    845842                membershipTable.clearSelection();
     
    855852        private List<Integer> position = new ArrayList<>();
    856853        private Iterable<OsmPrimitive> selection;
    857         private String positionString = null;
    858         private String roleString = null;
     854        private String positionString;
     855        private String roleString;
    859856
    860857        MemberInfo(Iterable<OsmPrimitive> selection) {
     
    909906     */
    910907    public static class ReadOnlyTableModel extends DefaultTableModel {
    911         @Override public boolean isCellEditable(int row, int column) {
     908        @Override
     909        public boolean isCellEditable(int row, int column) {
    912910            return false;
    913911        }
    914         @Override public Class<?> getColumnClass(int columnIndex) {
     912        @Override
     913        public Class<?> getColumnClass(int columnIndex) {
    915914            return String.class;
    916915        }
     
    922921    class DeleteAction extends JosmAction implements ListSelectionListener {
    923922
    924         static final String DELETE_FROM_RELATION_PREF = "delete_from_relation";
    925 
    926         public DeleteAction() {
     923        private static final String DELETE_FROM_RELATION_PREF = "delete_from_relation";
     924
     925        DeleteAction() {
    927926            super(tr("Delete"), /* ICON() */ "dialogs/delete", tr("Delete the selected key in all objects"),
    928927                    Shortcut.registerShortcut("properties:delete", tr("Delete Tags"), KeyEvent.VK_D,
     
    933932        protected void deleteTags(int[] rows){
    934933            // convert list of rows to HashMap (and find gap for nextKey)
    935             HashMap<String, String> tags = new HashMap<>(rows.length);
     934            Map<String, String> tags = new HashMap<>(rows.length);
    936935            int nextKeyIndex = rows[0];
    937936            for (int row : rows) {
     
    972971            int rowCount = membershipTable.getRowCount();
    973972            if (rowCount > 1) {
    974                 nextRelation = (Relation)membershipData.getValueAt((row + 1 < rowCount ? row + 1 : row - 1), 0);
     973                nextRelation = (Relation) membershipData.getValueAt(row + 1 < rowCount ? row + 1 : row - 1, 0);
    975974            }
    976975
     
    978977                    tr("Change relation"),
    979978                    new String[] {tr("Delete from relation"), tr("Cancel")});
    980             ed.setButtonIcons(new String[] {"dialogs/delete.png", "cancel.png"});
     979            ed.setButtonIcons(new String[] {"dialogs/delete", "cancel"});
    981980            ed.setContent(tr("Really delete selection from relation {0}?", cur.getDisplayName(DefaultNameFormatter.getInstance())));
    982981            ed.toggleEnable(DELETE_FROM_RELATION_PREF);
     
    10321031     */
    10331032    class AddAction extends JosmAction {
    1034         public AddAction() {
     1033        AddAction() {
    10351034            super(tr("Add Recommendation"), /* ICON() */ "dialogs/add", tr("Add a recommended key/value pair to your object"),
    10361035                    Shortcut.registerShortcut("properties:add", tr("Add Tag"), KeyEvent.VK_A,
     
    10401039        @Override
    10411040        public void actionPerformed(ActionEvent e) {
    1042             //System.out.println("clicked recommend");
    10431041            editHelper.addTag();
    10441042            btnAdd.requestFocusInWindow();           
     
    10511049     */
    10521050    class EditActionTrain extends JosmAction implements ListSelectionListener {
    1053         public EditActionTrain() {           
    1054 //            super(tr("Train a Model"), /* ICON() */ "dialogs/edit", tr("Start the training engine!"),
    1055 //                    Shortcut.registerShortcut("properties:edit", tr("Edit Tags"), KeyEvent.VK_S,
    1056 //                            Shortcut.ALT), false);
    1057            
     1051        EditActionTrain() {           
    10581052            super(tr("Train a Model"), /* ICON() */ "dialogs/fix", tr("Start the training engine!"),
    10591053                    Shortcut.registerShortcut("properties:edit", tr("Edit Tags"), KeyEvent.VK_S,
    10601054                            Shortcut.ALT), false);
    1061            
    1062             //images/dialogs/train.png
    1063             //System.out.println("icon");
    10641055            setEnabled(true);
    10651056            updateEnabledState();
     
    10751066            } else if (membershipTable.getSelectedRowCount() == 1) {
    10761067                int row = membershipTable.getSelectedRow();
    1077                 //System.out.println("tagTable: " + tagTable);
    1078                 //System.out.println("membershipTable: " + membershipTable);               
    10791068                editHelper.editTag(row, false);
    10801069                //editMembership(row);
     
    11011090
    11021091    class HelpAction extends AbstractAction {
    1103         public HelpAction() {
     1092        HelpAction() {
    11041093            putValue(NAME, tr("Go to OSM wiki for tag help (F1)"));
    11051094            putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));
     
    11161105                if (tagTable.getSelectedRowCount() == 1) {
    11171106                    row = tagTable.getSelectedRow();
    1118                     String key = URLEncoder.encode(tagData.getValueAt(row, 0).toString(), "UTF-8");
     1107                    String key = Utils.encodeUrl(tagData.getValueAt(row, 0).toString());
    11191108                    @SuppressWarnings("unchecked")
    11201109                    Map<String, Integer> m = (Map<String, Integer>) tagData.getValueAt(row, 1);
    1121                     String val = URLEncoder.encode(m.entrySet().iterator().next().getKey(), "UTF-8");
     1110                    String val = Utils.encodeUrl(m.entrySet().iterator().next().getKey());
    11221111
    11231112                    uris.add(new URI(String.format("%s%sTag:%s=%s", base, lang, key, val)));
     
    11311120                    String type = ((Relation)membershipData.getValueAt(row, 0)).get("type");
    11321121                    if (type != null) {
    1133                         type = URLEncoder.encode(type, "UTF-8");
     1122                        type = Utils.encodeUrl(type);
    11341123                    }
    11351124
     
    11921181                    }
    11931182                });
    1194             } catch (URISyntaxException | UnsupportedEncodingException e1) {
     1183            } catch (URISyntaxException e1) {
    11951184                Main.error(e1);
    11961185            }
     
    11991188
    12001189    class PasteValueAction extends AbstractAction {
    1201         public PasteValueAction() {
     1190        PasteValueAction() {
    12021191            putValue(NAME, tr("Paste Value"));
    12031192            putValue(SHORT_DESCRIPTION, tr("Paste the value of the selected tag from clipboard"));
     
    12471236    class CopyValueAction extends AbstractCopyAction {
    12481237
    1249         public CopyValueAction() {
     1238        /**
     1239         * Constructs a new {@code CopyValueAction}.
     1240         */
     1241        CopyValueAction() {
    12501242            putValue(NAME, tr("Copy Value"));
    12511243            putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard"));
     
    12611253    class CopyKeyValueAction extends AbstractCopyAction {
    12621254
    1263         public CopyKeyValueAction() {
     1255        CopyKeyValueAction() {
    12641256            putValue(NAME, tr("Copy selected Key(s)/Value(s)"));
    12651257            putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag(s) to clipboard"));
     
    12751267    class CopyAllKeyValueAction extends AbstractCopyAction {
    12761268
    1277         public CopyAllKeyValueAction() {
     1269        CopyAllKeyValueAction() {
    12781270            putValue(NAME, tr("Copy all Keys/Values"));
    12791271            putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard"));
     
    12911283
    12921284    class SearchAction extends AbstractAction {
    1293         final boolean sameType;
    1294 
    1295         public SearchAction(boolean sameType) {
     1285        private final boolean sameType;
     1286
     1287        SearchAction(boolean sameType) {
    12961288            this.sameType = sameType;
    12971289            if (sameType) {
     
    13291321                    t = "type:relation ";
    13301322                }
    1331                 s.append(sep).append("(").append(t).append("\"").append(
     1323                s.append(sep).append('(').append(t).append('"').append(
    13321324                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key)).append("\"=\"").append(
    13331325                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val)).append("\")");
     
    13351327            }
    13361328
    1337             SearchSetting ss = new SearchSetting();
     1329            final SearchSetting ss = new SearchSetting();
    13381330            ss.text = s.toString();
    13391331            ss.mode = SearchMode.replace;
Note: See TracChangeset for help on using the changeset viewer.