417
|
1 package test.editortest;
|
|
2
|
|
3 import java.awt.BorderLayout;
|
|
4 import java.awt.Dimension;
|
|
5 import java.awt.Font;
|
|
6 import java.awt.event.ActionEvent;
|
|
7 import java.awt.event.ActionListener;
|
|
8
|
|
9 import javax.swing.JButton;
|
|
10 import javax.swing.JFrame;
|
|
11 import javax.swing.JLabel;
|
|
12 import javax.swing.JScrollPane;
|
|
13 import javax.swing.JSplitPane;
|
|
14 import javax.swing.JTextArea;
|
|
15 import javax.swing.JTextField;
|
|
16 import javax.swing.JToolBar;
|
|
17
|
|
18 public class SimpleEditorForREPEditor extends JFrame implements ActionListener, LogTarget{
|
|
19
|
|
20 /**
|
|
21 *
|
|
22 */
|
|
23 private static final long serialVersionUID = 1L;
|
|
24 private JButton putButton;
|
|
25 private JButton joinButton;
|
|
26 private JTextField lineField;
|
|
27 private JTextField textField;
|
|
28 private JTextArea textArea;
|
|
29 private JScrollPane scrollPane1;
|
|
30 private JTextArea console;
|
|
31 private JScrollPane scrollPane2;
|
|
32 private JSplitPane splitPane;
|
|
33 private String BR = System.getProperty("line.separator");
|
|
34 private JButton deleteButton;
|
|
35 private JButton insertButton;
|
419
|
36 private REPEditor repEditor;
|
417
|
37
|
|
38 public SimpleEditorForREPEditor(String title){
|
|
39 super(title);
|
|
40 setSize(new Dimension(640, 480));
|
|
41 setLayout(new BorderLayout());
|
|
42
|
|
43 setToolBar();
|
|
44 setEditor();
|
|
45 setConsole();
|
|
46 setSplitPane();
|
|
47 }
|
|
48
|
|
49 private void setToolBar() {
|
|
50 JToolBar toolbar = new JToolBar();
|
|
51 putButton = new JButton("put");
|
|
52 joinButton = new JButton("join");
|
|
53 putButton.addActionListener(this);
|
|
54 joinButton.addActionListener(this);
|
|
55
|
|
56 JLabel label1 = new JLabel("line");
|
|
57 JLabel label2 = new JLabel("text");
|
|
58 lineField = new JTextField();
|
|
59 textField = new JTextField();
|
|
60
|
|
61 deleteButton = new JButton("delete");
|
|
62 insertButton = new JButton("insert");
|
|
63
|
|
64 toolbar.add(putButton);
|
|
65 toolbar.add(joinButton);
|
|
66 toolbar.addSeparator();
|
|
67 toolbar.add(label1);
|
|
68 toolbar.add(lineField);
|
|
69 toolbar.add(label2);
|
|
70 toolbar.add(textField);
|
|
71 toolbar.addSeparator();
|
|
72 toolbar.add(deleteButton);
|
|
73 toolbar.add(insertButton);
|
|
74
|
|
75 add(toolbar, BorderLayout.NORTH);
|
|
76 }
|
|
77
|
|
78 private void setEditor(){
|
|
79 textArea = new JTextArea();
|
|
80 textArea.setEditable(false);
|
|
81 textArea.setFont(new Font("Monaco", Font.PLAIN, textArea.getFont().getSize()));
|
|
82
|
|
83 scrollPane1 = new JScrollPane(textArea);
|
|
84 }
|
|
85
|
|
86 private void setConsole(){
|
|
87 console = new JTextArea();
|
|
88 console.setFont(new Font("Monaco", Font.PLAIN, console.getFont().getSize()-2));
|
|
89 console.setEditable(false);
|
|
90 scrollPane2 = new JScrollPane(console);
|
|
91 }
|
|
92
|
|
93 private void setSplitPane(){
|
|
94 splitPane = new JSplitPane();
|
|
95 splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
|
96 splitPane.add(scrollPane1, JSplitPane.TOP);
|
|
97 splitPane.add(scrollPane2, JSplitPane.BOTTOM);
|
|
98 splitPane.setDividerLocation(300);
|
|
99 add(splitPane, BorderLayout.CENTER);
|
|
100 }
|
|
101
|
|
102 public void actionPerformed(ActionEvent e) {
|
|
103 if(e.getSource() == putButton){
|
|
104 repPut();
|
|
105 }else if(e.getSource() == joinButton){
|
|
106 repJoin();
|
|
107 }
|
|
108 }
|
|
109
|
419
|
110 public void repPut() {
|
|
111 repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), true);
|
417
|
112 repEditor.start();
|
|
113 repEditor.setLogTarget(this);
|
|
114 putButton.setEnabled(false);
|
|
115 joinButton.setEnabled(false);
|
|
116 }
|
|
117
|
419
|
118 public void repJoin() {
|
|
119 repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), false);
|
417
|
120 repEditor.start();
|
|
121 repEditor.setLogTarget(this);
|
|
122 putButton.setEnabled(false);
|
|
123 joinButton.setEnabled(false);
|
|
124 }
|
|
125
|
|
126 public void printLog(String msg) {
|
|
127 console.append(msg + BR);
|
|
128 }
|
418
|
129
|
|
130 public static void main(String[] args){
|
|
131 SimpleEditorForREPEditor editor = new SimpleEditorForREPEditor("Simple Editor");
|
|
132 editor.setVisible(true);
|
|
133 }
|
417
|
134
|
419
|
135 public REPEditor getREPEditor() {
|
|
136 return repEditor;
|
|
137 }
|
|
138
|
417
|
139 }
|