Changeset 10070 in josm


Ignore:
Timestamp:
2016-03-28T14:45:45+02:00 (4 years ago)
Author:
Don-vip
Message:

refactor duplicated code

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r9497 r10070  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Container;
    76import java.awt.Dimension;
    87import java.awt.GraphicsEnvironment;
     
    1716import javax.swing.JPopupMenu;
    1817import javax.swing.JTable;
    19 import javax.swing.JViewport;
    2018import javax.swing.ListSelectionModel;
    2119import javax.swing.SwingUtilities;
     
    9593    @Override
    9694    public Dimension getPreferredSize() {
    97         Container c = getParent();
    98         while (c != null && !(c instanceof JViewport)) {
    99             c = c.getParent();
    100         }
    101         if (c != null) {
    102             Dimension d = super.getPreferredSize();
    103             d.width = c.getSize().width;
    104             return d;
    105         }
    106         return super.getPreferredSize();
     95        return getPreferredFullWidthSize();
    10796    }
    10897
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r9983 r10070  
    66
    77import java.awt.Component;
    8 import java.awt.Container;
    98import java.awt.Dimension;
    109import java.awt.KeyboardFocusManager;
     
    2524import javax.swing.JComponent;
    2625import javax.swing.JTable;
    27 import javax.swing.JViewport;
    2826import javax.swing.KeyStroke;
    2927import javax.swing.ListSelectionModel;
     
    4341import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    4442import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
     43import org.openstreetmap.josm.gui.widgets.JosmTable;
    4544import org.openstreetmap.josm.tools.ImageProvider;
    4645import org.openstreetmap.josm.tools.TextTagParser;
     
    5150 * @since 1762
    5251 */
    53 public class TagTable extends JTable  {
     52public class TagTable extends JosmTable  {
    5453    /** the table cell editor used by this table */
    5554    private TagCellEditor editor;
     
    415414    @Override
    416415    public Dimension getPreferredSize() {
    417         Container c = getParent();
    418         while (c != null && !(c instanceof JViewport)) {
    419             c = c.getParent();
    420         }
    421         if (c != null) {
    422             Dimension d = super.getPreferredSize();
    423             d.width = c.getSize().width;
    424             return d;
    425         }
    426         return super.getPreferredSize();
    427     }
    428 
    429     @Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
    430             int condition, boolean pressed) {
     416        return getPreferredFullWidthSize();
     417    }
     418
     419    @Override
     420    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    431421
    432422        // handle delete key
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmTable.java

    r9665 r10070  
    22package org.openstreetmap.josm.gui.widgets;
    33
     4import java.awt.Container;
     5import java.awt.Dimension;
    46import java.awt.KeyboardFocusManager;
    57import java.awt.event.ActionEvent;
     
    911import javax.swing.JComponent;
    1012import javax.swing.JTable;
     13import javax.swing.JViewport;
    1114import javax.swing.KeyStroke;
    1215import javax.swing.ListSelectionModel;
     
    105108        }
    106109    }
     110
     111    protected Dimension getPreferredFullWidthSize() {
     112        Container c = getParent();
     113        while (c != null && !(c instanceof JViewport)) {
     114            c = c.getParent();
     115        }
     116        if (c != null) {
     117            Dimension d = super.getPreferredSize();
     118            d.width = c.getSize().width;
     119            return d;
     120        }
     121        return super.getPreferredSize();
     122    }
    107123}
Note: See TracChangeset for help on using the changeset viewer.