mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
removed recursive call in paint
added scroll panes without relative position
This commit is contained in:
@@ -4,63 +4,11 @@
|
||||
Visible="true"
|
||||
Size="640, 480"
|
||||
Title="FANTASTICEST UI THINGY">
|
||||
<!-- <Panel-->
|
||||
<!-- Name="ProgramPanel"-->
|
||||
<!-- Size="1.0, 1.0"-->
|
||||
<!-- Location="0.0, 0.0"-->
|
||||
<!-- BackgroundColor="#333333">-->
|
||||
<Button
|
||||
Name="button1"
|
||||
BackgroundColor="#999999"
|
||||
AccentColor="#666666"
|
||||
ForegroundColor="#333333"
|
||||
Size="320, 240"
|
||||
Location="0.0, 0.5"
|
||||
HasBorder="true"
|
||||
Label="button1">
|
||||
<Button
|
||||
Name="button4"
|
||||
BackgroundColor="#009999"
|
||||
AccentColor="#006666"
|
||||
ForegroundColor="#003333"
|
||||
Size="0.5, 0.5"
|
||||
Location="0.25, 0.25"
|
||||
Icon="square_white"
|
||||
HasBorder="true">
|
||||
<ToggleButton
|
||||
Name="button2"
|
||||
BackgroundColor="#000099"
|
||||
AccentColor="#000066"
|
||||
ForegroundColor="#000033"
|
||||
Size="0.5, 0.5"
|
||||
Location="0.25, 0.25"
|
||||
Label="button2"/>
|
||||
</Button>
|
||||
</Button>
|
||||
<!-- <Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>-->
|
||||
<!-- <CheckBoxList-->
|
||||
<!-- Name="checkboxlist"-->
|
||||
<!-- CheckBoxSize="300, 20"-->
|
||||
<!-- BackgroundColor="#666666"-->
|
||||
<!-- AccentColor="#444444"-->
|
||||
<!-- ForegroundColor="#005599"-->
|
||||
<!-- Size="0.5, 0.3"-->
|
||||
<!-- Icon="check_white"-->
|
||||
<!-- Spacing="30"-->
|
||||
<!-- Location="0.0, 0.0">-->
|
||||
<!-- <CheckBox-->
|
||||
<!-- Name="checkbox1"-->
|
||||
<!-- Text="HAHA FRAR"/>-->
|
||||
<!-- <CheckBox-->
|
||||
<!-- Name="checkbox2"-->
|
||||
<!-- Text="HAHA FRAR2"/>-->
|
||||
<!-- <CheckBox-->
|
||||
<!-- Name="checkbox3"-->
|
||||
<!-- Text="HAHA FRAR3"/>-->
|
||||
<!-- </CheckBoxList>-->
|
||||
<ToggleButton Name="button3" BackgroundColor="#123456" AccentColor="654321" Size="100, 100" Location="0.5, 0.5" Icon="minimize_white"/>
|
||||
<Slider Name="slider" Location="-20, 0" Size="20, 100" HasBorder="false"/>
|
||||
<Slider Name="hslider" Location="400, 0" Size="80, 20" Direction="horizontal"/>
|
||||
<Button Location="350, 20" Size="20, 70"/>
|
||||
<!-- </Panel>-->
|
||||
<ScrollPanel Name="ScrollPane" BackgroundColor="#333333" Size="1.0, 1.0" Location="0.0, 0.0">
|
||||
<ToggleButton Name="button3" BackgroundColor="#123456" AccentColor="#654321" Size="100, 100" Location="320, 240" Icon="minimize_white"/>
|
||||
<Slider Name="Slider" Size="100, 20" Location="0, 0" Direction="horizontal" SliderSize="0.3"/>
|
||||
<Slider Name="VSlider" Size="20, 100" Location="101, 0" SliderSize="0.5"/>
|
||||
<Button Name="Button" BackgroundColor="#777777" AccentColor="#654321" Size="100, 100" Location="660, 0"/>
|
||||
<Button Name="Button" BackgroundColor="#777777" AccentColor="#654321" Size="100, 100" Location="660, 660"/>
|
||||
</ScrollPanel>
|
||||
</Window>
|
||||
@@ -1,53 +1,14 @@
|
||||
import guiTree.Animations.ColorAnimation;
|
||||
import guiTree.Animations.LocationAnimation;
|
||||
import guiTree.Components.Slider;
|
||||
import guiTree.Helper.Point2;
|
||||
import guiTree.Visual;
|
||||
import guiTree.Components.ScrollPanel;
|
||||
import guiTree.Window;
|
||||
import guiTree.events.MouseAdapter;
|
||||
import parser.XAMLParser;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
Window window = XAMLParser.parse("ui.xml");
|
||||
assert window != null;
|
||||
Slider hslider = (Slider)window.findByName("hslider");
|
||||
Slider slider = (Slider)window.findByName("slider");
|
||||
window.repaint();
|
||||
ColorAnimation sliderColor = new ColorAnimation(hslider, slider.getBackgroundColor(), Color.RED, 1000);
|
||||
window.addMouseListener(new MouseAdapter() {
|
||||
private boolean out = false;
|
||||
private LocationAnimation outAnimation;
|
||||
private LocationAnimation inAnimation;
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent mouseEvent) {
|
||||
if(mouseEvent.getX() < 20 && mouseEvent.getY() > 0 && mouseEvent.getY() < 100) {
|
||||
if(!out) {
|
||||
outAnimation = new LocationAnimation(slider, slider.getLocation(), new Point2<>(0, slider.getLocationY()), 500);
|
||||
window.removeAnimation(inAnimation);
|
||||
window.addAnimation(outAnimation);
|
||||
out = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(out) {
|
||||
inAnimation = new LocationAnimation(slider, slider.getLocation(), new Point2<>(- 20, slider.getLocationY()), 500);
|
||||
window.removeAnimation(outAnimation);
|
||||
window.addAnimation(inAnimation);
|
||||
out = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Thread.sleep(5000);
|
||||
System.out.println("Started moving");
|
||||
hslider.addAnimation(new LocationAnimation(hslider, hslider.getLocation(), new Point2<>(hslider.getLocationX(), hslider.getLocationY() + 100), 1000));
|
||||
hslider.addAnimation(sliderColor);
|
||||
ScrollPanel scrollPanel = (ScrollPanel)window.findByName("ScrollPane");
|
||||
System.out.println();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class FloatConverter implements ConverterInterface<Float> {
|
||||
public Float convert(String content) throws InvalidTypeException {
|
||||
content = content.replaceAll(" ", "");
|
||||
float number = Float.parseFloat(content);
|
||||
if(number > 1 || number < 0) {
|
||||
if(number > 1 || number < 0 || !content.contains(".")) {
|
||||
throw new InvalidTypeException();
|
||||
}
|
||||
return Float.parseFloat(content);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ColorAnimation implements AnimationInterface {
|
||||
from.b > to.b - 1 && from.b < to.b + 1 &&
|
||||
from.c > to.c - 1 && from.c < to.c + 1 &&
|
||||
from.d > to.d - 1 && from.d < to.d + 1) {
|
||||
element.setBackgroundColor(new Color(to.a, to.b, to.c, to.d));
|
||||
element.setPaintColor(new Color(to.a, to.b, to.c, to.d));
|
||||
Debugger.log("Animation for " + element.getName() + " finished", Debugger.Tag.ANIMATIONS);
|
||||
return true;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class ColorAnimation implements AnimationInterface {
|
||||
from.b += offset.b;
|
||||
from.c += offset.c;
|
||||
from.d += offset.d;
|
||||
element.setBackgroundColor(new Color(Math.round(from.a), Math.round(from.b), Math.round(from.c), Math.round(from.d)));
|
||||
element.setPaintColor(new Color(Math.round(from.a), Math.round(from.b), Math.round(from.c), Math.round(from.d)));
|
||||
element.update();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Animations.ColorAnimation;
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Visual;
|
||||
import guiTree.events.MouseAdapter;
|
||||
@@ -13,8 +14,6 @@ import java.io.IOException;
|
||||
|
||||
public class Button extends Visual {
|
||||
private String label;
|
||||
private Boolean pressed;
|
||||
private Boolean hovered;
|
||||
private BufferedImage icon;
|
||||
private int round = -1;
|
||||
|
||||
@@ -34,36 +33,33 @@ public class Button extends Visual {
|
||||
super();
|
||||
this.label = label;
|
||||
this.icon = icon;
|
||||
pressed = false;
|
||||
hovered = false;
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent mouseEvent) {
|
||||
pressed = false;
|
||||
update();
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
pressed = true;
|
||||
addAnimation(new ColorAnimation(Button.this, getAccentColor(), getForegroundColor(), 100));
|
||||
update();
|
||||
Debugger.log("Pressed: " + getName(), Debugger.Tag.LISTENER);
|
||||
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
pressed = false;
|
||||
addAnimation(new ColorAnimation(Button.this, getForegroundColor(), getAccentColor(), 100));
|
||||
update();
|
||||
Debugger.log("Calling repaint from released: " + getName(), Debugger.Tag.PAINTING);
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
hovered = true;
|
||||
addAnimation(new ColorAnimation(Button.this, getBackgroundColor(), getAccentColor(), 100));
|
||||
update();
|
||||
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
hovered = false;
|
||||
addAnimation(new ColorAnimation(Button.this, getAccentColor(), getBackgroundColor(), 100));
|
||||
update();
|
||||
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
|
||||
}
|
||||
@@ -83,17 +79,7 @@ public class Button extends Visual {
|
||||
//Get Graphics
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
//Choose background
|
||||
if(hovered) {
|
||||
g.setColor(this.getAccentColor());
|
||||
}
|
||||
else {
|
||||
g.setColor(this.getBackgroundColor());
|
||||
}
|
||||
if(pressed) {
|
||||
g.setColor(this.getForegroundColor());
|
||||
}
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
//Draw Button
|
||||
if(getHasBorder()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Animations.ColorAnimation;
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Visual;
|
||||
import guiTree.events.MouseAdapter;
|
||||
@@ -37,19 +38,29 @@ public class CheckBox extends Visual {
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
if(!marked) {
|
||||
addAnimation(new ColorAnimation(CheckBox.this, getAccentColor(), getForegroundColor(), 100));
|
||||
}
|
||||
else {
|
||||
addAnimation(new ColorAnimation(CheckBox.this, getForegroundColor(), getAccentColor(), 100));
|
||||
}
|
||||
marked = !marked;
|
||||
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
hovered = true;
|
||||
if(!marked) {
|
||||
addAnimation(new ColorAnimation(CheckBox.this, getBackgroundColor(), getAccentColor(), 100));
|
||||
}
|
||||
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
hovered = false;
|
||||
if(!marked) {
|
||||
addAnimation(new ColorAnimation(CheckBox.this, getAccentColor(), getBackgroundColor(), 100));
|
||||
}
|
||||
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@@ -92,19 +103,11 @@ public class CheckBox extends Visual {
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
|
||||
//Set Transparency
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
if(hovered && !marked) {
|
||||
g.setColor(getAccentColor());
|
||||
g.fillRect(0, 0, getHeight() - 1, getHeight() - 1);
|
||||
}
|
||||
g.fillRect(1, 1, getHeight() - 1, getHeight() - 1);
|
||||
|
||||
if(marked) {
|
||||
g.setColor(getForegroundColor());
|
||||
g.fillRect(1, 1, getHeight() - 2, getHeight() - 2);
|
||||
|
||||
if(icon != null) {
|
||||
int iconWidth = icon.getWidth();
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Animations.LocationAnimation;
|
||||
import guiTree.Helper.Point2;
|
||||
import guiTree.Visual;
|
||||
import guiTree.events.MouseAdapter;
|
||||
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class ScrollPanel extends Visual {
|
||||
private List<VisualLocation> children;
|
||||
|
||||
private float positionX;
|
||||
private float positionY;
|
||||
@@ -19,48 +26,187 @@ public class ScrollPanel extends Visual {
|
||||
public ScrollPanel() {
|
||||
super();
|
||||
setName("ScrollPanel");
|
||||
horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
|
||||
verticalScrollBar = new Slider(Slider.Direction.Vertical);
|
||||
verticalScrollBar.setHasBorder(true);
|
||||
horizontalScrollBar.setHasBorder(true);
|
||||
addVisual(verticalScrollBar);
|
||||
addVisual(horizontalScrollBar);
|
||||
verticalScrollBar.setName("vertical scroll bar");
|
||||
horizontalScrollBar.setName("horizontal scroll bar");
|
||||
children = new ArrayList<>();
|
||||
addMouseListener(new BarListener());
|
||||
addMouseWheelListener(new MouseWheelListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize() {
|
||||
super.setSize();
|
||||
if(verticalScrollBar != null && horizontalScrollBar != null) {
|
||||
verticalScrollBar.setSize(20, getHeight() - 20);
|
||||
horizontalScrollBar.setSize(getWidth() - 20, 20);
|
||||
return;
|
||||
if (getFarthestX() > getWidth()) {
|
||||
if (horizontalScrollBar == null) {
|
||||
horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
|
||||
horizontalScrollBar.setName(getName() + " horizontal scroll bar");
|
||||
super.addVisual(horizontalScrollBar);
|
||||
horizontalScrollBar.setWidth(1.0f);
|
||||
horizontalScrollBar.setHeight(20);
|
||||
}
|
||||
horizontalScrollBar.setSliderSize((float)getWidth() / getFarthestX());
|
||||
horizontalScrollBar.setLocation(0, getHeight());
|
||||
}
|
||||
|
||||
if(horizontalScrollBar != null) {
|
||||
horizontalScrollBar.setSize(getWidth(), 20);
|
||||
if (getFarthestY() > getHeight()) {
|
||||
if (verticalScrollBar == null) {
|
||||
verticalScrollBar = new Slider(Slider.Direction.Vertical);
|
||||
verticalScrollBar.setName(getName() + " vertical scroll bar");
|
||||
super.addVisual(verticalScrollBar);
|
||||
verticalScrollBar.setHeight(1.0f);
|
||||
verticalScrollBar.setWidth(20);
|
||||
}
|
||||
verticalScrollBar.setSliderSize((float)getHeight() / getFarthestY());
|
||||
verticalScrollBar.setLocation(getWidth(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(verticalScrollBar != null) {
|
||||
verticalScrollBar.setSize(20, getHeight());
|
||||
@Override
|
||||
public void addVisual(Visual v) {
|
||||
if(v.getWidth() + v.getLocationX() > getFarthestX()) {
|
||||
if (v.getWidth() + v.getLocationX() > getWidth()) {
|
||||
if (horizontalScrollBar == null) {
|
||||
horizontalScrollBar = new Slider(Slider.Direction.Horizontal);
|
||||
horizontalScrollBar.setName(getName() + " horizontal scroll bar");
|
||||
horizontalScrollBar.setWidth(1.0f);
|
||||
horizontalScrollBar.setHeight(20);
|
||||
super.addVisual(horizontalScrollBar);
|
||||
}
|
||||
horizontalScrollBar.setSliderSize((float)getWidth() / v.getWidth() + v.getLocationX());
|
||||
}
|
||||
}
|
||||
if(v.getHeight() + v.getLocationY() > getFarthestY()) {
|
||||
if (v.getHeight() + v.getLocationY() > getHeight()) {
|
||||
if (verticalScrollBar == null) {
|
||||
verticalScrollBar = new Slider(Slider.Direction.Vertical);
|
||||
verticalScrollBar.setName(getName() + " vertical scroll bar");
|
||||
verticalScrollBar.setHeight(1.0f);
|
||||
verticalScrollBar.setWidth(20);
|
||||
super.addVisual(verticalScrollBar);
|
||||
}
|
||||
verticalScrollBar.setSliderSize((float)getHeight() / v.getHeight() + v.getLocationY());
|
||||
}
|
||||
}
|
||||
|
||||
super.addVisual(v);
|
||||
children.add(new VisualLocation(v));
|
||||
}
|
||||
|
||||
private int getFarthestX() {
|
||||
int max = 0;
|
||||
for(VisualLocation visualLocation: children) {
|
||||
if(max < visualLocation.v.getWidth() + visualLocation.originalLocation.x) {
|
||||
max = visualLocation.v.getWidth() + visualLocation.originalLocation.x;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private int getFarthestY() {
|
||||
int max = 0;
|
||||
for(VisualLocation visualLocation: children) {
|
||||
if(max < visualLocation.v.getHeight() + visualLocation.originalLocation.y) {
|
||||
max = visualLocation.v.getHeight() + visualLocation.originalLocation.y;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private void setLocations() {
|
||||
for(VisualLocation visualLocation:children) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNotification(int notify) {
|
||||
if(notify == Slider.SLIDER_MOVED) {
|
||||
setLocations();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
g.setColor(getPaintColor());
|
||||
if(getHasBorder()) {
|
||||
g.setColor(getBackgroundColor());
|
||||
g.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
|
||||
g.fillRect(1, 1, getWidth() - 1, getHeight() - 1);
|
||||
g.setColor(getBorderColor());
|
||||
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||
}
|
||||
else {
|
||||
g.setColor(getBackgroundColor());
|
||||
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MouseWheelListener extends MouseAdapter {
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
|
||||
if(mouseWheelEvent.isShiftDown()) {
|
||||
horizontalScrollBar.moveSlider(mouseWheelEvent.getWheelRotation() * 10);
|
||||
return;
|
||||
}
|
||||
verticalScrollBar.moveSlider(mouseWheelEvent.getWheelRotation() * 10);
|
||||
}
|
||||
}
|
||||
|
||||
private static class VisualLocation {
|
||||
Visual v;
|
||||
Point2<Integer> originalLocation;
|
||||
|
||||
public VisualLocation(Visual v) {
|
||||
this.v = v;
|
||||
originalLocation = v.getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Slider extends Visual {
|
||||
public static final int SLIDER_MOVED = 3;
|
||||
|
||||
public enum Direction {
|
||||
Vertical,
|
||||
Horizontal
|
||||
@@ -84,19 +86,33 @@ public class Slider extends Visual {
|
||||
}
|
||||
|
||||
public float getSliderLocation() {
|
||||
int availableSpace;
|
||||
if(direction == Direction.Vertical) {
|
||||
return (float)slider.getLocationY() / getHeight();
|
||||
}
|
||||
else {
|
||||
return (float)slider.getLocationX() / getWidth();
|
||||
availableSpace = getHeight() - button1.getHeight() - slider.getHeight() - button2.getHeight();
|
||||
int sliderY = slider.getLocationY() - button1.getHeight();
|
||||
return (float)sliderY / availableSpace;
|
||||
}
|
||||
availableSpace = getWidth() - button1.getWidth() - slider.getWidth() - button2.getWidth();
|
||||
int sliderX = slider.getLocationX() - button1.getWidth();
|
||||
return (float)sliderX / availableSpace;
|
||||
}
|
||||
|
||||
public void setSliderSize(int width, int height) {
|
||||
slider.setSize(width, height);
|
||||
public float getSliderSize() {
|
||||
if(direction == Direction.Vertical) {
|
||||
return (float)slider.getHeight() / getHeight();
|
||||
}
|
||||
return (float)slider.getWidth() / getWidth();
|
||||
}
|
||||
|
||||
private void moveSlider(int offset) {
|
||||
public void setSliderSize(Float size) {
|
||||
if(direction == Direction.Vertical) {
|
||||
slider.setHeight(Math.round(size * getHeight()));
|
||||
return;
|
||||
}
|
||||
slider.setWidth(Math.round(size * getWidth()));
|
||||
}
|
||||
|
||||
public void moveSlider(Integer offset) {
|
||||
if(direction == Direction.Vertical) {
|
||||
if(slider.getLocationY() + slider.getHeight() + offset > getHeight() - button2.getHeight()) {
|
||||
slider.setLocationY(getHeight() - slider.getHeight() - button2.getHeight());
|
||||
@@ -119,6 +135,7 @@ public class Slider extends Visual {
|
||||
slider.setLocationX(Math.round(slider.getLocationX() + offset));
|
||||
}
|
||||
}
|
||||
notifyParent(SLIDER_MOVED);
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
@@ -143,7 +160,7 @@ public class Slider extends Visual {
|
||||
}
|
||||
}
|
||||
|
||||
private void moveSlider(float offset) {
|
||||
public void moveSlider(Float offset) {
|
||||
if(direction == Direction.Vertical) {
|
||||
moveSlider(Math.round(offset * getHeight()));
|
||||
return;
|
||||
@@ -198,13 +215,13 @@ public class Slider extends Visual {
|
||||
button1.setSize(Math.round(0.7f * getWidth()), Math.round(0.7f * getWidth()));
|
||||
button2.setSize(button1.getWidth(), button1.getHeight());
|
||||
button2.setLocation(0, getHeight() - button2.getHeight());
|
||||
slider.setSize(getWidth() / 2, 40);
|
||||
slider.setWidth(getWidth() / 2);
|
||||
}
|
||||
else {
|
||||
button1.setSize(Math.round(0.7f * getHeight()), Math.round(0.7f * getHeight()));
|
||||
button2.setSize(button1.getWidth(), button1.getHeight());
|
||||
button2.setLocation(getWidth() - button2.getWidth(), 0);
|
||||
slider.setSize(40, getHeight() / 2);
|
||||
slider.setHeight(getHeight() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +235,7 @@ public class Slider extends Visual {
|
||||
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||
}
|
||||
g.setColor(getBackgroundColor());
|
||||
|
||||
if(direction == Direction.Vertical) {
|
||||
int x1 = Math.round(0.15f * getWidth());
|
||||
int y1 = button1.getHeight();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package guiTree.Components;
|
||||
|
||||
import guiTree.Animations.ColorAnimation;
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Visual;
|
||||
import guiTree.events.MouseAdapter;
|
||||
@@ -38,20 +39,31 @@ public class ToggleButton extends Visual {
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
if(pressed) {
|
||||
addAnimation(new ColorAnimation(ToggleButton.this, getForegroundColor(), getAccentColor(), 100));
|
||||
}
|
||||
else {
|
||||
addAnimation(new ColorAnimation(ToggleButton.this, getAccentColor(), getForegroundColor(), 100));
|
||||
}
|
||||
pressed = !pressed;
|
||||
|
||||
Debugger.log("Pressed: " + getName(), Debugger.Tag.LISTENER);
|
||||
Debugger.log("Calling repaint from pressed: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
hovered = true;
|
||||
if(!pressed) {
|
||||
addAnimation(new ColorAnimation(ToggleButton.this, getBackgroundColor(), getAccentColor(), 100));
|
||||
}
|
||||
Debugger.log("Calling repaint from entered: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
hovered = false;
|
||||
if(!pressed) {
|
||||
addAnimation(new ColorAnimation(ToggleButton.this, getAccentColor(), getBackgroundColor(), 100));
|
||||
}
|
||||
Debugger.log("Calling repaint from exited: " + getName(), Debugger.Tag.PAINTING);
|
||||
update();
|
||||
}
|
||||
@@ -67,22 +79,7 @@ public class ToggleButton extends Visual {
|
||||
{
|
||||
//Get Graphics
|
||||
Graphics2D g = imageBuffer.createGraphics();
|
||||
|
||||
//Set Transparency
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
|
||||
//Choose background
|
||||
if(hovered) {
|
||||
g.setColor(this.getAccentColor());
|
||||
}
|
||||
else {
|
||||
g.setColor(this.getBackgroundColor());
|
||||
}
|
||||
if(pressed) {
|
||||
g.setColor(this.getForegroundColor());
|
||||
}
|
||||
g.setColor(getPaintColor());
|
||||
|
||||
//Draw Button
|
||||
if(getHasBorder()) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package guiTree;
|
||||
import guiTree.Helper.Debugger;
|
||||
import guiTree.Helper.Timer;
|
||||
import guiTree.events.KeyEventGetter;
|
||||
import guiTree.events.MouseWheelGetter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -4,8 +4,8 @@ public class Debugger {
|
||||
public enum Tag {
|
||||
LISTENER(false),
|
||||
PAINTING(false),
|
||||
FPS(false),
|
||||
ANIMATIONS(true),
|
||||
FPS(true),
|
||||
ANIMATIONS(false),
|
||||
PARSING(false);
|
||||
|
||||
public boolean value;
|
||||
|
||||
@@ -12,4 +12,9 @@ public class Point2<T> {
|
||||
public boolean equals(Point2<T> point2) {
|
||||
return x == point2.y && y == point2.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point2 x:" + x + " y: " + y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,9 @@ public class Point3<T> {
|
||||
public boolean equals(Point3<T> point3) {
|
||||
return x == point3.x && y == point3.y && z == point3.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point2 x:" + x + " y: " + y + " z: " + z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,9 @@ public class Point4<T> {
|
||||
public boolean equals(Point4<T> point4) {
|
||||
return a == point4.a && b == point4.b && c == point4.c && d == point4.d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Point2 a:" + a + " b: " + b + " c: " + c + " d: " + d;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package guiTree.events;
|
||||
|
||||
import guiTree.Window;
|
||||
package guiTree;
|
||||
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
@@ -14,6 +12,6 @@ public class MouseWheelGetter implements MouseWheelListener {
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
|
||||
|
||||
callingWindow.mouseWheelMoved(mouseWheelEvent);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public class Visual {
|
||||
private Color accentColor;
|
||||
private Color fontColor;
|
||||
private Color borderColor;
|
||||
private Color paintColor;
|
||||
private Boolean active;
|
||||
private Boolean dirty;
|
||||
private static Visual entered;
|
||||
@@ -135,6 +136,22 @@ public class Visual {
|
||||
notifyParent(SIZE_CHANGED);
|
||||
}
|
||||
|
||||
public void setHeight(Integer height) {
|
||||
setSize(getWidth(), height);
|
||||
}
|
||||
|
||||
public void setWidth(Integer width) {
|
||||
setSize(width, getHeight());
|
||||
}
|
||||
|
||||
public void setHeight(Float height) {
|
||||
setSize(relativeWidth, height);
|
||||
}
|
||||
|
||||
public void setWidth(Float width) {
|
||||
setSize(width, relativeHeight);
|
||||
}
|
||||
|
||||
public void setSize(Integer width, Integer height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -188,6 +205,7 @@ public class Visual {
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.paintColor = backgroundColor;
|
||||
propagateDirt();
|
||||
}
|
||||
|
||||
@@ -198,14 +216,22 @@ public class Visual {
|
||||
|
||||
public void setFontColor(Color fontColor) {
|
||||
this.fontColor = fontColor;
|
||||
propagateDirt();
|
||||
}
|
||||
|
||||
public void setAccentColor(Color accentColor) {
|
||||
this.accentColor = accentColor;
|
||||
propagateDirt();
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
propagateDirt();
|
||||
}
|
||||
|
||||
public void setPaintColor(Color paintColor) {
|
||||
this.paintColor = paintColor;
|
||||
propagateDirt();
|
||||
}
|
||||
|
||||
public void setHasBorder(Boolean hasBorder) {
|
||||
@@ -265,6 +291,10 @@ public class Visual {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public Color getPaintColor() {
|
||||
return paintColor;
|
||||
}
|
||||
|
||||
public Boolean getHasBorder() {
|
||||
return hasBorder;
|
||||
}
|
||||
@@ -360,7 +390,6 @@ public class Visual {
|
||||
if(!(this instanceof Window)){
|
||||
long time = timer.stopTiming();
|
||||
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
|
||||
parent.revalidate();
|
||||
return;
|
||||
}
|
||||
Window window = (Window)this;
|
||||
@@ -512,8 +541,8 @@ public class Visual {
|
||||
}
|
||||
|
||||
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
|
||||
if(focused) {
|
||||
for(MouseWheelListener mouseWheelListener: mouseWheelListeners) {
|
||||
if(entered.focused) {
|
||||
for(MouseWheelListener mouseWheelListener: entered.mouseWheelListeners) {
|
||||
mouseWheelListener.mouseWheelMoved(mouseWheelEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class XAMLParser {
|
||||
}
|
||||
for(Method method: methods){
|
||||
Class<?>[] types = method.getParameterTypes();
|
||||
if(types.length == values.size()) {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
try {
|
||||
primitiveAttributes.add(valueConverter.objectCreatorFactory(types[i], values.get(i)));
|
||||
@@ -106,6 +107,7 @@ public class XAMLParser {
|
||||
return primitiveAttributes;
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("Could not find method " + methodName + " with parameters " + values);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user