diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java index 0a241c8..a3bdee7 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java @@ -224,6 +224,17 @@ public class TimeCalcConfiguration { = new StringProperty(TimeCalcProperty.BAR_TYPE.getKey()); public final IntegerProperty barHeightProperty = new IntegerProperty(TimeCalcProperty.BAR_HEIGHT.getKey()); + + + // + public final BooleanProperty colorVisibleProperty + = new BooleanProperty(TimeCalcProperty.COLOR_VISIBLE.getKey()); + public final BooleanProperty colorHiddenProperty + = new BooleanProperty(TimeCalcProperty.COLOR_HIDDEN.getKey()); + public final StringProperty colorTypeProperty + = new StringProperty(TimeCalcProperty.COLOR_TYPE.getKey()); + public final IntegerProperty colorHeightProperty + = new IntegerProperty(TimeCalcProperty.COLOR_HEIGHT.getKey()); // public final BooleanProperty walkingHumanVisibleProperty = new BooleanProperty( @@ -351,6 +362,7 @@ public class TimeCalcConfiguration { squareVisibleProperty,squareTypeProperty, circleVisibleProperty,circleTypeProperty,circleInnerCircleVisibleProperty,circleOuterCircleOnlyBorderProperty, barVisibleProperty, barTypeProperty, barHiddenProperty, barHeightProperty, + colorVisibleProperty, colorTypeProperty, colorHiddenProperty, colorHeightProperty, dotVisibleProperty,dotTypeProperty, fuelVisibleProperty, fuelTypeProperty, fuelHiddenProperty, fuelIconVisibleProperty, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java index 2444342..ab574f6 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java @@ -110,6 +110,11 @@ public enum TimeCalcProperty { BAR_HIDDEN("bar.hidden", "Bar : Hidden"), BAR_HEIGHT("bar.height", "Bar : Height", Integer.class), // + COLOR_VISIBLE("color.visible", "Color"), + COLOR_TYPE("color.type", "Color : Type"), + COLOR_HIDDEN("color.hidden", "Color : Hidden"), + COLOR_HEIGHT("color.height", "Color : Height", Integer.class), + // WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"), WALKING_HUMAN_TYPE("walking-human.type", "Walking Human : Type"), WALKING_HUMAN_HIDDEN("walking-human.hidden", "Walking Human : Hidden"), diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressColor.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressColor.java new file mode 100644 index 0000000..d0fa248 --- /dev/null +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressColor.java @@ -0,0 +1,85 @@ +package org.nanoboot.utils.timecalc.swing.progress; + +import org.nanoboot.utils.timecalc.entity.Visibility; +import org.nanoboot.utils.timecalc.swing.common.Widget; +import org.nanoboot.utils.timecalc.swing.progress.battery.Battery; +import org.nanoboot.utils.timecalc.utils.common.NumberFormats; +import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +public class ProgressColor extends Widget { + + public IntegerProperty heightProperty = new IntegerProperty("heightProperty", 50); + public ProgressColor() { + setPreferredSize(new Dimension(600, 50)); + } + + private final Map colorMap = new HashMap<>(); + + @Override + public void paintWidget(Graphics g) { + Visibility visibility + = Visibility.valueOf(visibilityProperty.getValue()); + Graphics2D brush = (Graphics2D) g; + boolean stronglyColored = visibility.isStronglyColored() || mouseOver; + int numberStart = 255; + int numberEnd = stronglyColored ? 0 : (visibility.isWeaklyColored() ? 128 : 192) ; + int numberDiff = numberStart - numberEnd; + int number = (int) (numberStart - donePercent() * numberDiff); + if(!colorMap.containsKey(number)) { + colorMap.put(number, new Color(number, number, number)); + } + Function colorReturnFunction = (n) -> { + if(!colorMap.containsKey(n)) { + colorMap.put(n, new Color(n, n, n)); + } + return colorMap.get(n); + }; + Color color = colorReturnFunction.apply(number); + Color colorStart = colorReturnFunction.apply(numberStart); + Color colorEnd = colorReturnFunction.apply(numberEnd); + brush.setColor(color); + brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + int progressWidth = (int) (getWidth() * 0.5); + //int remainsWidth = getWidth() - progressWidth; + + int h = heightProperty.getValue() > getHeight() ? getHeight() : + heightProperty.getValue(); +// if(h < 1) {h = 1;} + brush.fillRect(0, 0, getWidth(), h); + brush.setColor(colorStart); + int iii = (int) (getWidth() * 0.05d); + brush.fillRect(0, 0, iii, h); + brush.setColor(colorEnd); + brush.fillRect(getWidth() - iii, 0, iii, h); + brush.setColor(Color.BLUE); + brush.setStroke(new BasicStroke(1f)); + brush.drawLine(iii, 0 , iii, h); + brush.drawLine(getWidth() - iii, 0 , getWidth() - iii, h); +// brush.setColor( +// visibility.isStronglyColored() || mouseOver ? +// Battery.getColourForProgress(donePercent(), visibility, mouseOver)/*Color.darkGray*/ +// : FOREGROUND_COLOR); +// brush.fillRect(0, 0, progressWidth, h); + brush.setColor(h <= 15 || progressWidth < 40 ? (visibility.isStronglyColored() ? Color.BLACK : Color.GRAY) : Color.WHITE); + brush.drawString( + NumberFormats.FORMATTER_ONE_DECIMAL_PLACE + .format(number) + " (" + numberStart + "-" + numberEnd + ")", + (int) (progressWidth * 0.2d), + h <= 15 ? h + 15 : 15); + + + } + +} diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/ConfigWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/ConfigWindow.java index 019d0ae..8f9beb0 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/ConfigWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/ConfigWindow.java @@ -210,6 +210,15 @@ public class ConfigWindow extends TWindow { private final JTextField barHeightProperty = new JTextField(TimeCalcProperty.BAR_HEIGHT.getKey()); // + private final JCheckBox colorVisibleProperty + = new JCheckBox(TimeCalcProperty.COLOR_VISIBLE.getKey()); + private final JTextField colorTypeProperty + = new JTextField(TimeCalcProperty.COLOR_TYPE.getKey()); + private final JCheckBox colorHiddenProperty + = new JCheckBox(TimeCalcProperty.COLOR_HIDDEN.getKey()); + private final JTextField colorHeightProperty + = new JTextField(TimeCalcProperty.COLOR_HEIGHT.getKey()); + // private final JCheckBox swingVisibleProperty = new JCheckBox(TimeCalcProperty.SWING_VISIBLE.getKey()); private final JTextField swingTypeProperty @@ -488,6 +497,8 @@ public class ConfigWindow extends TWindow { // barVisibleProperty.setSelected(enable); barHeightProperty.setText("50"); + colorVisibleProperty.setSelected(enable); + colorHeightProperty.setText("50"); swingVisibleProperty.setSelected(enable); swingQuarterIconVisibleProperty.setSelected(enable); walkingHumanVisibleProperty.setSelected(enable); @@ -580,6 +591,7 @@ public class ConfigWindow extends TWindow { squareVisibleProperty,squareHiddenProperty,squareTypeProperty, circleVisibleProperty,circleHiddenProperty,circleTypeProperty,circleInnerCircleVisibleProperty,circleOuterCircleVisibleProperty, barVisibleProperty, barHiddenProperty, barTypeProperty, barHeightProperty, + colorVisibleProperty, colorHiddenProperty, colorTypeProperty, colorHeightProperty, dotVisibleProperty,dotHiddenProperty,dotTypeProperty, fuelVisibleProperty,fuelTypeProperty,fuelHiddenProperty,fuelIconVisibleProperty, rotationVisibleProperty, rotationTypeProperty, rotationHiddenProperty, @@ -999,7 +1011,7 @@ public class ConfigWindow extends TWindow { index = 5; } - if (key.startsWith("square.")||key.startsWith("circle.")||key.startsWith("dot.")||key.startsWith("swing.")||key.startsWith("walking-human.") || key.startsWith("fuel.") || key.startsWith("rotation.") || key.startsWith("bar.")) { + if (key.startsWith("square.")||key.startsWith("circle.")||key.startsWith("dot.")||key.startsWith("swing.")||key.startsWith("walking-human.") || key.startsWith("fuel.") || key.startsWith("rotation.") || key.startsWith("bar.") || key.startsWith("color.")) { index = 6; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java index 2fbb48c..52eb95c 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java @@ -28,6 +28,7 @@ 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.ProgressBar; +import org.nanoboot.utils.timecalc.swing.progress.ProgressColor; 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; @@ -128,6 +129,7 @@ public class MainWindow extends TWindow { private final ProgressFuelGauge progressFuelGauge; private final ProgressRotation progressRotation; private final ProgressBar progressBar; + private final ProgressColor progressColor; private HelpWindow helpWindow = null; private ConfigWindow configWindow = null; private ActivitiesWindow activitiesWindow = null; @@ -474,6 +476,22 @@ public class MainWindow extends TWindow { add(progressBar); // + // + this.progressColor = new ProgressColor(); + progressColor.setBounds(progressBar.getX(), progressBar.getY() + progressBar.getHeight() + SwingUtils.MARGIN, + progressBar.getX() + progressBar.getWidth() - 2 * SwingUtils.MARGIN, 25); + + progressColor.visibleProperty + .bindTo(timeCalcConfiguration.colorVisibleProperty); + progressColor.typeProperty + .bindTo(timeCalcConfiguration.colorTypeProperty); + progressColor.hiddenProperty + .bindTo(timeCalcConfiguration.colorHiddenProperty); + progressColor.heightProperty + .bindTo(timeCalcConfiguration.colorHeightProperty); + + add(progressColor); + // { progressSquare.typeProperty @@ -522,7 +540,7 @@ public class MainWindow extends TWindow { progressWeather.hiddenProperty.bindTo(timeCalcConfiguration.weatherHiddenProperty); } TLabel arrivalTextFieldLabel = new TLabel("Arrival:", 70); - arrivalTextFieldLabel.setBoundsFromTop(progressBar, 3); + arrivalTextFieldLabel.setBoundsFromTop(progressColor, 3); arrivalTextField.setBoundsFromLeft(arrivalTextFieldLabel); TButton arrivalIncreaseButton = new SmallTButton('+'); @@ -1445,6 +1463,7 @@ public class MainWindow extends TWindow { progressFuelGauge.setProgress(progress); progressRotation.setProgress(progress); progressBar.setProgress(progress); + progressColor.setProgress(progress); dayBattery.setProgress(progress); monthBattery.setProgress(progress); diff --git a/modules/time-calc-app/src/main/resources/timecalc-default.conf b/modules/time-calc-app/src/main/resources/timecalc-default.conf index 6741149..e0550c2 100644 --- a/modules/time-calc-app/src/main/resources/timecalc-default.conf +++ b/modules/time-calc-app/src/main/resources/timecalc-default.conf @@ -63,7 +63,11 @@ circle.outer-circle.only-border=false bar.visible=true bar.type=day bar.hidden=false -bar.height=20 +bar.height=25 +color.visible=true +color.type=day +color.hidden=false +color.height=20 dot.visible=true dot.type=day dot.hidden=false