1 package com.zanthan.sequence; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 7 import java.io.*; 8 9 13 public class SequenceFrame extends JFrame { 14 15 private JTabbedPane tabbedPane = new JTabbedPane(); 16 17 20 public SequenceFrame() { 21 super("dynaop SEQUENCE"); 22 23 Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); 25 int width = size.width / 2; 26 int height = size.height / 2; 27 pack(); 28 setSize(new Dimension(width, height)); 29 30 setLocation( 32 (size.width - width) / 2, 33 (size.height - height) / 2 34 ); 35 36 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 38 addWindowListener(new WindowAdapter() { 39 public void windowClosed(WindowEvent e) { 40 System.exit(0); 41 } 42 }); 43 44 getContentPane().add(this.tabbedPane); 46 47 setVisible(true); 49 } 50 51 54 public void update(String s) { 55 57 Diagram diagram = (Diagram) localDiagram.get(); 58 diagram.out.write(s); 59 String code = diagram.out.toString(); 60 diagram.display.init(code); 61 diagram.model.setText(code, this); 62 } 63 64 67 private ThreadLocal localDiagram = new ThreadLocal () { 68 69 70 protected Object initialValue() { 71 final Diagram diagram = new Diagram(); 73 74 JPanel panel = new JPanel(); 75 panel.setLayout(new BorderLayout()); 76 77 JToolBar toolBar = new JToolBar(); 78 toolBar.setFloatable(false); 79 toolBar.add(new JButton(new SaveAsAction(diagram.model))); 80 toolBar.add(new JButton(new ExportAction(diagram.display))); 81 82 panel.add(toolBar, BorderLayout.NORTH); 83 panel.add(new JScrollPane(diagram.display, 84 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 85 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), 86 BorderLayout.CENTER 87 ); 88 89 SequenceFrame.this.tabbedPane.addTab( 90 Thread.currentThread().getName(), 91 panel 92 ); 93 94 return diagram; 95 } 96 }; 97 98 101 private class Diagram { 102 Display display = new Display(null); 103 Model model = new Model(); 104 StringWriter out = new StringWriter(); 105 } 106 107 } 108 | Popular Tags |