1 package org.enhydra.jawe.actions; 2 3 import javax.swing.*; 4 import org.enhydra.jawe.*; 5 import org.enhydra.jawe.xml.*; 6 import java.awt.event.*; 7 import java.io.*; 8 import javax.swing.*; 9 import javax.swing.text.*; 10 import java.awt.*; 11 12 18 public class TextSaveAs extends AbstractAction { 19 20 private JTextComponent textComponent = null; 21 22 public TextSaveAs(JTextComponent textComponent) { 23 this.textComponent = textComponent; 24 putValue(Action.NAME,Utils.getUnqualifiedClassName(getClass())); 25 } 26 27 public void actionPerformed(ActionEvent e) { 28 String fileName = XMLUtil.dialog(null, XMLUtil.getLanguageDependentString("SaveAsLabel"), 1, 3, "new_file.txt"); 29 if( fileName != null ) { 30 if( !this.saveFile(fileName) ) 31 XMLUtil.message(XMLUtil.getLanguageDependentString("ErrorErrorWhileSaveFile"), XMLUtil.ERROR_MESSAGE); 32 } 33 } 34 35 private boolean saveFile(String fileName) { 36 boolean success = true; 37 try { 38 File saveAsFile = new File( fileName ); 39 FileOutputStream fos = new FileOutputStream( saveAsFile ); 40 PrintStream printStream = new PrintStream(fos, true, JaWEConfig.getInstance().getEncoding()); 41 String text = new String ( textComponent.getText() ); 42 printStream.print(text); 43 fos.close(); 44 printStream.close(); 45 }catch(Exception e) { 46 e.printStackTrace(); 47 success = false; 48 } 49 return success; 50 } 51 52 } 53 | Popular Tags |