diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form index 2b65116..e1850d5 100644 --- a/src/main/java/gui/NewMDIApplication.form +++ b/src/main/java/gui/NewMDIApplication.form @@ -284,7 +284,7 @@ - + @@ -305,7 +305,7 @@ - + @@ -417,6 +417,9 @@ + + + diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java index 473c95e..3526be5 100644 --- a/src/main/java/gui/NewMDIApplication.java +++ b/src/main/java/gui/NewMDIApplication.java @@ -251,6 +251,11 @@ public class NewMDIApplication extends javax.swing.JFrame { }); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1x", "2x", "4x", "10x", "100x", "1000x", "max." })); + jComboBox1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jComboBox1ActionPerformed(evt); + } + }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); @@ -262,7 +267,7 @@ public class NewMDIApplication extends javax.swing.JFrame { .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 545, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 389, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() @@ -723,6 +728,10 @@ public class NewMDIApplication extends javax.swing.JFrame { } }//GEN-LAST:event_viewTraderListCheckBoxActionPerformed + private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jComboBox1ActionPerformed + /** * @param args the command line arguments * @throws java.lang.IllegalAccessException diff --git a/src/main/java/sesim/Scheduler.java b/src/main/java/sesim/Scheduler.java index 11a645b..6be5328 100644 --- a/src/main/java/sesim/Scheduler.java +++ b/src/main/java/sesim/Scheduler.java @@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class Scheduler extends Thread { - private double acceleration = 0.0; + private double acceleration = 1.0; public void setAcceleration(double val) { @@ -108,16 +108,54 @@ public class Scheduler extends Thread { Clock clock; + long last_nanos = System.nanoTime(); + double current_nanos = 0; + /** * * @return */ public long currentTimeMillis1() { + long cur = System.nanoTime(); + long diff = cur - last_nanos; + last_nanos = cur; + + if (pause) { + return (long) this.current_time_millis; + } + + // this.cur_nano += (((double)diff_nano)/1000000.0)*this.acceleration; + // return (long)(cur_nano/1000000.0); + + + + + this.current_nanos += (double)diff * (double)this.acceleration; + +// this.current_time_millis += ((double) diff) * this.acceleration; + + this.current_time_millis = this.current_nanos/1000000.0; + + return (long) this.current_time_millis; + } + + + /** + * + * @return + */ + public long currentTimeMillis1_old() { + + long cur_nano = System.nanoTime(); + long diff_nano = cur_nano - last_nanos; + last_nanos = cur_nano; + long cur = System.currentTimeMillis(); - long diff = cur - last_time_millis; + long diff = (cur - last_time_millis); + //System.out.printf("Diff Nanos: %d Diff Millis %d, ND: %d\n", diff_nano, diff, diff_nano/1000000); last_time_millis = cur; // last_time_millis += diff; @@ -127,11 +165,21 @@ public class Scheduler extends Thread { if (pause) { return (long) this.current_time_millis; } + + // this.cur_nano += (((double)diff_nano)/1000000.0)*this.acceleration; + // return (long)(cur_nano/1000000.0); + double fac = (((double) diff) + 10.0) * this.acceleration; + System.out.printf("Difdif: %f %f\n", fac, this.acceleration); this.current_time_millis += ((double) diff) * this.acceleration; return (long) this.current_time_millis; } + + + + public long currentTimeMillis() { +// return (long)(cur_nano/1000000.0); return (long) this.current_time_millis; } @@ -225,8 +273,7 @@ public class Scheduler extends Thread { return e.timerTask(); } - // HashMap tasks = new HashMap<>(); - + // HashMap tasks = new HashMap<>(); private boolean addTimerTask(TimerTaskDef e) { // long evtime = time + currentTimeMillis(); @@ -235,11 +282,10 @@ public class Scheduler extends Thread { s = new TreeSet<>(); event_queue.put(e.newevtime, s); } - - e.curevtime=e.newevtime; - // tasks.put(e, e.evtime); + e.curevtime = e.newevtime; + // tasks.put(e, e.evtime); return s.add(e); } @@ -252,11 +298,9 @@ public class Scheduler extends Thread { private void cancelMy(TimerTaskDef e) { // Long evtime = tasks.get(e.curevtime); - // if (evtime == null) { // return; // } - SortedSet s = event_queue.get(e.curevtime); if (s == null) { @@ -281,16 +325,26 @@ public class Scheduler extends Thread { long t = event_queue.firstKey(); long ct = currentTimeMillis1(); - ct = t; + +// ct = t; if (t > ct) { - // System.out.printf("Leave Event Queue in run events %d\n", Thread.currentThread().getId()); - System.out.printf("Sleeping somewat %d\n", (long) (t - this.currentTimeMillis() / this.acceleration)); - return (t - currentTimeMillis()) / (long) this.acceleration; + //if ((long) diff > 0) { + // System.out.printf("Leave Event Queue in run events %d\n", Thread.currentThread().getId()); +// System.out.printf("Sleeping somewat %d\n", (long) (0.5 + (t - this.currentTimeMillis()) / this.acceleration)); + // return (long) diff; + return (long) (((double)t - this.currentTimeMillis()) / this.acceleration ); } + if (t it = s.iterator(); @@ -323,7 +377,7 @@ public class Scheduler extends Thread { void initScheduler() { current_time_millis = 0.0; - // this.startTimerTask(new EmptyCtr(), 0); + this.startTimerTask(new EmptyCtr(), 0); terminate = false; }