diff --git a/resources/jistdemo.gif b/resources/jistdemo.gif
new file mode 100644
index 0000000..964e132
Binary files /dev/null and b/resources/jistdemo.gif differ
diff --git a/resources/otherui.xml b/resources/otherui.xml
index ecab3f9..e8c08c4 100644
--- a/resources/otherui.xml
+++ b/resources/otherui.xml
@@ -1,6 +1,6 @@
-
-
+
+
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5ee19cb
--- /dev/null
+++ b/src/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: Main
+
diff --git a/src/Main.java b/src/Main.java
index b33ee90..9604512 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,9 +1,16 @@
+import guiTree.Animations.ColorAnimation;
+import guiTree.Components.Button;
+import guiTree.Window;
+import guiTree.events.MouseAdapter;
import parser.XMLParser;
+import java.awt.event.MouseEvent;
+
public class Main {
public static void main(String[] args) {
+ Window window = null;
try {
- XMLParser.parse("otherui.xml");
+ window = (Window)XMLParser.parse("otherui.xml");
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/guiTree/Components/Button.java b/src/guiTree/Components/Button.java
index e235e5a..15ec9cc 100644
--- a/src/guiTree/Components/Button.java
+++ b/src/guiTree/Components/Button.java
@@ -86,6 +86,7 @@ public class Button extends MenuItem {
//Get Graphics
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setColor(getPaintColor());
//Draw Button
@@ -97,8 +98,8 @@ public class Button extends MenuItem {
int iconWidth = 0;
int iconHeight = 0;
if(icon != null) {
- iconWidth = icon.getWidth();
- iconHeight = icon.getHeight();
+ iconWidth = Math.min(icon.getWidth(), getWidth());
+ iconHeight = Math.min(icon.getHeight(), getHeight());
}
if(!label.equals("")) {
@@ -117,7 +118,7 @@ public class Button extends MenuItem {
}
int iconY = (getHeight() - iconHeight)/2;
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
- g2.drawImage(icon, iconX, iconY, null);
+ g2.drawImage(icon, iconX, iconY, iconWidth, iconHeight, null);
g2.dispose();
}
@@ -137,7 +138,7 @@ public class Button extends MenuItem {
g.dispose();
}
- public void setRound(int round) {
+ public void setRound(Integer round) {
this.round = round;
}
diff --git a/src/guiTree/Components/CheckBoxList.java b/src/guiTree/Components/CheckBoxList.java
index 33273fb..da0fd95 100644
--- a/src/guiTree/Components/CheckBoxList.java
+++ b/src/guiTree/Components/CheckBoxList.java
@@ -39,7 +39,7 @@ public class CheckBoxList extends Visual {
}
else {
- checkbox.setLocation(0, checkBoxList.get(checkBoxList.size() - 1).getLocationY() + spacing);
+ checkbox.setLocation(0, checkBoxList.get(checkBoxList.size() - 1).getLocationY() + checkBoxList.get(checkBoxList.size() - 1).getHeight() + spacing);
}
if(icon != null) {
checkbox.setIcon(icon);
@@ -88,6 +88,7 @@ public class CheckBoxList extends Visual {
cb.setSize(width, height);
}
checkBoxSize = new Point2<>(width, height);
+ setSpacing(this.spacing);
}
@Override
@@ -138,7 +139,7 @@ public class CheckBoxList extends Visual {
int offsetY = 0;
for(CheckBox cb: checkBoxList) {
cb.setLocationY(offsetY);
- offsetY += spacing;
+ offsetY += spacing + cb.getHeight();
}
}
diff --git a/src/guiTree/Components/Decorations/Placers/LocationPlacerFactory.java b/src/guiTree/Components/Decorations/Placers/LocationPlacerFactory.java
index 6de73e8..3135a61 100644
--- a/src/guiTree/Components/Decorations/Placers/LocationPlacerFactory.java
+++ b/src/guiTree/Components/Decorations/Placers/LocationPlacerFactory.java
@@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class LocationPlacerFactory {
- private static Map placerMap;
+ private static Map> placerMap;
private static boolean initialized = false;
public static Placer getPlacer(String name) {
@@ -12,27 +12,31 @@ public class LocationPlacerFactory {
initialize();
}
if(placerMap.containsKey(name)) {
- return placerMap.get(name);
+ try {
+ return (Placer) placerMap.get(name).newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
}
return null;
}
public static void addPlacer(String name, Placer placer) {
- placerMap.put(name, placer);
+ placerMap.put(name, placer.getClass());
}
private static void initialize() {
initialized = true;
placerMap = new HashMap<>();
- placerMap.put("top_left", new TopLeftPlacer());
- placerMap.put("top_right", new TopRightPlacer());
- placerMap.put("top_center", new TopCenterPlacer());
- placerMap.put("middle_left", new MiddleLeftPlacer());
- placerMap.put("middle_right", new MiddleRightPlacer());
- placerMap.put("middle_center", new MiddleCenterPlacer());
- placerMap.put("bottom_left", new BottomLeftPlacer());
- placerMap.put("bottom_right", new BottomRightPlacer());
- placerMap.put("bottom_center", new BottomCenterPlacer());
- placerMap.put("general", new GeneralPlacer());
+ placerMap.put("top_left", TopLeftPlacer.class);
+ placerMap.put("top_right", TopRightPlacer.class);
+ placerMap.put("top_center", TopCenterPlacer.class);
+ placerMap.put("middle_left", MiddleLeftPlacer.class);
+ placerMap.put("middle_right", MiddleRightPlacer.class);
+ placerMap.put("middle_center", MiddleCenterPlacer.class);
+ placerMap.put("bottom_left", BottomLeftPlacer.class);
+ placerMap.put("bottom_right", BottomRightPlacer.class);
+ placerMap.put("bottom_center", BottomCenterPlacer.class);
+ placerMap.put("general", GeneralPlacer.class);
}
}
diff --git a/src/guiTree/Components/DropDown.java b/src/guiTree/Components/DropDown.java
index 10cec25..9d391dc 100644
--- a/src/guiTree/Components/DropDown.java
+++ b/src/guiTree/Components/DropDown.java
@@ -25,6 +25,7 @@ public class DropDown extends MenuItem implements Menu{
private boolean elementHeightSet;
private int elementHeight;
private int elementWidth;
+ private int round;
private Point2 closedSize;
private Point2 openedSize;
@@ -38,6 +39,8 @@ public class DropDown extends MenuItem implements Menu{
elementHeightSet = false;
closedSize = new Point2<>(getWidth(), getHeight());
openedSize = new Point2<>(getWidth(), getHeight());
+ label = "";
+ round = 0;
addMouseListener(new MouseAdapter() {
@Override
@@ -225,14 +228,12 @@ public class DropDown extends MenuItem implements Menu{
}
public void open() {
- System.out.println("Opening");
isOpen = true;
items.forEach(super::addVisual);
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), openedSize, 70));
}
public void close() {
- System.out.println("Closing");
isOpen = false;
items.forEach(super::removeVisual);
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), closedSize, 70));
@@ -254,6 +255,10 @@ public class DropDown extends MenuItem implements Menu{
return isOpen;
}
+ public void setRound(Integer round) {
+ this.round = round;
+ }
+
public void setIcon(String url) {
try{
InputStream iconStream = getClass().getClassLoader().getResourceAsStream("icons/" + url + ".png");
@@ -270,39 +275,54 @@ public class DropDown extends MenuItem implements Menu{
@Override
public void paint(Image imageBuffer) {
- //Get Graphics
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getPaintColor());
//Draw Button
- g.fillRect(0, 0, closedSize.x, closedSize.y);
+ g.fillRoundRect(0, 0, getClosedSize().x, getClosedSize().y, round, round);
+
+ //Get Sizes
+ int textWidth = 0;
+ int textHeight = 0;
+ int iconWidth = 0;
+ int iconHeight = 0;
+ if(icon != null) {
+ iconWidth = icon.getWidth();
+ iconHeight = icon.getHeight();
+ }
+
+ if(!label.equals("")) {
+ textWidth = g.getFontMetrics().stringWidth(label);
+ textHeight = g.getFontMetrics().getHeight();
+ }
+
+ //Draw Icon
+ if(icon != null) {
+ int iconX;
+ if(textWidth != 0) {
+ iconX = (getClosedSize().x - iconWidth - textWidth - 10) / 2;
+ }
+ else {
+ iconX = (getClosedSize().x - iconWidth) / 2;
+ }
+ int iconY = (getClosedSize().y - iconHeight)/2;
+ Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
+ g2.drawImage(icon, iconX, iconY, null);
+ g2.dispose();
+
+ }
//Draw Label
if(getFont() != null) {
g.setFont(getFont());
}
g.setColor(this.getFontColor());
- int textWidth = 0;
- int textHeight = 0;
-
- //Draw Icon
- if(icon != null) {
- int iconWidth = icon.getWidth();
- int iconHeight = icon.getHeight();
- textWidth += iconWidth;
-
- int iconX = closedSize.x - iconWidth - 3;
- int iconY = (closedSize.y - iconHeight - textHeight) / 2;
- Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
- g2.drawImage(icon, iconX, iconY, null);
- g2.dispose();
- }
if(!label.equals("")) {
- textWidth += g.getFontMetrics().stringWidth(label);
- textHeight = g.getFontMetrics().getHeight();
- g.drawString(label, (closedSize.x - textWidth)/2, closedSize.y/2 + textHeight/2);
+ int labelX = (getClosedSize().x + iconWidth - textWidth) / 2;
+ int labelY = (getClosedSize().y - textHeight) / 2 + g.getFontMetrics().getAscent();
+ g.drawString(this.label, labelX, labelY);
}
g.dispose();
diff --git a/src/guiTree/Components/GridPanel.java b/src/guiTree/Components/GridPanel.java
index 9c704b8..49f3925 100644
--- a/src/guiTree/Components/GridPanel.java
+++ b/src/guiTree/Components/GridPanel.java
@@ -162,8 +162,9 @@ public class GridPanel extends Visual {
updateSize();
}
- public void paint(BufferedImage imageBuffer) {
- Graphics2D g = imageBuffer.createGraphics();
+ @Override
+ public void paint(Image imageBuffer) {
+ Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
diff --git a/src/guiTree/Components/InputTextBox.java b/src/guiTree/Components/InputTextBox.java
index a2e83b8..b7bcb25 100644
--- a/src/guiTree/Components/InputTextBox.java
+++ b/src/guiTree/Components/InputTextBox.java
@@ -236,6 +236,12 @@ public class InputTextBox extends Visual {
fontMetrics = null;
}
+ public String getText() {
+ StringBuilder builder = new StringBuilder();
+ lines.forEach(f -> builder.append(f).append('\n'));
+ return builder.substring(0, builder.length() - 1);
+ }
+
private void copyToClipboard() {
StringBuilder clipboardText = new StringBuilder();
for(StringBuilder line: selectedText) {
diff --git a/src/guiTree/Components/Panel.java b/src/guiTree/Components/Panel.java
index d8e486b..aa2869c 100644
--- a/src/guiTree/Components/Panel.java
+++ b/src/guiTree/Components/Panel.java
@@ -2,9 +2,9 @@ package guiTree.Components;
import guiTree.Helper.Point2;
import guiTree.Visual;
+import guiTree.Window;
import java.awt.*;
-import java.awt.image.BufferedImage;
import java.util.HashMap;
public class Panel extends Visual {
@@ -79,6 +79,9 @@ public class Panel extends Visual {
notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) {
notifyParent(v, notify);
}
+ if(notify == Window.BRING_TO_FRONT) {
+ bringToFront(v);
+ }
// if(notify == SIZE_CHANGED) {
// reposition();
// }
diff --git a/src/guiTree/Components/ScrollPanel.java b/src/guiTree/Components/ScrollPanel.java
index 18fa89d..05b4c2b 100644
--- a/src/guiTree/Components/ScrollPanel.java
+++ b/src/guiTree/Components/ScrollPanel.java
@@ -14,6 +14,12 @@ import java.awt.event.MouseEvent;
public class ScrollPanel extends Visual {
private List children;
+ private boolean outHorizontal = false;
+ private boolean outVertical = false;
+ private LocationAnimation outAnimationHorizontal;
+ private LocationAnimation outAnimationVertical;
+ private LocationAnimation inAnimationHorizontal;
+ private LocationAnimation inAnimationVertical;
private Slider verticalScrollBar;
private Slider horizontalScrollBar;
@@ -22,7 +28,6 @@ public class ScrollPanel extends Visual {
super();
setName("ScrollPanel");
children = new ArrayList<>();
- addMouseListener(new BarListener());
addMouseWheelListener(new MouseWheelListener());
}
@@ -89,7 +94,16 @@ public class ScrollPanel extends Visual {
}
}
+ v.setLocation("general");
super.addVisual(v);
+ if(verticalScrollBar != null) {
+ super.removeVisual(verticalScrollBar);
+ super.addVisual(verticalScrollBar);
+ }
+ if(horizontalScrollBar != null) {
+ super.removeVisual(horizontalScrollBar);
+ super.addVisual(horizontalScrollBar);
+ }
children.add(new VisualLocation(v));
}
@@ -115,9 +129,16 @@ public class ScrollPanel extends Visual {
private void setLocations() {
for(VisualLocation visualLocation:children) {
+ if(horizontalScrollBar == null) {
+ visualLocation.v.setLocationY(visualLocation.originalLocation.y - Math.round(verticalScrollBar.getSliderLocation() * (getFarthestY() - getHeight() + 20)));
+ continue;
+ }
+ if(verticalScrollBar == null) {
+ visualLocation.v.setLocationX(visualLocation.originalLocation.x - Math.round(horizontalScrollBar.getSliderLocation() * (getFarthestX() - getWidth() + 20)));
+ continue;
+ }
visualLocation.v.setLocation(visualLocation.originalLocation.x - Math.round(horizontalScrollBar.getSliderLocation() * (getFarthestX() - getWidth() + 20)),
visualLocation.originalLocation.y - Math.round(verticalScrollBar.getSliderLocation() * (getFarthestY() - getHeight() + 20)));
- System.out.println("Moved: " + visualLocation.v + " from x: " + visualLocation.originalLocation + " to " + visualLocation.v.getLocation());
}
}
@@ -138,52 +159,44 @@ public class ScrollPanel extends Visual {
g.dispose();
}
- private class BarListener extends MouseAdapter {
- private boolean outHorizontal = false;
- private boolean outVertical = false;
- private LocationAnimation outAnimationHorizontal;
- private LocationAnimation outAnimationVertical;
- private LocationAnimation inAnimationHorizontal;
- private LocationAnimation inAnimationVertical;
-
- @Override
- public void mouseMoved(MouseEvent mouseEvent) {
- if(verticalScrollBar != null) {
- if (mouseEvent.getX() > getWidth() - verticalScrollBar.getWidth() && mouseEvent.getY() > verticalScrollBar.getLocationY() && mouseEvent.getY() < verticalScrollBar.getHeight()) {
- if (!outVertical) {
- outAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth() - verticalScrollBar.getWidth(), verticalScrollBar.getLocationY()), 300);
- removeAnimation(inAnimationVertical);
- addAnimation(outAnimationVertical);
- outVertical = true;
- }
- } else {
- if (outVertical) {
- inAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth(), verticalScrollBar.getLocationY()), 300);
- removeAnimation(outAnimationVertical);
- addAnimation(inAnimationVertical);
- outVertical = false;
- }
+ @Override
+ public boolean isInside(int x, int y) {
+ if(verticalScrollBar != null) {
+ if (x > getWidth() + getAbsoluteX() - verticalScrollBar.getWidth() && y > verticalScrollBar.getAbsoluteY() && y < verticalScrollBar.getHeight() + verticalScrollBar.getAbsoluteY()) {
+ if (!outVertical) {
+ outAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth() - verticalScrollBar.getWidth(), verticalScrollBar.getLocationY()), 300);
+ removeAnimation(inAnimationVertical);
+ addAnimation(outAnimationVertical);
+ outVertical = true;
}
- }
-
- if(horizontalScrollBar != null) {
- if (mouseEvent.getY() > getHeight() - horizontalScrollBar.getHeight() && mouseEvent.getX() > horizontalScrollBar.getLocationX() && mouseEvent.getX() < horizontalScrollBar.getWidth()) {
- if (!outHorizontal) {
- outAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight() - horizontalScrollBar.getHeight()), 300);
- removeAnimation(inAnimationHorizontal);
- addAnimation(outAnimationHorizontal);
- outHorizontal = true;
- }
- } else {
- if (outHorizontal) {
- inAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight()), 300);
- removeAnimation(outAnimationHorizontal);
- addAnimation(inAnimationHorizontal);
- outHorizontal = false;
- }
+ } else {
+ if (outVertical) {
+ inAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth(), verticalScrollBar.getLocationY()), 300);
+ removeAnimation(outAnimationVertical);
+ addAnimation(inAnimationVertical);
+ outVertical = false;
}
}
}
+
+ if(horizontalScrollBar != null) {
+ if (y > getHeight() + getAbsoluteY() - horizontalScrollBar.getHeight() && x > horizontalScrollBar.getAbsoluteX() && x < horizontalScrollBar.getWidth() + horizontalScrollBar.getAbsoluteX()) {
+ if (!outHorizontal) {
+ outAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight() - horizontalScrollBar.getHeight()), 300);
+ removeAnimation(inAnimationHorizontal);
+ addAnimation(outAnimationHorizontal);
+ outHorizontal = true;
+ }
+ } else {
+ if (outHorizontal) {
+ inAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight()), 300);
+ removeAnimation(outAnimationHorizontal);
+ addAnimation(inAnimationHorizontal);
+ outHorizontal = false;
+ }
+ }
+ }
+ return super.isInside(x, y);
}
private class MouseWheelListener extends MouseAdapter {
diff --git a/src/guiTree/Components/SideDropDown.java b/src/guiTree/Components/SideDropDown.java
index e6aea0b..f50c681 100644
--- a/src/guiTree/Components/SideDropDown.java
+++ b/src/guiTree/Components/SideDropDown.java
@@ -29,7 +29,6 @@ public class SideDropDown extends DropDown implements Menu {
if(isInside(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen())) {
return;
}
- System.out.println("Exited somehow");
close();
addAnimation(new ColorAnimation(SideDropDown.this, getForegroundColor(), getBackgroundColor(), 70));
}
diff --git a/src/guiTree/Components/Slider.java b/src/guiTree/Components/Slider.java
index c0c06d0..15a92be 100644
--- a/src/guiTree/Components/Slider.java
+++ b/src/guiTree/Components/Slider.java
@@ -244,22 +244,22 @@ public class Slider extends Visual {
@Override
public void mousePressed(MouseEvent mouseEvent) {
if(direction == Direction.Vertical) {
- start = mouseEvent.getY();
+ start = mouseEvent.getYOnScreen();
}
else {
- start = mouseEvent.getX();
+ start = mouseEvent.getXOnScreen();
}
}
@Override
public void mouseDragged(MouseEvent mouseEvent) {
if(direction == Direction.Vertical) {
- moveSlider(mouseEvent.getY() - start);
- start = mouseEvent.getY();
+ moveSlider(mouseEvent.getYOnScreen() - start);
+ start = mouseEvent.getYOnScreen();
}
else {
- moveSlider(mouseEvent.getX() - start);
- start = mouseEvent.getX();
+ moveSlider(mouseEvent.getXOnScreen() - start);
+ start = mouseEvent.getXOnScreen();
}
slider.update();
}
diff --git a/src/guiTree/Components/TitleBar.java b/src/guiTree/Components/TitleBar.java
index 9b61d72..3b8175f 100644
--- a/src/guiTree/Components/TitleBar.java
+++ b/src/guiTree/Components/TitleBar.java
@@ -122,6 +122,38 @@ public class TitleBar extends Visual {
this.icon = icon;
}
+ @Override
+ public void setBackgroundColor(Color color) {
+ super.setBackgroundColor(color);
+ close.setBackgroundColor(color);
+ maximize.setBackgroundColor(color);
+ minimize.setBackgroundColor(color);
+ }
+
+ @Override
+ public void setAccentColor(Color color) {
+ super.setAccentColor(color);
+ close.setAccentColor(color);
+ maximize.setAccentColor(color);
+ minimize.setAccentColor(color);
+ }
+
+ @Override
+ public void setForegroundColor(Color color) {
+ super.setForegroundColor(color);
+ close.setForegroundColor(color);
+ maximize.setForegroundColor(color);
+ minimize.setForegroundColor(color);
+ }
+
+ @Override
+ public void setPaintColor(Color color) {
+ super.setPaintColor(color);
+ close.setPaintColor(color);
+ maximize.setPaintColor(color);
+ minimize.setPaintColor(color);
+ }
+
public void setTitle(String title) {
this.title = title;
update();
diff --git a/src/guiTree/Helper/Debugger.java b/src/guiTree/Helper/Debugger.java
index 67326c2..e7829d3 100644
--- a/src/guiTree/Helper/Debugger.java
+++ b/src/guiTree/Helper/Debugger.java
@@ -27,7 +27,7 @@ public class Debugger {
}
}
- public void enableTag(Tag tag, Boolean value) {
+ public static void enableTag(Tag tag, Boolean value) {
tag.setValue(value);
}
}
diff --git a/src/guiTree/Visual.java b/src/guiTree/Visual.java
index 83be5f2..1680439 100644
--- a/src/guiTree/Visual.java
+++ b/src/guiTree/Visual.java
@@ -3,6 +3,7 @@ package guiTree;
import guiTree.Animations.AnimationInterface;
import guiTree.Components.Decorations.*;
import guiTree.Components.Decorations.Placers.*;
+import guiTree.Components.DropDown;
import guiTree.Helper.Debugger;
import guiTree.Helper.Point2;
import guiTree.Helper.Point4;
@@ -44,7 +45,6 @@ public class Visual {
private List mouseListeners;
private List mouseWheelListeners;
private List keyListeners;
- private static List animations = new ArrayList<>();
private static boolean useGPU = GPU_DISABLED;
/*--------------------------------------------------------------------
@@ -254,10 +254,23 @@ public class Visual {
setLocation();
}
+ public void setLocation(Placer placer) {
+ locationPlacer = placer;
+ setLocation();
+ }
+
public void setFont(Font font) {
this.font = font;
}
+ public void setFontSize(Float size) {
+ if(font == null) {
+ font = new Font("TimesRoman", Font.BOLD, Math.round(size));
+ return;
+ }
+ font = font.deriveFont(size);
+ }
+
public void setFont(String font, Integer style) {
setFont(font, 10f, style);
}
@@ -511,25 +524,25 @@ public class Visual {
}
public void addAnimation(AnimationInterface animation) {
- animations.add(animation);
+ if (parent != null) {
+ parent.addAnimation(animation);
+ }
}
public void removeAnimation(AnimationInterface animation) {
- animations.remove(animation);
+ if(parent != null) {
+ parent.removeAnimation(animation);
+ }
}
public void removeAllAnimations() {
- animations.clear();
+ if(parent != null) {
+ parent.removeAllAnimations();
+ }
}
public void repaint() {
Debugger.log("Called repaint from " + name, Debugger.Tag.PAINTING);
- for(int i = 0; i < animations.size(); i++) {
- if(animations.get(i).step()) {
- animations.remove(animations.get(i));
- i--;
- }
- }
validating.lock();
if(dirty && active) {
revalidate();
@@ -546,7 +559,8 @@ public class Visual {
clearImageBuffer();
paint(imageBuffer);
- for (int i = 0; i < children.size(); i++) {
+ int size = children.size();
+ for (int i = 0; i < size; i++) {
Visual v = children.get(i);
if (v.dirty && v.active) {
v.revalidate();
@@ -580,6 +594,13 @@ public class Visual {
public void paint(Image imageBuffer) {
}
+ public void bringToFront(Visual v) {
+ if(children.contains(v)) {
+ children.remove(v);
+ children.add(v);
+ }
+ }
+
/*--------------------------------------------------------------------
Listener Methods
---------------------------------------------------------------------*/
@@ -762,6 +783,10 @@ public class Visual {
}
}
+ public void requestFocus() {
+ focused = this;
+ }
+
/*--------------------------------------------------------------------
Helper Methods
---------------------------------------------------------------------*/
diff --git a/src/guiTree/Window.java b/src/guiTree/Window.java
index 271a113..d33dffd 100644
--- a/src/guiTree/Window.java
+++ b/src/guiTree/Window.java
@@ -1,5 +1,6 @@
package guiTree;
+import guiTree.Animations.AnimationInterface;
import guiTree.Components.TitleBar;
import guiTree.Helper.Debugger;
import guiTree.Helper.Point2;
@@ -19,13 +20,18 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
public class Window extends Visual implements Runnable{
+ public static final int BRING_TO_FRONT = 100;
public CustomFrame frame;
private int FPS;
private TitleBar titleBar;
private Panel mainPanel;
private Panel contentPanel;
private Point2 oldSize;
+ private List animations;
private Boolean close;
private Point2 oldLocation;
@@ -42,6 +48,7 @@ public class Window extends Visual implements Runnable{
repaint();
});
this.mainPanel = new Panel();
+ animations = new ArrayList<>();
this.setMainPanel(mainPanel);
@@ -109,8 +116,8 @@ public class Window extends Visual implements Runnable{
frame.addWindowStateListener(listener);
}
- public void dispose()
- {
+ public void dispose() {
+ close = true;
frame.dispose();
}
@@ -200,8 +207,43 @@ public class Window extends Visual implements Runnable{
this.mainPanel = panel;
}
- public Panel getMainPanel() {
- return this.mainPanel;
+ public void setContentPanel(Panel contentPanel) {
+ mainPanel.removeVisual(this.contentPanel);
+ contentPanel.setName("ContentPanel");
+
+ if(titleBar != null) {
+ mainPanel.addVisual(titleBar);
+ contentPanel.setLocation(0, titleBar.getHeight());
+ contentPanel.setSize(mainPanel.getWidth(), mainPanel.getHeight() - titleBar.getHeight());
+ }
+ else {
+ contentPanel.setLocation(0, 0);
+ contentPanel.setSize(mainPanel.getWidth(), mainPanel.getHeight());
+ }
+
+ mainPanel.addVisual(contentPanel);
+ this.contentPanel = contentPanel;
+ }
+
+ public Panel getContentPanel() {
+ return contentPanel;
+ }
+
+ public void setTitleBarBackgroundColor(Color color) {
+ titleBar.setBackgroundColor(color);
+ }
+
+ public void setTitleBarAccentColor(Color color) {
+ titleBar.setAccentColor(color);
+ }
+
+ public void setTitleBarForegroundColor(Color color) {
+ titleBar.setForegroundColor(color);
+ }
+
+ @Override
+ public void setBackgroundColor(Color color) {
+ contentPanel.setBackgroundColor(color);
}
@Override
@@ -258,6 +300,21 @@ public class Window extends Visual implements Runnable{
frame.setCursor(cursor);
}
+ @Override
+ public void addAnimation(AnimationInterface animation) {
+ animations.add(animation);
+ }
+
+ @Override
+ public void removeAnimation(AnimationInterface animation) {
+ animations.remove(animation);
+ }
+
+ @Override
+ public void removeAllAnimations() {
+ animations.clear();
+ }
+
@Override
public void run() {
Timer frameTimer = new Timer();
@@ -267,6 +324,12 @@ public class Window extends Visual implements Runnable{
secondTimer.startTiming();
while(!close) {
if(frameTimer.getTime() >= 1000/FPS) {
+ for(int i = 0; i < animations.size(); i++) {
+ if(animations.get(i).step()) {
+ animations.remove(animations.get(i));
+ i--;
+ }
+ }
repaint();
frameTimer.startTiming();
frames ++;
diff --git a/src/parser/XMLParser.java b/src/parser/XMLParser.java
index ce4aa73..60e8b2d 100644
--- a/src/parser/XMLParser.java
+++ b/src/parser/XMLParser.java
@@ -66,7 +66,7 @@ public class XMLParser {
return returnMethods;
}
- public static Window parse(String filepath) throws Exception {
+ public static Visual parse(String filepath) throws Exception {
Object rootObject;
Debugger.log("Started", Debugger.Tag.PARSING);
InputStream fileIS = XMLParser.class.getClassLoader().getResourceAsStream(filepath);
@@ -84,10 +84,7 @@ public class XMLParser {
rootObject = parseNode(rootNode);
- if(rootObject instanceof Window) {
- return (Window) rootObject;
- }
- return null;
+ return (Visual)rootObject;
}
private static List