Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181001183306
20181007153006
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181001183306
20181007153006
11 changes: 11 additions & 0 deletions sources/net.sf.j2s.core/doc/Differences.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Notes
=====

update 10/1/2018 -- 3.2.4.01

AWT components in SwingJS:

-- can be accessed directly as java.awt Components
-- receive posted events to the component's MouseDown, MouseMove, etc, methods;
-- can also be extended to use (or can alternatively use) Swing MouseListener and MouseAdapter methods;
-- are subclasses of JComponent (JavaScript only, not Java), so also take all the event possibilities of Swing;
-- require explicit graphics.dispose() if getGraphics() is called in any component.


update 9/29/2018 -- 3.2.4 adds support for JAXB, changes default for ResourceBundle.getBundle
update 9/23/2018 -- 3.2.3 adds support for direct use of java.awt.* components and java.applet.Applet
-- no need for switching to a2s.*
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
221 changes: 110 additions & 111 deletions sources/net.sf.j2s.java.core/src/a2s/A2SEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ public A2SEvent(AWTEvent e) {
public void run() {
Event e = this.e;
Component target = (Component) this.target;
if (target instanceof Container)
if (target instanceof Container) {
target = ((Container)target).getMouseEventTarget(e.x, e.y, true, null, false);

Component parent = target;
while (parent != null && parent != this.target) {
e.x -= parent.getX();
e.y -= parent.getY();
parent = parent.getParent();
}
}

/**
* Otherwise the states have not changed
Expand Down Expand Up @@ -104,74 +110,69 @@ static int getOldEventKey(KeyEvent e) {
};


/**
* Converts a new event to an old one (used for compatibility).
* If the new event cannot be converted (because no old equivalent
* exists) then this returns null.
*
* Note: this method is here instead of in each individual new
* event class in java.awt.event because we don't want to make
* it public and it needs to be called from java.awt.
*/
static Event convertToOld(AWTEvent e) {
Object src = e.getSource();
int id = e.getID();
int newid = id;
/**
* Converts a new event to an old one (used for compatibility). If the new event
* cannot be converted (because no old equivalent exists) then this returns
* null.
*
* Note: this method is here instead of in each individual new event class in
* java.awt.event because we don't want to make it public and it needs to be
* called from java.awt.
*/
static Event convertToOld(AWTEvent e) {
Object src = e.getSource();
int id = e.getID();
int newid = id;

switch(id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
KeyEvent ke = (KeyEvent)e;
if (ke.isActionKey()) {
newid = (id == KeyEvent.KEY_PRESSED?
Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
}
int keyCode = ke.getKeyCode();
if (keyCode == KeyEvent.VK_SHIFT ||
keyCode == KeyEvent.VK_CONTROL ||
keyCode == KeyEvent.VK_ALT) {
return null; // suppress modifier keys in old event model.
}
// no mask for button1 existed in old Event - strip it out
return new Event(src, ke.getWhen(), newid, 0, 0,
getOldEventKey(ke),
(ke.getModifiers() & ~InputEvent.BUTTON1_MASK));
switch (id) {
case KeyEvent.KEY_PRESSED:
case KeyEvent.KEY_RELEASED:
KeyEvent ke = (KeyEvent) e;
if (ke.isActionKey()) {
newid = (id == KeyEvent.KEY_PRESSED ? Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
}
int keyCode = ke.getKeyCode();
if (keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT) {
return null; // suppress modifier keys in old event model.
}
// no mask for button1 existed in old Event - strip it out
return new Event(src, ke.getWhen(), newid, 0, 0, getOldEventKey(ke),
(ke.getModifiers() & ~InputEvent.BUTTON1_MASK));

case MouseEvent.MOUSE_CLICKED:
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
case MouseEvent.MOUSE_ENTERED:
case MouseEvent.MOUSE_EXITED:
MouseEvent me = (MouseEvent)e;
// no mask for button1 existed in old Event - strip it out
Event olde = new Event(src, me.getWhen(), newid,
me.getX(), me.getY(), 0,
(me.getModifiers() & ~InputEvent.BUTTON1_MASK));
olde.clickCount = me.getClickCount();
return olde;
case MouseEvent.MOUSE_CLICKED:
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_MOVED:
case MouseEvent.MOUSE_DRAGGED:
case MouseEvent.MOUSE_ENTERED:
case MouseEvent.MOUSE_EXITED:
MouseEvent me = (MouseEvent) e;
// no mask for button1 existed in old Event - strip it out
Event olde = new Event(src, me.getWhen(), newid, me.getX(), me.getY(), 0,
(me.getModifiers() & ~InputEvent.BUTTON1_MASK));
olde.clickCount = me.getClickCount();
return olde;

case FocusEvent.FOCUS_GAINED:
return new Event(src, Event.GOT_FOCUS, null);
case FocusEvent.FOCUS_GAINED:
return new Event(src, Event.GOT_FOCUS, null);

case FocusEvent.FOCUS_LOST:
return new Event(src, Event.LOST_FOCUS, null);
case FocusEvent.FOCUS_LOST:
return new Event(src, Event.LOST_FOCUS, null);

case WindowEvent.WINDOW_CLOSING:
case WindowEvent.WINDOW_ICONIFIED:
case WindowEvent.WINDOW_DEICONIFIED:
return new Event(src, newid, null);
case WindowEvent.WINDOW_CLOSING:
case WindowEvent.WINDOW_ICONIFIED:
case WindowEvent.WINDOW_DEICONIFIED:
return new Event(src, newid, null);

case ComponentEvent.COMPONENT_MOVED:
if (src instanceof Frame || src instanceof Dialog) {
Point p = ((Component)src).getLocation();
return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0);
}
break;
case ComponentEvent.COMPONENT_MOVED:
if (src instanceof Frame || src instanceof Dialog) {
Point p = ((Component) src).getLocation();
return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0);
}
break;

case ActionEvent.ACTION_PERFORMED:
ActionEvent ae = (ActionEvent)e;
case ActionEvent.ACTION_PERFORMED:
ActionEvent ae = (ActionEvent) e;
String cmd;
if (src instanceof AbstractButton) {
cmd = ((AbstractButton)src).getText();
Expand All @@ -180,58 +181,56 @@ static Event convertToOld(AWTEvent e) {
} else {
cmd = ae.getActionCommand();
}
return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd);
return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd);

case ItemEvent.ITEM_STATE_CHANGED:
ItemEvent ie = (ItemEvent)e;
Object arg;
if (src instanceof List) {
newid = (ie.getStateChange() == ItemEvent.SELECTED?
Event.LIST_SELECT : Event.LIST_DESELECT);
arg = ie.getItem();
} else {
newid = Event.ACTION_EVENT;
if (src instanceof Choice) {
arg = ie.getItem();
case ItemEvent.ITEM_STATE_CHANGED:
ItemEvent ie = (ItemEvent) e;
Object arg;
if (src instanceof List) {
newid = (ie.getStateChange() == ItemEvent.SELECTED ? Event.LIST_SELECT : Event.LIST_DESELECT);
arg = ie.getItem();
} else {
newid = Event.ACTION_EVENT;
if (src instanceof Choice) {
arg = ie.getItem();

} else { // Checkbox
arg = Boolean.valueOf(ie.getStateChange() == ItemEvent.SELECTED);
}
}
return new Event(src, newid, arg);
} else { // Checkbox
arg = Boolean.valueOf(ie.getStateChange() == ItemEvent.SELECTED);
}
}
return new Event(src, newid, arg);

case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
AdjustmentEvent aje = (AdjustmentEvent)e;
switch(aje.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
newid = Event.SCROLL_LINE_DOWN;
break;
case AdjustmentEvent.UNIT_DECREMENT:
newid = Event.SCROLL_LINE_UP;
break;
case AdjustmentEvent.BLOCK_INCREMENT:
newid = Event.SCROLL_PAGE_DOWN;
break;
case AdjustmentEvent.BLOCK_DECREMENT:
newid = Event.SCROLL_PAGE_UP;
break;
case AdjustmentEvent.TRACK:
if (aje.getValueIsAdjusting()) {
newid = Event.SCROLL_ABSOLUTE;
}
else {
newid = Event.SCROLL_END;
}
break;
default:
return null;
}
return new Event(src, newid, Integer.valueOf(aje.getValue()));
case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
AdjustmentEvent aje = (AdjustmentEvent) e;
switch (aje.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
newid = Event.SCROLL_LINE_DOWN;
break;
case AdjustmentEvent.UNIT_DECREMENT:
newid = Event.SCROLL_LINE_UP;
break;
case AdjustmentEvent.BLOCK_INCREMENT:
newid = Event.SCROLL_PAGE_DOWN;
break;
case AdjustmentEvent.BLOCK_DECREMENT:
newid = Event.SCROLL_PAGE_UP;
break;
case AdjustmentEvent.TRACK:
if (aje.getValueIsAdjusting()) {
newid = Event.SCROLL_ABSOLUTE;
} else {
newid = Event.SCROLL_END;
}
break;
default:
return null;
}
return new Event(src, newid, Integer.valueOf(aje.getValue()));

default:
}
return null;
}
default:
}
return null;
}

public static Component addListener(JComponent container, Component comp) {
A2SContainer top = (container == null ? null : ((A2SContainer) container.getTopLevelAncestor()));
Expand Down
Loading