Added ProgressRotation

This commit is contained in:
Robert Vokac 2024-04-18 17:32:29 +02:00
parent e20cf1d428
commit e74f63b6b5
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
5 changed files with 232 additions and 6 deletions

View File

@ -56,6 +56,6 @@ echo ... 4. Moving new jar file to dist directory
mv ./modules/time-calc-app/target/time-calc-app-$ORIG_VERSION-jar-with-all-dependencies.jar ./dist/time-calc-$VERSION.jar
rm ./modules/time-calc-app/target/time-calc-app-$ORIG_VERSION.jar
cp ./dist/time-calc-$VERSION.jar C:/Users/user/Desktop/rv
#cp ./dist/time-calc-$VERSION.jar C:/Users/user/Desktop/rv

View File

@ -0,0 +1,27 @@
package org.nanoboot.utils.timecalc.app;
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.ActivityRepositorySQLiteImpl;
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.SqliteConnectionFactory;
import org.nanoboot.utils.timecalc.swing.progress.Time;
import org.nanoboot.utils.timecalc.swing.windows.ActivitiesWindow;
/**
* @author pc00289
* @since 05.04.2024
*/
public class ActivitiesMain {
public static void main(String[] args) {
TimeCalcConfiguration timeCalcConfiguration =
new TimeCalcConfiguration();
timeCalcConfiguration
.loadFromTimeCalcProperties(TimeCalcProperties.getInstance());
ActivitiesWindow activitiesWindow = new ActivitiesWindow(
new ActivityRepositorySQLiteImpl(new SqliteConnectionFactory()),
new Time(),
timeCalcConfiguration
);
activitiesWindow.setVisible(true);
;
}
}

View File

@ -1,15 +1,13 @@
package org.nanoboot.utils.timecalc.app;
import java.io.File;
import java.io.IOException;
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
/**
* @author Robert Vokac
* @since 31.01.2024
*/
public class Main {
private static final boolean ONLY_ACTIVITIES_WINDOW_IS_ALLOWED = false;
public static void main(String[] args) throws IOException {
// for(File f:FileConstants.CLIMATE_TXT.getParentFile().listFiles()) {
// if(f.getName().contains("weather")) {
@ -17,7 +15,11 @@ public class Main {
// f.delete();
// }
// }
TimeCalcApp timeCalcApp = new TimeCalcApp();
timeCalcApp.start(args);
if(ONLY_ACTIVITIES_WINDOW_IS_ALLOWED) {
ActivitiesMain.main(args);
} else {
TimeCalcApp timeCalcApp = new TimeCalcApp();
timeCalcApp.start(args);
}
}
}

View File

@ -0,0 +1,180 @@
package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Progress;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.entity.WidgetType;
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.swing.controls.TMenuItem;
import org.nanoboot.utils.timecalc.swing.progress.battery.Battery;
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.TTime;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
//https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
public class ProgressRotation extends Widget {
public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED
= new Color(226,
126, 19);
public final BooleanProperty borderVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE
.getKey());
public final BooleanProperty borderOnlyHoursProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS
.getKey());
public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE
.getKey());
public final BooleanProperty circleStrongBorderProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER
.getKey());
public final BooleanProperty centreCircleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE
.getKey());
public final StringProperty centreCircleBorderColorProperty
= new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR
.getKey());
public final BooleanProperty centreCircleColoredProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_COLORED
.getKey());
public BooleanProperty circleProgressVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE
.getKey(), true);
private Color customCircleColor = null;
private List<JMenuItem> menuItems = null;
public ProgressRotation() {
typeProperty.setValue(WidgetType.DAY.name().toLowerCase(Locale.ROOT));
setPreferredSize(new Dimension(100, 100));
centreCircleBorderColorProperty.addListener(property
-> customCircleColor = SwingUtils.getColorFromString(
centreCircleBorderColorProperty.getValue()));
}
public static void main(String[] args) {
JFrame window = new JFrame("Analog Clock");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ProgressRotation rotation
= new ProgressRotation();
window.add(rotation);
window.pack();
rotation.visibilityProperty.setValue(Visibility.GRAY.name());
window.setVisible(true);
}
private double angle = 0d;
@Override
public void paintWidget(Graphics g) {
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
Graphics2D brush = (Graphics2D) g;
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
this.side = Math.min(getWidth(), getHeight());
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
if (customCircleColor == null) {
customCircleColor = SwingUtils.getColorFromString(
centreCircleBorderColorProperty.getValue());
}
//
angle = angle + 0.001d * donePercent() * 50d;
if(angle > 1.0d) {
angle = 0.0d;
}
drawHand(brush, side / 2 - 10, angle, 1.0f,
COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility);
//brush.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(angle), 15, 15);
if (centreCircleVisibleProperty.isEnabled()) {
drawCentreCircle(brush, centerX, centerY);
}
if (progress == null) {
progress = new Progress();
}
if (circleProgressVisibleProperty.isEnabled()) {
paintCircleProgress(brush, visibility, getWidth(), getHeight());
}
}
private void drawCentreCircle(Graphics2D brush, int centerX, int centerY) {
Color currentColor = brush.getColor();
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
brush.setColor(visibility.isStronglyColored() || mouseOver
? (centreCircleColoredProperty.isEnabled() ? Color.RED : Color.BLACK)
: FOREGROUND_COLOR);
brush.fillOval(centerX - 3, centerY - 3, 8, 8);
brush.setColor(currentColor);
}
private void drawHand(Graphics2D brush, int length, double value,
float stroke, Color color, Visibility visibility) {
length = length - 4;
double angle = Math.PI * 2 * (value - 0.25);
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
brush.setColor((visibility.isStronglyColored() || mouseOver)
? Color.BLACK : FOREGROUND_COLOR);
brush.setStroke(new BasicStroke(stroke));
brush.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
}
public int getTimerDelay() {
return 1;
}
@Override
public List<JMenuItem> createAdditionalMenus() {
if (menuItems == null) {
menuItems = new ArrayList<>();
}
return this.menuItems;
}
protected Consumer<Object> createRefreshConsumer() {
return (o) -> {
};
}
}

View File

@ -27,6 +27,7 @@ import org.nanoboot.utils.timecalc.swing.controls.TLabel;
import org.nanoboot.utils.timecalc.swing.controls.TTextField;
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
import org.nanoboot.utils.timecalc.swing.progress.ProgressRotation;
import org.nanoboot.utils.timecalc.swing.progress.battery.Battery;
import org.nanoboot.utils.timecalc.swing.progress.battery.DayBattery;
import org.nanoboot.utils.timecalc.swing.progress.battery.HourBattery;
@ -120,6 +121,7 @@ public class MainWindow extends TWindow {
private final ProgressMoney progressMoney;
private final ProgressWeather progressWeather;
private final ProgressFuelGauge progressFuelGauge;
private final ProgressRotation progressRotation;
private HelpWindow helpWindow = null;
private ConfigWindow configWindow = null;
private ActivitiesWindow activitiesWindow = null;
@ -435,6 +437,20 @@ public class MainWindow extends TWindow {
.bindTo(timeCalcConfiguration.fuelIconVisibleProperty);
add(progressFuelGauge);
//
this.progressRotation = new ProgressRotation();
progressRotation.setBounds(progressFuelGauge.getX() + progressFuelGauge.getWidth() + SwingUtils.MARGIN, progressFuelGauge.getY(),
100, 100);
progressRotation.visibleProperty
.bindTo(timeCalcConfiguration.fuelVisibleProperty);
progressRotation.typeProperty
.bindTo(timeCalcConfiguration.fuelTypeProperty);
progressRotation.hiddenProperty
.bindTo(timeCalcConfiguration.fuelHiddenProperty);
add(progressRotation);
//
{
progressSquare.typeProperty
@ -1310,6 +1326,7 @@ public class MainWindow extends TWindow {
progressMoney.setProgress(progress);
progressDot.setProgress(progress);
progressFuelGauge.setProgress(progress);
progressRotation.setProgress(progress);
dayBattery.setProgress(progress);
monthBattery.setProgress(progress);