Skip to content

Commit

Permalink
Merge pull request #1600 from danilovesky/task-description-details
Browse files Browse the repository at this point in the history
Task description mutable details
  • Loading branch information
danilovesky committed May 15, 2024
2 parents 13fe736 + 9e4efa4 commit bc51c09
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ public static void alignPortWithPin(VisualCircuit circuit, VisualContact port, d
pin = CircuitUtils.findDriver(circuit, port, false);
} else {
Collection<VisualContact> drivenContacts = CircuitUtils.findDriven(circuit, port, false);
if (!drivenContacts.isEmpty()) {
pin = drivenContacts.iterator().next();
for (VisualContact drivenContact : drivenContacts) {
if ((pin == null) || (drivenContact.getRootSpaceY() < pin.getRootSpaceY())) {
pin = drivenContact;
}
}
}
if (pin != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import javax.swing.border.LineBorder;
import java.awt.*;

@SuppressWarnings("serial")
public class TaskControl extends JPanel {

private final JLabel detailsLabel;
private final JProgressBar progressBar;
private final JButton cancelButton;

Expand All @@ -24,15 +24,17 @@ public TaskControl(String taskDescription) {
Border lineBorder = new CompoundBorder(outsideBorder, insideBorder);
setBorder(lineBorder);

JLabel label = new JLabel(taskDescription);
label.setMinimumSize(new Dimension(100, 20));
label.setPreferredSize(new Dimension(300, 20));
JLabel descriptionLabel = new JLabel(taskDescription);
detailsLabel = new JLabel();

JPanel labelPanel = new JPanel(GuiUtils.createFlowLayout());
labelPanel.add(descriptionLabel);
labelPanel.add(detailsLabel);

progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
progressBar.setMinimum(0);
progressBar.setMaximum(1000);

progressBar.setMinimumSize(new Dimension(100, 20));
progressBar.setPreferredSize(new Dimension(300, 20));

Expand All @@ -42,16 +44,20 @@ public TaskControl(String taskDescription) {
JPanel buttonsPanel = GuiUtils.createDialogButtonsPanel();
buttonsPanel.add(cancelButton);

add(label, BorderLayout.NORTH);
add(labelPanel, BorderLayout.NORTH);
add(progressBar, BorderLayout.CENTER);
add(buttonsPanel, BorderLayout.SOUTH);
}

public void progressUpdate(final double completion) {
public void setProgress(final double completion) {
progressBar.setIndeterminate(false);
progressBar.setValue((int) (completion * 1000));
}

public void setDetails(String details) {
detailsLabel.setText(details);
}

public boolean isCancelRequested() {
return cancelRequested;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public void isFinished(Result<?> result) {

@Override
public void progressUpdate(final double completion) {
SwingUtilities.invokeLater(() -> taskControl.progressUpdate(completion));
SwingUtilities.invokeLater(() -> taskControl.setProgress(completion));
}

@Override
public void setDetails(String details) {
SwingUtilities.invokeLater(() -> taskControl.setDetails(details));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public boolean isCancelRequested() {
return false;
}

@Override
public void setDetails(String details) {
}

@Override
public void progressUpdate(double completion) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ public void windowClosing(WindowEvent evt) {
doLayout();
}


@Override
public void setDetails(String details) {
taskControl.setDetails(details);
}

@Override
public void progressUpdate(double completion) {
taskControl.progressUpdate(completion);
taskControl.setProgress(completion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public interface ProgressMonitor<T> {
boolean isCancelRequested();
void setDetails(String details);
void progressUpdate(double completion);
void stdout(byte[] data);
void stderr(byte[] data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public void stdout(byte[] data) {
}
}

@Override
public void setDetails(String details) {
for (ProgressMonitor<? super T> o : this) {
o.setDetails(details);
}
}

@Override
public void progressUpdate(double completion) {
for (ProgressMonitor<? super T> o : this) {
Expand Down
34 changes: 34 additions & 0 deletions workcraft/WorkcraftCore/src/org/workcraft/utils/ListUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.workcraft.utils;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {

public static <T> List<T> zip(List<T> aList, List<T> bList) {
return zip(aList, bList, 1);
}

public static <T> List<T> zip(List<T> aList, List<T> bList, int sliceSize) {
List<T> result = new ArrayList<>();
if (sliceSize < 1) {
sliceSize = 1;
}
int aSize = aList.size();
int bSize = bList.size();
int aFromIndex = 0;
int bFromIndex = 0;
while ((aFromIndex < aSize) && (bFromIndex < bSize)) {
int aToIndex = Math.min(aFromIndex + sliceSize, aSize);
int bToIndex = Math.min(bFromIndex + sliceSize, bSize);
result.addAll(aList.subList(aFromIndex, aToIndex));
result.addAll(bList.subList(bFromIndex, bToIndex));
aFromIndex = aToIndex;
bFromIndex = bToIndex;
}
result.addAll(aList.subList(aFromIndex, aSize));
result.addAll(bList.subList(bFromIndex, bSize));
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.workcraft.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

class ListUtilsTests {

@Test
void zipTest() {
Assertions.assertEquals(List.of(),
ListUtils.zip(List.of(), List.of(), 1));

Assertions.assertEquals(List.of(1),
ListUtils.zip(List.of(1), List.of(), 2));

Assertions.assertEquals(List.of(2, 3, 4),
ListUtils.zip(List.of(), List.of(2, 3, 4), 2));

Assertions.assertEquals(Arrays.asList(1, 2, 3, 4, 5),
ListUtils.zip(Arrays.asList(1, 3, 5), Arrays.asList(2, 4), 1));

Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4"),
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4"),
Arrays.asList("b1", "b2", "b3", "b4"), 2));

Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4", "b5", "b6", "b7"),
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4"),
Arrays.asList("b1", "b2", "b3", "b4", "b5", "b6", "b7"), 2));

Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4", "a5", "a6", "a7"),
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4", "a5", "a6", "a7"),
Arrays.asList("b1", "b2", "b3", "b4"), 2));
}

}

0 comments on commit bc51c09

Please sign in to comment.