mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
added gif for readme
This commit is contained in:
BIN
resources/jistdemo.gif
Normal file
BIN
resources/jistdemo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 MiB |
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<Window Visible="True" Size="1024, 576">
|
<Window Title="Mock App" Visible="True" Size="1024, 576">
|
||||||
<Button BackgroundColor="#ff0000" Label="Button 1" Icon="circle" Location="top_left" Size="0.3f, 0.1f"/>
|
<Button BackgroundColor="#ff0000" Label="Button 1" Icon="circle" Location="top_left" Size="0.3f, 0.1f"/>
|
||||||
<ToggleButton BackgroundColor="#00ff00" Label="Button 2" Icon="arrow_up_white" Location="top_right" Size="0.3f, 0.3f"/>
|
<ToggleButton BackgroundColor="#00ff00" Label="Button 2" Icon="arrow_up_white" Location="top_right" Size="0.3f, 0.1f"/>
|
||||||
<Panel BackgroundColor="#555555" Size="0.5f, 0.5f" Location="0f, 0.5f"/>
|
<Panel BackgroundColor="#555555" Size="0.5f, 0.5f" Location="0f, 0.5f"/>
|
||||||
</Window>
|
</Window >
|
||||||
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: Main
|
||||||
|
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
|
import guiTree.Animations.ColorAnimation;
|
||||||
|
import guiTree.Components.Button;
|
||||||
|
import guiTree.Window;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
import parser.XMLParser;
|
import parser.XMLParser;
|
||||||
|
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Window window = null;
|
||||||
try {
|
try {
|
||||||
XMLParser.parse("otherui.xml");
|
window = (Window)XMLParser.parse("otherui.xml");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class Button extends MenuItem {
|
|||||||
//Get Graphics
|
//Get Graphics
|
||||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
g.setColor(getPaintColor());
|
g.setColor(getPaintColor());
|
||||||
|
|
||||||
//Draw Button
|
//Draw Button
|
||||||
@@ -97,8 +98,8 @@ public class Button extends MenuItem {
|
|||||||
int iconWidth = 0;
|
int iconWidth = 0;
|
||||||
int iconHeight = 0;
|
int iconHeight = 0;
|
||||||
if(icon != null) {
|
if(icon != null) {
|
||||||
iconWidth = icon.getWidth();
|
iconWidth = Math.min(icon.getWidth(), getWidth());
|
||||||
iconHeight = icon.getHeight();
|
iconHeight = Math.min(icon.getHeight(), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!label.equals("")) {
|
if(!label.equals("")) {
|
||||||
@@ -117,7 +118,7 @@ public class Button extends MenuItem {
|
|||||||
}
|
}
|
||||||
int iconY = (getHeight() - iconHeight)/2;
|
int iconY = (getHeight() - iconHeight)/2;
|
||||||
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
Graphics2D g2 = (Graphics2D)imageBuffer.getGraphics();
|
||||||
g2.drawImage(icon, iconX, iconY, null);
|
g2.drawImage(icon, iconX, iconY, iconWidth, iconHeight, null);
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -137,7 +138,7 @@ public class Button extends MenuItem {
|
|||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRound(int round) {
|
public void setRound(Integer round) {
|
||||||
this.round = round;
|
this.round = round;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class CheckBoxList extends Visual {
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
if(icon != null) {
|
||||||
checkbox.setIcon(icon);
|
checkbox.setIcon(icon);
|
||||||
@@ -88,6 +88,7 @@ public class CheckBoxList extends Visual {
|
|||||||
cb.setSize(width, height);
|
cb.setSize(width, height);
|
||||||
}
|
}
|
||||||
checkBoxSize = new Point2<>(width, height);
|
checkBoxSize = new Point2<>(width, height);
|
||||||
|
setSpacing(this.spacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -138,7 +139,7 @@ public class CheckBoxList extends Visual {
|
|||||||
int offsetY = 0;
|
int offsetY = 0;
|
||||||
for(CheckBox cb: checkBoxList) {
|
for(CheckBox cb: checkBoxList) {
|
||||||
cb.setLocationY(offsetY);
|
cb.setLocationY(offsetY);
|
||||||
offsetY += spacing;
|
offsetY += spacing + cb.getHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class LocationPlacerFactory {
|
public class LocationPlacerFactory {
|
||||||
private static Map<String, Placer> placerMap;
|
private static Map<String, Class<?>> placerMap;
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
public static Placer getPlacer(String name) {
|
public static Placer getPlacer(String name) {
|
||||||
@@ -12,27 +12,31 @@ public class LocationPlacerFactory {
|
|||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
if(placerMap.containsKey(name)) {
|
if(placerMap.containsKey(name)) {
|
||||||
return placerMap.get(name);
|
try {
|
||||||
|
return (Placer) placerMap.get(name).newInstance();
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addPlacer(String name, Placer placer) {
|
public static void addPlacer(String name, Placer placer) {
|
||||||
placerMap.put(name, placer);
|
placerMap.put(name, placer.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initialize() {
|
private static void initialize() {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
placerMap = new HashMap<>();
|
placerMap = new HashMap<>();
|
||||||
placerMap.put("top_left", new TopLeftPlacer());
|
placerMap.put("top_left", TopLeftPlacer.class);
|
||||||
placerMap.put("top_right", new TopRightPlacer());
|
placerMap.put("top_right", TopRightPlacer.class);
|
||||||
placerMap.put("top_center", new TopCenterPlacer());
|
placerMap.put("top_center", TopCenterPlacer.class);
|
||||||
placerMap.put("middle_left", new MiddleLeftPlacer());
|
placerMap.put("middle_left", MiddleLeftPlacer.class);
|
||||||
placerMap.put("middle_right", new MiddleRightPlacer());
|
placerMap.put("middle_right", MiddleRightPlacer.class);
|
||||||
placerMap.put("middle_center", new MiddleCenterPlacer());
|
placerMap.put("middle_center", MiddleCenterPlacer.class);
|
||||||
placerMap.put("bottom_left", new BottomLeftPlacer());
|
placerMap.put("bottom_left", BottomLeftPlacer.class);
|
||||||
placerMap.put("bottom_right", new BottomRightPlacer());
|
placerMap.put("bottom_right", BottomRightPlacer.class);
|
||||||
placerMap.put("bottom_center", new BottomCenterPlacer());
|
placerMap.put("bottom_center", BottomCenterPlacer.class);
|
||||||
placerMap.put("general", new GeneralPlacer());
|
placerMap.put("general", GeneralPlacer.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class DropDown extends MenuItem implements Menu{
|
|||||||
private boolean elementHeightSet;
|
private boolean elementHeightSet;
|
||||||
private int elementHeight;
|
private int elementHeight;
|
||||||
private int elementWidth;
|
private int elementWidth;
|
||||||
|
private int round;
|
||||||
private Point2<Integer> closedSize;
|
private Point2<Integer> closedSize;
|
||||||
private Point2<Integer> openedSize;
|
private Point2<Integer> openedSize;
|
||||||
|
|
||||||
@@ -38,6 +39,8 @@ public class DropDown extends MenuItem implements Menu{
|
|||||||
elementHeightSet = false;
|
elementHeightSet = false;
|
||||||
closedSize = new Point2<>(getWidth(), getHeight());
|
closedSize = new Point2<>(getWidth(), getHeight());
|
||||||
openedSize = new Point2<>(getWidth(), getHeight());
|
openedSize = new Point2<>(getWidth(), getHeight());
|
||||||
|
label = "";
|
||||||
|
round = 0;
|
||||||
|
|
||||||
addMouseListener(new MouseAdapter() {
|
addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -225,14 +228,12 @@ public class DropDown extends MenuItem implements Menu{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void open() {
|
public void open() {
|
||||||
System.out.println("Opening");
|
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
items.forEach(super::addVisual);
|
items.forEach(super::addVisual);
|
||||||
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), openedSize, 70));
|
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), openedSize, 70));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
System.out.println("Closing");
|
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
items.forEach(super::removeVisual);
|
items.forEach(super::removeVisual);
|
||||||
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), closedSize, 70));
|
addAnimation(new SizeAnimation(this, new Point2<>(getWidth(), getHeight()), closedSize, 70));
|
||||||
@@ -254,6 +255,10 @@ public class DropDown extends MenuItem implements Menu{
|
|||||||
return isOpen;
|
return isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRound(Integer round) {
|
||||||
|
this.round = round;
|
||||||
|
}
|
||||||
|
|
||||||
public void setIcon(String url) {
|
public void setIcon(String url) {
|
||||||
try{
|
try{
|
||||||
InputStream iconStream = getClass().getClassLoader().getResourceAsStream("icons/" + url + ".png");
|
InputStream iconStream = getClass().getClassLoader().getResourceAsStream("icons/" + url + ".png");
|
||||||
@@ -270,39 +275,54 @@ public class DropDown extends MenuItem implements Menu{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Image imageBuffer) {
|
public void paint(Image imageBuffer) {
|
||||||
//Get Graphics
|
|
||||||
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
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());
|
||||||
|
|
||||||
//Draw Button
|
//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
|
//Draw Label
|
||||||
if(getFont() != null) {
|
if(getFont() != null) {
|
||||||
g.setFont(getFont());
|
g.setFont(getFont());
|
||||||
}
|
}
|
||||||
g.setColor(this.getFontColor());
|
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("")) {
|
if(!label.equals("")) {
|
||||||
textWidth += g.getFontMetrics().stringWidth(label);
|
int labelX = (getClosedSize().x + iconWidth - textWidth) / 2;
|
||||||
textHeight = g.getFontMetrics().getHeight();
|
int labelY = (getClosedSize().y - textHeight) / 2 + g.getFontMetrics().getAscent();
|
||||||
g.drawString(label, (closedSize.x - textWidth)/2, closedSize.y/2 + textHeight/2);
|
g.drawString(this.label, labelX, labelY);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
|
|||||||
@@ -162,8 +162,9 @@ public class GridPanel extends Visual {
|
|||||||
updateSize();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(BufferedImage imageBuffer) {
|
@Override
|
||||||
Graphics2D g = imageBuffer.createGraphics();
|
public void paint(Image imageBuffer) {
|
||||||
|
Graphics2D g = (Graphics2D)imageBuffer.getGraphics();
|
||||||
g.setColor(getBackgroundColor());
|
g.setColor(getBackgroundColor());
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
g.dispose();
|
g.dispose();
|
||||||
|
|||||||
@@ -236,6 +236,12 @@ public class InputTextBox extends Visual {
|
|||||||
fontMetrics = null;
|
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() {
|
private void copyToClipboard() {
|
||||||
StringBuilder clipboardText = new StringBuilder();
|
StringBuilder clipboardText = new StringBuilder();
|
||||||
for(StringBuilder line: selectedText) {
|
for(StringBuilder line: selectedText) {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package guiTree.Components;
|
|||||||
|
|
||||||
import guiTree.Helper.Point2;
|
import guiTree.Helper.Point2;
|
||||||
import guiTree.Visual;
|
import guiTree.Visual;
|
||||||
|
import guiTree.Window;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Panel extends Visual {
|
public class Panel extends Visual {
|
||||||
@@ -79,6 +79,9 @@ public class Panel extends Visual {
|
|||||||
notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) {
|
notify == TitleBar.MINIMIZE || notify == TitleBar.NORMALIZE) {
|
||||||
notifyParent(v, notify);
|
notifyParent(v, notify);
|
||||||
}
|
}
|
||||||
|
if(notify == Window.BRING_TO_FRONT) {
|
||||||
|
bringToFront(v);
|
||||||
|
}
|
||||||
// if(notify == SIZE_CHANGED) {
|
// if(notify == SIZE_CHANGED) {
|
||||||
// reposition();
|
// reposition();
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import java.awt.event.MouseEvent;
|
|||||||
|
|
||||||
public class ScrollPanel extends Visual {
|
public class ScrollPanel extends Visual {
|
||||||
private List<VisualLocation> children;
|
private List<VisualLocation> 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 verticalScrollBar;
|
||||||
private Slider horizontalScrollBar;
|
private Slider horizontalScrollBar;
|
||||||
@@ -22,7 +28,6 @@ public class ScrollPanel extends Visual {
|
|||||||
super();
|
super();
|
||||||
setName("ScrollPanel");
|
setName("ScrollPanel");
|
||||||
children = new ArrayList<>();
|
children = new ArrayList<>();
|
||||||
addMouseListener(new BarListener());
|
|
||||||
addMouseWheelListener(new MouseWheelListener());
|
addMouseWheelListener(new MouseWheelListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +94,16 @@ public class ScrollPanel extends Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.setLocation("general");
|
||||||
super.addVisual(v);
|
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));
|
children.add(new VisualLocation(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,9 +129,16 @@ public class ScrollPanel extends Visual {
|
|||||||
|
|
||||||
private void setLocations() {
|
private void setLocations() {
|
||||||
for(VisualLocation visualLocation:children) {
|
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.v.setLocation(visualLocation.originalLocation.x - Math.round(horizontalScrollBar.getSliderLocation() * (getFarthestX() - getWidth() + 20)),
|
||||||
visualLocation.originalLocation.y - Math.round(verticalScrollBar.getSliderLocation() * (getFarthestY() - getHeight() + 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();
|
g.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BarListener extends MouseAdapter {
|
@Override
|
||||||
private boolean outHorizontal = false;
|
public boolean isInside(int x, int y) {
|
||||||
private boolean outVertical = false;
|
if(verticalScrollBar != null) {
|
||||||
private LocationAnimation outAnimationHorizontal;
|
if (x > getWidth() + getAbsoluteX() - verticalScrollBar.getWidth() && y > verticalScrollBar.getAbsoluteY() && y < verticalScrollBar.getHeight() + verticalScrollBar.getAbsoluteY()) {
|
||||||
private LocationAnimation outAnimationVertical;
|
if (!outVertical) {
|
||||||
private LocationAnimation inAnimationHorizontal;
|
outAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth() - verticalScrollBar.getWidth(), verticalScrollBar.getLocationY()), 300);
|
||||||
private LocationAnimation inAnimationVertical;
|
removeAnimation(inAnimationVertical);
|
||||||
|
addAnimation(outAnimationVertical);
|
||||||
@Override
|
outVertical = true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if (outVertical) {
|
||||||
if(horizontalScrollBar != null) {
|
inAnimationVertical = new LocationAnimation(verticalScrollBar, verticalScrollBar.getLocation(), new Point2<>(getWidth(), verticalScrollBar.getLocationY()), 300);
|
||||||
if (mouseEvent.getY() > getHeight() - horizontalScrollBar.getHeight() && mouseEvent.getX() > horizontalScrollBar.getLocationX() && mouseEvent.getX() < horizontalScrollBar.getWidth()) {
|
removeAnimation(outAnimationVertical);
|
||||||
if (!outHorizontal) {
|
addAnimation(inAnimationVertical);
|
||||||
outAnimationHorizontal = new LocationAnimation(horizontalScrollBar, horizontalScrollBar.getLocation(), new Point2<>(horizontalScrollBar.getLocationX(), getHeight() - horizontalScrollBar.getHeight()), 300);
|
outVertical = false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
private class MouseWheelListener extends MouseAdapter {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public class SideDropDown extends DropDown implements Menu {
|
|||||||
if(isInside(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen())) {
|
if(isInside(mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println("Exited somehow");
|
|
||||||
close();
|
close();
|
||||||
addAnimation(new ColorAnimation(SideDropDown.this, getForegroundColor(), getBackgroundColor(), 70));
|
addAnimation(new ColorAnimation(SideDropDown.this, getForegroundColor(), getBackgroundColor(), 70));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,22 +244,22 @@ public class Slider extends Visual {
|
|||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent mouseEvent) {
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
if(direction == Direction.Vertical) {
|
if(direction == Direction.Vertical) {
|
||||||
start = mouseEvent.getY();
|
start = mouseEvent.getYOnScreen();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
start = mouseEvent.getX();
|
start = mouseEvent.getXOnScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent mouseEvent) {
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
if(direction == Direction.Vertical) {
|
if(direction == Direction.Vertical) {
|
||||||
moveSlider(mouseEvent.getY() - start);
|
moveSlider(mouseEvent.getYOnScreen() - start);
|
||||||
start = mouseEvent.getY();
|
start = mouseEvent.getYOnScreen();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
moveSlider(mouseEvent.getX() - start);
|
moveSlider(mouseEvent.getXOnScreen() - start);
|
||||||
start = mouseEvent.getX();
|
start = mouseEvent.getXOnScreen();
|
||||||
}
|
}
|
||||||
slider.update();
|
slider.update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,38 @@ public class TitleBar extends Visual {
|
|||||||
this.icon = icon;
|
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) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
update();
|
update();
|
||||||
|
|||||||
@@ -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);
|
tag.setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package guiTree;
|
|||||||
import guiTree.Animations.AnimationInterface;
|
import guiTree.Animations.AnimationInterface;
|
||||||
import guiTree.Components.Decorations.*;
|
import guiTree.Components.Decorations.*;
|
||||||
import guiTree.Components.Decorations.Placers.*;
|
import guiTree.Components.Decorations.Placers.*;
|
||||||
|
import guiTree.Components.DropDown;
|
||||||
import guiTree.Helper.Debugger;
|
import guiTree.Helper.Debugger;
|
||||||
import guiTree.Helper.Point2;
|
import guiTree.Helper.Point2;
|
||||||
import guiTree.Helper.Point4;
|
import guiTree.Helper.Point4;
|
||||||
@@ -44,7 +45,6 @@ public class Visual {
|
|||||||
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;
|
private static boolean useGPU = GPU_DISABLED;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -254,10 +254,23 @@ public class Visual {
|
|||||||
setLocation();
|
setLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLocation(Placer placer) {
|
||||||
|
locationPlacer = placer;
|
||||||
|
setLocation();
|
||||||
|
}
|
||||||
|
|
||||||
public void setFont(Font font) {
|
public void setFont(Font font) {
|
||||||
this.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) {
|
public void setFont(String font, Integer style) {
|
||||||
setFont(font, 10f, style);
|
setFont(font, 10f, style);
|
||||||
}
|
}
|
||||||
@@ -511,25 +524,25 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addAnimation(AnimationInterface animation) {
|
public void addAnimation(AnimationInterface animation) {
|
||||||
animations.add(animation);
|
if (parent != null) {
|
||||||
|
parent.addAnimation(animation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAnimation(AnimationInterface animation) {
|
public void removeAnimation(AnimationInterface animation) {
|
||||||
animations.remove(animation);
|
if(parent != null) {
|
||||||
|
parent.removeAnimation(animation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAllAnimations() {
|
public void removeAllAnimations() {
|
||||||
animations.clear();
|
if(parent != null) {
|
||||||
|
parent.removeAllAnimations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repaint() {
|
public void repaint() {
|
||||||
Debugger.log("Called repaint from " + name, Debugger.Tag.PAINTING);
|
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();
|
validating.lock();
|
||||||
if(dirty && active) {
|
if(dirty && active) {
|
||||||
revalidate();
|
revalidate();
|
||||||
@@ -546,7 +559,8 @@ public class Visual {
|
|||||||
clearImageBuffer();
|
clearImageBuffer();
|
||||||
paint(imageBuffer);
|
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);
|
Visual v = children.get(i);
|
||||||
if (v.dirty && v.active) {
|
if (v.dirty && v.active) {
|
||||||
v.revalidate();
|
v.revalidate();
|
||||||
@@ -580,6 +594,13 @@ public class Visual {
|
|||||||
public void paint(Image imageBuffer) {
|
public void paint(Image imageBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void bringToFront(Visual v) {
|
||||||
|
if(children.contains(v)) {
|
||||||
|
children.remove(v);
|
||||||
|
children.add(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Listener Methods
|
Listener Methods
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
@@ -762,6 +783,10 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void requestFocus() {
|
||||||
|
focused = this;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Helper Methods
|
Helper Methods
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package guiTree;
|
package guiTree;
|
||||||
|
|
||||||
|
import guiTree.Animations.AnimationInterface;
|
||||||
import guiTree.Components.TitleBar;
|
import guiTree.Components.TitleBar;
|
||||||
import guiTree.Helper.Debugger;
|
import guiTree.Helper.Debugger;
|
||||||
import guiTree.Helper.Point2;
|
import guiTree.Helper.Point2;
|
||||||
@@ -19,13 +20,18 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Window extends Visual implements Runnable{
|
public class Window extends Visual implements Runnable{
|
||||||
|
public static final int BRING_TO_FRONT = 100;
|
||||||
public CustomFrame frame;
|
public CustomFrame frame;
|
||||||
private int FPS;
|
private int FPS;
|
||||||
private TitleBar titleBar;
|
private TitleBar titleBar;
|
||||||
private Panel mainPanel;
|
private Panel mainPanel;
|
||||||
private Panel contentPanel;
|
private Panel contentPanel;
|
||||||
private Point2<Integer> oldSize;
|
private Point2<Integer> oldSize;
|
||||||
|
private List<AnimationInterface> animations;
|
||||||
private Boolean close;
|
private Boolean close;
|
||||||
private Point2<Integer> oldLocation;
|
private Point2<Integer> oldLocation;
|
||||||
|
|
||||||
@@ -42,6 +48,7 @@ public class Window extends Visual implements Runnable{
|
|||||||
repaint();
|
repaint();
|
||||||
});
|
});
|
||||||
this.mainPanel = new Panel();
|
this.mainPanel = new Panel();
|
||||||
|
animations = new ArrayList<>();
|
||||||
|
|
||||||
this.setMainPanel(mainPanel);
|
this.setMainPanel(mainPanel);
|
||||||
|
|
||||||
@@ -109,8 +116,8 @@ public class Window extends Visual implements Runnable{
|
|||||||
frame.addWindowStateListener(listener);
|
frame.addWindowStateListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose()
|
public void dispose() {
|
||||||
{
|
close = true;
|
||||||
frame.dispose();
|
frame.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,8 +207,43 @@ public class Window extends Visual implements Runnable{
|
|||||||
this.mainPanel = panel;
|
this.mainPanel = panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Panel getMainPanel() {
|
public void setContentPanel(Panel contentPanel) {
|
||||||
return this.mainPanel;
|
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
|
@Override
|
||||||
@@ -258,6 +300,21 @@ public class Window extends Visual implements Runnable{
|
|||||||
frame.setCursor(cursor);
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Timer frameTimer = new Timer();
|
Timer frameTimer = new Timer();
|
||||||
@@ -267,6 +324,12 @@ public class Window extends Visual implements Runnable{
|
|||||||
secondTimer.startTiming();
|
secondTimer.startTiming();
|
||||||
while(!close) {
|
while(!close) {
|
||||||
if(frameTimer.getTime() >= 1000/FPS) {
|
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();
|
repaint();
|
||||||
frameTimer.startTiming();
|
frameTimer.startTiming();
|
||||||
frames ++;
|
frames ++;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class XMLParser {
|
|||||||
return returnMethods;
|
return returnMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Window parse(String filepath) throws Exception {
|
public static Visual parse(String filepath) throws Exception {
|
||||||
Object rootObject;
|
Object rootObject;
|
||||||
Debugger.log("Started", Debugger.Tag.PARSING);
|
Debugger.log("Started", Debugger.Tag.PARSING);
|
||||||
InputStream fileIS = XMLParser.class.getClassLoader().getResourceAsStream(filepath);
|
InputStream fileIS = XMLParser.class.getClassLoader().getResourceAsStream(filepath);
|
||||||
@@ -84,10 +84,7 @@ public class XMLParser {
|
|||||||
|
|
||||||
rootObject = parseNode(rootNode);
|
rootObject = parseNode(rootNode);
|
||||||
|
|
||||||
if(rootObject instanceof Window) {
|
return (Visual)rootObject;
|
||||||
return (Window) rootObject;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Object> convertStringToPrimitives(String value, List<Method> methods){
|
private static List<Object> convertStringToPrimitives(String value, List<Method> methods){
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ public class ColorConverter implements ConverterInterface<Color> {
|
|||||||
@Override
|
@Override
|
||||||
public Color convert(String content) {
|
public Color convert(String content) {
|
||||||
content = content.replaceAll(" ", "");
|
content = content.replaceAll(" ", "");
|
||||||
|
if(content.length() == 9) {
|
||||||
|
Color newColor = Color.decode(content.substring(0, 7));
|
||||||
|
Integer alpha = Integer.decode("#" + content.substring(7, 9));
|
||||||
|
return new Color(newColor.getRed(), newColor.getGreen(), newColor.getBlue(), alpha);
|
||||||
|
|
||||||
|
}
|
||||||
return Color.decode(content);
|
return Color.decode(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user