mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Добавлен WindowListener
This commit is contained in:
parent
4185fd5baa
commit
69e1a562fc
@ -29,6 +29,7 @@ public abstract class ContainerValue extends ComponentValue {
|
|||||||
set("getComponentCount", voidToInt(container::getComponentCount));
|
set("getComponentCount", voidToInt(container::getComponentCount));
|
||||||
set("isFocusCycleRoot", voidToBoolean(container::isFocusCycleRoot));
|
set("isFocusCycleRoot", voidToBoolean(container::isFocusCycleRoot));
|
||||||
set("isValidateRoot", voidToBoolean(container::isValidateRoot));
|
set("isValidateRoot", voidToBoolean(container::isValidateRoot));
|
||||||
|
set("setFocusCycleRoot", booleanToVoid(container::setFocusCycleRoot));
|
||||||
set("setLayout", new FunctionValue(this::setLayout));
|
set("setLayout", new FunctionValue(this::setLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package com.annimon.ownlang.modules.forms;
|
|||||||
import static com.annimon.ownlang.lib.Converters.*;
|
import static com.annimon.ownlang.lib.Converters.*;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
public class JFrameValue extends ContainerValue {
|
public class JFrameValue extends WindowValue {
|
||||||
|
|
||||||
final JFrame frame;
|
final JFrame frame;
|
||||||
|
|
||||||
@ -14,13 +14,10 @@ public class JFrameValue extends ContainerValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
set("dispose", voidToVoid(frame::dispose));
|
|
||||||
set("getTitle", voidToString(frame::getTitle));
|
set("getTitle", voidToString(frame::getTitle));
|
||||||
|
set("getResizable", voidToBoolean(frame::isResizable));
|
||||||
set("getDefaultCloseOperation", voidToInt(frame::getDefaultCloseOperation));
|
set("getDefaultCloseOperation", voidToInt(frame::getDefaultCloseOperation));
|
||||||
set("pack", voidToVoid(frame::pack));
|
|
||||||
set("setAlwaysOnTop", booleanOptToVoid(frame::setAlwaysOnTop));
|
|
||||||
set("setDefaultCloseOperation", intToVoid(frame::setDefaultCloseOperation));
|
set("setDefaultCloseOperation", intToVoid(frame::setDefaultCloseOperation));
|
||||||
set("setLocationByPlatform", booleanOptToVoid(frame::setLocationByPlatform));
|
|
||||||
set("setResizable", booleanOptToVoid(frame::setResizable));
|
set("setResizable", booleanOptToVoid(frame::setResizable));
|
||||||
set("setTitle", stringToVoid(frame::setTitle));
|
set("setTitle", stringToVoid(frame::setTitle));
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.annimon.ownlang.modules.forms;
|
||||||
|
|
||||||
|
import com.annimon.ownlang.lib.Arguments;
|
||||||
|
import static com.annimon.ownlang.lib.Converters.*;
|
||||||
|
import com.annimon.ownlang.lib.Function;
|
||||||
|
import com.annimon.ownlang.lib.MapValue;
|
||||||
|
import com.annimon.ownlang.lib.NumberValue;
|
||||||
|
import com.annimon.ownlang.lib.StringValue;
|
||||||
|
import com.annimon.ownlang.lib.Value;
|
||||||
|
import com.annimon.ownlang.lib.ValueUtils;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.event.WindowListener;
|
||||||
|
|
||||||
|
public class WindowValue extends ContainerValue {
|
||||||
|
|
||||||
|
private final Window window;
|
||||||
|
|
||||||
|
public WindowValue(int functionsCount, Window window) {
|
||||||
|
super(functionsCount + 18, window);
|
||||||
|
this.window = window;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
set("addWindowListener", this::addWindowListener);
|
||||||
|
set("dispose", voidToVoid(window::dispose));
|
||||||
|
set("isActive", voidToBoolean(window::isActive));
|
||||||
|
set("isAlwaysOnTop", voidToBoolean(window::isAlwaysOnTop));
|
||||||
|
set("isAlwaysOnTopSupported", voidToBoolean(window::isAlwaysOnTopSupported));
|
||||||
|
set("isAutoRequestFocus", voidToBoolean(window::isAutoRequestFocus));
|
||||||
|
set("isFocusableWindow", voidToBoolean(window::isFocusableWindow));
|
||||||
|
set("isFocused", voidToBoolean(window::isFocused));
|
||||||
|
set("isLocationByPlatform", voidToBoolean(window::isLocationByPlatform));
|
||||||
|
set("isShowing", voidToBoolean(window::isShowing));
|
||||||
|
set("getOpacity", voidToFloat(window::getOpacity));
|
||||||
|
set("pack", voidToVoid(window::pack));
|
||||||
|
set("setAlwaysOnTop", booleanOptToVoid(window::setAlwaysOnTop));
|
||||||
|
set("setAutoRequestFocus", booleanToVoid(window::setAutoRequestFocus));
|
||||||
|
set("setFocusableWindowState", booleanToVoid(window::setFocusableWindowState));
|
||||||
|
set("setLocationByPlatform", booleanOptToVoid(window::setLocationByPlatform));
|
||||||
|
set("setOpacity", floatToVoid(window::setOpacity));
|
||||||
|
set("toBack", voidToVoid(window::toBack));
|
||||||
|
set("toFront", voidToVoid(window::toFront));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Value addWindowListener(Value[] args) {
|
||||||
|
Arguments.check(1, args.length);
|
||||||
|
final Function action = ValueUtils.consumeFunction(args[0], 0);
|
||||||
|
window.addWindowListener(new WindowListener() {
|
||||||
|
@Override
|
||||||
|
public void windowOpened(WindowEvent e) {
|
||||||
|
handleWindowEvent("opened", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
handleWindowEvent("closing", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
handleWindowEvent("closed", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowIconified(WindowEvent e) {
|
||||||
|
handleWindowEvent("iconified", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowDeiconified(WindowEvent e) {
|
||||||
|
handleWindowEvent("deiconified", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowActivated(WindowEvent e) {
|
||||||
|
handleWindowEvent("activated", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowDeactivated(WindowEvent e) {
|
||||||
|
handleWindowEvent("deactivated", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleWindowEvent(String type, final WindowEvent e) {
|
||||||
|
final MapValue map = new MapValue(4);
|
||||||
|
map.set("id", NumberValue.of(e.getID()));
|
||||||
|
map.set("newState", NumberValue.of(e.getNewState()));
|
||||||
|
map.set("oldState", NumberValue.of(e.getOldState()));
|
||||||
|
map.set("paramString", new StringValue(e.paramString()));
|
||||||
|
action.execute(new StringValue(type), map);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return NumberValue.ZERO;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package com.annimon.ownlang.modules.forms;
|
|||||||
import com.annimon.ownlang.lib.*;
|
import com.annimon.ownlang.lib.*;
|
||||||
import com.annimon.ownlang.modules.Module;
|
import com.annimon.ownlang.modules.Module;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
@ -92,6 +93,21 @@ public final class forms implements Module {
|
|||||||
box.set("X_AXIS", NumberValue.of(BoxLayout.X_AXIS));
|
box.set("X_AXIS", NumberValue.of(BoxLayout.X_AXIS));
|
||||||
box.set("Y_AXIS", NumberValue.of(BoxLayout.Y_AXIS));
|
box.set("Y_AXIS", NumberValue.of(BoxLayout.Y_AXIS));
|
||||||
Variables.define("BoxLayout", box);
|
Variables.define("BoxLayout", box);
|
||||||
|
|
||||||
|
final MapValue windowEvent = new MapValue(4);
|
||||||
|
windowEvent.set("WINDOW_FIRST", NumberValue.of(WindowEvent.WINDOW_FIRST));
|
||||||
|
windowEvent.set("WINDOW_OPENED", NumberValue.of(WindowEvent.WINDOW_OPENED));
|
||||||
|
windowEvent.set("WINDOW_CLOSING", NumberValue.of(WindowEvent.WINDOW_CLOSING));
|
||||||
|
windowEvent.set("WINDOW_CLOSED", NumberValue.of(WindowEvent.WINDOW_CLOSED));
|
||||||
|
windowEvent.set("WINDOW_ICONIFIED", NumberValue.of(WindowEvent.WINDOW_ICONIFIED));
|
||||||
|
windowEvent.set("WINDOW_DEICONIFIED", NumberValue.of(WindowEvent.WINDOW_DEICONIFIED));
|
||||||
|
windowEvent.set("WINDOW_ACTIVATED", NumberValue.of(WindowEvent.WINDOW_ACTIVATED));
|
||||||
|
windowEvent.set("WINDOW_DEACTIVATED", NumberValue.of(WindowEvent.WINDOW_DEACTIVATED));
|
||||||
|
windowEvent.set("WINDOW_GAINED_FOCUS", NumberValue.of(WindowEvent.WINDOW_GAINED_FOCUS));
|
||||||
|
windowEvent.set("WINDOW_LOST_FOCUS", NumberValue.of(WindowEvent.WINDOW_LOST_FOCUS));
|
||||||
|
windowEvent.set("WINDOW_STATE_CHANGED", NumberValue.of(WindowEvent.WINDOW_STATE_CHANGED));
|
||||||
|
windowEvent.set("WINDOW_LAST", NumberValue.of(WindowEvent.WINDOW_LAST));
|
||||||
|
Variables.define("WindowEvent", windowEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user