summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/text/DefaultEditorKit.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/text/DefaultEditorKit.java')
-rw-r--r--libjava/classpath/javax/swing/text/DefaultEditorKit.java79
1 files changed, 58 insertions, 21 deletions
diff --git a/libjava/classpath/javax/swing/text/DefaultEditorKit.java b/libjava/classpath/javax/swing/text/DefaultEditorKit.java
index 3b3fc1f7238..88094b898f7 100644
--- a/libjava/classpath/javax/swing/text/DefaultEditorKit.java
+++ b/libjava/classpath/javax/swing/text/DefaultEditorKit.java
@@ -38,8 +38,10 @@ exception statement from your version. */
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;
@@ -112,8 +114,7 @@ public class DefaultEditorKit extends EditorKit
*/
public void actionPerformed(ActionEvent event)
{
- // FIXME: Implement me. Tookit.getSystemClipboard should be used
- // for that.
+ getTextComponent(event).copy();
}
}
@@ -144,8 +145,7 @@ public class DefaultEditorKit extends EditorKit
*/
public void actionPerformed(ActionEvent event)
{
- // FIXME: Implement me. Tookit.getSystemClipboard should be used
- // for that.
+ getTextComponent(event).cut();
}
}
@@ -174,8 +174,7 @@ public class DefaultEditorKit extends EditorKit
*/
public void actionPerformed(ActionEvent event)
{
- // FIXME: Implement me. Tookit.getSystemClipboard should be used
- // for that.
+ getTextComponent(event).paste();
}
}
@@ -216,19 +215,9 @@ public class DefaultEditorKit extends EditorKit
return;
JTextComponent t = getTextComponent(event);
- if (t != null)
- {
- try
- {
- t.getDocument().insertString(t.getCaret().getDot(),
- event.getActionCommand(), null);
- }
- catch (BadLocationException be)
- {
- // FIXME: we're not authorized to throw this.. swallow it?
- }
- }
- }
+ if (t != null && t.isEnabled() && t.isEditable())
+ t.replaceSelection(event.getActionCommand());
+ }
}
/**
@@ -309,7 +298,8 @@ public class DefaultEditorKit extends EditorKit
*/
public void actionPerformed(ActionEvent event)
{
- // FIXME: Implement this.
+ JTextComponent t = getTextComponent(event);
+ t.replaceSelection("\t");
}
}
@@ -710,6 +700,53 @@ public class DefaultEditorKit extends EditorKit
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)
@@ -911,7 +948,7 @@ public class DefaultEditorKit extends EditorKit
content.append("\n");
}
- document.insertString(offset, content.toString(),
+ document.insertString(offset, content.substring(0, content.length() - 1),
SimpleAttributeSet.EMPTY);
}
OpenPOWER on IntegriCloud