Ignore:
Timestamp:
2016-07-25T20:56:38+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13050 - cannot copy from the object history view (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/data/TagTransferData.java

    r10604 r10637  
    4040
    4141    /**
     42     * Create a new {@link TagTransferData} object with the given tags.
     43     * @param tags The tags.
     44     * @since 10637
     45     */
     46    public TagTransferData(Map<String, String> tags) {
     47        this.tags.putAll(tags);
     48    }
     49
     50    /**
    4251     * Gets all tags contained in this data.
    4352     * @return The tags.
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r10627 r10637  
    582582        @Override
    583583        public Object getValueAt(int row, int column) {
     584            return getKeyAt(row);
     585        }
     586
     587        /**
     588         * Get the key for the given row.
     589         * @param row The row
     590         * @return The key in that row.
     591         * @since 10637
     592         */
     593        public String getKeyAt(int row) {
    584594            return keys.get(row);
    585595        }
     
    637647        @Override
    638648        public int getColumnCount() {
    639             return 1;
     649            return 2;
    640650        }
    641651    }
  • trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java

    r8510 r10637  
    1313
    1414    private final Set<ListSelectionModel> participants;
     15    private boolean preventRecursion = false;
    1516
    1617    /**
     
    3233    @Override
    3334    public void valueChanged(ListSelectionEvent e) {
     35        if (preventRecursion) {
     36            return;
     37        }
     38        preventRecursion = true;
    3439        DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();
    3540        int i = referenceModel.getMinSelectionIndex();
     
    4045            model.setSelectionInterval(i, i);
    4146        }
     47        preventRecursion = false;
    4248    }
    4349}
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r7801 r10637  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.history;
     3
     4import java.awt.event.FocusEvent;
     5import java.awt.event.FocusListener;
    36
    47import javax.swing.JTable;
     
    1619 */
    1720public class TagInfoViewer extends HistoryViewerPanel {
     21    private static final class RepaintOnFocusChange implements FocusListener {
     22        @Override
     23        public void focusLost(FocusEvent e) {
     24            repaintSelected(e);
     25        }
     26
     27        @Override
     28        public void focusGained(FocusEvent e) {
     29            repaintSelected(e);
     30        }
     31
     32        private static void repaintSelected(FocusEvent e) {
     33            // we would only need the selected rows, but this is easier:
     34            e.getComponent().repaint();
     35        }
     36    }
     37
     38    /**
     39     * Constructs a new {@code TagInfoViewer}.
     40     * @param model The history browsing model
     41     */
     42    public TagInfoViewer(HistoryBrowserModel model) {
     43        super(model);
     44    }
    1845
    1946    @Override
     
    2451        );
    2552        table.setName("table.referencetagtable");
    26         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    27         selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
     53        setUpDataTransfer(table);
    2854        return table;
    2955    }
     
    3662        );
    3763        table.setName("table.currenttagtable");
    38         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    39         selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
     64        setUpDataTransfer(table);
    4065        return table;
    4166    }
    4267
    43     /**
    44      * Constructs a new {@code TagInfoViewer}.
    45      * @param model The history browsing model
    46      */
    47     public TagInfoViewer(HistoryBrowserModel model) {
    48         super(model);
     68    private void setUpDataTransfer(JTable table) {
     69        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     70        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
     71        table.setTransferHandler(new TagInfoTransferHandler());
     72        table.addFocusListener(new RepaintOnFocusChange());
    4973    }
    5074}
  • trunk/src/org/openstreetmap/josm/gui/history/TagTableCellRenderer.java

    r10217 r10637  
    1717 */
    1818public class TagTableCellRenderer extends JLabel implements TableCellRenderer {
    19     public static final Color BGCOLOR_SELECTED = new Color(143, 170, 255);
     19    /**
     20     * The background color for a selected row that has the focus.
     21     */
     22    public static final Color BGCOLOR_SELECTED_FOCUS = new Color(0xff8faaff);
     23    /**
     24     * The background color for a selected row while the table is not focused.
     25     */
     26    public static final Color BGCOLOR_SELECTED = new Color(0xffafc2ff);
    2027
    2128    /**
     
    2633    }
    2734
    28     protected void setBackgroundReadable(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected, boolean isValue) {
     35    protected void setBackgroundReadable(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected, boolean hasFocus,
     36            boolean isValue) {
    2937        Color bgColor = UIManager.getColor("Table.background");
    3038        if (!model.hasTag(key) && model.isCurrentPointInTime()
     
    3846        }
    3947        if (isSelected) {
    40             bgColor = BGCOLOR_SELECTED;
     48            if (hasFocus) {
     49                bgColor = BGCOLOR_SELECTED_FOCUS;
     50            } else {
     51                bgColor = BGCOLOR_SELECTED;
     52            }
    4153        }
    4254
     
    5466        HistoryBrowserModel.TagTableModel model = getTagTableModel(table);
    5567
    56         switch(column) {
    57         case 0:
    58             // the name column
    59             setText(model.hasTag(key) ? key : "");
    60             setToolTipText(getText());
    61             setBackgroundReadable(key, model, isSelected, false);
    62             break;
    63         case 1:
    64             // the value column
    65             setText(model.hasTag(key) ? model.getValue(key) : "");
    66             setToolTipText(getText());
    67             setBackgroundReadable(key, model, isSelected, true);
    68             break;
    69         default: // Do nothing
     68        String text = "";
     69        if (model.hasTag(key)) {
     70            switch(column) {
     71            case TagTableColumnModel.COLUMN_KEY:
     72                // the name column
     73                text = key;
     74                break;
     75            case TagTableColumnModel.COLUMN_VALUE:
     76                // the value column
     77                text = model.getValue(key);
     78                break;
     79            default: // Do nothing
     80            }
    7081        }
    7182
     83        setText(text);
     84        setToolTipText(text);
     85        setBackgroundReadable(key, model, isSelected, table.hasFocus(), column == TagTableColumnModel.COLUMN_VALUE);
    7286        return this;
    7387    }
  • trunk/src/org/openstreetmap/josm/gui/history/TagTableColumnModel.java

    r10308 r10637  
    1212 */
    1313public class TagTableColumnModel extends DefaultTableColumnModel {
     14    protected static final int COLUMN_KEY = 0;
     15    protected static final int COLUMN_VALUE = 1;
    1416
    1517    /**
Note: See TracChangeset for help on using the changeset viewer.