No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadWrapper.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package org.insa.graphs.gui;
  2. import java.time.Duration;
  3. import java.time.Instant;
  4. public class ThreadWrapper implements RunningAction {
  5. // Thread hold by this wrapper.
  6. private Thread thread;
  7. // Starting time of the thread.
  8. Instant startingTime;
  9. // MainWindow
  10. private MainWindow mainWindow;
  11. public ThreadWrapper(MainWindow mainWindow) {
  12. this.thread = null;
  13. this.mainWindow = mainWindow;
  14. }
  15. public void setThread(Thread thread) {
  16. this.thread = thread;
  17. }
  18. public void startThread() {
  19. this.startingTime = Instant.now();
  20. this.thread.start();
  21. }
  22. public Thread getThread() {
  23. return this.thread;
  24. }
  25. @Override
  26. public boolean isRunning() {
  27. return thread != null && thread.isAlive();
  28. }
  29. @SuppressWarnings("deprecation")
  30. @Override
  31. public void interrupt() {
  32. thread.stop();
  33. this.mainWindow.clearCurrentThread();
  34. }
  35. @Override
  36. public Instant getStartingTime() {
  37. return startingTime;
  38. }
  39. @Override
  40. public Duration getDuration() {
  41. return Duration.between(getStartingTime(), Instant.now());
  42. }
  43. @Override
  44. public String getInformation() {
  45. return getClass().getName();
  46. }
  47. }