most of mouse listeners, added title bar and title bar listeners with maximize and drag reposition
|
Before Width: | Height: | Size: 259 B |
|
Before Width: | Height: | Size: 264 B |
BIN
resources/icons/close_black.png
Normal file
|
After Width: | Height: | Size: 149 B |
BIN
resources/icons/close_white.png
Normal file
|
After Width: | Height: | Size: 154 B |
|
Before Width: | Height: | Size: 85 B After Width: | Height: | Size: 85 B |
|
Before Width: | Height: | Size: 88 B After Width: | Height: | Size: 88 B |
|
Before Width: | Height: | Size: 128 B After Width: | Height: | Size: 128 B |
|
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 131 B |
@@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<Window Name="window" Visible="true" Size="640, 480">
|
<Window Name="window" Visible="true" Size="640, 480">
|
||||||
<Button Name="button1" BackgroundColor="#990000" Size="200, 200" Label="button1">
|
<Button Name="button1" BackgroundColor="#990000" Size="200, 200" Label="button1">
|
||||||
<Button Name="button4" BackgroundColor="#009999" Size="100, 100" Label="button4">
|
<Button Name="button4" BackgroundColor="#009999" Size="100, 100" Icon="square_white">
|
||||||
<Button Name="button2" BackgroundColor="#000099" Label="button2"/>
|
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Name="button3" BackgroundColor="#009900" Location="300, 300" Label="button3"/>
|
<Button Name="button6" Location="350, 350" Size="100, 100"/>
|
||||||
|
<Button Name="button3" BackgroundColor="#009900" Size="100, 100" Location="300, 300" Icon="close_black"/>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
import guiTree.Button;
|
import guiTree.Components.Button;
|
||||||
|
import guiTree.Components.TitleBar;
|
||||||
import guiTree.Window;
|
import guiTree.Window;
|
||||||
import parser.XAMLParser;
|
import parser.XAMLParser;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -12,36 +18,42 @@ public class Main {
|
|||||||
assert window != null;
|
assert window != null;
|
||||||
window.revalidate();
|
window.revalidate();
|
||||||
Button button = (Button)window.findByName("button1");
|
Button button = (Button)window.findByName("button1");
|
||||||
window.addWindowListener(new WindowAdapter() {
|
|
||||||
@Override
|
BufferedImage icon = null;
|
||||||
public void windowClosing(WindowEvent e) {
|
try {
|
||||||
window.dispose();
|
icon = ImageIO.read(new File("resources\\icons\\square_white.png"));
|
||||||
}
|
} catch (IOException e) {
|
||||||
});
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
TitleBar bar = new TitleBar("Working Title", icon);
|
||||||
|
bar.setBackgroundColor(Color.GRAY);
|
||||||
|
window.setTitleBar(bar);
|
||||||
|
|
||||||
|
window.revalidate();
|
||||||
long now;
|
long now;
|
||||||
long prev = 0;
|
long prev = 0;
|
||||||
while(true) {
|
// while(true) {
|
||||||
now = System.currentTimeMillis();
|
// now = System.currentTimeMillis();
|
||||||
if(now - prev >= 1000) {
|
// if(now - prev >= 1000) {
|
||||||
int x = button.getLocationX();
|
// int x = button.getLocationX();
|
||||||
int y = button.getLocationY();
|
// int y = button.getLocationY();
|
||||||
if(x + button.getWidth() >= window.getWidth()) {
|
// if(x + button.getWidth() >= window.getWidth()) {
|
||||||
x = 0;
|
// x = 0;
|
||||||
if(y + button.getHeight() >= window.getHeight()) {
|
// if(y + button.getHeight() >= window.getHeight()) {
|
||||||
y = 0;
|
// y = 0;
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
y += 30;
|
// y += 30;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
x += 30;
|
// x += 30;
|
||||||
}
|
// }
|
||||||
button.setLocation(x, y);
|
// button.setLocation(x, y);
|
||||||
prev = now;
|
// prev = now;
|
||||||
window.revalidate();
|
// window.revalidate();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
package guiTree;
|
|
||||||
|
|
||||||
import guiTree.events.MouseAdapter;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
public class Button extends Visual {
|
|
||||||
private String label;
|
|
||||||
private Boolean pressed;
|
|
||||||
|
|
||||||
public Button() {
|
|
||||||
this("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Button(String label) {
|
|
||||||
super();
|
|
||||||
this.label = label;
|
|
||||||
pressed = false;
|
|
||||||
this.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent mouseEvent) {
|
|
||||||
pressed = true;
|
|
||||||
revalidate();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent mouseEvent) {
|
|
||||||
pressed = false;
|
|
||||||
revalidate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void paint(BufferedImage imageBuffer)
|
|
||||||
{
|
|
||||||
//Get Graphics
|
|
||||||
Graphics2D g = imageBuffer.createGraphics();
|
|
||||||
|
|
||||||
//Set Transparency
|
|
||||||
g.setComposite(AlphaComposite.Clear);
|
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
|
||||||
g.setComposite(AlphaComposite.Src);
|
|
||||||
|
|
||||||
//Choose background
|
|
||||||
if(pressed) {
|
|
||||||
g.setColor(Color.GRAY);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g.setColor(this.getBackgroundColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Draw Button
|
|
||||||
g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 50, 50);
|
|
||||||
g.setColor(this.getForegroundColor());
|
|
||||||
|
|
||||||
//Draw Label
|
|
||||||
int textWidth = g.getFontMetrics().stringWidth(label);
|
|
||||||
int textHeight = g.getFontMetrics().getHeight();
|
|
||||||
g.drawString(this.label, this.getWidth()/2 - textWidth/2, this.getHeight()/2 + textHeight/2);
|
|
||||||
|
|
||||||
g.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
return this.label;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
146
src/guiTree/Components/Button.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Visual;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Button extends Visual {
|
||||||
|
private String label;
|
||||||
|
private Boolean pressed;
|
||||||
|
private Boolean hovered;
|
||||||
|
private BufferedImage icon;
|
||||||
|
|
||||||
|
public Button() {
|
||||||
|
this("", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button(String label) {
|
||||||
|
this(label, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button(BufferedImage icon) {
|
||||||
|
this(null, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button(String label, BufferedImage icon) {
|
||||||
|
super();
|
||||||
|
this.label = label;
|
||||||
|
this.icon = icon;
|
||||||
|
pressed = false;
|
||||||
|
hovered = false;
|
||||||
|
this.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("Pressed: " + getName());
|
||||||
|
pressed = true;
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("Released: " + getName());
|
||||||
|
pressed = false;
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("Entered: " + getName());
|
||||||
|
hovered = true;
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("Exited: " + getName());
|
||||||
|
hovered = false;
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("DRAGGING: " + getName());
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
|
System.out.println("Moved: " + getName());
|
||||||
|
revalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(BufferedImage imageBuffer)
|
||||||
|
{
|
||||||
|
//Get Graphics
|
||||||
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
|
|
||||||
|
//Set Transparency
|
||||||
|
g.setComposite(AlphaComposite.Clear);
|
||||||
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
g.setComposite(AlphaComposite.Src);
|
||||||
|
|
||||||
|
//Choose background
|
||||||
|
if(hovered || pressed) {
|
||||||
|
g.setColor(this.getForegroundColor());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.setColor(this.getBackgroundColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw Button
|
||||||
|
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||||
|
g.setColor(this.getFontColor());
|
||||||
|
|
||||||
|
//Draw Label
|
||||||
|
int textWidth = 0;
|
||||||
|
int textHeight = 0;
|
||||||
|
if(!label.equals("")) {
|
||||||
|
textWidth = g.getFontMetrics().stringWidth(label);
|
||||||
|
textHeight = g.getFontMetrics().getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.drawString(this.label, (this.getWidth() - textWidth)/2, (this.getHeight() + textHeight)/2);
|
||||||
|
|
||||||
|
//Draw Icon
|
||||||
|
if(icon != null) {
|
||||||
|
int iconWidth = icon.getWidth();
|
||||||
|
int iconHeight = icon.getHeight();
|
||||||
|
|
||||||
|
int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
|
||||||
|
int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
|
||||||
|
Graphics2D g2 = imageBuffer.createGraphics();
|
||||||
|
g2.drawImage(icon, iconX, iconY, null);
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return this.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(BufferedImage icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String url) {
|
||||||
|
try{
|
||||||
|
icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
148
src/guiTree/Components/TitleBar.java
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Helper.Point2d;
|
||||||
|
import guiTree.Visual;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class TitleBar extends Visual {
|
||||||
|
public static final int MINIMIZE = 1;
|
||||||
|
public static final int MAXIMIZE = 2;
|
||||||
|
public static final int CLOSE = 3;
|
||||||
|
|
||||||
|
private BufferedImage icon;
|
||||||
|
private String title;
|
||||||
|
private Button minimize;
|
||||||
|
private Button maximize;
|
||||||
|
private Button close;
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------
|
||||||
|
Constructors
|
||||||
|
---------------------------------------------------------------------*/
|
||||||
|
public TitleBar() {
|
||||||
|
this(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TitleBar(String title) {
|
||||||
|
this(title, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TitleBar(BufferedImage icon) {
|
||||||
|
this(null, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TitleBar(String title, BufferedImage icon) {
|
||||||
|
super();
|
||||||
|
this.icon = icon;
|
||||||
|
this.title = title;
|
||||||
|
|
||||||
|
this.close = new Button();
|
||||||
|
this.minimize = new Button();
|
||||||
|
this.maximize = new Button();
|
||||||
|
close.setIcon("close_white");
|
||||||
|
minimize.setIcon("minimize_white");
|
||||||
|
maximize.setIcon("square_white");
|
||||||
|
close.setSize(60, 30);
|
||||||
|
minimize.setSize(60, 30);
|
||||||
|
maximize.setSize(60, 30);
|
||||||
|
close.setBackgroundColor(Color.GRAY);
|
||||||
|
maximize.setBackgroundColor(Color.GRAY);
|
||||||
|
minimize.setBackgroundColor(Color.GRAY);
|
||||||
|
close.setForegroundColor(Color.RED);
|
||||||
|
maximize.setForegroundColor(Color.LIGHT_GRAY);
|
||||||
|
minimize.setForegroundColor(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
|
this.setSize(1, 30);
|
||||||
|
this.setLocation(0, 0);
|
||||||
|
|
||||||
|
setButtonLocation();
|
||||||
|
close.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
|
notifyParent(3);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
maximize.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
|
notifyParent(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
minimize.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
|
notifyParent(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------
|
||||||
|
Getters
|
||||||
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
public BufferedImage getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String geTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------
|
||||||
|
Setters
|
||||||
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
public void setIcon(BufferedImage icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSize(Integer width, Integer height) {
|
||||||
|
super.setSize(width, height);
|
||||||
|
setButtonLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(BufferedImage imageBuffer) {
|
||||||
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
|
g.setColor(getBackgroundColor());
|
||||||
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
|
Graphics2D iconGraphics = imageBuffer.createGraphics();
|
||||||
|
iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null);
|
||||||
|
iconGraphics.dispose();
|
||||||
|
|
||||||
|
int stringOffset = icon.getWidth() + 10;
|
||||||
|
int textHeight = 0;
|
||||||
|
if(!title.equals("")) {
|
||||||
|
textHeight = g.getFontMetrics().getHeight();
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
g.drawString(title, stringOffset, getHeight()/2 + textHeight/4);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setButtonLocation() {
|
||||||
|
int buttonOffset = this.getWidth() - close.getWidth();
|
||||||
|
close.setLocation(buttonOffset, 0);
|
||||||
|
close.setName("close");
|
||||||
|
buttonOffset -= maximize.getWidth();
|
||||||
|
maximize.setLocation(buttonOffset, 0);
|
||||||
|
maximize.setName("maximize");
|
||||||
|
buttonOffset -= minimize.getWidth();
|
||||||
|
minimize.setLocation(buttonOffset, 0);
|
||||||
|
minimize.setName("minimize");
|
||||||
|
this.addVisual(close);
|
||||||
|
this.addVisual(minimize);
|
||||||
|
this.addVisual(maximize);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,6 @@ public class CustomFrame extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g)
|
public void paint(Graphics g)
|
||||||
{
|
{
|
||||||
g.drawImage(imageBuffer, 5, 0, this.getWidth(), this.getHeight(), null);
|
g.drawImage(imageBuffer, 0, 0, this.getWidth(), this.getHeight(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/guiTree/Helper/Point2d.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package guiTree.Helper;
|
||||||
|
|
||||||
|
public class Point2d {
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
|
||||||
|
public Point2d(int x,int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,41 +12,36 @@ public class MouseEventGetter implements MouseInputListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent mouseEvent) {
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseDragged(mouseEvent, 0, 0);
|
callingWindow.mouseDragged(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent mouseEvent) {
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseMoved(mouseEvent, 0, 0);
|
callingWindow.mouseMoved(mouseEvent, 0, 0);
|
||||||
System.out.println("MOVED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent mouseEvent) {
|
public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseClicked(mouseEvent, 0, 0);
|
callingWindow.mouseClicked(mouseEvent);
|
||||||
System.out.println("CLICKED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent) {
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
callingWindow.mousePressed(mouseEvent, 0, 0);
|
callingWindow.mousePressed(mouseEvent);
|
||||||
System.out.println("PRESSED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent mouseEvent) {
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseReleased(mouseEvent, 0, 0);
|
callingWindow.mouseReleased(mouseEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent mouseEvent) {
|
public void mouseEntered(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseEntered(mouseEvent, 0, 0);
|
callingWindow.mouseEntered(mouseEvent, 0, 0);
|
||||||
System.out.println("ENTERED");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent mouseEvent) {
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
callingWindow.mouseExited(mouseEvent, 0, 0);
|
callingWindow.mouseExited(mouseEvent);
|
||||||
System.out.println("EXITED");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class Visual {
|
|||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Tree Elements
|
Tree Elements
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
private List<Visual> children;
|
private List<Visual> children;
|
||||||
private Visual parent;
|
private Visual parent;
|
||||||
private BufferedImage imageBuffer;
|
private BufferedImage imageBuffer;
|
||||||
@@ -27,33 +28,50 @@ public class Visual {
|
|||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Attributes
|
Attributes
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
private Integer width;
|
private Integer width;
|
||||||
private Integer height;
|
private Integer height;
|
||||||
private Integer locationX;
|
private Integer locationX;
|
||||||
private Integer locationY;
|
private Integer locationY;
|
||||||
private Color backgroundColor;
|
private Color backgroundColor;
|
||||||
private Color foregroundColor;
|
private Color foregroundColor;
|
||||||
|
private Color fontColor;
|
||||||
private Boolean active;
|
private Boolean active;
|
||||||
private Boolean dirty;
|
private Boolean dirty;
|
||||||
|
private static Visual entered;
|
||||||
|
private Boolean focused;
|
||||||
private Boolean pressed;
|
private Boolean pressed;
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Constructors
|
Constructors
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
public Visual() {
|
public Visual() {
|
||||||
|
this(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Visual(int width, int height) {
|
||||||
this.children = new ArrayList<>();
|
this.children = new ArrayList<>();
|
||||||
this.mouseWheelListeners = new ArrayList<>();
|
this.mouseWheelListeners = new ArrayList<>();
|
||||||
this.mouseListeners = new ArrayList<>();
|
this.mouseListeners = new ArrayList<>();
|
||||||
this.keyListeners = new ArrayList<>();
|
this.keyListeners = new ArrayList<>();
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.backgroundColor = Color.WHITE;
|
this.backgroundColor = Color.WHITE;
|
||||||
this.foregroundColor = Color.BLACK;
|
this.foregroundColor = Color.BLUE;
|
||||||
|
this.fontColor = Color.BLACK;
|
||||||
|
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
this.active = this instanceof Window;
|
this.active = this instanceof Window;
|
||||||
}
|
this.focused = false;
|
||||||
|
this.pressed = false;
|
||||||
|
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
this.locationX = 0;
|
||||||
|
this.locationY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Attributes Setters
|
Attributes Setters
|
||||||
@@ -63,7 +81,7 @@ public class Visual {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(Integer width, Integer height){
|
public void setSize(Integer width, Integer height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
@@ -72,7 +90,7 @@ public class Visual {
|
|||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Integer x, Integer y){
|
public void setLocation(Integer x, Integer y) {
|
||||||
this.locationX = x;
|
this.locationX = x;
|
||||||
this.locationY = y;
|
this.locationY = y;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
@@ -88,21 +106,25 @@ public class Visual {
|
|||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFontColor(Color fontColor) {
|
||||||
|
this.fontColor = fontColor;
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateInitialSize() {
|
private void calculateInitialSize() {
|
||||||
if(this.width == null) {
|
if(this.width <= 0) {
|
||||||
this.width = 20;
|
this.width = 1;
|
||||||
}
|
}
|
||||||
if(this.height == null){
|
if(this.height <= 0){
|
||||||
this.height = 20;
|
this.height = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateInitialLocation(){
|
private void calculateInitialLocation() {
|
||||||
if(this.locationX == null) {
|
if(this.locationX == 0) {
|
||||||
this.locationX = 20;
|
this.locationX = 1;
|
||||||
}
|
}
|
||||||
if(this.locationY == null){
|
if(this.locationY == 0){
|
||||||
this.locationY = 50;
|
this.locationY = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,21 +136,19 @@ public class Visual {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth()
|
public int getWidth() {
|
||||||
{
|
|
||||||
return this.width;
|
return this.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight()
|
public int getHeight() {
|
||||||
{
|
|
||||||
return this.height;
|
return this.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLocationX(){
|
public int getLocationX() {
|
||||||
return this.locationX;
|
return this.locationX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLocationY(){
|
public int getLocationY() {
|
||||||
return this.locationY;
|
return this.locationY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,11 +160,15 @@ public class Visual {
|
|||||||
return foregroundColor;
|
return foregroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getFontColor() {
|
||||||
|
return fontColor;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Tree Methods
|
Tree Methods
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
public Visual findByName(String name){
|
public Visual findByName(String name) {
|
||||||
if(this.name.equals(name)){
|
if(this.name.equals(name)){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -161,9 +185,15 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addVisual(Visual child) {
|
public void addVisual(Visual child) {
|
||||||
|
this.addVisual(child, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisual(Visual child, int x, int y) {
|
||||||
this.children.add(child);
|
this.children.add(child);
|
||||||
child.setParent(this);
|
child.setParent(this);
|
||||||
child.calculateInitialLocation();
|
if(x == -1 && y == -1) {
|
||||||
|
child.calculateInitialLocation();
|
||||||
|
}
|
||||||
child.calculateInitialSize();
|
child.calculateInitialSize();
|
||||||
|
|
||||||
if(this.active) {
|
if(this.active) {
|
||||||
@@ -181,18 +211,16 @@ public class Visual {
|
|||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setParent(Visual parent)
|
private void setParent(Visual parent) {
|
||||||
{
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNotification() {
|
public void handleNotification(int notify) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyParent()
|
public void notifyParent(int notify) {
|
||||||
{
|
this.parent.handleNotification(notify);
|
||||||
this.parent.handleNotification();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repaint() {
|
private void repaint() {
|
||||||
@@ -234,94 +262,58 @@ public class Visual {
|
|||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Listener Methods
|
Listener Methods
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
void addMouseListener(MouseListener mouseListener) {
|
public void addMouseListener(MouseListener mouseListener) {
|
||||||
this.mouseListeners.add(mouseListener);
|
this.mouseListeners.add(mouseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMouseListener(MouseListener mouseListener) {
|
public void removeMouseListener(MouseListener mouseListener) {
|
||||||
this.mouseListeners.remove(mouseListener);
|
this.mouseListeners.remove(mouseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMouseWheelListener(MouseWheelListener mouseWheelListener) {
|
public void addMouseWheelListener(MouseWheelListener mouseWheelListener) {
|
||||||
this.mouseWheelListeners.add(mouseWheelListener);
|
this.mouseWheelListeners.add(mouseWheelListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMouseWheelListener(MouseWheelListener mouseWheelListener) {
|
public void removeMouseWheelListener(MouseWheelListener mouseWheelListener) {
|
||||||
this.mouseWheelListeners.remove(mouseWheelListener);
|
this.mouseWheelListeners.remove(mouseWheelListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addKeyListener(KeyListener keyListener) {
|
public void addKeyListener(KeyListener keyListener) {
|
||||||
this.keyListeners.add(keyListener);
|
this.keyListeners.add(keyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeKeyListener(KeyListener keyListener) {
|
public void removeKeyListener(KeyListener keyListener) {
|
||||||
this.keyListeners.remove(keyListener);
|
this.keyListeners.remove(keyListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseClicked(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseClicked(MouseEvent mouseEvent) {
|
||||||
boolean front = true;
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
mouseListener.mouseClicked(mouseEvent);
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mouseClicked(mouseEvent, v.locationX + offsetX, v.locationY + offsetY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(front) {
|
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
|
||||||
mouseListener.mouseClicked(mouseEvent);
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
dirty = true;
|
||||||
|
entered.focused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseReleased(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseReleased(MouseEvent mouseEvent) {
|
||||||
boolean front = true;
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
mouseListener.mouseReleased(mouseEvent);
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mouseReleased(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(front) {
|
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
|
||||||
mouseListener.mouseReleased(mouseEvent);
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
dirty = true;
|
||||||
|
entered.pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mousePressed(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mousePressed(MouseEvent mouseEvent) {
|
||||||
boolean front = true;
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
mouseListener.mousePressed(mouseEvent);
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mousePressed(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(front) {
|
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
|
||||||
mouseListener.mousePressed(mouseEvent);
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
dirty = true;
|
||||||
|
entered.pressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseEntered(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseEntered(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
||||||
|
if(entered != null && entered.pressed){
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean front = true;
|
boolean front = true;
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
int mouseX = mouseEvent.getX() - offsetX;
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
int mouseY = mouseEvent.getY() - offsetY;
|
||||||
@@ -335,6 +327,7 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(front) {
|
if(front) {
|
||||||
|
entered = this;
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
for(MouseListener mouseListener: mouseListeners) {
|
||||||
mouseListener.mouseEntered(mouseEvent);
|
mouseListener.mouseEntered(mouseEvent);
|
||||||
}
|
}
|
||||||
@@ -342,87 +335,74 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseExited(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseExited(MouseEvent mouseEvent) {
|
||||||
boolean front = true;
|
if(entered == null) {
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
return;
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mouseExited(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(front) {
|
if(entered.pressed) {
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
return;
|
||||||
mouseListener.mouseExited(mouseEvent);
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
|
mouseListener.mouseExited(mouseEvent);
|
||||||
|
}
|
||||||
|
entered = null;
|
||||||
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseDragged(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseDragged(MouseEvent mouseEvent) {
|
||||||
boolean front = true;
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
mouseListener.mouseDragged(mouseEvent);
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mouseDragged(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(front) {
|
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
|
||||||
mouseListener.mouseDragged(mouseEvent);
|
|
||||||
}
|
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
|
entered.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseMoved(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
void mouseMoved(MouseEvent mouseEvent, int offsetX, int offsetY) {
|
||||||
|
if(entered != null && entered.pressed){
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean front = true;
|
boolean front = true;
|
||||||
int mouseX = mouseEvent.getX() - offsetX;
|
int mouseX = mouseEvent.getX() - offsetX;
|
||||||
int mouseY = mouseEvent.getY() - offsetY;
|
int mouseY = mouseEvent.getY() - offsetY;
|
||||||
|
if(entered != null) {
|
||||||
|
if (!entered.isInside(mouseEvent.getX(), mouseEvent.getY())) {
|
||||||
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
|
mouseListener.mouseExited(mouseEvent);
|
||||||
|
}
|
||||||
|
entered = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
for(Visual v: children) {
|
for(Visual v: children) {
|
||||||
if(mouseX > v.getLocationX() &&
|
if(v.isInside(mouseX, mouseY)) {
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
front = false;
|
||||||
v.mouseMoved(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
v.mouseMoved(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(front) {
|
if(front) {
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
if(this.isInside(mouseEvent.getX(), mouseEvent.getY())) {
|
||||||
mouseListener.mouseMoved(mouseEvent);
|
if (this != entered && entered != null) {
|
||||||
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
|
mouseListener.mouseExited(mouseEvent);
|
||||||
|
}
|
||||||
|
entered = this;
|
||||||
|
for (MouseListener mouseListener : mouseListeners) {
|
||||||
|
mouseListener.mouseEntered(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (MouseListener mouseListener : mouseListeners) {
|
||||||
|
mouseListener.mouseMoved(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent, int offsetX, int offsetY) {
|
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent, int offsetX, int offsetY) {
|
||||||
boolean front = true;
|
if(focused) {
|
||||||
int mouseX = mouseWheelEvent.getX() - offsetX;
|
|
||||||
int mouseY = mouseWheelEvent.getY() - offsetY;
|
|
||||||
for(Visual v: children) {
|
|
||||||
if(mouseX > v.getLocationX() &&
|
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()) {
|
|
||||||
front = false;
|
|
||||||
v.mouseWheelMoved(mouseWheelEvent, offsetX + v.locationX, offsetY + v.locationY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(front) {
|
|
||||||
for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
|
for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
|
||||||
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
|
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
|
||||||
}
|
}
|
||||||
dirty = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,4 +437,8 @@ public class Visual {
|
|||||||
child.deactivate();
|
child.deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInside(int x, int y) {
|
||||||
|
return x > locationX && x < locationX + width && y > locationY && y < locationY + height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
package guiTree;
|
package guiTree;
|
||||||
|
|
||||||
|
import guiTree.Components.TitleBar;
|
||||||
|
import guiTree.Helper.Point2d;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import javax.tools.Tool;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.WindowListener;
|
import java.awt.event.WindowListener;
|
||||||
import java.awt.event.WindowStateListener;
|
import java.awt.event.WindowStateListener;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class Window extends Visual {
|
public class Window extends Visual {
|
||||||
public CustomFrame frame;
|
public CustomFrame frame;
|
||||||
|
private TitleBar titleBar;
|
||||||
|
|
||||||
public Window()
|
public Window()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.frame = new CustomFrame(this);
|
this.frame = new CustomFrame(this);
|
||||||
|
this.setUndecorated(true);
|
||||||
this.addWindowStateListener(e -> {
|
this.addWindowStateListener(e -> {
|
||||||
this.setSize(getWidth(), getHeight());
|
this.setSize(getWidth(), getHeight());
|
||||||
revalidate();
|
revalidate();
|
||||||
@@ -23,6 +31,10 @@ public class Window extends Visual {
|
|||||||
{
|
{
|
||||||
this.frame.setSize(width, height);
|
this.frame.setSize(width, height);
|
||||||
super.setSize(width, height);
|
super.setSize(width, height);
|
||||||
|
if(this.titleBar != null) {
|
||||||
|
this.titleBar.setSize(this.getWidth(), titleBar.getHeight());
|
||||||
|
}
|
||||||
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
||||||
@@ -62,6 +74,22 @@ public class Window extends Visual {
|
|||||||
frame.repaint(tm);
|
frame.repaint(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTitleBar(TitleBar titleBar) {
|
||||||
|
titleBar.setSize(this.getWidth(), titleBar.getHeight());
|
||||||
|
|
||||||
|
if(this.getTitleBar() != null) {
|
||||||
|
this.removeVisual(this.titleBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.titleBar = titleBar;
|
||||||
|
this.addVisual(titleBar, 0, 0);
|
||||||
|
this.titleBar.addMouseListener(new TitleBarMouseListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TitleBar getTitleBar() {
|
||||||
|
return this.titleBar;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPositionRelativeTo(Component c){
|
public void setPositionRelativeTo(Component c){
|
||||||
frame.setLocationRelativeTo(c);
|
frame.setLocationRelativeTo(c);
|
||||||
}
|
}
|
||||||
@@ -71,4 +99,71 @@ public class Window extends Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setUndecorated(Boolean undecorated){frame.setUndecorated(undecorated);}
|
public void setUndecorated(Boolean undecorated){frame.setUndecorated(undecorated);}
|
||||||
|
|
||||||
|
public void setState(int state) {
|
||||||
|
frame.setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveTo(int x, int y) {
|
||||||
|
this.frame.setLocation(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleNotification(int notify) {
|
||||||
|
switch(notify) {
|
||||||
|
case TitleBar.CLOSE:
|
||||||
|
dispose();
|
||||||
|
break;
|
||||||
|
case TitleBar.MINIMIZE:
|
||||||
|
setState(Frame.ICONIFIED);
|
||||||
|
break;
|
||||||
|
case TitleBar.MAXIMIZE:
|
||||||
|
Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
|
||||||
|
this.setSize(screenBounds.width, screenBounds.height);
|
||||||
|
this.moveTo(screenBounds.x, screenBounds.y);
|
||||||
|
setState(Frame.MAXIMIZED_BOTH);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class WindowMouseListener extends MouseAdapter{
|
||||||
|
private Boolean resizing;
|
||||||
|
private Boolean moving;
|
||||||
|
private Point2d initialLocation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
this.initialLocation = new Point2d(mouseEvent.getX(), mouseEvent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
|
moving = false;
|
||||||
|
resizing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private class TitleBarMouseListener extends MouseAdapter {
|
||||||
|
private Boolean moving = false;
|
||||||
|
private Point2d initialLocation;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
|
if(moving) {
|
||||||
|
moveTo(mouseEvent.getXOnScreen() - initialLocation.x, mouseEvent.getYOnScreen() - initialLocation.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
moving = true;
|
||||||
|
initialLocation = new Point2d(mouseEvent.getX(), mouseEvent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
|
moving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class XAMLParser {
|
public class XAMLParser {
|
||||||
private final static String packageName = "guiTree.";
|
private final static String packageGuiTree = "guiTree.";
|
||||||
|
private final static String packageComponents = "guiTree.Components.";
|
||||||
private static Converter valueConverter = new Converter();
|
private static Converter valueConverter = new Converter();
|
||||||
|
|
||||||
private static void setAttributes(Object object, NamedNodeMap attributeList){
|
private static void setAttributes(Object object, NamedNodeMap attributeList){
|
||||||
@@ -119,7 +120,13 @@ public class XAMLParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Object parseNode(Node parentNode)throws Exception{
|
private static Object parseNode(Node parentNode)throws Exception{
|
||||||
Class<?> parentClass = Class.forName(packageName.concat(parentNode.getNodeName()));
|
Class<?> parentClass;
|
||||||
|
try {
|
||||||
|
parentClass = Class.forName(packageComponents.concat(parentNode.getNodeName()));
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
parentClass = Class.forName(packageGuiTree.concat(parentNode.getNodeName()));
|
||||||
|
}
|
||||||
Object parentObject = parentClass.getDeclaredConstructor().newInstance();
|
Object parentObject = parentClass.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
setAttributes(parentObject, parentNode.getAttributes());
|
setAttributes(parentObject, parentNode.getAttributes());
|
||||||
|
|||||||