Added close button for widgets I

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

View File

@ -49,6 +49,8 @@ public class TimeCalcConfiguration {
.getKey());
public final BooleanProperty smileysColoredProperty =
new BooleanProperty(TimeCalcProperty.SMILEYS_COLORED.getKey());
public final BooleanProperty squareVisibleProperty =
new BooleanProperty(TimeCalcProperty.SQUARE_VISIBLE.getKey());
private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>();
private List<Property> allProperties = new ArrayList<>();
@ -67,6 +69,7 @@ public class TimeCalcConfiguration {
commandsVisibleProperty,
notificationsVisibleProperty,
smileysColoredProperty,
squareVisibleProperty,
}) {
allProperties.add(p);
}
@ -81,6 +84,7 @@ public class TimeCalcConfiguration {
}
public void saveToTimeCalcProperties() {
System.out.println("Going to save properties.");
if(timeCalcProperties == null) {
throw new TimeCalcException("Cannot save properties, because timeCalcProperties is null.");
}

View File

@ -24,10 +24,6 @@ public class TimeCalcProperties {
private final Map<String, String> defaultProperties = new HashMap<>();
private TimeCalcProperties() {
if (!FILE.exists()) {
//nothing to do;
return;
}
try {
this.properties.load(new FileInputStream("timecalc.conf"));
} catch (IOException e) {
@ -36,6 +32,7 @@ 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("#"))
@ -64,8 +61,8 @@ public class TimeCalcProperties {
getDefaultStringValue(timeCalcProperty)));
}
private String getDefaultStringValue(TimeCalcProperty timeCalcProperty) {
if(!defaultProperties.containsKey(timeCalcProperty.getKey())) {
throw new TimeCalcException("timecalc-default.conf is missing key: " + timeCalcProperty.getKey());
if(!defaultProperties.containsKey((String)timeCalcProperty.getKey())) {
throw new TimeCalcException("timecalc-default.conf is missing key: \"" + timeCalcProperty.getKey() + "\"");
}
return defaultProperties.get(timeCalcProperty.getKey());
}
@ -113,7 +110,17 @@ public class TimeCalcProperties {
}
public void save(Properties properties) {
properties.entrySet().stream().forEach(e-> this.properties.replace(e.getKey(), e.getValue().toString()));
properties.entrySet().stream().forEach(e ->
{
if (this.properties.containsKey(e.getKey())) {
this.properties
.replace(e.getKey(), e.getValue().toString());
} else {
this.properties
.put(e.getKey(), e.getValue().toString());
}
}
);
try {
this.properties.store(new FileOutputStream(FILE), null);
System.out.println("Saving to " + FILE + " was successful");

View File

@ -27,7 +27,9 @@ public enum TimeCalcProperty {
JOKES_VISIBLE("jokes.visible", "Jokes"),
COMMANDS_VISIBLE("commands.visible", "Commands"),
NOTIFICATIONS_VISIBLE("notifications.visible", "Notifications"),
SMILEYS_COLORED("smileys.colored", "Smileys : Colored");
SMILEYS_COLORED("smileys.colored", "Smileys : Colored"),
SQUARE_VISIBLE("square.visible", "Square");
@Getter
private final String key;

View File

@ -56,6 +56,8 @@ public class ConfigWindow extends TWindow {
new JCheckBox("notifications.visible");
private JCheckBox smileysColoredProperty =
new JCheckBox("smileys.colored");
private JCheckBox squareVisibleProperty =
new JCheckBox("square.visible");
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcConfiguration = timeCalcConfiguration;
@ -73,7 +75,8 @@ public class ConfigWindow extends TWindow {
jokesVisibleProperty,
commandsVisibleProperty,
notificationsVisibleProperty,
smileysColoredProperty));
smileysColoredProperty,
squareVisibleProperty));
//
propertiesList.stream().forEach(p -> {
if(p == visibilityDefaultProperty) {

View File

@ -133,6 +133,7 @@ public class MainWindow extends TWindow {
.setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(),
200);
add(progressSquare);
progressSquare.visibleProperty.bindTo(timeCalcConfiguration.squareVisibleProperty);
ProgressCircle progressCircle = new ProgressCircle();
progressCircle
@ -340,7 +341,7 @@ public class MainWindow extends TWindow {
if(activitiesWindow != null) {activitiesWindow.setVisible(false);activitiesWindow.dispose();}
if(helpWindow != null) {helpWindow.setVisible(false);helpWindow.dispose();}
//timeCalcConfiguration.saveToTimeCalcProperties();
timeCalcConfiguration.saveToTimeCalcProperties();
setVisible(false);
dispose();

View File

@ -1,5 +1,7 @@
package org.nanoboot.utils.timecalc.swing.common;
import java.awt.Color;
/**
* @author Robert
* @since 26.02.2024
@ -9,4 +11,6 @@ public class SwingUtils {
//Not meant to be instantiated.
}
public static final int MARGIN = 10;
public static final Color
CLOSE_BUTTON_BACKGROUND_COLOR = new Color(127,127,127);
}

View File

@ -12,10 +12,12 @@ import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@ -30,6 +32,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 StringProperty visibilityProperty =
new StringProperty("widget.visibilityProperty",
Visibility.STRONGLY_COLORED.name());
@ -37,6 +40,8 @@ public class Widget extends JPanel implements
new BooleanProperty("smileysColoredProperty", true);
public final BooleanProperty visibilitySupportedColoredProperty =
new BooleanProperty("visibilitySupportedColoredProperty", true);
public final BooleanProperty visibleProperty =
new BooleanProperty("visibleProperty", true);
protected int side = 0;
protected double donePercent = 0;
@ -49,6 +54,13 @@ public class Widget extends JPanel implements
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
int x=e.getX();
int y=e.getY();
if(x >= getWidth() - 15 && y <= 15) {
visibleProperty.setValue(false);
return;
}
if(visibilitySupportedColoredProperty.isDisabled()) {
//nothing to do
return;
@ -105,13 +117,23 @@ public class Widget extends JPanel implements
}
@Override
public final void paintComponent(Graphics g) {
super.paintComponent(g);
public final void paintComponent(Graphics brush) {
super.paintComponent(brush);
setVisible(visibleProperty.isEnabled());
Visibility visibility =
Visibility.valueOf(visibilityProperty.getValue());
this.setVisible(visibility != Visibility.NONE);
paintWidget(g);
paintWidget(brush);
if (mouseOver) {
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
brush.fillOval(getWidth() - 15 - 1 ,0 + 1,15,15);
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);
}
}

View File

@ -12,6 +12,7 @@ jokes.visible=true
commands.visible=true
notifications.visible=true
smileys.colored=true
square.visible=true
#todo
logs.detailed=false
@ -23,7 +24,6 @@ battery.charging-unicode-character.visible=true
battery.percent-precision.count-of-decimal-points=5
battery.label.finished-from-total.visible=true
widgets.clock.visible=true
square.visible=true
circle.visible=true
walking-human.visible=true
battery.visible=true

View File

@ -1,29 +1,12 @@
#Thu Feb 29 07:17:51 CET 2024
battery.charging-unicode-character.visible=true
battery.week.visible=true
smileys.colored=true
circle.smileys.visible=true
notifications.visible=false
clock.hands.second.visible=true
battery.hour.visible=true
widgets.clock.visible=true
battery.visible=true
clock.hands.millisecond.visible=false
#Thu Feb 29 09:38:02 CET 2024
commands.visible=true
battery.percent-precision.count-of-decimal-points=5
smileys.colored=true
visibility.default=STRONGLY_COLORED
clock.hands.millisecond.visible=false
visibility.supported.colored=true
jokes.visible=true
visibility.default=STRONGLY_COLORED
square.smileys.visible=true
battery.month.visible=true
clock.hands.second.visible=true
notifications.visible=true
battery.waves.visible=true
battery.day.visible=true
battery.smileys.visible=true
clock.hands.minute.visible=true
circle.visible=true
logs.detailed=false
clock.hands.long.visible=true
square.visible=true
walking-human.visible=true
battery.label.finished-from-total.visible=true
smileys.visible=true