Skip to content

Commit

Permalink
Multi-monitor support
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Apr 13, 2021
1 parent e7f2b7f commit 2c23342
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Collection;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -39,8 +40,8 @@ public TimeTracker() {
startTimeTrackingThread();
}

public void startTracking(ProjectDto project, String taskDescription, String taskTag) {
trackingData.set(new TrackingData(System.currentTimeMillis(), nextSchedule(project), taskDescription, taskTag, project));
public void startTracking(ProjectDto project, String taskDescription, String taskTag, Collection<GraphicsDevice> devices) {
trackingData.set(new TrackingData(System.currentTimeMillis(), nextSchedule(project), taskDescription, taskTag, project, devices));
}

public void stopTracking() {
Expand Down Expand Up @@ -73,7 +74,7 @@ private void captureTimeLog(TrackingData data) {
Path logDir = ProjectFileStructUtil.logDir();
logDir.toFile().mkdir();
String baseName = "" + Instant.now().toEpochMilli();
writeScreenshotIfNeeded(logDir, baseName, data.getProject());
writeScreenshotIfNeeded(logDir, baseName, data.getProject(), data.getDevices());
val duration = System.currentTimeMillis() - data.getForTime();
if (duration <= 0) {
return;
Expand All @@ -92,12 +93,16 @@ private void captureTimeLog(TrackingData data) {
}

@SneakyThrows
private void writeScreenshotIfNeeded(Path dir, String baseName, ProjectDto project) {
private void writeScreenshotIfNeeded(Path dir, String baseName, ProjectDto project, Collection<GraphicsDevice> devices) {
if (!screenShotsEnabled.get()) {
return;
}

BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
Rectangle screenRect = new Rectangle(0, 0, 0, 0);
for (GraphicsDevice gd : devices) {
screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds());
}
BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenRect));
ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next();
ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam();
jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
Expand Down Expand Up @@ -128,5 +133,6 @@ private static class TrackingData {
private final String taskDescription;
private final String taskTag;
private final ProjectDto project;
private final Collection<GraphicsDevice> devices;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ua.timetracker.desktoptracker.TrackerDialog">
<grid id="27dc6" binding="mainPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="661" height="187"/>
<xy x="20" y="20" width="683" height="453"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -131,14 +131,14 @@
<children>
<component id="1ec59" class="javax.swing.JComboBox" binding="currentProject">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties/>
</component>
<component id="8330b" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
Expand All @@ -147,28 +147,19 @@
</component>
<component id="c8533" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="2.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Work description:"/>
</properties>
</component>
<component id="52665" class="javax.swing.JCheckBox" binding="captureScreenshots">
<constraints>
<grid row="1" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Capture screenshots"/>
</properties>
</component>
<component id="d8264" class="javax.swing.JTextArea" binding="taskDescription">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
<gridbag weightx="1.0" weighty="2.0"/>
<gridbag weightx="1.0" weighty="10.0"/>
</constraints>
<properties>
<lineWrap value="true"/>
Expand All @@ -184,52 +175,34 @@
</vspacer>
<hspacer id="9a116">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<component id="f8435" class="javax.swing.JComboBox" binding="workType">
<constraints>
<grid row="3" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties>
<maximumSize width="32767" height="32767"/>
</properties>
</component>
<component id="a27e4" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Work type"/>
</properties>
</component>
<hspacer id="e2b9">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<hspacer id="1a5a7">
<constraints>
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<component id="30480" class="javax.swing.JButton" binding="start">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="20.0" weighty="1.0"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="50.0" weighty="1.0"/>
</constraints>
<properties>
<text value="Start ►"/>
</properties>
</component>
<component id="5969a" class="javax.swing.JButton" binding="stop">
<constraints>
<grid row="5" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="6" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="1.0"/>
</constraints>
<properties>
Expand All @@ -238,7 +211,7 @@
</component>
<component id="4bed7" class="javax.swing.JLabel" binding="trackingErrorMessage">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
Expand All @@ -249,13 +222,31 @@
</component>
<vspacer id="e3e63">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</vspacer>
<component id="b8e11" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Wait before upload:"/>
</properties>
</component>
<component id="a27e4" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Work type"/>
</properties>
</component>
<component id="bd67f" class="javax.swing.JComboBox" binding="waitBeforeUpload">
<constraints>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
Expand All @@ -268,15 +259,33 @@
</model>
</properties>
</component>
<component id="b8e11" class="javax.swing.JLabel">
<component id="f8435" class="javax.swing.JComboBox" binding="workType">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties>
<maximumSize width="32767" height="32767"/>
</properties>
</component>
<component id="52665" class="javax.swing.JCheckBox" binding="captureScreenshots">
<constraints>
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="Wait before upload:"/>
<text value="Capture screenshots"/>
</properties>
</component>
<component id="53bdf" class="javax.swing.JList" binding="monitorList" custom-create="true">
<constraints>
<grid row="3" column="6" row-span="2" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="4f905" binding="logoutPanel" layout-manager="GridBagLayout">
Expand Down
Loading

0 comments on commit 2c23342

Please sign in to comment.