mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
added hardware acceleration support
refactored to work with jdk 8 changed the validator to reentrant lock
This commit is contained in:
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
@@ -3,6 +3,8 @@
|
||||
Name="Window"
|
||||
Visible="True"
|
||||
Title="Sudoku 1.0"
|
||||
EnableGPU="True"
|
||||
HardwareAccelerated="True"
|
||||
Size="1024, 576">
|
||||
<GridPanel
|
||||
BackgroundColor="#75ff75"
|
||||
@@ -17,11 +19,13 @@
|
||||
<Panel
|
||||
BackgroundColor="#555555"
|
||||
Name="Panel"
|
||||
Overlapping="false"
|
||||
Row="0"
|
||||
Column="1">
|
||||
<Image
|
||||
<Picture
|
||||
Size="0.5f, 0.3f"
|
||||
Location="0.5f, 0.0f"
|
||||
Margins="10"
|
||||
Name="Image"
|
||||
Image="heart"/>
|
||||
<RadioButtons
|
||||
Size="0.4f, 0.3f">
|
||||
@@ -61,43 +65,58 @@
|
||||
ContentHeight="30"
|
||||
ContentWidth="100"
|
||||
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
|
||||
Name="SideDropDown"
|
||||
Label="SideDropDown"
|
||||
Name="TopSide"
|
||||
Label="Top"
|
||||
ClosedWidth="100"
|
||||
ClosedHeight="30"
|
||||
ContentHeight="30"
|
||||
ContentWidth="100">
|
||||
<Button
|
||||
Name="Button3"
|
||||
Label="Button3"/>
|
||||
Name="topLeft"
|
||||
Label="Left"/>
|
||||
<Button
|
||||
Name="Button4"
|
||||
Label="Button4"/>
|
||||
Name="topCenter"
|
||||
Label="Center"/>
|
||||
<Button
|
||||
Name="topRight"
|
||||
Label="Right"/>
|
||||
</SideDropDown>
|
||||
|
||||
<SideDropDown
|
||||
Name="SideDropDown"
|
||||
Label="SideDropDown"
|
||||
Name="MiddleSide"
|
||||
Label="Middle"
|
||||
ClosedWidth="100"
|
||||
ClosedHeight="30"
|
||||
ContentHeight="30"
|
||||
ContentWidth="100">
|
||||
<Button
|
||||
Name="Button5"
|
||||
Label="Button5"/>
|
||||
Name="middleLeft"
|
||||
Label="Left"/>
|
||||
<Button
|
||||
Name="Button6"
|
||||
Label="Button6"/>
|
||||
Name="middleCenter"
|
||||
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>
|
||||
|
||||
</DropDown>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import guiTree.Components.Button;
|
||||
import guiTree.Components.DropDown;
|
||||
import guiTree.Components.Text;
|
||||
import guiTree.Components.Picture;
|
||||
import guiTree.Window;
|
||||
import guiTree.events.MouseAdapter;
|
||||
import parser.XAMLParser;
|
||||
@@ -16,34 +15,87 @@ public class Main {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert window != null;
|
||||
Button alignToLeft = (Button) window.findByName("align_to_left");
|
||||
Button alignToRight = (Button) window.findByName("align_to_right");
|
||||
Button alignToCenter = (Button) window.findByName("align_to_center");
|
||||
Text textField = (Text) window.findByName("Text");
|
||||
Button topLeft = (Button) window.findByName("topLeft");
|
||||
Button topCenter = (Button) window.findByName("topCenter");
|
||||
Button topRight = (Button) window.findByName("topRight");
|
||||
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
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
textField.setAlignment("left");
|
||||
textField.update();
|
||||
picture.setLocation("top_left");
|
||||
picture.update();
|
||||
}
|
||||
});
|
||||
|
||||
alignToCenter.addMouseListener(new MouseAdapter() {
|
||||
topRight.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
textField.setAlignment("center");
|
||||
textField.update();
|
||||
picture.setLocation("top_right");
|
||||
picture.update();
|
||||
}
|
||||
});
|
||||
|
||||
alignToRight.addMouseListener(new MouseAdapter() {
|
||||
topCenter.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
textField.setAlignment("right");
|
||||
textField.update();
|
||||
picture.setLocation("top_center");
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ public class Button extends MenuItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer)
|
||||
public void paint(Image imageBuffer)
|
||||
{
|
||||
//Get Graphics
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
@@ -106,7 +106,7 @@ public class Button extends MenuItem {
|
||||
|
||||
int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
|
||||
int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
|
||||
Graphics2D g2 = imageBuffer.createGraphics();
|
||||
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
||||
g2.drawImage(icon, iconX, iconY, null);
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class CheckBox extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
@@ -130,7 +130,7 @@ public class CheckBox extends Visual {
|
||||
|
||||
int iconX = (this.getHeight() - iconWidth) / 2;
|
||||
int iconY = (this.getHeight() - iconHeight) / 2;
|
||||
Graphics2D g2 = imageBuffer.createGraphics();
|
||||
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
||||
g2.drawImage(icon, iconX, iconY, null);
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
@@ -36,11 +36,13 @@ public class Border extends Decoration {
|
||||
update();
|
||||
}
|
||||
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
@Override
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
|
||||
g.setColor(color);
|
||||
g.setStroke(new BasicStroke(thickness));
|
||||
g.drawRect(thickness/2, thickness/2, getWidth() - thickness, getHeight() - thickness);
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
|
||||
@@ -48,8 +48,8 @@ public class CenterTextAligner implements TextAligner{
|
||||
public Point2<Integer> getPositionOnScreen(int x, int y) {
|
||||
String currentLine = wholeText.get(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));
|
||||
return new Point2<>(width, y);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import guiTree.Visual;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
import jdk.jfr.Percentage;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
15
src/guiTree/Components/Decorations/Placers/Placer.java
Normal file
15
src/guiTree/Components/Decorations/Placers/Placer.java
Normal 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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package guiTree.Components.Decoarations;
|
||||
package guiTree.Components.Decorations;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
|
||||
@@ -266,10 +266,11 @@ public class DropDown extends MenuItem implements Menu{
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void paint(BufferedImage imageBuffer)
|
||||
@Override
|
||||
public void paint(Image imageBuffer)
|
||||
{
|
||||
//Get Graphics
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
@@ -293,7 +294,7 @@ public class DropDown extends MenuItem implements Menu{
|
||||
|
||||
int iconX = closedSize.x - iconWidth - 3;
|
||||
int iconY = (closedSize.y - iconHeight - textHeight) / 2;
|
||||
Graphics2D g2 = imageBuffer.createGraphics();
|
||||
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
||||
g2.drawImage(icon, iconX, iconY, null);
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@@ -456,15 +456,14 @@ public class InputTextBox extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
|
||||
g.setColor(getPaintColor());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
if(fontMetrics == null) {
|
||||
fontMetrics = g.getFontMetrics();
|
||||
return;
|
||||
}
|
||||
|
||||
g.setColor(Color.BLUE);
|
||||
@@ -487,5 +486,6 @@ public class InputTextBox extends Visual {
|
||||
g.drawString(line.toString(), 0, y);
|
||||
y += fontMetrics.getHeight();
|
||||
}
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Helper.Point2;
|
||||
import guiTree.Visual;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Panel extends Visual {
|
||||
List<Visual> visuals;
|
||||
HashMap<Visual, Point2<Integer>> visuals;
|
||||
private Boolean overlapping;
|
||||
|
||||
public Panel() {
|
||||
super();
|
||||
overlapping = true;
|
||||
visuals = new ArrayList<>();
|
||||
visuals = new HashMap<>();
|
||||
}
|
||||
|
||||
public void setOverlapping(Boolean overlapping) {
|
||||
@@ -26,74 +26,51 @@ public class Panel extends Visual {
|
||||
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) {
|
||||
if(!overlapping) {
|
||||
boolean ok = false;
|
||||
while(!ok) {
|
||||
ok = true;
|
||||
for (int i = 0; i < visuals.size(); i++) {
|
||||
Visual v2 = visuals.get(i);
|
||||
if (isOverlapping(v, v2) && v != v2) {
|
||||
System.out.println(v + " Overlapping with: " + v2);
|
||||
if(v.getLocationX() + v.getWidth() + v2.getWidth() > this.getWidth()) {
|
||||
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(overlapping) {
|
||||
return;
|
||||
}
|
||||
boolean ok = false;
|
||||
while(!ok) {
|
||||
ok = true;
|
||||
for(Visual v2: visuals.keySet()) {
|
||||
if(v == v2) {
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
v.setLocationY(v.getLocationY() + 10);
|
||||
}
|
||||
if(v.getLocationY() > this.getHeight()) {
|
||||
v.setLocation(0, 0);
|
||||
break;
|
||||
if(v2.getHeight() + v2.getLocationY() + v.getHeight() > getHeight()) {
|
||||
v.setLocation(v2.getLocationX() + v2.getWidth() + 1, visuals.get(v).y);
|
||||
}
|
||||
v.setLocation(visuals.get(v).x, v2.getLocationY() + v2.getHeight() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void reposition() {
|
||||
for(int i = visuals.size() - 1; i >= 0; i--) {
|
||||
calculatePosition(visuals.get(i));
|
||||
}
|
||||
@Override
|
||||
public void removeVisual(Visual v) {
|
||||
super.removeVisual(v);
|
||||
visuals.remove(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVisual(Visual v) {
|
||||
super.addVisual(v);
|
||||
visuals.put(v, new Point2<>(v.getLocationX(), v.getLocationY()));
|
||||
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
|
||||
@@ -101,16 +78,15 @@ public class Panel extends Visual {
|
||||
if(notify == TitleBar.CLOSE || notify == TitleBar.MAXIMIZE ||
|
||||
notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) {
|
||||
notifyParent(v, notify);
|
||||
// return;
|
||||
}
|
||||
// if(notify == SIZE_CHANGED || notify == LOCATION_CHANGED) {
|
||||
// if(notify == SIZE_CHANGED) {
|
||||
// reposition();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
|
||||
g.setColor(getBackgroundColor());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
@@ -8,17 +8,17 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Image extends Visual {
|
||||
public class Picture extends Visual {
|
||||
private BufferedImage bufferedImage;
|
||||
|
||||
public Image() {
|
||||
public Picture() {
|
||||
}
|
||||
|
||||
public Image(String url) {
|
||||
public Picture(String url) {
|
||||
setImage(url);
|
||||
}
|
||||
|
||||
public Image(BufferedImage image) {
|
||||
public Picture(BufferedImage image) {
|
||||
setImage(image);
|
||||
}
|
||||
|
||||
@@ -28,15 +28,16 @@ public class Image extends Visual {
|
||||
|
||||
public void setImage(String url) {
|
||||
try{
|
||||
bufferedImage = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
|
||||
bufferedImage = ImageIO.read(new File("resources\\images\\" + url + ".png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.drawImage(bufferedImage, 0, 0, getWidth(), getHeight(), null);
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ public class RadioButton extends CheckBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
@@ -134,8 +134,8 @@ public class ScrollPanel extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
@@ -205,17 +205,14 @@ public class ScrollPanel extends Visual {
|
||||
private static class VisualLocation {
|
||||
Visual v;
|
||||
Point2<Integer> originalLocation;
|
||||
Point2<Float> originalRelativeLocation;
|
||||
|
||||
public VisualLocation(Visual v) {
|
||||
this.v = v;
|
||||
originalLocation = v.getLocation();
|
||||
originalRelativeLocation = v.getRelativeLocation();
|
||||
}
|
||||
|
||||
public void updateLocation() {
|
||||
originalLocation = v.getLocation();
|
||||
originalRelativeLocation = v.getRelativeLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +216,8 @@ public class Slider extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
g.setColor(getBackgroundColor());
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Components.Decoarations.CenterTextAligner;
|
||||
import guiTree.Components.Decoarations.LeftTextAligner;
|
||||
import guiTree.Components.Decoarations.RightTextAligner;
|
||||
import guiTree.Components.Decoarations.TextAligner;
|
||||
import guiTree.Components.Decorations.CenterTextAligner;
|
||||
import guiTree.Components.Decorations.LeftTextAligner;
|
||||
import guiTree.Components.Decorations.RightTextAligner;
|
||||
import guiTree.Components.Decorations.TextAligner;
|
||||
import guiTree.Helper.Point2;
|
||||
import guiTree.Helper.Point4;
|
||||
import guiTree.Visual;
|
||||
@@ -276,8 +276,8 @@ public class Text extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
if(fontMetrics == null) {
|
||||
fontMetrics = g.getFontMetrics();
|
||||
textAligner.setFontMetrics(fontMetrics);
|
||||
@@ -295,5 +295,6 @@ public class Text extends Visual {
|
||||
Point2<Integer> position = textAligner.alignLine(lines.indexOf(line));
|
||||
g.drawString(line.toString(), position.x, position.y);
|
||||
}
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,12 +134,12 @@ public class TitleBar extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
public void paint(Image imageBuffer) {
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setColor(getBackgroundColor());
|
||||
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.dispose();
|
||||
|
||||
@@ -153,6 +153,7 @@ public class TitleBar extends Visual {
|
||||
g.setColor(Color.WHITE);
|
||||
}
|
||||
g.drawString(title, stringOffset, getHeight()/2 + textHeight/4);
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
private void setButtonLocation() {
|
||||
|
||||
@@ -73,10 +73,10 @@ public class ToggleButton extends Visual {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer)
|
||||
public void paint(Image imageBuffer)
|
||||
{
|
||||
//Get Graphics
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
//Draw Button
|
||||
@@ -103,7 +103,7 @@ public class ToggleButton extends Visual {
|
||||
|
||||
int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
|
||||
int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
|
||||
Graphics2D g2 = imageBuffer.createGraphics();
|
||||
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
||||
g2.drawImage(icon, iconX, iconY, null);
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class CustomFrame extends JFrame {
|
||||
private BufferedImage imageBuffer;
|
||||
private Image imageBuffer;
|
||||
private Window parentWindow;
|
||||
private final int resizeDelta = 5;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CustomFrame extends JFrame {
|
||||
this.addMouseListener(listener);
|
||||
}
|
||||
|
||||
public void setImageBuffer(BufferedImage imageBuffer) {
|
||||
public void setImageBuffer(Image imageBuffer) {
|
||||
this.imageBuffer = imageBuffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package guiTree.Helper;
|
||||
|
||||
public class Debugger {
|
||||
public enum Tag {
|
||||
LISTENER(false),
|
||||
LISTENER(true),
|
||||
PAINTING(false),
|
||||
FPS(false),
|
||||
ANIMATIONS(false),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package guiTree;
|
||||
|
||||
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.Point2;
|
||||
import guiTree.Helper.Point4;
|
||||
import guiTree.Helper.Timer;
|
||||
import guiTree.events.KeyListener;
|
||||
import guiTree.events.MouseListener;
|
||||
@@ -14,10 +16,12 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class Visual {
|
||||
/*--------------------------------------------------------------------
|
||||
@@ -26,7 +30,8 @@ public class Visual {
|
||||
|
||||
public static final int SIZE_CHANGED = 1;
|
||||
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
|
||||
@@ -34,11 +39,13 @@ public class Visual {
|
||||
|
||||
private List<Visual> children;
|
||||
private Visual parent;
|
||||
private BufferedImage imageBuffer;
|
||||
private Image imageBuffer;
|
||||
private String name;
|
||||
private List<MouseListener> mouseListeners;
|
||||
private List<MouseWheelListener> mouseWheelListeners;
|
||||
private List<KeyListener> keyListeners;
|
||||
private static List<AnimationInterface> animations = new ArrayList<>();
|
||||
private static boolean useGPU = GPU_DISABLED;
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Attributes
|
||||
@@ -51,10 +58,9 @@ public class Visual {
|
||||
private Float relativeHeight;
|
||||
private Integer locationX;
|
||||
private Integer locationY;
|
||||
private Placer locationPlacer;
|
||||
private Integer absoluteX;
|
||||
private Integer absoluteY;
|
||||
private Float relativeX;
|
||||
private Float relativeY;
|
||||
private Font font;
|
||||
private Color backgroundColor;
|
||||
private Color foregroundColor;
|
||||
@@ -66,7 +72,8 @@ public class Visual {
|
||||
private static Visual entered;
|
||||
private static Visual focused;
|
||||
private Boolean pressed;
|
||||
private Boolean validating;
|
||||
private Lock validating;
|
||||
private Boolean hardwareAccelerated;
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Constructors
|
||||
@@ -77,35 +84,38 @@ public class Visual {
|
||||
}
|
||||
|
||||
public Visual(int width, int height) {
|
||||
this.children = new ArrayList<>();
|
||||
this.mouseWheelListeners = new ArrayList<>();
|
||||
this.mouseListeners = new ArrayList<>();
|
||||
this.keyListeners = new ArrayList<>();
|
||||
this.parent = null;
|
||||
this.name = "";
|
||||
this.backgroundColor = Color.WHITE;
|
||||
this.foregroundColor = Color.BLUE;
|
||||
this.fontColor = Color.BLACK;
|
||||
this.accentColor = Color.BLUE;
|
||||
children = new ArrayList<>();
|
||||
mouseWheelListeners = new ArrayList<>();
|
||||
mouseListeners = new ArrayList<>();
|
||||
keyListeners = new ArrayList<>();
|
||||
parent = null;
|
||||
name = "";
|
||||
backgroundColor = Color.WHITE;
|
||||
foregroundColor = Color.BLUE;
|
||||
fontColor = Color.BLACK;
|
||||
accentColor = Color.BLUE;
|
||||
|
||||
this.dirty = true;
|
||||
this.active = this instanceof Window;
|
||||
this.pressed = false;
|
||||
this.attributeMap = new HashMap<>();
|
||||
dirty = true;
|
||||
active = this instanceof Window;
|
||||
pressed = false;
|
||||
attributeMap = new HashMap<>();
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.relativeWidth = -1.0f;
|
||||
this.relativeHeight = -1.0f;
|
||||
this.relativeX = -1.0f;
|
||||
this.relativeY = -1.0f;
|
||||
relativeWidth = -1.0f;
|
||||
relativeHeight = -1.0f;
|
||||
locationPlacer = new GeneralPlacer();
|
||||
locationPlacer.setElementSize(width, height);
|
||||
locationPlacer.setLocation(0, 0);
|
||||
locationPlacer.setRelativeLocation(-1.0f, -1.0f);
|
||||
|
||||
this.locationX = 0;
|
||||
this.locationY = 0;
|
||||
this.absoluteX = 0;
|
||||
this.absoluteY = 0;
|
||||
locationX = 0;
|
||||
locationY = 0;
|
||||
absoluteX = 0;
|
||||
absoluteY = 0;
|
||||
|
||||
this.validating = false;
|
||||
validating = new ReentrantLock();
|
||||
hardwareAccelerated = useGPU;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
@@ -127,12 +137,14 @@ public class Visual {
|
||||
|
||||
}
|
||||
initializeImageBuffer();
|
||||
locationPlacer.setElementSize(width, height);
|
||||
|
||||
for(Visual v: children) {
|
||||
if(v.relativeHeight > 0.0 || v.relativeWidth > 0.0) {
|
||||
v.setSize();
|
||||
}
|
||||
if(v.relativeX >= 0.0 || v.relativeY >= 0.0) {
|
||||
if(v.locationPlacer != null) {
|
||||
v.locationPlacer.setParentSize(getWidth(), getHeight());
|
||||
v.setLocation();
|
||||
}
|
||||
}
|
||||
@@ -168,15 +180,18 @@ public class Visual {
|
||||
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() {
|
||||
if(parent != null) {
|
||||
if(relativeX >= 0.0) {
|
||||
locationX = Math.round(relativeX * parent.width);
|
||||
}
|
||||
if(relativeY >= 0.0) {
|
||||
locationY = Math.round(relativeY * parent.height);
|
||||
}
|
||||
}
|
||||
Point2<Integer> location = locationPlacer.getPosition();
|
||||
locationX = location.x;
|
||||
locationY = location.y;
|
||||
|
||||
calculateAbsoluteLocation();
|
||||
update();
|
||||
@@ -184,14 +199,12 @@ public class Visual {
|
||||
}
|
||||
|
||||
public void setLocation(Float x, Float y) {
|
||||
relativeX = x;
|
||||
relativeY = y;
|
||||
locationPlacer.setRelativeLocation(x, y);
|
||||
setLocation();
|
||||
}
|
||||
|
||||
public void setLocation(Integer x, Integer y) {
|
||||
this.locationX = x;
|
||||
this.locationY = y;
|
||||
locationPlacer.setLocation(x, y);
|
||||
setLocation();
|
||||
}
|
||||
|
||||
@@ -203,10 +216,80 @@ public class Visual {
|
||||
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) {
|
||||
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) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.paintColor = backgroundColor;
|
||||
@@ -233,6 +316,19 @@ public class Visual {
|
||||
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) {
|
||||
attributeMap.put(attribute, value);
|
||||
}
|
||||
@@ -265,6 +361,10 @@ public class Visual {
|
||||
return locationY;
|
||||
}
|
||||
|
||||
public Point4<Integer> getMargins() {
|
||||
return locationPlacer.getMargins();
|
||||
}
|
||||
|
||||
public Point2<Integer> getLocation() {
|
||||
return new Point2<>(locationX, locationY);
|
||||
}
|
||||
@@ -281,10 +381,6 @@ public class Visual {
|
||||
return new Point2<>(absoluteX, absoluteY);
|
||||
}
|
||||
|
||||
public Point2<Float> getRelativeLocation() {
|
||||
return new Point2<>(relativeX, relativeY);
|
||||
}
|
||||
|
||||
public boolean isFocused() {
|
||||
return this == focused;
|
||||
}
|
||||
@@ -313,6 +409,14 @@ public class Visual {
|
||||
return paintColor;
|
||||
}
|
||||
|
||||
public boolean isHardwareAccelerated() {
|
||||
return hardwareAccelerated;
|
||||
}
|
||||
|
||||
public boolean isGpuEnabled() {
|
||||
return useGPU;
|
||||
}
|
||||
|
||||
public String getAttribute(String attribute) {
|
||||
return attributeMap.get(attribute);
|
||||
}
|
||||
@@ -419,21 +523,25 @@ public class Visual {
|
||||
Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING);
|
||||
Timer timer = new Timer();
|
||||
|
||||
validating = true;
|
||||
timer.startTiming();
|
||||
validating.lock();
|
||||
try {
|
||||
timer.startTiming();
|
||||
|
||||
clearImageBuffer();
|
||||
paint(imageBuffer);
|
||||
for (Visual v : children) {
|
||||
if (v.dirty && v.active) {
|
||||
v.revalidate();
|
||||
clearImageBuffer();
|
||||
paint(imageBuffer);
|
||||
for (Visual v : children) {
|
||||
if (v.dirty && v.active) {
|
||||
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)){
|
||||
long time = timer.stopTiming();
|
||||
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;
|
||||
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) {
|
||||
@@ -578,7 +687,8 @@ public class Visual {
|
||||
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)) {
|
||||
v.mouseMoved(mouseEvent);
|
||||
return;
|
||||
@@ -649,7 +759,13 @@ public class Visual {
|
||||
if(this.width <= 0 || this.height <= 0) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -657,7 +773,7 @@ public class Visual {
|
||||
if(imageBuffer == null) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g = this.imageBuffer.createGraphics();
|
||||
Graphics2D g = (Graphics2D) imageBuffer.getGraphics();
|
||||
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
@@ -705,16 +821,19 @@ public class Visual {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
dirty = true;
|
||||
validating.lock();
|
||||
try {
|
||||
dirty = true;
|
||||
} finally {
|
||||
validating.unlock();
|
||||
}
|
||||
if(parent != null) {
|
||||
while(parent.validating){
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parent.validating.lock();
|
||||
try {
|
||||
parent.update();
|
||||
} finally {
|
||||
parent.validating.unlock();
|
||||
}
|
||||
parent.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Window extends Visual implements Runnable{
|
||||
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.repaint();
|
||||
}
|
||||
@@ -244,8 +244,8 @@ public class Window extends Visual implements Runnable{
|
||||
public void addVisual(Visual v) {
|
||||
contentPanel.addVisual(v);
|
||||
}
|
||||
|
||||
public void setCursor(Cursor cursor) {
|
||||
System.out.println("Changed cursor ASD");
|
||||
frame.setCursor(cursor);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package parser;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
import guiTree.Components.Decoarations.Decoration;
|
||||
import guiTree.Components.Decorations.Decoration;
|
||||
import parser.converters.Converter;
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Visual;
|
||||
@@ -18,6 +17,7 @@ import java.util.List;
|
||||
public class XAMLParser {
|
||||
private final static String packageGuiTree = "guiTree.";
|
||||
private final static String packageComponents = "guiTree.Components.";
|
||||
private final static String packageDecorations = "guiTree.Components.Decorations.";
|
||||
private static Converter valueConverter = new Converter();
|
||||
|
||||
private static void setAttributes(Object object, NamedNodeMap attributeList){
|
||||
@@ -102,7 +102,7 @@ public class XAMLParser {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
try {
|
||||
primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i)));
|
||||
} catch (InvalidTypeException | NumberFormatException e) {
|
||||
} catch (InvalidClassException | NumberFormatException e) {
|
||||
primitiveAttributes.clear();
|
||||
break;
|
||||
}
|
||||
@@ -122,7 +122,12 @@ public class XAMLParser {
|
||||
parentClass = Class.forName(packageComponents.concat(parentNode.getNodeName()));
|
||||
}
|
||||
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);
|
||||
Object parentObject = parentClass.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package parser.converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
import guiTree.Components.Slider;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.InvalidClassException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Converter {
|
||||
@@ -24,10 +24,10 @@ public class Converter {
|
||||
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)) {
|
||||
return this.converterTable.get(type).convert(content);
|
||||
}
|
||||
throw new InvalidTypeException();
|
||||
throw new InvalidClassException(type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package parser.converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
import java.io.InvalidClassException;
|
||||
|
||||
public interface ConverterInterface<T> {
|
||||
T convert(String content) throws InvalidTypeException;
|
||||
T convert(String content) throws InvalidClassException;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package parser.converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
import guiTree.Components.Slider;
|
||||
|
||||
import java.io.InvalidClassException;
|
||||
|
||||
public class DirectionConverter implements ConverterInterface<Slider.Direction> {
|
||||
@Override
|
||||
public Slider.Direction convert(String content) throws InvalidTypeException {
|
||||
public Slider.Direction convert(String content) throws InvalidClassException {
|
||||
content = content.toLowerCase();
|
||||
if(content.equals("horizontal")) {
|
||||
return Slider.Direction.Horizontal;
|
||||
@@ -13,6 +14,6 @@ public class DirectionConverter implements ConverterInterface<Slider.Direction>
|
||||
if(content.equals("vertical")) {
|
||||
return Slider.Direction.Vertical;
|
||||
}
|
||||
throw new InvalidTypeException();
|
||||
throw new InvalidClassException(Slider.Direction.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package parser.converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
import java.io.InvalidClassException;
|
||||
|
||||
public class FloatConverter implements ConverterInterface<Float> {
|
||||
|
||||
@Override
|
||||
public Float convert(String content) throws InvalidTypeException {
|
||||
public Float convert(String content) throws InvalidClassException {
|
||||
content = content.replaceAll(" ", "");
|
||||
|
||||
if(content.toLowerCase().charAt(content.length() - 1) != 'f') {
|
||||
throw new InvalidTypeException();
|
||||
throw new InvalidClassException(Float.class.getName());
|
||||
}
|
||||
content = content.substring(0, content.length() - 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user