Stefan Schuermans commited on 2011-09-11 16:49:24
Showing 4 changed files, with 181 additions and 5 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.2 2011-09-11 |
|
7 |
+---------------- |
|
8 |
+added scrolling text generator |
|
9 |
+ |
|
6 | 10 |
1.4.1 2011-09-11 |
7 | 11 |
---------------- |
8 | 12 |
added FlexiPix output feature |
... | ... |
@@ -75,7 +75,7 @@ public class Blimp extends JApplet |
75 | 75 |
JFrame frame; //main window (if running as full application) |
76 | 76 |
Component dialogParent; //parent to use for dialogs |
77 | 77 |
JMenuBar menubar; //menubar in main window |
78 |
- JMenu menuFile, menuInfo, menuEdit, menuFrameSel, menuPlay; //menus |
|
78 |
+ JMenu menuFile, menuInfo, menuEdit, menuFrameSel, menuGen, menuPlay; //menus |
|
79 | 79 |
JMenu menuOutput, menuHelp; |
80 | 80 |
JMenuItem menuFileNew, menuFileLoad, menuFileSave, menuFileSaveAs, menuFileQuit; |
81 | 81 |
JMenuItem menuInfoShow, menuInfoAdd, menuInfoDelete; |
... | ... |
@@ -85,6 +85,7 @@ public class Blimp extends JApplet |
85 | 85 |
JMenuItem menuEditInsertFrame, menuEditDuplicateFrame, menuEditDeleteFrame; |
86 | 86 |
JMenuItem menuFrameSelNone, menuFrameSelSingle, menuFrameSelStart, menuFrameSelEnd; |
87 | 87 |
JMenuItem menuFrameSelCopy, menuFrameSelMove, menuFrameSelReverse, menuFrameSelDelete; |
88 |
+ JMenuItem menuGenScrollText; |
|
88 | 89 |
JMenuItem menuEditImportImages, menuEditImportMovie; |
89 | 90 |
JMenuItem menuPlayStart, menuPlayStop; |
90 | 91 |
JCheckBoxMenuItem menuPlayBegin, menuPlayLoop; |
... | ... |
@@ -428,7 +429,7 @@ public class Blimp extends JApplet |
428 | 429 |
info[i] = curMovie.getInfoType( i ) + ": " + |
429 | 430 |
curMovie.getInfoData( i ); |
430 | 431 |
|
431 |
- //ask for new size |
|
432 |
+ //ask for information to delete |
|
432 | 433 |
selected = JOptionPane.showInputDialog( dialogParent, |
433 | 434 |
"Select information to delete:", |
434 | 435 |
"Blimp - Delete Information...", |
... | ... |
@@ -742,8 +743,8 @@ public class Blimp extends JApplet |
742 | 743 |
bufferedImage.getGraphics( ).drawImage( image, 0, 0, width, height, null ); |
743 | 744 |
|
744 | 745 |
//create new empty frame |
745 |
- newFrame = new BlinkenFrame( height, width, |
|
746 |
- curMovie.getChannels( ), curMovie.getMaxval( ), defDuration ); |
|
746 |
+ newFrame = new BlinkenFrame( height, width, curMovie.getChannels( ), |
|
747 |
+ curMovie.getMaxval( ), defDuration ); |
|
747 | 748 |
height = newFrame.getHeight( ); //dimensions might have been invalid and thus been adapted |
748 | 749 |
width = newFrame.getWidth( ); |
749 | 750 |
newFrame.clear( ); |
... | ... |
@@ -1018,6 +1019,162 @@ public class Blimp extends JApplet |
1018 | 1019 |
updateFrames( frameNo ); |
1019 | 1020 |
} |
1020 | 1021 |
|
1022 |
+ //"Generate Scrolling Text..." was chosen from menu |
|
1023 |
+ private void actionGenScrollText( ) |
|
1024 |
+ { |
|
1025 |
+ GraphicsEnvironment graphEnv; |
|
1026 |
+ Font [] fonts; |
|
1027 |
+ String [] fontNames; |
|
1028 |
+ int i, width, height, x, y, frameCnt, frameNo, frameNoStart; |
|
1029 |
+ int fontHeight, fontPos, textWidth, textPos; |
|
1030 |
+ Object res; |
|
1031 |
+ Font font, scaledFont; |
|
1032 |
+ String text; |
|
1033 |
+ BufferedImage imgBackgr, img; |
|
1034 |
+ Graphics2D grBackgr, gr; |
|
1035 |
+ float fontSize; |
|
1036 |
+ FontMetrics metrics; |
|
1037 |
+ BlinkenFrame frame; |
|
1038 |
+ |
|
1039 |
+ //do nothing if there is no current frame |
|
1040 |
+ if( curFrame == null ) { |
|
1041 |
+ labelStatus.setText( "Generate Scrolling Text: " + |
|
1042 |
+ "not possible withpout current frame as background..." ); |
|
1043 |
+ return; |
|
1044 |
+ } |
|
1045 |
+ |
|
1046 |
+ //get available fonts and their names |
|
1047 |
+ graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment( ); |
|
1048 |
+ fonts = graphEnv.getAllFonts( ); |
|
1049 |
+ fontNames = new String [fonts.length]; |
|
1050 |
+ for( i = 0; i < fonts.length; ++i ) |
|
1051 |
+ fontNames[i] = fonts[i].getFontName( ); |
|
1052 |
+ |
|
1053 |
+ |
|
1054 |
+ //let user choose a font |
|
1055 |
+ res = JOptionPane.showInputDialog( dialogParent, |
|
1056 |
+ "Please note that scrolling text" + |
|
1057 |
+ " is one of the most boring things" + |
|
1058 |
+ " to look at.\n\n" + |
|
1059 |
+ "Select font:", |
|
1060 |
+ "Blimp - Generate Scrolling Text...", |
|
1061 |
+ JOptionPane.QUESTION_MESSAGE, |
|
1062 |
+ null, fontNames, null ); |
|
1063 |
+ if( res == null ) { //exit if dialog was cancelled |
|
1064 |
+ labelStatus.setText( "Generate Scrolling Text: cancelled..." ); |
|
1065 |
+ return; |
|
1066 |
+ } |
|
1067 |
+ |
|
1068 |
+ //get selected font |
|
1069 |
+ font = null; |
|
1070 |
+ for( i = 0; i < fontNames.length; i++ ) { |
|
1071 |
+ if( fontNames[i] == res ) { |
|
1072 |
+ font = fonts[i]; |
|
1073 |
+ break; |
|
1074 |
+ } |
|
1075 |
+ } |
|
1076 |
+ if( font == null ) { // could not get font |
|
1077 |
+ labelStatus.setText( "Generate Scrolling Text: no font selected..." ); |
|
1078 |
+ return; |
|
1079 |
+ } |
|
1080 |
+ //free unused fonts |
|
1081 |
+ fonts = null; |
|
1082 |
+ fontNames = null; |
|
1083 |
+ |
|
1084 |
+ //ask user for text |
|
1085 |
+ res = JOptionPane.showInputDialog( dialogParent, |
|
1086 |
+ "Please note that scrolling text" + |
|
1087 |
+ " is one of the most boring things" + |
|
1088 |
+ " to look at.\n\n" + |
|
1089 |
+ "Enter text:", |
|
1090 |
+ "Blimp - Generate Scrolling Text...", |
|
1091 |
+ JOptionPane.QUESTION_MESSAGE, |
|
1092 |
+ null, null, "" ); |
|
1093 |
+ if( res == null ) { //exit if dialog was cancelled |
|
1094 |
+ labelStatus.setText( "Generate Scrolling Text: cancelled..." ); |
|
1095 |
+ return; |
|
1096 |
+ } |
|
1097 |
+ text = res.toString( ); |
|
1098 |
+ if( text.length( ) == 0 ) { //exit if no text was entered |
|
1099 |
+ labelStatus.setText( "Generate Scrolling Text: no text entered..." ); |
|
1100 |
+ return; |
|
1101 |
+ } |
|
1102 |
+ |
|
1103 |
+ //get current frame as buffered image to use as background |
|
1104 |
+ width = curFrame.getWidth( ); |
|
1105 |
+ height = curFrame.getHeight( ); |
|
1106 |
+ imgBackgr = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB ); |
|
1107 |
+ for( y = 0; y < height; y++ ) |
|
1108 |
+ for( x = 0; x < width; x++ ) |
|
1109 |
+ imgBackgr.setRGB( x, y, curFrame.getColor( y, x ).getRGB( ) ); |
|
1110 |
+ |
|
1111 |
+ //adapt font size until height matches frame |
|
1112 |
+ grBackgr = imgBackgr.createGraphics( ); |
|
1113 |
+ fontSize = 1.0f; |
|
1114 |
+ while( true ) { |
|
1115 |
+ scaledFont = font.deriveFont( fontSize ); |
|
1116 |
+ metrics = grBackgr.getFontMetrics( scaledFont ); |
|
1117 |
+ fontHeight = metrics.getAscent( ) + |
|
1118 |
+ metrics.getDescent( ) + |
|
1119 |
+ metrics.getLeading( ); |
|
1120 |
+ if( fontHeight == height ) |
|
1121 |
+ break; |
|
1122 |
+ else if( fontHeight <= 0 ) |
|
1123 |
+ fontSize *= 100.0f; |
|
1124 |
+ else |
|
1125 |
+ fontSize *= (float)height / (float)fontHeight; |
|
1126 |
+ } |
|
1127 |
+ |
|
1128 |
+ //get position where to insert frames |
|
1129 |
+ frameCnt = curMovie.getFrameCnt( ); |
|
1130 |
+ frameNoStart = scrollFrames.getValue( ) + 1; |
|
1131 |
+ if( frameNoStart < 0 ) |
|
1132 |
+ frameNoStart = 0; |
|
1133 |
+ if( frameNoStart > frameCnt ) |
|
1134 |
+ frameNoStart = frameCnt; |
|
1135 |
+ |
|
1136 |
+ //render scrolling text on top of backround image |
|
1137 |
+ fontPos = metrics.getAscent( ) + metrics.getLeading( ) / 2; |
|
1138 |
+ textWidth = metrics.charsWidth( text.toCharArray( ), 0, text.length( ) ); |
|
1139 |
+ frameNo = frameNoStart; |
|
1140 |
+ for( textPos = width; textPos >= -textWidth ; textPos-- ) { |
|
1141 |
+ |
|
1142 |
+ //duplicate background and render text onto it |
|
1143 |
+ img = new BufferedImage( imgBackgr.getColorModel( ), |
|
1144 |
+ imgBackgr.copyData( null ), |
|
1145 |
+ imgBackgr.getColorModel( ).isAlphaPremultiplied( ), |
|
1146 |
+ null ); |
|
1147 |
+ gr = img.createGraphics( ); |
|
1148 |
+ gr.setColor( frameEditor.getColor( ) ); |
|
1149 |
+ gr.setFont( scaledFont ); |
|
1150 |
+ gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, |
|
1151 |
+ RenderingHints.VALUE_ANTIALIAS_ON ); |
|
1152 |
+ gr.drawString( text, textPos, fontPos ); |
|
1153 |
+ |
|
1154 |
+ //convert image to BlinkenFrame and intert it into movie |
|
1155 |
+ frame = new BlinkenFrame( height, width, |
|
1156 |
+ curFrame.getChannels( ), |
|
1157 |
+ curFrame.getMaxval( ), |
|
1158 |
+ curFrame.getDuration( ) ); |
|
1159 |
+ for( y = 0; y < height; y++ ) |
|
1160 |
+ for( x = 0; x < width; x++ ) |
|
1161 |
+ frame.setColor( y, x, new Color( img.getRGB( x, y ) ) ); |
|
1162 |
+ curMovie.insertFrame( frameNo, frame ); |
|
1163 |
+ frameNo++; |
|
1164 |
+ |
|
1165 |
+ } |
|
1166 |
+ curMovieChanged = true; |
|
1167 |
+ |
|
1168 |
+ //update controls |
|
1169 |
+ updateFrames( frameSelStart ); |
|
1170 |
+ //select newly inserted frames |
|
1171 |
+ frameSelStart = frameNoStart; |
|
1172 |
+ frameSelEnd = frameNo - 1; |
|
1173 |
+ stateFrameSel( ); |
|
1174 |
+ |
|
1175 |
+ labelStatus.setText( "Generate Scrolling Text: generated frames inserted..." ); |
|
1176 |
+ } |
|
1177 |
+ |
|
1021 | 1178 |
//"Play Start" was chosen from menu |
1022 | 1179 |
private void actionPlayStart( ) |
1023 | 1180 |
{ |
... | ... |
@@ -2026,6 +2183,8 @@ public class Blimp extends JApplet |
2026 | 2183 |
actionFrameSelReverse( ); |
2027 | 2184 |
else if( e.getSource( ) == menuFrameSelDelete ) |
2028 | 2185 |
actionFrameSelDelete( ); |
2186 |
+ else if( e.getSource( ) == menuGenScrollText ) |
|
2187 |
+ actionGenScrollText( ); |
|
2029 | 2188 |
else if( e.getSource( ) == menuPlayStart ) |
2030 | 2189 |
actionPlayStart( ); |
2031 | 2190 |
else if( e.getSource( ) == menuPlayStop ) |
... | ... |
@@ -2548,6 +2707,14 @@ public class Blimp extends JApplet |
2548 | 2707 |
menuFrameSelDelete.setEnabled( false ); |
2549 | 2708 |
menuFrameSelDelete.addActionListener( this ); |
2550 | 2709 |
menuFrameSel.add( menuFrameSelDelete ); |
2710 |
+ //generate menu |
|
2711 |
+ menuGen = new JMenu( "Generate" ); |
|
2712 |
+ menuGen.setMnemonic( KeyEvent.VK_G ); |
|
2713 |
+ menubar.add( menuGen ); |
|
2714 |
+ menuGenScrollText = new JMenuItem( "Scrolling Text..." ); |
|
2715 |
+ menuGenScrollText.setMnemonic( KeyEvent.VK_S ); |
|
2716 |
+ menuGenScrollText.addActionListener( this ); |
|
2717 |
+ menuGen.add( menuGenScrollText ); |
|
2551 | 2718 |
//play menu |
2552 | 2719 |
menuPlay = new JMenu( "Play" ); |
2553 | 2720 |
menuPlay.setMnemonic( KeyEvent.VK_P ); |