diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ArrivalChart.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ArrivalChart.java index da2d9a6..815283e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ArrivalChart.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ArrivalChart.java @@ -12,6 +12,7 @@ import org.jfree.data.time.Day; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; +import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; import javax.swing.BorderFactory; import javax.swing.JPanel; @@ -33,10 +34,14 @@ public class ArrivalChart extends JPanel { private static final Color BROWN = new Color(128, 0, 64); private static final Color PURPLE = new Color(128, 0, 255); public static final Rectangle EMPTY_RECTANGLE = new Rectangle(); + public static final int MIN_CHART_WIDTH = 600; private final boolean ma14Enabled; private final boolean ma28Enabled; private final boolean ma56Enabled; + public IntegerProperty widthProperty = new IntegerProperty("widthProperty", 600); + public IntegerProperty heightProperty = new IntegerProperty("heightProperty", 400); + public ArrivalChart(ArrivalChartData data, int width) { this(data.getDays(), data.getArrival(), data.getTarget(), data.getMa7(), data.getMa14(), data.getMa28(), data.getMa56(), @@ -66,10 +71,23 @@ public class ArrivalChart extends JPanel { chartPanel.setDomainZoomable(true); chartPanel.setMouseZoomable(true); this.add(chartPanel); + widthProperty.addListener(e-> { + if (widthProperty.getValue() > MIN_CHART_WIDTH) { + chartPanel.setBounds(10, 10, widthProperty.getValue(), + heightProperty.getValue()); + } else {widthProperty.setValue(MIN_CHART_WIDTH);} + }); + heightProperty.addListener(e-> chartPanel.setBounds(10, 10, widthProperty.getValue(), heightProperty.getValue())); + + + + + widthProperty.setValue(width); chartPanel.setBounds(10, 10, width, 400); this.ma14Enabled = ma14Enabled; this.ma28Enabled = ma28Enabled; this.ma56Enabled = ma56Enabled; + } private JFreeChart createChart(List timeSeries, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java index 7aa0283..023ef16 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java @@ -703,6 +703,7 @@ public class MainWindow extends TWindow { System.out.println(wd); while (true) { + if (updateWindow(timeCalcApp, time, clock, minuteBattery, hourBattery, dayBattery, weekBattery, monthBattery, yearBattery, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TWindow.java index 3473e8c..8fb1c5c 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TWindow.java @@ -1,8 +1,13 @@ package org.nanoboot.utils.timecalc.swing.common; +import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; + import javax.swing.JFrame; +import javax.swing.Timer; import java.awt.Component; import java.awt.HeadlessException; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; /** * @author Robert Vokac @@ -10,8 +15,25 @@ import java.awt.HeadlessException; */ public class TWindow extends JFrame { + public IntegerProperty widthProperty = new IntegerProperty("widthProperty"); + public IntegerProperty heightProperty = new IntegerProperty("heightProperty"); public TWindow() throws HeadlessException { - + addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + widthProperty.setValue(getWidth()); + heightProperty.setValue(getHeight()); + } + }); + widthProperty.addListener(e -> { + if (widthProperty.getValue() > 100 /*&& widthProperty.getValue() % 10 == 0*/) { + setSize(widthProperty.getValue(), getHeight()); + } + }); + heightProperty.addListener(e -> { + if (heightProperty.getValue() > 100 /*&& widthProperty.getValue() % 10 == 0*/) { + setSize(getWidth(), heightProperty.getValue()); + } + }); } public Component[] addAll(Component... comp) { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java index 5225320..40b88aa 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java @@ -8,6 +8,8 @@ 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.common.Utils; +import org.nanoboot.utils.timecalc.utils.property.InvalidationListener; +import org.nanoboot.utils.timecalc.utils.property.Property; import javax.swing.JButton; import javax.swing.JComboBox; @@ -23,6 +25,7 @@ import java.awt.event.KeyListener; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.function.Consumer; /** * @author Robert Vokac @@ -50,6 +53,7 @@ public class WorkingDaysWindow extends TWindow { private JTable table = null; private final JScrollPane scrollPane; private int loadedYear; + private InvalidationListener invalidationChartWidthListener; public WorkingDaysWindow(WorkingDayRepositoryApi workingDayRepository, Time time, double target) { @@ -460,6 +464,15 @@ public class WorkingDaysWindow extends TWindow { scrollPane.setViewportView(table); table.setBounds(30, 30, 750, 600); + this.widthProperty.addListener(e-> { + if(/*this.widthProperty.getValue() % 10 == 0 && */this.widthProperty.getValue() > 100) { + scrollPane.setBounds(SwingUtils.MARGIN, + arrivalChart.getY() + arrivalChart.getHeight() + + SwingUtils.MARGIN, + (this.widthProperty.getValue() - 50), + scrollPane.getHeight()); + } + }); //table.setDefaultRenderer(Object.class, new ColorRenderer()); ArrivalChartData acd = WorkingDayForStats .toArrivalChartData(wdfsList, 7d, startTextField.getText(), @@ -474,6 +487,18 @@ public class WorkingDaysWindow extends TWindow { Rectangle bounds = this.arrivalChart.getBounds(); remove(this.arrivalChart); this.arrivalChart = new ArrivalChart(newArrivalChartData, chartWidth); + if(this.invalidationChartWidthListener != null) { + this.widthProperty.removeListener(invalidationChartWidthListener); + this.invalidationChartWidthListener = null; + } + this.invalidationChartWidthListener = + new InvalidationListener() { + @Override + public void invalidated(Property property) { + arrivalChart.widthProperty.setValue(getWidth() - 30); + } + }; + this.widthProperty.addListener(invalidationChartWidthListener); add(arrivalChart); arrivalChart.setBounds(bounds); add(arrivalChart); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java index 5cafaf6..5ef6b3f 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java @@ -117,7 +117,9 @@ public class Property { public void addListener(ChangeListener listener) { this.changeListeners.add(listener); } - + public void removeListener(InvalidationListener listener) { + this.invalidationListeners.remove(listener); + } public void removeListener(ChangeListener listener) { this.changeListeners.remove(listener); }