Skip to content

Commit 6f2930c

Browse files
hansonrhansonr
authored andcommitted
JTextPane and JEditorPane upgrade to fully utilize Java events for
updating the HTML5 object. However, there is a problem with scrolling after typing -- probably needs to be after a timeout, but I did not have time to look at that.
1 parent 484ae93 commit 6f2930c

26 files changed

+904
-528
lines changed

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public AppContext getAppContext() {
252252
* @see #getFont
253253
* @see #setFont
254254
*/
255-
Font font;
255+
public Font font; // was package-private; need to set it here from a2s directory
256256

257257
/**
258258
* The font which the peer is currently using. (<code>null</code> if no peer

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.beans.PropertyChangeListener;
3434
import java.util.Arrays;
3535

36+
import javax.swing.Action;
3637
import javax.swing.JComponent;
3738
import javax.swing.JPopupMenu;
3839
import javax.swing.JRootPane;
@@ -98,6 +99,11 @@ public interface A2SWrappedComponent {
9899

99100
}
100101

102+
/**
103+
* indicates an key action is being processed
104+
*/
105+
public Action 秘keyAction;
106+
101107
protected boolean 秘isAppletFrame;
102108
public boolean 秘isFramedApplet;
103109

sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import javax.swing.event.AncestorListener;
6969
import javax.swing.event.EventListenerList;
7070
import javax.swing.plaf.ComponentUI;
71+
import javax.swing.text.DefaultEditorKit;
7172

7273
import javajs.util.Lst;
7374
import sun.font.FontDesignMetrics;
@@ -2665,12 +2666,9 @@ protected void processKeyEvent(KeyEvent e) {
26652666

26662667
shouldProcessKey = KeyboardState.shouldProcess(e);
26672668

2668-
if (e.isConsumed()) {
2669-
return;
2670-
}
2671-
2672-
if (shouldProcessKey
2673-
&& processKeyBindings(e, e.getID() == KeyEvent.KEY_PRESSED)) {
2669+
if (!e.isConsumed() && (shouldProcessKey
2670+
&& processKeyBindings(e, e.getID() == KeyEvent.KEY_PRESSED)
2671+
|| 秘getUI().processKeyEvent(e))) {
26742672
e.consume();
26752673
}
26762674
}
@@ -2709,8 +2707,12 @@ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition,
27092707
Object binding = map.get(ks);
27102708
Action action = (binding == null) ? null : am.get(binding);
27112709
if (action != null) {
2712-
return SwingUtilities.notifyAction(action, ks, e, this,
2710+
//System.out.println("JComponent action: " + action.getValue(Action.NAME));
2711+
this.秘keyAction = action;
2712+
boolean ret = SwingUtilities.notifyAction(action, ks, e, this,
27132713
e.getModifiers());
2714+
this.秘keyAction = null;
2715+
return ret;
27142716
}
27152717
}
27162718
return false;

sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultCaret.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,8 @@ void changeCaretPosition(int dot, Position.Bias dotBias) {
13361336
dotLTR = isPositionLTR(dot, dotBias);
13371337
fireStateChanged();
13381338

1339-
if (false && !working)
1340-
updateSystemSelection();
1339+
if (!working)
1340+
updateSystemSelection();
13411341

13421342
setMagicCaretPosition(null);
13431343

@@ -1389,7 +1389,7 @@ void repaintNewCaret() {
13891389
}
13901390

13911391
private void updateSystemSelection() {
1392-
((JSTextUI) component.ui).updateJSCursorFromCaret();
1392+
// will be taken care of by fireStateChanged ((JSTextUI) component.ui).updateJSCursorFromCaret();
13931393

13941394

13951395

@@ -1624,7 +1624,7 @@ int getCaretWidth(int height) {
16241624
// access bug
16251625
JTextComponent component;
16261626

1627-
int updatePolicy = UPDATE_WHEN_ON_EDT;
1627+
int updatePolicy = ALWAYS_UPDATE;//UPDATE_WHEN_ON_EDT;
16281628
boolean visible;
16291629
boolean active;
16301630
protected int dot;

sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultEditorKit.java

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import swingjs.JSToolkit;
3939
import swingjs.api.Interface;
40+
import swingjs.plaf.JSTextUI;
4041

4142
import java.awt.ComponentOrientation;
4243
import java.awt.Point;
@@ -1065,39 +1066,13 @@ static class DeletePrevCharAction extends TextAction {
10651066
@Override
10661067
public void actionPerformed(ActionEvent e) {
10671068
JTextComponent target = getTextComponent(e);
1068-
boolean beep = true;
1069+
// boolean beep = true;
10691070
if ((target != null) && (target.isEditable())) {
1070-
try {
1071-
Document doc = target.getDocument();
1072-
Caret caret = target.getCaret();
1073-
int dot = caret.getDot();
1074-
int mark = caret.getMark();
1075-
if (dot != mark) {
1076-
doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1077-
beep = false;
1078-
} else if (dot > 0) {
1079-
int delChars = 1;
1080-
1081-
if (dot > 1) {
1082-
String dotChars = doc.getText(dot - 2, 2);
1083-
char c0 = dotChars.charAt(0);
1084-
char c1 = dotChars.charAt(1);
1085-
1086-
if (c0 >= '\uD800' && c0 <= '\uDBFF' &&
1087-
c1 >= '\uDC00' && c1 <= '\uDFFF') {
1088-
delChars = 2;
1089-
}
1090-
}
1091-
1092-
doc.remove(dot - delChars, delChars);
1093-
beep = false;
1094-
}
1095-
} catch (BadLocationException bl) {
1096-
}
1097-
}
1098-
if (beep) {
1099-
UIManager.getLookAndFeel().provideErrorFeedback(target);
1071+
((JSTextUI)target.ui).action("delete", -1);
11001072
}
1073+
// if (beep) {
1074+
// UIManager.getLookAndFeel().provideErrorFeedback(target);
1075+
// }
11011076
}
11021077
}
11031078

@@ -1118,38 +1093,8 @@ static class DeleteNextCharAction extends TextAction {
11181093
@Override
11191094
public void actionPerformed(ActionEvent e) {
11201095
JTextComponent target = getTextComponent(e);
1121-
boolean beep = true;
11221096
if ((target != null) && (target.isEditable())) {
1123-
try {
1124-
Document doc = target.getDocument();
1125-
Caret caret = target.getCaret();
1126-
int dot = caret.getDot();
1127-
int mark = caret.getMark();
1128-
if (dot != mark) {
1129-
doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1130-
beep = false;
1131-
} else if (dot < doc.getLength()) {
1132-
int delChars = 1;
1133-
1134-
if (dot < doc.getLength() - 1) {
1135-
String dotChars = doc.getText(dot, 2);
1136-
char c0 = dotChars.charAt(0);
1137-
char c1 = dotChars.charAt(1);
1138-
1139-
if (c0 >= '\uD800' && c0 <= '\uDBFF' &&
1140-
c1 >= '\uDC00' && c1 <= '\uDFFF') {
1141-
delChars = 2;
1142-
}
1143-
}
1144-
1145-
doc.remove(dot, delChars);
1146-
beep = false;
1147-
}
1148-
} catch (BadLocationException bl) {
1149-
}
1150-
}
1151-
if (beep) {
1152-
UIManager.getLookAndFeel().provideErrorFeedback(target);
1097+
((JSTextUI)target.ui).action("delete", 1);
11531098
}
11541099
}
11551100
}

sources/net.sf.j2s.java.core/src/javax/swing/text/JTextComponent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
//import java.security.AccessController;
8383
//import java.security.PrivilegedAction;
8484
//import swingjs.api.JSMinimalAbstractDocument;
85+
import swingjs.plaf.JSTextUI;
8586

8687
/**
8788
* <code>JTextComponent</code> is the base class for swing text
@@ -1438,6 +1439,7 @@ public int viewToModel(Point pt) {
14381439
* @see java.awt.datatransfer.Clipboard
14391440
*/
14401441
public void cut() {
1442+
((JSTextUI)this.ui).action("delete", 0);
14411443
// if (isEditable() && isEnabled()) {
14421444
// invokeAction("cut", TransferHandler.getCutAction());
14431445
// }
@@ -1469,6 +1471,7 @@ public void copy() {
14691471
* @see java.awt.datatransfer.Clipboard
14701472
*/
14711473
public void paste() {
1474+
((JSTextUI)this.ui).action("paste", 0);
14721475
// if (isEditable() && isEnabled()) {
14731476
// invokeAction("paste", TransferHandler.getPasteAction());
14741477
// }
@@ -4048,8 +4051,7 @@ static final JTextComponent getFocusedComponent() {
40484051
// return modifiers;
40494052
// }
40504053
//
4051-
private static final Object KEYMAP_TABLE = new Object(); // JTextComponent_KeymapTable
4052-
// private JTextComponent editor;
4054+
private static final String KEYMAP_TABLE = "JTextComponent_KeymapTable";//new Object(); // new StringBuilder("JTextComponent_KeymapTable"
40534055
//
40544056
// member variables used for on-the-spot input method
40554057
// editing style support

sources/net.sf.j2s.java.core/src/swingjs/JSKeyEvent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ public class JSKeyEvent extends KeyEvent {
3434
* @param time
3535
* @return
3636
*/
37-
public static boolean dispatchKeyEvent(JComponent c, int id, int modifiers, Object jqevent, long time) {
37+
public static boolean dispatchKeyEvent(JComponent c, int id, Object jqevent, long time) {
38+
if (id == 0)
39+
id = JSMouse.fixEventType(jqevent, 0);
3840
if (id == KeyEvent.KEY_TYPED) {
3941
// HTML5 keypress is no longer reliable
4042
JSToolkit.consumeEvent(jqevent);
4143
return false;
4244
}
4345
if (c != null) {
4446
JSComponentUI ui = c.秘getUI();
45-
KeyEvent e = newJSKeyEvent(c, jqevent, 0, false);
47+
KeyEvent e = newJSKeyEvent(c, jqevent, id, false);
4648
// create our own KEY_PRESSED event
4749
c.dispatchEvent(e);
4850
if (!ui.j2sDoPropagate)
@@ -128,8 +130,7 @@ private static int getJavaKeyCode(int jskeyCode, String jskey) {
128130
return jskeyCode;
129131
}
130132
if (jskey.length() == 1) {
131-
// same if 1-character, except numeric keypad 0-9
132-
return (jskeyCode >= 96 && jskeyCode <= 105 ? jskeyCode : 0 + jskey.toUpperCase().charAt(0));
133+
return jskeyCode;
133134
}
134135
switch (jskeyCode) {
135136
case 91: // META

sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public boolean processEvent(int id, int x, int y, int modifiers, long time, Obje
5959
case KeyEvent.KEY_PRESSED:
6060
case KeyEvent.KEY_TYPED:
6161
case KeyEvent.KEY_RELEASED:
62-
return keyAction(id, modifiers, jqevent, time);
62+
return keyAction(id, jqevent, time);
6363
}
6464
if (id != MouseEvent.MOUSE_WHEEL && id != MouseEvent.MOUSE_MOVED)
6565
modifiers = applyLeftMouse(modifiers);
@@ -476,11 +476,11 @@ private static boolean isPopupTrigger(int id, int mods, boolean isWin) {
476476
}
477477
}
478478

479-
private boolean keyAction(int id, int modifiers, Object jqevent, long time) {
479+
private boolean keyAction(int id, Object jqevent, long time) {
480480
JComponent c = /** @j2sNative
481481
jqevent.target["data-shadowkeycomponent"] || jqevent.target["data-keycomponent"]
482482
*/null;
483-
return JSKeyEvent.dispatchKeyEvent(c, id, modifiers, jqevent, time);
483+
return JSKeyEvent.dispatchKeyEvent(c, id, jqevent, time);
484484
}
485485

486486
public static int getScroll(Object ev) {

sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sComboBox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ $( function() {
111111
.removeClass( 'custom-j2sCB' )
112112
.enableSelection()
113113
.css( 'background-color', 'transparent' );
114+
this._trigger('change', null, [this, 'destroyed']);
114115
},
115116

116117
// _setOptions is called with a hash of all options that are changing

sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ try{
364364

365365
_create:function(){
366366

367-
368-
xxm = this;
369-
370-
xxe = e;
371367
this.closed = false;
372368

373369
if (typeof this.options.delay == "number")

0 commit comments

Comments
 (0)