added hardware acceleration support

refactored to work with jdk 8
changed the validator to reentrant lock
This commit is contained in:
Macocian Adrian Radu
2020-06-08 18:21:54 +03:00
parent 84c1fa885b
commit 0225b80460
41 changed files with 1063 additions and 242 deletions

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -3,6 +3,8 @@
Name="Window" Name="Window"
Visible="True" Visible="True"
Title="Sudoku 1.0" Title="Sudoku 1.0"
EnableGPU="True"
HardwareAccelerated="True"
Size="1024, 576"> Size="1024, 576">
<GridPanel <GridPanel
BackgroundColor="#75ff75" BackgroundColor="#75ff75"
@@ -17,11 +19,13 @@
<Panel <Panel
BackgroundColor="#555555" BackgroundColor="#555555"
Name="Panel" Name="Panel"
Overlapping="false"
Row="0" Row="0"
Column="1"> Column="1">
<Image <Picture
Size="0.5f, 0.3f" Size="0.5f, 0.3f"
Location="0.5f, 0.0f" Margins="10"
Name="Image"
Image="heart"/> Image="heart"/>
<RadioButtons <RadioButtons
Size="0.4f, 0.3f"> Size="0.4f, 0.3f">
@@ -61,43 +65,58 @@
ContentHeight="30" ContentHeight="30"
ContentWidth="100" ContentWidth="100"
ClosedSize="200, 30"> ClosedSize="200, 30">
<Button
Name="align_to_left"
Label="Align to Left"/>
<Button
Name="align_to_right"
Label="Align to Right"/>
<Button
Name="align_to_center"
Label="Align to Center"/>
<SideDropDown <SideDropDown
Name="SideDropDown" Name="TopSide"
Label="SideDropDown" Label="Top"
ClosedWidth="100" ClosedWidth="100"
ClosedHeight="30" ClosedHeight="30"
ContentHeight="30" ContentHeight="30"
ContentWidth="100"> ContentWidth="100">
<Button <Button
Name="Button3" Name="topLeft"
Label="Button3"/> Label="Left"/>
<Button <Button
Name="Button4" Name="topCenter"
Label="Button4"/> Label="Center"/>
<Button
Name="topRight"
Label="Right"/>
</SideDropDown> </SideDropDown>
<SideDropDown <SideDropDown
Name="SideDropDown" Name="MiddleSide"
Label="SideDropDown" Label="Middle"
ClosedWidth="100" ClosedWidth="100"
ClosedHeight="30" ClosedHeight="30"
ContentHeight="30" ContentHeight="30"
ContentWidth="100"> ContentWidth="100">
<Button <Button
Name="Button5" Name="middleLeft"
Label="Button5"/> Label="Left"/>
<Button <Button
Name="Button6" Name="middleCenter"
Label="Button6"/> Label="Center"/>
<Button
Name="middleRight"
Label="Right"/>
</SideDropDown>
<SideDropDown
Name="BottomSide"
Label="Bottom"
ClosedWidth="100"
ClosedHeight="30"
ContentHeight="30"
ContentWidth="100">
<Button
Name="bottomLeft"
Label="Left"/>
<Button
Name="bottomCenter"
Label="Center"/>
<Button
Name="bottomRight"
Label="Right"/>
</SideDropDown> </SideDropDown>
</DropDown> </DropDown>

View File

@@ -1,6 +1,5 @@
import guiTree.Components.Button; import guiTree.Components.Button;
import guiTree.Components.DropDown; import guiTree.Components.Picture;
import guiTree.Components.Text;
import guiTree.Window; import guiTree.Window;
import guiTree.events.MouseAdapter; import guiTree.events.MouseAdapter;
import parser.XAMLParser; import parser.XAMLParser;
@@ -16,34 +15,87 @@ public class Main {
e.printStackTrace(); e.printStackTrace();
} }
assert window != null; assert window != null;
Button alignToLeft = (Button) window.findByName("align_to_left"); Button topLeft = (Button) window.findByName("topLeft");
Button alignToRight = (Button) window.findByName("align_to_right"); Button topCenter = (Button) window.findByName("topCenter");
Button alignToCenter = (Button) window.findByName("align_to_center"); Button topRight = (Button) window.findByName("topRight");
Text textField = (Text) window.findByName("Text"); Button middleLeft = (Button) window.findByName("middleLeft");
Button middleCenter = (Button) window.findByName("middleCenter");
Button middleRight = (Button) window.findByName("middleRight");
Button bottomLeft = (Button) window.findByName("bottomLeft");
Button bottomCenter = (Button) window.findByName("bottomCenter");
Button bottomRight = (Button) window.findByName("bottomRight");
Picture picture = (Picture) window.findByName("Image");
alignToLeft.addMouseListener(new MouseAdapter() { topLeft.addMouseListener(new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent mouseEvent) { public void mousePressed(MouseEvent mouseEvent) {
textField.setAlignment("left"); picture.setLocation("top_left");
textField.update(); picture.update();
} }
}); });
alignToCenter.addMouseListener(new MouseAdapter() { topRight.addMouseListener(new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent mouseEvent) { public void mousePressed(MouseEvent mouseEvent) {
textField.setAlignment("center"); picture.setLocation("top_right");
textField.update(); picture.update();
} }
}); });
alignToRight.addMouseListener(new MouseAdapter() { topCenter.addMouseListener(new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent mouseEvent) { public void mousePressed(MouseEvent mouseEvent) {
textField.setAlignment("right"); picture.setLocation("top_center");
textField.update(); picture.update();
} }
}); });
middleLeft.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("middle_left");
picture.update();
}
});
middleRight.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("middle_right");
picture.update();
}
});
middleCenter.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("middle_center");
picture.update();
}
});
bottomLeft.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("bottom_left");
picture.update();
}
});
bottomRight.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("bottom_right");
picture.update();
}
});
bottomCenter.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
picture.setLocation("bottom_center");
picture.update();
}
});
} }
} }

View File

@@ -75,10 +75,10 @@ public class Button extends MenuItem {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) public void paint(Image imageBuffer)
{ {
//Get Graphics //Get Graphics
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getPaintColor()); g.setColor(getPaintColor());
@@ -106,7 +106,7 @@ public class Button extends MenuItem {
int iconX = (this.getWidth() - iconWidth - textWidth) / 2; int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
int iconY = (this.getHeight() - iconHeight - textHeight) / 2; int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
Graphics2D g2 = imageBuffer.createGraphics(); Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
g2.drawImage(icon, iconX, iconY, null); g2.drawImage(icon, iconX, iconY, null);
g2.dispose(); g2.dispose();
} }

View File

@@ -115,8 +115,8 @@ public class CheckBox extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getPaintColor()); g.setColor(getPaintColor());
@@ -130,7 +130,7 @@ public class CheckBox extends Visual {
int iconX = (this.getHeight() - iconWidth) / 2; int iconX = (this.getHeight() - iconWidth) / 2;
int iconY = (this.getHeight() - iconHeight) / 2; int iconY = (this.getHeight() - iconHeight) / 2;
Graphics2D g2 = imageBuffer.createGraphics(); Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
g2.drawImage(icon, iconX, iconY, null); g2.drawImage(icon, iconX, iconY, null);
g2.dispose(); g2.dispose();
} }

View File

@@ -1,4 +1,4 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -36,11 +36,13 @@ public class Border extends Decoration {
update(); update();
} }
public void paint(BufferedImage imageBuffer) { @Override
Graphics2D g = imageBuffer.createGraphics(); public void paint(Image imageBuffer) {
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(color); g.setColor(color);
g.setStroke(new BasicStroke(thickness)); g.setStroke(new BasicStroke(thickness));
g.drawRect(thickness/2, thickness/2, getWidth() - thickness, getHeight() - thickness); g.drawRect(thickness/2, thickness/2, getWidth() - thickness, getHeight() - thickness);
g.dispose();
} }
} }

View File

@@ -1,4 +1,4 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;
@@ -48,8 +48,8 @@ public class CenterTextAligner implements TextAligner{
public Point2<Integer> getPositionOnScreen(int x, int y) { public Point2<Integer> getPositionOnScreen(int x, int y) {
String currentLine = wholeText.get(y); String currentLine = wholeText.get(y);
y = (fontMetrics.getHeight() + spacing) * y; y = (fontMetrics.getHeight() + spacing) * y;
int textStart = (width - fontMetrics.stringWidth(currentLine)) / 2;
int width = textStart; int width = (this.width - fontMetrics.stringWidth(currentLine)) / 2;
width += fontMetrics.stringWidth(currentLine.substring(0, x)); width += fontMetrics.stringWidth(currentLine.substring(0, x));
return new Point2<>(width, y); return new Point2<>(width, y);
} }

View File

@@ -1,4 +1,4 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import guiTree.Visual; import guiTree.Visual;

View File

@@ -1,7 +1,6 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;
import jdk.jfr.Percentage;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;

View File

@@ -0,0 +1,63 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class BottomCenterPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public BottomCenterPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int y = parentSize.y - size.y - margin.b;
int x = (parentSize.x - size.x) / 2;
return new Point2<>(x, y);
}
}

View File

@@ -0,0 +1,62 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class BottomLeftPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public BottomLeftPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int y = parentSize.y - size.y - margin.b;
return new Point2<>(margin.b, y);
}
}

View File

@@ -0,0 +1,63 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class BottomRightPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public BottomRightPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int y = parentSize.y - size.y - margin.b;
int x = parentSize.x - size.x - margin.d;
return new Point2<>(x, y);
}
}

View File

@@ -0,0 +1,74 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class GeneralPlacer implements Placer {
private Point2<Integer> location;
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point2<Float> relativeLocation;
private Point4<Integer> margin;
public GeneralPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
relativeLocation = new Point2<>(x, y);
}
@Override
public void setLocation(int x, int y) {
location = new Point2<>(x, y);
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
int x = location.x;
int y = location.y;
if(parentSize != null) {
if(relativeLocation != null) {
if(relativeLocation.x != -1) {
x = Math.round(relativeLocation.x * parentSize.x);
}
if(relativeLocation.y != -1) {
y = Math.round(relativeLocation.y * parentSize.y);
}
}
}
return new Point2<>(x, y);
}
}

View File

@@ -0,0 +1,63 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class MiddleCenterPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public MiddleCenterPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int x = (parentSize.x - size.x) / 2;
int y = (parentSize.y - size.y) / 2;
return new Point2<>(x, y);
}
}

View File

@@ -0,0 +1,63 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class MiddleLeftPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public MiddleLeftPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int y = (parentSize.y - size.y) / 2;
return new Point2<>(margin.c, y);
}
}

View File

@@ -0,0 +1,64 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class MiddleRightPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public MiddleRightPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int x = parentSize.x - size.x - margin.d;
int y = (parentSize.y - size.y) / 2;
return new Point2<>(x, y);
}
}

View File

@@ -0,0 +1,15 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public interface Placer {
void setRelativeLocation(float x, float y);
void setLocation(int x, int y);
void setElementSize(int width, int height);
void setParentSize(int width, int height);
void setMargins(int up, int down, int left, int right);
void setMargins(int margin);
Point4<Integer> getMargins();
Point2<Integer> getPosition();
}

View File

@@ -0,0 +1,63 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class TopCenterPlacer implements Placer{
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public TopCenterPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int x = (parentSize.x - size.x) / 2;
return new Point2<>(x, margin.a);
}
}

View File

@@ -0,0 +1,55 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class TopLeftPlacer implements Placer {
private Point4<Integer> margin;
public TopLeftPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float relativeX, float relativeY) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
}
@Override
public void setParentSize(int width, int height) {
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
return new Point2<>(margin.c, margin.a);
}
}

View File

@@ -0,0 +1,62 @@
package guiTree.Components.Decorations.Placers;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
public class TopRightPlacer implements Placer {
private Point2<Integer> size;
private Point2<Integer> parentSize;
private Point4<Integer> margin;
public TopRightPlacer() {
margin = new Point4<>(0, 0, 0, 0);
}
@Override
public void setRelativeLocation(float x, float y) {
}
@Override
public void setLocation(int x, int y) {
}
@Override
public void setElementSize(int width, int height) {
size = new Point2<>(width, height);
}
@Override
public void setParentSize(int width, int height) {
parentSize = new Point2<>(width, height);
}
@Override
public void setMargins(int up, int down, int left, int right) {
margin.a = up;
margin.b = down;
margin.c = left;
margin.d = right;
}
@Override
public void setMargins(int margin) {
this.margin.a = margin;
this.margin.b = margin;
this.margin.c = margin;
this.margin.d = margin;
}
@Override
public Point4<Integer> getMargins() {
return margin;
}
@Override
public Point2<Integer> getPosition() {
if(parentSize == null) {
return new Point2<>(margin.c, margin.a);
}
int x = parentSize.x - size.x - margin.d;
return new Point2<>(x, margin.a);
}
}

View File

@@ -1,4 +1,4 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;

View File

@@ -1,4 +1,4 @@
package guiTree.Components.Decoarations; package guiTree.Components.Decorations;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;

View File

@@ -266,10 +266,11 @@ public class DropDown extends MenuItem implements Menu{
return icon; return icon;
} }
public void paint(BufferedImage imageBuffer) @Override
public void paint(Image imageBuffer)
{ {
//Get Graphics //Get Graphics
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getPaintColor()); g.setColor(getPaintColor());
@@ -293,7 +294,7 @@ public class DropDown extends MenuItem implements Menu{
int iconX = closedSize.x - iconWidth - 3; int iconX = closedSize.x - iconWidth - 3;
int iconY = (closedSize.y - iconHeight - textHeight) / 2; int iconY = (closedSize.y - iconHeight - textHeight) / 2;
Graphics2D g2 = imageBuffer.createGraphics(); Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
g2.drawImage(icon, iconX, iconY, null); g2.drawImage(icon, iconX, iconY, null);
g2.dispose(); g2.dispose();
} }

View File

@@ -456,15 +456,14 @@ public class InputTextBox extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getPaintColor()); g.setColor(getPaintColor());
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
if(fontMetrics == null) { if(fontMetrics == null) {
fontMetrics = g.getFontMetrics(); fontMetrics = g.getFontMetrics();
return;
} }
g.setColor(Color.BLUE); g.setColor(Color.BLUE);
@@ -487,5 +486,6 @@ public class InputTextBox extends Visual {
g.drawString(line.toString(), 0, y); g.drawString(line.toString(), 0, y);
y += fontMetrics.getHeight(); y += fontMetrics.getHeight();
} }
g.dispose();
} }
} }

View File

@@ -1,20 +1,20 @@
package guiTree.Components; package guiTree.Components;
import guiTree.Helper.Point2;
import guiTree.Visual; import guiTree.Visual;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List;
public class Panel extends Visual { public class Panel extends Visual {
List<Visual> visuals; HashMap<Visual, Point2<Integer>> visuals;
private Boolean overlapping; private Boolean overlapping;
public Panel() { public Panel() {
super(); super();
overlapping = true; overlapping = true;
visuals = new ArrayList<>(); visuals = new HashMap<>();
} }
public void setOverlapping(Boolean overlapping) { public void setOverlapping(Boolean overlapping) {
@@ -26,74 +26,51 @@ public class Panel extends Visual {
return this.overlapping; return this.overlapping;
} }
private void calculateSize(Visual v) { private void reposition() {
if(!overlapping) {
return;
}
visuals.keySet().forEach(f -> f.setLocation(visuals.get(f).x, visuals.get(f).y));
visuals.keySet().forEach(this::calculatePosition);
} }
private void calculatePosition(Visual v) { private void calculatePosition(Visual v) {
if(!overlapping) { if(overlapping) {
boolean ok = false; return;
while(!ok) { }
ok = true; boolean ok = false;
for (int i = 0; i < visuals.size(); i++) { while(!ok) {
Visual v2 = visuals.get(i); ok = true;
if (isOverlapping(v, v2) && v != v2) { for(Visual v2: visuals.keySet()) {
System.out.println(v + " Overlapping with: " + v2); if(v == v2) {
if(v.getLocationX() + v.getWidth() + v2.getWidth() > this.getWidth()) { continue;
if(v.getLocationY() + v.getHeight() + v2.getHeight() > this.getHeight()) {
break;
}
else {
v.setLocationY(v2.getLocationY() + v2.getHeight());
}
}
else {
v.setLocationX(v2.getLocationX() + v2.getWidth());
}
i = 0;
}
} }
if(v.getLocationX() + v.getWidth() > this.getWidth()) { if(v2.isInside(v.getLocationX(), v.getLocationY()) ||
v2.isInside(v.getLocationX() + v.getWidth(), v.getLocationY()) ||
v2.isInside(v.getLocationX(), v.getLocationY() + v.getHeight()) ||
v2.isInside(v.getLocationX() + v.getWidth(), v.getLocationY() + v.getHeight())) {
System.out.println(v + " Overlapping with: " + v2);
ok = false; ok = false;
v.setLocationY(v.getLocationY() + 10); if(v2.getHeight() + v2.getLocationY() + v.getHeight() > getHeight()) {
} v.setLocation(v2.getLocationX() + v2.getWidth() + 1, visuals.get(v).y);
if(v.getLocationY() > this.getHeight()) { }
v.setLocation(0, 0); v.setLocation(visuals.get(v).x, v2.getLocationY() + v2.getHeight() + 1);
break;
} }
} }
} }
} }
private void reposition() { @Override
for(int i = visuals.size() - 1; i >= 0; i--) { public void removeVisual(Visual v) {
calculatePosition(visuals.get(i)); super.removeVisual(v);
} visuals.remove(v);
} }
@Override @Override
public void addVisual(Visual v) { public void addVisual(Visual v) {
super.addVisual(v); super.addVisual(v);
visuals.put(v, new Point2<>(v.getLocationX(), v.getLocationY()));
calculatePosition(v); calculatePosition(v);
visuals.add(v);
}
private Boolean isOverlapping(Visual v1, Visual v2) {
int l1x = v1.getLocationX();
int r1x = v1.getLocationX() + v1.getWidth();
int l1y = v1.getLocationY();
int r1y = v1.getLocationY() + v1.getHeight();
int l2x = v2.getLocationX();
int r2x = v2.getLocationX() + v2.getWidth();
int l2y = v2.getLocationY();
int r2y = v2.getLocationY() + v2.getHeight();
if(l1x >= r2x || l2x >= r1x) {
return false;
}
return l1y < r2y && l2y < r1y;
} }
@Override @Override
@@ -101,16 +78,15 @@ public class Panel extends Visual {
if(notify == TitleBar.CLOSE || notify == TitleBar.MAXIMIZE || if(notify == TitleBar.CLOSE || notify == TitleBar.MAXIMIZE ||
notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) { notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) {
notifyParent(v, notify); notifyParent(v, notify);
// return;
} }
// if(notify == SIZE_CHANGED || notify == LOCATION_CHANGED) { // if(notify == SIZE_CHANGED) {
// reposition(); // reposition();
// } // }
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getBackgroundColor()); g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());

View File

@@ -8,17 +8,17 @@ import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
public class Image extends Visual { public class Picture extends Visual {
private BufferedImage bufferedImage; private BufferedImage bufferedImage;
public Image() { public Picture() {
} }
public Image(String url) { public Picture(String url) {
setImage(url); setImage(url);
} }
public Image(BufferedImage image) { public Picture(BufferedImage image) {
setImage(image); setImage(image);
} }
@@ -28,15 +28,16 @@ public class Image extends Visual {
public void setImage(String url) { public void setImage(String url) {
try{ try{
bufferedImage = ImageIO.read(new File("resources\\icons\\" + url + ".png")); bufferedImage = ImageIO.read(new File("resources\\images\\" + url + ".png"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.drawImage(bufferedImage, 0, 0, getWidth(), getHeight(), null); g.drawImage(bufferedImage, 0, 0, getWidth(), getHeight(), null);
g.dispose();
} }
} }

View File

@@ -9,8 +9,8 @@ public class RadioButton extends CheckBox {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getPaintColor()); g.setColor(getPaintColor());

View File

@@ -134,8 +134,8 @@ public class ScrollPanel extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getPaintColor()); g.setColor(getPaintColor());
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
@@ -205,17 +205,14 @@ public class ScrollPanel extends Visual {
private static class VisualLocation { private static class VisualLocation {
Visual v; Visual v;
Point2<Integer> originalLocation; Point2<Integer> originalLocation;
Point2<Float> originalRelativeLocation;
public VisualLocation(Visual v) { public VisualLocation(Visual v) {
this.v = v; this.v = v;
originalLocation = v.getLocation(); originalLocation = v.getLocation();
originalRelativeLocation = v.getRelativeLocation();
} }
public void updateLocation() { public void updateLocation() {
originalLocation = v.getLocation(); originalLocation = v.getLocation();
originalRelativeLocation = v.getRelativeLocation();
} }
} }
} }

View File

@@ -216,8 +216,8 @@ public class Slider extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getBackgroundColor()); g.setColor(getBackgroundColor());

View File

@@ -1,9 +1,9 @@
package guiTree.Components; package guiTree.Components;
import guiTree.Components.Decoarations.CenterTextAligner; import guiTree.Components.Decorations.CenterTextAligner;
import guiTree.Components.Decoarations.LeftTextAligner; import guiTree.Components.Decorations.LeftTextAligner;
import guiTree.Components.Decoarations.RightTextAligner; import guiTree.Components.Decorations.RightTextAligner;
import guiTree.Components.Decoarations.TextAligner; import guiTree.Components.Decorations.TextAligner;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;
import guiTree.Helper.Point4; import guiTree.Helper.Point4;
import guiTree.Visual; import guiTree.Visual;
@@ -276,8 +276,8 @@ public class Text extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
if(fontMetrics == null) { if(fontMetrics == null) {
fontMetrics = g.getFontMetrics(); fontMetrics = g.getFontMetrics();
textAligner.setFontMetrics(fontMetrics); textAligner.setFontMetrics(fontMetrics);
@@ -295,5 +295,6 @@ public class Text extends Visual {
Point2<Integer> position = textAligner.alignLine(lines.indexOf(line)); Point2<Integer> position = textAligner.alignLine(lines.indexOf(line));
g.drawString(line.toString(), position.x, position.y); g.drawString(line.toString(), position.x, position.y);
} }
g.dispose();
} }
} }

View File

@@ -134,12 +134,12 @@ public class TitleBar extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getBackgroundColor()); g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
Graphics2D iconGraphics = imageBuffer.createGraphics(); Graphics2D iconGraphics = (Graphics2D)imageBuffer.getGraphics();
iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null); iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null);
iconGraphics.dispose(); iconGraphics.dispose();
@@ -153,6 +153,7 @@ public class TitleBar extends Visual {
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
} }
g.drawString(title, stringOffset, getHeight()/2 + textHeight/4); g.drawString(title, stringOffset, getHeight()/2 + textHeight/4);
g.dispose();
} }
private void setButtonLocation() { private void setButtonLocation() {

View File

@@ -73,10 +73,10 @@ public class ToggleButton extends Visual {
} }
@Override @Override
public void paint(BufferedImage imageBuffer) public void paint(Image imageBuffer)
{ {
//Get Graphics //Get Graphics
Graphics2D g = imageBuffer.createGraphics(); Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getPaintColor()); g.setColor(getPaintColor());
//Draw Button //Draw Button
@@ -103,7 +103,7 @@ public class ToggleButton extends Visual {
int iconX = (this.getWidth() - iconWidth - textWidth) / 2; int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
int iconY = (this.getHeight() - iconHeight - textHeight) / 2; int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
Graphics2D g2 = imageBuffer.createGraphics(); Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
g2.drawImage(icon, iconX, iconY, null); g2.drawImage(icon, iconX, iconY, null);
g2.dispose(); g2.dispose();
} }

View File

@@ -9,7 +9,7 @@ import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
public class CustomFrame extends JFrame { public class CustomFrame extends JFrame {
private BufferedImage imageBuffer; private Image imageBuffer;
private Window parentWindow; private Window parentWindow;
private final int resizeDelta = 5; private final int resizeDelta = 5;
@@ -31,7 +31,7 @@ public class CustomFrame extends JFrame {
this.addMouseListener(listener); this.addMouseListener(listener);
} }
public void setImageBuffer(BufferedImage imageBuffer) { public void setImageBuffer(Image imageBuffer) {
this.imageBuffer = imageBuffer; this.imageBuffer = imageBuffer;
} }

View File

@@ -2,7 +2,7 @@ package guiTree.Helper;
public class Debugger { public class Debugger {
public enum Tag { public enum Tag {
LISTENER(false), LISTENER(true),
PAINTING(false), PAINTING(false),
FPS(false), FPS(false),
ANIMATIONS(false), ANIMATIONS(false),

View File

@@ -1,9 +1,11 @@
package guiTree; package guiTree;
import guiTree.Animations.AnimationInterface; import guiTree.Animations.AnimationInterface;
import guiTree.Components.Decoarations.Decoration; import guiTree.Components.Decorations.*;
import guiTree.Components.Decorations.Placers.*;
import guiTree.Helper.Debugger; import guiTree.Helper.Debugger;
import guiTree.Helper.Point2; import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
import guiTree.Helper.Timer; import guiTree.Helper.Timer;
import guiTree.events.KeyListener; import guiTree.events.KeyListener;
import guiTree.events.MouseListener; import guiTree.events.MouseListener;
@@ -14,10 +16,12 @@ import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.io.File;
import java.util.HashMap; import java.io.IOException;
import java.util.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class Visual { public class Visual {
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@@ -26,7 +30,8 @@ public class Visual {
public static final int SIZE_CHANGED = 1; public static final int SIZE_CHANGED = 1;
public static final int LOCATION_CHANGED = 2; public static final int LOCATION_CHANGED = 2;
private static List<AnimationInterface> animations = new ArrayList<>(); public static final boolean GPU_DISABLED = false;
public static final boolean GPU_ENABLED = true;
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Tree Elements Tree Elements
@@ -34,11 +39,13 @@ public class Visual {
private List<Visual> children; private List<Visual> children;
private Visual parent; private Visual parent;
private BufferedImage imageBuffer; private Image imageBuffer;
private String name; private String name;
private List<MouseListener> mouseListeners; private List<MouseListener> mouseListeners;
private List<MouseWheelListener> mouseWheelListeners; private List<MouseWheelListener> mouseWheelListeners;
private List<KeyListener> keyListeners; private List<KeyListener> keyListeners;
private static List<AnimationInterface> animations = new ArrayList<>();
private static boolean useGPU = GPU_DISABLED;
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Attributes Attributes
@@ -51,10 +58,9 @@ public class Visual {
private Float relativeHeight; private Float relativeHeight;
private Integer locationX; private Integer locationX;
private Integer locationY; private Integer locationY;
private Placer locationPlacer;
private Integer absoluteX; private Integer absoluteX;
private Integer absoluteY; private Integer absoluteY;
private Float relativeX;
private Float relativeY;
private Font font; private Font font;
private Color backgroundColor; private Color backgroundColor;
private Color foregroundColor; private Color foregroundColor;
@@ -66,7 +72,8 @@ public class Visual {
private static Visual entered; private static Visual entered;
private static Visual focused; private static Visual focused;
private Boolean pressed; private Boolean pressed;
private Boolean validating; private Lock validating;
private Boolean hardwareAccelerated;
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
Constructors Constructors
@@ -77,35 +84,38 @@ public class Visual {
} }
public Visual(int width, int height) { public Visual(int width, int height) {
this.children = new ArrayList<>(); children = new ArrayList<>();
this.mouseWheelListeners = new ArrayList<>(); mouseWheelListeners = new ArrayList<>();
this.mouseListeners = new ArrayList<>(); mouseListeners = new ArrayList<>();
this.keyListeners = new ArrayList<>(); keyListeners = new ArrayList<>();
this.parent = null; parent = null;
this.name = ""; name = "";
this.backgroundColor = Color.WHITE; backgroundColor = Color.WHITE;
this.foregroundColor = Color.BLUE; foregroundColor = Color.BLUE;
this.fontColor = Color.BLACK; fontColor = Color.BLACK;
this.accentColor = Color.BLUE; accentColor = Color.BLUE;
this.dirty = true; dirty = true;
this.active = this instanceof Window; active = this instanceof Window;
this.pressed = false; pressed = false;
this.attributeMap = new HashMap<>(); attributeMap = new HashMap<>();
this.width = width; this.width = width;
this.height = height; this.height = height;
this.relativeWidth = -1.0f; relativeWidth = -1.0f;
this.relativeHeight = -1.0f; relativeHeight = -1.0f;
this.relativeX = -1.0f; locationPlacer = new GeneralPlacer();
this.relativeY = -1.0f; locationPlacer.setElementSize(width, height);
locationPlacer.setLocation(0, 0);
locationPlacer.setRelativeLocation(-1.0f, -1.0f);
this.locationX = 0; locationX = 0;
this.locationY = 0; locationY = 0;
this.absoluteX = 0; absoluteX = 0;
this.absoluteY = 0; absoluteY = 0;
this.validating = false; validating = new ReentrantLock();
hardwareAccelerated = useGPU;
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@@ -127,12 +137,14 @@ public class Visual {
} }
initializeImageBuffer(); initializeImageBuffer();
locationPlacer.setElementSize(width, height);
for(Visual v: children) { for(Visual v: children) {
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) { if(v.locationPlacer != null) {
v.locationPlacer.setParentSize(getWidth(), getHeight());
v.setLocation(); v.setLocation();
} }
} }
@@ -168,15 +180,18 @@ public class Visual {
setSize(); setSize();
} }
public void setMargins(Integer up, Integer down, Integer left, Integer right) {
locationPlacer.setMargins(up, down, left, right);
}
public void setMargins(Integer margin) {
locationPlacer.setMargins(margin);
}
public void setLocation() { public void setLocation() {
if(parent != null) { Point2<Integer> location = locationPlacer.getPosition();
if(relativeX >= 0.0) { locationX = location.x;
locationX = Math.round(relativeX * parent.width); locationY = location.y;
}
if(relativeY >= 0.0) {
locationY = Math.round(relativeY * parent.height);
}
}
calculateAbsoluteLocation(); calculateAbsoluteLocation();
update(); update();
@@ -184,14 +199,12 @@ public class Visual {
} }
public void setLocation(Float x, Float y) { public void setLocation(Float x, Float y) {
relativeX = x; locationPlacer.setRelativeLocation(x, y);
relativeY = y;
setLocation(); setLocation();
} }
public void setLocation(Integer x, Integer y) { public void setLocation(Integer x, Integer y) {
this.locationX = x; locationPlacer.setLocation(x, y);
this.locationY = y;
setLocation(); setLocation();
} }
@@ -203,10 +216,80 @@ public class Visual {
setLocation(getLocationX(), y); setLocation(getLocationX(), y);
} }
public void setLocation(String location) {
location = location.toLowerCase();
Point4<Integer> margins = locationPlacer.getMargins();
switch (location) {
case "top_left": {
locationPlacer = new TopLeftPlacer();
break;
}
case "top_right": {
locationPlacer = new TopRightPlacer();
break;
}
case "top_center": {
locationPlacer = new TopCenterPlacer();
break;
}
case "middle_left": {
locationPlacer = new MiddleLeftPlacer();
break;
}
case "middle_center": {
locationPlacer = new MiddleCenterPlacer();
break;
}
case "middle_right": {
locationPlacer = new MiddleRightPlacer();
break;
}
case "bottom_left": {
locationPlacer = new BottomLeftPlacer();
break;
}
case "bottom_center": {
locationPlacer = new BottomCenterPlacer();
break;
}
case "bottom_right": {
locationPlacer = new BottomRightPlacer();
break;
}
default: {
System.err.println("Not a valid location");
return;
}
}
locationPlacer.setElementSize(width, height);
locationPlacer.setMargins(margins.a, margins.b, margins.c, margins.d);
if(parent != null) {
locationPlacer.setParentSize(parent.width, parent.height);
}
setLocation();
}
public void setFont(Font font) { public void setFont(Font font) {
this.font = font; this.font = font;
} }
public void setFont(String font, Integer style) {
setFont(font, 10f, style);
}
public void setFont(String font, Float size) {
setFont(font, size, Font.PLAIN);
}
public void setFont(String font, Float size, Integer style) {
try {
this.font = Font.createFont(Font.TRUETYPE_FONT, new File("resources\\fonts\\" + font + ".ttf"));
this.font = this.font.deriveFont(style, size);
} catch (FontFormatException | IOException e) {
e.printStackTrace();
}
}
public void setBackgroundColor(Color backgroundColor) { public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor; this.backgroundColor = backgroundColor;
this.paintColor = backgroundColor; this.paintColor = backgroundColor;
@@ -233,6 +316,19 @@ public class Visual {
update(); update();
} }
public void setHardwareAccelerated(Boolean hardwareAccelerated) {
this.hardwareAccelerated = hardwareAccelerated;
children.forEach(f -> f.setHardwareAccelerated(hardwareAccelerated));
initializeImageBuffer();
update();
}
public static void setEnableGPU(Boolean gpu) {
useGPU = gpu;
System.setProperty("sun.java2d.opengl", "true");
System.setProperty("sun.java2d.accthreshold", "0");
}
public void setAttribute(String attribute, String value) { public void setAttribute(String attribute, String value) {
attributeMap.put(attribute, value); attributeMap.put(attribute, value);
} }
@@ -265,6 +361,10 @@ public class Visual {
return locationY; return locationY;
} }
public Point4<Integer> getMargins() {
return locationPlacer.getMargins();
}
public Point2<Integer> getLocation() { public Point2<Integer> getLocation() {
return new Point2<>(locationX, locationY); return new Point2<>(locationX, locationY);
} }
@@ -281,10 +381,6 @@ public class Visual {
return new Point2<>(absoluteX, absoluteY); return new Point2<>(absoluteX, absoluteY);
} }
public Point2<Float> getRelativeLocation() {
return new Point2<>(relativeX, relativeY);
}
public boolean isFocused() { public boolean isFocused() {
return this == focused; return this == focused;
} }
@@ -313,6 +409,14 @@ public class Visual {
return paintColor; return paintColor;
} }
public boolean isHardwareAccelerated() {
return hardwareAccelerated;
}
public boolean isGpuEnabled() {
return useGPU;
}
public String getAttribute(String attribute) { public String getAttribute(String attribute) {
return attributeMap.get(attribute); return attributeMap.get(attribute);
} }
@@ -419,21 +523,25 @@ public class Visual {
Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING); Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING);
Timer timer = new Timer(); Timer timer = new Timer();
validating = true; validating.lock();
timer.startTiming(); try {
timer.startTiming();
clearImageBuffer(); clearImageBuffer();
paint(imageBuffer); paint(imageBuffer);
for (Visual v : children) { for (Visual v : children) {
if (v.dirty && v.active) { if (v.dirty && v.active) {
v.revalidate(); v.revalidate();
}
Graphics2D g = (Graphics2D) imageBuffer.getGraphics();
g.drawImage(v.imageBuffer, v.locationX, v.locationY, null);
g.dispose();
} }
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
dirty = false;
} finally {
validating.unlock();
} }
dirty = false;
validating = false;
if(!(this instanceof Window)){ if(!(this instanceof Window)){
long time = timer.stopTiming(); long time = timer.stopTiming();
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING); Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
@@ -453,7 +561,7 @@ public class Visual {
} }
} }
public void paint(BufferedImage imageBuffer) { public void paint(Image imageBuffer) {
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@@ -521,6 +629,7 @@ public class Visual {
} }
focused = entered; focused = entered;
Debugger.log("Pressed " + entered.name, Debugger.Tag.LISTENER); Debugger.log("Pressed " + entered.name, Debugger.Tag.LISTENER);
System.out.println(entered.name + " hardware accelerated: " + imageBuffer.getCapabilities(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()).isAccelerated());
} }
void mouseEntered(MouseEvent mouseEvent) { void mouseEntered(MouseEvent mouseEvent) {
@@ -578,7 +687,8 @@ public class Visual {
entered = this; entered = this;
} }
} }
for(Visual v: children) { for(int i = children.size() - 1; i >=0; i--) {
Visual v = children.get(i);
if(v.isInside(mouseX, mouseY)) { if(v.isInside(mouseX, mouseY)) {
v.mouseMoved(mouseEvent); v.mouseMoved(mouseEvent);
return; return;
@@ -649,7 +759,13 @@ public class Visual {
if(this.width <= 0 || this.height <= 0) { if(this.width <= 0 || this.height <= 0) {
return; return;
} }
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); if(useGPU == GPU_ENABLED && hardwareAccelerated) {
imageBuffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleVolatileImage(width, height, Transparency.TRANSLUCENT);
imageBuffer.setAccelerationPriority(0);
clearImageBuffer();
return;
}
imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
clearImageBuffer(); clearImageBuffer();
} }
@@ -657,7 +773,7 @@ public class Visual {
if(imageBuffer == null) { if(imageBuffer == null) {
return; return;
} }
Graphics2D g = this.imageBuffer.createGraphics(); Graphics2D g = (Graphics2D) imageBuffer.getGraphics();
g.setComposite(AlphaComposite.Clear); g.setComposite(AlphaComposite.Clear);
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
@@ -705,16 +821,19 @@ public class Visual {
} }
public void update() { public void update() {
dirty = true; validating.lock();
try {
dirty = true;
} finally {
validating.unlock();
}
if(parent != null) { if(parent != null) {
while(parent.validating){ parent.validating.lock();
try { try {
Thread.sleep(1); parent.update();
} catch (InterruptedException e) { } finally {
e.printStackTrace(); parent.validating.unlock();
}
} }
parent.update();
} }
} }
} }

View File

@@ -76,7 +76,7 @@ public class Window extends Visual implements Runnable{
Debugger.log("Calling repaint from window set size: ", Debugger.Tag.PAINTING); Debugger.log("Calling repaint from window set size: ", Debugger.Tag.PAINTING);
} }
public void setFrameImageBuffer(BufferedImage imageBuffer){ public void setFrameImageBuffer(Image imageBuffer){
this.frame.setImageBuffer(imageBuffer); this.frame.setImageBuffer(imageBuffer);
this.frame.repaint(); this.frame.repaint();
} }
@@ -244,8 +244,8 @@ public class Window extends Visual implements Runnable{
public void addVisual(Visual v) { public void addVisual(Visual v) {
contentPanel.addVisual(v); contentPanel.addVisual(v);
} }
public void setCursor(Cursor cursor) { public void setCursor(Cursor cursor) {
System.out.println("Changed cursor ASD");
frame.setCursor(cursor); frame.setCursor(cursor);
} }

View File

@@ -1,7 +1,6 @@
package parser; package parser;
import com.sun.jdi.InvalidTypeException; import guiTree.Components.Decorations.Decoration;
import guiTree.Components.Decoarations.Decoration;
import parser.converters.Converter; import parser.converters.Converter;
import guiTree.Helper.Debugger; import guiTree.Helper.Debugger;
import guiTree.Visual; import guiTree.Visual;
@@ -18,6 +17,7 @@ import java.util.List;
public class XAMLParser { public class XAMLParser {
private final static String packageGuiTree = "guiTree."; private final static String packageGuiTree = "guiTree.";
private final static String packageComponents = "guiTree.Components."; private final static String packageComponents = "guiTree.Components.";
private final static String packageDecorations = "guiTree.Components.Decorations.";
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){
@@ -102,7 +102,7 @@ public class XAMLParser {
for (int i = 0; i < types.length; i++) { for (int i = 0; i < types.length; i++) {
try { try {
primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i))); primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i)));
} catch (InvalidTypeException | NumberFormatException e) { } catch (InvalidClassException | NumberFormatException e) {
primitiveAttributes.clear(); primitiveAttributes.clear();
break; break;
} }
@@ -122,7 +122,12 @@ public class XAMLParser {
parentClass = Class.forName(packageComponents.concat(parentNode.getNodeName())); parentClass = Class.forName(packageComponents.concat(parentNode.getNodeName()));
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException e) {
parentClass = Class.forName(packageGuiTree.concat(parentNode.getNodeName())); try {
parentClass = Class.forName(packageGuiTree.concat(parentNode.getNodeName()));
}
catch (ClassNotFoundException f) {
parentClass = Class.forName(packageDecorations.concat(parentNode.getNodeName()));
}
} }
Debugger.log("Parsing " + parentClass, Debugger.Tag.PARSING); Debugger.log("Parsing " + parentClass, Debugger.Tag.PARSING);
Object parentObject = parentClass.getDeclaredConstructor().newInstance(); Object parentObject = parentClass.getDeclaredConstructor().newInstance();

View File

@@ -1,9 +1,9 @@
package parser.converters; package parser.converters;
import com.sun.jdi.InvalidTypeException;
import guiTree.Components.Slider; import guiTree.Components.Slider;
import java.awt.*; import java.awt.*;
import java.io.InvalidClassException;
import java.util.HashMap; import java.util.HashMap;
public class Converter { public class Converter {
@@ -24,10 +24,10 @@ public class Converter {
this.converterTable.put(Slider.Direction.class, new DirectionConverter()); this.converterTable.put(Slider.Direction.class, new DirectionConverter());
} }
public Object objectCreatorFactory (Class<?> type, String content) throws InvalidTypeException { public Object objectCreatorFactory (Class<?> type, String content) throws InvalidClassException {
if(this.converterTable.containsKey(type)) { if(this.converterTable.containsKey(type)) {
return this.converterTable.get(type).convert(content); return this.converterTable.get(type).convert(content);
} }
throw new InvalidTypeException(); throw new InvalidClassException(type.getName());
} }
} }

View File

@@ -1,7 +1,7 @@
package parser.converters; package parser.converters;
import com.sun.jdi.InvalidTypeException; import java.io.InvalidClassException;
public interface ConverterInterface<T> { public interface ConverterInterface<T> {
T convert(String content) throws InvalidTypeException; T convert(String content) throws InvalidClassException;
} }

View File

@@ -1,11 +1,12 @@
package parser.converters; package parser.converters;
import com.sun.jdi.InvalidTypeException;
import guiTree.Components.Slider; import guiTree.Components.Slider;
import java.io.InvalidClassException;
public class DirectionConverter implements ConverterInterface<Slider.Direction> { public class DirectionConverter implements ConverterInterface<Slider.Direction> {
@Override @Override
public Slider.Direction convert(String content) throws InvalidTypeException { public Slider.Direction convert(String content) throws InvalidClassException {
content = content.toLowerCase(); content = content.toLowerCase();
if(content.equals("horizontal")) { if(content.equals("horizontal")) {
return Slider.Direction.Horizontal; return Slider.Direction.Horizontal;
@@ -13,6 +14,6 @@ public class DirectionConverter implements ConverterInterface<Slider.Direction>
if(content.equals("vertical")) { if(content.equals("vertical")) {
return Slider.Direction.Vertical; return Slider.Direction.Vertical;
} }
throw new InvalidTypeException(); throw new InvalidClassException(Slider.Direction.class.getName());
} }
} }

View File

@@ -1,15 +1,15 @@
package parser.converters; package parser.converters;
import com.sun.jdi.InvalidTypeException; import java.io.InvalidClassException;
public class FloatConverter implements ConverterInterface<Float> { public class FloatConverter implements ConverterInterface<Float> {
@Override @Override
public Float convert(String content) throws InvalidTypeException { public Float convert(String content) throws InvalidClassException {
content = content.replaceAll(" ", ""); content = content.replaceAll(" ", "");
if(content.toLowerCase().charAt(content.length() - 1) != 'f') { if(content.toLowerCase().charAt(content.length() - 1) != 'f') {
throw new InvalidTypeException(); throw new InvalidClassException(Float.class.getName());
} }
content = content.substring(0, content.length() - 1); content = content.substring(0, content.length() - 1);