Index: make/properties.xml =================================================================== --- make/properties.xml (revision 588163) +++ make/properties.xml (working copy) @@ -265,7 +265,7 @@ - + Index: modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java =================================================================== --- modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java (revision 588163) +++ modules/awt/src/main/java/common/org/apache/harmony/awt/text/TextUtils.java (working copy) @@ -51,7 +51,6 @@ import java.util.Calendar; import java.util.Date; import javax.swing.BoundedRangeModel; -import javax.swing.JComponent; import javax.swing.JEditorPane; import javax.swing.JFormattedTextField; import javax.swing.SwingConstants; @@ -996,23 +995,6 @@ public class TextUtils { return retVal; } - public static Rectangle getEditorRect(final JComponent component) { - if (component == null) { - return null; - } - Insets insets = component.getInsets(); - int left = 0; - int top = 0; - if (insets != null) { - left = insets.left; - top = insets.top; - } - Dimension r = component.getSize(); - return r.width == 0 || r.height == 0 ? null - : new Rectangle(left, top, r.width - getHrzInsets(insets), - r.height - getVrtInsets(insets)); - } - public static int getHrzInsets(final Insets insets) { return (insets != null) ? insets.left + insets.right : 0; } Index: modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/TextUtils.java =================================================================== --- modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/TextUtils.java (revision 0) +++ modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/TextUtils.java (revision 0) @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.x.swing.text; + +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Rectangle; + +import javax.swing.text.JTextComponent; + +public class TextUtils { + + /** + * Returns, component getSize, excluding insets. + */ + public static Rectangle getEditorRect(JTextComponent component) { + if (component == null) { + return null; + } + Insets insets = component.getInsets(); + int left = 0; + int top = 0; + if (insets != null) { + left = insets.left; + top = insets.top; + } + Dimension r = component.getSize(); + return r.width == 0 || r.height == 0 ? null : new Rectangle(left, top, + r.width + - org.apache.harmony.awt.text.TextUtils + .getHrzInsets(insets), r.height + - org.apache.harmony.awt.text.TextUtils + .getVrtInsets(insets)); + } +} Property changes on: modules/swing/src/main/java/common/org/apache/harmony/x/swing/text/TextUtils.java ___________________________________________________________________ Name: svn:executable + * Index: modules/swing/src/main/java/common/javax/swing/text/DefaultHighlighter.java =================================================================== --- modules/swing/src/main/java/common/javax/swing/text/DefaultHighlighter.java (revision 588163) +++ modules/swing/src/main/java/common/javax/swing/text/DefaultHighlighter.java (working copy) @@ -25,19 +25,17 @@ import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; import java.util.ArrayList; + import javax.swing.plaf.TextUI; import org.apache.harmony.awt.text.TextKit; import org.apache.harmony.awt.text.TextUtils; - import org.apache.harmony.x.swing.internal.nls.Messages; - - public class DefaultHighlighter extends LayeredHighlighter { // This vector contains all highlights - private final HighlightList highlights = new HighlightList();; + private final ArrayList highlights = new ArrayList(); // Defines paint procedure private boolean drawsLayeredHighlights; @@ -48,21 +46,6 @@ public class DefaultHighlighter extends private TextKit textKit; /** - * Provides more convinient interface for DefaultHighlighter - */ - private class HighlightList extends ArrayList { - - public HighlightImpl getElem(final Object obj) { - int index = indexOf(obj); - return index >= 0 ? (HighlightImpl)get(index) : null; - } - - public HighlightImpl getElem(final int index) { - return (HighlightImpl)get(index); - } - } - - /** * Stores all Highlights information. * */ @@ -103,8 +86,7 @@ public class DefaultHighlighter extends /** * Changes highlight. Changes startPosition, endPosition, bounds. */ - public void changeHighlight(final Position start, - final Position end) { + public void changeHighlight(final Position start, final Position end) { startPosition = start; endPosition = end; } @@ -135,8 +117,7 @@ public class DefaultHighlighter extends } } - public static class DefaultHighlightPainter extends - LayerPainter { + public static class DefaultHighlightPainter extends LayerPainter { private final Color color; public DefaultHighlightPainter(final Color c) { @@ -185,25 +166,22 @@ public class DefaultHighlighter extends g.setColor(getRealColor(jtc)); //It need to add 1 to width and height as that requires fillRect if (isLineGap) { - g.fillRect(shapeBounds.x, - startRectMaxY, - shapeBounds.width + 1, + g.fillRect(shapeBounds.x, startRectMaxY, shapeBounds.width + 1, endRect.y - startRectMaxY + 1); } if (isDifferentLine) { - g.fillRect(startRect.x, - startRect.y, - shapeBounds.width - startRect.x + 1 + shapeBounds.x, + g + .fillRect(startRect.x, startRect.y, shapeBounds.width + - startRect.x + 1 + shapeBounds.x, startRect.height + 1); - g.fillRect(shapeBounds.x, endRect.y, - endRect.x - shapeBounds.x + 1, - endRect.height + 1); + g.fillRect(shapeBounds.x, endRect.y, endRect.x - shapeBounds.x + + 1, endRect.height + 1); } else { - g.fillRect(Math.min(startRect.x, endRect.x), - startRect.y, - Math.abs(endRect.x - startRect.x + 1), - startRect.height + 1); + g + .fillRect(Math.min(startRect.x, endRect.x), + startRect.y, Math.abs(endRect.x - startRect.x + + 1), startRect.height + 1); } } @@ -217,11 +195,10 @@ public class DefaultHighlighter extends * drawsLayered of the current Highlight equals true. */ public Shape paintLayer(final Graphics g, final int start, - final int end, - final Shape shape, final JTextComponent jtc, + final int end, final Shape shape, final JTextComponent jtc, final View view) { - return TextUtils.paintLayer(g, start, end, shape, getRealColor(jtc), - view, true); + return TextUtils.paintLayer(g, start, end, shape, + getRealColor(jtc), view, true); } private Color getRealColor(final JTextComponent c) { @@ -232,8 +209,8 @@ public class DefaultHighlighter extends /** * DefaultHighlighter.DefaultHighlighterPainter with color equal to null */ - public static final LayerPainter DefaultPainter = - new DefaultHighlightPainter(null); + public static final LayerPainter DefaultPainter = new DefaultHighlightPainter( + null); /** * Calls setDrawLayeredHighlights(true). Initializes internal vector @@ -244,22 +221,25 @@ public class DefaultHighlighter extends } public Object addHighlight(final int start, final int end, - final Highlighter.HighlightPainter pnt) - throws BadLocationException { + final Highlighter.HighlightPainter pnt) throws BadLocationException { checkBoundaries(start, end); - Highlight h = new HighlightImpl(createPosition(start), + HighlightImpl h = new HighlightImpl(createPosition(start), createPosition(end), pnt); highlights.add(h); repaintComponent(getBoundsByOffsets(start, end)); return h; } - public void changeHighlight(final Object obj, final int start, - final int end) + private HighlightImpl updateHighlight(Object obj) { + int index = highlights.indexOf(obj); + return index >= 0 ? (HighlightImpl) highlights.get(index) : null; + } + + public void changeHighlight(final Object obj, final int start, final int end) throws BadLocationException { checkBoundaries(start, end); - HighlightImpl h = highlights.getElem(obj); + HighlightImpl h = updateHighlight(obj); if (h == null) { return; } @@ -296,9 +276,10 @@ public class DefaultHighlighter extends */ public void paint(final Graphics g) { - Rectangle r = TextUtils.getEditorRect(component); + Rectangle r = org.apache.harmony.x.swing.text.TextUtils + .getEditorRect(component); for (int i = 0; i < highlights.size(); i++) { - HighlightImpl hElem = highlights.getElem(i); + HighlightImpl hElem = highlights.get(i); int start = hElem.getStartOffset(); int end = hElem.getEndOffset(); if (hElem.needSimplePaint()) { @@ -316,25 +297,23 @@ public class DefaultHighlighter extends * */ public void paintLayeredHighlights(final Graphics g, final int p0, - final int p1, final Shape viewBounds, - final JTextComponent editor, + final int p1, final Shape viewBounds, final JTextComponent editor, final View view) { Document doc = editor.getDocument(); int length = doc.getLength(); for (int i = highlights.size() - 1; i >= 0; i--) { - HighlightImpl hElem = highlights.getElem(i); + HighlightImpl hElem = highlights.get(i); int start = hElem.getStartOffset(); int end = hElem.getEndOffset(); - if (hElem.needSimplePaint() - || end > length || start > p1 || end < p0) { + if (hElem.needSimplePaint() || end > length || start > p1 + || end < p0) { continue; } - ((LayerPainter)(hElem.getPainter())) - .paintLayer(g, Math.max(p0, start), Math.min(p1, end), - viewBounds, editor, view); + ((LayerPainter) (hElem.getPainter())).paintLayer(g, Math.max(p0, + start), Math.min(p1, end), viewBounds, editor, view); } } @@ -344,7 +323,7 @@ public class DefaultHighlighter extends */ public void removeAllHighlights() { while (!highlights.isEmpty()) { - HighlightImpl hElem = highlights.getElem(0); + HighlightImpl hElem = highlights.get(0); Rectangle highlightBounds = getBoundsByHighlight(hElem); highlights.remove(0); repaintComponent(highlightBounds); @@ -357,7 +336,7 @@ public class DefaultHighlighter extends * */ public void removeHighlight(final Object obj) { - Highlight highlight = highlights.getElem(obj); + Highlight highlight = updateHighlight(obj); if (highlight != null) { Rectangle highlightBounds = getBoundsByHighlight(highlight); highlights.remove(highlight); @@ -381,10 +360,12 @@ public class DefaultHighlighter extends private void checkBoundaries(final int start, final int end) throws BadLocationException { if (start < 0) { - throw new BadLocationException(Messages.getString("swing.89", start), end); //$NON-NLS-1$ + throw new BadLocationException(Messages + .getString("swing.89", start), end); //$NON-NLS-1$ } if (end < start) { - throw new BadLocationException(Messages.getString("swing.89", start), end); //$NON-NLS-1$ + throw new BadLocationException(Messages + .getString("swing.89", start), end); //$NON-NLS-1$ } } @@ -403,15 +384,14 @@ public class DefaultHighlighter extends if (oldEnd < newStart || oldStart > oldEnd) { repaintComponent(oldStart, oldEnd, newStart, newEnd); } else { - repaintComponent(Math.min(oldStart, newStart), - Math.max(oldStart, newStart), - Math.min(oldEnd, newEnd), - Math.max(oldEnd, newEnd)); + repaintComponent(Math.min(oldStart, newStart), Math.max(oldStart, + newStart), Math.min(oldEnd, newEnd), Math.max(oldEnd, + newEnd)); } } - private void repaintComponent(final int p0, final int p1, - final int p2, final int p3) { + private void repaintComponent(final int p0, final int p1, final int p2, + final int p3) { repaintComponent(getBoundsByOffsets(p0, p1)); repaintComponent(getBoundsByOffsets(p2, p3)); } @@ -424,8 +404,7 @@ public class DefaultHighlighter extends private Rectangle getBoundsByHighlight(final Highlight highlight) { return TextUtils.getBoundsByOffsets(textKit, - highlight.getStartOffset(), - highlight.getEndOffset()); + highlight.getStartOffset(), highlight.getEndOffset()); } private Rectangle getBoundsByOffsets(final int p0, final int p1) { @@ -433,5 +412,3 @@ public class DefaultHighlighter extends } } - - Index: modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java =================================================================== --- modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java (revision 588163) +++ modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java (working copy) @@ -20,7 +20,6 @@ */ package javax.swing.plaf.basic; - import java.awt.AWTKeyStroke; import java.awt.Color; import java.awt.Dimension; @@ -89,7 +88,6 @@ import org.apache.harmony.x.swing.String import org.apache.harmony.x.swing.Utilities; import org.apache.harmony.x.swing.internal.nls.Messages; - public abstract class BasicTextUI extends TextUI implements ViewFactory { public static class BasicCaret extends DefaultCaret implements UIResource { @@ -152,8 +150,7 @@ public abstract class BasicTextUI extend //Initiator for DnD private GestureRecognizer gestureRecognizer; - private final RootViewContext.ViewFactoryGetter viewFactoryGetter = - new RootViewContext.ViewFactoryGetter() { + private final RootViewContext.ViewFactoryGetter viewFactoryGetter = new RootViewContext.ViewFactoryGetter() { public ViewFactory getViewFactory() { ViewFactory viewFactory = getEditorKit(component).getViewFactory(); @@ -186,8 +183,8 @@ public abstract class BasicTextUI extend * javax.swing.TransferHandler because it doesn't support required * operations. See java.beans (Introspector, BeanInfo,...) */ - private static class TextTransferHandler extends TransferHandler - implements UIResource { + private static class TextTransferHandler extends TransferHandler implements + UIResource { boolean isDrag = false; public boolean canImport(final JComponent comp, @@ -260,8 +257,8 @@ public abstract class BasicTextUI extend * Call rootView.removeUpdate */ public void removeUpdate(final DocumentEvent e) { - getRootView().removeUpdate(e, getVisibleEditorRect(), getRootView() - .getViewFactory()); + getRootView().removeUpdate(e, getVisibleEditorRect(), + getRootView().getViewFactory()); } /** @@ -289,9 +286,9 @@ public abstract class BasicTextUI extend } else if (StringConstants.COMPONENT_ORIENTATION.equals(name)) { modelChanged(); - } else if (JTextComponent.FOCUS_ACCELERATOR_KEY.equals(name)) { - lastFocusAccelerator = ((Character)e.getOldValue()).charValue(); + lastFocusAccelerator = ((Character) e.getOldValue()) + .charValue(); updateFocusAcceleratorBinding(true); } propertyChangeImpl(e); @@ -326,8 +323,7 @@ public abstract class BasicTextUI extend * e.getTransferable(); start = textComponent.getSelectionStart(); * end = textComponent.getSelectionEnd(); try { str = (String) t * .getTransferData(DataFlavor.stringFlavor); } catch (final - * UnsupportedFlavorException ufe) { } catch (final IOException - * ioe) {} + * UnsupportedFlavorException ufe) { } catch (final IOException ioe) {} */ } @@ -374,8 +370,8 @@ public abstract class BasicTextUI extend public void mouseDragged(final MouseEvent me) { if (wasMousePressed) { wasMousePressed = false; - component.getTransferHandler() - .exportAsDrag(component, me, TransferHandler.MOVE); + component.getTransferHandler().exportAsDrag(component, me, + TransferHandler.MOVE); } } } @@ -415,14 +411,13 @@ public abstract class BasicTextUI extend Object bindings = UIManager.get(addPrefix(".keyBindings")); if (bindings != null) { JTextComponent.loadKeymap(keymap, - (JTextComponent.KeyBinding[])bindings, - component.getActions()); + (JTextComponent.KeyBinding[]) bindings, component + .getActions()); } return keymap; } - public void damageRange(final JTextComponent c, final int p0, - final int p1) { + public void damageRange(final JTextComponent c, final int p0, final int p1) { damageRange(c, p0, p1, Position.Bias.Forward, Position.Bias.Forward); } @@ -434,8 +429,8 @@ public abstract class BasicTextUI extend final Position.Bias b1, final Position.Bias b2) { Shape shape = null; try { - shape = getRootView() - .modelToView(p0, b1, p1, b2, getVisibleEditorRect()); + shape = getRootView().modelToView(p0, b1, p1, b2, + getVisibleEditorRect()); } catch (final BadLocationException e) { } Rectangle rect; @@ -479,20 +474,16 @@ public abstract class BasicTextUI extend return new Dimension(minX, minY); } - /** * Calls getNextVisualPosition on root view. If root view returns -1, then * this method will return p0 and biasRet[0] will be the same as bias */ public int getNextVisualPositionFrom(final JTextComponent c, final int p0, - final Position.Bias bias, - final int p1, - final Position.Bias[] biasRet) - throws BadLocationException { + final Position.Bias bias, final int p1, + final Position.Bias[] biasRet) throws BadLocationException { int pos = getRootView().getNextVisualPositionFrom(p0, bias, - getVisibleEditorRect(), - p1, biasRet); + getVisibleEditorRect(), p1, biasRet); if (pos == -1) { pos = p0; biasRet[0] = bias; @@ -534,7 +525,8 @@ public abstract class BasicTextUI extend * Returns, component getSize, excluding insets. */ protected Rectangle getVisibleEditorRect() { - return TextUtils.getEditorRect(component); + return org.apache.harmony.x.swing.text.TextUtils + .getEditorRect(component); } final String addPrefix(final String property) { @@ -543,8 +535,7 @@ public abstract class BasicTextUI extend protected void installDefaults() { LookAndFeel.installColorsAndFont(component, addPrefix(".background"), - addPrefix(".foreground"), - addPrefix(".font")); + addPrefix(".foreground"), addPrefix(".font")); if (Utilities.isUIResource(component.getBorder())) { component.setBorder(UIManager.getBorder(addPrefix(".border"))); } @@ -553,13 +544,13 @@ public abstract class BasicTextUI extend } //RI 6251901. Documentation error if (Utilities.isUIResource(component.getCaretColor())) { - component.setCaretColor(UIManager.getColor(addPrefix( - ".caretForeground"))); + component.setCaretColor(UIManager + .getColor(addPrefix(".caretForeground"))); } if (Utilities.isUIResource(component.getSelectionColor())) { - component.setSelectionColor(UIManager.getColor(addPrefix( - ".selectionBackground"))); + component.setSelectionColor(UIManager + .getColor(addPrefix(".selectionBackground"))); } if (Utilities.isUIResource(component.getSelectedTextColor())) { @@ -568,8 +559,8 @@ public abstract class BasicTextUI extend } if (Utilities.isUIResource(component.getDisabledTextColor())) { - component.setDisabledTextColor(UIManager.getColor(addPrefix( - ".inactiveForeground"))); + component.setDisabledTextColor(UIManager + .getColor(addPrefix(".inactiveForeground"))); } } @@ -582,8 +573,8 @@ public abstract class BasicTextUI extend result.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK)); } else { - result.add(KeyStroke - .getKeyStroke(KeyEvent.VK_TAB, + result + .add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); } @@ -598,15 +589,11 @@ public abstract class BasicTextUI extend if (component == null) { return; } - Set forwardFocusTraversalKeys = - getDefaultFocusTraversalKeys(KeyboardFocusManager - .FORWARD_TRAVERSAL_KEYS); - Set backwardFocusTraversalKeys = - getDefaultFocusTraversalKeys(KeyboardFocusManager - .BACKWARD_TRAVERSAL_KEYS); + Set forwardFocusTraversalKeys = getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); + Set backwardFocusTraversalKeys = getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); KeyStroke tabPressed = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); - KeyStroke shiftTabPressed = KeyStroke - .getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK); + KeyStroke shiftTabPressed = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, + InputEvent.SHIFT_DOWN_MASK); if (component.isEditable()) { forwardFocusTraversalKeys.remove(tabPressed); @@ -620,11 +607,11 @@ public abstract class BasicTextUI extend } } - component.setFocusTraversalKeys(KeyboardFocusManager - .FORWARD_TRAVERSAL_KEYS, + component.setFocusTraversalKeys( + KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardFocusTraversalKeys); - component.setFocusTraversalKeys(KeyboardFocusManager - .BACKWARD_TRAVERSAL_KEYS, + component.setFocusTraversalKeys( + KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardFocusTraversalKeys); } @@ -737,8 +724,8 @@ public abstract class BasicTextUI extend //DnD support // java.awt.Component doesn't support DnD /* - * try { component.getDropTarget().addDropTargetListener(dropListener); - * } catch (final TooManyListenersException e){} + * try { component.getDropTarget().addDropTargetListener(dropListener); } + * catch (final TooManyListenersException e){} */ component.addMouseListener(gestureRecognizer); component.addMouseMotionListener(gestureRecognizer); @@ -757,8 +744,8 @@ public abstract class BasicTextUI extend } try { setDocument(document); - View view = getRootView().getViewFactory() - .create(document.getDefaultRootElement()); + View view = getRootView().getViewFactory().create( + document.getDefaultRootElement()); setView(view); setViewSize(); } finally { @@ -777,8 +764,7 @@ public abstract class BasicTextUI extend } public Rectangle modelToView(final JTextComponent comp, final int p, - final Position.Bias b) - throws BadLocationException { + final Position.Bias b) throws BadLocationException { final Document doc = document; readLock(doc); @@ -972,8 +958,7 @@ public abstract class BasicTextUI extend } else if (!wasInputMap) { im = new ComponentInputMapUIResource(component); im.put(KeyStroke.getKeyStroke(accelerator, - InputEvent.ALT_DOWN_MASK), - FOCUS_ACTION_NAME); + InputEvent.ALT_DOWN_MASK), FOCUS_ACTION_NAME); if (!wasInputMap) { SwingUtilities.replaceUIInputMap(component, JComponent.WHEN_IN_FOCUSED_WINDOW, im); @@ -1015,10 +1000,8 @@ public abstract class BasicTextUI extend } final boolean getI18nProperty() { - return document == null - ? false - : ((Boolean)document.getProperty(StringConstants.BIDI_PROPERTY)) - .booleanValue(); + return document == null ? false : ((Boolean) document + .getProperty(StringConstants.BIDI_PROPERTY)).booleanValue(); } private View getRootView() { @@ -1042,5 +1025,3 @@ public abstract class BasicTextUI extend setDocument(document); } } - -