add MCUF file/device output
Stefan Schuermans

Stefan Schuermans commited on 2013-10-26 10:24:14
Showing 9 changed files, with 123 additions and 13 deletions.

... ...
@@ -1,8 +1,12 @@
1 1
 BlinkenLightsInteractiveMovieProgram
2
-Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
 Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
 a blinkenarea.org project
5 5
 
6
+1.4.3 2013-10-26
7
+----------------
8
+added MCUF output to file/device
9
+
6 10
 1.4.2 2011-09-11
7 11
 ----------------
8 12
 added scrolling text generator
... ...
@@ -1,5 +1,5 @@
1 1
 # BlinkenLightsInteractiveMovieProgram
2
-# Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+# Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
 # Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
 # a blinkenarea.org project
5 5
 
... ...
@@ -8,7 +8,7 @@ JFLEXIPIX=../JFlexiPix/JFlexiPix.jar
8 8
 
9 9
 VERSION_MAJOR=1
10 10
 VERSION_MINOR=4
11
-VERSION_REVISION=2
11
+VERSION_REVISION=3
12 12
 
13 13
 JAVAC=javac
14 14
 JAR=jar
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -90,7 +90,7 @@ public class Blimp extends JApplet
90 90
   JMenuItem menuPlayStart, menuPlayStop;
91 91
   JCheckBoxMenuItem menuPlayBegin, menuPlayLoop;
92 92
   ButtonGroup groupOutput;
93
-  JRadioButtonMenuItem menuOutputNone, menuOutputMcuf, menuOutputFlexiPix;
93
+  JRadioButtonMenuItem menuOutputNone, menuOutputMcuf, menuOutputMcufFile, menuOutputFlexiPix;
94 94
   JMenuItem menuHelpAbout;
95 95
   JPanel panel, panelStatus, panelMain, panelFrames, panelOuterFrame; //panels of main window
96 96
   JPanel panelMiddleFrame, panelFrame, panelDuration, panelColors;
... ...
@@ -142,6 +142,8 @@ public class Blimp extends JApplet
142 142
   InetAddress outMcufHost; //host part of destination
143 143
   int outMcufPort; //port part of destination
144 144
   DatagramSocket outMcufSock; // UDP socket to send MCUF output on
145
+  String outMcufFileName; // name of MCUF output file
146
+  FileOutputStream outMcufFile; // file/device to output MCUF to
145 147
   File outFlexiPixCurDir = null;  //directory of config file
146 148
   File outFlexiPixCurFile = null; //config file
147 149
   org.blinkenarea.JFlexiPix.Display outFlexiPixDisplay; //FlexiPix display
... ...
@@ -1262,6 +1264,18 @@ public class Blimp extends JApplet
1262 1264
       outMcufSock = null;
1263 1265
     }
1264 1266
 
1267
+    //close MCUF file output
1268
+    if( outMcufFile != null ) {
1269
+      try
1270
+      {
1271
+        outMcufFile.close( );
1272
+      }
1273
+      catch( java.io.IOException e )
1274
+      {
1275
+      }
1276
+      outMcufFile = null;
1277
+    }
1278
+
1265 1279
     //close FlexiPix output
1266 1280
     if( outFlexiPixDisplay != null )
1267 1281
       outFlexiPixDisplay = null;
... ...
@@ -1354,6 +1368,63 @@ public class Blimp extends JApplet
1354 1368
     outFrame( );
1355 1369
   }
1356 1370
 
1371
+  //"Output Mcuf file/device" was chosen from menu
1372
+  private void actionOutputMcufFile( )
1373
+  {
1374
+    Object fileDevice;
1375
+    String fileName;
1376
+    FileOutputStream file;
1377
+
1378
+    //reset outputs
1379
+    actionOutputNone( );
1380
+
1381
+    //ask for file/device name
1382
+    fileDevice = JOptionPane.showInputDialog( dialogParent,
1383
+                                              "Please enter the file/device name for the MCUF data:\n",
1384
+                                              "Blimp - Output MCUF file/device...",
1385
+                                              JOptionPane.QUESTION_MESSAGE,
1386
+                                              null, null, outMcufFileName );
1387
+    if( fileDevice == null )
1388
+    {
1389
+      //dialog was cancelled -> turn off output
1390
+      actionOutputNone( );
1391
+      labelStatus.setText( "MCUF file/device output: cancelled..." );
1392
+      return;
1393
+    }
1394
+    fileName = fileDevice.toString( );
1395
+
1396
+    //open file/device
1397
+    try
1398
+    {
1399
+      file = new FileOutputStream( fileName );
1400
+    }
1401
+    catch( FileNotFoundException e )
1402
+    {
1403
+      //cannot open file -> turn off output
1404
+      actionOutputNone( );
1405
+      labelStatus.setText( "MCUF file/device output: cannot open file \"" + fileName + "\"..." );
1406
+      return;
1407
+    }
1408
+    catch( SecurityException e )
1409
+    {
1410
+      //not allowed to open file -> turn off output
1411
+      actionOutputNone( );
1412
+      labelStatus.setText( "MCUF file/device output: no poermission to open file \"" + fileName + "\"..." );
1413
+      return;
1414
+    }
1415
+
1416
+    //remember new file name and file
1417
+    outMcufFileName = fileName;
1418
+    outMcufFile = file;
1419
+
1420
+    //set status to MCUF file/device output
1421
+    menuOutputMcufFile.setSelected( true );
1422
+    labelStatus.setText( "MCUF file/device output to \"" + fileName + "\" ..." );
1423
+
1424
+    //output current frame
1425
+    outFrame( );
1426
+  }
1427
+
1357 1428
   //"Output FlexiPix" was chosen from menu
1358 1429
   private void actionOutputFlexiPix( )
1359 1430
   {
... ...
@@ -1409,7 +1480,7 @@ public class Blimp extends JApplet
1409 1480
     JOptionPane.showMessageDialog( dialogParent,
1410 1481
                                    "BlinkenLightsInteractiveMovieProgram\n" +
1411 1482
                                    String.format( "version %d.%d.%d\n", Version.Major, Version.Minor, Version.Revision ) +
1412
-                                   "Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>\n" +
1483
+                                   "Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>\n" +
1413 1484
                                    "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" +
1414 1485
                                    "a blinkenarea.org project\n\n" +
1415 1486
                                    String.format( "contains BlinkenLibJava %d.%d.%d\n",
... ...
@@ -2195,6 +2266,8 @@ public class Blimp extends JApplet
2195 2266
       actionOutputNone( );
2196 2267
     else if( e.getSource( ) == menuOutputMcuf )
2197 2268
       actionOutputMcuf( );
2269
+    else if( e.getSource( ) == menuOutputMcufFile )
2270
+      actionOutputMcufFile( );
2198 2271
     else if( e.getSource( ) == menuOutputFlexiPix )
2199 2272
       actionOutputFlexiPix( );
2200 2273
     else if( e.getSource( ) == timerOut )
... ...
@@ -2431,6 +2504,10 @@ public class Blimp extends JApplet
2431 2504
     if( menuOutputMcuf.isSelected( ) )
2432 2505
       outMcuf( );
2433 2506
 
2507
+    //MCUF file output
2508
+    if( menuOutputMcufFile.isSelected( ) )
2509
+      outMcufFile( );
2510
+
2434 2511
     //FlexiPix output
2435 2512
     if( menuOutputFlexiPix.isSelected( ) )
2436 2513
       outFlexiPix( );
... ...
@@ -2465,6 +2542,30 @@ public class Blimp extends JApplet
2465 2542
     }
2466 2543
   }
2467 2544
 
2545
+  //output current frame via MCUF to file
2546
+  private void outMcufFile( )
2547
+  {
2548
+    byte [] data;
2549
+    DatagramPacket pack;
2550
+
2551
+    // exit if no file open
2552
+    if( outMcufFile == null )
2553
+      return;
2554
+
2555
+    //convert current frame into MCUF
2556
+    data = curFrame.toNetwork( BlinkenConstants.BlinkenProtoMcuf );
2557
+    if( data == null || data.length == 0 )
2558
+      return;
2559
+
2560
+    //write data to file
2561
+    try {
2562
+      outMcufFile.write( data );
2563
+    }
2564
+    catch( java.io.IOException e )
2565
+    {
2566
+    }
2567
+  }
2568
+
2468 2569
   //output current frame to FlexiPix
2469 2570
   private void outFlexiPix( )
2470 2571
   {
... ...
@@ -2754,6 +2855,11 @@ public class Blimp extends JApplet
2754 2855
     menuOutputMcuf.addActionListener( this );
2755 2856
     menuOutput.add( menuOutputMcuf );
2756 2857
     groupOutput.add( menuOutputMcuf );
2858
+    menuOutputMcufFile = new JRadioButtonMenuItem( "MCUF file/device", false );
2859
+    menuOutputMcufFile.setMnemonic( KeyEvent.VK_D );
2860
+    menuOutputMcufFile.addActionListener( this );
2861
+    menuOutput.add( menuOutputMcufFile );
2862
+    groupOutput.add( menuOutputMcufFile );
2757 2863
     menuOutputFlexiPix = new JRadioButtonMenuItem( "FlexiPix", false );
2758 2864
     menuOutputFlexiPix.setMnemonic( KeyEvent.VK_F );
2759 2865
     menuOutputFlexiPix.addActionListener( this );
... ...
@@ -3199,7 +3305,7 @@ public class Blimp extends JApplet
3199 3305
     //running as command line tool
3200 3306
     System.out.println( "BlinkenLightsInteractiveMovieProgram\n" +
3201 3307
                         String.format( "Blimp (version %d.%d.%d)", Version.Major, Version.Minor, Version.Revision ) +
3202
-                        "Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>\n" +
3308
+                        "Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>\n" +
3203 3309
                         "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" +
3204 3310
                         "a blinkenarea.org project\n" );
3205 3311
 
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLightsInteractiveMovieProgram
2
- * Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
2
+ * Copyright (C) 2004-2013: Stefan Schuermans <stefan@blinkenarea.org>
3 3
  * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
  * a blinkenarea.org project
5 5
  */
6 6