diff --git a/sources/net.sf.j2s.core/dist/build-site.xml b/sources/net.sf.j2s.core/dist/build-site.xml
index 6c8918fea..80e3af5a8 100644
--- a/sources/net.sf.j2s.core/dist/build-site.xml
+++ b/sources/net.sf.j2s.core/dist/build-site.xml
@@ -8,6 +8,7 @@
- unzip libjs/*.zip into site/swingjs/j2s
- unzips swingjs/SwingJS-site.zip into site/
- copies non-java resources from resources/ into site/swingjs/j2s
+ - copies site resources from site-resources/ to site/
-->
diff --git a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
index 5e866c8a1..bb63211a6 100644
Binary files a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip differ
diff --git a/sources/net.sf.j2s.core/dist/swingjs/_j2sclasslist.txt b/sources/net.sf.j2s.core/dist/swingjs/_j2sclasslist.txt
index b91ce26be..6190ec887 100644
--- a/sources/net.sf.j2s.core/dist/swingjs/_j2sclasslist.txt
+++ b/sources/net.sf.j2s.core/dist/swingjs/_j2sclasslist.txt
@@ -350,7 +350,6 @@ swingjs/a2s/ScrollPane.js
swingjs/a2s/TextArea.js
swingjs/a2s/TextField.js
swingjs/api/Interface.js
-swingjs/api/JSUtilI.js
swingjs/api/js/DOMNode.js
swingjs/api/js/HTML5CanvasContext2D.js
swingjs/api/js/JSInterface.js
diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp
index 7bbd0f418..2576d6a76 100644
--- a/sources/net.sf.j2s.core/dist/swingjs/timestamp
+++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp
@@ -1 +1 @@
-20200327093924
+20200404075511
diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip
index 5e866c8a1..bb63211a6 100644
Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/SwingJS-site.zip differ
diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/_j2sclasslist.txt b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/_j2sclasslist.txt
index b91ce26be..6190ec887 100644
--- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/_j2sclasslist.txt
+++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/_j2sclasslist.txt
@@ -350,7 +350,6 @@ swingjs/a2s/ScrollPane.js
swingjs/a2s/TextArea.js
swingjs/a2s/TextField.js
swingjs/api/Interface.js
-swingjs/api/JSUtilI.js
swingjs/api/js/DOMNode.js
swingjs/api/js/HTML5CanvasContext2D.js
swingjs/api/js/JSInterface.js
diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp
index 7bbd0f418..2576d6a76 100644
--- a/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp
+++ b/sources/net.sf.j2s.core/dist/swingjs/ver/3.2.9/timestamp
@@ -1 +1 @@
-20200327093924
+20200404075511
diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
index 5e866c8a1..bb63211a6 100644
Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ
diff --git a/sources/net.sf.j2s.java.core/dist/_j2sclasslist.txt b/sources/net.sf.j2s.java.core/dist/_j2sclasslist.txt
index b91ce26be..6190ec887 100644
--- a/sources/net.sf.j2s.java.core/dist/_j2sclasslist.txt
+++ b/sources/net.sf.j2s.java.core/dist/_j2sclasslist.txt
@@ -350,7 +350,6 @@ swingjs/a2s/ScrollPane.js
swingjs/a2s/TextArea.js
swingjs/a2s/TextField.js
swingjs/api/Interface.js
-swingjs/api/JSUtilI.js
swingjs/api/js/DOMNode.js
swingjs/api/js/HTML5CanvasContext2D.js
swingjs/api/js/JSInterface.js
diff --git a/sources/net.sf.j2s.java.core/src/java/awt/Component.java b/sources/net.sf.j2s.java.core/src/java/awt/Component.java
index 6cd192021..64cf9a9f3 100644
--- a/sources/net.sf.j2s.java.core/src/java/awt/Component.java
+++ b/sources/net.sf.j2s.java.core/src/java/awt/Component.java
@@ -51,6 +51,7 @@
import java.awt.event.PaintEvent;
import java.awt.event.TextEvent;
import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
diff --git a/sources/net.sf.j2s.java.core/src/java/awt/EventQueue.java b/sources/net.sf.j2s.java.core/src/java/awt/EventQueue.java
index 4920f77e5..0b5c7ea26 100644
--- a/sources/net.sf.j2s.java.core/src/java/awt/EventQueue.java
+++ b/sources/net.sf.j2s.java.core/src/java/awt/EventQueue.java
@@ -735,15 +735,12 @@ private void dispatchEventImpl(final AWTEvent event, final Object src, boolean a
* @since 1.4
*/
public static long getMostRecentEventTime() {
- return 0;
- // return Toolkit.getEventQueue().getMostRecentEventTimeImpl();
+ return Toolkit.getEventQueue().getMostRecentEventTimeImpl();
}
- // private synchronized long getMostRecentEventTimeImpl() {
- // return (Thread.currentThread() == dispatchThread)
- // ? mostRecentEventTime
- // : System.currentTimeMillis();
- // }
+ private synchronized long getMostRecentEventTimeImpl() {
+ return (Thread.currentThread() == dispatchThread) ? mostRecentEventTime : System.currentTimeMillis();
+ }
/**
* @return most recent event time on all threads.
diff --git a/sources/net.sf.j2s.java.core/src/java/awt/datatransfer/Clipboard.java b/sources/net.sf.j2s.java.core/src/java/awt/datatransfer/Clipboard.java
index 3e6c79e67..2b1d0f640 100644
--- a/sources/net.sf.j2s.java.core/src/java/awt/datatransfer/Clipboard.java
+++ b/sources/net.sf.j2s.java.core/src/java/awt/datatransfer/Clipboard.java
@@ -37,6 +37,7 @@
import java.io.IOException;
import sun.awt.EventListenerAggregate;
+import swingjs.JSUtil;
/**
@@ -127,14 +128,21 @@ public synchronized void setContents(Transferable contents, ClipboardOwner owner
this.owner = owner;
this.contents = contents;
-
- if (oldOwner != null && oldOwner != owner) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- oldOwner.lostOwnership(Clipboard.this, oldContents);
- }
- });
+ if ("System".equals(name) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+ try {
+ String s = (String) contents.getTransferData(DataFlavor.stringFlavor);
+ JSUtil.setClipboardContents(s);
+ } catch (UnsupportedFlavorException | IOException e) {
+ }
}
+
+// if (oldOwner != null && oldOwner != owner) {
+// EventQueue.invokeLater(new Runnable() {
+// public void run() {
+// oldOwner.lostOwnership(Clipboard.this, oldContents);
+// }
+// });
+// }
fireFlavorsChanged();
}
diff --git a/sources/net.sf.j2s.java.core/src/java/awt/event/InvocationEvent.java b/sources/net.sf.j2s.java.core/src/java/awt/event/InvocationEvent.java
index 5ee9e0390..957472e3d 100644
--- a/sources/net.sf.j2s.java.core/src/java/awt/event/InvocationEvent.java
+++ b/sources/net.sf.j2s.java.core/src/java/awt/event/InvocationEvent.java
@@ -232,6 +232,10 @@ public void dispatch() {
exception = (Exception) t;
}
throwable = t;
+ System.err.println("InvocationException: " + t);
+ try {
+ t.printStackTrace();
+ } catch(Throwable e) {}
}
}
else {
diff --git a/sources/net.sf.j2s.java.core/src/java/lang/Class.java b/sources/net.sf.j2s.java.core/src/java/lang/Class.java
index f07a30928..a91827ab0 100644
--- a/sources/net.sf.j2s.java.core/src/java/lang/Class.java
+++ b/sources/net.sf.j2s.java.core/src/java/lang/Class.java
@@ -2490,7 +2490,7 @@ public InputStream getResourceAsStream(String name) {
Clazz.load("java.io.ByteArrayInputStream");
var is = Clazz.new_(java.io.BufferedInputStream.c$$java_io_InputStream, [Clazz.new_(java.io.ByteArrayInputStream.c$$BA, [bytes])]);
is.url = url;
- url._streamData = is;
+ url._streamData = bytes;
return is;
*/
{
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/CellRendererPane.java b/sources/net.sf.j2s.java.core/src/javax/swing/CellRendererPane.java
index 350603c46..35428c60b 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/CellRendererPane.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/CellRendererPane.java
@@ -32,7 +32,9 @@
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Rectangle;
+import java.awt.peer.ComponentPeer;
+import swingjs.api.js.DOMNode;
import swingjs.plaf.JSComponentUI;
/**
@@ -164,9 +166,16 @@ public void paintComponent(Graphics g, Component c, Container p, int x, int y, i
// c.validate();
// }
JSComponentUI ui = ((JComponent) c).秘getUI();
- c.秘reshape(x, y, w, h, false);
+ c.秘reshape(0, 0, w, h, false);
+ // x and y are not used in Component.reshape in SwingJS
+ //c.setLocation(x, y);
+ //ui.setBounds(x, y, 0, 0, ComponentPeer.SET_LOCATION);
((JComponent) c).validateTree();
ui.updateDOMNode();
+ if (p instanceof JTable)
+ DOMNode.setTopLeftAbsolute(ui.domNode, ((JTable) p).getRowMargin() / 2, ((JTable) p).getColumnModel().getColumnMargin() / 2);
+ if (c instanceof JLabel)
+ DOMNode.setStyles(ui.domNode, "overflow", "hidden");
// if (!ui.doPaintBackground())
// return;
// ui.setTainted(false);
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/ImageIcon.java b/sources/net.sf.j2s.java.core/src/javax/swing/ImageIcon.java
index 952342e75..349b45206 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/ImageIcon.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/ImageIcon.java
@@ -33,6 +33,7 @@
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import swingjs.JSGraphics2D;
@@ -126,6 +127,12 @@ public class ImageIcon implements Icon {
* Id used in loading images from MediaTracker.
*/
private static int mediaTrackerID;
+ /**
+ * See JSImageKit
+ *
+ */
+ public ImageIcon 秘tempIcon;
+
private final static Object TRACKER_KEY = new StringBuilder("TRACKER_KEY");
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java b/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java
index a8e7bf441..0be5908bb 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java
@@ -4847,7 +4847,7 @@ public void setTransferHandler(TransferHandler newHandler) {
}
public TransferHandler getTransferHandler() {
- return null;
+ return (TransferHandler)getClientProperty(JComponent_TRANSFER_HANDLER);
}
Object setDropLocation(DropLocation dropLocation, Object state,
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JTable.java b/sources/net.sf.j2s.java.core/src/javax/swing/JTable.java
index 37fef511b..4187b3a75 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/JTable.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/JTable.java
@@ -83,8 +83,6 @@
import swingjs.plaf.CellHolder;
// SwingJS TODO import java.text.DateFormat;
//import sun.swing.SwingLazyValue;
-import swingjs.plaf.JSComponentUI;
-import swingjs.plaf.JSTableUI;
/**
* SwingJS TODO: print/printable all not implemented
@@ -4655,7 +4653,11 @@ private void tableRowsInserted(TableModelEvent e) {
int rh = getRowHeight();
Rectangle drawRect = new Rectangle(0, start * rh, getColumnModel().getTotalColumnWidth(),
(getRowCount() - start) * rh);
+ firePropertyChange("tableAppending", null, e); //$NON-NLS-1$
+ Rectangle r = getVisibleRect();
+ if (drawRect.y > r.y + r.height)
+ return;
revalidate();
// PENDING(milne) revalidate calls 秘repaint() if parent is a ScrollPane
// repaint still required in the unusual case where there is no
@@ -6065,5 +6067,15 @@ public void removeEditor() {
}
}
+ /**
+ * SwingJS method to optionally return null.
+ * @param row
+ * @param col
+ * @param isScrolling
+ * @return the cell renderer or null.
+ */
+ public TableCellRenderer getCellRendererOrNull(int row, int col, boolean isScrolling) {
+ return getCellRenderer(row, col);
+ }
} // End of Class JTable
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java b/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java
index 277a56cbb..05f5bcc9d 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/JTextField.java
@@ -27,7 +27,6 @@
*/
package javax.swing;
-import swingjs.JSToolkit;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Dimension;
@@ -252,7 +251,11 @@ public JTextField(Document doc, String text, int columns) {
this.columns = columns;
if (doc == null) {
doc = createDefaultModel();
- }
+ } else if ((Object) doc == "null") {
+ // SwingJS only
+ doc = new JSPlainDocument();
+ }
+
setDocument(doc);
if (text != null) {
setText(text);
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java b/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java
index a4bc8d157..fcd654bc9 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/JViewport.java
@@ -698,9 +698,9 @@ public void paint(Graphics g)
return;
}
- myClip.width = width;
- myClip.height = height;
- ((JSViewportUI) ui).setClip(myClip);
+ 秘myClip.width = width;
+ 秘myClip.height = height;
+ ((JSViewportUI) ui).setClip(秘myClip);
if (inBlitPaint) {
// We invoked paint as part of copyArea cleanup, let it through.
super.paint(g);
@@ -1625,8 +1625,8 @@ private boolean windowBlitPaint(Graphics g) {
// }
- Rectangle myClip = new Rectangle();
-
+ private Rectangle 秘myClip = new Rectangle();
+
/**
* Called to paint the view, usually when blitPaint
* can not blit.
@@ -1635,20 +1635,18 @@ private boolean windowBlitPaint(Graphics g) {
*/
private void paintView(Graphics g) {
JComponent view = (JComponent)getView();
-
Rectangle clip = g.getClipBounds();
if (view.getWidth() >= getWidth()) {
// Graphics is relative to JViewport, need to map to view's
// coordinates space.
int x = view.getX();
int y = view.getY();// will be negative
- //System.out.println(">>>>painting JView" + x + " " + y + " " +clip);
//Graphics g1 = g.create();
g.translate(x, y);
- myClip.width = clip.width;
- myClip.height = clip.height;
- myClip.x = clip.x - x;
- myClip.y = clip.y - y;
+ 秘myClip.width = clip.width;
+ 秘myClip.height = clip.height;
+ 秘myClip.x = clip.x - x;
+ 秘myClip.y = clip.y - y;
paintForceDoubleBuffered(g, view);
//g.setColor(Math.random() > 0.5 ? Color.GREEN : Color.MAGENTA);
//g.fillRect(-x, 50-y, clip.width, clip.height);
@@ -1657,8 +1655,8 @@ private void paintView(Graphics g) {
//g.setClip(clip.x, clip.y, clip.width, clip.height);
}
else {
- myClip.x = clip.x;
- myClip.y = clip.y;
+ 秘myClip.x = clip.x;
+ 秘myClip.y = clip.y;
// To avoid any problems that may result from the viewport being
// bigger than the view we start painting from the viewport.
try {
@@ -1668,16 +1666,17 @@ private void paintView(Graphics g) {
inBlitPaint = false;
}
}
+
}
private void paintForceDoubleBuffered(Graphics g, JComponent c) {
- g.clipRect(myClip.x, myClip.y, myClip.width, myClip.height);
+ g.clipRect(秘myClip.x, 秘myClip.y, 秘myClip.width, 秘myClip.height);
RepaintManager rm = RepaintManager.currentManager(c);
rm.beginPaint();
秘setFlag(JComponent.秘ISREPAINTING, true);
try {
- rm.paint(c, c, g, myClip.x, myClip.y, myClip.width, myClip.height);
+ rm.paint(c, c, g, 秘myClip.x, 秘myClip.y, 秘myClip.width, 秘myClip.height);
} finally {
rm.endPaint();
秘setFlag(JComponent.秘ISREPAINTING, false);
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/TransferHandler.java b/sources/net.sf.j2s.java.core/src/javax/swing/TransferHandler.java
index aa55de410..2ef5482fa 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/TransferHandler.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/TransferHandler.java
@@ -1699,7 +1699,7 @@ public boolean isEnabled(Object sender) {
//
@Override
public void actionPerformed(final ActionEvent e) {
- final Object src = e.getSource();
+// final Object src = e.getSource();
//
// final PrivilegedAction action = new PrivilegedAction() {
// public Void run() {
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultCaret.java b/sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultCaret.java
index d0954dca0..25ee37c93 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultCaret.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/text/DefaultCaret.java
@@ -1299,7 +1299,9 @@ else if(lastBias != Position.Bias.Backward &&
}
if (lastBias == Position.Bias.Backward && offset > 0) {
try {
- Segment s = new Segment();
+ s.count = 0;
+ s.offset = 0;
+ s.array = null;
component.getDocument().getText(offset - 1, 1, s);
if (s.count > 0 && s.array[s.offset] == '\n') {
lastBias = Position.Bias.Forward;
@@ -1309,6 +1311,8 @@ else if(lastBias != Position.Bias.Backward &&
}
return lastBias;
}
+
+ private static Segment s = new Segment();
// ---- local methods --------------------------------------------
@@ -1778,7 +1782,8 @@ public void insertUpdate(DocumentEvent e) {
Document doc = component.getDocument();
boolean isNewline;
try {
- Segment s = new Segment();
+ s.count = s.offset = 0;
+ s.array = null;
doc.getText(newDot - 1, 1, s);
isNewline = (s.count > 0 &&
s.array[s.offset] == '\n');
diff --git a/sources/net.sf.j2s.java.core/src/javax/swing/text/JTextComponent.java b/sources/net.sf.j2s.java.core/src/javax/swing/text/JTextComponent.java
index be49c7091..3978f1e10 100644
--- a/sources/net.sf.j2s.java.core/src/javax/swing/text/JTextComponent.java
+++ b/sources/net.sf.j2s.java.core/src/javax/swing/text/JTextComponent.java
@@ -31,13 +31,22 @@
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
+import java.awt.EventQueue;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.TextComponent;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DnDConstants;
+import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.InputEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
@@ -47,6 +56,7 @@
import java.io.Reader;
import java.io.Writer;
import java.util.Enumeration;
+import java.util.EventListener;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
@@ -70,6 +80,9 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.EventListenerList;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.event.DocumentEvent.ElementChange;
+import javax.swing.event.DocumentEvent.EventType;
import javax.swing.plaf.TextUI;
import javax.swing.plaf.UIResource;
@@ -422,8 +435,13 @@ protected void fireCaretUpdate(CaretEvent e) {
* expert: true
*/
public void setDocument(Document doc) {
+
Document old = model;
+ if ((Object) doc == "null") {
+ doc = new JSPlainDocument();
+ }
+
/*
* aquire a read lock on the old model to prevent notification of
* mutations while we disconnecting the old model.
@@ -1445,9 +1463,9 @@ public int viewToModel(Point pt) {
*/
public void cut() {
((JSTextUI)this.ui).action("delete", 0);
-// if (isEditable() && isEnabled()) {
-// invokeAction("cut", TransferHandler.getCutAction());
-// }
+ if (isEditable() && isEnabled()) {
+ invokeAction("cut", TransferHandler.getCutAction());
+ }
}
/**
@@ -1460,7 +1478,7 @@ public void cut() {
* @see java.awt.datatransfer.Clipboard
*/
public void copy() {
-// invokeAction("copy", TransferHandler.getCopyAction());
+ invokeAction("copy", TransferHandler.getCopyAction());
}
/**
@@ -1477,48 +1495,48 @@ public void copy() {
*/
public void paste() {
((JSTextUI)this.ui).action("paste", 0);
-// if (isEditable() && isEnabled()) {
-// invokeAction("paste", TransferHandler.getPasteAction());
-// }
+ if (isEditable() && isEnabled()) {
+ invokeAction("paste", TransferHandler.getPasteAction());
+ }
}
-// /**
-// * This is a conveniance method that is only useful for
-// * cut
, copy
and paste
. If
-// * an Action
with the name name
does not
-// * exist in the ActionMap
, this will attemp to install a
-// * TransferHandler
and then use altAction
.
-// */
-// private void invokeAction(String name, Action altAction) {
-// ActionMap map = getActionMap();
-// Action action = null;
-//
-// if (map != null) {
-// action = map.get(name);
-// }
-// if (action == null) {
-// installDefaultTransferHandlerIfNecessary();
-// action = altAction;
-// }
-// action.actionPerformed(new ActionEvent(this,
-// ActionEvent.ACTION_PERFORMED, (String)action.
-// getValue(Action.NAME),
-// EventQueue.getMostRecentEventTime(),
-// getCurrentEventModifiers()));
-// }
+ /**
+ * This is a conveniance method that is only useful for
+ * cut
, copy
and paste
. If
+ * an Action
with the name name
does not
+ * exist in the ActionMap
, this will attemp to install a
+ * TransferHandler
and then use altAction
.
+ */
+ private void invokeAction(String name, Action altAction) {
+ ActionMap map = getActionMap();
+ Action action = null;
-// /**
-// * If the current TransferHandler
is null, this will
-// * install a new one.
-// */
-// private void installDefaultTransferHandlerIfNecessary() {
-// if (getTransferHandler() == null) {
-// if (defaultTransferHandler == null) {
-// defaultTransferHandler = new DefaultTransferHandler();
-// }
-// setTransferHandler(defaultTransferHandler);
-// }
-// }
+ if (map != null) {
+ action = map.get(name);
+ }
+ installDefaultTransferHandlerIfNecessary();
+ if (action == null) {
+ action = altAction;
+ }
+ action.actionPerformed(new ActionEvent(this,
+ ActionEvent.ACTION_PERFORMED, (String)action.
+ getValue(Action.NAME),
+ EventQueue.getMostRecentEventTime(),
+ getCurrentEventModifiers()));
+ }
+
+ /**
+ * If the current TransferHandler
is null, this will
+ * install a new one.
+ */
+ private void installDefaultTransferHandlerIfNecessary() {
+ if (getTransferHandler() == null) {
+ if (defaultTransferHandler == null) {
+ defaultTransferHandler = new DefaultTransferHandler();
+ }
+ setTransferHandler(defaultTransferHandler);
+ }
+ }
/**
* Moves the caret to a new position, leaving behind a mark
@@ -3900,7 +3918,8 @@ public Position.Bias getBias() {
*
* @return a string representation of this drop location
*/
- public String toString() {
+ @Override
+ public String toString() {
return getClass().getName()
+ "[dropPoint=" + getDropPoint() + ","
+ "index=" + index + ","
@@ -3912,10 +3931,10 @@ public String toString() {
// }
}
-// /**
-// * TransferHandler used if one hasn't been supplied by the UI.
-// */
-// private static DefaultTransferHandler defaultTransferHandler;
+ /**
+ * TransferHandler used if one hasn't been supplied by the UI.
+ */
+ private static DefaultTransferHandler defaultTransferHandler;
/**
* Maps from class name to Boolean indicating if
@@ -3960,81 +3979,83 @@ protected String paramString() {
}
-// /**
-// * A Simple TransferHandler that exports the data as a String, and
-// * imports the data from the String clipboard. This is only used
-// * if the UI hasn't supplied one, which would only happen if someone
-// * hasn't subclassed Basic.
-// */
-// static class DefaultTransferHandler extends TransferHandler implements
-// UIResource {
-//// public void exportToClipboard(JComponent comp, Clipboard clipboard,
-//// int action) throws IllegalStateException {
-//// if (comp instanceof JTextComponent) {
-//// JTextComponent text = (JTextComponent)comp;
-//// int p0 = text.getSelectionStart();
-//// int p1 = text.getSelectionEnd();
-//// if (p0 != p1) {
-//// try {
-//// Document doc = text.getDocument();
-//// String srcData = doc.getText(p0, p1 - p0);
-//// StringSelection contents =new StringSelection(srcData);
-////
-//// // this may throw an IllegalStateException,
-//// // but it will be caught and handled in the
-//// // action that invoked this method
-//// clipboard.setContents(contents, null);
-////
-//// if (action == TransferHandler.MOVE) {
-//// doc.remove(p0, p1 - p0);
-//// }
-//// } catch (BadLocationException ble) {}
-//// }
-//// }
-//// }
-//// public boolean importData(JComponent comp, Transferable t) {
-//// if (comp instanceof JTextComponent) {
-//// DataFlavor flavor = getFlavor(t.getTransferDataFlavors());
-////
-//// if (flavor != null) {
-////// InputContext ic = comp.getInputContext();
-////// if (ic != null) {
-////// ic.endComposition();
-////// }
-//// try {
-//// String data = (String)t.getTransferData(flavor);
-////
-//// ((JTextComponent)comp).replaceSelection(data);
-//// return true;
-//// } catch (UnsupportedFlavorException ufe) {
-//// } catch (IOException ioe) {
-//// }
-//// }
-//// }
-//// return false;
-//// }
-//// public boolean canImport(JComponent comp,
-//// DataFlavor[] transferFlavors) {
-//// JTextComponent c = (JTextComponent)comp;
-//// if (!(c.isEditable() && c.isEnabled())) {
-//// return false;
-//// }
-//// return (getFlavor(transferFlavors) != null);
-//// }
-//// public int getSourceActions(JComponent c) {
-//// return DnDConstants.ACTION_NONE;
-//// }
-//// private DataFlavor getFlavor(DataFlavor[] flavors) {
-//// if (flavors != null) {
-//// for (int counter = 0; counter < flavors.length; counter++) {
-//// if (flavors[counter].equals(DataFlavor.stringFlavor)) {
-//// return flavors[counter];
-//// }
-//// }
-//// }
-//// return null;
-//// }
-// }
+ /**
+ * A Simple TransferHandler that exports the data as a String, and
+ * imports the data from the String clipboard. This is only used
+ * if the UI hasn't supplied one, which would only happen if someone
+ * hasn't subclassed Basic.
+ */
+ static class DefaultTransferHandler extends TransferHandler implements
+ UIResource {
+ @Override
+ public void exportToClipboard(JComponent comp, Clipboard clipboard,
+ int action) throws IllegalStateException {
+ if (comp instanceof JTextComponent) {
+ JTextComponent text = (JTextComponent)comp;
+ int p0 = text.getSelectionStart();
+ int p1 = text.getSelectionEnd();
+ if (p0 != p1) {
+ try {
+ Document doc = text.getDocument();
+ String srcData = doc.getText(p0, p1 - p0);
+ StringSelection contents =new StringSelection(srcData);
+
+ // this may throw an IllegalStateException,
+ // but it will be caught and handled in the
+ // action that invoked this method
+ clipboard.setContents(contents, null);
+
+ if (action == TransferHandler.MOVE) {
+ doc.remove(p0, p1 - p0);
+ }
+ } catch (BadLocationException ble) {}
+ }
+ }
+ }
+ public boolean importData(JComponent comp, Transferable t) {
+ if (comp instanceof JTextComponent) {
+ DataFlavor flavor = getFlavor(t.getTransferDataFlavors());
+
+ if (flavor != null) {
+// InputContext ic = comp.getInputContext();
+// if (ic != null) {
+// ic.endComposition();
+// }
+ try {
+ String data = (String)t.getTransferData(flavor);
+ ((JTextComponent)comp).replaceSelection(data);
+ return true;
+ } catch (UnsupportedFlavorException ufe) {
+ } catch (IOException ioe) {
+ }
+ }
+ }
+ return false;
+ }
+ @Override
+ public boolean canImport(JComponent comp,
+ DataFlavor[] transferFlavors) {
+ JTextComponent c = (JTextComponent)comp;
+ if (!(c.isEditable() && c.isEnabled())) {
+ return false;
+ }
+ return (getFlavor(transferFlavors) != null);
+ }
+ @Override
+ public int getSourceActions(JComponent c) {
+ return DnDConstants.ACTION_NONE;
+ }
+ private DataFlavor getFlavor(DataFlavor[] flavors) {
+ if (flavors != null) {
+ for (int counter = 0; counter < flavors.length; counter++) {
+ if (flavors[counter].equals(DataFlavor.stringFlavor)) {
+ return flavors[counter];
+ }
+ }
+ }
+ return null;
+ }
+ }
/**
* Returns the JTextComponent that most recently had focus. The returned
@@ -4045,17 +4066,17 @@ static final JTextComponent getFocusedComponent() {
get(FOCUSED_COMPONENT);
}
-// private int getCurrentEventModifiers() {
-// int modifiers = 0;
-// AWTEvent currentEvent = EventQueue.getCurrentEvent();
-// if (currentEvent instanceof InputEvent) {
-// modifiers = ((InputEvent)currentEvent).getModifiers();
-// } else if (currentEvent instanceof ActionEvent) {
-// modifiers = ((ActionEvent)currentEvent).getModifiers();
-// }
-// return modifiers;
-// }
-//
+ private int getCurrentEventModifiers() {
+ int modifiers = 0;
+ AWTEvent currentEvent = EventQueue.getCurrentEvent();
+ if (currentEvent instanceof InputEvent) {
+ modifiers = ((InputEvent)currentEvent).getModifiers();
+ } else if (currentEvent instanceof ActionEvent) {
+ modifiers = ((ActionEvent)currentEvent).getModifiers();
+ }
+ return modifiers;
+ }
+
private static final String KEYMAP_TABLE = "JTextComponent_KeymapTable";//new Object(); // new StringBuilder("JTextComponent_KeymapTable"
//
// member variables used for on-the-spot input method
@@ -5093,4 +5114,184 @@ public void setTextFromUI(String val) {
// host.setCaretPosition(newPos.getOffset());
// }
// }
+
+ /**
+ * A simple class that implements only the essential aspects of PlainDocument.
+ * No undo/redo, no positioning. Just insert, replace, getLength, getText, and
+ * basic DocumentListener support.
+ *
+ * Nonpublic instantiation.
+ *
+ * @author hansonr
+ *
+ */
+ public class JSPlainDocument implements Document {
+
+ public JSPlainDocument() { }
+
+ class DocEvent implements DocumentEvent {
+
+ private EventType type;
+ private int offset;
+ private int length;
+
+ DocEvent(int offset, int length, EventType type) {
+ this.type = type;
+ this.offset = offset;
+ this.length = length;
+ }
+
+ @Override
+ public int getOffset() {
+ return offset;
+ }
+
+ @Override
+ public int getLength() {
+ return length;
+ }
+
+ @Override
+ public Document getDocument() {
+ return JSPlainDocument.this;
+ }
+
+ @Override
+ public EventType getType() {
+ return type;
+ }
+
+ @Override
+ public ElementChange getChange(Element elem) {
+ return null;
+ }
+
+ }
+
+ private StringBuffer myText = new StringBuffer();
+
+ @Override
+ public int getLength() {
+ return myText.length();
+ }
+
+ @Override
+ public String getText(int offset, int length) throws BadLocationException {
+ return myText.substring(offset, offset + length);
+ }
+
+ @Override
+ public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
+ if ((str == null) || (str.length() == 0)) {
+ return;
+ }
+ myText.insert(offset, str);
+ DocEvent e = new DocEvent(offset, str.length(), DocumentEvent.EventType.INSERT);
+ fireInsertUpdate(e);
+ }
+
+ @Override
+ public void remove(int offs, int len) throws BadLocationException {
+ if (len <= 0)
+ return;
+ if (offs < 0 || (offs + len) > getLength()) {
+ throw new BadLocationException("Invalid remove", getLength() + 1);
+ }
+ myText.replace(offs, len, "");
+ DocEvent chng = new DocEvent(offs, len, DocumentEvent.EventType.REMOVE);
+ fireRemoveUpdate(chng);
+ }
+
+ private EventListenerList listenerList = new EventListenerList();
+
+ private void fireInsertUpdate(DocumentEvent e) {
+ Object[] listeners = listenerList.getListenerList();
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ ((DocumentListener) listeners[i + 1]).insertUpdate(e);
+ }
+ }
+ }
+
+ private void fireRemoveUpdate(DocumentEvent e) {
+ Object[] listeners = listenerList.getListenerList();
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ ((DocumentListener) listeners[i + 1]).removeUpdate(e);
+ }
+ }
+ }
+
+ public T[] getListeners(Class listenerType) {
+ return listenerList.getListeners(listenerType);
+ }
+
+ @Override
+ public void addDocumentListener(DocumentListener listener) {
+ listenerList.add(DocumentListener.class, listener);
+ }
+
+ @Override
+ public void removeDocumentListener(DocumentListener listener) {
+ listenerList.remove(DocumentListener.class, listener);
+ }
+
+ // unimplemented by design:
+
+ char[] achar = new char[0];
+
+ @Override
+ public void getText(int offset, int length, Segment txt) throws BadLocationException {
+ return;
+ }
+
+ @Override
+ public Position getStartPosition() {
+ return null;
+ }
+
+ @Override
+ public Position getEndPosition() {
+ return null;
+ }
+
+ @Override
+ public Position createPosition(int offs) throws BadLocationException {
+ return null;
+ }
+
+ @Override
+ public Element[] getRootElements() {
+ return null;
+ }
+
+ @Override
+ public Element getDefaultRootElement() {
+ return null;
+ }
+
+ @Override
+ public Object getProperty(Object key) {
+ return null;
+ }
+
+ @Override
+ public void putProperty(Object key, Object value) {
+ }
+
+ @Override
+ public void render(Runnable r) {
+ }
+
+ @Override
+ public void addUndoableEditListener(UndoableEditListener listener) {
+ }
+
+ @Override
+ public void removeUndoableEditListener(UndoableEditListener listener) {
+ }
+
+
+ }
+
}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSImagekit.java b/sources/net.sf.j2s.java.core/src/swingjs/JSImagekit.java
index bad9c70be..cb23488d6 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/JSImagekit.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/JSImagekit.java
@@ -262,13 +262,27 @@ public static int getSourceType(byte[] b) {
public static ImageIcon createImageIcon(Component c, Icon icon, String id) {
int width = icon.getIconWidth();
int height = icon.getIconHeight();
- JSGraphics2D g = createCanvasGraphics(width, height, id);
- // A JSGraphics2D is not a real Graphics object - must coerce
+ DOMNode canvas = DOMNode.getElement(id);
+ ImageIcon imgIcon;
+ BufferedImage img;
+ JSGraphics2D g;
+ if (canvas != null && (imgIcon = ((ImageIcon) icon).秘tempIcon) != null && DOMNode.getAttrInt(canvas, "width") == width
+ && DOMNode.getAttrInt(canvas, "height") == height) {
+ // reuse this canvas
+ img = (BufferedImage) imgIcon.getImage();
+ g = img.秘g;
+ } else {
+ g = createCanvasGraphics(width, height, id);
+ // A JSGraphics2D is not a real Graphics object - must coerce
+ ColorModel cm = ColorModel.getRGBdefault();
+ img = new BufferedImage(cm, cm.createCompatibleWritableRaster(width, height), false, null);
+ imgIcon = new ImageIcon(img, "paintedIcon");
+ }
icon.paintIcon(c, (Graphics)(Object) g, 0, 0);
- ColorModel cm = ColorModel.getRGBdefault();
- BufferedImage img = new BufferedImage(cm, cm.createCompatibleWritableRaster(width, height), false, null);
img.setImageFromHTML5Canvas(g);
- return new ImageIcon(img, "paintedIcon");
+ g.dispose();
+ ((ImageIcon) icon).秘tempIcon = imgIcon;
+ return imgIcon;
}
public static JSGraphics2D createCanvasGraphics(int width, int height, String id) {
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java
index c7a075281..8cc3bc9e4 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java
@@ -736,7 +736,7 @@ public static void getFileFromDialog(JSFileHandler jsFileHandler, String type) {
@Override
public Clipboard getSystemClipboard() {
if (systemClipboard == null)
- systemClipboard = (Clipboard) JSUtil.getInstance("java.awt.datatransfer.Clipboard");
+ systemClipboard = new Clipboard("System");
return systemClipboard;
}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java
index e7e014ea3..5ce68baaf 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/JSUtil.java
@@ -5,6 +5,7 @@
import java.awt.Dimension;
import java.awt.JSComponent;
import java.awt.Toolkit;
+import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -748,6 +749,10 @@ public static HTML5Applet getApplet() {
return getHTML5Applet(null);
}
+ public static String getJSClassName(Object o) {
+ return /** @j2sNative o && o.__CLASS_NAME__ ||*/"";
+ }
+
public static String getJSID(Object o) {
/** @j2sNative
@@ -934,5 +939,18 @@ public void setJavaScriptMapObjectEnabled(boolean enabled)
*/
}
+ public static void setClipboardContents(String data) {
+ try {
+ /**
+ * @j2sNative
+ *
+ * navigator.clipboard.writeText(data);
+ *
+ */
+ } catch (Throwable t) {
+ alert(data);
+ }
+ }
+
}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java
index 25d8354a2..be04fbce1 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/a2s/TextField.java
@@ -29,7 +29,7 @@ public TextField(int width) {
}
public TextField(String text, int width) {
- super(text, width);
+ super((Document) (Object) "null", text, width);
}
private static Insets awtInsets = new Insets(0, 1, 0, 1);
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicArrowButton.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicArrowButton.java
index 91f182dc9..c6c80f8c1 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicArrowButton.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicArrowButton.java
@@ -207,7 +207,7 @@ public Dimension getMinimumSize() {
*/
@Override
public Dimension getMaximumSize() {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+ return JSComponentUI.ANY_SIZE;
}
/**
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicTransferable.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicTransferable.java
new file mode 100644
index 000000000..36bafc6e6
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/BasicTransferable.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package swingjs.plaf;
+
+import sun.awt.datatransfer.DataTransferer;
+
+import java.io.*;
+import java.awt.datatransfer.*;
+import javax.swing.plaf.UIResource;
+
+/**
+ * A transferable implementation for the default data transfer of some Swing
+ * components.
+ *
+ * @author Timothy Prinzing
+ */
+class BasicTransferable implements Transferable, UIResource {
+
+ protected String plainData;
+ protected String htmlData;
+
+ private static DataFlavor[] htmlFlavors;
+ private static DataFlavor[] stringFlavors;
+ private static DataFlavor[] plainFlavors;
+
+ static {
+ try {
+ htmlFlavors = new DataFlavor[3];
+ htmlFlavors[0] = new DataFlavor("text/html;class=java.lang.String");
+ htmlFlavors[1] = new DataFlavor("text/html;class=java.io.Reader");
+ htmlFlavors[2] = new DataFlavor("text/html;charset=unicode;class=java.io.InputStream");
+
+ plainFlavors = new DataFlavor[3];
+ plainFlavors[0] = new DataFlavor("text/plain;class=java.lang.String");
+ plainFlavors[1] = new DataFlavor("text/plain;class=java.io.Reader");
+ plainFlavors[2] = new DataFlavor("text/plain;charset=unicode;class=java.io.InputStream");
+
+ stringFlavors = new DataFlavor[2];
+ stringFlavors[0] = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+";class=java.lang.String");
+ stringFlavors[1] = DataFlavor.stringFlavor;
+
+ } catch (ClassNotFoundException cle) {
+ System.err.println("error initializing javax.swing.plaf.basic.BasicTranserable");
+ }
+ }
+
+ public BasicTransferable(String plainData, String htmlData) {
+ this.plainData = plainData;
+ this.htmlData = htmlData;
+ }
+
+
+ /**
+ * Returns an array of DataFlavor objects indicating the flavors the data
+ * can be provided in. The array should be ordered according to preference
+ * for providing the data (from most richly descriptive to least descriptive).
+ * @return an array of data flavors in which this data can be transferred
+ */
+ public DataFlavor[] getTransferDataFlavors() {
+ //DataFlavor[] richerFlavors = getRicherFlavors();
+ int nRicher = 0;// (richerFlavors != null) ? richerFlavors.length : 0;
+ int nHTML = (isHTMLSupported()) ? htmlFlavors.length : 0;
+ int nPlain = (isPlainSupported()) ? plainFlavors.length: 0;
+ int nString = (isPlainSupported()) ? stringFlavors.length : 0;
+ int nFlavors = nRicher + nHTML + nPlain + nString;
+ DataFlavor[] flavors = new DataFlavor[nFlavors];
+
+ // fill in the array
+ int nDone = 0;
+// if (nRicher > 0) {
+// System.arraycopy(richerFlavors, 0, flavors, nDone, nRicher);
+// nDone += nRicher;
+// }
+ if (nHTML > 0) {
+ System.arraycopy(htmlFlavors, 0, flavors, nDone, nHTML);
+ nDone += nHTML;
+ }
+ if (nPlain > 0) {
+ System.arraycopy(plainFlavors, 0, flavors, nDone, nPlain);
+ nDone += nPlain;
+ }
+ if (nString > 0) {
+ System.arraycopy(stringFlavors, 0, flavors, nDone, nString);
+ nDone += nString;
+ }
+ return flavors;
+ }
+
+ /**
+ * Returns whether or not the specified data flavor is supported for
+ * this object.
+ * @param flavor the requested flavor for the data
+ * @return boolean indicating whether or not the data flavor is supported
+ */
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ DataFlavor[] flavors = getTransferDataFlavors();
+ for (int i = 0; i < flavors.length; i++) {
+ if (flavors[i].equals(flavor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns an object which represents the data to be transferred. The class
+ * of the object returned is defined by the representation class of the flavor.
+ *
+ * @param flavor the requested flavor for the data
+ * @see DataFlavor#getRepresentationClass
+ * @exception IOException if the data is no longer available
+ * in the requested flavor.
+ * @exception UnsupportedFlavorException if the requested data flavor is
+ * not supported.
+ */
+ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
+// DataFlavor[] richerFlavors = getRicherFlavors();
+// if (isRicherFlavor(flavor)) {
+// return getRicherData(flavor);
+// } else
+ if (isHTMLFlavor(flavor)) {
+ String data = getHTMLData();
+ data = (data == null) ? "" : data;
+ if (String.class.equals(flavor.getRepresentationClass())) {
+ return data;
+ } else if (Reader.class.equals(flavor.getRepresentationClass())) {
+ return new StringReader(data);
+ } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
+ return createInputStream(flavor, data);
+ }
+ // fall through to unsupported
+ } else if (isPlainFlavor(flavor)) {
+ String data = getPlainData();
+ data = (data == null) ? "" : data;
+ if (String.class.equals(flavor.getRepresentationClass())) {
+ return data;
+ } else if (Reader.class.equals(flavor.getRepresentationClass())) {
+ return new StringReader(data);
+ } else if (InputStream.class.equals(flavor.getRepresentationClass())) {
+ return createInputStream(flavor, data);
+ }
+ // fall through to unsupported
+
+ } else if (isStringFlavor(flavor)) {
+ String data = getPlainData();
+ data = (data == null) ? "" : data;
+ return data;
+ }
+ throw new UnsupportedFlavorException(flavor);
+ }
+
+ private InputStream createInputStream(DataFlavor flavor, String data)
+ throws IOException, UnsupportedFlavorException {
+ String cs = DataTransferer.getTextCharset(flavor);
+ if (cs == null) {
+ throw new UnsupportedFlavorException(flavor);
+ }
+ return new ByteArrayInputStream(data.getBytes(cs));
+ }
+//
+// // --- richer subclass flavors ----------------------------------------------
+//
+// protected boolean isRicherFlavor(DataFlavor flavor) {
+// DataFlavor[] richerFlavors = getRicherFlavors();
+// int nFlavors = (richerFlavors != null) ? richerFlavors.length : 0;
+// for (int i = 0; i < nFlavors; i++) {
+// if (richerFlavors[i].equals(flavor)) {
+// return true;
+// }
+// }
+// return false;
+// }
+//
+// /**
+// * Some subclasses will have flavors that are more descriptive than HTML
+// * or plain text. If this method returns a non-null value, it will be
+// * placed at the start of the array of supported flavors.
+// */
+// protected DataFlavor[] getRicherFlavors() {
+// return null;
+// }
+//
+// protected Object getRicherData(DataFlavor flavor) throws UnsupportedFlavorException {
+// return null;
+// }
+
+ // --- html flavors ----------------------------------------------------------
+
+ /**
+ * Returns whether or not the specified data flavor is an HTML flavor that
+ * is supported.
+ * @param flavor the requested flavor for the data
+ * @return boolean indicating whether or not the data flavor is supported
+ */
+ protected boolean isHTMLFlavor(DataFlavor flavor) {
+ DataFlavor[] flavors = htmlFlavors;
+ for (int i = 0; i < flavors.length; i++) {
+ if (flavors[i].equals(flavor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Should the HTML flavors be offered? If so, the method
+ * getHTMLData should be implemented to provide something reasonable.
+ */
+ protected boolean isHTMLSupported() {
+ return htmlData != null;
+ }
+
+ /**
+ * Fetch the data in a text/html format
+ */
+ protected String getHTMLData() {
+ return htmlData;
+ }
+
+ // --- plain text flavors ----------------------------------------------------
+
+ /**
+ * Returns whether or not the specified data flavor is an plain flavor that
+ * is supported.
+ * @param flavor the requested flavor for the data
+ * @return boolean indicating whether or not the data flavor is supported
+ */
+ protected boolean isPlainFlavor(DataFlavor flavor) {
+ DataFlavor[] flavors = plainFlavors;
+ for (int i = 0; i < flavors.length; i++) {
+ if (flavors[i].equals(flavor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Should the plain text flavors be offered? If so, the method
+ * getPlainData should be implemented to provide something reasonable.
+ */
+ protected boolean isPlainSupported() {
+ return plainData != null;
+ }
+
+ /**
+ * Fetch the data in a text/plain format.
+ */
+ protected String getPlainData() {
+ return plainData;
+ }
+
+ // --- string flavorss --------------------------------------------------------
+
+ /**
+ * Returns whether or not the specified data flavor is a String flavor that
+ * is supported.
+ * @param flavor the requested flavor for the data
+ * @return boolean indicating whether or not the data flavor is supported
+ */
+ protected boolean isStringFlavor(DataFlavor flavor) {
+ DataFlavor[] flavors = stringFlavors;
+ for (int i = 0; i < flavors.length; i++) {
+ if (flavors[i].equals(flavor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/HTML5LookAndFeel.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/HTML5LookAndFeel.java
index fc3e2067c..06288b007 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/HTML5LookAndFeel.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/HTML5LookAndFeel.java
@@ -32,7 +32,6 @@
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
-import java.awt.JSComponent;
import javax.swing.DefaultListCellRenderer;
import javax.swing.LookAndFeel;
@@ -1952,7 +1951,7 @@ public Object createValue(UIDefaults table) {
// "TextArea.selectionForeground", textHighlightText,
// "TextArea.caretForeground", textText,
// "TextArea.caretBlinkRate", caretBlinkRate,
- // "TextArea.border", marginBorder,
+ //"TextArea.border", marginBorder,
"TextArea.margin",
zeroInsets,
@@ -1967,7 +1966,7 @@ public Object createValue(UIDefaults table) {
// "TextPane.caretForeground", textText,
// "TextPane.caretBlinkRate", caretBlinkRate,
"TextPane.inactiveForeground", disabledTextColor,
- // "TextPane.border", marginBorder,
+ "TextPane.border", marginBorder,
"TextPane.margin",
editorMargin,
"TextPane.focusInputMap", multilineInputMap,
@@ -1983,7 +1982,7 @@ public Object createValue(UIDefaults table) {
// "EditorPane.caretForeground", textText,
// "EditorPane.caretBlinkRate", caretBlinkRate,
"EditorPane.inactiveForeground", disabledTextColor,
- // "EditorPane.border", marginBorder,
+ "EditorPane.border", marginBorder,
"EditorPane.margin",
editorMargin,
"EditorPane.focusInputMap", multilineInputMap,
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java
index a58f6e157..4a67a9c3d 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java
@@ -1802,6 +1802,8 @@ protected Dimension getCSSAdjustment(boolean addingCSS) {
return new Dimension(0, 0);
}
+ protected static Dimension ANY_SIZE = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+
/**
* Creates the DOM node and inserts it into the tree at the correct place,
* iterating through all children if this is a container.
@@ -1845,21 +1847,9 @@ protected DOMNode setHTMLElementCUI() {
if (n == 0)
return outerNode;
}
-
if (outerNode == null)
- outerNode = wrap("div", id, domNode);
-
- /**
- * @j2sNative
- *
- * this.outerNode.setAttribute("name", this.jc.__CLASS_NAME__);
- */
- {
- }
- // set position
-
+ createOuterNode();
setOuterLocationFromComponent();
-
if (n > 0 && containerNode == null)
containerNode = outerNode;
if (isContainer || n > 0) {
@@ -1909,6 +1899,15 @@ && isFrameIndependent() && !isSticky) {
return outerNode;
}
+ private void createOuterNode() {
+ outerNode = wrap("div", id, domNode);
+ @SuppressWarnings("unused")
+ JComponent c = jc;
+ String s = (/** @j2sNative c.__CLASS_NAME__|| */"");
+ outerNode.setAttribute("name", s);
+ }
+
+
protected boolean isFrameIndependent() {
return true;
}
@@ -1947,7 +1946,8 @@ protected void addChildrenToDOM(Component[] children, int n) {
}
ui.parent = this;
if (ui.getOuterNode() == null) {
- System.out.println("JSCUI addChildren no outer node for " + ui.id);
+ if (ui.domNode != null)
+ System.out.println("JSCUI addChildren no outer node for " + ui.id);
} else {
if (ui.domNode != ui.outerNode && DOMNode.getParent(ui.domNode) == null)
ui.outerNode.appendChild(ui.domNode);
@@ -2265,10 +2265,12 @@ protected void getDisabledColors(String pp) {
}
@Override
- final public void setBounds(int x, int y, int width, int height, int op) {
- // note that x and y are completely ignored.
+ public void setBounds(int x, int y, int width, int height, int op) {
+ // note that x and y are completely ignored.
if (isUIDisabled)
return;
+
+
boolean isBounded = (width > 0 && height > 0);
if (isBounded && !boundsSet) {
// now we can set it to be visible, because its bounds have
@@ -2317,7 +2319,7 @@ private void setOuterLocationFromComponent() {
&& parent.outerNode != null)
DOMNode.appendChildSafely(parent.outerNode, outerNode);
DOMNode.setPositionAbsolute(outerNode);
- DOMNode.setStyles(outerNode, "left", (x = c.getX()) + "px", "top", (y = c.getY()) + "px");
+ DOMNode.setStyles(outerNode, "left", (x = c.getX()) + "px", "top", (y = c.getY()) + "px");
}
}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java
index 64dc3370a..ca7678196 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSEditorPaneUI.java
@@ -11,8 +11,11 @@
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
import javax.swing.event.CaretEvent;
import javax.swing.plaf.InputMapUIResource;
+import javax.swing.plaf.UIResource;
import javax.swing.text.AbstractDocument.BranchElement;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
@@ -224,6 +227,14 @@ public DOMNode updateDOMNode() {
return updateDOMNodeCUI();
}
+ @Override
+ protected void setBorder(String prefix) {
+ Border b = editor.getBorder();
+ if ((b == null) || (b instanceof UIResource)) {
+ editor.setBorder(UIManager.getBorder(prefix + ".border"));
+ }
+ }
+
@Override
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java
index d7c0a15a4..c0354df77 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSSplitPaneUI.java
@@ -1374,7 +1374,7 @@ public void invalidateLayout(Container c) {
*/
@Override
public Dimension maximumLayoutSize(Container target) {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
+ return ANY_SIZE;
}
//
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableUI.java
index 568e95ee4..62e6ab752 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableUI.java
@@ -33,11 +33,13 @@
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
+import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.JSComponent;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
@@ -83,7 +85,6 @@
import sun.swing.SwingUtilities2;
import sun.swing.UIAction;
import swingjs.JSMouse;
-import swingjs.JSUtil;
import swingjs.api.js.DOMNode;
/**
@@ -162,15 +163,18 @@ public void beginLayout() {
super.beginLayout();
}
+ @Override
+ public void setBounds(int x, int y, int w, int h, int op) {
+ //if (getScrollPane() == null)
+ enableTable(true);
+ super.setBounds(x, y, w, h, op);
+ }
@Override
public void endLayout() {
super.endLayout();
currentRowMin = currentRowMax = -1;
justLaidOut = true;
- JSTableHeaderUI hui = getHeaderUI();
- if (hui != null)
- hui.setUIDisabled(false);
- setUIDisabled(false);
+ enableTable(true);
}
@Override
@@ -211,18 +215,12 @@ public void setTainted() {
@Override
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
- // System.out.println("JSTableUI prop=" + prop);
- JSTableHeaderUI hui;
switch (prop) {
case "model":
currentRowMin = currentRowMax = -1;
isLaidOut = false;
setHTMLElement();
- // System.out.println(e.getNewValue());
- hui = this.getHeaderUI();
- if (hui != null)
- hui.setUIDisabled(true);
- setUIDisabled(true);
+ enableTable(false);
JScrollPane sp = getScrollPane();
if (sp != null) {
sp.getVerticalScrollBar().setValue(0);
@@ -245,10 +243,23 @@ public void propertyChange(PropertyChangeEvent e) {
// TODO ?
return;
}
- System.out.println("JTableUI property not handled: " + prop);
+ //System.out.println("JTableUI property not handled: " + prop);
super.propertyChange(e);
}
+ private void enableTable(boolean b) {
+ JSTableHeaderUI hui = this.getHeaderUI();
+ if (hui != null)
+ hui.setUIDisabled(!b);
+ setUIDisabled(!b);
+ }
+
+ private JSTableHeaderUI getHeaderUI() {
+ JTableHeader th = table.getTableHeader();
+ return (th == null ? null : (JSTableHeaderUI) th.getUI());
+ }
+
+
/**
* Each cell is controlled by a single renderer, but each renderer may control
* any number of cells in any number of tables. So in this case there is no 1:1
@@ -306,21 +317,30 @@ protected void addChildrenToDOM(Component[] children, int n) {
if (currentRowMin == -1) {
setHidden(true);
havePainted = false;
- int nrows = table.getRowCount();
int ncols = table.getColumnCount();
- int h = table.getRowHeight();
+ int rowCount = table.getRowCount();
int[] cw = getColumnWidths();
int rminy, rmaxy, rminx, rmaxx;
table.computeVisibleRect(tmpRect);
rminx = tmpRect.x;
rmaxx = tmpRect.x + tmpRect.width;
- // DOMNode.setStyles(outerNode, "overflow", "hidden", "height", th + "px");
+ int h = table.getRowHeight();
+
+ if (getScrollPane() == null) {
+ int height = 0;
+ if (rowCount > 0 && ncols > 0) {
+ Rectangle r = table.getCellRect(rowCount - 1, 0, true);
+ height = r.y + r.height;
+ DOMNode.setStyles(outerNode, "overflow", "hidden", "height", height + "px");
+ }
+ }
+
$(domNode).empty();
rminy = tmpRect.y;
rmaxy = tmpRect.y + tmpRect.height;
if (tmpRect.height != 0) {
currentRowMin = 0;
- addElements(rminx, rminy, rmaxx, rmaxy, cw, h, 0, nrows, 0, ncols);
+ addElements(rminx, rminy, rmaxx, rmaxy, cw, h, 0, rowCount, 0, ncols);
}
}
}
@@ -484,6 +504,8 @@ private void notifyEntry(boolean isEntry) {
private boolean isFileList = false;
public boolean dragging;
+ private boolean isNewModel;
+
//
// Helper class for keyboard actions
//
@@ -786,7 +808,7 @@ public void actionPerformed(ActionEvent e) {
this.dy = 0;
}
} else {
- if (!(table.getParent().getParent() instanceof JScrollPane)) {
+ if (((JSTableUI) table.秘getUI()).getScrollPane() == null) {
return;
}
@@ -1174,12 +1196,15 @@ public void focusLost(FocusEvent e) {
}
// KeyListener
+ @Override
public void keyPressed(KeyEvent e) {
}
+ @Override
public void keyReleased(KeyEvent e) {
}
+ @Override
public void keyTyped(KeyEvent e) {
KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyChar(), e.getModifiers());
@@ -1301,8 +1326,8 @@ private void setValueIsAdjusting(boolean flag) {
// delivered if DnD is cancelled (via ESCAPE for example)
private boolean dragStarted;
- // Whether or not we should start the editing timer on release
- private boolean shouldStartTimer;
+// // Whether or not we should start the editing timer on release
+// private boolean shouldStartTimer;
// To cache the return value of pointOutsidePrefSize since we use
// it multiple times.
@@ -1351,10 +1376,10 @@ public void mousePressed(MouseEvent e) {
pressedCol = table.columnAtPoint(p);
outsidePrefSize = pointOutsidePrefSize(pressedRow, pressedCol, p);
- if (isFileList) {
- shouldStartTimer = table.isCellSelected(pressedRow, pressedCol) && !e.isShiftDown()
- && !e.isControlDown() && !outsidePrefSize;
- }
+// if (isFileList) {
+// shouldStartTimer = table.isCellSelected(pressedRow, pressedCol) && !e.isShiftDown()
+// && !e.isControlDown() && !outsidePrefSize;
+// }
if (table.getDragEnabled()) {
mousePressedDND(e);
@@ -1582,29 +1607,28 @@ public void mouseDragged(MouseEvent e) {
// PropertyChangeListener
@Override
public void propertyChange(PropertyChangeEvent event) {
- String changeName = event.getPropertyName();
- if ("tableCellEditor" == changeName) {
-
-// System.err.println("JSTABLEUI TABLECELLEDITOR " + event.getNewValue());
-
+ switch (event.getPropertyName()) {
+ case "tableCellEditor":
prepareDOMEditor(event.getNewValue() != null, pressedRow, pressedCol);
- } else if ("componentOrientation" == changeName) {
+ break;
+ case "componentOrientation":
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
-
SwingUtilities.replaceUIInputMap(table, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
-
JTableHeader header = table.getTableHeader();
if (header != null) {
header.setComponentOrientation((ComponentOrientation) event.getNewValue());
}
- } else if ("model" == changeName) {
-
- } else if ("dropLocation" == changeName) {
+ break;
+ case "model":
+ newModel();
+ break;
+ case "dropLocation":
rebuildTable();
// JTable.DropLocation oldValue = (JTable.DropLocation)event.getOldValue();
// repaintDropLocation(oldValue);
// repaintDropLocation(table.getDropLocation());
- } else if ("Table.isFileList" == changeName) {
+ break;
+ case "Table.isFileList":
isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"));
table.revalidate();
table.秘repaint();
@@ -1614,12 +1638,14 @@ public void propertyChange(PropertyChangeEvent event) {
table.getSelectionModel().removeListSelectionListener(getHandler());
timer = null;
}
- } else if ("selectionModel" == changeName) {
+ break;
+ case "selectionModel":
if (isFileList) {
ListSelectionModel old = (ListSelectionModel) event.getOldValue();
old.removeListSelectionListener(getHandler());
table.getSelectionModel().addListSelectionListener(getHandler());
}
+ break;
}
}
@@ -1652,6 +1678,22 @@ public void propertyChange(PropertyChangeEvent event) {
// }
}
+ public void rebuildTable() {
+ setTainted();
+ currentRowMin = -1;
+ setHTMLElement();
+ rebuildHeader();
+ }
+
+ private void rebuildHeader() {
+ JSComponentUI ui = getHeaderUI();
+ if (ui != null) {
+ ui.setTainted();
+ ui.setHTMLElement();
+ table.getTableHeader().秘repaint();
+ }
+ }
+
/*
* Returns true if the given point is outside the preferredSize of the item at
* the given row of the table. (Column must be 0). Returns false if the
@@ -1665,6 +1707,14 @@ private boolean pointOutsidePrefSize(int row, int column, Point p) {
return SwingUtilities2.pointOutsidePrefSize(table, row, column, p);
}
+ public void newModel() {
+ isNewModel = true;
+ }
+
+ public boolean haveSrollPane() {
+ return (table.getParent().getParent() instanceof JScrollPane);
+ }
+
public void repaintCell(int lr, int lc) {
table._getCellRect(lr, lc, false, tmpRect);
table.repaint(tmpRect);
@@ -1767,22 +1817,26 @@ protected void installDefaults() {
isFileList = Boolean.TRUE.equals(table.getClientProperty("Table.isFileList"));
}
- private JScrollPane getScrollPane() {
+ JScrollPane getScrollPane() {
Container parent;
parent = ((parent = table.getParent()) == null ? null : parent.getParent());
return (parent instanceof JScrollPane ? (JScrollPane) parent : null);
}
private void installDefaults2() {
-// TransferHandler th = table.getTransferHandler();
-// if (th == null || th instanceof UIResource) {
-// table.setTransferHandler(defaultTransferHandler);
-// // default TransferHandler doesn't support drop
-// // so we don't want drop handling
-// if (table.getDropTarget() instanceof UIResource) {
-// table.setDropTarget(null);
-// }
-// }
+ //installTransferHandlerIfNeeded();
+ }
+
+ public void installDefaultTransferHandlerIfNecessary() {
+ TransferHandler th = table.getTransferHandler();
+ if (th == null || th instanceof UIResource) {
+ table.setTransferHandler(defaultTransferHandler);
+ // default TransferHandler doesn't support drop
+ // so we don't want drop handling
+ if (table.getDropTarget() instanceof UIResource) {
+ table.setDropTarget(null);
+ }
+ }
}
/**
@@ -2061,10 +2115,14 @@ public void paint(Graphics g, JComponent c) {
//table.getFillsViewportHeight();
Rectangle clip = getClip();
-
+ int rc = table.getRowCount();
+ int rh = table.getRowHeight();
+ if (getScrollPane() != null) {
+ DOMNode.setStyles(outerNode, "overflow", "hidden", "height", (rc * rh) + "px");
+ }
table.computeVisibleRect(tmpRect);
- if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
+ if (rc <= 0 || table.getColumnCount() <= 0 ||
// this check prevents us from painting the entire table
// when the clip doesn't intersect our bounds at all
!tmpRect.intersects(clip)) {
@@ -2080,6 +2138,8 @@ public void paint(Graphics g, JComponent c) {
int rMin = table.rowAtPoint(upperLeft);
int rMax = table.rowAtPoint(lowerRight);
+ // happens after new model when scrollbar is not at 0
+
// This should never happen (as long as our bounds intersect the clip,
// which is why we bail above if that is the case).
if (rMin == -1) {
@@ -2090,16 +2150,15 @@ public void paint(Graphics g, JComponent c) {
// which is why we bail above if that is the case).
// Replace this with the index of the last row.
if (rMax == -1) {
- rMax = table.getRowCount() - 1;
+ rMax = rc - 1;
}
-
resized = (tmpRect.width != lastWidth);
if (resized) {
// table has been resized
if (rMax - rMin > 1) {
JScrollPane sp = getScrollPane();
if (sp != null) {
- int val = Math.max(1, (rMax - rMin - 1) * table.getRowHeight());
+ int val = Math.max(1, (rMax - rMin - 1) * rh);
sp.getVerticalScrollBar().setBlockIncrement(val);
sp.getVerticalScrollBar().setUnitIncrement((val + 1) / 2);
@@ -2114,11 +2173,10 @@ public void paint(Graphics g, JComponent c) {
JSTableHeaderUI hui = getHeaderUI();
if (hui != null)
hui.paint(g, c);
- table.repaint(tmpRect);
+ table.repaint();//tmpRect);
return;
}
}
-
working = true;
boolean ltr = table.getComponentOrientation().isLeftToRight();
@@ -2171,7 +2229,12 @@ public void paint(Graphics g, JComponent c) {
private Rectangle myClip = new Rectangle();
private Rectangle getClip() {
if (table.parent instanceof JViewport) {
- return ((JSViewportUI)table.parent.getUI()).myClip;
+ JSViewportUI ui = ((JSViewportUI)table.parent.getUI());
+ if (isNewModel) {
+ ui.myClip.x = ui.myClip.y = 0;
+ isNewModel = false;
+ }
+ return ui.myClip;
}
myClip.width = table.getWidth();
myClip.height = table.getHeight();
@@ -2179,7 +2242,6 @@ private Rectangle getClip() {
}
private void paintCells(Graphics g, int rMin0, int rMax0, int rMin, int rMax, int cMin, int cMax) {
-
TableColumnModel cm = table.getColumnModel();
int columnMargin = cm.getColumnMargin();
@@ -2261,11 +2323,12 @@ private void paintCell(Graphics g, Rectangle cellRect, int row, int col, int[] c
row + 1, col, col + 1);
}
boolean fullPaint = (newtd || !havePainted || !isScrolling || table.getSelectedRowCount() > 0);
- TableCellRenderer renderer = table.getCellRenderer(row, col);
+ TableCellRenderer renderer = (fullPaint ? table.getCellRenderer(row, col)
+ : table.getCellRendererOrNull(row, col, isScrolling));
if (!fullPaint) {
// no need to paint the default renderers with nothing selected
/**
- * @j2sNative if (renderer.__CLASS_NAME__.indexOf("javax.swing.") == 0) return;
+ * @j2sNative if (!renderer || renderer.__CLASS_NAME__.indexOf("javax.swing.") == 0) return;
*/
}
JComponent comp = (JComponent) getCellComponent(renderer, row, col, cw[col], h, td, fullPaint);
@@ -2471,110 +2534,107 @@ private static int getAdjustedLead(JTable table, boolean row) {
: getAdjustedLead(table, row, table.getColumnModel().getSelectionModel());
}
-//
-// private static final TransferHandler defaultTransferHandler = new TableTransferHandler();
-//
-// static class TableTransferHandler extends TransferHandler implements UIResource {
-//
-// /**
-// * Create a Transferable to use as the source for a data transfer.
-// *
-// * @param c The component holding the data to be transfered. This
-// * argument is provided to enable sharing of TransferHandlers by
-// * multiple components.
-// * @return The representation of the data to be transfered.
-// *
-// */
-// protected Transferable createTransferable(JComponent c) {
-// if (c instanceof JTable) {
-// JTable table = (JTable) c;
-// int[] rows;
-// int[] cols;
-//
-// if (!table.getRowSelectionAllowed() && !table.getColumnSelectionAllowed()) {
-// return null;
-// }
-//
-// if (!table.getRowSelectionAllowed()) {
-// int rowCount = table.getRowCount();
-//
-// rows = new int[rowCount];
-// for (int counter = 0; counter < rowCount; counter++) {
-// rows[counter] = counter;
-// }
-// } else {
-// rows = table.getSelectedRows();
-// }
-//
-// if (!table.getColumnSelectionAllowed()) {
-// int colCount = table.getColumnCount();
-//
-// cols = new int[colCount];
-// for (int counter = 0; counter < colCount; counter++) {
-// cols[counter] = counter;
-// }
-// } else {
-// cols = table.getSelectedColumns();
-// }
-//
-// if (rows == null || cols == null || rows.length == 0 || cols.length == 0) {
-// return null;
-// }
-//
-// StringBuffer plainBuf = new StringBuffer();
-// StringBuffer htmlBuf = new StringBuffer();
-//
-// htmlBuf.append("\n\n\n");
-//
-// for (int row = 0; row < rows.length; row++) {
-// htmlBuf.append("\n");
-// for (int col = 0; col < cols.length; col++) {
-// Object obj = table.getValueAt(rows[row], cols[col]);
-// String val = ((obj == null) ? "" : obj.toString());
-// plainBuf.append(val + "\t");
-// htmlBuf.append(" " + val + " | \n");
-// }
-// // we want a newline at the end of each line and not a tab
-// plainBuf.deleteCharAt(plainBuf.length() - 1).append("\n");
-// htmlBuf.append("
\n");
-// }
-//
-// // remove the last newline
-// plainBuf.deleteCharAt(plainBuf.length() - 1);
-// htmlBuf.append("
\n\n");
-//
-// return new BasicTransferable(plainBuf.toString(), htmlBuf.toString());
-// }
-//
-// return null;
-// }
-//
-// public int getSourceActions(JComponent c) {
-// return COPY;
-// }
-//
-// }
-//
- public void rebuildTable() {
- setTainted();
- currentRowMin = -1;
- setHTMLElement();
- rebuildHeader();
- }
+ private static final TransferHandler defaultTransferHandler = new TableTransferHandler();
- private void rebuildHeader() {
- JSComponentUI ui = getHeaderUI();
- if (ui != null) {
- ui.setTainted();
- ui.setHTMLElement();
- table.getTableHeader().秘repaint();
+ static class TableTransferHandler extends TransferHandler implements UIResource {
+
+ /**
+ * Create a Transferable to use as the source for a data transfer.
+ *
+ * @param c The component holding the data to be transfered. This argument is
+ * provided to enable sharing of TransferHandlers by multiple
+ * components.
+ * @return The representation of the data to be transfered.
+ *
+ */
+ @Override
+ protected Transferable createTransferable(JComponent c) {
+ if (c instanceof JTable) {
+ JTable table = (JTable) c;
+ int[] rows;
+ int[] cols;
+
+ if (!table.getRowSelectionAllowed() && !table.getColumnSelectionAllowed()) {
+ return null;
+ }
+
+ if (!table.getRowSelectionAllowed()) {
+ int rowCount = table.getRowCount();
+
+ rows = new int[rowCount];
+ for (int counter = 0; counter < rowCount; counter++) {
+ rows[counter] = counter;
+ }
+ } else {
+ rows = table.getSelectedRows();
+ }
+
+ if (!table.getColumnSelectionAllowed()) {
+ int colCount = table.getColumnCount();
+
+ cols = new int[colCount];
+ for (int counter = 0; counter < colCount; counter++) {
+ cols[counter] = counter;
+ }
+ } else {
+ cols = table.getSelectedColumns();
+ }
+
+ if (rows == null || cols == null || rows.length == 0 || cols.length == 0) {
+ return null;
+ }
+
+ StringBuffer plainBuf = new StringBuffer();
+ StringBuffer htmlBuf = new StringBuffer();
+
+ htmlBuf.append("\n\n\n");
+
+ for (int row = 0; row < rows.length; row++) {
+ htmlBuf.append("\n");
+ for (int col = 0; col < cols.length; col++) {
+ Object obj = table.getValueAt(rows[row], cols[col]);
+ String val = ((obj == null) ? "" : obj.toString());
+ plainBuf.append(val + "\t");
+ htmlBuf.append(" " + val + " | \n");
+ }
+ // we want a newline at the end of each line and not a tab
+ plainBuf.deleteCharAt(plainBuf.length() - 1).append("\n");
+ htmlBuf.append("
\n");
+ }
+
+ // remove the last newline
+ plainBuf.deleteCharAt(plainBuf.length() - 1);
+ htmlBuf.append("
\n\n");
+
+ return new BasicTransferable(plainBuf.toString(), htmlBuf.toString());
+ }
+
+ return null;
+ }
+
+ @Override
+ public int getSourceActions(JComponent c) {
+ return COPY;
}
- }
- private JSTableHeaderUI getHeaderUI() {
- JTableHeader th = table.getTableHeader();
- return (th == null ? null : (JSTableHeaderUI) th.getUI());
}
+ public void invokeAction(String name, Action altAction) {
+ ActionMap map = table.getActionMap();
+ Action action = null;
+
+ if (map != null) {
+ action = map.get(name);
+ }
+ installDefaultTransferHandlerIfNecessary();
+ if (action == null) {
+ action = altAction;
+ }
+ action.actionPerformed(new ActionEvent(this,
+ ActionEvent.ACTION_PERFORMED, (String)action.
+ getValue(Action.NAME),
+ EventQueue.getMostRecentEventTime(), 0));
+ }
+
}
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java
index 4d6cce9ac..2a62bef32 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextAreaUI.java
@@ -4,8 +4,12 @@
import java.awt.Point;
import java.beans.PropertyChangeEvent;
+import javax.swing.JComponent;
import javax.swing.JTextArea;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
import javax.swing.event.CaretEvent;
+import javax.swing.plaf.UIResource;
import javax.swing.text.Element;
import javax.swing.text.PlainView;
import javax.swing.text.View;
@@ -33,7 +37,7 @@ public DOMNode updateDOMNode() {
valueNode = domNode = newDOMObject("textarea", id, "spellcheck", FALSE, "autocomplete", "off");
allowPaintedBackground = false;
focusNode = enableNode = textNode = domNode;
- DOMNode.setStyles(domNode, "resize", "none", "margin", "0px", "padding", "0px","scrollbar-width", "thin"); // otherwise it overflows
+ DOMNode.setStyles(domNode, "resize", "none", "border", "none", "margin", "0px", "padding", "0px","scrollbar-width", "thin"); // otherwise it overflows
DOMNode.setStyles(domNode, "box-sizing", "border-box");
bindJSKeyEvents(focusNode, true);
}
@@ -53,6 +57,15 @@ public DOMNode updateDOMNode() {
return super.updateDOMNode();
}
+
+// @Override
+// protected void setBorder(String prefix) {
+// Border b = editor.getBorder();
+// if ((b == null) || (b instanceof UIResource)) {
+// editor.setBorder(UIManager.getBorder(prefix + ".border"));
+// }
+// }
+
@Override
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
@@ -156,6 +169,12 @@ public boolean isFocusable() {
return false;
}
+
+ @Override
+ public Dimension getMaximumSize(JComponent jc) {
+ return ANY_SIZE;
+ }
+
@Override
protected boolean handleTab(Object jqEvent) {
String val = getJSTextValue();
diff --git a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java
index 2b72c4c42..cabe7d1e6 100644
--- a/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java
+++ b/sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java
@@ -50,6 +50,7 @@
import javax.swing.JViewport;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
+import javax.swing.TransferHandler;
import javax.swing.UIManager;
import javax.swing.event.CaretEvent;
import javax.swing.plaf.ActionMapUIResource;
@@ -269,18 +270,13 @@ protected void undisposeUI(DOMNode node) {
*/
protected void installDefaults() {
String prefix = getPropertyPrefix();
+
Font f = editor.getFont();
if ((f == null && !isAWT) || (f instanceof UIResource)) {
editor.setFont(UIManager.getFont(prefix + ".font"));
}
-
setColors(prefix);
- //
- // Border b = editor.getBorder();
- // if ((b == null) || (b instanceof UIResource)) {
- // editor.setBorder(UIManager.getBorder(prefix + ".border"));
- // }
- //
+ //setBorder(prefix);
Insets margin = editor.getMargin();
if (margin == null || margin instanceof UIResource) {
editor.setMargin(UIManager.getInsets(prefix + ".margin"));
@@ -289,6 +285,10 @@ protected void installDefaults() {
// updateCursor();
}
+ protected void setBorder(String prefix) {
+ // set JSEditorPaneUI
+ }
+
protected void setColors(String prefix) {
Color bg = editor.getBackground();
if ((bg == null) || (bg instanceof UIResource)) {
@@ -515,12 +515,12 @@ ActionMap createActionMap() {
map.put(a.getValue(Action.NAME), a);
//System.out.println("JSTextUI " + jc.getUIClassID() + ".createAction: " + a.getValue(Action.NAME));
}
- // map.put(TransferHandler.getCutAction().getValue(Action.NAME),
- // TransferHandler.getCutAction());
- // map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
- // TransferHandler.getCopyAction());
- // map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
- // TransferHandler.getPasteAction());
+ map.put(TransferHandler.getCutAction().getValue(Action.NAME),
+ TransferHandler.getCutAction());
+ map.put(TransferHandler.getCopyAction().getValue(Action.NAME),
+ TransferHandler.getCopyAction());
+ map.put(TransferHandler.getPasteAction().getValue(Action.NAME),
+ TransferHandler.getPasteAction());
return map;
}
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java
index 7e5e2e8bc..fae0c96e6 100644
--- a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java
@@ -10,11 +10,8 @@
//web_Features= graphics, AWT-to-Swing
import java.awt.Adjustable;
-import java.awt.BorderLayout;
-import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
-import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
@@ -27,7 +24,9 @@
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
+import java.awt.font.TextAttribute;
import java.text.DecimalFormat;
+import java.util.EventListener;
import javax.swing.ButtonGroup;
import javax.swing.JApplet;
@@ -48,9 +47,290 @@
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.Position;
+import javax.swing.text.Segment;
public class Test_Applet_Scroll extends JApplet implements ChangeListener, MouseListener, MouseMotionListener {
+
+// class SimpleDocument implements Document {
+//
+// public class DocEvent implements DocumentEvent {
+//
+// private EventType type;
+// private int offset;
+// private int length;
+//
+// public DocEvent(int offset, int length, EventType type) {
+// this.type = type;
+// this.offset = offset;
+// this.length = length;
+// }
+//
+// @Override
+// public int getOffset() {return offset;}
+//
+// @Override
+// public int getLength() {return length;}
+//
+// @Override
+// public Document getDocument() {
+// return SimpleDocument.this;
+// }
+//
+// @Override
+// public EventType getType() {
+// return type;
+// }
+//
+// @Override
+// public ElementChange getChange(Element elem) {
+// return null;
+// }
+//
+// }
+//
+// private StringBuffer myText = new StringBuffer();
+//
+//// Element root = new Element() {
+////
+////
+//// @Override
+//// public Document getDocument() {
+//// return SimpleDocument.this;
+//// }
+////
+//// @Override
+//// public Element getParentElement() {
+//// return null;
+//// }
+////
+//// @Override
+//// public String getName() {
+//// return "root"; }
+////
+//// @Override
+//// public AttributeSet getAttributes() {
+//// return null;
+//// }
+////
+//// @Override
+//// public int getStartOffset() {
+//// return 0;
+//// }
+////
+//// @Override
+//// public int getEndOffset() {
+//// return myText.length();
+//// }
+////
+//// @Override
+//// public int getElementIndex(int offset) {
+//// return 0;
+//// }
+////
+//// @Override
+//// public int getElementCount() {
+//// return 0;
+//// }
+////
+//// @Override
+//// public Element getElement(int index) {
+//// return null;
+//// }
+////
+//// @Override
+//// public boolean isLeaf() {
+//// return true;
+//// }
+////
+//// };
+//
+// @Override
+// public int getLength() {
+// return myText.length();
+// }
+//
+// @Override
+// public void addDocumentListener(DocumentListener listener) {
+// listenerList.add(DocumentListener.class, listener);
+// }
+//
+// @Override
+// public void removeDocumentListener(DocumentListener listener) {
+// listenerList.remove(DocumentListener.class, listener);
+// }
+//
+// @Override
+// public void addUndoableEditListener(UndoableEditListener listener) {
+// System.out.println(listener);
+// }
+//
+// @Override
+// public void removeUndoableEditListener(UndoableEditListener listener) {
+// System.out.println(listener);
+// }
+//
+// @Override
+// public Object getProperty(Object key) {
+//// if (key == TextAttribute.RUN_DIRECTION)
+//// return TextAttribute.RUN_DIRECTION_LTR;
+//// if (key.toString().equals("tabSize"))
+//// return new Integer(8);
+// return null;
+// }
+//
+// @Override
+// public void putProperty(Object key, Object value) {
+//// System.out.println("putprop " + key + " " + value);
+// }
+//
+// @Override
+// public void remove(int offs, int len) throws BadLocationException {
+// if (len <= 0)
+// return;
+// if (offs < 0 || (offs + len) > getLength()) {
+// throw new BadLocationException("Invalid remove", getLength() + 1);
+// }
+// myText.replace(offs, len, "");
+//
+// DocEvent chng = new DocEvent(offs, len, DocumentEvent.EventType.REMOVE);
+//
+// //postRemoveUpdate(chng);
+// fireRemoveUpdate(chng);
+// }
+//
+// @Override
+// public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
+// if ((str == null) || (str.length() == 0)) {
+// return;
+// }
+// myText.insert(offset, str);
+// DocEvent e = new DocEvent(offset, str.length(), DocumentEvent.EventType.INSERT);
+// fireInsertUpdate(e);
+// }
+//
+// @Override
+// public String getText(int offset, int length) throws BadLocationException {
+// return myText.substring(offset, offset + length);
+// }
+//
+// char[] achar = new char[0];
+// @Override
+// public void getText(int offset, int length, Segment txt) throws BadLocationException {
+// System.out.println("getText");
+// if (length > 0) {
+// if (achar.length < offset + length)
+// achar = new char[offset + length * 2];
+// if (txt.array != achar)
+// txt.array = achar;
+// myText.getChars(offset, offset + length, achar, offset);
+// }
+// txt.offset = offset;
+// txt.count = length;
+// }
+//
+// @Override
+// public Position getStartPosition() {
+// return null;
+//// System.out.println("getstartpos");
+//// return new Position() {
+////
+//// @Override
+//// public int getOffset() {
+//// return 0;
+//// }
+////
+//// };
+// }
+//
+// @Override
+// public Position getEndPosition() {
+// System.out.println("getendpos");
+// return null;
+//// return new Position() {
+////
+//// @Override
+//// public int getOffset() {
+//// return myText.length();
+//// }
+////
+//// };
+// }
+//
+// @Override
+// public Position createPosition(int offs) throws BadLocationException {
+// return null;
+//// return new Position() {
+////
+//// @Override
+//// public int getOffset() {
+//// return offs;
+//// }
+////
+//// };
+// }
+//
+// @Override
+// public Element[] getRootElements() {
+// return null;
+//// return new Element[] {root};
+// }
+//
+// @Override
+// public Element getDefaultRootElement() {
+// return null;
+//// return root;
+// }
+//
+//
+//
+// @Override
+// public void render(Runnable r) {
+// }
+//
+// protected void fireInsertUpdate(DocumentEvent e) {
+// try {
+// Object[] listeners = listenerList.getListenerList();
+// for (int i = listeners.length - 2; i >= 0; i -= 2) {
+// if (listeners[i] == DocumentListener.class) {
+// ((DocumentListener) listeners[i + 1]).insertUpdate(e);
+// }
+// }
+// } finally {
+//// notifyingListeners = false;
+// }
+// }
+// protected void fireRemoveUpdate(DocumentEvent e) {
+// try {
+// Object[] listeners = listenerList.getListenerList();
+// for (int i = listeners.length - 2; i >= 0; i -= 2) {
+// if (listeners[i] == DocumentListener.class) {
+// ((DocumentListener) listeners[i + 1]).removeUpdate(e);
+// }
+// }
+// } finally {
+//// notifyingListeners = false;
+// }
+// }
+// protected EventListenerList listenerList = new EventListenerList();
+// public T[] getListeners(Class listenerType) {
+// return listenerList.getListeners(listenerType);
+// }
+//
+//
+//}
+
+
static {
/**
* @j2sNative
@@ -99,16 +379,17 @@ public void update(Graphics g) {
@Override
public void init() {
final JLabel label = new JLabel("hello") {
+ @Override
public void paintComponent(Graphics g) {
- //super.paintComponent(g);
- /**@j2sNative g.unclip$I(-4);*/
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setColor(Color.red);
- g2.setClip(-60,-60, 70,70);
- g2.fillRect(-60,-60,70,70);
- //g2.dispose();
- /**@j2sNative g.unclip$I(4);*/
-
+ super.paintComponent(g);
+// /**@j2sNative g.unclip$I(-4);*/
+// Graphics2D g2 = (Graphics2D) g.create();
+// g2.setColor(Color.red);
+// g2.setClip(-60,-60, 70,70);
+// g2.fillRect(-60,-60,70,70);
+// //g2.dispose();
+// /**@j2sNative g.unclip$I(4);*/
+//
}
};
@@ -120,10 +401,21 @@ public void paintComponent(Graphics g) {
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setVerticalAlignment(SwingConstants.CENTER);
- final JTextField tf = new JTextField("12.5", 8);
- tf.setBackground(Color.black);
- tf.setForeground(Color.yellow);
- tf.setOpaque(true);
+ final JTextField tf = new JTextField(/** @j2sNative "JS" ||*/null, "12.5", 8);
+// final JTextField tf = new JTextField(new PlainDocument() {
+// @Override
+// public void getText(int offset, int length, Segment txt) throws BadLocationException {
+// System.out.println("getText");
+// super.getText(offset, length, txt);
+// System.out.println(txt);
+// }
+//
+// }, "12.5", 8);
+
+//
+// tf.setBackground(Color.orange);
+// tf.setForeground(Color.yellow);
+// tf.setOpaque(true);
setSize(tf, 80, 40);
tf.addActionListener(new java.awt.event.ActionListener() {
@Override
@@ -179,17 +471,17 @@ public void actionPerformed(ActionEvent event) {
@Override
public void actionPerformed(ActionEvent event) {
label.setBackground(button2.isSelected() ? Color.green : Color.yellow);
- tf.setBackground(Color.green);
- label.setText("btn2");
- vp.remove(vslider);
- vp.add(vslider);
- JFrame frame1 = new JFrame();
- frame1.setLocationRelativeTo(button2);
- JPanel jp = new JPanel();
- jp.setPreferredSize(new Dimension(150,150));
- frame1.add(jp);
- frame1.pack();
- frame1.setVisible(true);
+// tf.setBackground(Color.green);
+// label.setText("btn2");
+// vp.remove(vslider);
+// vp.add(vslider);
+// JFrame frame1 = new JFrame();
+// frame1.setLocationRelativeTo(button2);
+// JPanel jp = new JPanel();
+// jp.setPreferredSize(new Dimension(150,150));
+// frame1.add(jp);
+// frame1.pack();
+// frame1.setVisible(true);
}
});
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java
index 48d313635..faaf5e97d 100644
--- a/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll_AWT.java
@@ -82,7 +82,7 @@ public void init() {
final TextField tf = new TextField("12.5", 8);
// tf.setBackground(Color.red);
tf.setForeground(Color.orange);
- tf.setEditable(false);
+ tf.setEditable(true);
//tf.setOpaque(true);
setSize(tf, 80, 40);
tf.addActionListener(new java.awt.event.ActionListener() {
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Class.java b/sources/net.sf.j2s.java.core/src/test/Test_Class.java
index 947a9a946..7d5d33796 100644
--- a/sources/net.sf.j2s.java.core/src/test/Test_Class.java
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Class.java
@@ -311,6 +311,8 @@ public static String localtest() {
public static void main(String[] args) {
+ System.out.println(System.getProperty("screen"));
+
// tricky situation where a parameter changes a value that is also changed by the static initializer of a class:
boolean test1 = false;
if (test1) {
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Clipboard.java b/sources/net.sf.j2s.java.core/src/test/Test_Clipboard.java
new file mode 100644
index 000000000..7393afce2
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Clipboard.java
@@ -0,0 +1,172 @@
+package test;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.EventQueue;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Date;
+
+import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.BoxLayout;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.TransferHandler;
+import javax.swing.table.DefaultTableModel;
+
+import swingjs.plaf.JSTableUI;
+
+public class Test_Clipboard extends JFrame {
+
+ public static class CopiableTable extends JTable {
+
+ @SuppressWarnings("unused")
+ public void copy() {
+ if (/** @j2sNative true || */
+ false) {
+ JSTableUI ui = (JSTableUI) 秘getUI();
+ ui.installDefaultTransferHandlerIfNecessary();
+ }
+ invokeAction("copy", TransferHandler.getCopyAction());
+ }
+
+ public void invokeAction(String name, Action altAction) {
+ ActionMap map = getActionMap();
+ Action action = null;
+
+ if (map != null) {
+ action = map.get(name);
+ }
+ // installDefaultTransferHandlerIfNecessary();
+ if (action == null) {
+ action = altAction;
+ }
+ action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
+ (String) action.getValue(Action.NAME), EventQueue.getMostRecentEventTime(), 0));
+ }
+
+ }
+
+ private DefaultListModel listModel;
+
+ public Test_Clipboard() {
+ super();
+ JPanel p = new JPanel();
+ p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
+ add(p, BorderLayout.CENTER);
+ this.setLocation(300, 300);
+
+ JTextArea area = new JTextArea(10, 50);
+ area.setText("this\nis\na\ntest\n" + new Date());
+ p.add(area);
+
+ area.setBackground(Color.orange);
+
+ String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years",
+ // "Vegetarian"
+ };
+
+ Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
+ { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
+ { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
+ { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
+ { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
+ { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
+ { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
+ { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
+ { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
+ { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
+ { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
+ { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
+ { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) },
+ { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
+ { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) },
+ { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) },
+ { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };
+
+ CopiableTable table = new CopiableTable();
+ table.setModel(new DefaultTableModel(data, columnNames));
+ table.setCellSelectionEnabled(true);
+ table.setFillsViewportHeight(true);
+ table.setBackground(Color.yellow);
+ //table.setRowHeight(10); // very tight! exact match
+ //table.setRowMargin(10);
+ table.getColumnModel().setColumnMargin(10);
+ //JScrollPane scrollPane = new JScrollPane(table);
+
+ //p.add(scrollPane);
+ p.add(table);
+
+ listModel = new DefaultListModel();
+ listModel.addElement("Jane Doe");
+ listModel.addElement("John Smith");
+ listModel.addElement("Kathy Green");
+ listModel.addElement("Rose Red");
+ listModel.addElement("Nearly Black");
+ listModel.addElement("Pearly White");
+ // Create the list and put it in a scroll pane.
+ JList list = new JList(listModel);
+ list.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 24));
+ list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ list.setSelectedIndex(0);
+ //list.addListSelectionListener(this);
+ list.setVisibleRowCount(5);
+ p.add(list);
+
+ JPanel m = new JPanel(new GridLayout());
+
+ JButton btn = new JButton("copy text");
+ btn.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (area.getSelectedText() == null || area.getSelectedText().length() == 0)
+ area.selectAll();
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ area.copy();
+ }
+ });
+ }
+
+ });
+ m.add(btn, null);
+ btn = new JButton("copy table");
+ btn.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (table.getSelectedColumnCount() == 0 && table.getSelectedColumnCount() == 0)
+ table.selectAll();
+ table.copy();
+ }
+
+ });
+
+ m.add(btn, null);
+ add(m, BorderLayout.SOUTH);
+
+ pack();
+ setVisible(true);
+ }
+
+ public static void main(String[] args) {
+ try {
+ new Test_Clipboard();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Static.java b/sources/net.sf.j2s.java.core/src/test/Test_Static.java
index 423dcef2f..6c6a3e43b 100644
--- a/sources/net.sf.j2s.java.core/src/test/Test_Static.java
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Static.java
@@ -75,6 +75,14 @@ private static String testStatic() {
@SuppressWarnings("static-access")
public static void main(String[] args) {
+ try {
+ new Test_Static1("Static.main");
+ //Class.forName("test.Test_Static1");
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
new Test_Static().callStatic();
// each of these pairs will be the same:
test.testStatic();
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Static1.java b/sources/net.sf.j2s.java.core/src/test/Test_Static1.java
index 85a6ab4b6..78ce7d5a0 100644
--- a/sources/net.sf.j2s.java.core/src/test/Test_Static1.java
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Static1.java
@@ -1,25 +1,36 @@
package test;
-class Test_Static1 extends Test_ {
- public static class InnerStatic {
+/**
+ * Test of static initialization of subclass with object initialization of superclass prior to static initialization of superclass
+ * @author hansonr
+ *
+ */
+class Test_Static1 extends Test_ {
+
+ static {
+ System.out.println("Test_Static1.1 1 1");
+ }
-// public InnerStatic() {
-// System.out.println("innerStatic initializer");
-// }
+ static int v1 = 1;
+ static String s1 = "s1";
+ static Test_Static2 ts12 = new Test_Static2("Static1.ts2");
+ static {
+ System.out.println("Test_Static1.2 14 2");
+ }
+ {
+ System.out.println("Test_Static1.3 10 or 15 if not from Class.forName ");
-
- public void test(String...strings) {
-
- }
-
}
-
- public static void main(String[] args) {
-
- new Test_Static1.InnerStatic();
+ Test_Static1(String test) {
+ super();
+ System.out.println("Test_Static1.4 15 or 16 if not from Class.forName(Test_Static1) test_int was " + test_int + " v1=" + v1 + " s1=" + s1);
+ test_int = 1;
}
+ public static void main(String[] args) {
+ System.out.println("Test_Static1 [main]");
+ new Test_Static1("Static1.main");
+ }
}
-
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Static2.java b/sources/net.sf.j2s.java.core/src/test/Test_Static2.java
new file mode 100644
index 000000000..8765fb835
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Static2.java
@@ -0,0 +1,28 @@
+package test;
+
+class Test_Static2 extends Test_Static3 {
+
+ static {
+ System.out.println("Test_Static2.1 8 1");
+ }
+
+ static int v2 = 2;
+
+ static String s2 = "s2";
+
+ static {
+ System.out.println("Test_Static2.2 9 2");
+ }
+
+ {
+ System.out.println("Test_Static2.3 5,12 ");
+
+ }
+
+ Test_Static2(String test) {
+ super(test);
+ System.out.println("Test_Static2.4 6,13 test_int was " + test_int + " v2=" + v2 + " s2=" + s2 + " v3=" + v3 + " s3=" + s3);
+ test_int = 2;
+ }
+
+}
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Static2b.java b/sources/net.sf.j2s.java.core/src/test/Test_Static2b.java
new file mode 100644
index 000000000..ec75d7ad4
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Static2b.java
@@ -0,0 +1,28 @@
+package test;
+
+class Test_Static2b extends Test_Static3 {
+
+ static {
+ System.out.println("Test_Static2b.1 2.1 1");
+ }
+
+ static int v2b = 20;
+
+ static String s2b = "s2b";
+
+ static {
+ System.out.println("Test_Static2b.2 2.2 2");
+ }
+
+ {
+ System.out.println("Test_Static2b.3 4.1 ");
+
+ }
+
+ Test_Static2b(String test) {
+ super(test);
+ System.out.println("Test_Static2b.4 4.2 test_int was " + test_int + " v2b=" + v2b + " s2b=" + s2b + " v3=" + v3 + " s3=" + s3);
+ test_int = 2;
+ }
+
+}
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Static3.java b/sources/net.sf.j2s.java.core/src/test/Test_Static3.java
new file mode 100644
index 000000000..8b4a3bf7b
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/test/Test_Static3.java
@@ -0,0 +1,31 @@
+package test;
+
+
+class Test_Static3 extends Test_ {
+
+
+ static {
+ System.out.println("Test_Static3.1 2 1");
+ }
+
+ static int v3 = 3;
+ static String s3 = "s3";
+
+
+ static Test_Static2b ts2b = new Test_Static2b("new static2b"); // the killer?
+ static Test_Static2 ts2 = new Test_Static2("new static2");
+
+ static {
+ System.out.println("Test_Static3.2 7 2");
+ }
+
+ {
+ System.out.println("Test_Static3.3 3,10,4.3");
+
+ }
+
+ Test_Static3(String test) {
+ System.out.println("Test_Static3.4 4,11,4.4 test_int was " + test_int + " v3=" + v3 + " s3=" + s3 + " test=" + test);
+ test_int = 3;
+ }
+}
diff --git a/sources/net.sf.j2s.java.core/src/test/Test_StaticInner.java b/sources/net.sf.j2s.java.core/src/test/Test_StaticInner.java
new file mode 100644
index 000000000..a5e9b5d55
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/src/test/Test_StaticInner.java
@@ -0,0 +1,25 @@
+package test;
+
+class Test_StaticInner extends Test_ {
+
+ public static class InnerStatic {
+
+// public InnerStatic() {
+// System.out.println("innerStatic initializer");
+// }
+
+
+ public void test(String...strings) {
+
+ }
+
+ }
+
+ public static void main(String[] args) {
+
+ new Test_StaticInner.InnerStatic();
+ }
+
+
+}
+
diff --git a/sources/net.sf.j2s.java.core/src/test/components/SimpleTableDemo.java b/sources/net.sf.j2s.java.core/src/test/components/SimpleTableDemo.java
index ea583516a..f15a59ab4 100644
--- a/sources/net.sf.j2s.java.core/src/test/components/SimpleTableDemo.java
+++ b/sources/net.sf.j2s.java.core/src/test/components/SimpleTableDemo.java
@@ -59,7 +59,7 @@ public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;
public SimpleTableDemo() {
- super(new GridLayout(2,0));
+ super(new GridLayout(2,2));
String[] columnNames = {"First Name",
"Last Name",
diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js
index 475a74f7f..8fd44aa9a 100644
--- a/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js
+++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js
@@ -168,6 +168,7 @@ window.J2S = J2S = (function() {
// these sites are known to implement
// access-control-allow-origin *
// null here means no conversion necessary
+ "INTERNET.TEST" : "https://pubchem.ncbi.nlm.nih.gov",
"chemapps.stolaf.edu" : null,
"cactus.nci.nih.gov" : null,
".x3dna.org" : null,
@@ -858,7 +859,9 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
var isHttps2Http = (J2S._httpProto == "https://" && fileName.indexOf("http://") == 0);
var cantDoSynchronousLoad = (!isMyHost && J2S.$supportsIECrossDomainScripting());
var mustCallHome = !isFile && (isHttps2Http || asBase64 || !fSuccess && cantDoSynchronousLoad);
- var isNotDirectCall = !mustCallHome && !isFile && !isMyHost && !J2S._isDirectCall(fileName);
+ var url;
+ var isNotDirectCall = !mustCallHome && !isFile && !isMyHost && !(url = J2S._isDirectCall(fileName));
+ fileName = url || fileName;
var data = null;
if (mustCallHome || isNotDirectCall) {
data = J2S._getRawDataFromServer("_", fileName, fSuccess, fSuccess,
@@ -913,7 +916,7 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
for ( var key in J2S.db._DirectDatabaseCalls) {
if (key.indexOf(".") >= 0 && url.indexOf(key) >= 0) {
// hack because ebi is not returning ajax calls
- return true;//url.indexOf(".ebi.ac.") < 0 || url.indexOf("dbfetch/dbfetch") < 0;
+ return J2S.db._DirectDatabaseCalls[key] || url;//url.indexOf(".ebi.ac.") < 0 || url.indexOf("dbfetch/dbfetch") < 0;
}
}
@@ -2657,7 +2660,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
applet.__Info.code = clazz;
}
- var cl = Clazz.loadClass(clazz);cl.$static$ && cl.$static$();
+ var cl = Clazz.loadClass(clazz);
+ //cl.$static$ && cl.$static$();
if (clazz.indexOf("_.") == 0)
J2S.setWindowVar(clazz.substring(2), cl);
if (isApp && cl.j2sHeadless)
diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js
index b79342a3f..47a8be1bd 100644
--- a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js
+++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js
@@ -7,8 +7,9 @@
// Google closure compiler cannot handle Clazz.new or Clazz.super
+// BH 2020.04.01 2.2.0-v1e fixes missing C$.superclazz when class loaded from core
// BH 2020.03.19 3.2.9-v1c fixes new String("xxx") !== "xxx"
-// BH 2020.03.11 3.2.9-v1b fixes numerous subtle issues with boxed primatives Integer, Float, etc.
+// BH 2020.03.11 3.2.9-v1b fixes numerous subtle issues with boxed primitives Integer, Float, etc.
// BH 2020.03.07 3.2.9-v1a fixes array.hashCode() to be System.identityHashCode(array).
// BH 2020.02.18 3.2.8-v2 upgrades String, Integer, ClassLoader, Package, various Exceptions
// BH 2020.02.12 3.2.8-v1 new Throwable().getStackTrace() should not include j2sClazz methods
@@ -296,6 +297,7 @@ Clazz.exceptionOf = function(e, clazz) {
Clazz.forName = function(name, initialize, loader, isQuiet) {
// we need to consider loading a class from the path of the calling class.
var cl = null;
+ (typeof initialize == "undefined") && (initialize = true);
if (loader) {
try {
isQuiet = true;
@@ -402,9 +404,10 @@ var initStatic = function(cl, impls) {
Clazz.load = function(cName, from$clinit$) {
if (!cName)
return null;
- if (from$clinit$ == 1) {
+ var cl = cName;
+ switch (from$clinit$ || 0) {
+ case 1:
// C$.$clinit$ call to finalize all dependencies
- var cl = cName;
cl.$clinit$ = 0-cl.$clinit$;
// -2 means v 3.2.6
// -1 means v 3.2.5
@@ -421,12 +424,15 @@ Clazz.load = function(cName, from$clinit$) {
break;
}
return;
- }
- if (from$clinit$ == 2) {
+ case 2:
// C$.$static$ to do static initialization
- if (cName.$load$) {
- cName.$load$ = 0;
- initStatic(cName, cName.$isInterface ? cName.implementz : 0);
+ if (cl.$load$) {
+ if (cl.$load$[0] && !cl.superclazz) {
+ // can happen with Clazz.new_($I(n,1)....)
+ setSuperclass(cl, Clazz.load(cl.$load$[0]));
+ }
+ cl.$load$ = 0;
+ initStatic(cl, cl.$isInterface ? cl.implementz : 0);
}
return;
}
@@ -441,8 +447,8 @@ Clazz.load = function(cName, from$clinit$) {
return cl1;
}
// allow for a clazz itself
- if (cName.__CLASS_NAME__)
- return Clazz._initClass(cName,1,1,0);
+ if (cl.__CLASS_NAME__)
+ return Clazz._initClass(cl,1,1,0);
// standard load of class by name
if (cName.indexOf("Thread.") == 0)
Clazz._4Name("java.lang.Thread", null, null, true)
@@ -2397,7 +2403,8 @@ Clazz.loadClass = function (name, onLoaded, async) {
if (!name)
return null;
if (!async)
- return Clazz._4Name(name, null, null, true, true);
+ return Clazz._4Name(name, null, null, true, true);
+
_Loader.loadClass(name, function() {
var cl = Clazz._getDeclared(name);
onLoaded(cl && Clazz._initClass(cl, 1, 1));
@@ -2574,10 +2581,10 @@ var evaluate = function(file, js) {
}
}
-Clazz._initClass = function(c,clinit,status,objThis) {
+Clazz._initClass = function(c,clinit,statics,objThis) {
var f;
return clinit && (f=c.$clinit$) && (f === 1 || f === 2 ? Clazz.load(c,1) : f && typeof f == "function"? f() : 0),
- status && c.$load$ && Clazz.load(c, 2),
+ statics && c.$load$ && Clazz.load(c, 2),
objThis && (f=c.$init0$) && f.apply(objThis),
c;
}
@@ -3224,7 +3231,8 @@ C$.setProperties$java_util_Properties=function (props) {
C$.getProperty$S=function (key) {
C$.checkKey$S(key);
- return (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key));
+ var p = (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key))
+ return (p == null ? null : p);
}
C$.getProperty$S$S=function (key, def) {
@@ -4109,7 +4117,7 @@ var maxFloat = 3.4028235E38;
var minFloat = -3.4028235E38;
m$(Float,"c$", function(v){
- v || v == null || (v = 0);
+ v || v == null || v != v || (v = 0);
if (typeof v != "number")
v = Float.parseFloat$S(v);
this.valueOf=function(){return v;}
@@ -4238,7 +4246,7 @@ m$(Double, "c$$D", function(v){
}, 1);
m$(Double,"c$", function(v){
-v || v == null || (v = 0);
+v || v == null || v != v || (v = 0);
if (typeof v != "number")
v = Double.parseDouble$S(v);
this.valueOf=function(){return v;}
diff --git a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js
index 0715e547f..3832b8eaa 100644
--- a/sources/net.sf.j2s.java.core/srcjs/swingjs2.js
+++ b/sources/net.sf.j2s.java.core/srcjs/swingjs2.js
@@ -10837,6 +10837,7 @@ window.J2S = J2S = (function() {
// these sites are known to implement
// access-control-allow-origin *
// null here means no conversion necessary
+ "INTERNET.TEST" : "https://pubchem.ncbi.nlm.nih.gov",
"chemapps.stolaf.edu" : null,
"cactus.nci.nih.gov" : null,
".x3dna.org" : null,
@@ -11527,7 +11528,9 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
var isHttps2Http = (J2S._httpProto == "https://" && fileName.indexOf("http://") == 0);
var cantDoSynchronousLoad = (!isMyHost && J2S.$supportsIECrossDomainScripting());
var mustCallHome = !isFile && (isHttps2Http || asBase64 || !fSuccess && cantDoSynchronousLoad);
- var isNotDirectCall = !mustCallHome && !isFile && !isMyHost && !J2S._isDirectCall(fileName);
+ var url;
+ var isNotDirectCall = !mustCallHome && !isFile && !isMyHost && !(url = J2S._isDirectCall(fileName));
+ fileName = url || fileName;
var data = null;
if (mustCallHome || isNotDirectCall) {
data = J2S._getRawDataFromServer("_", fileName, fSuccess, fSuccess,
@@ -11582,7 +11585,7 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
for ( var key in J2S.db._DirectDatabaseCalls) {
if (key.indexOf(".") >= 0 && url.indexOf(key) >= 0) {
// hack because ebi is not returning ajax calls
- return true;//url.indexOf(".ebi.ac.") < 0 || url.indexOf("dbfetch/dbfetch") < 0;
+ return J2S.db._DirectDatabaseCalls[key] || url;//url.indexOf(".ebi.ac.") < 0 || url.indexOf("dbfetch/dbfetch") < 0;
}
}
@@ -13326,7 +13329,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
applet.__Info.code = clazz;
}
- var cl = Clazz.loadClass(clazz);cl.$static$ && cl.$static$();
+ var cl = Clazz.loadClass(clazz);
+ //cl.$static$ && cl.$static$();
if (clazz.indexOf("_.") == 0)
J2S.setWindowVar(clazz.substring(2), cl);
if (isApp && cl.j2sHeadless)
@@ -13901,8 +13905,9 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
// Google closure compiler cannot handle Clazz.new or Clazz.super
+// BH 2020.04.01 2.2.0-v1e fixes missing C$.superclazz when class loaded from core
// BH 2020.03.19 3.2.9-v1c fixes new String("xxx") !== "xxx"
-// BH 2020.03.11 3.2.9-v1b fixes numerous subtle issues with boxed primatives Integer, Float, etc.
+// BH 2020.03.11 3.2.9-v1b fixes numerous subtle issues with boxed primitives Integer, Float, etc.
// BH 2020.03.07 3.2.9-v1a fixes array.hashCode() to be System.identityHashCode(array).
// BH 2020.02.18 3.2.8-v2 upgrades String, Integer, ClassLoader, Package, various Exceptions
// BH 2020.02.12 3.2.8-v1 new Throwable().getStackTrace() should not include j2sClazz methods
@@ -14190,6 +14195,7 @@ Clazz.exceptionOf = function(e, clazz) {
Clazz.forName = function(name, initialize, loader, isQuiet) {
// we need to consider loading a class from the path of the calling class.
var cl = null;
+ (typeof initialize == "undefined") && (initialize = true);
if (loader) {
try {
isQuiet = true;
@@ -14296,9 +14302,10 @@ var initStatic = function(cl, impls) {
Clazz.load = function(cName, from$clinit$) {
if (!cName)
return null;
- if (from$clinit$ == 1) {
+ var cl = cName;
+ switch (from$clinit$ || 0) {
+ case 1:
// C$.$clinit$ call to finalize all dependencies
- var cl = cName;
cl.$clinit$ = 0-cl.$clinit$;
// -2 means v 3.2.6
// -1 means v 3.2.5
@@ -14315,12 +14322,15 @@ Clazz.load = function(cName, from$clinit$) {
break;
}
return;
- }
- if (from$clinit$ == 2) {
+ case 2:
// C$.$static$ to do static initialization
- if (cName.$load$) {
- cName.$load$ = 0;
- initStatic(cName, cName.$isInterface ? cName.implementz : 0);
+ if (cl.$load$) {
+ if (cl.$load$[0] && !cl.superclazz) {
+ // can happen with Clazz.new_($I(n,1)....)
+ setSuperclass(cl, Clazz.load(cl.$load$[0]));
+ }
+ cl.$load$ = 0;
+ initStatic(cl, cl.$isInterface ? cl.implementz : 0);
}
return;
}
@@ -14335,8 +14345,8 @@ Clazz.load = function(cName, from$clinit$) {
return cl1;
}
// allow for a clazz itself
- if (cName.__CLASS_NAME__)
- return Clazz._initClass(cName,1,1,0);
+ if (cl.__CLASS_NAME__)
+ return Clazz._initClass(cl,1,1,0);
// standard load of class by name
if (cName.indexOf("Thread.") == 0)
Clazz._4Name("java.lang.Thread", null, null, true)
@@ -16291,7 +16301,8 @@ Clazz.loadClass = function (name, onLoaded, async) {
if (!name)
return null;
if (!async)
- return Clazz._4Name(name, null, null, true, true);
+ return Clazz._4Name(name, null, null, true, true);
+
_Loader.loadClass(name, function() {
var cl = Clazz._getDeclared(name);
onLoaded(cl && Clazz._initClass(cl, 1, 1));
@@ -16468,10 +16479,10 @@ var evaluate = function(file, js) {
}
}
-Clazz._initClass = function(c,clinit,status,objThis) {
+Clazz._initClass = function(c,clinit,statics,objThis) {
var f;
return clinit && (f=c.$clinit$) && (f === 1 || f === 2 ? Clazz.load(c,1) : f && typeof f == "function"? f() : 0),
- status && c.$load$ && Clazz.load(c, 2),
+ statics && c.$load$ && Clazz.load(c, 2),
objThis && (f=c.$init0$) && f.apply(objThis),
c;
}
@@ -17118,7 +17129,8 @@ C$.setProperties$java_util_Properties=function (props) {
C$.getProperty$S=function (key) {
C$.checkKey$S(key);
- return (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key));
+ var p = (C$.props == null ? sysprops[key] : C$.props.getProperty$S(key))
+ return (p == null ? null : p);
}
C$.getProperty$S$S=function (key, def) {
@@ -18003,7 +18015,7 @@ var maxFloat = 3.4028235E38;
var minFloat = -3.4028235E38;
m$(Float,"c$", function(v){
- v || v == null || (v = 0);
+ v || v == null || v != v || (v = 0);
if (typeof v != "number")
v = Float.parseFloat$S(v);
this.valueOf=function(){return v;}
@@ -18132,7 +18144,7 @@ m$(Double, "c$$D", function(v){
}, 1);
m$(Double,"c$", function(v){
-v || v == null || (v = 0);
+v || v == null || v != v || (v = 0);
if (typeof v != "number")
v = Double.parseDouble$S(v);
this.valueOf=function(){return v;}
diff --git a/sources/net.sf.j2s.java.core/unused/JSPlainDocument.java b/sources/net.sf.j2s.java.core/unused/JSPlainDocument.java
new file mode 100644
index 000000000..abff56fd6
--- /dev/null
+++ b/sources/net.sf.j2s.java.core/unused/JSPlainDocument.java
@@ -0,0 +1,226 @@
+package swingjs;
+
+import java.util.EventListener;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.event.DocumentEvent.ElementChange;
+import javax.swing.event.DocumentEvent.EventType;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.Element;
+import javax.swing.text.Position;
+import javax.swing.text.Segment;
+
+public class JSPlainDocument implements Document {
+
+ public JSPlainDocument() {}
+
+ public class DocEvent implements DocumentEvent {
+
+ private EventType type;
+ private int offset;
+ private int length;
+
+ public DocEvent(int offset, int length, EventType type) {
+ this.type = type;
+ this.offset = offset;
+ this.length = length;
+ }
+
+ @Override
+ public int getOffset() {return offset;}
+
+ @Override
+ public int getLength() {return length;}
+
+ @Override
+ public Document getDocument() {
+ return JSPlainDocument.this;
+ }
+
+ @Override
+ public EventType getType() {
+ return type;
+ }
+
+ @Override
+ public ElementChange getChange(Element elem) {
+ return null;
+ }
+
+ }
+
+ private StringBuffer myText = new StringBuffer();
+
+ @Override
+ public int getLength() {
+ return myText.length();
+ }
+
+ @Override
+ public void addDocumentListener(DocumentListener listener) {
+ listenerList.add(DocumentListener.class, listener);
+ }
+
+ @Override
+ public void removeDocumentListener(DocumentListener listener) {
+ listenerList.remove(DocumentListener.class, listener);
+ }
+
+ @Override
+ public void addUndoableEditListener(UndoableEditListener listener) {
+ System.out.println(listener);
+ }
+
+ @Override
+ public void removeUndoableEditListener(UndoableEditListener listener) {
+ System.out.println(listener);
+ }
+
+ @Override
+ public Object getProperty(Object key) {
+ return null;
+ }
+
+ @Override
+ public void putProperty(Object key, Object value) {
+ }
+
+ @Override
+ public void remove(int offs, int len) throws BadLocationException {
+ if (len <= 0)
+ return;
+ if (offs < 0 || (offs + len) > getLength()) {
+ throw new BadLocationException("Invalid remove", getLength() + 1);
+ }
+ myText.replace(offs, len, "");
+
+ DocEvent chng = new DocEvent(offs, len, DocumentEvent.EventType.REMOVE);
+
+ fireRemoveUpdate(chng);
+ }
+
+ @Override
+ public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
+ if ((str == null) || (str.length() == 0)) {
+ return;
+ }
+ myText.insert(offset, str);
+ DocEvent e = new DocEvent(offset, str.length(), DocumentEvent.EventType.INSERT);
+ fireInsertUpdate(e);
+ }
+
+ @Override
+ public String getText(int offset, int length) throws BadLocationException {
+ return myText.substring(offset, offset + length);
+ }
+
+ char[] achar = new char[0];
+ @Override
+ public void getText(int offset, int length, Segment txt) throws BadLocationException {
+ return;
+// System.out.println("getText");
+// if (length > 0) {
+// if (achar.length < offset + length)
+// achar = new char[offset + length * 2];
+// if (txt.array != achar)
+// txt.array = achar;
+// myText.getChars(offset, offset + length, achar, offset);
+// }
+// txt.offset = offset;
+// txt.count = length;
+ }
+
+ @Override
+ public Position getStartPosition() {
+ return null;
+// System.out.println("getstartpos");
+// return new Position() {
+//
+// @Override
+// public int getOffset() {
+// return 0;
+// }
+//
+// };
+ }
+
+ @Override
+ public Position getEndPosition() {
+ return null;
+// return new Position() {
+//
+// @Override
+// public int getOffset() {
+// return myText.length();
+// }
+//
+// };
+ }
+
+ @Override
+ public Position createPosition(int offs) throws BadLocationException {
+ return null;
+// return new Position() {
+//
+// @Override
+// public int getOffset() {
+// return offs;
+// }
+//
+// };
+ }
+
+ @Override
+ public Element[] getRootElements() {
+ return null;
+// return new Element[] {root};
+ }
+
+ @Override
+ public Element getDefaultRootElement() {
+ return null;
+// return root;
+ }
+
+
+
+ @Override
+ public void render(Runnable r) {
+ }
+
+ protected void fireInsertUpdate(DocumentEvent e) {
+ try {
+ Object[] listeners = listenerList.getListenerList();
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ ((DocumentListener) listeners[i + 1]).insertUpdate(e);
+ }
+ }
+ } finally {
+// notifyingListeners = false;
+ }
+ }
+ protected void fireRemoveUpdate(DocumentEvent e) {
+ try {
+ Object[] listeners = listenerList.getListenerList();
+ for (int i = listeners.length - 2; i >= 0; i -= 2) {
+ if (listeners[i] == DocumentListener.class) {
+ ((DocumentListener) listeners[i + 1]).removeUpdate(e);
+ }
+ }
+ } finally {
+// notifyingListeners = false;
+ }
+ }
+ protected EventListenerList listenerList = new EventListenerList();
+ public T[] getListeners(Class listenerType) {
+ return listenerList.getListeners(listenerType);
+ }
+
+
+}