mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 21:50:04 +00:00
improved efficiency
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<Window Name="window" Visible="true" Size="640, 480">
|
<Window Name="window" Visible="true" Size="640, 480">
|
||||||
<!-- <Panel Name="MainPanel" BackgroundColor="#FFFFFF" Size="1.0, 1.0" Overlapping="false">-->
|
<Panel Name="MainPanel" BackgroundColor="#999999" Size="1.0, 1.0" Overlapping="true">
|
||||||
<Button Name="button1" BackgroundColor="#990000" Size="0.5, 0.5" Label="button1">
|
<Button Name="button1" BackgroundColor="#990000" Size="0.5, 0.5" Location="0.0, 0.0" Label="button1">
|
||||||
<Button Name="button4" BackgroundColor="#009999" Size="0.3, 0.3" Icon="square_white">
|
<Button Name="button4" BackgroundColor="#009999" Size="0.3, 0.3" Icon="square_white">
|
||||||
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/>
|
<Button Name="button2" BackgroundColor="#000099" Size="50, 50" Label="button2"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Button>
|
</Button>
|
||||||
<Button Name="button6" BackgroundColor="#555555" Location="320, 0" Size="0.5, 0.5"/>
|
<Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>
|
||||||
<Button Name="button3" BackgroundColor="#009900" Size="100, 100" Location="300, 300" Icon="close_black"/>
|
<Button Name="button3" BackgroundColor="#009900" Size="0.5, 0.5" Location="0.5, 0.0" Icon="close_black"/>
|
||||||
<!-- </Panel>-->
|
<!-- <Button Name="button3" BackgroundColor="#123456" Size="0.5, 0.5" Location="0.5, 0.0" Icon="minimize_white"/>-->
|
||||||
|
</Panel>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -12,7 +12,7 @@ public class Main {
|
|||||||
try{
|
try{
|
||||||
Window window = XAMLParser.parse("ui.xml");
|
Window window = XAMLParser.parse("ui.xml");
|
||||||
assert window != null;
|
assert window != null;
|
||||||
window.revalidate();
|
window.repaint();
|
||||||
Button button = (Button)window.findByName("button3");
|
Button button = (Button)window.findByName("button3");
|
||||||
button.addMouseListener(new MouseAdapter() {
|
button.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -24,11 +24,11 @@ public class Main {
|
|||||||
else {
|
else {
|
||||||
panel.setOverlapping(true);
|
panel.setOverlapping(true);
|
||||||
}
|
}
|
||||||
window.revalidate();
|
window.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.revalidate();
|
window.repaint();
|
||||||
System.out.println(Float.parseFloat("3"));
|
System.out.println(Float.parseFloat("3"));
|
||||||
long now;
|
long now;
|
||||||
long prev = 0;
|
long prev = 0;
|
||||||
|
|||||||
@@ -38,30 +38,30 @@ public class Button extends Visual {
|
|||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent) {
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
pressed = true;
|
pressed = true;
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent mouseEvent) {
|
public void mouseReleased(MouseEvent mouseEvent) {
|
||||||
pressed = false;
|
pressed = false;
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent mouseEvent) {
|
public void mouseEntered(MouseEvent mouseEvent) {
|
||||||
hovered = true;
|
hovered = true;
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent mouseEvent) {
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
hovered = false;
|
hovered = false;
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent mouseEvent) {
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent mouseEvent) {
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public class Visual {
|
|||||||
private Float relativeHeight;
|
private Float relativeHeight;
|
||||||
private Integer locationX;
|
private Integer locationX;
|
||||||
private Integer locationY;
|
private Integer locationY;
|
||||||
|
private Float relativeX;
|
||||||
|
private Float relativeY;
|
||||||
private Color backgroundColor;
|
private Color backgroundColor;
|
||||||
private Color foregroundColor;
|
private Color foregroundColor;
|
||||||
private Color fontColor;
|
private Color fontColor;
|
||||||
@@ -78,6 +80,8 @@ public class Visual {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
this.relativeWidth = -1.0f;
|
this.relativeWidth = -1.0f;
|
||||||
this.relativeHeight = -1.0f;
|
this.relativeHeight = -1.0f;
|
||||||
|
this.relativeX = -1.0f;
|
||||||
|
this.relativeY = -1.0f;
|
||||||
|
|
||||||
this.locationX = 0;
|
this.locationX = 0;
|
||||||
this.locationY = 0;
|
this.locationY = 0;
|
||||||
@@ -107,6 +111,9 @@ public class Visual {
|
|||||||
if(v.relativeHeight > 0.0 || v.relativeWidth > 0.0) {
|
if(v.relativeHeight > 0.0 || v.relativeWidth > 0.0) {
|
||||||
v.setSize();
|
v.setSize();
|
||||||
}
|
}
|
||||||
|
if(v.relativeX >= 0.0 || v.relativeY >= 0.0) {
|
||||||
|
v.setLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
this.notifyParent(SIZE_CHANGED);
|
this.notifyParent(SIZE_CHANGED);
|
||||||
@@ -124,11 +131,30 @@ public class Visual {
|
|||||||
setSize();
|
setSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLocation() {
|
||||||
|
if(parent != null) {
|
||||||
|
if(relativeX >= 0.0) {
|
||||||
|
locationX = Math.round(relativeX * parent.width);
|
||||||
|
}
|
||||||
|
if(relativeY >= 0.0) {
|
||||||
|
locationY = Math.round(relativeY * parent.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dirty = true;
|
||||||
|
notifyParent(LOCATION_CHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Float x, Float y) {
|
||||||
|
relativeX = x;
|
||||||
|
relativeY = y;
|
||||||
|
setLocation();
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
setLocation();
|
||||||
notifyParent(LOCATION_CHANGED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationX(Integer x) {
|
public void setLocationX(Integer x) {
|
||||||
@@ -251,22 +277,20 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repaint() {
|
public void repaint() {
|
||||||
this.paint(imageBuffer);
|
if(!this.active){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(this.dirty) {
|
if(this.dirty) {
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(Visual v: children) {
|
for(Visual v: children) {
|
||||||
v.repaint();
|
v.repaint();
|
||||||
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revalidate() {
|
private void revalidate() {
|
||||||
if(!this.active){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearImageBuffer();
|
clearImageBuffer();
|
||||||
this.paint(imageBuffer);
|
this.paint(imageBuffer);
|
||||||
for (Visual v : children) {
|
for (Visual v : children) {
|
||||||
@@ -280,7 +304,7 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
Window window = (Window)this;
|
Window window = (Window)this;
|
||||||
window.setFrameImageBuffer(imageBuffer);
|
window.setFrameImageBuffer(imageBuffer);
|
||||||
window.repaint();
|
window.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(BufferedImage imageBuffer) {
|
public void paint(BufferedImage imageBuffer) {
|
||||||
@@ -449,7 +473,6 @@ public class Visual {
|
|||||||
|
|
||||||
private void activate() {
|
private void activate() {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
for(Visual child: children) {
|
for(Visual child: children) {
|
||||||
child.activate();
|
child.activate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class Window extends Visual {
|
|||||||
private TitleBar titleBar;
|
private TitleBar titleBar;
|
||||||
private Panel mainPanel;
|
private Panel mainPanel;
|
||||||
private Panel contentPanel;
|
private Panel contentPanel;
|
||||||
private ResizeListener windowResizeListener;
|
|
||||||
private Point2d oldSize;
|
private Point2d oldSize;
|
||||||
private Point2d oldLocation;
|
private Point2d oldLocation;
|
||||||
|
|
||||||
@@ -31,25 +30,7 @@ public class Window extends Visual {
|
|||||||
this.setUndecorated(true);
|
this.setUndecorated(true);
|
||||||
this.addWindowStateListener(e -> {
|
this.addWindowStateListener(e -> {
|
||||||
this.setSize(getWidth(), getHeight());
|
this.setSize(getWidth(), getHeight());
|
||||||
revalidate();
|
repaint();
|
||||||
});
|
|
||||||
Direction[] directions = {Direction.SOUTH, Direction.EAST, Direction.WEST};
|
|
||||||
windowResizeListener = new ResizeListener(directions, new Point2d(getWidth(), getHeight()), new Point2d(getLocationX(), getLocationY()));
|
|
||||||
this.addMouseListener(windowResizeListener);
|
|
||||||
this.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent mouseEvent) {
|
|
||||||
setSize(windowResizeListener.size.x, windowResizeListener.size.y);
|
|
||||||
setLocation(windowResizeListener.location.x, windowResizeListener.location.y);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent mouseEvent) {
|
|
||||||
frame.setCursor(windowResizeListener.cursor);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent mouseEvent) {
|
|
||||||
frame.setCursor(windowResizeListener.cursor);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.mainPanel = new Panel();
|
this.mainPanel = new Panel();
|
||||||
|
|
||||||
@@ -77,9 +58,8 @@ public class Window extends Visual {
|
|||||||
else {
|
else {
|
||||||
contentPanel.setSize(width, height);
|
contentPanel.setSize(width, height);
|
||||||
}
|
}
|
||||||
windowResizeListener.setSize(width, height);
|
|
||||||
mainPanel.setSize(width, height);
|
mainPanel.setSize(width, height);
|
||||||
revalidate();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
||||||
@@ -87,7 +67,7 @@ public class Window extends Visual {
|
|||||||
this.frame.repaint();
|
this.frame.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repaint() {
|
public void revalidate() {
|
||||||
this.frame.repaint();
|
this.frame.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +151,6 @@ public class Window extends Visual {
|
|||||||
|
|
||||||
public void setLocation(int x, int y) {
|
public void setLocation(int x, int y) {
|
||||||
this.frame.setLocation(x, y);
|
this.frame.setLocation(x, y);
|
||||||
windowResizeListener.setLocation(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMainPanel(Panel panel) {
|
public void setMainPanel(Panel panel) {
|
||||||
|
|||||||
Reference in New Issue
Block a user