mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
bugs
added checkbox lists
This commit is contained in:
BIN
resources/icons/check_black.png
Normal file
BIN
resources/icons/check_black.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 127 B |
BIN
resources/icons/check_white.png
Normal file
BIN
resources/icons/check_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 133 B |
@@ -4,35 +4,60 @@
|
|||||||
Visible="true"
|
Visible="true"
|
||||||
Size="640, 480"
|
Size="640, 480"
|
||||||
Title="FANTASTICEST UI THINGY">
|
Title="FANTASTICEST UI THINGY">
|
||||||
<Button
|
<!-- <Panel-->
|
||||||
Name="button1"
|
<!-- Name="ProgramPanel"-->
|
||||||
BackgroundColor="#999999"
|
<!-- Size="1.0, 1.0"-->
|
||||||
AccentColor="#666666"
|
<!-- Location="0.0, 0.0"-->
|
||||||
ForegroundColor="#333333"
|
<!-- BackgroundColor="#333333">-->
|
||||||
Size="0.5, 0.5"
|
<!-- <Button-->
|
||||||
Location="0.0, 0.0"
|
<!-- Name="button1"-->
|
||||||
HasBorder="true"
|
<!-- BackgroundColor="#999999"-->
|
||||||
Label="button1">
|
<!-- AccentColor="#666666"-->
|
||||||
<Button
|
<!-- ForegroundColor="#333333"-->
|
||||||
Name="button4"
|
<!-- Size="0.5, 0.5"-->
|
||||||
BackgroundColor="#009999"
|
<!-- Location="0.0, 0.0"-->
|
||||||
AccentColor="#006666"
|
<!-- HasBorder="true"-->
|
||||||
ForegroundColor="#003333"
|
<!-- Label="button1">-->
|
||||||
Size="0.5, 0.5"
|
<!-- <Button-->
|
||||||
Location="0.25, 0.25"
|
<!-- Name="button4"-->
|
||||||
Icon="square_white"
|
<!-- BackgroundColor="#009999"-->
|
||||||
HasBorder="true">
|
<!-- AccentColor="#006666"-->
|
||||||
<Button
|
<!-- ForegroundColor="#003333"-->
|
||||||
Name="button2"
|
<!-- Size="0.5, 0.5"-->
|
||||||
BackgroundColor="#000099"
|
<!-- Location="0.25, 0.25"-->
|
||||||
AccentColor="#000066"
|
<!-- Icon="square_white"-->
|
||||||
ForegroundColor="#000033"
|
<!-- HasBorder="true">-->
|
||||||
Size="0.5, 0.5"
|
<!-- <ToggleButton-->
|
||||||
Location="0.25, 0.25"
|
<!-- Name="button2"-->
|
||||||
Label="button2"/>
|
<!-- BackgroundColor="#000099"-->
|
||||||
</Button>
|
<!-- AccentColor="#000066"-->
|
||||||
</Button>
|
<!-- ForegroundColor="#000033"-->
|
||||||
<Button Name="button6" BackgroundColor="#555555" Location="0.5, 0.5" Size="0.5, 0.5"/>
|
<!-- Size="0.5, 0.5"-->
|
||||||
<Button Name="button3" BackgroundColor="#009900" Size="0.5, 0.5" Location="0.0, 0.5" Icon="close_black"/>
|
<!-- Location="0.25, 0.25"-->
|
||||||
<Button Name="button3" BackgroundColor="#123456" Size="0.5, 0.5" Location="0.5, 0.0" Icon="minimize_white"/>
|
<!-- 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.5"
|
||||||
|
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"/>
|
||||||
|
<!-- </Panel>-->
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import guiTree.Components.Button;
|
import guiTree.Components.Button;
|
||||||
|
import guiTree.Components.CheckBox;
|
||||||
|
import guiTree.Components.ToggleButton;
|
||||||
import guiTree.Window;
|
import guiTree.Window;
|
||||||
import guiTree.events.MouseAdapter;
|
import guiTree.events.MouseAdapter;
|
||||||
import parser.XAMLParser;
|
import parser.XAMLParser;
|
||||||
@@ -11,29 +13,31 @@ public class Main {
|
|||||||
Window window = XAMLParser.parse("ui.xml");
|
Window window = XAMLParser.parse("ui.xml");
|
||||||
assert window != null;
|
assert window != null;
|
||||||
|
|
||||||
Button button1 = (Button)window.findByName("button1");
|
// Button button1 = (Button)window.findByName("button1");
|
||||||
button1.addMouseListener(new MouseAdapter() {
|
// button1.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void mouseClicked(MouseEvent mouseEvent) {
|
// public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
|
// System.out.println("Button x: " + button1.getLocationX() + " y: " + button1.getLocationY());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
Button button2 = (Button)window.findByName("button2");
|
// ToggleButton button2 = (ToggleButton)window.findByName("button2");
|
||||||
button2.addMouseListener(new MouseAdapter() {
|
// button2.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void mouseClicked(MouseEvent mouseEvent) {
|
// public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
System.out.println("Button x: " + button2.getLocationX() + " y: " + button2.getLocationY());
|
// System.out.println("Button x: " + button2.getLocationX() + " y: " + button2.getLocationY());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
Button button4 = (Button)window.findByName("button4");
|
// Button button4 = (Button)window.findByName("button4");
|
||||||
button4.addMouseListener(new MouseAdapter() {
|
// button4.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
// @Override
|
||||||
public void mouseClicked(MouseEvent mouseEvent) {
|
// public void mouseClicked(MouseEvent mouseEvent) {
|
||||||
System.out.println("Button x: " + button4.getLocationX() + " y: " + button4.getLocationY());
|
// System.out.println("Button x: " + button4.getLocationX() + " y: " + button4.getLocationY());
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
CheckBox checkBox = (CheckBox)window.findByName("checkbox");
|
||||||
|
window.repaint();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ public class BooleanConverter implements ConverterInterface<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean convert(String content) {
|
public Boolean convert(String content) {
|
||||||
|
content = content.replaceAll(" ", "");
|
||||||
return Boolean.valueOf(content);
|
return Boolean.valueOf(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.awt.*;
|
|||||||
public class ColorConverter implements ConverterInterface<Color> {
|
public class ColorConverter implements ConverterInterface<Color> {
|
||||||
@Override
|
@Override
|
||||||
public Color convert(String content) {
|
public Color convert(String content) {
|
||||||
|
content = content.replaceAll(" ", "");
|
||||||
return Color.decode(content);
|
return Color.decode(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ public class DoubleConverter implements ConverterInterface<Double>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double convert(String content) {
|
public Double convert(String content) {
|
||||||
|
content = content.replaceAll(" ", "");
|
||||||
return Double.parseDouble(content);
|
return Double.parseDouble(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public class FloatConverter implements ConverterInterface<Float> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float convert(String content) throws InvalidTypeException {
|
public Float convert(String content) throws InvalidTypeException {
|
||||||
|
content = content.replaceAll(" ", "");
|
||||||
float number = Float.parseFloat(content);
|
float number = Float.parseFloat(content);
|
||||||
if(number > 1 || number < 0) {
|
if(number > 1 || number < 0) {
|
||||||
throw new InvalidTypeException();
|
throw new InvalidTypeException();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ public class IntegerConverter implements ConverterInterface<Integer> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer convert(String content) {
|
public Integer convert(String content) {
|
||||||
|
content = content.replaceAll(" ", "");
|
||||||
return Integer.parseInt(content);
|
return Integer.parseInt(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package guiTree.Components;
|
|||||||
|
|
||||||
import guiTree.Helper.Debugger;
|
import guiTree.Helper.Debugger;
|
||||||
import guiTree.Helper.Tag;
|
import guiTree.Helper.Tag;
|
||||||
import guiTree.Helper.Timer;
|
|
||||||
import guiTree.Visual;
|
import guiTree.Visual;
|
||||||
import guiTree.events.MouseAdapter;
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
@@ -111,6 +110,9 @@ public class Button extends Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Draw Label
|
//Draw Label
|
||||||
|
if(getFont() != null) {
|
||||||
|
g.setFont(getFont());
|
||||||
|
}
|
||||||
g.setColor(this.getFontColor());
|
g.setColor(this.getFontColor());
|
||||||
int textWidth = 0;
|
int textWidth = 0;
|
||||||
int textHeight = 0;
|
int textHeight = 0;
|
||||||
|
|||||||
134
src/guiTree/Components/CheckBox.java
Normal file
134
src/guiTree/Components/CheckBox.java
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Helper.Debugger;
|
||||||
|
import guiTree.Helper.Tag;
|
||||||
|
import guiTree.Visual;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CheckBox extends Visual {
|
||||||
|
private BufferedImage icon;
|
||||||
|
private boolean hovered;
|
||||||
|
private boolean marked;
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
public CheckBox() {
|
||||||
|
this(false, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox(Boolean marked) {
|
||||||
|
this(marked, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox(String text) {
|
||||||
|
this(false, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBox(Boolean value, String text) {
|
||||||
|
super();
|
||||||
|
this.marked = value;
|
||||||
|
this.text = text;
|
||||||
|
setAccentColor(new Color(0.6f, 0.6f, 0.6f, 0.5f));
|
||||||
|
this.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
marked = !marked;
|
||||||
|
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent mouseEvent) {
|
||||||
|
hovered = true;
|
||||||
|
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
|
hovered = false;
|
||||||
|
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
|
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMarked() {
|
||||||
|
return marked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarked(boolean marked) {
|
||||||
|
this.marked = marked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(BufferedImage icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String url) {
|
||||||
|
try{
|
||||||
|
icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
|
||||||
|
if(hovered && !marked) {
|
||||||
|
g.setColor(getAccentColor());
|
||||||
|
g.fillRect(0, 0, getHeight() - 1, getHeight() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(marked) {
|
||||||
|
g.setColor(getForegroundColor());
|
||||||
|
g.fillRect(1, 1, getHeight() - 2, getHeight() - 2);
|
||||||
|
|
||||||
|
if(icon != null) {
|
||||||
|
int iconWidth = icon.getWidth();
|
||||||
|
int iconHeight = icon.getHeight();
|
||||||
|
|
||||||
|
int iconX = (this.getHeight() - iconWidth) / 2;
|
||||||
|
int iconY = (this.getHeight() - iconHeight) / 2;
|
||||||
|
Graphics2D g2 = imageBuffer.createGraphics();
|
||||||
|
g2.drawImage(icon, iconX, iconY, null);
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(getFontColor());
|
||||||
|
if(getFont() != null) {
|
||||||
|
g.setFont(getFont());
|
||||||
|
}
|
||||||
|
int textHeight = g.getFontMetrics().getHeight();
|
||||||
|
g.drawString(text, getHeight() + 10, getHeight() / 2 + textHeight / 4);
|
||||||
|
|
||||||
|
g.setColor(getBorderColor());
|
||||||
|
g.drawRect(0, 0, getHeight() - 1, getHeight() - 1);
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
151
src/guiTree/Components/CheckBoxList.java
Normal file
151
src/guiTree/Components/CheckBoxList.java
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Helper.Point2d;
|
||||||
|
import guiTree.Visual;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CheckBoxList extends Visual {
|
||||||
|
private List<CheckBox> checkBoxList;
|
||||||
|
int spacing;
|
||||||
|
private BufferedImage icon;
|
||||||
|
private Point2d checkBoxSize;
|
||||||
|
|
||||||
|
public CheckBoxList() {
|
||||||
|
this(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckBoxList(int spacing) {
|
||||||
|
checkBoxList = new ArrayList<>();
|
||||||
|
this.spacing = spacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addVisual(Visual v) {
|
||||||
|
if(!(v instanceof CheckBox)) {
|
||||||
|
System.out.println("Trying to insert into checkbox list something different from checkbox");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CheckBox checkbox = (CheckBox)v;
|
||||||
|
if(checkBoxList.size() == 0) {
|
||||||
|
checkbox.setLocation(0, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
checkbox.setLocation(0, checkBoxList.get(checkBoxList.size() - 1).getLocationY() + spacing);
|
||||||
|
}
|
||||||
|
if(icon != null) {
|
||||||
|
checkbox.setIcon(icon);
|
||||||
|
}
|
||||||
|
if(checkBoxSize != null) {
|
||||||
|
checkbox.setSize(checkBoxSize.x, checkBoxSize.y);
|
||||||
|
}
|
||||||
|
checkbox.setForegroundColor(getForegroundColor());
|
||||||
|
checkbox.setBackgroundColor(getBackgroundColor());
|
||||||
|
checkbox.setAccentColor(getAccentColor());
|
||||||
|
checkbox.setFontColor(getFontColor());
|
||||||
|
checkBoxList.add(checkbox);
|
||||||
|
super.addVisual(checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeVisual(Visual v) {
|
||||||
|
if(v instanceof CheckBox) {
|
||||||
|
checkBoxList.remove(v);
|
||||||
|
super.removeVisual(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(BufferedImage icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setIcon(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String url) {
|
||||||
|
try {
|
||||||
|
icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setIcon(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckBoxSize(Integer width, Integer height) {
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setSize(width, height);
|
||||||
|
}
|
||||||
|
checkBoxSize = new Point2d(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFont(Font font) {
|
||||||
|
super.setFont(font);
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setFont(font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBackgroundColor(Color backgroundColor) {
|
||||||
|
super.setBackgroundColor(backgroundColor);
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setBackgroundColor(backgroundColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setForegroundColor(Color foregroundColor) {
|
||||||
|
super.setForegroundColor(foregroundColor);
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setForegroundColor(foregroundColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFontColor(Color fontColor) {
|
||||||
|
super.setFontColor(fontColor);
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setFontColor(fontColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAccentColor(Color accentColor) {
|
||||||
|
super.setAccentColor(accentColor);
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setAccentColor(accentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpacing(Integer spacing) {
|
||||||
|
this.spacing = spacing;
|
||||||
|
if(checkBoxList == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int offsetY = 0;
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
cb.setLocationY(offsetY);
|
||||||
|
offsetY += spacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CheckBox> getActiveBoxes() {
|
||||||
|
List<CheckBox> markedBoxes = new ArrayList<>();
|
||||||
|
for(CheckBox cb: checkBoxList) {
|
||||||
|
if(cb.isMarked()) {
|
||||||
|
markedBoxes.add(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return markedBoxes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,6 +124,7 @@ public class TitleBar extends Visual {
|
|||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -142,6 +143,9 @@ public class TitleBar extends Visual {
|
|||||||
iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null);
|
iconGraphics.drawImage(icon, 5, (getHeight() - icon.getHeight())/2, null);
|
||||||
iconGraphics.dispose();
|
iconGraphics.dispose();
|
||||||
|
|
||||||
|
if(getFont() != null) {
|
||||||
|
g.setFont(getFont());
|
||||||
|
}
|
||||||
int stringOffset = icon.getWidth() + 10;
|
int stringOffset = icon.getWidth() + 10;
|
||||||
int textHeight = 0;
|
int textHeight = 0;
|
||||||
if(!title.equals("")) {
|
if(!title.equals("")) {
|
||||||
|
|||||||
159
src/guiTree/Components/ToggleButton.java
Normal file
159
src/guiTree/Components/ToggleButton.java
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Helper.Debugger;
|
||||||
|
import guiTree.Helper.Tag;
|
||||||
|
import guiTree.Visual;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ToggleButton extends Visual {
|
||||||
|
private String label;
|
||||||
|
private Boolean pressed;
|
||||||
|
private Boolean hovered;
|
||||||
|
private BufferedImage icon;
|
||||||
|
|
||||||
|
public ToggleButton() {
|
||||||
|
this("", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButton(String label) {
|
||||||
|
this(label, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButton(BufferedImage icon) {
|
||||||
|
this(null, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButton(String label, BufferedImage icon) {
|
||||||
|
super();
|
||||||
|
this.label = label;
|
||||||
|
this.icon = icon;
|
||||||
|
pressed = false;
|
||||||
|
hovered = false;
|
||||||
|
this.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
pressed = !pressed;
|
||||||
|
Debugger.log("Pressed: " + getName(), Tag.LISTENER);
|
||||||
|
Debugger.log("Calling repaint from pressed: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent mouseEvent) {
|
||||||
|
hovered = true;
|
||||||
|
Debugger.log("Calling repaint from entered: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
|
hovered = false;
|
||||||
|
Debugger.log("Calling repaint from exited: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
|
Debugger.log("Calling repaint from moved: " + getName(), Tag.PAINTING);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(BufferedImage imageBuffer)
|
||||||
|
{
|
||||||
|
//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());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw Button
|
||||||
|
if(getHasBorder()) {
|
||||||
|
g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2);
|
||||||
|
g.setColor(getBorderColor());
|
||||||
|
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw Label
|
||||||
|
if(getFont() != null) {
|
||||||
|
g.setFont(getFont());
|
||||||
|
}
|
||||||
|
g.setColor(this.getFontColor());
|
||||||
|
int textWidth = 0;
|
||||||
|
int textHeight = 0;
|
||||||
|
if(!label.equals("")) {
|
||||||
|
textWidth = g.getFontMetrics().stringWidth(label);
|
||||||
|
textHeight = g.getFontMetrics().getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.drawString(this.label, (this.getWidth() - textWidth)/2, (this.getHeight() + textHeight)/2);
|
||||||
|
|
||||||
|
//Draw Icon
|
||||||
|
if(icon != null) {
|
||||||
|
int iconWidth = icon.getWidth();
|
||||||
|
int iconHeight = icon.getHeight();
|
||||||
|
|
||||||
|
int iconX = (this.getWidth() - iconWidth - textWidth) / 2;
|
||||||
|
int iconY = (this.getHeight() - iconHeight - textHeight) / 2;
|
||||||
|
Graphics2D g2 = imageBuffer.createGraphics();
|
||||||
|
g2.drawImage(icon, iconX, iconY, null);
|
||||||
|
g2.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return this.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(BufferedImage icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String url) {
|
||||||
|
try{
|
||||||
|
icon = ImageIO.read(new File("resources\\icons\\" + url + ".png"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BufferedImage getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPressed(Boolean pressed) {
|
||||||
|
this.pressed = pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getPressed() {
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package guiTree.Helper;
|
package guiTree.Helper;
|
||||||
|
|
||||||
public enum Tag {
|
public enum Tag {
|
||||||
LISTENER(false),
|
LISTENER(true),
|
||||||
PAINTING(false);
|
PAINTING(false);
|
||||||
|
|
||||||
public boolean value;
|
public boolean value;
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public class Visual {
|
|||||||
private Integer absoluteY;
|
private Integer absoluteY;
|
||||||
private Float relativeX;
|
private Float relativeX;
|
||||||
private Float relativeY;
|
private Float relativeY;
|
||||||
|
private Boolean hasBorder;
|
||||||
|
private Font font;
|
||||||
private Color backgroundColor;
|
private Color backgroundColor;
|
||||||
private Color foregroundColor;
|
private Color foregroundColor;
|
||||||
private Color accentColor;
|
private Color accentColor;
|
||||||
@@ -57,7 +59,6 @@ public class Visual {
|
|||||||
public Boolean dirty;
|
public Boolean dirty;
|
||||||
private static Visual entered;
|
private static Visual entered;
|
||||||
private Boolean focused;
|
private Boolean focused;
|
||||||
private Boolean hasBorder;
|
|
||||||
private Boolean pressed;
|
private Boolean pressed;
|
||||||
|
|
||||||
|
|
||||||
@@ -109,7 +110,7 @@ public class Visual {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSize() {
|
public void setSize() {
|
||||||
if(parent != null) {
|
if(parent != null) {
|
||||||
if(relativeWidth > 0.0) {
|
if(relativeWidth > 0.0) {
|
||||||
width = Math.round(relativeWidth * parent.width);
|
width = Math.round(relativeWidth * parent.width);
|
||||||
@@ -180,6 +181,10 @@ public class Visual {
|
|||||||
this.locationY = y;
|
this.locationY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFont(Font font) {
|
||||||
|
this.font = font;
|
||||||
|
}
|
||||||
|
|
||||||
public void setBackgroundColor(Color backgroundColor) {
|
public void setBackgroundColor(Color backgroundColor) {
|
||||||
this.backgroundColor = backgroundColor;
|
this.backgroundColor = backgroundColor;
|
||||||
propagateDirt();
|
propagateDirt();
|
||||||
@@ -230,6 +235,10 @@ public class Visual {
|
|||||||
return this.locationY;
|
return this.locationY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Font getFont() {
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
public Color getBackgroundColor() {
|
public Color getBackgroundColor() {
|
||||||
return backgroundColor;
|
return backgroundColor;
|
||||||
}
|
}
|
||||||
@@ -339,8 +348,11 @@ public class Visual {
|
|||||||
window.revalidate();
|
window.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(BufferedImage imageBuffer) {
|
public void update() {
|
||||||
|
propagateDirt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(BufferedImage imageBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -508,8 +520,12 @@ public class Visual {
|
|||||||
if(imageBuffer == null) {
|
if(imageBuffer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Graphics g = this.imageBuffer.getGraphics();
|
Graphics2D g = this.imageBuffer.createGraphics();
|
||||||
g.setColor(backgroundColor);
|
|
||||||
|
g.setComposite(AlphaComposite.Clear);
|
||||||
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
g.setComposite(AlphaComposite.Src);
|
||||||
|
|
||||||
g.fillRect(0, 0, width, height);
|
g.fillRect(0, 0, width, height);
|
||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class XAMLParser {
|
|||||||
List<Object> primitiveAttributes = new ArrayList<>();
|
List<Object> primitiveAttributes = new ArrayList<>();
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
|
|
||||||
value = value.replaceAll(" ", "");
|
// value = value.replaceAll(" ", "");
|
||||||
while (value.contains(",")) {
|
while (value.contains(",")) {
|
||||||
values.add(value.substring(0, value.indexOf(',')));
|
values.add(value.substring(0, value.indexOf(',')));
|
||||||
value = value.substring(value.indexOf(',') + 1);
|
value = value.substring(value.indexOf(',') + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user