Tony and I implemented HOME and END actions for text components. Unfortunately, we tried to implement a more efficient solution but viewToModel was not returning the proper values. I added a TODO comment in there, so it could get looked at later once we have viewToModel fixed.
2005-12-20 Lillian Angel <[EMAIL PROTECTED]> * javax/swing/text/DefaultEditorKit.java: Added implementation for beginLineAction and endLineAction. * javax/swing/text/JTextComponent.java (JTextComponent): Added key bindings for HOME and END.
Index: javax/swing/text/DefaultEditorKit.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultEditorKit.java,v retrieving revision 1.25 diff -u -r1.25 DefaultEditorKit.java --- javax/swing/text/DefaultEditorKit.java 21 Nov 2005 20:59:32 -0000 1.25 +++ javax/swing/text/DefaultEditorKit.java 20 Dec 2005 22:37:42 -0000 @@ -38,8 +38,10 @@ package javax.swing.text; +import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ActionEvent; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -698,6 +700,53 @@ new InsertContentAction(), new InsertTabAction(), new PasteAction(), + new TextAction(beginLineAction) + { + public void actionPerformed(ActionEvent event) + { + JTextComponent t = getTextComponent(event); + try + { + // TODO: There is a more efficent solution, but + // viewToModel doesn't work properly. + Point p = t.modelToView(t.getCaret().getDot()).getLocation(); + int cur = t.getCaretPosition(); + int y = p.y; + while (y == p.y && cur > 0) + y = t.modelToView(--cur).getLocation().y; + if (cur != 0) + cur++; + t.setCaretPosition(cur); + } + catch (BadLocationException ble) + { + // Do nothing here. + } + } + }, + new TextAction(endLineAction) + { + public void actionPerformed(ActionEvent event) + { + JTextComponent t = getTextComponent(event); + try + { + Point p = t.modelToView(t.getCaret().getDot()).getLocation(); + int cur = t.getCaretPosition(); + int y = p.y; + int length = t.getDocument().getLength(); + while (y == p.y && cur < length) + y = t.modelToView(++cur).getLocation().y; + if (cur != length) + cur--; + t.setCaretPosition(cur); + } + catch (BadLocationException ble) + { + // Nothing to do here + } + } + }, new TextAction(deleteNextCharAction) { public void actionPerformed(ActionEvent event) Index: javax/swing/text/JTextComponent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v retrieving revision 1.46 diff -u -r1.46 JTextComponent.java --- javax/swing/text/JTextComponent.java 21 Nov 2005 20:59:32 -0000 1.46 +++ javax/swing/text/JTextComponent.java 20 Dec 2005 22:37:42 -0000 @@ -945,6 +945,10 @@ new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK), DefaultEditorKit.selectionForwardAction), + new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), + DefaultEditorKit.beginLineAction), + new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), + DefaultEditorKit.endLineAction), new KeyBinding(KeyStroke.getKeyStroke("typed \u007f"), DefaultEditorKit.deleteNextCharAction) },
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches