diff options
Diffstat (limited to 'javax')
21 files changed, 286 insertions, 101 deletions
diff --git a/javax/swing/AbstractButton.java b/javax/swing/AbstractButton.java index d4e35cfa3..348daece1 100644 --- a/javax/swing/AbstractButton.java +++ b/javax/swing/AbstractButton.java @@ -39,10 +39,12 @@ package javax.swing; import gnu.classpath.NotImplementedException; +import java.awt.Component; import java.awt.Graphics; import java.awt.Image; import java.awt.Insets; import java.awt.ItemSelectable; +import java.awt.LayoutManager; import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; @@ -2372,6 +2374,45 @@ public abstract class AbstractButton extends JComponent } /** + * Adds the specified component to this AbstractButton. This overrides the + * default in order to install an {@link OverlayLayout} layout manager + * before adding the component. The layout manager is only installed if + * no other layout manager has been installed before. + * + * @param comp the component to be added + * @param constraints constraints for the layout manager + * @param index the index at which the component is added + * + * @since 1.5 + */ + protected void addImpl(Component comp, Object constraints, int index) + { + // We use a client property here, so that no extra memory is used in + // the common case with no layout manager. + if (getClientProperty("AbstractButton.customLayoutSet") == null) + setLayout(new OverlayLayout(this)); + super.addImpl(comp, constraints, index); + } + + /** + * Sets a layout manager on this AbstractButton. This is overridden in order + * to detect if the application sets a custom layout manager. If no custom + * layout manager is set, {@link #addImpl(Component, Object, int)} installs + * an OverlayLayout before adding a component. + * + * @param layout the layout manager to install + * + * @since 1.5 + */ + public void setLayout(LayoutManager layout) + { + // We use a client property here, so that no extra memory is used in + // the common case with no layout manager. + putClientProperty("AbstractButton.customLayoutSet", Boolean.TRUE); + super.setLayout(layout); + } + + /** * Helper method for * {@link LookAndFeel#installProperty(JComponent, String, Object)}. * diff --git a/javax/swing/ButtonGroup.java b/javax/swing/ButtonGroup.java index 9aeae379e..3d11713cf 100644 --- a/javax/swing/ButtonGroup.java +++ b/javax/swing/ButtonGroup.java @@ -91,8 +91,12 @@ public class ButtonGroup implements Serializable { b.getModel().setGroup(this); if (b.isSelected()) - sel = b.getModel(); - buttons.addElement(b); + { + if (sel == null) + sel = b.getModel(); + else + b.setSelected(false); + } buttons.addElement(b); } /** diff --git a/javax/swing/DefaultDesktopManager.java b/javax/swing/DefaultDesktopManager.java index df2ab6cdb..0304461ad 100644 --- a/javax/swing/DefaultDesktopManager.java +++ b/javax/swing/DefaultDesktopManager.java @@ -124,8 +124,6 @@ public class DefaultDesktopManager implements DesktopManager, Serializable public void closeFrame(JInternalFrame frame) { Container c = frame.getParent(); - frame.doDefaultCloseAction(); - if (c != null) { if (frame.isIcon()) diff --git a/javax/swing/ImageIcon.java b/javax/swing/ImageIcon.java index 7347985eb..cedf4be35 100644 --- a/javax/swing/ImageIcon.java +++ b/javax/swing/ImageIcon.java @@ -288,12 +288,12 @@ public class ImageIcon } /** - * Creates an ImageIcon from the given URL without any description - * set. + * Creates an ImageIcon from the given URL and sets the description + * to the URL String representation. */ public ImageIcon(URL url) { - this(url, null); + this(url, url.toString()); } /** diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java index 68d7d9d1c..ba3712b88 100644 --- a/javax/swing/JComponent.java +++ b/javax/swing/JComponent.java @@ -1764,8 +1764,9 @@ public abstract class JComponent extends Container implements Serializable paintBorder(g2); paintChildren(g2); Rectangle clip = g2.getClipBounds(); - if (clip.x == 0 && clip.y == 0 && clip.width == getWidth() - && clip.height == getHeight()) + if (clip == null + || (clip.x == 0 && clip.y == 0 && clip.width == getWidth() + && clip.height == getHeight())) RepaintManager.currentManager(this).markCompletelyClean(this); } } diff --git a/javax/swing/JLabel.java b/javax/swing/JLabel.java index 65b1e6fcd..a993fb8f3 100644 --- a/javax/swing/JLabel.java +++ b/javax/swing/JLabel.java @@ -38,6 +38,8 @@ exception statement from your version. */ package javax.swing; +import gnu.classpath.NotImplementedException; + import java.awt.Component; import java.awt.Font; import java.awt.Image; @@ -67,15 +69,15 @@ public class JLabel extends JComponent implements Accessible, SwingConstants implements AccessibleText, AccessibleExtendedComponent { /** - * Returns the selected text. This is an empty string since JLabels + * Returns the selected text. This is null since JLabels * are not selectable. * - * @return the selected text + * @return <code>null</code> because JLabels cannot have selected text */ public String getSelectedText() { - // We return "" here since JLabel's text is not selectable. - return ""; + // We return null here since JLabel's text is not selectable. + return null; } /** @@ -85,8 +87,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public int getSelectionStart() { - // TODO: Figure out what should be returned here, because JLabels don't - // allow selection. I guess -1 for now. + // JLabel don't have selected text, so we return -1 here. return -1; } @@ -97,8 +98,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public int getSelectionEnd() { - // TODO: Figure out what should be returned here, because JLabels don't - // allow selection. I guess -1 for now. + // JLabel don't have selected text, so we return -1 here. return -1; } @@ -115,6 +115,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public AttributeSet getCharacterAttribute(int index) { + // FIXME: Return null here for simple labels, and query the HTML + // view for HTML labels. return new SimpleAttributeSet(); } @@ -259,6 +261,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public int getCharCount() { + // FIXME: Query HTML view for HTML labels. return text.length(); } @@ -271,6 +274,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants * @return the bounding box of the character at the specified index */ public Rectangle getCharacterBounds(int index) + throws NotImplementedException { // FIXME: Implement this correctly. return new Rectangle(); @@ -286,6 +290,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants * point */ public int getIndexAtPoint(Point point) + throws NotImplementedException { // FIXME: Implement this correctly. return 0; @@ -339,7 +344,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public JLabel() { - this(null, null, LEADING); + this("", null, LEADING); } /** @@ -350,7 +355,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public JLabel(Icon image) { - this(null, image, CENTER); + this("", image, CENTER); } /** @@ -363,7 +368,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public JLabel(Icon image, int horizontalAlignment) { - this(null, image, horizontalAlignment); + this("", image, horizontalAlignment); } /** @@ -454,7 +459,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ protected String paramString() { - return "JLabel"; + return super.paramString(); } /** diff --git a/javax/swing/JOptionPane.java b/javax/swing/JOptionPane.java index 360e60af7..0bef12b61 100644 --- a/javax/swing/JOptionPane.java +++ b/javax/swing/JOptionPane.java @@ -75,13 +75,14 @@ public class JOptionPane extends JComponent implements Accessible } /** - * DOCUMENT ME! + * Returns the accessible role of this object, which is always + * {@link AccessibleRole#OPTION_PANE}. * - * @return DOCUMENT ME! + * @return the accessible role of this object */ public AccessibleRole getAccessibleRole() { - return null; + return AccessibleRole.OPTION_PANE; } } diff --git a/javax/swing/JTable.java b/javax/swing/JTable.java index 3463ac26f..1298f128d 100644 --- a/javax/swing/JTable.java +++ b/javax/swing/JTable.java @@ -1246,8 +1246,12 @@ public class JTable { Icon iconValue = (Icon) value; setIcon(iconValue); - setText(""); } + else + { + setIcon(null); + } + setText(""); return this; } } @@ -1893,8 +1897,13 @@ public class JTable int x0 = 0; - int idx0 = event.getFirstIndex(); - int idxn = event.getLastIndex(); + // We must limit the indices to the bounds of the JTable's model, because + // we might get values of -1 or greater then columnCount in the case + // when columns get removed. + int idx0 = Math.max(0, Math.min(getColumnCount() - 1, + event.getFirstIndex())); + int idxn = Math.max(0, Math.min(getColumnCount() - 1, + event.getLastIndex())); int i; for (i = 0; i < idx0; i++) @@ -1955,9 +1964,33 @@ public class JTable // affect the size parameters of the JTable. Otherwise we only need // to perform a repaint to update the view. if (event == null || event.getType() == TableModelEvent.INSERT) - revalidate(); + { + // Sync selection model with data model. + if (event != null) + { + int first = event.getFirstRow(); + if (first < 0) + first = 0; + int last = event.getLastRow(); + if (last < 0) + last = getRowCount() - 1; + selectionModel.insertIndexInterval(first, last - first + 1, true); + } + revalidate(); + } if (event == null || event.getType() == TableModelEvent.DELETE) { + // Sync selection model with data model. + if (event != null) + { + int first = event.getFirstRow(); + if (first < 0) + first = 0; + int last = event.getLastRow(); + if (last < 0) + last = getRowCount() - 1; + selectionModel.removeIndexInterval(first, last); + } if (dataModel.getRowCount() == 0) clearSelection(); revalidate(); @@ -3562,8 +3595,7 @@ public class JTable } /** - * Set value for the cell at the given position. If the cell is not - * editable, this method returns without action. The modified cell is + * Set value for the cell at the given position. The modified cell is * repainted. * * @param value the value to set @@ -3572,8 +3604,6 @@ public class JTable */ public void setValueAt(Object value, int row, int column) { - if (!isCellEditable(row, column)) - return; dataModel.setValueAt(value, row, convertColumnIndexToModel(column)); repaint(getCellRect(row, column, true)); @@ -3721,6 +3751,13 @@ public class JTable private void moveToCellBeingEdited(Component component) { Rectangle r = getCellRect(editingRow, editingColumn, true); + // Adjust bounding box of the editing component, so that it lies + // 'above' the grid on all edges, not only right and bottom. + // The table grid is painted only at the right and bottom edge of a cell. + r.x -= 1; + r.y -= 1; + r.width += 1; + r.height += 1; component.setBounds(r); } diff --git a/javax/swing/plaf/basic/BasicButtonListener.java b/javax/swing/plaf/basic/BasicButtonListener.java index 1fca69451..89e99a29a 100644 --- a/javax/swing/plaf/basic/BasicButtonListener.java +++ b/javax/swing/plaf/basic/BasicButtonListener.java @@ -52,6 +52,7 @@ import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JComponent; +import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -204,14 +205,12 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, { AbstractButton button = (AbstractButton) e.getSource(); ButtonModel model = button.getModel(); - if (button.isRolloverEnabled()) + if (button.isRolloverEnabled() + && ! SwingUtilities.isLeftMouseButton(e)) model.setRollover(true); - - if (model.isPressed() - && (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0) + + if (model.isPressed()) model.setArmed(true); - else - model.setArmed(false); } } diff --git a/javax/swing/plaf/basic/BasicInternalFrameUI.java b/javax/swing/plaf/basic/BasicInternalFrameUI.java index 0a330e776..7ec3aa074 100644 --- a/javax/swing/plaf/basic/BasicInternalFrameUI.java +++ b/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -1205,6 +1205,15 @@ public class BasicInternalFrameUI extends InternalFrameUI frame.setLayout(internalFrameLayout); LookAndFeel.installBorder(frame, "InternalFrame.border"); frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon")); + + // Let the content pane inherit the background color from its + // frame by setting the background to null. + Component contentPane = frame.getContentPane(); + if (contentPane != null + && contentPane.getBackground() instanceof UIResource) + { + contentPane.setBackground(null); + } } /** diff --git a/javax/swing/plaf/basic/BasicRadioButtonUI.java b/javax/swing/plaf/basic/BasicRadioButtonUI.java index 66e538037..a66fa28e6 100644 --- a/javax/swing/plaf/basic/BasicRadioButtonUI.java +++ b/javax/swing/plaf/basic/BasicRadioButtonUI.java @@ -45,6 +45,7 @@ import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.AbstractButton; +import javax.swing.ButtonModel; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.SwingUtilities; @@ -142,14 +143,15 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI g.setFont(f); + ButtonModel m = b.getModel(); Icon currentIcon = null; - if (b.isSelected() && b.isEnabled()) + if (m.isSelected() && m.isEnabled()) currentIcon = b.getSelectedIcon(); - else if (!b.isSelected() && b.isEnabled()) + else if (! m.isSelected() && m.isEnabled()) currentIcon = b.getIcon(); - else if (b.isSelected() && !b.isEnabled()) + else if (m.isSelected() && ! m.isEnabled()) currentIcon = b.getDisabledSelectedIcon(); - else // (!b.isSelected() && !b.isEnabled()) + else // (!m.isSelected() && ! m.isEnabled()) currentIcon = b.getDisabledIcon(); SwingUtilities.calculateInnerArea(b, vr); @@ -166,7 +168,7 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI if (text != null) paintText(g, b, tr, text); // TODO: Figure out what is the size parameter? - if (b.hasFocus() && b.isFocusPainted() && b.isEnabled()) + if (b.hasFocus() && b.isFocusPainted() && m.isEnabled()) paintFocus(g, tr, null); } diff --git a/javax/swing/plaf/basic/BasicTableHeaderUI.java b/javax/swing/plaf/basic/BasicTableHeaderUI.java index fbef6e69f..cfbebda21 100644 --- a/javax/swing/plaf/basic/BasicTableHeaderUI.java +++ b/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -99,6 +99,11 @@ public class BasicTableHeaderUI extends TableHeaderUI * The header cell border. */ private Border cellBorder; + + /** + * Original mouse cursor prior to resizing. + */ + private Cursor originalCursor; /** * If not null, one of the columns is currently being dragged. @@ -245,6 +250,7 @@ public class BasicTableHeaderUI extends TableHeaderUI if (onBoundary) { + originalCursor = header.getCursor(); if (p < x) header.setCursor(Cursor.getPredefinedCursor (Cursor.W_RESIZE_CURSOR)); @@ -254,7 +260,7 @@ public class BasicTableHeaderUI extends TableHeaderUI } else { - header.setCursor(Cursor.getDefaultCursor()); + header.setCursor(originalCursor); header.setResizingColumn(null); } @@ -345,7 +351,7 @@ public class BasicTableHeaderUI extends TableHeaderUI showingResizeCursor = false; if (timer != null) timer.stop(); - header.setCursor(Cursor.getDefaultCursor()); + header.setCursor(originalCursor); } /** diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java index 0711ce385..ef491cbf1 100644 --- a/javax/swing/plaf/basic/BasicTableUI.java +++ b/javax/swing/plaf/basic/BasicTableUI.java @@ -1245,17 +1245,19 @@ public class BasicTableUI extends TableUI int rn = table.rowAtPoint(p2); if (rn == -1) rn = table.getRowCount() - 1; - + + int columnMargin = table.getColumnModel().getColumnMargin(); + int rowMargin = table.getRowMargin(); + TableColumnModel cmodel = table.getColumnModel(); int [] widths = new int[cn+1]; for (int i = c0; i <=cn ; i++) { - widths[i] = cmodel.getColumn(i).getWidth(); + widths[i] = cmodel.getColumn(i).getWidth() - columnMargin; } Rectangle bounds = table.getCellRect(r0, c0, false); - bounds.height = table.getRowHeight()+table.getRowMargin(); - + // The left boundary of the area being repainted. int left = bounds.x; @@ -1265,9 +1267,6 @@ public class BasicTableUI extends TableUI // The bottom boundary of the area being repainted. int bottom; - // The cell height. - int height = bounds.height; - // paint the cell contents Color grid = table.getGridColor(); for (int r = r0; r <= rn; ++r) @@ -1276,25 +1275,28 @@ public class BasicTableUI extends TableUI { bounds.width = widths[c]; paintCell(gfx, r, c, bounds, table.getCellRenderer(r, c)); - bounds.x += widths[c]; + bounds.x += widths[c] + columnMargin; } - bounds.y += height; bounds.x = left; + bounds.y += table.getRowHeight(r) + rowMargin; + // Update row height for tables with custom heights. + bounds.height = table.getRowHeight(r + 1); } - bottom = bounds.y; + bottom = bounds.y - rowMargin; // paint vertical grid lines if (grid != null && table.getShowVerticalLines()) { Color save = gfx.getColor(); gfx.setColor(grid); - int x = left; - + int x = left - columnMargin; for (int c = c0; c <= cn; ++c) { + // The vertical grid is draw right from the cells, so we + // add before drawing. + x += widths[c] + columnMargin; gfx.drawLine(x, top, x, bottom); - x += widths[c]; } gfx.setColor(save); } @@ -1304,11 +1306,13 @@ public class BasicTableUI extends TableUI { Color save = gfx.getColor(); gfx.setColor(grid); - int y = top; + int y = top - rowMargin; for (int r = r0; r <= rn; ++r) { + // The horizontal grid is draw below the cells, so we + // add before drawing. + y += table.getRowHeight(r) + rowMargin; gfx.drawLine(left, y, p2.x, y); - y += height; } gfx.setColor(save); } diff --git a/javax/swing/plaf/basic/BasicTreeUI.java b/javax/swing/plaf/basic/BasicTreeUI.java index fb09ac998..48ad1b93d 100644 --- a/javax/swing/plaf/basic/BasicTreeUI.java +++ b/javax/swing/plaf/basic/BasicTreeUI.java @@ -1376,6 +1376,12 @@ public class BasicTreeUI public void paint(Graphics g, JComponent c) { JTree tree = (JTree) c; + + int rows = treeState.getRowCount(); + + if (rows == 0) + // There is nothing to do if the tree is empty. + return; Rectangle clip = g.getClipBounds(); @@ -1387,9 +1393,7 @@ public class BasicTreeUI int endIndex = tree.getClosestRowForLocation(clip.x + clip.width, clip.y + clip.height); - // Also paint dashes to the invisible nodes below: - int rows = treeState.getRowCount(); - + // Also paint dashes to the invisible nodes below. // These should be painted first, otherwise they may cover // the control icons. if (endIndex < rows) diff --git a/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java index 534f0ca34..f74828e56 100644 --- a/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java +++ b/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -93,7 +93,11 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane public void propertyChange(PropertyChangeEvent e) { String propName = e.getPropertyName(); - if (propName.equals("JInternalFrame.isPalette")) + if (e.getPropertyName().equals(JInternalFrame.FRAME_ICON_PROPERTY)) + { + title.setIcon( frame.getFrameIcon() ); + } + else if (propName.equals("JInternalFrame.isPalette")) { if (e.getNewValue().equals(Boolean.TRUE)) setPalette(true); @@ -262,7 +266,7 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight"); paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon"); minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16); - + title = new JLabel(frame.getTitle(), MetalIconFactory.getInternalFrameDefaultMenuIcon(), SwingConstants.LEFT); @@ -383,8 +387,8 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane paintPalette(g); else { - paintTitleBackground(g); - paintChildren(g); + paintTitleBackground(g); + paintChildren(g); Dimension d = getSize(); if (frame.isSelected()) g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); diff --git a/javax/swing/plaf/metal/MetalLookAndFeel.java b/javax/swing/plaf/metal/MetalLookAndFeel.java index 0011b1c17..d7cd9ab24 100644 --- a/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -1204,7 +1204,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel "Table.focusCellForeground", getControlTextColor(), "Table.foreground", getControlTextColor(), "Table.focusCellHighlightBorder", - new BorderUIResource.LineBorderUIResource(getControlShadow()), + new BorderUIResource.LineBorderUIResource(getFocusColor()), "Table.focusCellBackground", getWindowBackground(), "Table.gridColor", getControlDarkShadow(), "Table.selectionBackground", new ColorUIResource(204, 204, 255), diff --git a/javax/swing/plaf/metal/OceanTheme.java b/javax/swing/plaf/metal/OceanTheme.java index cfba4b5ff..9d76ff7e8 100644 --- a/javax/swing/plaf/metal/OceanTheme.java +++ b/javax/swing/plaf/metal/OceanTheme.java @@ -43,6 +43,7 @@ import java.util.Arrays; import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; +import javax.swing.plaf.BorderUIResource.LineBorderUIResource; /** * A modern theme for the Metal Look & Feel. @@ -264,6 +265,10 @@ public class OceanTheme extends DefaultMetalTheme defaults.put("ToolBar.borderColor", c3); defaults.put("Tree.selectionBorderColor", PRIMARY1); + // Borders. + defaults.put("Table.focusCellHighlightBorder", + new LineBorderUIResource(getPrimary1())); + // Insets. defaults.put("TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3)); defaults.put("TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6)); diff --git a/javax/swing/table/DefaultTableCellRenderer.java b/javax/swing/table/DefaultTableCellRenderer.java index f56fd4f0e..a9bbe9a78 100644 --- a/javax/swing/table/DefaultTableCellRenderer.java +++ b/javax/swing/table/DefaultTableCellRenderer.java @@ -58,7 +58,7 @@ public class DefaultTableCellRenderer extends JLabel { static final long serialVersionUID = 7878911414715528324L; - protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); + protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); public static class UIResource extends DefaultTableCellRenderer implements javax.swing.plaf.UIResource @@ -163,17 +163,17 @@ public class DefaultTableCellRenderer extends JLabel super.setForeground(table.getForeground()); } + Border b = null; if (hasFocus) { - setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); - if (table.isCellEditable(row, column)) - { - super.setBackground(UIManager.getColor("Table.focusCellBackground")); - super.setForeground(UIManager.getColor("Table.focusCellForeground")); - } + if (isSelected) + b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); + if (b == null) + b = UIManager.getBorder("Table.focusCellHighlightBorder"); } else - setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); + b = noFocusBorder; + setBorder(b); setFont(table.getFont()); diff --git a/javax/swing/table/DefaultTableModel.java b/javax/swing/table/DefaultTableModel.java index c281caa07..09be2f752 100644 --- a/javax/swing/table/DefaultTableModel.java +++ b/javax/swing/table/DefaultTableModel.java @@ -294,12 +294,7 @@ public class DefaultTableModel extends AbstractTableModel else { int rowsToAdd = rowCount - existingRowCount; - for (int i = 0; i < rowsToAdd; i++) - { - Vector tmp = new Vector(); - tmp.setSize(columnIdentifiers.size()); - dataVector.add(tmp); - } + addExtraRows(rowsToAdd, columnIdentifiers.size()); fireTableRowsInserted(existingRowCount,rowCount-1); } } @@ -366,12 +361,7 @@ public class DefaultTableModel extends AbstractTableModel if (columnData.length > dataVector.size()) { int rowsToAdd = columnData.length - dataVector.size(); - for (int i = 0; i < rowsToAdd; i++) - { - Vector tmp = new Vector(); - tmp.setSize(columnIdentifiers.size()); - dataVector.add(tmp); - } + addExtraRows(rowsToAdd, columnIdentifiers.size()); } else if (columnData.length < dataVector.size()) { @@ -502,7 +492,8 @@ public class DefaultTableModel extends AbstractTableModel else { if (column < getColumnCount()) - { + { + checkSize(); Object id = columnIdentifiers.get(column); if (id != null) result = id.toString(); @@ -588,4 +579,41 @@ public class DefaultTableModel extends AbstractTableModel vector.add(convertToVector(data[i])); return vector; } + + /** + * This method adds some rows to <code>dataVector</code>. + * + * @param rowsToAdd number of rows to add + * @param nbColumns size of the added rows + */ + private void addExtraRows(int rowsToAdd, int nbColumns) + { + for (int i = 0; i < rowsToAdd; i++) + { + Vector tmp = new Vector(); + tmp.setSize(columnIdentifiers.size()); + dataVector.add(tmp); + } + } + + /** + * Checks the real columns/rows sizes against the ones returned by + * <code>getColumnCount()</code> and <code>getRowCount()</code>. + * If the supposed one are bigger, then we grow <code>columIdentifiers</code> + * and <code>dataVector</code> to their expected size. + */ + private void checkSize() + { + int columnCount = getColumnCount(); + int rowCount = getRowCount(); + + if (columnCount > columnIdentifiers.size()) + columnIdentifiers.setSize(columnCount); + + if (rowCount > dataVector.size()) + { + int rowsToAdd = rowCount - dataVector.size(); + addExtraRows(rowsToAdd, columnCount); + } + } } diff --git a/javax/swing/text/AbstractDocument.java b/javax/swing/text/AbstractDocument.java index bb065044d..801a0cdb4 100644 --- a/javax/swing/text/AbstractDocument.java +++ b/javax/swing/text/AbstractDocument.java @@ -543,6 +543,10 @@ public abstract class AbstractDocument implements Document, Serializable * * <p>If a {@link DocumentFilter} is installed in this document, the * corresponding method of the filter object is called.</p> + * + * <p>The method has no effect when <code>text</code> is <code>null</code> + * or has a length of zero.</p> + * * * @param offset the location at which the string should be inserted * @param text the content to be inserted @@ -554,10 +558,14 @@ public abstract class AbstractDocument implements Document, Serializable public void insertString(int offset, String text, AttributeSet attributes) throws BadLocationException { - if (documentFilter != null) - documentFilter.insertString(getBypass(), offset, text, attributes); - else + // Bail out if we have a bogus insertion (Behavior observed in RI). + if (text == null || text.length() == 0) + return; + + if (documentFilter == null) insertStringImpl(offset, text, attributes); + else + documentFilter.insertString(getBypass(), offset, text, attributes); } void insertStringImpl(int offset, String text, AttributeSet attributes) @@ -706,8 +714,14 @@ public abstract class AbstractDocument implements Document, Serializable * Removes a piece of content from this <code>Document</code>. * * <p>If a {@link DocumentFilter} is installed in this document, the - * corresponding method of the filter object is called.</p> - * + * corresponding method of the filter object is called. The + * <code>DocumentFilter</code> is called even if <code>length</code> + * is zero. This is different from {@link #replace}.</p> + * + * <p>Note: When <code>length</code> is zero or below the call is not + * forwarded to the underlying {@link AbstractDocument.Content} instance + * of this document and no exception is thrown.</p> + * * @param offset the start offset of the fragment to be removed * @param length the length of the fragment to be removed * @@ -717,14 +731,18 @@ public abstract class AbstractDocument implements Document, Serializable */ public void remove(int offset, int length) throws BadLocationException { - if (documentFilter != null) - documentFilter.remove(getBypass(), offset, length); - else + if (documentFilter == null) removeImpl(offset, length); + else + documentFilter.remove(getBypass(), offset, length); } void removeImpl(int offset, int length) throws BadLocationException { + // Prevent some unneccessary method invocation (observed in the RI). + if (length <= 0) + return; + DefaultDocumentEvent event = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.REMOVE); @@ -752,6 +770,10 @@ public abstract class AbstractDocument implements Document, Serializable * * <p>If a {@link DocumentFilter} is installed in this document, the * corresponding method of the filter object is called.</p> + * + * <p>The method has no effect if <code>length</code> is zero (and + * only zero) and, at the same time, <code>text</code> is + * <code>null</code> or has zero length.</p> * * @param offset the start offset of the fragment to be removed * @param length the length of the fragment to be removed @@ -768,10 +790,25 @@ public abstract class AbstractDocument implements Document, Serializable AttributeSet attributes) throws BadLocationException { - if (documentFilter != null) - documentFilter.replace(getBypass(), offset, length, text, attributes); + // Bail out if we have a bogus replacement (Behavior observed in RI). + if (length == 0 + && (text == null || text.length() == 0)) + return; + + if (documentFilter == null) + { + // It is important to call the methods which again do the checks + // of the arguments and the DocumentFilter because subclasses may + // have overridden these methods and provide crucial behavior + // which would be skipped if we call the non-checking variants. + // An example for this is PlainDocument where insertString can + // provide a filtering of newlines. + remove(offset, length); + insertString(offset, text, attributes); + } else - replaceImpl(offset, length, text, attributes); + documentFilter.replace(getBypass(), offset, length, text, attributes); + } void replaceImpl(int offset, int length, String text, diff --git a/javax/swing/tree/DefaultTreeSelectionModel.java b/javax/swing/tree/DefaultTreeSelectionModel.java index e38850af8..1a761d6c7 100644 --- a/javax/swing/tree/DefaultTreeSelectionModel.java +++ b/javax/swing/tree/DefaultTreeSelectionModel.java @@ -121,7 +121,7 @@ public class DefaultTreeSelectionModel /** * The row of the last added path according to the RowMapper. */ - protected int leadRow; + protected int leadRow = -1; /** * Constructs a new DefaultTreeSelectionModel. |