Added new improvements
This commit is contained in:
parent
1ad3ad3e6a
commit
b08a45a5b9
@ -0,0 +1,85 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 26.02.2024
|
||||
*/
|
||||
public class CommandActionListener
|
||||
implements ActionListener {
|
||||
private final TimeCalcApp timeCalcApp;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
|
||||
public CommandActionListener(TimeCalcApp timeCalcApp, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
this.timeCalcApp = timeCalcApp;
|
||||
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String commands = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Run a command:",
|
||||
"Command launching",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
"test"
|
||||
);
|
||||
String[] commandsAsArray = commands.split(" ");
|
||||
switch (commandsAsArray[0]) {
|
||||
case "test":
|
||||
JOptionPane.showMessageDialog(null, "Test");
|
||||
break;
|
||||
case "color":
|
||||
timeCalcApp.visibilityProperty.setValue(
|
||||
commandsAsArray[1].equals("1") ?
|
||||
Visibility.STRONGLY_COLORED.name() :
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
break;
|
||||
case "gray":
|
||||
timeCalcApp.visibilityProperty.setValue(
|
||||
commandsAsArray[1].equals("1") ?
|
||||
Visibility.GRAY.name() :
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
break;
|
||||
case "waves":
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
case "uptime":
|
||||
JOptionPane.showMessageDialog(null,
|
||||
timeCalcApp
|
||||
.getCountOfMinutesSinceAppStarted()
|
||||
+ " minutes");
|
||||
break;
|
||||
case "toast":
|
||||
Toaster t = new Toaster();
|
||||
t.setToasterWidth(800);
|
||||
t.setToasterHeight(800);
|
||||
t.setDisplayTime(60000 * 5);
|
||||
t.setToasterColor(Color.GRAY);
|
||||
Font font = new Font("sans", Font.PLAIN, 12);
|
||||
t.setToasterMessageFont(font);
|
||||
t.setDisplayTime(5000);
|
||||
t.showToaster(commands.substring(6));
|
||||
break;
|
||||
case "toasts":
|
||||
Utils.toastsAreEnabled
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
default:
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Unknown command: " + commandsAsArray[0]);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 26.02.2024
|
||||
*/
|
||||
public interface GetProperty<T> {
|
||||
Property<T> getProperty();
|
||||
}
|
@ -25,10 +25,8 @@ import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JOptionPane;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -135,65 +133,7 @@ public class TimeCalcManager {
|
||||
|
||||
weatherButton
|
||||
.addActionListener(e -> new WeatherWindow().setVisible(true));
|
||||
commandButton
|
||||
.addActionListener(e ->
|
||||
{
|
||||
String commands = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Run a command:",
|
||||
"Command launching",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
"test"
|
||||
);
|
||||
String[] commandsAsArray = commands.split(" ");
|
||||
switch (commandsAsArray[0]) {
|
||||
case "test":
|
||||
JOptionPane.showMessageDialog(null, "Test");
|
||||
break;
|
||||
case "color":
|
||||
timeCalcApp.visibilityProperty.setValue(
|
||||
commandsAsArray[1].equals("1") ?
|
||||
Visibility.STRONGLY_COLORED.name() :
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
break;
|
||||
case "gray":
|
||||
timeCalcApp.visibilityProperty.setValue(
|
||||
commandsAsArray[1].equals("1") ?
|
||||
Visibility.GRAY.name() :
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
break;
|
||||
case "waves":
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
case "uptime":
|
||||
JOptionPane.showMessageDialog(null,
|
||||
timeCalcApp
|
||||
.getCountOfMinutesSinceAppStarted()
|
||||
+ " minutes");
|
||||
break;
|
||||
case "toast":
|
||||
Toaster t = new Toaster();
|
||||
t.setToasterWidth(800);
|
||||
t.setToasterHeight(800);
|
||||
t.setDisplayTime(60000 * 5);
|
||||
t.setToasterColor(Color.GRAY);
|
||||
Font font = new Font("sans", Font.PLAIN, 12);
|
||||
t.setToasterMessageFont(font);
|
||||
t.setDisplayTime(5000);
|
||||
t.showToaster(commands.substring(6));
|
||||
break;
|
||||
case "toasts":
|
||||
Utils.toastsAreEnabled
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
default:
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Unknown command: " + commandsAsArray[0]);
|
||||
}
|
||||
});
|
||||
commandButton.addActionListener(new CommandActionListener(timeCalcApp, timeCalcConfiguration));
|
||||
|
||||
jokeButton.addActionListener(e -> {
|
||||
for (int i = 1; i <= 1; i++) {
|
||||
@ -345,15 +285,6 @@ public class TimeCalcManager {
|
||||
weekBattery.getY(), 140);
|
||||
window.add(monthBattery);
|
||||
|
||||
hourBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
dayBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
weekBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
monthBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
|
||||
ComponentRegistry<JComponent> componentRegistry = new ComponentRegistry();
|
||||
componentRegistry.addAll(
|
||||
walkingHumanProgressAsciiArt,
|
||||
@ -371,75 +302,36 @@ public class TimeCalcManager {
|
||||
exitButton
|
||||
);
|
||||
ComponentRegistry<TimeCalcButton> buttonRegistry = new ComponentRegistry();
|
||||
for(Component c:componentRegistry.getSet()) {
|
||||
if(c instanceof TimeCalcButton) {
|
||||
buttonRegistry.add((TimeCalcButton)c);
|
||||
}
|
||||
}
|
||||
walkingHumanProgressAsciiArt.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressSquare.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressCircle.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
analogClock.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
dayBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
weekBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
monthBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
hourBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
configButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
jokeButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
commandButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof TimeCalcButton).forEach(c->
|
||||
buttonRegistry.add((TimeCalcButton)c));
|
||||
componentRegistry.getSet().stream().filter(c ->
|
||||
GetProperty.class.isAssignableFrom(c.getClass())).forEach(c->
|
||||
((GetProperty<String>)c).getProperty().bindTo(timeCalcApp.visibilityProperty));
|
||||
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof Battery).forEach(c ->
|
||||
((Battery)c).wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty));
|
||||
|
||||
window.setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN,
|
||||
exitButton.getY() + 3 * exitButton.getHeight() + SwingUtils.MARGIN);
|
||||
while (true) {
|
||||
Visibility visibility = Visibility
|
||||
Visibility currentVisibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled() && visibility.isColored() ){
|
||||
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled() && currentVisibility.isColored() ){
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
//time.writeString();
|
||||
if (stopBeforeEnd) {
|
||||
window.setVisible(false);
|
||||
window.dispose();
|
||||
break;
|
||||
}
|
||||
|
||||
componentRegistry.setVisible(currentVisibility.isNotNone());
|
||||
|
||||
componentRegistry.setVisible(visibility.isNotNone());
|
||||
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||
configButton.setBackground(BACKGROUND_COLOR);
|
||||
jokeButton.setBackground(BACKGROUND_COLOR);
|
||||
commandButton.setBackground(BACKGROUND_COLOR);
|
||||
restartButton.setBackground(BACKGROUND_COLOR);
|
||||
exitButton.setBackground(BACKGROUND_COLOR);
|
||||
|
||||
configButton.setForeground(FOREGROUND_COLOR);
|
||||
jokeButton.setForeground(FOREGROUND_COLOR);
|
||||
commandButton.setForeground(FOREGROUND_COLOR);
|
||||
restartButton.setForeground(FOREGROUND_COLOR);
|
||||
exitButton.setForeground(FOREGROUND_COLOR);
|
||||
} else {
|
||||
configButton.setOriginalBackground();
|
||||
jokeButton.setOriginalBackground();
|
||||
commandButton.setOriginalBackground();
|
||||
restartButton.setOriginalBackground();
|
||||
exitButton.setOriginalBackground();
|
||||
//
|
||||
configButton.setOriginalForeground();
|
||||
jokeButton.setOriginalForeground();
|
||||
commandButton.setOriginalForeground();
|
||||
restartButton.setOriginalForeground();
|
||||
exitButton.setOriginalForeground();
|
||||
}
|
||||
jokeButton.setVisible(
|
||||
TimeCalcProperties.getInstance().areJokesEnabled()
|
||||
&& !visibility.isNone());
|
||||
&& !currentVisibility.isNone());
|
||||
|
||||
window.setTitle(visibility.isNone() ? "" : windowTitle);
|
||||
window.setTitle(currentVisibility.isNone() ? "" : windowTitle);
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String nowString =
|
||||
@ -546,7 +438,7 @@ public class TimeCalcManager {
|
||||
}
|
||||
|
||||
walkingHumanProgressAsciiArt.setForeground(
|
||||
visibility.isStronglyColored()
|
||||
currentVisibility.isStronglyColored()
|
||||
|| walkingHumanProgressAsciiArt
|
||||
.getClientProperty("mouseEntered").equals("true") ?
|
||||
Color.BLACK : Color.LIGHT_GRAY);
|
||||
|
@ -1,6 +1,9 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import javax.swing.JButton;
|
||||
@ -12,7 +15,7 @@ import java.awt.Color;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class TimeCalcButton extends JButton {
|
||||
public class TimeCalcButton extends JButton implements GetProperty {
|
||||
private static final int BUTTON_WIDTH = 100;
|
||||
private static final int BUTTON_HEIGHT = 30;
|
||||
public StringProperty visibilityProperty =
|
||||
@ -23,7 +26,18 @@ public class TimeCalcButton extends JButton {
|
||||
|
||||
public TimeCalcButton(String label) {
|
||||
super(label);
|
||||
new Timer(100, e -> setVisible(Visibility.valueOf(visibilityProperty.getValue()).isNotNone())).start();
|
||||
new Timer(100, e -> {
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
setVisible(visibility.isNotNone());
|
||||
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||
setBackground(TimeCalcManager.BACKGROUND_COLOR);
|
||||
setForeground(TimeCalcManager.FOREGROUND_COLOR);
|
||||
} else {
|
||||
setOriginalBackground();
|
||||
setOriginalForeground();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y) {
|
||||
@ -48,4 +62,9 @@ public class TimeCalcButton extends JButton {
|
||||
+ jComponent.getHeight()
|
||||
+ SwingUtils.MARGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty() {
|
||||
return visibilityProperty;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
@ -15,7 +17,8 @@ import java.awt.event.MouseListener;
|
||||
* @author Robert Vokac
|
||||
* @since 20.02.2024
|
||||
*/
|
||||
public class Widget extends JPanel {
|
||||
public class Widget extends JPanel implements
|
||||
GetProperty {
|
||||
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
|
||||
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
@ -98,4 +101,9 @@ public class Widget extends JPanel {
|
||||
|
||||
protected void paintWidget(Graphics g) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty() {
|
||||
return visibilityProperty;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
@ -7,6 +8,7 @@ import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@ -25,7 +27,8 @@ import java.util.Set;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class WalkingHumanProgressAsciiArt extends JTextPane {
|
||||
public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
||||
GetProperty {
|
||||
private static final String WALL = "||";
|
||||
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
||||
public StringProperty visibilityProperty =
|
||||
@ -184,4 +187,8 @@ public class WalkingHumanProgressAsciiArt extends JTextPane {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getProperty() {
|
||||
return visibilityProperty;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user