Skip to content

Commit 197d176

Browse files
authored
Merge pull request #161 from BobHanson/hanson1
various optimizations, including AWT TextField simplification
2 parents c40d424 + b7e2ffe commit 197d176

28 files changed

+338
-133
lines changed
2.14 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200321085805
1+
20200327093924
2.14 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200321085805
1+
20200327093924
2.14 KB
Binary file not shown.

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,53 @@ protected final void invalidateIfValid() {
27272727
}
27282728
}
27292729

2730+
// SwingJS see JComponent
2731+
// /**
2732+
// * Revalidates the component hierarchy up to the nearest validate root.
2733+
// * <p>
2734+
// * This method first invalidates the component hierarchy starting from this
2735+
// * component up to the nearest validate root. Afterwards, the component
2736+
// * hierarchy is validated starting from the nearest validate root.
2737+
// * <p>
2738+
// * This is a convenience method supposed to help application developers
2739+
// * avoid looking for validate roots manually. Basically, it's equivalent to
2740+
// * first calling the {@link #invalidate()} method on this component, and
2741+
// * then calling the {@link #validate()} method on the nearest validate
2742+
// * root.
2743+
// *
2744+
// * @see Container#isValidateRoot
2745+
// * @since 1.7
2746+
// */
2747+
// public void revalidate() {
2748+
// revalidateSynchronously();
2749+
// }
2750+
//
2751+
// /**
2752+
// * Revalidates the component synchronously.
2753+
// */
2754+
// final void revalidateSynchronously() {
2755+
// synchronized (getTreeLock()) {
2756+
// invalidate();
2757+
//
2758+
// Container root = getContainer();
2759+
// if (root == null) {
2760+
// // There's no parents. Just validate itself.
2761+
// validate();
2762+
// } else {
2763+
// while (!root.isValidateRoot()) {
2764+
// if (root.getContainer() == null) {
2765+
// // If there's no validate roots, we'll validate the
2766+
// // topmost container
2767+
// break;
2768+
// }
2769+
//
2770+
// root = root.getContainer();
2771+
// }
2772+
//
2773+
// root.validate();
2774+
// }
2775+
// }
2776+
// }
27302777
/**
27312778
*
27322779
* Unused in SwingJS. For SwingJS, we have the graphics without needing to get it from a peer.

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import javax.swing.JComponent;
4949
import javax.swing.JLayeredPane;
5050
import javax.swing.JRootPane;
51+
import javax.swing.RepaintManager;
5152
import javax.swing.RootPaneContainer;
53+
import javax.swing.SwingUtilities;
5254

5355
import sun.awt.AppContext;
5456
import swingjs.JSToolkit;
@@ -62,6 +64,8 @@
6264
* with this, but the reason was to allow JInternalFrame to subclass JFrame
6365
* instead of duplicating in code all of its functionality.
6466
*
67+
* In addition, it allows all sorts of windows to be JComponents and have UIs.
68+
*
6569
*
6670
* A <code>Window</code> object is a top-level window with no borders and no
6771
* menubar.
@@ -3632,6 +3636,33 @@ final Point getLocationOnWindow() {
36323636
// y + h * securityWarningAlignmentY + securityWarningPointY);
36333637
// }
36343638

3639+
3640+
/**
3641+
* Indicates if this container is a validate root.
3642+
* <p>
3643+
* {@code Window} objects are the validate roots, and, therefore, they
3644+
* override this method to return {@code true}.
3645+
*
3646+
* @return {@code true}
3647+
* @since 1.7
3648+
* @see java.awt.Container#isValidateRoot
3649+
*/
3650+
@Override
3651+
public boolean isValidateRoot() {
3652+
return true;
3653+
}
3654+
3655+
@Override
3656+
public void revalidate() {
3657+
// added to see if JFrame can be revalidated this way after a change in contentPane.
3658+
// SwingJS - set this UI to rebuild itself due to some
3659+
// internal structural change.
3660+
if (ui != null)
3661+
((JSComponentUI)ui).setTainted();
3662+
invalidate();
3663+
validate();
3664+
}
3665+
36353666
} // class Window
36363667

36373668

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
302302
Graphics2D g = origDst.createGraphics();
303303
try {
304304
g.setComposite(AlphaComposite.Src);
305-
((JSGraphics2D)(Object) g).drawImagePriv(dst, 0, 0, null);
305+
((JSGraphics2D)(Object) g).drawImageFromRaster(dst, 0, 0, null);
306306
} finally {
307307
g.dispose();
308308
}

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ public void flush() {
18261826
// allow creating a Graphics from MemoryImageSource
18271827
// so pixels would never be there.
18281828
if (pix != null)
1829-
秘g.drawImagePriv(this, 0, 0, null);
1829+
秘g.drawImageFromRaster(this, 0, 0, null);
18301830
/**
18311831
* @j2sNative if (pix) pix.img = this;
18321832
*
@@ -1972,23 +1972,49 @@ public void flush() {
19721972
* @param force initially false just to get the pre-constructed canvas if it exists
19731973
* @return
19741974
*/
1975+
1976+
public final static int GET_IMAGE_ALLOW_NULL = 0;
1977+
public final static int GET_IMAGE_FOR_RASTER = 1;
1978+
public final static int GET_IMAGE_FOR_ICON = 2;
1979+
19751980

1976-
public DOMNode 秘getImageNode(boolean force) {
1981+
/**
1982+
*
1983+
* Return or create a DOMNode canvas or image tag or null
1984+
*
1985+
* @param mode GET_IMAGE_ALLOW_NULL(0) || GET_IMAGE_FOR_RASTER(1) ||
1986+
* GET_IMAGE_FOR_ICON(2)
1987+
* @return if allowing null, return the canvas if we have raster data (always
1988+
* null?) or the canvas or imgNode if not; if getting an image for a
1989+
* raster, we already know this is a raster image, so create its image;
1990+
* if getting an image for an icon, return the canvas or imgNode if this
1991+
* is not a raster image, or create its image
1992+
*/
1993+
public DOMNode 秘getImageNode(int mode) {
19771994
// If we have raster data and are not forcing, return the canvas if it exists.
1978-
// If we we have no raster data and are not forcing, force the issue anyway
1995+
// If we we have no raster data and are not forcing, force the issue anyway
19791996
// and return the canvas or image node.
19801997
// If we are forcing, or force the creation of a canvas
1981-
if (!force)
1998+
switch (mode) {
1999+
default:
2000+
case GET_IMAGE_ALLOW_NULL:
19822001
return (DOMNode) (秘hasRasterData || 秘canvas != null ? 秘canvas
19832002
: 秘imgNode != null ? 秘imgNode : JSGraphicsCompositor.createImageNode(this));
1984-
// we are forcing
1985-
秘getPixelsFromRaster();
1986-
秘g = null;
1987-
秘getImageGraphic();
1988-
DOMNode canvas = 秘g.getCanvas();
1989-
秘g = null;
1990-
秘canvas = null;
1991-
return canvas;
2003+
case GET_IMAGE_FOR_ICON:
2004+
if (!秘hasRasterData)
2005+
return (DOMNode) (秘canvas != null ? 秘canvas
2006+
: 秘imgNode != null ? 秘imgNode : JSGraphicsCompositor.createImageNode(this));
2007+
//$fall-through$
2008+
case GET_IMAGE_FOR_RASTER:
2009+
// we are forcing
2010+
秘getPixelsFromRaster();
2011+
秘g = null;
2012+
秘getImageGraphic();
2013+
DOMNode canvas = 秘g.getCanvas();
2014+
秘g = null;
2015+
秘canvas = null;
2016+
return canvas;
2017+
}
19922018
}
19932019

19942020
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public final BufferedImage filter (BufferedImage src, BufferedImage dst) {
214214
if (origDst != dst) {
215215
Graphics2D g = origDst.createGraphics();
216216
try {
217-
((JSGraphics2D)(Object)g).drawImagePriv(dst, 0, 0, null);
217+
((JSGraphics2D)(Object)g).drawImageFromRaster(dst, 0, 0, null);
218218
} finally {
219219
g.dispose();
220220
}

0 commit comments

Comments
 (0)