Skip to content

Commit ed563a1

Browse files
committed
Fixes missing awt.List Item listener not installed
1 parent 58602a1 commit ed563a1

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed
1.03 MB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191207231619
1+
20191208152303
1.03 MB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191207231619
1+
20191208152303
1.03 MB
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/a2s/A2SListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import javax.swing.event.ChangeEvent;
1919
import javax.swing.event.ChangeListener;
20+
import javax.swing.event.ListSelectionEvent;
21+
import javax.swing.event.ListSelectionListener;
2022

2123
public class A2SListener implements AdjustmentListener, ActionListener, KeyListener, MouseListener, MouseMotionListener, TextListener, ChangeListener, ItemListener {
2224

sources/net.sf.j2s.java.core/src/swingjs/a2s/List.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.awt.event.ActionListener;
1010
import java.awt.event.ItemEvent;
1111
import java.awt.event.ItemListener;
12+
import java.awt.event.MouseEvent;
1213
import java.awt.peer.ListPeer;
1314
import java.util.EventListener;
1415

@@ -17,8 +18,13 @@
1718
import javax.swing.JScrollPane;
1819
import javax.swing.ListSelectionModel;
1920
import javax.swing.border.LineBorder;
21+
import javax.swing.event.ListSelectionEvent;
22+
import javax.swing.event.ListSelectionListener;
23+
24+
import sun.swing.SwingUtilities2;
25+
2026
import java.awt.JSComponent;
21-
public class List extends JList implements ItemSelectable, JSComponent.A2SWrappedComponent {
27+
public class List extends JList implements ItemSelectable, JSComponent.A2SWrappedComponent, ListSelectionListener {
2228

2329
public void isAWT() {}
2430

@@ -225,6 +231,7 @@ public synchronized void clear() {
225231
public synchronized void remove(String item) {
226232
awtmodel.removeElement(item);
227233
}
234+
228235

229236
/**
230237
* Removes the item at the specified position
@@ -607,6 +614,8 @@ public synchronized void addItemListener(ItemListener l) {
607614
}
608615
itemListener = AWTEventMulticaster.add(itemListener, l);
609616
newEventsOnly = true;
617+
removeListSelectionListener(this);
618+
addListSelectionListener(this);
610619
}
611620

612621
/**
@@ -630,6 +639,8 @@ public synchronized void removeItemListener(ItemListener l) {
630639
return;
631640
}
632641
itemListener = AWTEventMulticaster.remove(itemListener, l);
642+
if (itemListener == null)
643+
removeListSelectionListener(this);
633644
}
634645

635646
/**
@@ -845,6 +856,15 @@ protected void processItemEvent(ItemEvent e) {
845856
}
846857
}
847858

859+
@Override
860+
public void valueChanged(ListSelectionEvent e) {
861+
if (itemListener != null && getSelectionModel().getValueIsAdjusting()) {
862+
processItemEvent(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, getSelectedItem(), ItemEvent.SELECTED));
863+
}
864+
}
865+
866+
867+
848868
/**
849869
* Processes action events occurring on this component
850870
* by dispatching them to any registered
@@ -885,4 +905,19 @@ protected String paramString() {
885905
return super.paramString() + ",selected=" + getSelectedItem();
886906
}
887907

908+
@Override
909+
public boolean 秘processUIEvent(MouseEvent e) {
910+
super.秘processUIEvent(e);
911+
if (e.getID() == MouseEvent.MOUSE_CLICKED) {
912+
if (e.getClickCount() == 2) {
913+
processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, this.getSelectedItem()));
914+
if (itemListener != null)
915+
processItemEvent(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, getSelectedItem(), ItemEvent.SELECTED));
916+
// indicate handled
917+
return true;
918+
}
919+
}
920+
return false;
921+
}
922+
888923
}

0 commit comments

Comments
 (0)