mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 21:50:04 +00:00
added merge tu grid Panel
moved borders to external components added text field for one line with select
This commit is contained in:
@@ -4,4 +4,24 @@
|
|||||||
Visible="True"
|
Visible="True"
|
||||||
Title="Sudoku 1.0"
|
Title="Sudoku 1.0"
|
||||||
Size="1024, 576">
|
Size="1024, 576">
|
||||||
|
<GridPanel
|
||||||
|
BackgroundColor="#75ff75"
|
||||||
|
Size="1.0f, 1.0f"
|
||||||
|
Name="Main Grid">
|
||||||
|
<Text
|
||||||
|
Text="Ioana"
|
||||||
|
Name="Text"
|
||||||
|
Row="0"
|
||||||
|
Column="0"/>
|
||||||
|
<Panel
|
||||||
|
BackgroundColor="#555555"
|
||||||
|
Name="Panel"
|
||||||
|
Row="0"
|
||||||
|
Column="1">
|
||||||
|
<Border
|
||||||
|
Thickness="10"
|
||||||
|
Color="#ff0000"/>
|
||||||
|
</Panel>
|
||||||
|
</GridPanel>
|
||||||
|
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
import guiTree.Components.ScrollPanel;
|
|
||||||
import guiTree.Window;
|
import guiTree.Window;
|
||||||
import parser.XAMLParser;
|
import parser.XAMLParser;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try{
|
Window window = null;
|
||||||
Window window = XAMLParser.parse("ui.xml");
|
try {
|
||||||
assert window != null;
|
window = XAMLParser.parse("ui.xml");
|
||||||
ScrollPanel scrollPanel = (ScrollPanel)window.findByName("ScrollPane");
|
} catch (Exception e) {
|
||||||
System.out.println();
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
0
src/Sudoku/Layout
Normal file
0
src/Sudoku/Layout
Normal file
37
src/Sudoku/SudokuButton.java
Normal file
37
src/Sudoku/SudokuButton.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package Sudoku;
|
||||||
|
|
||||||
|
import guiTree.Animations.ColorAnimation;
|
||||||
|
import guiTree.Components.ToggleButton;
|
||||||
|
import guiTree.events.KeyAdapter;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
public class SudokuButton extends ToggleButton {
|
||||||
|
private int number;
|
||||||
|
private boolean entered;
|
||||||
|
private boolean fixed;
|
||||||
|
private boolean toggle;
|
||||||
|
|
||||||
|
public SudokuButton(Boolean fixed) {
|
||||||
|
super();
|
||||||
|
this.fixed = fixed;
|
||||||
|
if(!fixed) {
|
||||||
|
addKeyListener(new SudokuKeyListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SudokuKeyListener extends KeyAdapter {
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent keyEvent) {
|
||||||
|
if(keyEvent.getKeyCode() >= 48 && keyEvent.getKeyCode() <= 57) {
|
||||||
|
setLabel(String.valueOf(keyEvent.getKeyCode() - 48));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addAnimation(new ColorAnimation(SudokuButton.this, Color.RED, getBackgroundColor(), 100));
|
||||||
|
}
|
||||||
|
setPressed(false);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/Sudoku/SudokuLayout.java
Normal file
28
src/Sudoku/SudokuLayout.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package Sudoku;
|
||||||
|
|
||||||
|
public class SudokuLayout {
|
||||||
|
public static String grid1 = "----3--67";
|
||||||
|
public static String grid2 = "-------35";
|
||||||
|
public static String grid3 = "---16---4";
|
||||||
|
public static String grid4 = "6-8-9---2";
|
||||||
|
public static String grid5 = "12--8--79";
|
||||||
|
public static String grid6 = "9---3-8-6";
|
||||||
|
public static String grid7 = "8---26---";
|
||||||
|
public static String grid8 = "69-------";
|
||||||
|
public static String grid9 = "35--9----";
|
||||||
|
|
||||||
|
public static String getGrid(int nr) {
|
||||||
|
switch(nr) {
|
||||||
|
case 1: return grid1;
|
||||||
|
case 2: return grid2;
|
||||||
|
case 3: return grid3;
|
||||||
|
case 4: return grid4;
|
||||||
|
case 5: return grid5;
|
||||||
|
case 6: return grid6;
|
||||||
|
case 7: return grid7;
|
||||||
|
case 8: return grid8;
|
||||||
|
case 9: return grid9;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/guiTree/Components/Border.java
Normal file
48
src/guiTree/Components/Border.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Visual;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class Border extends Visual {
|
||||||
|
private int thickness;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
public Border() {
|
||||||
|
this(1, Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Border(int thickness) {
|
||||||
|
this(thickness, Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Border(Color color) {
|
||||||
|
this(1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Border(int thickness, Color color) {
|
||||||
|
super();
|
||||||
|
this.thickness = thickness;
|
||||||
|
this.color = color;
|
||||||
|
setSize(1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThickness(Integer thickness) {
|
||||||
|
this.thickness = thickness;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(BufferedImage imageBuffer) {
|
||||||
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
|
|
||||||
|
g.setColor(color);
|
||||||
|
g.setStroke(new BasicStroke(thickness));
|
||||||
|
g.drawRect(0, 0, getWidth(), getHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,14 +82,7 @@ public class Button extends Visual {
|
|||||||
g.setColor(getPaintColor());
|
g.setColor(getPaintColor());
|
||||||
|
|
||||||
//Draw Button
|
//Draw Button
|
||||||
if(getHasBorder()) {
|
g.fillRoundRect(0, 0, getWidth(), getHeight(), round, round);
|
||||||
g.fillRoundRect(1, 1, getWidth() - 1, getHeight() - 1, round, round);
|
|
||||||
g.setColor(getBorderColor());
|
|
||||||
g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, round, round);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g.fillRoundRect(0, 0, getWidth(), getHeight(), round, round);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Draw Label
|
//Draw Label
|
||||||
if(getFont() != null) {
|
if(getFont() != null) {
|
||||||
|
|||||||
@@ -128,8 +128,6 @@ public class CheckBox extends Visual {
|
|||||||
int textHeight = g.getFontMetrics().getHeight();
|
int textHeight = g.getFontMetrics().getHeight();
|
||||||
g.drawString(text, getHeight() + 10, getHeight() / 2 + textHeight / 4);
|
g.drawString(text, getHeight() + 10, getHeight() / 2 + textHeight / 4);
|
||||||
|
|
||||||
g.setColor(getBorderColor());
|
|
||||||
g.drawRect(0, 0, getHeight() - 1, getHeight() - 1);
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,46 +6,27 @@ import java.awt.*;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import guiTree.Helper.Point2;
|
import guiTree.Helper.Point2;
|
||||||
|
|
||||||
public class GridPanel extends Visual {
|
public class GridPanel extends Visual {
|
||||||
private int columnCount;
|
private Map<Visual, Point2<Integer>>children;
|
||||||
private int rowsCount;
|
private Map<Integer, Integer> fixedRows;
|
||||||
private Map<Integer, List<Visual>> childrenCols;
|
private Map<Integer, Integer> fixedColumns;
|
||||||
private Map<Integer, List<Visual>> childrenRows;
|
private List<Integer> rowSizes;
|
||||||
private Map<Integer, Integer> rowSizes;
|
private List<Integer> columnSizes;
|
||||||
private Map<Integer, Integer> columnSizes;
|
|
||||||
private Map<Point2<Integer>, Integer> rowPadding;
|
private Map<Point2<Integer>, Integer> rowPadding;
|
||||||
private Map<Point2<Integer>, Integer> columnPadding;
|
private Map<Point2<Integer>, Integer> columnPadding;
|
||||||
|
|
||||||
public GridPanel(){
|
public GridPanel(){
|
||||||
super();
|
super();
|
||||||
childrenCols = new TreeMap<>();
|
children = new HashMap<>();
|
||||||
childrenRows = new TreeMap<>();
|
rowSizes = new ArrayList<>();
|
||||||
rowsCount = 0;
|
columnSizes = new ArrayList<>();
|
||||||
columnCount = 0;
|
|
||||||
rowSizes = new HashMap<>();
|
|
||||||
columnSizes = new HashMap<>();
|
|
||||||
rowPadding = new HashMap<>();
|
rowPadding = new HashMap<>();
|
||||||
columnPadding = new HashMap<>();
|
columnPadding = new HashMap<>();
|
||||||
}
|
fixedRows = new HashMap<>();
|
||||||
|
fixedColumns = new HashMap<>();
|
||||||
private void refresh() {
|
|
||||||
rowsCount = 0;
|
|
||||||
columnCount = 0;
|
|
||||||
for(int i: childrenRows.keySet()) {
|
|
||||||
if(childrenRows.get(i).size() != 0 && !rowSizes.containsKey(i)) {
|
|
||||||
rowsCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i: childrenCols.keySet()) {
|
|
||||||
if(childrenCols.get(i).size() != 0 && !columnSizes.containsKey(i)) {
|
|
||||||
columnCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize() {
|
public void setSize() {
|
||||||
@@ -53,71 +34,132 @@ public class GridPanel extends Visual {
|
|||||||
updateSize();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateSize() {
|
private void updateSize() {
|
||||||
if(rowsCount == 0 && columnCount == 0) {
|
if(rowSizes.size() == 0 && columnSizes.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setHeights = 0;
|
int setHeights = 0;
|
||||||
int setWidths = 0;
|
int setWidths = 0;
|
||||||
for(int i: rowSizes.keySet()) {
|
for(int i: fixedRows.keySet()) {
|
||||||
setHeights += rowSizes.get(i);
|
rowSizes.set(i, fixedRows.get(i));
|
||||||
|
setHeights += fixedRows.get(i);
|
||||||
}
|
}
|
||||||
for(int i: columnSizes.keySet()) {
|
for(int i: fixedColumns.keySet()) {
|
||||||
setWidths += columnSizes.get(i);
|
columnSizes.set(i, fixedColumns.get(i));
|
||||||
|
setWidths += fixedColumns.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int height = (getHeight() - setHeights) / rowsCount;
|
int height = 0;
|
||||||
int width = (getWidth() - setWidths) / columnCount;
|
int width = 0;
|
||||||
|
if(fixedRows.size() != rowSizes.size()) {
|
||||||
|
height = (getHeight() - setHeights) / (rowSizes.size() - fixedRows.size());
|
||||||
|
}
|
||||||
|
if(fixedColumns.size() != columnSizes.size()) {
|
||||||
|
width = (getWidth() - setWidths) / (columnSizes.size() - fixedColumns.size());
|
||||||
|
}
|
||||||
|
|
||||||
int locationY = 0;
|
for(int i = 0; i < rowSizes.size(); i++) {
|
||||||
for(int i: childrenRows.keySet()) {
|
if(!fixedRows.containsKey(i)) {
|
||||||
int actualHeight = rowSizes.getOrDefault(i, height);
|
rowSizes.set(i, height);
|
||||||
for(Visual v: childrenRows.get(i)) {
|
|
||||||
|
|
||||||
v.setHeight(actualHeight);
|
|
||||||
v.setLocationY(locationY);
|
|
||||||
}
|
}
|
||||||
locationY += actualHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int locationX = 0;
|
for(int i = 0; i < columnSizes.size(); i++) {
|
||||||
for(int i: childrenCols.keySet()) {
|
if(!fixedColumns.containsKey(i)) {
|
||||||
int actualWidth = columnSizes.getOrDefault(i, width);
|
columnSizes.set(i, width);
|
||||||
for(Visual v: childrenCols.get(i)) {
|
|
||||||
v.setWidth(actualWidth);
|
|
||||||
v.setLocationX(locationX);
|
|
||||||
}
|
}
|
||||||
locationX += actualWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Visual v : children.keySet()) {
|
||||||
|
Point2<Integer> cell = children.get(v);
|
||||||
|
Point2<Integer> location = getGridLocation(cell);
|
||||||
|
v.setLocation(location.x, location.y);
|
||||||
|
int cellWidth = columnSizes.get(cell.x);
|
||||||
|
int cellHeight = rowSizes.get(cell.y);
|
||||||
|
int rowPad = rowPadding.getOrDefault(cell, 0);
|
||||||
|
int colPad = columnPadding.getOrDefault(cell, 0);
|
||||||
|
|
||||||
|
for(int i = 0; i < colPad; i++) {
|
||||||
|
cellWidth += columnSizes.get(cell.x + i + 1);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < rowPad; i++) {
|
||||||
|
cellHeight += rowSizes.get(cell.y + i + 1);
|
||||||
|
}
|
||||||
|
v.setSize(cellWidth, cellHeight);
|
||||||
|
if(v.getWidth() != cellWidth) {
|
||||||
|
v.setWidth(-1.0f);
|
||||||
|
v.setWidth(cellWidth);
|
||||||
|
}
|
||||||
|
if(v.getHeight() != cellHeight) {
|
||||||
|
v.setHeight(-1.0f);
|
||||||
|
v.setHeight(cellHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRowPadding(int row, int col, int padding) {
|
public void setRowPadding(int row, int col, int padding) {
|
||||||
rowPadding.put(new Point2<>(row, col), padding);
|
rowPadding.put(new Point2<>(col, row), padding);
|
||||||
|
for(int i = rowSizes.size(); i <= row + padding; i++) {
|
||||||
|
rowSizes.add(0);
|
||||||
|
}
|
||||||
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumnPadding(int row, int col, int padding) {
|
public void setColumnPadding(int row, int col, int padding) {
|
||||||
columnPadding.put(new Point2<>(row, col), padding);
|
columnPadding.put(new Point2<>(col, row), padding);
|
||||||
|
for(int i = columnSizes.size(); i <= col + padding; i++) {
|
||||||
|
columnSizes.add(0);
|
||||||
|
}
|
||||||
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRowSize(int row, int height) {
|
public void setRowSize(int row, int height) {
|
||||||
rowSizes.put(row, height);
|
fixedRows.put(row, height);
|
||||||
refresh();
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumnSize(int column, int width) {
|
public void setColumnSize(int column, int width) {
|
||||||
columnSizes.put(column, width);
|
fixedColumns.put(column, width);
|
||||||
refresh();
|
updateSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point2<Integer> getGridLocation(Point2<Integer> grid) {
|
||||||
|
int locationX = 0;
|
||||||
|
int locationY = 0;
|
||||||
|
for(int i = 0; i < grid.x; i++) {
|
||||||
|
locationX += columnSizes.get(i);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < grid.y; i++) {
|
||||||
|
locationY += rowSizes.get(i);
|
||||||
|
}
|
||||||
|
return new Point2<>(locationX, locationY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVisual(Visual v) {
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
if(v.getAttribute("row") != null) {
|
||||||
|
x = Integer.parseInt(v.getAttribute("row"));
|
||||||
|
}
|
||||||
|
if(v.getAttribute("column") != null) {
|
||||||
|
y = Integer.parseInt(v.getAttribute("column"));
|
||||||
|
}
|
||||||
|
this.addVisual(v, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVisual(Visual v, int row, int col) {
|
public void addVisual(Visual v, int row, int col) {
|
||||||
super.addVisual(v);
|
super.addVisual(v);
|
||||||
childrenCols.computeIfAbsent(col, k -> new ArrayList<>());
|
children.put(v, new Point2<>(col, row));
|
||||||
childrenRows.computeIfAbsent(row, k -> new ArrayList<>());
|
|
||||||
childrenCols.get(col).add(v);
|
|
||||||
childrenRows.get(row).add(v);
|
|
||||||
v.setLocation(-1.0f, -1.0f);
|
v.setLocation(-1.0f, -1.0f);
|
||||||
refresh();
|
for(int i = rowSizes.size(); i <= row; i++) {
|
||||||
|
rowSizes.add(0);
|
||||||
|
}
|
||||||
|
for(int i = columnSizes.size(); i <= col; i++) {
|
||||||
|
columnSizes.add(0);
|
||||||
|
}
|
||||||
|
updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(BufferedImage imageBuffer) {
|
public void paint(BufferedImage imageBuffer) {
|
||||||
|
|||||||
@@ -115,11 +115,6 @@ public class Panel extends Visual {
|
|||||||
g.setColor(getBackgroundColor());
|
g.setColor(getBackgroundColor());
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
if(getHasBorder()) {
|
|
||||||
g.setColor(getBorderColor());
|
|
||||||
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,14 +141,8 @@ public class ScrollPanel extends Visual {
|
|||||||
public void paint(BufferedImage imageBuffer) {
|
public void paint(BufferedImage imageBuffer) {
|
||||||
Graphics2D g = imageBuffer.createGraphics();
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
g.setColor(getPaintColor());
|
g.setColor(getPaintColor());
|
||||||
if(getHasBorder()) {
|
|
||||||
g.fillRect(1, 1, getWidth() - 1, getHeight() - 1);
|
g.fillRect(0, 0, getWidth(), getHeight());
|
||||||
g.setColor(getBorderColor());
|
|
||||||
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
g.dispose();
|
g.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ public class Slider extends Visual {
|
|||||||
setBackgroundColor(new Color(175, 175, 175));
|
setBackgroundColor(new Color(175, 175, 175));
|
||||||
setForegroundColor(new Color(112, 112, 112));
|
setForegroundColor(new Color(112, 112, 112));
|
||||||
setAccentColor(new Color(50, 50, 50));
|
setAccentColor(new Color(50, 50, 50));
|
||||||
button1.setHasBorder(false);
|
|
||||||
button2.setHasBorder(false);
|
|
||||||
|
|
||||||
if(direction == Direction.Horizontal) {
|
if(direction == Direction.Horizontal) {
|
||||||
button1.setIcon("arrow_left_black");
|
button1.setIcon("arrow_left_black");
|
||||||
@@ -192,14 +190,6 @@ public class Slider extends Visual {
|
|||||||
slider.setForegroundColor(color);
|
slider.setForegroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setBorderColor(Color color) {
|
|
||||||
super.setBorderColor(color);
|
|
||||||
button1.setBorderColor(color);
|
|
||||||
button2.setBorderColor(color);
|
|
||||||
slider.setBorderColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
super.setName(name);
|
super.setName(name);
|
||||||
@@ -230,10 +220,6 @@ public class Slider extends Visual {
|
|||||||
Graphics2D g = imageBuffer.createGraphics();
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
if(getHasBorder()) {
|
|
||||||
g.setColor(getBorderColor());
|
|
||||||
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
|
|
||||||
}
|
|
||||||
g.setColor(getBackgroundColor());
|
g.setColor(getBackgroundColor());
|
||||||
|
|
||||||
if(direction == Direction.Vertical) {
|
if(direction == Direction.Vertical) {
|
||||||
|
|||||||
185
src/guiTree/Components/Text.java
Normal file
185
src/guiTree/Components/Text.java
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
package guiTree.Components;
|
||||||
|
|
||||||
|
import guiTree.Visual;
|
||||||
|
import guiTree.events.MouseAdapter;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
public class Text extends Visual {
|
||||||
|
private String text;
|
||||||
|
private boolean selectable;
|
||||||
|
private int startIndex;
|
||||||
|
private int endIndex;
|
||||||
|
private int textWidth;
|
||||||
|
private int textHeight;
|
||||||
|
private boolean inside;
|
||||||
|
private int[] characterWidthMap;
|
||||||
|
private FontMetrics fontMetrics;
|
||||||
|
private int textX;
|
||||||
|
private int textY;
|
||||||
|
|
||||||
|
public Text() {
|
||||||
|
this(0, 0, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Text(int x, int y, String text) {
|
||||||
|
super(x, y);
|
||||||
|
this.text = text;
|
||||||
|
inside = false;
|
||||||
|
characterWidthMap = new int[text.length()];
|
||||||
|
startIndex = -1;
|
||||||
|
endIndex = -1;
|
||||||
|
textX = 0;
|
||||||
|
textY = 0;
|
||||||
|
|
||||||
|
addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent mouseEvent) {
|
||||||
|
int x = mouseEvent.getX();
|
||||||
|
int y = mouseEvent.getY();
|
||||||
|
if(isOverText(x, y)) {
|
||||||
|
startIndex = getCharAt(x);
|
||||||
|
System.out.println("Start Index: " + startIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startIndex = -1;
|
||||||
|
endIndex = -1;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent mouseEvent) {
|
||||||
|
int x = mouseEvent.getX();
|
||||||
|
int y = mouseEvent.getY();
|
||||||
|
|
||||||
|
if(startIndex != -1) {
|
||||||
|
endIndex = getCharAt(x);
|
||||||
|
System.out.println("End index: " + endIndex);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent mouseEvent) {
|
||||||
|
if(inside) {
|
||||||
|
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent mouseEvent) {
|
||||||
|
int x = mouseEvent.getX();
|
||||||
|
int y = mouseEvent.getY();
|
||||||
|
if(isOverText(x, y)) {
|
||||||
|
if(!inside) {
|
||||||
|
setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||||
|
inside = true;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(inside) {
|
||||||
|
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
inside = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
characterWidthMap = new int[text.length()];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectable(Boolean selectable) {
|
||||||
|
this.selectable = selectable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCharAt(int x) {
|
||||||
|
int location = (getWidth() - textWidth)/2;
|
||||||
|
for(int i = 0; i < text.length(); i++) {
|
||||||
|
if(x < location + characterWidthMap[i] / 2) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
location += characterWidthMap[i];
|
||||||
|
}
|
||||||
|
return text.length()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFont(Font font) {
|
||||||
|
super.setFont(font);
|
||||||
|
fontMetrics = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOverText(int x, int y) {
|
||||||
|
if(x < textX || x > textX + textWidth) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(y > textY || y < textY - textHeight) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
System.out.println("Text X: " + textX + " Text Y: " + textY + " x: " + x + " y: " + y + " textWidth: " + textWidth + " textHeight: " + textHeight);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCharacterWidthMap() {
|
||||||
|
for(int i = 0; i < text.length(); i++) {
|
||||||
|
int charWidth = fontMetrics.charWidth(text.charAt(i));
|
||||||
|
characterWidthMap[i] = charWidth;
|
||||||
|
}
|
||||||
|
textWidth = fontMetrics.stringWidth(text);
|
||||||
|
textHeight = fontMetrics.getHeight();
|
||||||
|
textX = (getWidth() - textWidth)/2;
|
||||||
|
textY = (getHeight() + textHeight)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void paint(BufferedImage imageBuffer) {
|
||||||
|
Graphics2D g = imageBuffer.createGraphics();
|
||||||
|
|
||||||
|
if(getFont() != null) {
|
||||||
|
g.setFont(getFont());
|
||||||
|
}
|
||||||
|
if(fontMetrics == null) {
|
||||||
|
fontMetrics = g.getFontMetrics();
|
||||||
|
setCharacterWidthMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(startIndex != -1 && endIndex != -1) {
|
||||||
|
int startX;
|
||||||
|
int endX;
|
||||||
|
if(startIndex > endIndex) {
|
||||||
|
endX = startIndex;
|
||||||
|
startX = endIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
startX = startIndex;
|
||||||
|
endX = endIndex;
|
||||||
|
}
|
||||||
|
int highlightStartX = textX;
|
||||||
|
int highlightEndX = textX;
|
||||||
|
|
||||||
|
for(int i = 0; i <= endX; i++) {
|
||||||
|
if(i < startX) {
|
||||||
|
highlightStartX += characterWidthMap[i];
|
||||||
|
}
|
||||||
|
highlightEndX += characterWidthMap[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(Color.BLUE);
|
||||||
|
g.fillRect(highlightStartX, textY - textHeight + 3, highlightEndX - highlightStartX, textHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(getFontColor());
|
||||||
|
|
||||||
|
g.drawString(text, textX, textY);
|
||||||
|
|
||||||
|
g.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,14 +82,7 @@ public class ToggleButton extends Visual {
|
|||||||
g.setColor(getPaintColor());
|
g.setColor(getPaintColor());
|
||||||
|
|
||||||
//Draw Button
|
//Draw Button
|
||||||
if(getHasBorder()) {
|
g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
|
||||||
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
|
//Draw Label
|
||||||
if(getFont() != null) {
|
if(getFont() != null) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public class CustomFrame extends JFrame {
|
|||||||
private int startX;
|
private int startX;
|
||||||
private int startY;
|
private int startY;
|
||||||
private boolean resizing = false;
|
private boolean resizing = false;
|
||||||
|
private boolean changedCursor = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@@ -87,9 +88,13 @@ public class CustomFrame extends JFrame {
|
|||||||
if(e.getX() < resizeDelta || e.getX() > getWidth() - resizeDelta ||
|
if(e.getX() < resizeDelta || e.getX() > getWidth() - resizeDelta ||
|
||||||
e.getY() < resizeDelta || e.getY() > getHeight() - resizeDelta) {
|
e.getY() < resizeDelta || e.getY() > getHeight() - resizeDelta) {
|
||||||
this.setResizeCursor(e);
|
this.setResizeCursor(e);
|
||||||
|
changedCursor = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
if(changedCursor) {
|
||||||
|
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
changedCursor = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public class Debugger {
|
|||||||
public enum Tag {
|
public enum Tag {
|
||||||
LISTENER(true),
|
LISTENER(true),
|
||||||
PAINTING(false),
|
PAINTING(false),
|
||||||
FPS(true),
|
FPS(false),
|
||||||
ANIMATIONS(false),
|
ANIMATIONS(false),
|
||||||
PARSING(false);
|
PARSING(false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package guiTree.Helper;
|
package guiTree.Helper;
|
||||||
|
|
||||||
public class Point2<T> {
|
public class Point2<T extends Comparable<T>> implements Comparable<Point2<T>> {
|
||||||
public T x;
|
public T x;
|
||||||
public T y;
|
public T y;
|
||||||
|
|
||||||
@@ -9,8 +9,13 @@ public class Point2<T> {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Point2<T> point2) {
|
@Override
|
||||||
return x == point2.y && y == point2.y;
|
public boolean equals(Object obj) {
|
||||||
|
if(!(obj instanceof Point2<?>)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Point2<?> point2 = (Point2<?>)obj;
|
||||||
|
return point2.x.equals(x) && point2.y.equals(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -22,4 +27,13 @@ public class Point2<T> {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (x.toString() + ", " + y.toString()).hashCode();
|
return (x.toString() + ", " + y.toString()).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Point2<T> tPoint2) {
|
||||||
|
int cmp = x.compareTo(tPoint2.x);
|
||||||
|
if(cmp == 0) {
|
||||||
|
return y.compareTo(tPoint2.y);
|
||||||
|
}
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Visual {
|
public class Visual {
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -42,6 +43,7 @@ public class Visual {
|
|||||||
Attributes
|
Attributes
|
||||||
---------------------------------------------------------------------*/
|
---------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
private Map<String, String> attributeMap;
|
||||||
private Integer width;
|
private Integer width;
|
||||||
private Integer height;
|
private Integer height;
|
||||||
private Float relativeWidth;
|
private Float relativeWidth;
|
||||||
@@ -52,19 +54,18 @@ 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 Font font;
|
||||||
private Color backgroundColor;
|
private Color backgroundColor;
|
||||||
private Color foregroundColor;
|
private Color foregroundColor;
|
||||||
private Color accentColor;
|
private Color accentColor;
|
||||||
private Color fontColor;
|
private Color fontColor;
|
||||||
private Color borderColor;
|
|
||||||
private Color paintColor;
|
private Color paintColor;
|
||||||
private Boolean active;
|
private Boolean active;
|
||||||
private Boolean dirty;
|
private Boolean dirty;
|
||||||
private static Visual entered;
|
private static Visual entered;
|
||||||
private static Visual focused;
|
private static Visual focused;
|
||||||
private Boolean pressed;
|
private Boolean pressed;
|
||||||
|
private Boolean validating;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
Constructors
|
Constructors
|
||||||
@@ -84,13 +85,12 @@ public class Visual {
|
|||||||
this.backgroundColor = Color.WHITE;
|
this.backgroundColor = Color.WHITE;
|
||||||
this.foregroundColor = Color.BLUE;
|
this.foregroundColor = Color.BLUE;
|
||||||
this.fontColor = Color.BLACK;
|
this.fontColor = Color.BLACK;
|
||||||
this.borderColor = Color.BLACK;
|
|
||||||
this.accentColor = Color.BLUE;
|
this.accentColor = Color.BLUE;
|
||||||
|
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
this.hasBorder = false;
|
|
||||||
this.active = this instanceof Window;
|
this.active = this instanceof Window;
|
||||||
this.pressed = false;
|
this.pressed = false;
|
||||||
|
this.attributeMap = new HashMap<>();
|
||||||
|
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
@@ -103,6 +103,8 @@ public class Visual {
|
|||||||
this.locationY = 0;
|
this.locationY = 0;
|
||||||
this.absoluteX = 0;
|
this.absoluteX = 0;
|
||||||
this.absoluteY = 0;
|
this.absoluteY = 0;
|
||||||
|
|
||||||
|
this.validating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -133,7 +135,7 @@ public class Visual {
|
|||||||
v.setLocation();
|
v.setLocation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
propagateDirt();
|
update();
|
||||||
notifyParent(this, SIZE_CHANGED);
|
notifyParent(this, SIZE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +178,7 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
calculateAbsoluteLocation();
|
calculateAbsoluteLocation();
|
||||||
propagateDirt();
|
update();
|
||||||
notifyParent(this, LOCATION_CHANGED);
|
notifyParent(this, LOCATION_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,37 +209,31 @@ public class Visual {
|
|||||||
public void setBackgroundColor(Color backgroundColor) {
|
public void setBackgroundColor(Color backgroundColor) {
|
||||||
this.backgroundColor = backgroundColor;
|
this.backgroundColor = backgroundColor;
|
||||||
this.paintColor = backgroundColor;
|
this.paintColor = backgroundColor;
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForegroundColor(Color foregroundColor) {
|
public void setForegroundColor(Color foregroundColor) {
|
||||||
this.foregroundColor = foregroundColor;
|
this.foregroundColor = foregroundColor;
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFontColor(Color fontColor) {
|
public void setFontColor(Color fontColor) {
|
||||||
this.fontColor = fontColor;
|
this.fontColor = fontColor;
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccentColor(Color accentColor) {
|
public void setAccentColor(Color accentColor) {
|
||||||
this.accentColor = accentColor;
|
this.accentColor = accentColor;
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
|
||||||
|
|
||||||
public void setBorderColor(Color borderColor) {
|
|
||||||
this.borderColor = borderColor;
|
|
||||||
propagateDirt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPaintColor(Color paintColor) {
|
public void setPaintColor(Color paintColor) {
|
||||||
this.paintColor = paintColor;
|
this.paintColor = paintColor;
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHasBorder(Boolean hasBorder) {
|
public void setAttribute(String attribute, String value) {
|
||||||
this.hasBorder = hasBorder;
|
attributeMap.put(attribute, value);
|
||||||
propagateDirt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -292,16 +288,12 @@ public class Visual {
|
|||||||
return accentColor;
|
return accentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getBorderColor() {
|
|
||||||
return borderColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getPaintColor() {
|
public Color getPaintColor() {
|
||||||
return paintColor;
|
return paintColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getHasBorder() {
|
public String getAttribute(String attribute) {
|
||||||
return hasBorder;
|
return attributeMap.get(attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------
|
/*--------------------------------------------------------------------
|
||||||
@@ -333,7 +325,7 @@ public class Visual {
|
|||||||
if(this.active) {
|
if(this.active) {
|
||||||
child.activate();
|
child.activate();
|
||||||
}
|
}
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeVisual(Visual child) {
|
public void removeVisual(Visual child) {
|
||||||
@@ -344,7 +336,7 @@ public class Visual {
|
|||||||
child.setParent(null);
|
child.setParent(null);
|
||||||
child.imageBuffer = null;
|
child.imageBuffer = null;
|
||||||
child.deactivate();
|
child.deactivate();
|
||||||
propagateDirt();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setParent(Visual parent) {
|
private void setParent(Visual parent) {
|
||||||
@@ -396,8 +388,10 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void revalidate() {
|
private void revalidate() {
|
||||||
Timer timer = new Timer();
|
|
||||||
Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING);
|
Debugger.log("Revalidating " + name, Debugger.Tag.PAINTING);
|
||||||
|
Timer timer = new Timer();
|
||||||
|
|
||||||
|
validating = true;
|
||||||
timer.startTiming();
|
timer.startTiming();
|
||||||
|
|
||||||
clearImageBuffer();
|
clearImageBuffer();
|
||||||
@@ -408,7 +402,10 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
|
imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
validating = false;
|
||||||
|
|
||||||
if(!(this instanceof Window)){
|
if(!(this instanceof Window)){
|
||||||
long time = timer.stopTiming();
|
long time = timer.stopTiming();
|
||||||
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
|
Debugger.log("Finished Revalidating " + name + ": " + time, Debugger.Tag.PAINTING);
|
||||||
@@ -422,8 +419,10 @@ public class Visual {
|
|||||||
window.revalidate();
|
window.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void setCursor(Cursor cursor) {
|
||||||
propagateDirt();
|
if(parent != null) {
|
||||||
|
parent.setCursor(cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(BufferedImage imageBuffer) {
|
public void paint(BufferedImage imageBuffer) {
|
||||||
@@ -459,14 +458,14 @@ public class Visual {
|
|||||||
|
|
||||||
void mouseClicked(MouseEvent mouseEvent) {
|
void mouseClicked(MouseEvent mouseEvent) {
|
||||||
for(MouseListener mouseListener: entered.mouseListeners) {
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
mouseListener.mouseClicked(mouseEvent);
|
mouseListener.mouseClicked(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Clicked " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Clicked " + entered.name, Debugger.Tag.LISTENER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseReleased(MouseEvent mouseEvent) {
|
void mouseReleased(MouseEvent mouseEvent) {
|
||||||
for(MouseListener mouseListener: entered.mouseListeners) {
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
mouseListener.mouseReleased(mouseEvent);
|
mouseListener.mouseReleased(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Released " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Released " + entered.name, Debugger.Tag.LISTENER);
|
||||||
entered.pressed = false;
|
entered.pressed = false;
|
||||||
@@ -474,7 +473,7 @@ public class Visual {
|
|||||||
|
|
||||||
void mousePressed(MouseEvent mouseEvent) {
|
void mousePressed(MouseEvent mouseEvent) {
|
||||||
for(MouseListener mouseListener: entered.mouseListeners) {
|
for(MouseListener mouseListener: entered.mouseListeners) {
|
||||||
mouseListener.mousePressed(mouseEvent);
|
mouseListener.mousePressed(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
entered.pressed = true;
|
entered.pressed = true;
|
||||||
focused = entered;
|
focused = entered;
|
||||||
@@ -488,17 +487,14 @@ public class Visual {
|
|||||||
int mouseX = mouseEvent.getX();
|
int mouseX = mouseEvent.getX();
|
||||||
int mouseY = mouseEvent.getY();
|
int mouseY = mouseEvent.getY();
|
||||||
for(Visual v: children) {
|
for(Visual v: children) {
|
||||||
if(mouseX > v.getLocationX() &&
|
if(v.isInside(mouseX, mouseY)){
|
||||||
mouseY > v.getLocationY() &&
|
|
||||||
mouseX < v.getWidth() + v.getLocationX() &&
|
|
||||||
mouseY < v.getHeight() + v.getLocationY()){
|
|
||||||
v.mouseEntered(mouseEvent);
|
v.mouseEntered(mouseEvent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entered = this;
|
entered = this;
|
||||||
for(MouseListener mouseListener: mouseListeners) {
|
for(MouseListener mouseListener: mouseListeners) {
|
||||||
mouseListener.mouseEntered(mouseEvent);
|
mouseListener.mouseEntered(createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Entered " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Entered " + entered.name, Debugger.Tag.LISTENER);
|
||||||
}
|
}
|
||||||
@@ -511,7 +507,7 @@ public class Visual {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
mouseListener.mouseExited(mouseEvent);
|
mouseListener.mouseExited(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
|
||||||
entered = null;
|
entered = null;
|
||||||
@@ -519,7 +515,7 @@ public class Visual {
|
|||||||
|
|
||||||
void mouseDragged(MouseEvent mouseEvent) {
|
void mouseDragged(MouseEvent mouseEvent) {
|
||||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
mouseListener.mouseDragged(mouseEvent);
|
mouseListener.mouseDragged(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Dragged " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Dragged " + entered.name, Debugger.Tag.LISTENER);
|
||||||
}
|
}
|
||||||
@@ -533,7 +529,7 @@ public class Visual {
|
|||||||
if(entered != null) {
|
if(entered != null) {
|
||||||
if (!entered.isInside(mouseX, mouseY)) {
|
if (!entered.isInside(mouseX, mouseY)) {
|
||||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
mouseListener.mouseExited(mouseEvent);
|
mouseListener.mouseExited(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
|
Debugger.log("Exited " + entered.name, Debugger.Tag.LISTENER);
|
||||||
entered = this;
|
entered = this;
|
||||||
@@ -547,16 +543,17 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
if (this != entered && entered != null) {
|
if (this != entered && entered != null) {
|
||||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||||
mouseListener.mouseExited(mouseEvent);
|
mouseListener.mouseExited(entered.createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
entered = this;
|
entered = this;
|
||||||
for (MouseListener mouseListener : mouseListeners) {
|
for (MouseListener mouseListener : mouseListeners) {
|
||||||
mouseListener.mouseEntered(mouseEvent);
|
mouseListener.mouseEntered(createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
|
Debugger.log("Entered " + this.name, Debugger.Tag.LISTENER);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (MouseListener mouseListener : mouseListeners) {
|
for (MouseListener mouseListener : mouseListeners) {
|
||||||
mouseListener.mouseMoved(mouseEvent);
|
mouseListener.mouseMoved(createMouseEvent(mouseEvent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debugger.log("Moved " + this.name, Debugger.Tag.LISTENER);
|
Debugger.log("Moved " + this.name, Debugger.Tag.LISTENER);
|
||||||
@@ -640,6 +637,12 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MouseEvent createMouseEvent(MouseEvent mouseEvent) {
|
||||||
|
return new MouseEvent(mouseEvent.getComponent(), mouseEvent.getID(), mouseEvent.getWhen(), mouseEvent.getModifiersEx(),
|
||||||
|
mouseEvent.getX() - absoluteX, mouseEvent.getY() - absoluteY, mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen(),
|
||||||
|
mouseEvent.getClickCount(), mouseEvent.isPopupTrigger(), mouseEvent.getButton());
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isInside(int x, int y) {
|
private boolean isInside(int x, int y) {
|
||||||
return x > absoluteX && x < absoluteX + width && y > absoluteY && y < absoluteY + height;
|
return x > absoluteX && x < absoluteX + width && y > absoluteY && y < absoluteY + height;
|
||||||
}
|
}
|
||||||
@@ -658,10 +661,17 @@ public class Visual {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void propagateDirt() {
|
public void update() {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
if(parent != null) {
|
if(parent != null) {
|
||||||
parent.propagateDirt();
|
while(parent.validating){
|
||||||
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,6 +244,10 @@ public class Window extends Visual implements Runnable{
|
|||||||
public void addVisual(Visual v) {
|
public void addVisual(Visual v) {
|
||||||
contentPanel.addVisual(v);
|
contentPanel.addVisual(v);
|
||||||
}
|
}
|
||||||
|
public void setCursor(Cursor cursor) {
|
||||||
|
System.out.println("Changed cursor ASD");
|
||||||
|
frame.setCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
import com.sun.jdi.InvalidTypeException;
|
import com.sun.jdi.InvalidTypeException;
|
||||||
import converters.Converter;
|
import parser.converters.Converter;
|
||||||
import guiTree.Helper.Debugger;
|
import guiTree.Helper.Debugger;
|
||||||
import guiTree.Visual;
|
import guiTree.Visual;
|
||||||
import guiTree.Window;
|
import guiTree.Window;
|
||||||
@@ -24,7 +24,18 @@ public class XAMLParser {
|
|||||||
Node attribute = attributeList.item(i);
|
Node attribute = attributeList.item(i);
|
||||||
String methodName = "set";
|
String methodName = "set";
|
||||||
methodName = methodName.concat(attribute.getNodeName());
|
methodName = methodName.concat(attribute.getNodeName());
|
||||||
List<Object> parameterList = convertStringToPrimitives(object, attribute.getNodeValue(), methodName);
|
|
||||||
|
List<Method> methods = getMethodsFromName(object, methodName);
|
||||||
|
String value = attribute.getNodeValue();
|
||||||
|
if(methods.size() == 0) {
|
||||||
|
String firstAttribute = methodName.substring(3).toLowerCase();
|
||||||
|
methodName = "setAttribute";
|
||||||
|
methods = getMethodsFromName(object, methodName);
|
||||||
|
|
||||||
|
value = firstAttribute.concat(",").concat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Object> parameterList = convertStringToPrimitives(value, methods);
|
||||||
Debugger.log("Calling " + methodName + " " + attribute.getNodeValue(), Debugger.Tag.PARSING);
|
Debugger.log("Calling " + methodName + " " + attribute.getNodeValue(), Debugger.Tag.PARSING);
|
||||||
if(parameterList == null) {
|
if(parameterList == null) {
|
||||||
break;
|
break;
|
||||||
@@ -75,7 +86,7 @@ public class XAMLParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Object> convertStringToPrimitives(Object object, String value, String methodName){
|
private static List<Object> convertStringToPrimitives(String value, List<Method> methods){
|
||||||
List<Object> primitiveAttributes = new ArrayList<>();
|
List<Object> primitiveAttributes = new ArrayList<>();
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
|
|
||||||
@@ -84,10 +95,7 @@ public class XAMLParser {
|
|||||||
value = value.substring(value.indexOf(',') + 1);
|
value = value.substring(value.indexOf(',') + 1);
|
||||||
}
|
}
|
||||||
values.add(value);
|
values.add(value);
|
||||||
List<Method> methods = getMethodsFromName(object, methodName);
|
|
||||||
if(methods.size() == 0) {
|
|
||||||
System.out.println("Could not find method " + methodName);
|
|
||||||
}
|
|
||||||
for(Method method: methods){
|
for(Method method: methods){
|
||||||
Class<?>[] types = method.getParameterTypes();
|
Class<?>[] types = method.getParameterTypes();
|
||||||
if(types.length == values.size()) {
|
if(types.length == values.size()) {
|
||||||
@@ -104,7 +112,7 @@ public class XAMLParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.err.println("Could not find method " + methodName + " with parameters " + values);
|
System.err.println("Could not find method " + methods.get(0).getName() + " with parameters " + values);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
public class BooleanConverter implements ConverterInterface<Boolean> {
|
public class BooleanConverter implements ConverterInterface<Boolean> {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
import com.sun.jdi.InvalidTypeException;
|
import com.sun.jdi.InvalidTypeException;
|
||||||
import guiTree.Components.Slider;
|
import guiTree.Components.Slider;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
import com.sun.jdi.InvalidTypeException;
|
import com.sun.jdi.InvalidTypeException;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
import com.sun.jdi.InvalidTypeException;
|
import com.sun.jdi.InvalidTypeException;
|
||||||
import guiTree.Components.Slider;
|
import guiTree.Components.Slider;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
public class DoubleConverter implements ConverterInterface<Double>{
|
public class DoubleConverter implements ConverterInterface<Double>{
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
import com.sun.jdi.InvalidTypeException;
|
import com.sun.jdi.InvalidTypeException;
|
||||||
|
|
||||||
@@ -7,10 +7,12 @@ 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(" ", "");
|
content = content.replaceAll(" ", "");
|
||||||
float number = Float.parseFloat(content);
|
|
||||||
if(number > 1 || number < 0 || !content.contains(".")) {
|
if(content.toLowerCase().charAt(content.length() - 1) != 'f') {
|
||||||
throw new InvalidTypeException();
|
throw new InvalidTypeException();
|
||||||
}
|
}
|
||||||
|
content = content.substring(0, content.length() - 1);
|
||||||
|
|
||||||
return Float.parseFloat(content);
|
return Float.parseFloat(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
public class IntegerConverter implements ConverterInterface<Integer> {
|
public class IntegerConverter implements ConverterInterface<Integer> {
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package converters;
|
package parser.converters;
|
||||||
|
|
||||||
public class StringConverter implements ConverterInterface<String> {
|
public class StringConverter implements ConverterInterface<String> {
|
||||||
|
|
||||||
Reference in New Issue
Block a user