Skip to content

Commit 3e3ccc5

Browse files
committed
Applet resizing
Applet resizing is possible, but apparently not in Java when the applet is embedded. So we copy that idea in JavaScript as well. But we still allow an applet resizer handle. TODO: make applet resizer handle able to be removed by developer. Default none?
1 parent 5ab9c43 commit 3e3ccc5

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed
-2.23 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/applet/Applet.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@ public void setVisible(boolean b) {
219219
*/
220220
@Override
221221
public void resize(int width, int height) {
222-
if (appletViewer == null) {
222+
// no resizing if we have a stub -- embedded in a page
223+
if (stub == null)
223224
resizeOriginal(width, height);
224-
} else {
225-
// use J2S.Applet._resizeApplet.
225+
}
226+
227+
public void resizeHTML(int width, int height) {
228+
if (appletViewer != null)
226229
appletViewer.html5Applet._resizeApplet(new int[] {width, height});
227-
}
228230
}
229-
231+
230232
@SuppressWarnings("deprecation")
231233
public void resizeOriginal(int width, int height) {
232234
Dimension d = size();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ public abstract class JSComponent extends Component {
5454
*
5555
* SwingJS Applet repurposes resize(width, height) to call
5656
* J2S.Applet.prototype._resizeApplet in order to take care
57-
* of all the HTML5 business associated with this applet.
57+
* of all the HTML5 business associated with this applet, and
58+
* it overrides resizeOriginal as well
5859
*
5960
*
6061
* @param width
6162
* @param height
6263
*/
6364
@SuppressWarnings("deprecation")
6465
public void resizeOriginal(int width, int height) {
66+
// o
6567
resize(width, height);
6668
}
6769

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public int run1(int mode) {
410410
}
411411
System.out.println("JSAppletViewer init");
412412
japplet.setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
413-
japplet.resizeOriginal(defaultAppletSize.width, defaultAppletSize.height);
413+
japplet.resizeHTML(defaultAppletSize.width, defaultAppletSize.height);
414414
japplet.init();
415415
// Need the default(fallback) font to be created in this
416416
// AppContext

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected void fHandleDOMResize(Object event, int dw, int dh) {
148148
if (jframe == null) {
149149
rootPane.getGraphics().setColor(Color.WHITE);
150150
rootPane.getGraphics().fillRect(0, 0, r.width, r.height);
151-
((JApplet) rootPane.getParent()).resize(r.width, r.height);
151+
((JApplet) rootPane.getParent()).resizeHTML(r.width, r.height);
152152
} else {
153153
jframe.setPreferredSize(new Dimension(r.width, r.height));
154154
jframe.invalidate();

0 commit comments

Comments
 (0)