mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 21:50:04 +00:00
initial parser working as intended
This commit is contained in:
22
src/guiTree/Button.java
Normal file
22
src/guiTree/Button.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package guiTree;
|
||||
|
||||
import guiTree.Visual;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Button extends Visual {
|
||||
|
||||
public Button()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(BufferedImage imageBuffer)
|
||||
{
|
||||
Graphics g = imageBuffer.getGraphics();
|
||||
g.setColor(this.getBackgroundColor());
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
}
|
||||
28
src/guiTree/CustomFrame.java
Normal file
28
src/guiTree/CustomFrame.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package guiTree;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class CustomFrame extends Frame {
|
||||
private BufferedImage imageBuffer;
|
||||
|
||||
public CustomFrame()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public CustomFrame(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setImageBuffer(BufferedImage imageBuffer) {
|
||||
this.imageBuffer = imageBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
g.drawImage(imageBuffer, 5, 0, this.getWidth(), this.getHeight(), null);
|
||||
}
|
||||
}
|
||||
185
src/guiTree/Visual.java
Normal file
185
src/guiTree/Visual.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package guiTree;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Visual {
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Tree Elements
|
||||
---------------------------------------------------------------------*/
|
||||
private List<Visual> children;
|
||||
private Visual parent;
|
||||
private BufferedImage imageBuffer;
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Attributes
|
||||
---------------------------------------------------------------------*/
|
||||
private String name;
|
||||
private Integer width;
|
||||
private Integer height;
|
||||
private Integer locationX;
|
||||
private Integer locationY;
|
||||
private Color backgroundColor;
|
||||
private Color foregroundColor;
|
||||
private Boolean active;
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Constructors
|
||||
---------------------------------------------------------------------*/
|
||||
public Visual() {
|
||||
this.children = new ArrayList<>();
|
||||
this.parent = null;
|
||||
this.backgroundColor = Color.WHITE;
|
||||
this.foregroundColor = Color.BLACK;
|
||||
|
||||
this.active = this instanceof Window;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Attributes Methods
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public void setSize(Integer width, Integer height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
initializeImageBuffer(width, height);
|
||||
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public int getLocationX(){
|
||||
return this.locationX;
|
||||
}
|
||||
|
||||
public int getLocationY(){
|
||||
return this.locationY;
|
||||
}
|
||||
|
||||
public void setLocation(Integer x, Integer y){
|
||||
this.locationX = x;
|
||||
this.locationY = y;
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public Color getBackgroundColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public void setBackgroundColor(Color backgroundColor) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public Color getForegroundColor() {
|
||||
return foregroundColor;
|
||||
}
|
||||
|
||||
public void setForegroundColor(Color foregroundColor) {
|
||||
this.foregroundColor = foregroundColor;
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
private void calculateInitialSize() {
|
||||
this.width = 20;
|
||||
this.height = 20;
|
||||
}
|
||||
|
||||
private void calculateInitialLocation(){
|
||||
this.locationX = 20;
|
||||
this.locationY = 50;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Tree Methods
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
public void addVisual(Visual child) {
|
||||
this.children.add(child);
|
||||
child.setParent(this);
|
||||
child.calculateInitialLocation();
|
||||
child.calculateInitialSize();
|
||||
child.imageBuffer = new BufferedImage(child.getWidth(), child.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
|
||||
|
||||
child.active = true;
|
||||
child.revalidate();
|
||||
}
|
||||
|
||||
private void setParent(Visual parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
private void handleNotification() {
|
||||
|
||||
}
|
||||
|
||||
private void notifyParent()
|
||||
{
|
||||
this.parent.handleNotification();
|
||||
}
|
||||
|
||||
public void callRepaint()
|
||||
{
|
||||
this.paint(this.imageBuffer);
|
||||
this.parent.revalidate();
|
||||
}
|
||||
|
||||
public void revalidate() {
|
||||
if(!this.active){
|
||||
return;
|
||||
}
|
||||
initializeImageBuffer(width, height);
|
||||
this.paint(imageBuffer);
|
||||
for(Visual v:children){
|
||||
this.imageBuffer.getGraphics().drawImage(v.imageBuffer, v.locationX, v.locationY, null);
|
||||
}
|
||||
if(!(this instanceof Window)){
|
||||
this.parent.revalidate();
|
||||
}
|
||||
else{
|
||||
Window window = (Window)this;
|
||||
window.setFrameImageBuffer(this.imageBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(BufferedImage imageBuffer) {
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Helper Methods
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
private void initializeImageBuffer(Integer width, Integer height){
|
||||
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
this.imageBuffer.getGraphics().setColor(backgroundColor);
|
||||
this.imageBuffer.getGraphics().fillRect(0, 0, width, height);
|
||||
this.imageBuffer.getGraphics().setColor(foregroundColor);
|
||||
}
|
||||
}
|
||||
67
src/guiTree/Window.java
Normal file
67
src/guiTree/Window.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package guiTree;
|
||||
|
||||
import guiTree.Visual;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.event.WindowStateListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class Window extends Visual {
|
||||
public CustomFrame frame;
|
||||
|
||||
public Window()
|
||||
{
|
||||
super();
|
||||
this.frame = new CustomFrame();
|
||||
this.addWindowStateListener(e -> {
|
||||
this.setSize(getWidth(), getHeight());
|
||||
revalidate();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(Integer width, Integer height)
|
||||
{
|
||||
this.frame.setSize(width, height);
|
||||
super.setSize(width, height);
|
||||
revalidate();
|
||||
}
|
||||
|
||||
public void setFrameImageBuffer(BufferedImage imageBuffer){
|
||||
this.frame.setImageBuffer(imageBuffer);
|
||||
this.frame.repaint();
|
||||
}
|
||||
|
||||
public void setSize(Dimension dimension) {
|
||||
this.setSize(dimension.width, dimension.height);
|
||||
}
|
||||
|
||||
public void setVisible(Boolean visible)
|
||||
{
|
||||
frame.setVisible(visible);
|
||||
}
|
||||
|
||||
public void addWindowListener(WindowListener listener)
|
||||
{
|
||||
frame.addWindowListener(listener);
|
||||
}
|
||||
|
||||
public void addWindowStateListener(WindowStateListener listener)
|
||||
{
|
||||
frame.addWindowStateListener(listener);
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
public void setPositionRelativeTo(Component c){
|
||||
frame.setLocationRelativeTo(c);
|
||||
}
|
||||
|
||||
public void setPositionRelativeTo(){
|
||||
frame.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user