Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added filter into file chooser; added progress bar

  • Loading branch information...
commit e56f5561a53b97837c4f0d870c6fcd2278f3e4b6 1 parent 85469db
fugazza authored February 20, 2012
BIN  dist/PLTtools.jar
Binary file not shown
67  src/plttools/PLTfile.java
@@ -4,8 +4,9 @@
4 4
  */
5 5
 package plttools;
6 6
 
  7
+import java.beans.PropertyChangeListener;
  8
+import java.beans.PropertyChangeSupport;
7 9
 import java.io.*;
8  
-import java.text.DecimalFormat;
9 10
 import java.util.StringTokenizer;
10 11
 import java.util.logging.Level;
11 12
 import java.util.logging.Logger;
@@ -27,19 +28,23 @@
27 28
     private int pocetBodu = 0;
28 29
     private double delkaCar = 0.0;
29 30
     private double delkaPrejezdu = 0.0;
  31
+    private PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
  32
+    private PLTfile optimizedFile = null;
30 33
     
31  
-    public static PLTfile readPLTfromFile(File file) {
  34
+    public void readPLTfromFile(File file) {
32 35
         BufferedReader reader = null;
33  
-        PLTfile plt = new PLTfile();
34 36
         try {
  37
+//            System.out.println("reading started");
35 38
             reader = new BufferedReader(new FileReader(file));
36 39
             StringBuilder contents = new StringBuilder();
37 40
             String text = "";
38 41
             while ((text = reader.readLine()) != null) {
39 42
                 contents.append(text).append(System.getProperty("line.separator"));            
40 43
             }
41  
-            plt.setRawPLT(contents);
42  
-            plt.parseRaw();
  44
+//            System.out.println("file read");
  45
+            setRawPLT(contents);
  46
+//            System.out.println("start parsing");
  47
+            parseRaw();
43 48
         } catch (FileNotFoundException ex) {
44 49
             Logger.getLogger(PLTfile.class.getName()).log(Level.SEVERE, null, ex);
45 50
         } catch (IOException ex) {
@@ -51,13 +56,19 @@ public static PLTfile readPLTfromFile(File file) {
51 56
                 Logger.getLogger(PLTfile.class.getName()).log(Level.SEVERE, null, ex);
52 57
             }
53 58
         }
54  
-        return plt;
  59
+//        System.out.println("reading finished");
55 60
     }
56 61
 
57 62
     private void parseRaw() {
58 63
         String prikaz;
59 64
         boolean penUp = true;
60 65
         // spočítat čáry a přejezdy
  66
+        pocetCar = 0;
  67
+        pocetPrejezdu = 0;
  68
+        pocetBodu = 0;
  69
+        delkaPrejezdu = 0;
  70
+        delkaCar = 0;
  71
+//        System.out.println("parseRaw - start parsing");
61 72
         StringTokenizer st0 = new StringTokenizer(rawPLT.toString(),";");
62 73
         while (st0.hasMoreTokens()) {
63 74
             prikaz = st0.nextToken();
@@ -85,7 +96,7 @@ private void parseRaw() {
85 96
                 penUp = false;
86 97
             }
87 98
         }
88  
-        
  99
+//        System.out.println("parseRaw - lines counted");
89 100
         
90 101
         // teď teprve získat jednotlivé hodnoty
91 102
         pens = new int[pocetCar];
@@ -108,7 +119,9 @@ private void parseRaw() {
108 119
         }
109 120
         
110 121
         penUp = true;
  122
+//        System.out.println("parseRaw - before tokenizer");
111 123
         StringTokenizer st = new StringTokenizer(rawPLT.toString(),";");
  124
+//        System.out.println("parseRaw - tokenizer started");
112 125
         while (st.hasMoreTokens()) {
113 126
             prikaz = st.nextToken();
114 127
 
@@ -143,6 +156,7 @@ private void parseRaw() {
143 156
                     lastX = x2a;
144 157
                     lastY = y2a;
145 158
                     i++;
  159
+                    //System.out.println("parseRaw - "+i+" tokens read");
146 160
                 }
147 161
                 penUp = false;
148 162
             } else if (prikaz.equals("PD")) {
@@ -156,6 +170,9 @@ private void parseRaw() {
156 170
             }
157 171
         }
158 172
 
  173
+//        System.out.println("before property fire");
  174
+        propertySupport.firePropertyChange("fileRead", false, true);
  175
+//        System.out.println("after property fire");
159 176
         calculateDistances();
160 177
         for (int k=0; k < pocetCar; k++) {
161 178
             if (status[k] <= 0) {
@@ -274,20 +291,26 @@ private boolean findLoop(int startIndex) {
274 291
         return false;
275 292
     } 
276 293
     
277  
-    public PLTfile getOptimizedPLT() {
  294
+    public void optimizePLT() {
278 295
         int alghoritm = 3;
279 296
         switch(alghoritm) {
280 297
             case 3:
281  
-                return optimizationAntColony();
  298
+                optimizedFile = optimizationAntColony();
282 299
             case 2:
283  
-                return optimizationGreedy();
  300
+                optimizedFile = optimizationGreedy();
284 301
             case 1:
285 302
             default:
286  
-                return optimizationGreedyModified();
287  
-        }
  303
+                optimizedFile = optimizationGreedyModified();
  304
+        }        
  305
+        propertySupport.firePropertyChange("progressFinished", false, true);
  306
+    }
  307
+    
  308
+    public PLTfile getOptimizedPLT() {
  309
+        return optimizedFile;
288 310
     }
289 311
     
290 312
     private PLTfile optimizationAntColony() {
  313
+        propertySupport.firePropertyChange("progressMessage", null, "optimization started");
291 314
         System.out.println("optimization started");
292 315
         PLTfile p = (PLTfile) clone();
293 316
         calculateDistances();
@@ -312,13 +335,14 @@ private PLTfile optimizationAntColony() {
312 335
         float attract;
313 336
         int i, j, k;
314 337
         int lastPoint;
315  
-        int antsCount = 30;
  338
+        int antsCount = 10;
316 339
         for (k=0; k<antsCount; k++) {
317 340
             if (k==(antsCount-1)) {
318 341
                 lastPoint = 0;
319 342
             } else {
320 343
                 lastPoint = (int) (Math.random()*pocetBodu);
321 344
             }
  345
+            propertySupport.firePropertyChange("progressMessage", null, "Ant "+(k+1)+" from "+(antsCount)+"is running");
322 346
             System.out.println("Ant "+k+"; startpoint = "+lastPoint);
323 347
             int nextPoint = 0;
324 348
             boolean processed[] = new boolean[pocetBodu];
@@ -327,6 +351,7 @@ private PLTfile optimizationAntColony() {
327 351
             float vahaVzdalenost = 1.0f;
328 352
             float vahaFeromon = 2.0f;
329 353
             float vahaNahoda = 1.0f;
  354
+            propertySupport.firePropertyChange("progressMessage", null, "Ant "+(k+1)+" from "+(antsCount)+" calculating attraction");
330 355
             for (i=0; i<pocetBodu;i++) {
331 356
                 for (j=i+1; j<pocetBodu;j++) {
332 357
                     if (distances[i][j] == 0) {
@@ -341,9 +366,11 @@ private PLTfile optimizationAntColony() {
341 366
                     attractivity[i][j] = attract;
342 367
                     attractivity[j][i] = attract;
343 368
                 }
  369
+            propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*i)/pocetBodu));                            
344 370
             }
345 371
             // generate ant path
346 372
             numProcessed = 0;
  373
+            propertySupport.firePropertyChange("progressMessage", null, "Ant "+(k+1)+" from "+(antsCount)+" running through lines");
347 374
             while (numProcessed < pocetBodu) {
348 375
                 maxAttractivity = 0;
349 376
                 for(i=0; i<pocetBodu; i++) {
@@ -356,6 +383,7 @@ private PLTfile optimizationAntColony() {
356 383
                 antPath[numProcessed] = nextPoint;
357 384
                 lastPoint = nextPoint;
358 385
                 numProcessed++;
  386
+                propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*numProcessed)/pocetBodu));                            
359 387
             }
360 388
             // calculate path length
361 389
             antPathLength = 0.0;
@@ -375,14 +403,17 @@ private PLTfile optimizationAntColony() {
375 403
             }
376 404
             System.out.println("pheromone increase = " + 20000.0f/antPathLength);
377 405
             int r,s;
  406
+            propertySupport.firePropertyChange("progressMessage", null, "Ant "+(k+1)+" from "+(antsCount)+" deposing pheromones");
378 407
             for (i=1; i<pocetBodu; i++) {
379 408
                 r = antPath[i];
380 409
                 s = antPath[i-1];
381 410
                 pheromone = (float) (pheromones[r][s] + 20000.0f/antPathLength);
382 411
                 pheromones[r][s] = pheromone;
383 412
                 pheromones[s][r] = pheromone;
  413
+                propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*i)/pocetBodu));                            
384 414
             }
385 415
         }
  416
+        propertySupport.firePropertyChange("progressMessage", null, "Generating final path.");
386 417
         for (i=1; i<pocetBodu; i++) {
387 418
             for(j=0; j<pocetCar; j++) {
388 419
                 if (lines_1[j] == antPath[i-1] && lines_2[j] == antPath[i]) {
@@ -403,6 +434,7 @@ private PLTfile optimizationAntColony() {
403 434
                     break;
404 435
                 }         
405 436
             }
  437
+            propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*i)/pocetBodu));                            
406 438
         }
407 439
         p.calculatePathLengths();
408 440
         return p;
@@ -464,6 +496,7 @@ private void calculateDistances() {
464 496
         float dist;
465 497
         distances = new float[pocetBodu][pocetBodu];
466 498
         int i, j, k;
  499
+        propertySupport.firePropertyChange("progressMessage", null, "distance calculation");
467 500
         for (i=0; i<pocetBodu; i++) {
468 501
             distances[i][i] = 2*(max_x+max_y);
469 502
             for (j=i+1; j<pocetBodu; j++) {
@@ -473,8 +506,10 @@ private void calculateDistances() {
473 506
                 distances[i][j] = dist;
474 507
                 distances[j][i] = dist;
475 508
             }
  509
+            propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*i)/pocetBodu));            
476 510
         }
477 511
         // set distance of points, that are common for just two lines to bad value
  512
+        propertySupport.firePropertyChange("progressMessage", null, "loops detection");
478 513
         int zeroDistCount;
479 514
         for (i=0; i<pocetBodu; i++) {
480 515
             zeroDistCount = 0;
@@ -505,6 +540,7 @@ private void calculateDistances() {
505 540
                     }
506 541
                 }
507 542
             }
  543
+            propertySupport.firePropertyChange("progressValue", 0, (int) ((100.0*i)/pocetBodu));            
508 544
         }
509 545
         
510 546
         // set distance of all connected points best value
@@ -520,6 +556,7 @@ private void calculateDistances() {
520 556
 //            }
521 557
 //            System.out.println();
522 558
 //        }
  559
+        propertySupport.firePropertyChange("progressFinished", false, true);
523 560
     }
524 561
     
525 562
     private PLTfile optimizationGreedyModified() {
@@ -728,4 +765,8 @@ protected Object clone() {
728 765
         return p;
729 766
     }
730 767
         
  768
+    public void addPropertyChangeListener(PropertyChangeListener listener) {
  769
+        propertySupport.addPropertyChangeListener(listener);
  770
+    }
  771
+
731 772
 }
29  src/plttools/PLTtools.form
@@ -31,8 +31,8 @@
31 31
               <EmptySpace max="-2" attributes="0"/>
32 32
               <Group type="103" groupAlignment="0" attributes="0">
33 33
                   <Component id="pLTpanel1" max="32767" attributes="0"/>
34  
-                  <Component id="jLabel1" max="32767" attributes="0"/>
35  
-                  <Group type="102" alignment="0" attributes="0">
  34
+                  <Component id="jLabel1" alignment="0" max="32767" attributes="0"/>
  35
+                  <Group type="102" attributes="0">
36 36
                       <Component id="jButton1" min="-2" max="-2" attributes="0"/>
37 37
                       <EmptySpace max="-2" attributes="0"/>
38 38
                       <Component id="jButton2" min="-2" max="-2" attributes="0"/>
@@ -42,8 +42,9 @@
42 42
                       <Component id="jCheckBox1" min="-2" max="-2" attributes="0"/>
43 43
                       <EmptySpace max="-2" attributes="0"/>
44 44
                       <Component id="jCheckBox2" min="-2" max="-2" attributes="0"/>
45  
-                      <EmptySpace min="0" pref="26" max="32767" attributes="0"/>
  45
+                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
46 46
                   </Group>
  47
+                  <Component id="jProgressBar1" max="32767" attributes="0"/>
47 48
               </Group>
48 49
               <EmptySpace max="-2" attributes="0"/>
49 50
           </Group>
@@ -65,6 +66,8 @@
65 66
               <EmptySpace max="-2" attributes="0"/>
66 67
               <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
67 68
               <EmptySpace max="-2" attributes="0"/>
  69
+              <Component id="jProgressBar1" min="-2" max="-2" attributes="0"/>
  70
+              <EmptySpace max="-2" attributes="0"/>
68 71
           </Group>
69 72
       </Group>
70 73
     </DimensionLayout>
@@ -88,21 +91,16 @@
88 91
       <Layout>
89 92
         <DimensionLayout dim="0">
90 93
           <Group type="103" groupAlignment="0" attributes="0">
91  
-              <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
  94
+              <EmptySpace min="0" pref="421" max="32767" attributes="0"/>
92 95
           </Group>
93 96
         </DimensionLayout>
94 97
         <DimensionLayout dim="1">
95 98
           <Group type="103" groupAlignment="0" attributes="0">
96  
-              <EmptySpace min="0" pref="274" max="32767" attributes="0"/>
  99
+              <EmptySpace min="0" pref="278" max="32767" attributes="0"/>
97 100
           </Group>
98 101
         </DimensionLayout>
99 102
       </Layout>
100 103
     </Container>
101  
-    <Component class="javax.swing.JLabel" name="jLabel1">
102  
-      <Properties>
103  
-        <Property name="text" type="java.lang.String" value="PLT info:"/>
104  
-      </Properties>
105  
-    </Component>
106 104
     <Component class="javax.swing.JButton" name="jButton2">
107 105
       <Properties>
108 106
         <Property name="text" type="java.lang.String" value="Optimize"/>
@@ -136,5 +134,16 @@
136 134
         <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jCheckBox2ActionPerformed"/>
137 135
       </Events>
138 136
     </Component>
  137
+    <Component class="javax.swing.JLabel" name="jLabel1">
  138
+      <Properties>
  139
+        <Property name="text" type="java.lang.String" value="PLT info:"/>
  140
+      </Properties>
  141
+    </Component>
  142
+    <Component class="javax.swing.JProgressBar" name="jProgressBar1">
  143
+      <Properties>
  144
+        <Property name="string" type="java.lang.String" value="Ready"/>
  145
+        <Property name="stringPainted" type="boolean" value="true"/>
  146
+      </Properties>
  147
+    </Component>
139 148
   </SubComponents>
140 149
 </Form>
120  src/plttools/PLTtools.java
@@ -4,24 +4,44 @@
4 4
  */
5 5
 package plttools;
6 6
 
  7
+import java.beans.PropertyChangeEvent;
  8
+import java.beans.PropertyChangeListener;
7 9
 import java.io.File;
8  
-import javax.swing.GroupLayout;
  10
+import java.util.concurrent.ExecutorService;
  11
+import java.util.concurrent.Executors;
9 12
 import javax.swing.JFileChooser;
  13
+import javax.swing.SwingWorker;
  14
+import javax.swing.filechooser.FileFilter;
10 15
 
11 16
 /**
12 17
  *
13 18
  * @author Vláďa
14 19
  */
15  
-public class PLTtools extends javax.swing.JFrame {
  20
+public class PLTtools extends javax.swing.JFrame implements PropertyChangeListener {
16 21
 
17  
-    PLTfile pltFile;
  22
+    PLTfile pltFile = new PLTfile();
  23
+    ExecutorService executorService;
18 24
     
19 25
     /**
20 26
      * Creates new form PLTtools
21 27
      */
22 28
     public PLTtools() {
23 29
         initComponents();
24  
-        GroupLayout layout = (GroupLayout) getContentPane().getLayout();
  30
+        jFileChooser1.setFileFilter(new FileFilter() {
  31
+
  32
+            @Override
  33
+            public boolean accept(File pathname) {
  34
+                return pathname.isDirectory() || pathname.getName().toLowerCase().endsWith(".plt");
  35
+            }
  36
+
  37
+            @Override
  38
+            public String getDescription() {
  39
+                return "*.plt (Hewlett-Packard Graphics Language plot file)";
  40
+            }
  41
+            
  42
+        });   
  43
+        pltFile.addPropertyChangeListener(PLTtools.this);
  44
+        executorService = Executors.newSingleThreadExecutor();
25 45
     }
26 46
 
27 47
     /** This method is called from within the constructor to
@@ -36,11 +56,12 @@ private void initComponents() {
36 56
         jFileChooser1 = new javax.swing.JFileChooser();
37 57
         jButton1 = new javax.swing.JButton();
38 58
         pLTpanel1 = new plttools.PLTpanel();
39  
-        jLabel1 = new javax.swing.JLabel();
40 59
         jButton2 = new javax.swing.JButton();
41 60
         jButton3 = new javax.swing.JButton();
42 61
         jCheckBox1 = new javax.swing.JCheckBox();
43 62
         jCheckBox2 = new javax.swing.JCheckBox();
  63
+        jLabel1 = new javax.swing.JLabel();
  64
+        jProgressBar1 = new javax.swing.JProgressBar();
44 65
 
45 66
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
46 67
         setTitle("PLT tools");
@@ -58,15 +79,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
58 79
         pLTpanel1.setLayout(pLTpanel1Layout);
59 80
         pLTpanel1Layout.setHorizontalGroup(
60 81
             pLTpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
61  
-            .addGap(0, 0, Short.MAX_VALUE)
  82
+            .addGap(0, 421, Short.MAX_VALUE)
62 83
         );
63 84
         pLTpanel1Layout.setVerticalGroup(
64 85
             pLTpanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
65  
-            .addGap(0, 274, Short.MAX_VALUE)
  86
+            .addGap(0, 278, Short.MAX_VALUE)
66 87
         );
67 88
 
68  
-        jLabel1.setText("PLT info:");
69  
-
70 89
         jButton2.setText("Optimize");
71 90
         jButton2.addActionListener(new java.awt.event.ActionListener() {
72 91
             public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -96,6 +115,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
96 115
             }
97 116
         });
98 117
 
  118
+        jLabel1.setText("PLT info:");
  119
+
  120
+        jProgressBar1.setString("Ready");
  121
+        jProgressBar1.setStringPainted(true);
  122
+
99 123
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
100 124
         getContentPane().setLayout(layout);
101 125
         layout.setHorizontalGroup(
@@ -115,7 +139,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
115 139
                         .addComponent(jCheckBox1)
116 140
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
117 141
                         .addComponent(jCheckBox2)
118  
-                        .addGap(0, 26, Short.MAX_VALUE)))
  142
+                        .addGap(0, 0, Short.MAX_VALUE))
  143
+                    .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
119 144
                 .addContainerGap())
120 145
         );
121 146
         layout.setVerticalGroup(
@@ -132,6 +157,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
132 157
                 .addComponent(pLTpanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
133 158
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
134 159
                 .addComponent(jLabel1)
  160
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  161
+                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
135 162
                 .addContainerGap())
136 163
         );
137 164
 
@@ -139,23 +166,51 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
139 166
     }// </editor-fold>//GEN-END:initComponents
140 167
 
141 168
     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
142  
-//        int result = jFileChooser1.showOpenDialog(this);
143  
-//        if (result == JFileChooser.APPROVE_OPTION) {
144  
-//            setTitle(jFileChooser1.getSelectedFile().getName()+" - PLT tools");
145  
-//            pltFile = PLTfile.readPLTfromFile(jFileChooser1.getSelectedFile());
146  
-//            jLabel1.setText("PLT info: čar " + pltFile.getPocetCar() + " (délka " + Math.round(pltFile.getDelkaCar()) + "); přejezdů " + pltFile.getPocetPrejezdu() + " (délka " + Math.round(pltFile.getDelkaPrejezdu()) + ")");
147  
-//            pLTpanel1.setPlt(pltFile);
148  
-//        }
149  
-            pltFile = PLTfile.readPLTfromFile(new File("G:/inova/stitky/13636.plt"));
150  
-            jLabel1.setText("PLT info: čar " + pltFile.getPocetCar() + " (délka " + Math.round(pltFile.getDelkaCar()) + "); přejezdů " + pltFile.getPocetPrejezdu() + " (délka " + Math.round(pltFile.getDelkaPrejezdu()) + ")");
151  
-            pLTpanel1.setPlt(pltFile);
  169
+        int result = jFileChooser1.showOpenDialog(this);
  170
+        if (result == JFileChooser.APPROVE_OPTION) {
  171
+            setTitle(jFileChooser1.getSelectedFile().getName()+" - PLT tools");
  172
+            SwingWorker sw = new SwingWorker<Void, Void>() {
  173
+
  174
+                @Override
  175
+                protected Void doInBackground() throws Exception {
  176
+                    pltFile.readPLTfromFile(jFileChooser1.getSelectedFile());
  177
+                    return null;
  178
+                }
  179
+                
  180
+            };
  181
+            executorService.submit(sw);            
  182
+        }
  183
+//        SwingWorker sw = new SwingWorker<Void, Void>() {
  184
+//            @Override
  185
+//            protected Void doInBackground() throws Exception {
  186
+//                System.out.println("reader: Swing worker started.");
  187
+//                pltFile.readPLTfromFile(new File("G:/inova/stitky/13636.plt"));
  188
+//                System.out.println("reader: Swing worker finished.");
  189
+//                return null;
  190
+//            }
  191
+//        };
  192
+//        executorService.submit(sw);            
  193
+
152 194
     }//GEN-LAST:event_jButton1ActionPerformed
153 195
 
154 196
     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
155 197
         if (pltFile != null) {
156  
-            pltFile = pltFile.getOptimizedPLT();
157  
-            pLTpanel1.setPlt(pltFile);            
158  
-            jLabel1.setText("PLT info: čar " + pltFile.getPocetCar() + " (délka " + Math.round(pltFile.getDelkaCar()) + "); přejezdů " + pltFile.getPocetPrejezdu() + " (délka " + Math.round(pltFile.getDelkaPrejezdu()) + ")");
  198
+            SwingWorker sw = new SwingWorker<Void, Void>() {
  199
+
  200
+                @Override
  201
+                protected Void doInBackground() throws Exception {
  202
+                    pltFile.optimizePLT();
  203
+                    return null;
  204
+                }
  205
+
  206
+                @Override
  207
+                protected void done() {
  208
+                    pltFile = pltFile.getOptimizedPLT();
  209
+                    pltFile.addPropertyChangeListener(PLTtools.this);
  210
+                    pLTpanel1.setPlt(pltFile);            
  211
+                    jLabel1.setText("PLT info: čar " + pltFile.getPocetCar() + " (délka " + Math.round(pltFile.getDelkaCar()) + "); přejezdů " + pltFile.getPocetPrejezdu() + " (délka " + Math.round(pltFile.getDelkaPrejezdu()) + ")");
  212
+                }};      
  213
+            executorService.submit(sw);
159 214
         }
160 215
     }//GEN-LAST:event_jButton2ActionPerformed
161 216
 
@@ -176,6 +231,22 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
176 231
         pLTpanel1.repaint();
177 232
     }//GEN-LAST:event_jCheckBox2ActionPerformed
178 233
 
  234
+    @Override
  235
+    public void propertyChange(PropertyChangeEvent evt) {
  236
+        if (evt.getPropertyName().equals("fileRead")) {
  237
+            System.out.println("reader: file read");
  238
+            jLabel1.setText("PLT info: čar " + pltFile.getPocetCar() + " (délka " + Math.round(pltFile.getDelkaCar()) + "); přejezdů " + pltFile.getPocetPrejezdu() + " (délka " + Math.round(pltFile.getDelkaPrejezdu()) + ")");
  239
+            pLTpanel1.setPlt(pltFile);            
  240
+        } else if (evt.getPropertyName().equals("progressValue")) {
  241
+            jProgressBar1.setValue((Integer) evt.getNewValue());
  242
+        } else if (evt.getPropertyName().equals("progressMessage")) {
  243
+            jProgressBar1.setString((String) evt.getNewValue());
  244
+        } else if (evt.getPropertyName().equals("progressFinished")) {
  245
+            jProgressBar1.setValue(0);
  246
+            jProgressBar1.setString("Ready");
  247
+        }
  248
+    }
  249
+
179 250
     /**
180 251
      * @param args the command line arguments
181 252
      */
@@ -212,6 +283,7 @@ public static void main(String args[]) {
212 283
          */
213 284
         java.awt.EventQueue.invokeLater(new Runnable() {
214 285
 
  286
+            @Override
215 287
             public void run() {
216 288
                 new PLTtools().setVisible(true);
217 289
             }
@@ -225,6 +297,8 @@ public void run() {
225 297
     private javax.swing.JCheckBox jCheckBox2;
226 298
     private javax.swing.JFileChooser jFileChooser1;
227 299
     private javax.swing.JLabel jLabel1;
  300
+    private javax.swing.JProgressBar jProgressBar1;
228 301
     private plttools.PLTpanel pLTpanel1;
229 302
     // End of variables declaration//GEN-END:variables
  303
+
230 304
 }

0 notes on commit e56f556

Please sign in to comment.
Something went wrong with that request. Please try again.