Skip to content

Commit d4351a6

Browse files
committed
multiple fixes related to Jalview mouse, tooltip, array.equals$ and
.clone // BH 6/29/2018 9:48:13 AM fixes key info for mouse move // BH 6/29/2018 10:13:51 AM array.equals$O, fixes array.clone // BH 6/28/2018 7:34:58 AM fix for array.clone not copying array in the case of objects
1 parent d5a56ab commit d4351a6

File tree

14 files changed

+190
-51
lines changed

14 files changed

+190
-51
lines changed
48 Bytes
Binary file not shown.

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
@@ -2866,7 +2866,7 @@ public void setCursor(Cursor cursor) {
28662866
final void updateCursorImmediately() {
28672867
// this is the key method that updates a JComponent if there is
28682868
// no layout manager -- for example, for a JDesktop.
2869-
JSToolkit.setCursor(cursor);
2869+
JSToolkit.setCursor(this, cursor);
28702870
// TODO
28712871
// if (peer instanceof LightweightPeer) {
28722872
// Container nativeContainer = getNativeContainer();

sources/net.sf.j2s.java.core/src/java/awt/image/BufferedImage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,20 @@ public int getTransparency() {
16651665
return colorModel.getTransparency();
16661666
}
16671667

1668+
1669+
/**
1670+
* Set the underlying graphics object coming from painting this image
1671+
*
1672+
*
1673+
*/
1674+
1675+
public void setImageFromHTML5Canvas(JSGraphics2D g) {
1676+
this._g = g;
1677+
width = raster.width;
1678+
height = raster.height;
1679+
setPixels();
1680+
}
1681+
16681682
/**
16691683
* Extract the int[] data from this image by installing it in a canvas.
16701684
* Note that if if img.complete == false, then this will result in a

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,4 +1000,5 @@ public void dispose() {
10001000
reset(initialState);
10011001
}
10021002

1003+
10031004
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
import java.util.Hashtable;
44

5+
import javax.swing.Icon;
6+
import javax.swing.ImageIcon;
7+
58
import javajs.img.BMPDecoder;
69
import javajs.util.AU;
10+
11+
import java.awt.Component;
12+
import java.awt.Graphics;
713
import java.awt.Image;
14+
import java.awt.image.BufferedImage;
815
import java.awt.image.ColorModel;
916
import java.awt.image.ImageConsumer;
17+
import java.awt.image.WritableRaster;
18+
1019
import swingjs.api.Interface;
20+
import swingjs.api.js.DOMNode;
21+
import swingjs.api.js.HTML5Canvas;
1122

1223
/**
1324
* An image consumer for off-line images.
@@ -81,6 +92,7 @@ public Image getCreatedImage() {
8192
return jsimage;
8293
}
8394

95+
8496
@Override
8597
public void setDimensions(int width, int height) {
8698
this.width = width;
@@ -233,6 +245,36 @@ public static int getSourceType(byte[] b) {
233245
: UNK);
234246
}
235247

248+
249+
/**
250+
* Create an ImageIcon by painting from an Icon to an HTML5 canvas, and then
251+
* using that as the basis for an image.
252+
*
253+
* @param c
254+
* @param icon
255+
* @return
256+
*/
257+
public static ImageIcon createImageIcon(Component c, Icon icon) {
258+
int width = icon.getIconWidth();
259+
int height = icon.getIconHeight();
260+
HTML5Canvas canvas = (HTML5Canvas) DOMNode.createElement("canvas", "tmpIcon");
261+
DOMNode.setStyles(canvas, "width", width + "px", "height", height + "px");
262+
/**
263+
* @j2sNative
264+
*
265+
* canvas.width = width;
266+
* canvas.height = height;
267+
*
268+
*/
269+
JSGraphics2D g = new JSGraphics2D(canvas);
270+
// A JSGraphics2D is not a real Graphics object - must coerce
271+
icon.paintIcon(c, (Graphics)(Object) g, 0, 0);
272+
ColorModel cm = ColorModel.getRGBdefault();
273+
BufferedImage img = new BufferedImage(cm, cm.createCompatibleWritableRaster(width, height), false, null);
274+
img.setImageFromHTML5Canvas(g);
275+
return new ImageIcon(img, "paintedIcon");
276+
}
277+
236278

237279

238280
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import javax.sound.sampled.AudioFormat;
4343
import javax.sound.sampled.Line;
4444
import javax.sound.sampled.UnsupportedAudioFileException;
45+
import javax.swing.Icon;
46+
import javax.swing.ImageIcon;
4547
import javax.swing.JComponent;
4648
import javax.swing.UIDefaults;
4749
import javax.swing.UIManager;
@@ -605,6 +607,10 @@ public Image createImage(ImageProducer producer) {
605607
return kit.getCreatedImage();
606608
}
607609

610+
public ImageIcon createImageIcon(Component c, Icon icon) {
611+
return getImagekit().createImageIcon(c, icon);
612+
}
613+
608614
@Override
609615
public Image createImage(String filename) {
610616
return getImagekit().createImageFromBytes(JSUtil.getSignedStreamBytes(new BufferedInputStream ( new ByteArrayInputStream(JSUtil.getFileAsBytes(filename)))), 0, -1, filename);
@@ -748,7 +754,7 @@ public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
748754
return null;
749755
}
750756

751-
public static void setCursor(Cursor c) {
757+
public static void setCursor(Component comp, Cursor c) {
752758
String curs = null;
753759
switch(c == null ? Cursor.DEFAULT_CURSOR : c.getType()) {
754760
case Cursor.CROSSHAIR_CURSOR:
@@ -787,7 +793,8 @@ public static void setCursor(Cursor c) {
787793
curs = "default";
788794
break;
789795
}
790-
DOMNode.setCursor(curs);
796+
DOMNode.setCursor(curs, comp);
797+
791798
}
792799

793800

@@ -933,4 +940,8 @@ public PrintJob getPrintJob(Frame frame, String jobtitle,
933940
return (PrintJob) (Object) job;
934941
}
935942

943+
public static ImageIcon paintImageForIcon(JComponent c, Icon icon) {
944+
return JSImagekit.createImageIcon(c, icon);
945+
}
946+
936947
}

sources/net.sf.j2s.java.core/src/swingjs/api/js/DOMNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package swingjs.api.js;
22

33
import java.applet.AudioClip;
4+
import java.awt.Component;
45
import java.awt.Image;
56
import java.awt.Rectangle;
67

@@ -236,11 +237,11 @@ public static AudioClip getAudioElement(String filePath, boolean isLoop) {
236237
"controls", "true", (isLoop ? "loop" : null), (isLoop ? "true" : null), "src", filePath);
237238
}
238239

239-
public static void setCursor(String c) {
240+
public static void setCursor(String c, Component comp) {
240241
/**
241242
* @j2sNative
242243
*
243-
* document.body.style.cursor = c;
244+
* if (comp && comp.ui) { comp.ui.getDOMNode().style.cursor = c } else { document.body.style.cursor = c }
244245
*
245246
*/
246247
{}

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.EventObject;
3131

3232
import javax.swing.AbstractButton;
33+
import javax.swing.Icon;
3334
import javax.swing.ImageIcon;
3435
import javax.swing.JComponent;
3536
import javax.swing.SwingConstants;
@@ -744,10 +745,10 @@ protected void propertyChangedCUI(String prop) {
744745
}
745746
if (prop == "icon") {
746747
if (iconNode != null) {
747-
// note that we use AbstratButton cast here just because
748+
// note that we use AbstractButton cast here just because
748749
// it has a getIcon() method. JavaScript will not care if
749750
// it is really a JLabel or JOptionPane, which also have icons
750-
ImageIcon icon = (ImageIcon) ((AbstractButton) c).getIcon();
751+
ImageIcon icon = getIcon(c, null);
751752
if (icon == null ? currentIcon != null : !icon.equals(currentIcon))
752753
setIconAndText(prop, icon, currentGap, currentText);
753754
}
@@ -761,21 +762,29 @@ protected void propertyChangedCUI(String prop) {
761762
System.out.println("JSComponentUI: unrecognized prop: " + this.id + " " + prop);
762763
}
763764

764-
protected void setIconAndText(String prop, ImageIcon icon, int gap, String text) {
765+
private ImageIcon getIcon(JSComponent c, Icon icon) {
766+
return (c == null || icon == null
767+
&& (icon = ((AbstractButton) c).getIcon()) == null ?
768+
null : (icon instanceof ImageIcon) ? (ImageIcon) icon :
769+
JSToolkit.paintImageForIcon(jc, icon));
770+
}
771+
772+
protected void setIconAndText(String prop, Icon icon, int gap, String text) {
765773

766774
// TODO add textPosition
767775

768776
actualWidth = actualHeight = 0;
769-
currentIcon = icon;
770777
currentText = text;
771778
currentGap = gap;
772779
canAlignText = false;
773780
canAlignIcon = false;
781+
currentIcon = null;
774782
imageNode = null;
775783
if (iconNode != null) {
784+
currentIcon = getIcon(jc, icon);
776785
DOMNode.setAttr(iconNode, "innerHTML", "");
777786
if (icon != null) {
778-
imageNode = DOMNode.getImageNode(icon.getImage());
787+
imageNode = DOMNode.getImageNode(currentIcon.getImage());
779788
DOMNode.setStyles(imageNode, "vertical-align", "middle"); // else
780789
// this
781790
// will

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ private class SplitPaneDivider extends JLabel {
8484
protected void fHandleDrag(int dx, int dy, int type) {
8585
switch (type) {
8686
case MouseEvent.MOUSE_PRESSED:
87-
DOMNode.setCursor("nwse-resize");
87+
DOMNode.setCursor("nwse-resize", null);
8888
// set cursor to dragging
8989
break;
9090
case MouseEvent.MOUSE_DRAGGED:
9191
break;
9292
case MouseEvent.MOUSE_RELEASED:
93-
DOMNode.setCursor(null);
93+
DOMNode.setCursor(null, null);
9494
break;
9595
}
9696
}

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSToolTipUI.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package swingjs.plaf;
22

3+
import java.awt.Dimension;
4+
import java.awt.Insets;
5+
36
import javax.swing.JComponent;
47
import javax.swing.JToolTip;
58
import javax.swing.LookAndFeel;
69

10+
import swingjs.api.js.DOMNode;
11+
712
public class JSToolTipUI extends JSLabelUI {
813

914
// TODO: allow generic tool tip, not just text
1015

16+
// note that, however, JSToolTip is not an AbstractButton.
17+
1118
public JSToolTipUI() {
1219
super();
1320
allowTextAlignment = false;
@@ -18,8 +25,14 @@ public JSToolTipUI() {
1825
@Override
1926
protected void getIconAndText() {
2027
icon = null;
28+
iconNode = null; // not an Abstract Button
2129
gap = 0;
22-
text = toolTip.getTipText();
30+
text = toolTip.getTipText();
31+
}
32+
33+
@Override
34+
public Insets getInsets() {
35+
return new Insets(2,2,2,2);
2336
}
2437

2538
@Override
@@ -35,8 +48,6 @@ public void uninstallUI(JComponent jc) {
3548
System.out.println("Uninstalling ToolTipUI");
3649
// should remove dom node?
3750
// TODO Auto-generated method stub
38-
3951
}
4052

41-
4253
}

0 commit comments

Comments
 (0)