1 package cve.osservatori; 2 3 import cve.staticLayout.*; 4 import cve.core.elementEEL.*; 5 6 import cve.esecutori.*; 7 import cve.esecutori.components.specificaLV.*; 8 import cve.esecutori.servizioEACesec.*; 9 10 import cve.osservatori.servizioOACesec.*; 11 12 import interactionHandler.*; 13 import interactionGraphics.*; 14 15 import cve.util.ConfigurationRead; 16 17 import java.io.File ; 18 import java.io.IOException ; 19 import java.io.*; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 25 import javax.swing.text.*; 27 import javax.swing.*; 28 import javax.swing.event.*; 29 30 import org.apache.log4j.Logger; 31 import cve.staticLayout.Cve; 32 33 import wippog.*; 34 35 52 public class OACesec extends Osservatore { 53 56 private ControllerOACesec med; 57 58 61 private HashMap buttonAlf=new HashMap(); 62 63 66 private IJTool tbar; 67 68 71 private IJCanvas canvas; 72 73 76 private IEsecutionSentence eseGS; 77 78 81 private String modality="Modality 1"; 82 83 86 private OACesec istOACesec=this; 87 88 private QueryFrame queryFrame; 89 private interactionHandler.MappingEventActivity mappingEventFrame; 90 91 92 94 95 101 public Action getLinguaggio = new AbstractAction("") { 102 public void actionPerformed(ActionEvent e) { 103 Cve.errLog.debug(""); 104 File current=new File (ConfigurationRead.getCveRoot()+"/VisualLanguage/SpecificheWippog"); 105 String fileAut=Osservatore.getFileXml(current); 106 107 if (fileAut.equals("")==false ){ 108 setLanguage(fileAut); 109 getLinguaggio.setEnabled(false); 110 cancLinguaggio.setEnabled(true); 111 cancSentenza.setEnabled(true); 112 repaint(); 113 repaintAll(); 114 } 115 } 116 }; 117 118 121 public Action cancLinguaggio = new AbstractAction("") { 122 public void actionPerformed(ActionEvent e) { 123 Cve.errLog.debug(""); 128 clearLanguage(); 129 cancLinguaggio.setEnabled(false); 130 cancSentenza.setEnabled(false); 131 getLinguaggio.setEnabled(true); 132 repaint(); 133 repaintAll(); 134 } 135 }; 136 137 140 public Action cancSentenza = new AbstractAction("") { 141 public void actionPerformed(ActionEvent e) { 142 Cve.errLog.debug(""); 145 clearSentence(); 146 cancLinguaggio.setEnabled(true); 147 getLinguaggio.setEnabled(false); 148 cancSentenza.setEnabled(false); 149 repaint(); 150 repaintAll(); 151 } 152 }; 153 154 157 public Action colorSelect = new AbstractAction("") { 158 public void actionPerformed(ActionEvent e) { 159 Cve.errLog.debug(""); 160 ViewLog.writeInLog(" #O# Eseguita attivita' (action) colorSelect"+"\n"); 161 canvas.setColorSelected(); 162 } 163 }; 164 165 168 public Action advancedFeature = new AbstractAction("") { 169 public void actionPerformed(ActionEvent e) { 170 canvas.advanced(); 171 } 172 }; 173 174 177 public Action cambiaLingua = new AbstractAction("") { 178 public void actionPerformed(ActionEvent e) { 179 Cve.errLog.debug(""); 180 } 182 }; 183 184 187 public Action colorDummy = new AbstractAction("") { 188 public void actionPerformed(ActionEvent e) { 189 Cve.errLog.debug(""); 190 ViewLog.writeInLog(" #O# Eseguita attivita' (action) colorDummy"+"\n"); 191 canvas.setColorDummy(); 192 } 193 }; 194 195 198 public Action changeEventAction = new AbstractAction("") { 199 public void actionPerformed(ActionEvent e) { 200 Cve.errLog.debug(""); 201 openMappingFrame(); 203 } 205 }; 206 207 208 211 public Action saveSentence = new AbstractAction("") { 212 public void actionPerformed(ActionEvent e) { 213 Cve.errLog.debug(""); 214 } 216 }; 217 218 221 public Action loadSentence = new AbstractAction("") { 222 public void actionPerformed(ActionEvent e) { 223 Cve.errLog.debug(""); 224 } 226 }; 227 228 229 231 232 235 public OACesec(){ 236 Cve.errLog.debug(""); 237 med = new ControllerOACesec(this); 238 setMediator(med); 239 240 setMappingFrameOpen(false); 242 setQueryElementOpen(false); 243 } 244 245 249 275 276 279 284 285 290 public void setComponents (Collection param){ 291 Cve.errLog.debug(""); 292 Iterator itParam=param.iterator(); 293 while (itParam.hasNext()){ 294 Object component=itParam.next(); 295 if (component instanceof IJCanvas){ 296 canvas=(IJCanvas)component; 297 } 298 if (component instanceof IJTool){ 299 tbar=(IJTool)component; 300 } 301 } 302 canvas.setController(med); 304 tbar.setController(med); 305 cveCont.setLayout(new BorderLayout()); 307 cveCont.add("Center",(Component)canvas); 308 cveCont.add("East",(Component)tbar); 309 impostaComandi(); 310 } 311 312 316 public Controller getMediator() { 317 Cve.errLog.debug(""); 318 return med; 319 } 320 321 326 public void setLanguage(String fileAut) { 327 Cve.errLog.debug(""); 328 eseGS=(IEsecutionSentence)getEsecutore(); 329 if (eseGS!=null){ 330 eseGS.setLanguage(fileAut); 331 } 332 } 333 334 337 private void clearLanguage() { 338 Cve.errLog.debug(""); 339 eseGS=(IEsecutionSentence)getEsecutore(); 340 eseGS.clearLanguage(); 342 } 343 344 347 private void clearSentence() { 348 Cve.errLog.debug(""); 349 eseGS=(IEsecutionSentence)getEsecutore(); 350 eseGS.clearSentence(); 352 } 353 354 364 public void inputSelected(String id,String idIstanza, boolean selected){ 365 Cve.errLog.debug(""); 366 eseGS=(IEsecutionSentence)getEsecutore(); 367 eseGS.inputSelected(id,idIstanza,selected); 368 369 } 371 372 381 public void query(String idTipo,String idIstanza){ 382 Cve.errLog.debug(""); 383 eseGS=(IEsecutionSentence)getEsecutore(); 384 eseGS.inputQuery(idTipo,idIstanza); 385 386 } 388 389 395 public void setStateButton(Collection disab, boolean enable){ 396 Cve.errLog.debug(""); 397 System.out.println(" #O setStateButton flag: " + enable + " elenco pulsanti: " + disab.toString()); 398 399 Vector allButton=new Vector (buttonAlf.values()); 401 407 Iterator disabIt=disab.iterator(); 409 while (disabIt.hasNext()){ 410 Object idButton=disabIt.next(); 412 String idButtonS=idButton.toString(); 414 System.out.println(" #O setStateButton: pulsante : " + idButton); 415 AlfButton refButton=(AlfButton)buttonAlf.get(idButtonS); 416 if (enable) 417 refButton.setEnabled(true); 418 else 419 refButton.setEnabled(false); 420 } 421 422 repaint(); 423 System.out.println(" #O setStateButton: dopo repaint"); 424 } 425 426 435 public void trigger(String idTipo){ 436 Cve.errLog.debug(""); 437 if (eseGS!=null) { 438 eseGS.inputTrigger(idTipo); 439 } 440 } 441 442 443 445 446 452 protected void react(Observable o, Object arg){ 453 Cve.errLog.debug(""); 454 if (arg instanceof SentenceEvent ){ 455 SentenceEvent sentEv=(SentenceEvent)arg; 456 String action=sentEv.getActionUser(); 457 458 ViewLog.writeInLog(" #O# Sono in react osservatore ("+action+")"+"\n"); 459 System.out.println(" #O# Sono in react osservatore ("+action+")"); 460 461 462 if (action.equals("clearSentence")){ 463 eseGS=(IEsecutionSentence)getEsecutore(); 464 canvas.clear(); 465 } 468 if (action.equals("clearLanguage")){ 469 eseGS=(IEsecutionSentence)getEsecutore(); 470 canvas.clear(); 471 removeElementTool(); 473 } 474 if (action.equals("trigger")){ 475 eseGS=(IEsecutionSentence)getEsecutore(); 476 Vector sentence=new Vector((Collection)eseGS.getSentence()); 477 System.out.println("dentro react trigger -->"+sentence.size()); 478 canvas.computeCoordinate(sentence); 480 } 481 if (action.equals("selected")){ 482 eseGS=(IEsecutionSentence)getEsecutore(); 483 String stateError=eseGS.getStateError(); 484 if (stateError.equals("")){ 485 Vector sentence=new Vector((Collection)eseGS.getSentence()); 486 canvas.setSentence(sentence); 488 }else{ 489 openStateError(stateError); 491 } 492 } 493 if (action.equals("query")){ 494 eseGS=(IEsecutionSentence)getEsecutore(); 495 IResource item=eseGS.getQueryItem(); 496 viewQuery(item); 498 499 500 } 501 if (action.equals("language")){ 502 eseGS=(IEsecutionSentence)getEsecutore(); 503 Map rap=eseGS.getRappresentations(); 504 Collection rappre=rap.values(); 505 setAlfabet(rappre); 506 tbar.repaint(); 507 } 508 if (action.equals("deselectButton")){ 509 eseGS=(IEsecutionSentence)getEsecutore(); 510 Collection buttonS=eseGS.getDisableButton(); 513 setStateButton(buttonS,false); 514 tbar.repaint(); 515 } 516 if (action.equals("selectButton")){ 517 eseGS=(IEsecutionSentence)getEsecutore(); 518 Collection buttonS=eseGS.getEnableButton(); 522 setStateButton(buttonS,true); 523 tbar.repaint(); 524 } 525 repaintAll(); 526 } 527 } 528 529 531 private void repaint(){ 532 Cve.errLog.debug(""); 533 canvas.repaint(); 534 } 535 536 539 private void openStateError(String state){ 540 Cve.errLog.debug(""); 541 JOptionPane.showMessageDialog(null,"Utente non abilitato allo stato: " + state,"ATTENZIONE",JOptionPane.WARNING_MESSAGE); 542 } 543 544 548 private void setButtonAlf(String pathIcon,String id,String tip){ 549 Cve.errLog.debug(""); 550 ImageIcon icon=new ImageIcon(pathIcon); 551 AlfButton but=new AlfButton (med,icon,id,tip); 552 buttonAlf.put(id,but); 554 tbar.addCve(but); 555 } 556 557 561 private void impostaComandi(){ 562 Cve.errLog.debug(""); 563 getLinguaggio.setEnabled(true); 564 cancLinguaggio.setEnabled(false); 565 cancSentenza.setEnabled(false); 566 cambiaLingua.setEnabled(false); 568 } 569 570 576 private void setAlfabet(Collection rappre) { 577 Cve.errLog.debug(""); 579 removeElementTool(); 580 if (rappre!=null){ 581 String path=ConfigurationRead.getCveRoot()+"/"; 582 Iterator itRappre=rappre.iterator(); 583 while (itRappre.hasNext()) { 584 Representation istRap=(Representation)itRappre.next(); 585 setButtonAlf(path+istRap.getAttribute("icon"),istRap.getAttribute("name"),istRap.getAttribute("name")); 586 } 587 } 588 repaintAll(); 589 } 590 591 private void removeElementTool(){ 592 Cve.errLog.debug(""); 593 tbar.removeAll(); 594 tbar.repaint(); 595 } 596 597 600 private void openMappingFrame(){ 601 Cve.errLog.debug(""); 602 if (getMappingFrameOpen()){ 603 try{ 604 mappingEventFrame.setSelected(true); 605 } catch (Exception e){ 606 Cve.errLog.error(e.toString()); 607 } 608 }else{ 609 610 mappingEventFrame = new interactionHandler.MappingEventActivity("Mapping Event-Activity","/resource/INTERACTION.GIF"); 612 613 mappingEventFrame.setOAC(this); 615 mappingEventFrame.init(); 616 617 JDesktopPane desktop; 619 desktop =Cve.getDesktop(); 620 desktop.add(mappingEventFrame); 621 622 try{ 623 mappingEventFrame.setSelected(true); 624 } catch (Exception e){ 625 Cve.errLog.error(e.toString()); 626 } 627 628 setMappingFrameOpen(true); 629 } 630 } 631 632 637 private void viewQuery(IResource item){ 638 639 Cve.errLog.debug(""); 640 if (getQueryElementOpen()){ 641 try{ 642 queryFrame.setSelected(true); 643 } catch (Exception e){ 644 Cve.errLog.error(e.toString()); 645 } 646 }else{ 647 queryFrame = new QueryFrame("Query Item","/resource/QueryView.GIF"); 649 setQueryElementOpen(true); 650 651 queryFrame.setOAC(this); 653 queryFrame.init(item); 654 655 JDesktopPane desktop; 657 desktop =Cve.getDesktop(); 658 desktop.add(queryFrame); 659 try{ 660 queryFrame.setSelected(true); 661 } catch (Exception e){ 662 Cve.errLog.error(e.toString()); 663 } 664 } 665 } 666 } | Popular Tags |