mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added close button for widgets II
This commit is contained in:
parent
416fdf1ae2
commit
9ca7d18fff
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,6 +13,6 @@ proxy.txt
|
|||||||
out.txt
|
out.txt
|
||||||
pocasi.txt
|
pocasi.txt
|
||||||
test.txt
|
test.txt
|
||||||
timecalc.template.conf
|
timecalc.conf
|
||||||
focus.txt
|
focus.txt
|
||||||
dist/*
|
dist/*
|
||||||
|
@ -32,7 +32,6 @@ public class TimeCalcProperties {
|
|||||||
try {
|
try {
|
||||||
String defaultConfiguration = Utils.readTextFromTextResourceInJar(
|
String defaultConfiguration = Utils.readTextFromTextResourceInJar(
|
||||||
"timecalc-default.conf");
|
"timecalc-default.conf");
|
||||||
System.out.println("defaultConfiguration=" + defaultConfiguration);
|
|
||||||
Arrays.stream(defaultConfiguration.split("\n"))
|
Arrays.stream(defaultConfiguration.split("\n"))
|
||||||
.filter(l -> !l.trim().isEmpty())
|
.filter(l -> !l.trim().isEmpty())
|
||||||
.filter(l -> !l.trim().startsWith("#"))
|
.filter(l -> !l.trim().startsWith("#"))
|
||||||
|
@ -20,6 +20,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @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 Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
|
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
|
||||||
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
|
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
|
||||||
|
public static final int CLOSE_BUTTON_SIDE = 15;
|
||||||
|
|
||||||
public StringProperty visibilityProperty =
|
public StringProperty visibilityProperty =
|
||||||
new StringProperty("widget.visibilityProperty",
|
new StringProperty("widget.visibilityProperty",
|
||||||
@ -46,17 +48,31 @@ public class Widget extends JPanel implements
|
|||||||
protected int side = 0;
|
protected int side = 0;
|
||||||
protected double donePercent = 0;
|
protected double donePercent = 0;
|
||||||
protected boolean mouseOver = false;
|
protected boolean mouseOver = false;
|
||||||
|
protected boolean mouseOverCloseButton = false;
|
||||||
protected JLabel smileyIcon;
|
protected JLabel smileyIcon;
|
||||||
|
|
||||||
public Widget() {
|
public Widget() {
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
new Timer(getTimerDelay(), e -> repaint()).start();
|
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() {
|
addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
int x=e.getX();
|
|
||||||
int y=e.getY();
|
if(mouseOverCloseButton) {
|
||||||
if(x >= getWidth() - 15 && y <= 15) {
|
|
||||||
visibleProperty.setValue(false);
|
visibleProperty.setValue(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -125,14 +141,15 @@ public class Widget extends JPanel implements
|
|||||||
Visibility.valueOf(visibilityProperty.getValue());
|
Visibility.valueOf(visibilityProperty.getValue());
|
||||||
this.setVisible(visibility != Visibility.NONE);
|
this.setVisible(visibility != Visibility.NONE);
|
||||||
paintWidget(brush);
|
paintWidget(brush);
|
||||||
if (mouseOver) {
|
|
||||||
|
if (mouseOver && mouseOverCloseButton) {
|
||||||
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
|
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);
|
brush.setColor(Color.LIGHT_GRAY);
|
||||||
Graphics2D brush2d = (Graphics2D) brush;
|
Graphics2D brush2d = (Graphics2D) brush;
|
||||||
brush2d.setStroke(new BasicStroke(2f));
|
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() - CLOSE_BUTTON_SIDE - 1 + 2 ,0 + 1 + 2, getWidth() - 0 * CLOSE_BUTTON_SIDE - 1 - 2 ,0 + CLOSE_BUTTON_SIDE + 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 + CLOSE_BUTTON_SIDE + 1 - 2, getWidth() - 0 * CLOSE_BUTTON_SIDE - 1 - 2 ,0 + 1 + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
Loading…
x
Reference in New Issue
Block a user