Ignore:
Timestamp:
2011-05-04T07:09:56+02:00 (13 years ago)
Author:
jttt
Message:

Fix #6301 Check for null mandatory in TableCellRenderer.getTableCellRendererComponent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r4041 r4072  
    8484
    8585    final protected boolean isMapPaint;
    86    
     86
    8787    protected JTable tblActiveSources;
    8888    protected ActiveSourcesModel activeSourcesModel;
     
    113113            // some kind of hack to prevent the table from scrolling slightly to the
    114114            // right when clicking on the text
     115            @Override
    115116            public void scrollRectToVisible(Rectangle aRect) {
    116117                super.scrollRectToVisible(new Rectangle(0, aRect.y, aRect.width, aRect.height));
     
    142143        });
    143144        activeSourcesModel.setActiveSources(getInitialSourcesList());
    144        
     145
    145146        final EditActiveSourceAction editActiveSourceAction = new EditActiveSourceAction();
    146147        tblActiveSources.getSelectionModel().addListSelectionListener(editActiveSourceAction);
     
    368369     */
    369370    protected enum I18nString { AVAILABLE_SOURCES, ACTIVE_SOURCES, NEW_SOURCE_ENTRY_TOOLTIP, NEW_SOURCE_ENTRY,
    370             REMOVE_SOURCE_TOOLTIP, EDIT_SOURCE_TOOLTIP, ACTIVATE_TOOLTIP, RELOAD_ALL_AVAILABLE,
    371             LOADING_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC,
    372             ILLEGAL_FORMAT_OF_ENTRY }
     371        REMOVE_SOURCE_TOOLTIP, EDIT_SOURCE_TOOLTIP, ACTIVATE_TOOLTIP, RELOAD_ALL_AVAILABLE,
     372        LOADING_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC,
     373        ILLEGAL_FORMAT_OF_ENTRY }
    373374
    374375    /**
     
    378379    private static void adjustColumnWidth(JTable tbl, int col) {
    379380        int maxwidth = 0;
    380                 for (int row=0; row<tbl.getRowCount(); row++) {
     381        for (int row=0; row<tbl.getRowCount(); row++) {
    381382            TableCellRenderer tcr = tbl.getCellRenderer(row, col);
    382                 Object val = tbl.getValueAt(row, col);
    383                 Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col);
    384                 maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);
    385                 }
    386                 tbl.getColumnModel().getColumn(col).setPreferredWidth(maxwidth);
     383            Object val = tbl.getValueAt(row, col);
     384            Component comp = tcr.getTableCellRendererComponent(tbl, val, false, false, row, col);
     385            maxwidth = Math.max(comp.getPreferredSize().width, maxwidth);
     386        }
     387        tbl.getColumnModel().getColumn(col).setPreferredWidth(maxwidth);
    387388    }
    388389
     
    587588            if (sel.length == 0)
    588589                return false;
    589             if (i < 0) { // Up
     590            if (i < 0)
    590591                return sel[0] >= -i;
    591             } else if (i > 0) { // Down
    592                 return sel[sel.length-1] <= getRowCount()-1 - i;
    593             } else
    594                 return true;
     592                else if (i > 0)
     593                    return sel[sel.length-1] <= getRowCount()-1 - i;
     594                else
     595                    return true;
    595596        }
    596597
     
    735736        }
    736737
     738        @Override
    737739        public String getTitle() {
    738740            return tfTitle.getText();
     
    12111213        }
    12121214    }
    1213    
     1215
    12141216    class SourceEntryTableCellRenderer extends DefaultTableCellRenderer {
    12151217        @Override
    12161218        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     1219            if (value == null)
     1220                return this;
    12171221            SourceEntry se = (SourceEntry) value;
    12181222            JLabel label = (JLabel)super.getTableCellRendererComponent(table,
     
    14901494        public Collection<? extends SourceEntry> readNewFormat() {
    14911495            List<SourceEntry> entries = readNewFormatImpl();
    1492             if (entries == null) {
     1496            if (entries == null)
    14931497                return getDefault();
    1494             }
    14951498            return entries;
    14961499        }
     
    15001503            Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null);
    15011504            if (mappaintSrc == null || mappaintSrc.isEmpty()) {
    1502                 if (Main.pref.getBoolean(pref + "._empty_", false)) {
     1505                if (Main.pref.getBoolean(pref + "._empty_", false))
    15031506                    return Collections.<SourceEntry>emptyList();
    1504                 }
    15051507                return null;
    15061508            }
Note: See TracChangeset for help on using the changeset viewer.