Skip to content

Commit 58c71ae

Browse files
hansonrhansonr
authored andcommitted
allowing for undecorated JInternalFrame and Frame
1 parent ccf132d commit 58c71ae

File tree

8 files changed

+73
-80
lines changed

8 files changed

+73
-80
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,12 @@ public Rectangle getMaximizedBounds() {
833833
*/
834834
public void setUndecorated(boolean undecorated) {
835835
/* Make sure we don't run in the middle of peer creation.*/
836-
synchronized (getTreeLock()) {
837-
if (isDisplayable()) {
838-
throw new IllegalComponentStateException("The frame is displayable.");
839-
}
836+
// synchronized (getTreeLock()) {
837+
// if (isDisplayable()) {
838+
// throw new IllegalComponentStateException("The frame is displayable.");
839+
// }
840840
this.undecorated = undecorated;
841-
}
841+
// }
842842
}
843843

844844
/**

sources/net.sf.j2s.java.core/src/javax/swing/JInternalFrame.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@
2525

2626
package javax.swing;
2727

28-
import java.awt.*;
29-
28+
import java.awt.Component;
29+
import java.awt.Container;
30+
import java.awt.Cursor;
31+
import java.awt.Dimension;
32+
import java.awt.Graphics;
33+
import java.awt.JSComponent;
34+
import java.awt.Rectangle;
35+
import java.beans.PropertyChangeEvent;
36+
import java.beans.PropertyChangeListener;
3037
import java.beans.PropertyVetoException;
3138
import java.beans.VetoableChangeListener;
3239
import java.beans.VetoableChangeSupport;
33-
import java.beans.PropertyChangeEvent;
3440

35-
import javax.swing.event.EventListenerList;
3641
import javax.swing.event.InternalFrameEvent;
3742
import javax.swing.event.InternalFrameListener;
38-
import javax.swing.plaf.*;
39-
40-
import javax.accessibility.*;
43+
import javax.swing.plaf.InternalFrameUI;
4144

42-
import java.io.ObjectOutputStream;
43-
import java.io.IOException;
44-
import java.beans.PropertyChangeListener;
4545
import sun.awt.AppContext;
4646
import sun.swing.SwingUtilities2;
4747

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.awt.JSFrame;
1818
import java.awt.JobAttributes;
1919
import java.awt.PageAttributes;
20+
import java.awt.Point;
2021
import java.awt.PrintJob;
2122
import java.awt.Window;
2223
import java.awt.datatransfer.Clipboard;
@@ -990,4 +991,8 @@ public static void consumeEvent(Object e) {
990991
*/
991992
}
992993

994+
public static Point getMouseLocation() {
995+
return JSUtil.J2S.getMousePosition(new Point());
996+
}
997+
993998
}

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

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

33
import java.awt.JSComponent;
4+
import java.awt.Point;
45
import java.util.Hashtable;
56

67
import javajs.api.JSFunction;
@@ -23,6 +24,8 @@ public interface J2SInterface {
2324

2425
void getFileFromDialog(JSFunction f, String type);
2526

27+
Point getMousePosition(Point p);
28+
2629
Object getJavaResource(String resourceName, boolean isJavaPath);
2730

2831
String getJavaVersion();

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package swingjs.plaf;
22

3-
import javajs.api.JSFunction;
4-
53
import java.awt.Color;
6-
import java.awt.Container;
74
import java.awt.Dimension;
85
import java.awt.Insets;
96
import java.awt.Rectangle;
107
import java.awt.Toolkit;
118
import java.awt.event.ComponentEvent;
12-
import java.awt.event.ComponentListener;
139
import java.awt.event.WindowEvent;
14-
import java.awt.event.WindowListener;
1510
import java.awt.peer.FramePeer;
1611
import java.beans.PropertyChangeEvent;
1712

1813
import javax.swing.JComponent;
1914
import javax.swing.JFrame;
2015
import javax.swing.LookAndFeel;
21-
import javax.swing.SwingUtilities;
2216

23-
import swingjs.JSUtil;
17+
import javajs.api.JSFunction;
2418
import swingjs.api.js.DOMNode;
2519

2620
public class JSFrameUI extends JSWindowUI implements FramePeer {
2721

22+
private static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);
23+
2824
// a window with a border and optional menubar and (though not here) min and max buttons
2925

3026
// Adds a root pane to the JPanel content pane to connect the menubar with the content plane
@@ -114,7 +110,8 @@ public DOMNode updateDOMNode() {
114110
DOMNode.setStyles(closerNode, "width", "20px", "height", "20px", "position", "absolute", "text-align",
115111
"center", "right", "0px");
116112
bindJQueryEvents(closerNode, "click mouseenter mouseout", -1);
117-
frameNode.appendChild(titleBarNode);
113+
if (!frame.isUndecorated())
114+
frameNode.appendChild(titleBarNode);
118115
if (isModal) {
119116
modalNode = DOMNode.createElement("div", id + "_modaldiv");
120117
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
@@ -314,7 +311,7 @@ public Rectangle getBoundsPrivate() {
314311

315312
@Override
316313
public Insets getInsets() {
317-
return (isDummyFrame ? null : jc.getFrameViewer().getInsets());
314+
return (isDummyFrame ? null : frame.isUndecorated() ? ZERO_INSETS : jc.getFrameViewer().getInsets());
318315
}
319316

320317
@Override

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

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.awt.Container;
55
import java.awt.Dimension;
66
import java.awt.IllegalComponentStateException;
7-
import java.awt.event.ComponentEvent;
87
import java.awt.event.WindowEvent;
98
import java.awt.event.WindowFocusListener;
109
import java.beans.PropertyChangeEvent;
@@ -15,6 +14,7 @@
1514
import javax.swing.Icon;
1615
import javax.swing.InputMap;
1716
import javax.swing.JComponent;
17+
import javax.swing.JDesktopPane;
1818
import javax.swing.JInternalFrame;
1919
import javax.swing.LookAndFeel;
2020
import javax.swing.SwingConstants;
@@ -25,6 +25,7 @@
2525
import javax.swing.plaf.UIResource;
2626

2727
import sun.swing.DefaultLookup;
28+
import swingjs.api.js.DOMNode;
2829

2930
public class JSInternalFrameUI extends JSFrameUI {
3031

@@ -33,6 +34,15 @@ public JSInternalFrameUI() {
3334
isInternalFrame = true;
3435
}
3536

37+
38+
@Override
39+
public DOMNode updateDOMNode() {
40+
super.updateDOMNode();
41+
42+
return domNode;
43+
44+
}
45+
3646
@Override
3747
protected void frameCloserAction() {
3848
JInternalFrame jif = (JInternalFrame) iframe;
@@ -61,6 +71,7 @@ public int[] getMoveCoords(int x, int y) {
6171
private Handler handler;
6272
private Handler internalFrameListener;
6373
private PropertyChangeListener propertyChangeListener;
74+
private boolean titleBarHidden;
6475
private static DesktopManager sharedDesktopManager;
6576

6677
@Override
@@ -187,13 +198,7 @@ protected void installListeners() {
187198
// }
188199
}
189200

190-
// Provide a FocusListener to listen for a WINDOW_LOST_FOCUS event,
191-
// so that a resize can be cancelled if the focus is lost while resizing
192-
// when an Alt-Tab, modal dialog popup, iconify, dispose, or remove
193-
// of the internal frame occurs.
194-
private WindowFocusListener getWindowFocusListener(){
195-
return getHandler();
196-
}
201+
197202

198203
// // Cancel a resize in progress by calling finishMouseReleased().
199204
// private void cancelResize() {
@@ -463,47 +468,6 @@ public void windowLostFocus(WindowEvent e) {
463468
// cancelResize();
464469
}
465470

466-
// ComponentHandler methods
467-
/** Invoked when a JInternalFrame's parent's size changes. */
468-
public void componentResized(ComponentEvent e) {
469-
hideAllMenus();
470-
// // Get the JInternalFrame's parent container size
471-
// Rectangle parentNewBounds = ((Component) e.getSource()).getBounds();
472-
// JInternalFrame.JDesktopIcon icon = null;
473-
//
474-
// if (frame != null) {
475-
// icon = frame.getDesktopIcon();
476-
// // Resize the internal frame if it is maximized and relocate
477-
// // the associated icon as well.
478-
// if (frame.isMaximum()) {
479-
// frame.setBounds(0, 0, parentNewBounds.width,
480-
// parentNewBounds.height);
481-
// }
482-
// }
483-
//
484-
// // Relocate the icon base on the new parent bounds.
485-
// if (icon != null) {
486-
// Rectangle iconBounds = icon.getBounds();
487-
// int y = iconBounds.y +
488-
// (parentNewBounds.height - parentBounds.height);
489-
// icon.setBounds(iconBounds.x, y,
490-
// iconBounds.width, iconBounds.height);
491-
// }
492-
//
493-
// // Update the new parent bounds for next resize.
494-
//// if (!parentBounds.equals(parentNewBounds)) {
495-
//// parentBounds = parentNewBounds;
496-
//// }
497-
//
498-
// // Validate the component tree for this container.
499-
// if (frame != null) frame.validate();
500-
}
501-
502-
public void componentMoved(ComponentEvent e) {hideAllMenus();}
503-
public void componentShown(ComponentEvent e) {hideAllMenus();}
504-
public void componentHidden(ComponentEvent e) {hideAllMenus();}
505-
506-
507471
// InternalFrameListener
508472
@Override
509473
public void internalFrameClosed(InternalFrameEvent e) {
@@ -513,7 +477,7 @@ public void internalFrameClosed(InternalFrameEvent e) {
513477

514478
@Override
515479
public void internalFrameActivated(InternalFrameEvent e) {
516-
hideAllMenus();
480+
// hideAllMenus();
517481
// if (!isKeyBindingRegistered()){
518482
// setKeyBindingRegistered(true);
519483
// setupMenuOpenKey();
@@ -578,6 +542,14 @@ public void propertyChange(PropertyChangeEvent evt) {
578542
deactivateFrame(f);
579543
}
580544
} else if (prop == "ancestor") {
545+
if (frame.getParent() != null) {
546+
boolean allowResize = frame.isResizable() && frame.getParent() instanceof JDesktopPane;
547+
Resizer r = frame.getFrameViewer().resizer;
548+
if (r != null) {
549+
r.setEnabled(allowResize);
550+
r.setAllowResize(allowResize);
551+
}
552+
}
581553
// if (newValue == null) {
582554
// // Cancel a resize in progress, if the internal frame
583555
// // gets a remove(), removeNotify() or setIcon(true).
@@ -604,4 +576,10 @@ public void propertyChange(PropertyChangeEvent evt) {
604576
}
605577
}
606578

579+
public void setNorthPane(JComponent c) {
580+
frame.setUndecorated(true);
581+
//DOMNode.setVisible(titleBarNode, c != null);
582+
setTainted();
583+
}
584+
607585
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ protected void setWindowClass() {
104104
DOMNode.setZ(domNode, z);
105105
$(domNode).addClass("swingjs-window");
106106

107-
System.out.println("JSWIndowUI ????");
107+
System.out.println("JSWIndowUI testing?");
108108

109-
// these next two lines are what allow the FocusManager to work.
109+
// these next two lines are what allow the FocusManager to work....or not
110110
// focusNode = domNode;
111111
// addJQueryFocusCallbacks();
112112
}
@@ -257,7 +257,7 @@ public void windowDeiconified(WindowEvent e) {
257257

258258
@Override
259259
public void windowActivated(WindowEvent e) {
260-
System.out.println("JSFrameUI windowActivated " + c.isVisible());
260+
// System.out.println("JSFrameUI windowActivated " + c.isVisible());
261261
// c.requestFocus(); // caused problem with combobox focus
262262
}
263263

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Resizer {
2828
@SuppressWarnings("unused")
2929
private int titleHeight;
3030
private boolean enabled = true;
31+
private boolean allowResize = true;
3132

3233
public Resizer() {
3334
}
@@ -46,7 +47,7 @@ public Resizer set(JSFrameViewer viewer, RootPaneContainer top) {
4647
}
4748

4849
public void show() {
49-
if (!enabled)
50+
if (!allowResize || !enabled)
5051
return;
5152
if (resizer == null)
5253
createAndShowResizer();
@@ -108,7 +109,7 @@ public DOMNode getDOMNode() {
108109
* @param type
109110
*/
110111
protected void fHandleResizer(int dx, int dy, int type) {
111-
if (!enabled)
112+
if (!enabled || !allowResize)
112113
return;
113114
switch (type) {
114115
case MouseEvent.MOUSE_MOVED:
@@ -173,8 +174,17 @@ private Rectangle getFrameOffset(int dw, int dh) {
173174
return r;
174175
}
175176

177+
/**
178+
* Embedded frames can do this
179+
*
180+
* @param b
181+
*/
182+
public void setAllowResize(boolean b) {
183+
allowResize = b;
184+
}
185+
176186
public void setEnabled(boolean b) {
177-
enabled = b;
187+
enabled = b;
178188
if (b)
179189
show();
180190
else

0 commit comments

Comments
 (0)