added FlexiPix output
Stefan Schuermans

Stefan Schuermans commited on 2011-09-11 12:37:05
Showing 3 changed files, with 109 additions and 7 deletions.

... ...
@@ -3,6 +3,10 @@ Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>
3 3
 Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
 a blinkenarea.org project
5 5
 
6
+1.4.1 2011-09-11
7
+----------------
8
+added FlexiPix output feature
9
+
6 10
 1.4.0 2011-09-10
7 11
 ----------------
8 12
 added MCUF output feature
... ...
@@ -3,11 +3,12 @@
3 3
 # Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
 # a blinkenarea.org project
5 5
 
6
-BLINKEN_LIB=../BlinkenLibJava/BlinkenLib.jar
6
+BLINKENLIB=../BlinkenLibJava/BlinkenLib.jar
7
+JFLEXIPIX=../JFlexiPix/JFlexiPix.jar
7 8
 
8 9
 VERSION_MAJOR=1
9 10
 VERSION_MINOR=4
10
-VERSION_REVISION=0
11
+VERSION_REVISION=1
11 12
 
12 13
 JAVAC=javac
13 14
 JAR=jar
... ...
@@ -18,7 +19,7 @@ JAVA=java
18 19
 P=org/blinkenarea/Blimp
19 20
 IMG=$(P)/images
20 21
 
21
-CLASSPATH=.:$(BLINKEN_LIB)
22
+CLASSPATH=.:$(BLINKENLIB):$(JFLEXIPIX)
22 23
 CLASS_FILES=$(P)/BlinkenFileFilter.class $(P)/BlinkenFrameDisplay.class \
23 24
             $(P)/BlinkenFrameDisplayListener.class $(P)/BlinkenFrameDisplayInterceptor.class \
24 25
             $(P)/BlinkenFrameEditor.class $(P)/BlinkenFrameEditorListener.class \
... ...
@@ -89,7 +89,7 @@ public class Blimp extends JApplet
89 89
   JMenuItem menuPlayStart, menuPlayStop;
90 90
   JCheckBoxMenuItem menuPlayBegin, menuPlayLoop;
91 91
   ButtonGroup groupOutput;
92
-  JRadioButtonMenuItem menuOutputNone, menuOutputMcuf;
92
+  JRadioButtonMenuItem menuOutputNone, menuOutputMcuf, menuOutputFlexiPix;
93 93
   JMenuItem menuHelpAbout;
94 94
   JPanel panel, panelStatus, panelMain, panelFrames, panelOuterFrame; //panels of main window
95 95
   JPanel panelMiddleFrame, panelFrame, panelDuration, panelColors;
... ...
@@ -141,6 +141,9 @@ public class Blimp extends JApplet
141 141
   InetAddress outMcufHost; //host part of destination
142 142
   int outMcufPort; //port part of destination
143 143
   DatagramSocket outMcufSock; // UDP socket to send MCUF output on
144
+  File outFlexiPixCurDir = null;  //directory of config file
145
+  File outFlexiPixCurFile = null; //config file
146
+  org.blinkenarea.JFlexiPix.Display outFlexiPixDisplay; //FlexiPix display
144 147
 
145 148
   //other variables
146 149
   boolean noRecurseZoomAspect = false; //set when changing zoom or aspect value per program to inhibit recursion triggered by events
... ...
@@ -1102,6 +1105,10 @@ public class Blimp extends JApplet
1102 1105
       outMcufSock = null;
1103 1106
     }
1104 1107
 
1108
+    //close FlexiPix output
1109
+    if( outFlexiPixDisplay != null )
1110
+      outFlexiPixDisplay = null;
1111
+
1105 1112
     //set status to no output
1106 1113
     menuOutputNone.setSelected( true );
1107 1114
     labelStatus.setText( "output turned off..." );
... ...
@@ -1190,6 +1197,48 @@ public class Blimp extends JApplet
1190 1197
     outFrame( );
1191 1198
   }
1192 1199
 
1200
+  //"Output FlexiPix" was chosen from menu
1201
+  private void actionOutputFlexiPix( )
1202
+  {
1203
+    JFileChooser fileChooser;
1204
+    String cfgFile;
1205
+
1206
+    //reset outputs
1207
+    actionOutputNone( );
1208
+
1209
+    //ask for config file
1210
+    fileChooser = new JFileChooser( );
1211
+    fileChooser.setDialogTitle( "Blimp - Output FlexiPix..." );
1212
+    if( outFlexiPixCurDir != null )
1213
+      fileChooser.setCurrentDirectory( outFlexiPixCurDir );
1214
+    if( fileChooser.showOpenDialog( dialogParent ) != JFileChooser.APPROVE_OPTION )
1215
+      return;
1216
+    //save current directory and current file
1217
+    outFlexiPixCurDir = fileChooser.getCurrentDirectory( );
1218
+    outFlexiPixCurFile = fileChooser.getSelectedFile( );
1219
+    cfgFile = outFlexiPixCurFile.getPath( );
1220
+
1221
+    //create FlexiPix display
1222
+    try
1223
+    {
1224
+      outFlexiPixDisplay = new org.blinkenarea.JFlexiPix.Display( cfgFile, null );
1225
+    }
1226
+    catch( Exception e )
1227
+    {
1228
+      //cannot create display -> turn off output
1229
+      actionOutputNone( );
1230
+      labelStatus.setText( "FlexiPix output: cannot create display: " + e.getMessage( ) );
1231
+      return;
1232
+    }
1233
+
1234
+    //set status to FlexiPix output
1235
+    menuOutputFlexiPix.setSelected( true );
1236
+    labelStatus.setText( "FlexiPix output using \"" + cfgFile + "\" ..." );
1237
+
1238
+    //output current frame
1239
+    outFrame( );
1240
+  }
1241
+
1193 1242
   //output timer elapsed
1194 1243
   private void actionOutTimer( )
1195 1244
   {
... ...
@@ -1206,10 +1255,14 @@ public class Blimp extends JApplet
1206 1255
                                    "Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info>\n" +
1207 1256
                                    "Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html\n" +
1208 1257
                                    "a blinkenarea.org project\n\n" +
1209
-                                   String.format( "contains BlinkenLibJava %d.%d.%d",
1258
+                                   String.format( "contains BlinkenLibJava %d.%d.%d\n",
1210 1259
                                                   org.blinkenarea.BlinkenLib.Version.Major,
1211 1260
                                                   org.blinkenarea.BlinkenLib.Version.Minor,
1212
-                                                  org.blinkenarea.BlinkenLib.Version.Revision ),
1261
+                                                  org.blinkenarea.BlinkenLib.Version.Revision ) +
1262
+                                   String.format( "contains JFlexiPix %d.%d.%d\n",
1263
+                                                  org.blinkenarea.JFlexiPix.Version.Major,
1264
+                                                  org.blinkenarea.JFlexiPix.Version.Minor,
1265
+                                                  org.blinkenarea.JFlexiPix.Version.Revision ),
1213 1266
                                    "Blimp - About...",
1214 1267
                                    JOptionPane.INFORMATION_MESSAGE );
1215 1268
   }
... ...
@@ -1983,6 +2036,8 @@ public class Blimp extends JApplet
1983 2036
       actionOutputNone( );
1984 2037
     else if( e.getSource( ) == menuOutputMcuf )
1985 2038
       actionOutputMcuf( );
2039
+    else if( e.getSource( ) == menuOutputFlexiPix )
2040
+      actionOutputFlexiPix( );
1986 2041
     else if( e.getSource( ) == timerOut )
1987 2042
       actionOutTimer( );
1988 2043
     else if( e.getSource( ) == menuHelpAbout )
... ...
@@ -2217,6 +2272,10 @@ public class Blimp extends JApplet
2217 2272
     if( menuOutputMcuf.isSelected( ) )
2218 2273
       outMcuf( );
2219 2274
 
2275
+    //FlexiPix output
2276
+    if( menuOutputFlexiPix.isSelected( ) )
2277
+      outFlexiPix( );
2278
+
2220 2279
     //re-output after 1 s
2221 2280
     timerOut.setInitialDelay( 1000 );
2222 2281
     timerOut.restart( );
... ...
@@ -2228,7 +2287,7 @@ public class Blimp extends JApplet
2228 2287
     byte [] data;
2229 2288
     DatagramPacket pack;
2230 2289
 
2231
-    // exit if nos socket
2290
+    // exit if no socket
2232 2291
     if( outMcufSock == null )
2233 2292
       return;
2234 2293
 
... ...
@@ -2247,6 +2306,39 @@ public class Blimp extends JApplet
2247 2306
     }
2248 2307
   }
2249 2308
 
2309
+  //output current frame to FlexiPix
2310
+  private void outFlexiPix( )
2311
+  {
2312
+    BlinkenFrame frame;
2313
+    int width, height;
2314
+    byte [] data;
2315
+
2316
+    // exit if no FlexiPix display
2317
+    if( outFlexiPixDisplay == null )
2318
+      return;
2319
+
2320
+    //convert current frame to 24bit RGB and FlexiPix display size
2321
+    frame = new BlinkenFrame( curFrame );
2322
+    frame.resize( frame.getHeight( ), frame.getWidth( ), 3, 255 );
2323
+    width = outFlexiPixDisplay.getWidth( );
2324
+    height = outFlexiPixDisplay.getHeight( );
2325
+    frame.scale( height, width );
2326
+
2327
+    //convert frame into MCUF data
2328
+    data = frame.toNetwork( BlinkenConstants.BlinkenProtoMcuf );
2329
+    if( data == null || data.length == 0 )
2330
+      return;
2331
+
2332
+    //transfer data to FlexiPix display object
2333
+    outFlexiPixDisplay.data(data,
2334
+                            3, width * 3,         // x stride, y stride
2335
+                            12,                   // index of top-left pixel
2336
+                            0, 0, width, height); // whole area
2337
+
2338
+    //send packets to real FlexiPix display
2339
+    outFlexiPixDisplay.send( );
2340
+  }
2341
+
2250 2342
   //entry point of main thread
2251 2343
   public void run( )
2252 2344
   {
... ...
@@ -2495,6 +2587,11 @@ public class Blimp extends JApplet
2495 2587
     menuOutputMcuf.addActionListener( this );
2496 2588
     menuOutput.add( menuOutputMcuf );
2497 2589
     groupOutput.add( menuOutputMcuf );
2590
+    menuOutputFlexiPix = new JRadioButtonMenuItem( "FlexiPix", false );
2591
+    menuOutputFlexiPix.setMnemonic( KeyEvent.VK_F );
2592
+    menuOutputFlexiPix.addActionListener( this );
2593
+    menuOutput.add( menuOutputFlexiPix );
2594
+    groupOutput.add( menuOutputFlexiPix );
2498 2595
     menuOutputNone.setSelected( true );
2499 2596
     //help menu
2500 2597
     menuHelp = new JMenu( "Help" );
2501 2598