Added close button for widgets II

This commit is contained in:
Robert Vokac 2024-02-24 14:02:13 +00:00
parent 416fdf1ae2
commit 9ca7d18fff
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
4 changed files with 25 additions and 21 deletions

2
.gitignore vendored
View File

@ -13,6 +13,6 @@ proxy.txt
out.txt
pocasi.txt
test.txt
timecalc.template.conf
timecalc.conf
focus.txt
dist/*

View File

@ -32,7 +32,6 @@ public class TimeCalcProperties {
try {
String defaultConfiguration = Utils.readTextFromTextResourceInJar(
"timecalc-default.conf");
System.out.println("defaultConfiguration=" + defaultConfiguration);
Arrays.stream(defaultConfiguration.split("\n"))
.filter(l -> !l.trim().isEmpty())
.filter(l -> !l.trim().startsWith("#"))

View File

@ -20,6 +20,7 @@ import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
/**
* @author Robert Vokac
@ -32,6 +33,7 @@ public class Widget extends JPanel implements
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
public static final int CLOSE_BUTTON_SIDE = 15;
public StringProperty visibilityProperty =
new StringProperty("widget.visibilityProperty",
@ -46,17 +48,31 @@ public class Widget extends JPanel implements
protected int side = 0;
protected double donePercent = 0;
protected boolean mouseOver = false;
protected boolean mouseOverCloseButton = false;
protected JLabel smileyIcon;
public Widget() {
setBackground(BACKGROUND_COLOR);
new Timer(getTimerDelay(), e -> repaint()).start();
this.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void mouseMoved(MouseEvent e) {
int x=e.getX();
int y=e.getY();
mouseOverCloseButton = x >= getWidth() - CLOSE_BUTTON_SIDE && y <= CLOSE_BUTTON_SIDE;
}
});
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
if(x >= getWidth() - 15 && y <= 15) {
if(mouseOverCloseButton) {
visibleProperty.setValue(false);
return;
}
@ -125,14 +141,15 @@ public class Widget extends JPanel implements
Visibility.valueOf(visibilityProperty.getValue());
this.setVisible(visibility != Visibility.NONE);
paintWidget(brush);
if (mouseOver) {
if (mouseOver && mouseOverCloseButton) {
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
brush.fillOval(getWidth() - 15 - 1 ,0 + 1,15,15);
brush.fillOval(getWidth() - CLOSE_BUTTON_SIDE - 1 , 0 + 1,CLOSE_BUTTON_SIDE,CLOSE_BUTTON_SIDE);
brush.setColor(Color.LIGHT_GRAY);
Graphics2D brush2d = (Graphics2D) brush;
brush2d.setStroke(new BasicStroke(2f));
brush.drawLine(getWidth() - 15 - 1 + 2 ,0 + 1 + 2, getWidth() - 0 * 15 - 1 - 2 ,0 + 15 + 1 - 2);
brush.drawLine(getWidth() - 15 - 1 + 2, 0 + 15 + 1 - 2, getWidth() - 0 * 15 - 1 - 2 ,0 + 1 + 2);
brush.drawLine(getWidth() - CLOSE_BUTTON_SIDE - 1 + 2 ,0 + 1 + 2, getWidth() - 0 * CLOSE_BUTTON_SIDE - 1 - 2 ,0 + CLOSE_BUTTON_SIDE + 1 - 2);
brush.drawLine(getWidth() - CLOSE_BUTTON_SIDE - 1 + 2, 0 + CLOSE_BUTTON_SIDE + 1 - 2, getWidth() - 0 * CLOSE_BUTTON_SIDE - 1 - 2 ,0 + 1 + 2);
}
}

View File

@ -1,12 +0,0 @@
#Thu Feb 29 09:38:02 CET 2024
commands.visible=true
smileys.colored=true
visibility.default=STRONGLY_COLORED
clock.hands.millisecond.visible=false
visibility.supported.colored=true
jokes.visible=true
clock.hands.second.visible=true
notifications.visible=true
battery.waves.visible=true
clock.hands.minute.visible=true
clock.hands.long.visible=true