1 package cve.osservatori.servizioOACBuildSemantic; 2 3 import javax.swing.JInternalFrame ; 4 import javax.swing.tree.*; 5 import javax.swing.*; 6 import javax.swing.event.*; 7 import java.io.*; 8 9 import java.awt.event.*; 10 import java.awt.*; 11 import java.util.*; 12 13 import cve.osservatori.*; 14 import cve.core.elementLDL.*; 15 import cve.core.elementEEL.*; 16 import cve.util.ConfigurationRead; 17 import cve.staticLayout.*; 18 19 import interactionGraphics.*; 20 21 import cve.staticLayout.*; 22 import org.apache.log4j.Logger; 23 24 32 public class EditorRules extends GenericFrame 33 implements ItemListener,ActionListener, ChangeListener { 34 private OACBuildSemantic oac; 35 private String file_in; 36 private JPanel jpanelText; 37 private JPanel jpanelButton; 38 39 private JTextArea textArea; 40 private JButton b_save, b_cancel; 41 42 public EditorRules(String Title, String iconPath){ 43 super(Title, iconPath); 44 Cve.errLog.debug(""); 45 }; 46 47 48 public void init(String file) { 50 51 Cve.errLog.debug(""); 52 this.file_in = file; 54 55 jpanelText = new JPanel(); 57 jpanelText.setLayout(new BorderLayout()); 58 59 textArea=new JTextArea(); 61 textArea.setEditable(true); 62 JScrollPane scrollPane = new JScrollPane(textArea); 63 loadFile(); 64 jpanelText.add(scrollPane); 65 66 jpanelButton = new JPanel(); 68 jpanelButton.setLayout(new GridLayout(1,2)); 69 70 ImageIcon iconsave = new ImageIcon(ConfigurationRead.getCveRoot() + "//resource//SAVE.gif"); 71 b_save = new JButton("Save",iconsave); 72 b_save.addActionListener(this); 73 ImageIcon iconcancel = new ImageIcon(ConfigurationRead.getCveRoot() + "//resource//CANCEL.gif"); 74 75 b_cancel = new JButton("Cancel", iconcancel); 76 b_cancel.addActionListener(this); 77 78 jpanelButton.add(b_save); 79 jpanelButton.add(b_cancel); 80 81 this.getContentPane().add(jpanelText,BorderLayout.CENTER); 83 this.getContentPane().add(jpanelButton,BorderLayout.SOUTH); 84 } 85 86 public void setOAC(OACBuildSemantic oac_in){ 88 Cve.errLog.debug(""); 89 this.oac = oac_in; 90 } 91 92 95 private void loadFile() { 96 Cve.errLog.debug(""); 97 String all=new String (""),line; 98 BufferedReader str_input=null; 99 try { 100 str_input = new BufferedReader(new FileReader(file_in)); 101 } catch (Exception e) { 102 Cve.errLog.error(e.toString()); 103 System.out.println("ATTENZIONE!Impossibile aprire il file perchè: "+ e +"\n"); 104 } 105 106 try { 107 while((line=str_input.readLine())!=null) textArea.append(line + "\n"); 108 }catch (Exception e){ 109 Cve.errLog.error(e.toString()); 110 System.out.println("ATTENZIONE!Errore di Lettura file perchè: "+ e +"\n"); 111 } 112 } 113 114 117 private void saveFile() { 118 119 BufferedWriter str_output; 120 Cve.errLog.debug(""); 121 try { 122 str_output=new BufferedWriter (new FileWriter(file_in)); 123 StringTokenizer token=new StringTokenizer(textArea.getText(),"\n"); 126 String line = new String (""); 127 128 while(token.hasMoreTokens()) { 129 line=token.nextToken(); 130 str_output.write(line+"\r\n"); 131 } 132 str_output.close(); 133 }catch (Exception e) { 134 Cve.errLog.error(e.toString()); 135 System.out.println("ATTENZIONE!Errore di Scrittura file perchè: "+ e +"\n"); 136 } 137 } 138 139 141 145 public void itemStateChanged(ItemEvent e) { 146 Cve.errLog.debug(""); 147 } 148 149 153 public void actionPerformed(ActionEvent e) { 154 Cve.errLog.debug(""); 155 if (e.getSource().equals(b_save)) { 157 158 if (oac != null){ 159 saveFile(); 160 } 161 dispose(); 162 } 163 if (e.getSource().equals(b_cancel)) { 165 dispose(); 166 } 167 } 168 169 173 public void stateChanged(ChangeEvent changeevent) { 174 Cve.errLog.debug(""); 175 } 176 177 } | Popular Tags |