package com.nexirius.framework.application;
import com.nexirius.framework.datamodel.StructModel;
import com.nexirius.framework.datamodel.IntModel;
import com.nexirius.framework.datamodel.StringModel;
import javax.swing.*;
import java.awt.*;
public class DialogPropertiesModel extends StructModel {
private StringModel name;
private IntModel x;
private IntModel y;
private IntModel w;
private IntModel h;
public DialogPropertiesModel(String name, Rectangle bounds) {
super("DialogProperties");
init(name, bounds);
}
public DialogPropertiesModel() {
this("", new Rectangle());
}
private void init(String name, Rectangle bounds) {
this.name = new StringModel(name, "name");
append(this.name);
x = new IntModel(bounds.x, "x");
append(x);
y = new IntModel(bounds.y, "y");
append(y);
w = new IntModel(bounds.width, "w");
append(w);
h = new IntModel(bounds.height, "h");
append(h);
}
public boolean apply(JDialog dialog) {
boolean ret = false;
Rectangle newBounds = getBounds();
Rectangle screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
if (screen.contains(newBounds)) {
dialog.setBounds(newBounds);
ret = true;
}
dialog.setName(name.getText());
return ret;
}
public Rectangle getBounds() {
return new Rectangle(x.getInt(), y.getInt(), w.getInt(), h.getInt());
}
public String getName() {
return name.getText();
}
}