ConfigWindow VIII
This commit is contained in:
parent
c56e3be383
commit
6e92cf26fd
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,6 +13,6 @@ proxy.txt
|
||||
out.txt
|
||||
pocasi.txt
|
||||
test.txt
|
||||
timecalc.conf
|
||||
timecalc.template.conf
|
||||
focus.txt
|
||||
dist/*
|
||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
@ -51,6 +52,8 @@ public class TimeCalcConfiguration {
|
||||
|
||||
private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>();
|
||||
private List<Property> allProperties = new ArrayList<>();
|
||||
private TimeCalcProperties timeCalcProperties;
|
||||
|
||||
public TimeCalcConfiguration() {
|
||||
for(Property p:new Property[] {
|
||||
visibilityDefaultProperty,
|
||||
@ -77,8 +80,18 @@ public class TimeCalcConfiguration {
|
||||
return mapOfProperties.get(timeCalcProperty);
|
||||
}
|
||||
|
||||
public void setFromTimeCalcProperties(
|
||||
public void saveToTimeCalcProperties() {
|
||||
if(timeCalcProperties == null) {
|
||||
throw new TimeCalcException("Cannot save properties, because timeCalcProperties is null.");
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
this.allProperties.stream().forEach(p -> properties.put(p.getName(), p.getValue()));
|
||||
this.timeCalcProperties.save(properties);
|
||||
|
||||
}
|
||||
public void loadFromTimeCalcProperties(
|
||||
TimeCalcProperties timeCalcProperties) {
|
||||
this.timeCalcProperties = timeCalcProperties;
|
||||
for(Property p:allProperties) {
|
||||
if(p instanceof BooleanProperty) {
|
||||
((BooleanProperty)p).setValue(timeCalcProperties.getBooleanProperty(TimeCalcProperty.forKey(p.getName())));
|
||||
|
@ -5,6 +5,7 @@ import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -17,12 +18,13 @@ import java.util.Properties;
|
||||
*/
|
||||
public class TimeCalcProperties {
|
||||
|
||||
public static final File FILE = new File("timecalc.conf");
|
||||
private static TimeCalcProperties INSTANCE;
|
||||
private final Properties properties = new Properties();
|
||||
private final Map<String, String> defaultProperties = new HashMap<>();
|
||||
|
||||
private TimeCalcProperties() {
|
||||
if (!new File("timecalc.conf").exists()) {
|
||||
if (!FILE.exists()) {
|
||||
//nothing to do;
|
||||
return;
|
||||
}
|
||||
@ -110,11 +112,14 @@ public class TimeCalcProperties {
|
||||
properties.replace(key, value.name());
|
||||
}
|
||||
|
||||
public void load() {
|
||||
//to be implemented
|
||||
}
|
||||
|
||||
public void save() {
|
||||
//to be implemented
|
||||
public void save(Properties properties) {
|
||||
properties.entrySet().stream().forEach(e-> this.properties.replace(e.getKey(), e.getValue().toString()));
|
||||
try {
|
||||
this.properties.store(new FileOutputStream(FILE), null);
|
||||
System.out.println("Saving to " + FILE + " was successful");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Saving to " + FILE + " failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,48 +121,49 @@ public class ConfigWindow extends TimeCalcWindow {
|
||||
|
||||
Arrays.stream(getComponents()).forEach(c->c.getClass().getName());
|
||||
ConfigWindow configWindow = this;
|
||||
class ConfigThread implements Runnable {
|
||||
public final AtomicBoolean stopped = new AtomicBoolean();
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
if (stopped.get()) {
|
||||
break;
|
||||
}
|
||||
if (!configWindow.visibilitySupportedColoredProperty
|
||||
.isSelected()
|
||||
&& configWindow.visibilityDefaultProperty.isEnabled()) {
|
||||
configWindow.visibilityDefaultProperty.disable();
|
||||
}
|
||||
if (configWindow.visibilitySupportedColoredProperty
|
||||
.isSelected()
|
||||
&& !configWindow.visibilityDefaultProperty
|
||||
.isEnabled()) {
|
||||
configWindow.visibilityDefaultProperty.enable();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigThread configThread = new ConfigThread();
|
||||
Thread thread = new Thread(configThread);
|
||||
|
||||
thread.start();
|
||||
// class ConfigThread implements Runnable {
|
||||
// public final AtomicBoolean stopped = new AtomicBoolean();
|
||||
//
|
||||
// public void run() {
|
||||
// while (true) {
|
||||
// if (stopped.get()) {
|
||||
// System.out.println("stopping thread");
|
||||
// break;
|
||||
// }
|
||||
// if (!configWindow.visibilitySupportedColoredProperty
|
||||
// .isSelected()
|
||||
// && configWindow.visibilityDefaultProperty.isEnabled()) {
|
||||
// configWindow.visibilityDefaultProperty.disable();
|
||||
// }
|
||||
// if (configWindow.visibilitySupportedColoredProperty
|
||||
// .isSelected()
|
||||
// && !configWindow.visibilityDefaultProperty
|
||||
// .isEnabled()) {
|
||||
// configWindow.visibilityDefaultProperty.enable();
|
||||
// }
|
||||
// }
|
||||
// try {
|
||||
// Thread.sleep(100);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// System.out.println(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ConfigThread configThread = new ConfigThread();
|
||||
// Thread thread = new Thread(configThread);
|
||||
//
|
||||
// thread.start();
|
||||
addWindowListener(new WindowAdapter() {
|
||||
//for closing
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
//configThread.stopped.set(true);
|
||||
}
|
||||
//for closed
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
configThread.stopped.set(true);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -63,11 +63,12 @@ public class MainWindow extends TimeCalcWindow{
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
timeCalcConfiguration.saveToTimeCalcProperties();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
timeCalcConfiguration
|
||||
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
.loadFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
|
||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||
Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||
@ -319,6 +320,7 @@ public class MainWindow extends TimeCalcWindow{
|
||||
if(activitiesWindow != null) {activitiesWindow.setVisible(false);activitiesWindow.dispose();}
|
||||
if(helpWindow != null) {helpWindow.setVisible(false);helpWindow.dispose();}
|
||||
|
||||
timeCalcConfiguration.saveToTimeCalcProperties();
|
||||
setVisible(false);
|
||||
dispose();
|
||||
|
||||
@ -434,6 +436,7 @@ public class MainWindow extends TimeCalcWindow{
|
||||
if(activitiesWindow != null) {activitiesWindow.setVisible(false);activitiesWindow.dispose();}
|
||||
if(helpWindow != null) {helpWindow.setVisible(false);helpWindow.dispose();}
|
||||
|
||||
timeCalcConfiguration.saveToTimeCalcProperties();
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ public class Battery extends Widget {
|
||||
private final String name;
|
||||
private final double[] randomDoubles =
|
||||
new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
|
||||
public BooleanProperty wavesProperty = new BooleanProperty("waves", true);
|
||||
public BooleanProperty wavesProperty = new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE
|
||||
.getKey(), true);
|
||||
private final BooleanProperty blinking = new BooleanProperty("blinking");
|
||||
private long tmpNanoTime = 0l;
|
||||
private int totalHeight = 0;
|
||||
|
@ -1,34 +1,29 @@
|
||||
visibility.default=STRONGLY_COLORED
|
||||
visibility.supported.colored=false
|
||||
#
|
||||
clock.hands.long.visible=true
|
||||
clock.hands.minute.visible=true
|
||||
clock.hands.second.visible=true
|
||||
clock.hands.millisecond.visible=false
|
||||
#
|
||||
battery.waves.visible=true
|
||||
#
|
||||
jokes.visible=true
|
||||
commands.visible=true
|
||||
notifications.visible=true
|
||||
smileys.colored=false
|
||||
|
||||
#todo
|
||||
logs.detailed=false
|
||||
smileys.visible=true
|
||||
battery.smileys.visible=true
|
||||
square.smileys.visible=true
|
||||
circle.smileys.visible=true
|
||||
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
|
||||
battery.hour.visible=true
|
||||
battery.day.visible=true
|
||||
battery.week.visible=true
|
||||
battery.month.visible=true
|
||||
|
||||
#Wed Feb 28 12:20:58 CET 2024
|
||||
battery.charging-unicode-character.visible=true
|
||||
battery.week.visible=true
|
||||
smileys.colored=false
|
||||
circle.smileys.visible=true
|
||||
notifications.visible=true
|
||||
clock.hands.second.visible=true
|
||||
battery.hour.visible=true
|
||||
widgets.clock.visible=true
|
||||
battery.visible=true
|
||||
clock.hands.millisecond.visible=false
|
||||
commands.visible=true
|
||||
battery.percent-precision.count-of-decimal-points=5
|
||||
visibility.supported.colored=false
|
||||
jokes.visible=true
|
||||
visibility.default=GRAY
|
||||
square.smileys.visible=true
|
||||
battery.month.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
|
||||
|
34
timecalc.template.conf
Normal file
34
timecalc.template.conf
Normal file
@ -0,0 +1,34 @@
|
||||
visibility.default=STRONGLY_COLORED
|
||||
visibility.supported.colored=false
|
||||
#
|
||||
clock.hands.long.visible=true
|
||||
clock.hands.minute.visible=true
|
||||
clock.hands.second.visible=true
|
||||
clock.hands.millisecond.visible=false
|
||||
#
|
||||
battery.waves.visible=true
|
||||
#
|
||||
jokes.visible=true
|
||||
commands.visible=true
|
||||
notifications.visible=true
|
||||
smileys.colored=false
|
||||
|
||||
#todo
|
||||
logs.detailed=false
|
||||
smileys.visible=true
|
||||
battery.smileys.visible=true
|
||||
square.smileys.visible=true
|
||||
circle.smileys.visible=true
|
||||
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
|
||||
battery.hour.visible=true
|
||||
battery.day.visible=true
|
||||
battery.week.visible=true
|
||||
battery.month.visible=true
|
||||
|
Loading…
x
Reference in New Issue
Block a user