mirror of
https://github.com/macocianradu/javaGUItoolkit.git
synced 2026-03-18 13:40:04 +00:00
reworked some content panel logic and listener logic
This commit is contained in:
@@ -29,6 +29,7 @@ public class Main {
|
||||
});
|
||||
|
||||
window.revalidate();
|
||||
System.out.println(Float.parseFloat("3"));
|
||||
long now;
|
||||
long prev = 0;
|
||||
// while(true) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
|
||||
public interface ConverterInterface<T> {
|
||||
T convert(String content);
|
||||
T convert(String content) throws InvalidTypeException;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package converters;
|
||||
|
||||
import com.sun.jdi.InvalidTypeException;
|
||||
|
||||
public class FloatConverter implements ConverterInterface<Float> {
|
||||
|
||||
@Override
|
||||
public Float convert(String content) {
|
||||
public Float convert(String content) throws InvalidTypeException {
|
||||
float number = Float.parseFloat(content);
|
||||
if(number > 1 || number < 0) {
|
||||
throw new InvalidTypeException();
|
||||
}
|
||||
return Float.parseFloat(content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ public class Panel extends Visual {
|
||||
int l2y = v2.getLocationY();
|
||||
int r2y = v2.getLocationY() + v2.getHeight();
|
||||
|
||||
if(l1x > r2x || l2x > r1x) {
|
||||
if(l1x >= r2x || l2x >= r1x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return l1y <= r2y && l2y <= r1y;
|
||||
return l1y < r2y && l2y < r1y;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TitleBar extends Visual {
|
||||
maximize.setForegroundColor(Color.LIGHT_GRAY);
|
||||
minimize.setForegroundColor(Color.LIGHT_GRAY);
|
||||
|
||||
this.setSize(1, 30);
|
||||
this.setSize(0, 30);
|
||||
this.setLocation(0, 0);
|
||||
|
||||
setButtonLocation();
|
||||
@@ -97,7 +97,6 @@ public class TitleBar extends Visual {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Getters
|
||||
---------------------------------------------------------------------*/
|
||||
|
||||
@@ -331,7 +331,6 @@ public class Visual {
|
||||
if(entered != null && entered.pressed){
|
||||
return;
|
||||
}
|
||||
boolean front = true;
|
||||
int mouseX = mouseEvent.getX() - offsetX;
|
||||
int mouseY = mouseEvent.getY() - offsetY;
|
||||
for(Visual v: children) {
|
||||
@@ -339,17 +338,15 @@ public class Visual {
|
||||
mouseY > v.getLocationY() &&
|
||||
mouseX < v.getWidth() + v.getLocationX() &&
|
||||
mouseY < v.getHeight() + v.getLocationY()){
|
||||
front = false;
|
||||
v.mouseEntered(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(front) {
|
||||
entered = this;
|
||||
for(MouseListener mouseListener: mouseListeners) {
|
||||
mouseListener.mouseEntered(mouseEvent);
|
||||
}
|
||||
dirty = true;
|
||||
entered = this;
|
||||
for(MouseListener mouseListener: mouseListeners) {
|
||||
mouseListener.mouseEntered(mouseEvent);
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void mouseExited(MouseEvent mouseEvent) {
|
||||
@@ -377,7 +374,6 @@ public class Visual {
|
||||
if(entered != null && entered.pressed){
|
||||
return;
|
||||
}
|
||||
boolean front = true;
|
||||
int mouseX = mouseEvent.getX() - offsetX;
|
||||
int mouseY = mouseEvent.getY() - offsetY;
|
||||
if(entered != null) {
|
||||
@@ -390,29 +386,25 @@ public class Visual {
|
||||
}
|
||||
for(Visual v: children) {
|
||||
if(v.isInside(mouseX, mouseY)) {
|
||||
front = false;
|
||||
v.mouseMoved(mouseEvent, offsetX + v.locationX, offsetY + v.locationY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(front) {
|
||||
if(this.isInside(mouseEvent.getX(), mouseEvent.getY())) {
|
||||
if (this != entered && entered != null) {
|
||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||
mouseListener.mouseExited(mouseEvent);
|
||||
}
|
||||
entered = this;
|
||||
for (MouseListener mouseListener : mouseListeners) {
|
||||
mouseListener.mouseEntered(mouseEvent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (MouseListener mouseListener : mouseListeners) {
|
||||
mouseListener.mouseMoved(mouseEvent);
|
||||
}
|
||||
}
|
||||
if (this != entered && entered != null) {
|
||||
for (MouseListener mouseListener : entered.mouseListeners) {
|
||||
mouseListener.mouseExited(mouseEvent);
|
||||
}
|
||||
entered = this;
|
||||
for (MouseListener mouseListener : mouseListeners) {
|
||||
mouseListener.mouseEntered(mouseEvent);
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
else {
|
||||
for (MouseListener mouseListener : mouseListeners) {
|
||||
mouseListener.mouseMoved(mouseEvent);
|
||||
}
|
||||
}
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void mouseWheelMoved(MouseWheelEvent mouseWheelEvent, int offsetX, int offsetY) {
|
||||
@@ -427,7 +419,7 @@ public class Visual {
|
||||
Helper Methods
|
||||
---------------------------------------------------------------------*/
|
||||
private void initializeImageBuffer(){
|
||||
if(this.width == 0 || this.height == 0) {
|
||||
if(this.width <= 0 || this.height <= 0) {
|
||||
return;
|
||||
}
|
||||
this.imageBuffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -435,6 +427,9 @@ public class Visual {
|
||||
}
|
||||
|
||||
private void clearImageBuffer() {
|
||||
if(imageBuffer == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = this.imageBuffer.getGraphics();
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
@@ -20,6 +20,7 @@ public class Window extends Visual {
|
||||
public CustomFrame frame;
|
||||
private TitleBar titleBar;
|
||||
private Panel mainPanel;
|
||||
private Panel contentPanel;
|
||||
private ResizeListener windowResizeListener;
|
||||
private Point2d oldSize;
|
||||
private Point2d oldLocation;
|
||||
@@ -52,7 +53,7 @@ public class Window extends Visual {
|
||||
});
|
||||
this.mainPanel = new Panel();
|
||||
|
||||
super.addVisual(mainPanel);
|
||||
this.setMainPanel(mainPanel);
|
||||
|
||||
BufferedImage icon = null;
|
||||
try {
|
||||
@@ -69,8 +70,12 @@ public class Window extends Visual {
|
||||
public void setSize(Integer width, Integer height) {
|
||||
this.frame.setSize(width, height);
|
||||
super.setSize(width, height);
|
||||
if(this.titleBar != null) {
|
||||
this.titleBar.setSize(this.getWidth(), titleBar.getHeight());
|
||||
if(titleBar != null) {
|
||||
titleBar.setSize(this.getWidth(), titleBar.getHeight());
|
||||
contentPanel.setSize(width, height - titleBar.getHeight());
|
||||
}
|
||||
else {
|
||||
contentPanel.setSize(width, height);
|
||||
}
|
||||
windowResizeListener.setSize(width, height);
|
||||
mainPanel.setSize(width, height);
|
||||
@@ -122,6 +127,9 @@ public class Window extends Visual {
|
||||
}
|
||||
|
||||
this.titleBar = titleBar;
|
||||
titleBar.setLocation(0, 0);
|
||||
contentPanel.setLocation(0, titleBar.getHeight());
|
||||
contentPanel.setSize(mainPanel.getWidth(), mainPanel.getHeight() - titleBar.getHeight());
|
||||
mainPanel.addVisual(titleBar);
|
||||
this.titleBar.addMouseListener(new MouseAdapter() {
|
||||
private int startX;
|
||||
@@ -168,7 +176,20 @@ public class Window extends Visual {
|
||||
|
||||
public void setMainPanel(Panel panel) {
|
||||
this.removeVisual(mainPanel);
|
||||
this.addVisual(panel);
|
||||
contentPanel = new Panel();
|
||||
contentPanel.setName("ContentPanel");
|
||||
if(titleBar != null) {
|
||||
panel.addVisual(titleBar);
|
||||
contentPanel.setLocation(0, titleBar.getHeight());
|
||||
contentPanel.setSize(panel.getWidth(), panel.getHeight() - titleBar.getHeight());
|
||||
}
|
||||
else {
|
||||
contentPanel.setLocation(0, 0);
|
||||
contentPanel.setSize(panel.getWidth(), panel.getHeight());
|
||||
}
|
||||
panel.setName("MainPanel");
|
||||
panel.addVisual(contentPanel);
|
||||
super.addVisual(panel);
|
||||
this.mainPanel = panel;
|
||||
}
|
||||
|
||||
@@ -208,6 +229,6 @@ public class Window extends Visual {
|
||||
|
||||
@Override
|
||||
public void addVisual(Visual v) {
|
||||
mainPanel.addVisual(v);
|
||||
contentPanel.addVisual(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user