added gif for readme

This commit is contained in:
Macocian Adrian Radu
2022-05-18 15:20:05 +02:00
parent 0d6716e528
commit 6199c541c3
20 changed files with 302 additions and 121 deletions

BIN
resources/jistdemo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 MiB

View File

@@ -1,6 +1,6 @@
<?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"/>
<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"/>
</Window>
</Window >

3
src/META-INF/MANIFEST.MF Normal file
View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Main

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class LocationPlacerFactory {
private static Map<String, Placer> placerMap;
private static Map<String, Class<?>> 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);
}
}

View File

@@ -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<Integer> closedSize;
private Point2<Integer> 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();

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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();
// }

View File

@@ -14,6 +14,12 @@ import java.awt.event.MouseEvent;
public class ScrollPanel extends Visual {
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 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,18 +159,10 @@ 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) {
public boolean isInside(int x, int y) {
if(verticalScrollBar != null) {
if (mouseEvent.getX() > getWidth() - verticalScrollBar.getWidth() && mouseEvent.getY() > verticalScrollBar.getLocationY() && mouseEvent.getY() < verticalScrollBar.getHeight()) {
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);
@@ -167,7 +180,7 @@ public class ScrollPanel extends Visual {
}
if(horizontalScrollBar != null) {
if (mouseEvent.getY() > getHeight() - horizontalScrollBar.getHeight() && mouseEvent.getX() > horizontalScrollBar.getLocationX() && mouseEvent.getX() < horizontalScrollBar.getWidth()) {
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);
@@ -183,7 +196,7 @@ public class ScrollPanel extends Visual {
}
}
}
}
return super.isInside(x, y);
}
private class MouseWheelListener extends MouseAdapter {

View File

@@ -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));
}

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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);
}
}

View File

@@ -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<MouseListener> mouseListeners;
private List<MouseWheelListener> mouseWheelListeners;
private List<KeyListener> keyListeners;
private static List<AnimationInterface> 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
---------------------------------------------------------------------*/

View File

@@ -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<Integer> oldSize;
private List<AnimationInterface> animations;
private Boolean close;
private Point2<Integer> 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 ++;

View File

@@ -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<Object> convertStringToPrimitives(String value, List<Method> methods){

View File

@@ -6,6 +6,12 @@ public class ColorConverter implements ConverterInterface<Color> {
@Override
public Color convert(String content) {
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);
}