Blame view
circus/src/circusRefine/gui/PrintOptionsFrame.java
19.1 KB
8d0dc533f
![]() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
package circusRefine.gui; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.LinkedList; import java.util.Stack; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; import circusRefine.core.ExternalManager; import circusRefine.core.idt.IdtUtils; import circusRefine.core.util.Text; import circusRefine.util.CRefineException; import circusRefine.util.DocCommentsType; import circusRefine.util.docgenerator.DocGeneratorUtils; import circusRefine.util.docgenerator.DocGenerator; /** * Janela onde o usurario podera selecionar o que fara parte do arquivo de saida. * O arquivo podera conter : A Especificação Original, O Desenvolvimento, Comentarios e * as Obrigações de Prova * @author Alessandro * */ public class PrintOptionsFrame extends JDialog { /** * */ private static final long serialVersionUID = 1L; private boolean code; private boolean originalSpec; private boolean des; private DocCommentsType comment; private boolean proofOb; /* Campo que determina se a impressao das OPs serao feitas * de forma Expandida ou Resumida*/ private boolean formaExpandida; private boolean subdevelopments; private ButtonGroup comentarios = new ButtonGroup(); private ButtonGroup opsGroup = new ButtonGroup(); int aumento; JLabel apresentacao; private JCheckBox oriSpecBox; private JCheckBox desBox; private JCheckBox proofObBox; private JCheckBox expandedBox; private JCheckBox notExpandedBox; private JCheckBox commentBox; private JCheckBox commentBeforeBox; private JCheckBox commentAfterBox; private JCheckBox commentAtListBox; private JCheckBox codBox; private JCheckBox subdevelopmentsBox; private JButton ok; private JButton cancel; private ExternalManager gerInterface; public PrintOptionsFrame(ExternalManager gerExt) { super(gerExt.retornarTelaPrincipal()); /* valores Default*/ gerInterface = gerExt; originalSpec = true; code = true; des = true; proofOb = true; formaExpandida = false; subdevelopments = false; comment = DocCommentsType.EM_LISTA; jbInit(); } /** * Metodo que inicializa os componentes graficos * */ private void jbInit() { this.setTitle(this.retornarMensagem("COD0007")); this.setLocation((this.gerInterface.getTamanhoHorizontal()*(15))/100, (this.gerInterface.getTamanhoVertical()*20)/100); this.setSize(250,320); this.setLayout(null); this.setResizable(true); //CONFIGURANDO COMPONENTES apresentacao = new JLabel(this.retornarMensagem("COD0522")); apresentacao.setToolTipText(this.retornarMensagem("COD0523")); apresentacao.setLocation(10, 10); apresentacao.setSize(this.getWidth(), 20); oriSpecBox = new JCheckBox(this.retornarMensagem("COD0524"), true); oriSpecBox.setLocation(apresentacao.getX(), apresentacao.getY() + apresentacao.getHeight() + 10); oriSpecBox.setSize(this.getWidth(),20); oriSpecBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { oriSpecBox_ItemStateChanged(e); } }); desBox = new JCheckBox(this.retornarMensagem("COD0001"), true); desBox.setLocation(oriSpecBox.getX(), oriSpecBox.getY() + oriSpecBox.getHeight() + 10); desBox.setSize(this.getWidth(),20); desBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { desBox_ItemStateChanged(e); } }); proofObBox = new JCheckBox(this.retornarMensagem("COD0525"), true); proofObBox.setLocation(desBox.getX(), desBox.getY() + desBox.getHeight() + 10); proofObBox.setSize(this.getWidth(),20); proofObBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { proofObBox_ItemStateChanged(e); } }); notExpandedBox = new JCheckBox(this.retornarMensagem("COD0595"), true); notExpandedBox.setLocation(proofObBox.getX() + 20, proofObBox.getY() + proofObBox.getHeight() + 10); notExpandedBox.setSize(this.getWidth(),20); notExpandedBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { OPsOption_ItemStateChanged(e); } }); expandedBox = new JCheckBox(this.retornarMensagem("COD0596")); expandedBox.setLocation(notExpandedBox.getX(), notExpandedBox.getY() + notExpandedBox.getHeight()+ 10); expandedBox.setSize(this.getWidth(),20); expandedBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { OPsOption_ItemStateChanged(e); } }); codBox = new JCheckBox(this.retornarMensagem("COD0083"), true); codBox.setLocation(proofObBox.getX(), expandedBox.getY() + expandedBox.getHeight() + 10); codBox.setSize(this.getWidth(),20); codBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { codBox_ItemStateChanged(e); } }); subdevelopmentsBox = new JCheckBox(this.retornarMensagem("SubDevelopment"), true); subdevelopmentsBox.setLocation(codBox.getX(), codBox.getY() +codBox.getHeight() + 10); subdevelopmentsBox.setSize(this.getWidth(),20); subdevelopmentsBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { subDevelopmentBox_ItemStateChanged(e); } }); commentBox = new JCheckBox(this.retornarMensagem("COD0279"), true); commentBox.setLocation(proofObBox.getX(), codBox.getY() + codBox.getHeight() + 10); commentBox.setSize(this.getWidth(),20); commentBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { commentBox_ItemStateChanged(e); } }); ok = new JButton(this.gerInterface.getMessage("COD0072")); ok.setBackground(this.getBackground()); ok.setFont(new Font("Dialog", 1, 12)); ok.setLocation(commentBox.getX() + 65, commentBox.getY() + commentBox.getHeight() + 10); ok.setSize(70,20); ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { try { ok_actionPerformed(e); } catch (CRefineException e1) { ErrorDialog errorDialog = new ErrorDialog(gerInterface, "" , e1); errorDialog.setVisible(true); } } }); cancel = new JButton("Cancel"); cancel.setLocation(ok.getX() + ok.getWidth() + 10, ok.getY()); cancel.setSize(80, 20); cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { cancel_actionPerformed(e); } }); //ADICIONANDO COMPONENTES add(apresentacao); add(oriSpecBox); add(desBox); add(proofObBox); add(codBox); add(commentBox); add(ok); add(cancel); if (this.gerInterface.getNumberOfDev() > 0) { if (this.gerInterface.hasChild()) { subdevelopments = true; add(subdevelopmentsBox); commentBox.setLocation(commentBox.getX(), commentBox.getY() + subdevelopmentsBox.getHeight() + 10); ok.setLocation(ok.getX(), ok.getY() + ok.getHeight() + 10); cancel.setLocation(cancel.getX(), cancel.getY() + cancel.getHeight() + 10); this.setSize(this.getWidth(), this.getHeight() + subdevelopmentsBox.getHeight() + 10); } } commentAtListBox = new JCheckBox(this.retornarMensagem("COD0526"), true); commentAtListBox.setLocation(commentBox.getX() + 20, commentBox.getY() + commentBox.getHeight() + 10); commentAtListBox.setSize(this.getWidth(),20); commentAtListBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { commentOptionsBox_ItemStateChanged(e); } }); //Opção default de comentario commentBeforeBox = new JCheckBox(this.retornarMensagem("COD0527")); commentBeforeBox.setLocation(commentAtListBox.getX(), commentAtListBox.getY() + commentAtListBox.getHeight()+ 10); commentBeforeBox.setSize(this.getWidth(),20); commentBeforeBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { commentOptionsBox_ItemStateChanged(e); } }); commentAfterBox = new JCheckBox(this.retornarMensagem("COD0528")); commentAfterBox.setLocation(commentBeforeBox.getX(), commentBeforeBox.getY() + commentBeforeBox.getHeight() + 10);; commentAfterBox.setSize(this.getWidth(),20); commentAfterBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { commentOptionsBox_ItemStateChanged(e); } }); aumento = commentAtListBox.getHeight() + commentBeforeBox.getHeight() + commentAfterBox.getHeight() + 40; this.setSize(this.getWidth(), this.getHeight() + aumento ); ok.setLocation(ok.getX(), ok.getY() + aumento); cancel.setLocation(cancel.getX(), cancel.getY() + aumento); add(commentAtListBox); add(commentBeforeBox); add(commentAfterBox); add(expandedBox); add(notExpandedBox); comentarios.add(commentAtListBox); comentarios.add(commentBeforeBox); comentarios.add(commentAfterBox); opsGroup.add(expandedBox); opsGroup.add(notExpandedBox); this.repaint(); } protected void subDevelopmentBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { subdevelopments = true; } else { subdevelopments = false; } } /** * Metodo que realiza a selecao de como sera feita a impressao das * Obrigacoes de Prova, podendo estar tanto na forma Resumida, quanto * na forma Expandida. * @param e */ protected void OPsOption_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getSource() == expandedBox) { formaExpandida = true; } else if (e.getSource() == notExpandedBox) { formaExpandida = false; } } } protected void codBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { code = true; } else { code = false; } } protected void proofObBox_ItemStateChanged(ItemEvent e) { int aumentoJanela = notExpandedBox.getHeight() + expandedBox.getHeight() + 20; if (e.getStateChange() == ItemEvent.SELECTED) { proofOb = true; this.setSize(this.getWidth(), this.getHeight() + aumentoJanela); codBox.setLocation(codBox.getX(), codBox.getY() + aumentoJanela); commentBox.setLocation(commentBox.getX(), commentBox.getY() + aumentoJanela); commentAtListBox.setLocation(commentAtListBox.getX(), commentAtListBox.getY() + aumentoJanela); commentBeforeBox.setLocation(commentBeforeBox.getX(), commentBeforeBox.getY() + aumentoJanela); commentAfterBox.setLocation(commentAfterBox.getX(), commentAfterBox.getY() + aumentoJanela); ok.setLocation(ok.getX(), ok.getY() + aumentoJanela); cancel.setLocation(cancel.getX(), cancel.getY() + aumentoJanela); this.add(notExpandedBox); this.add(expandedBox); } else { proofOb = false; this.setSize(this.getWidth(), this.getHeight() - aumentoJanela); codBox.setLocation(codBox.getX(), codBox.getY() - aumentoJanela); commentBox.setLocation(commentBox.getX(), commentBox.getY() - aumentoJanela); commentAtListBox.setLocation(commentAtListBox.getX(), commentAtListBox.getY() - aumentoJanela); commentBeforeBox.setLocation(commentBeforeBox.getX(), commentBeforeBox.getY() - aumentoJanela); commentAfterBox.setLocation(commentAfterBox.getX(), commentAfterBox.getY() - aumentoJanela); ok.setLocation(ok.getX(), ok.getY() - aumentoJanela); cancel.setLocation(cancel.getX(), cancel.getY() - aumentoJanela); this.remove(notExpandedBox); this.remove(expandedBox); } } protected void desBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { des = true; } else { des = false; } } protected void oriSpecBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { originalSpec = true; } else { originalSpec = false; } } /** * Metodo que abri a opção de imprimir onde os comentarios * deverao ser inseridos no arquivo de saida .tex * @param e */ protected void commentBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { aumento = commentAtListBox.getHeight() + commentBeforeBox.getHeight() + commentAfterBox.getHeight() + 40; this.setSize(this.getWidth(), this.getHeight() + aumento ); ok.setLocation(ok.getX(), ok.getY() + aumento); cancel.setLocation(cancel.getX(), cancel.getY() + aumento); add(commentAtListBox); add(commentBeforeBox); add(commentAfterBox); this.repaint(); comentarios.add(commentAtListBox); comentarios.add(commentBeforeBox); comentarios.add(commentAfterBox); } else { comment = DocCommentsType.NENHUM; OriginalFrame(); } } protected void commentOptionsBox_ItemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getSource() == commentAtListBox) { comment = DocCommentsType.EM_LISTA; } else if (e.getSource() == commentBeforeBox) { comment = DocCommentsType.ANTES_DE_LINHA; } //CommentAfter else { comment = DocCommentsType.DEPOIS_DE_LINHA; } } } /** * Metodo utilizado para deselecionar as opções de comentarios; * */ private void OriginalFrame() { this.remove(commentAtListBox); this.remove(commentAfterBox); this.remove(commentBeforeBox); this.setSize(this.getWidth(), this.getHeight() - aumento ); ok.setLocation(ok.getX(), ok.getY() - aumento); cancel.setLocation(cancel.getX(), cancel.getY() - aumento); comment = DocCommentsType.NENHUM; this.repaint(); } /** * Cancela a impressao. Nada � gerado. * @param e */ protected void cancel_actionPerformed(ActionEvent e) { this.setVisible(false); } /** * Metodo que gera o arquivo de saida .tex. Para isso, * verifica os itens selecionados. */ protected void ok_actionPerformed(ActionEvent e) throws CRefineException { StringBuffer strText = new StringBuffer(); int redosize = this.gerInterface.getSizeOfRedoHistorico(); try { DocGeneratorUtils doc = new DocGeneratorUtils(strText, redosize, gerInterface, originalSpec, des, proofOb, comment, code, formaExpandida); strText = doc.getTextFromProgram(); } catch (Exception e2) { e2.printStackTrace(); throw new GenerateDocException(e2.getMessage(),e2); } /* * Salvando Arquivo */ criandoArquivo(strText.toString()); if (subdevelopments) { for( Integer i : this.gerInterface.getFilhos()) { this.gerInterface.selecionarDesenvolvimento(i); StringBuffer strText2 = new StringBuffer(); int redosize2 = this.gerInterface.getSizeOfRedoHistorico(); try { DocGeneratorUtils doc = new DocGeneratorUtils(strText2, redosize2, gerInterface, originalSpec, des, proofOb, comment, code, formaExpandida); strText2 = doc.getTextFromProgram(); } catch (Exception e2) { e2.printStackTrace(); throw new GenerateDocException(e2.getMessage(),e2); } /* * Salvando Arquivo */ criandoArquivo(strText2.toString()); } } setVisible(false); } /** * Método utilizado para criar o arquivo .tex * @param str O texto do arquivo.tex * @throws GenerateDocException */ private void criandoArquivo(String str) throws GenerateDocException { try { JFileChooser fileChooser = new JFileChooser(); File currentDir = new File("."); fileChooser = new JFileChooser(currentDir); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); fileChooser.setDialogTitle(this.gerInterface.getMessage("COD0542")); fileChooser.showSaveDialog(this); File file = fileChooser.getSelectedFile(); if (file != null) { String fileName = file.getPath(); CopiandoStyles(file.getParent()); File output; if (fileName.endsWith(".tex")) { output = new File(fileName); } else{ output = new File(fileName + ".tex"); } FileOutputStream out = new FileOutputStream(output); byte [] data = str.getBytes(); try { out.write(data); out.close(); JOptionPane.showMessageDialog(null , this.retornarMensagem("COD0622"), "DocGenerator", JOptionPane.INFORMATION_MESSAGE); } catch (IOException except) { CRefineException e = new CRefineException(except, except.getMessage()); e.setTitleCode("COD0609"); throw e; } } } catch(Exception exception) { throw new GenerateDocException(exception.getMessage(),exception); } } /** * Metodo que copia os arquivos .sty necessarios para o * arquivo .tex . * @param parentFile pasta em que devera ser inserido */ private void CopiandoStyles(String parentFile) { try { String path; String zstyString; String circusstyString; String cspstyString; String cztstyString; String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) { path = "novoSty\\"; //path = "sty\\"; zstyString = "\\zed.sty"; circusstyString = "\\circus.sty"; cztstyString = "\\czt.sty"; cspstyString = "\\csp.sty"; } else{ //path = "sty/"; path = "novoSty/"; zstyString = "/zed.sty"; circusstyString = "/circus.sty"; cztstyString = "/czt.sty"; cspstyString = "/csp.sty"; } FileInputStream zedSty = new FileInputStream(path + "zed.sty"); FileInputStream circusSty = new FileInputStream(path + "circus.sty"); FileInputStream cztSty = new FileInputStream(path + "czt.sty"); FileInputStream cspSty = new FileInputStream(path + "csp.sty"); File saidaZed = new File(parentFile + zstyString); FileOutputStream toZed = new FileOutputStream(saidaZed); File saidaCircus = new File(parentFile + circusstyString); FileOutputStream toCircus = new FileOutputStream(saidaCircus); File saidaCzt = new File(parentFile + cztstyString); FileOutputStream toCzt= new FileOutputStream(saidaCzt); File saidaCsp = new File(parentFile + cspstyString); FileOutputStream toCsp = new FileOutputStream(saidaCsp); int readBytes; try { while ((readBytes = zedSty.read())!= -1) { toZed.write(readBytes); } readBytes = 0; while ((readBytes = circusSty.read())!= -1) { toCircus.write(readBytes); } readBytes = 0; while ((readBytes = cztSty.read())!= -1) { toCzt.write(readBytes); } readBytes = 0; while ((readBytes = cspSty.read())!= -1) { toCsp.write(readBytes); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } } /** * Metodo de intercionalizacao, utilizando os idiomas portugues e ingles * @param string * @return */ private String retornarMensagem(String string) { return gerInterface.getMessage(string); } } |