1 package com.ca.directory.jxplorer.editor; 2 3 import com.ca.commons.cbutil.*; 4 5 import javax.swing.*; 6 import java.awt.*; 7 import java.awt.event.ActionListener ; 8 import java.awt.event.ActionEvent ; 9 import java.io.*; 10 import java.util.logging.Logger ; 11 12 13 19 20 public class baseodmediaeditor extends defaultbinaryeditor 21 { 22 25 protected File file = null; 26 27 30 protected String title = "BaseODMediaEditor"; 31 32 35 protected String fileName = "BaseODMediaEditor"; 36 37 40 protected String extension = ""; 41 42 private static Logger log = Logger.getLogger(baseodmediaeditor.class.getName()); 43 44 48 49 public baseodmediaeditor(Frame owner) 50 { 51 super(owner); 52 this.setDialogTitle(title); 53 } 54 55 59 public void setDialogTitle(String title) 60 { 61 this.title = title; 62 super.setDialogTitle(CBIntText.get(title)); 63 } 64 65 69 public void setFileName(String fileName) 70 { 71 this.fileName = fileName; 72 } 73 74 78 public void setExtension(String extension) 79 { 80 this.extension = extension; 81 addChoosableFileFilter(new CBFileFilter(new String []{extension}, fileName + " Files (*" + extension +")")); 82 } 83 84 90 public JComponent addComponent() 91 { 92 CBButton btnView = new CBButton(CBIntText.get("Launch"), CBIntText.get("")); 93 btnView.setToolTipText(CBIntText.get("Launch the saved file into it's default application.")); 94 btnView.addActionListener(new ActionListener () 95 { 96 public void actionPerformed(ActionEvent e) 97 { 98 launch(); 99 } 100 }); 101 102 106 if (System.getProperty("os.name").equalsIgnoreCase("SunOS")) 107 return null; 108 else 109 return btnView; 110 } 111 112 113 117 118 public void launch() 119 { 120 if (bytes == null) 121 { 122 log.warning("No file to launch via " + fileName + "."); 123 return; 124 } 125 126 File dir = new File("temp"); 127 dir.mkdir(); 128 dir.deleteOnExit(); 129 130 file = new File(dir, fileName + extension); file.deleteOnExit(); 132 133 try 134 { 135 FileOutputStream output = new FileOutputStream(file); 136 output.write(bytes); 137 output.close(); 138 } 139 catch (IOException e) 140 { 141 CBUtility.error("Error writing to the file!" + e); 142 } 143 144 CBLauncher.launchProgram(extension, file.getPath()); 145 } 146 147 148 151 152 public void quit() 153 { 154 if (file != null) 155 file.delete(); 156 } 157 } | Popular Tags |