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;
|
|
36
|
|
37 public SimpleEditorForREPEditor(String title){
|
|
38 super(title);
|
|
39 setSize(new Dimension(640, 480));
|
|
40 setLayout(new BorderLayout());
|
|
41
|
|
42 setToolBar();
|
|
43 setEditor();
|
|
44 setConsole();
|
|
45 setSplitPane();
|
|
46 }
|
|
47
|
|
48 private void setToolBar() {
|
|
49 JToolBar toolbar = new JToolBar();
|
|
50 putButton = new JButton("put");
|
|
51 joinButton = new JButton("join");
|
|
52 putButton.addActionListener(this);
|
|
53 joinButton.addActionListener(this);
|
|
54
|
|
55 JLabel label1 = new JLabel("line");
|
|
56 JLabel label2 = new JLabel("text");
|
|
57 lineField = new JTextField();
|
|
58 textField = new JTextField();
|
|
59
|
|
60 deleteButton = new JButton("delete");
|
|
61 insertButton = new JButton("insert");
|
|
62
|
|
63 toolbar.add(putButton);
|
|
64 toolbar.add(joinButton);
|
|
65 toolbar.addSeparator();
|
|
66 toolbar.add(label1);
|
|
67 toolbar.add(lineField);
|
|
68 toolbar.add(label2);
|
|
69 toolbar.add(textField);
|
|
70 toolbar.addSeparator();
|
|
71 toolbar.add(deleteButton);
|
|
72 toolbar.add(insertButton);
|
|
73
|
|
74 add(toolbar, BorderLayout.NORTH);
|
|
75 }
|
|
76
|
|
77 private void setEditor(){
|
|
78 textArea = new JTextArea();
|
|
79 textArea.setEditable(false);
|
|
80 textArea.setFont(new Font("Monaco", Font.PLAIN, textArea.getFont().getSize()));
|
|
81
|
|
82 scrollPane1 = new JScrollPane(textArea);
|
|
83 }
|
|
84
|
|
85 private void setConsole(){
|
|
86 console = new JTextArea();
|
|
87 console.setFont(new Font("Monaco", Font.PLAIN, console.getFont().getSize()-2));
|
|
88 console.setEditable(false);
|
|
89 scrollPane2 = new JScrollPane(console);
|
|
90 }
|
|
91
|
|
92 private void setSplitPane(){
|
|
93 splitPane = new JSplitPane();
|
|
94 splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
|
95 splitPane.add(scrollPane1, JSplitPane.TOP);
|
|
96 splitPane.add(scrollPane2, JSplitPane.BOTTOM);
|
|
97 splitPane.setDividerLocation(300);
|
|
98 add(splitPane, BorderLayout.CENTER);
|
|
99 }
|
|
100
|
|
101 public void actionPerformed(ActionEvent e) {
|
|
102 if(e.getSource() == putButton){
|
|
103 repPut();
|
|
104 }else if(e.getSource() == joinButton){
|
|
105 repJoin();
|
|
106 }
|
|
107 }
|
|
108
|
|
109 private void repPut() {
|
|
110 REPEditor repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), true);
|
|
111 repEditor.start();
|
|
112 repEditor.setLogTarget(this);
|
|
113 putButton.setEnabled(false);
|
|
114 joinButton.setEnabled(false);
|
|
115 }
|
|
116
|
|
117 private void repJoin() {
|
|
118 REPEditor repEditor = new REPEditor(new REPTextWithJTextArea(textArea, lineField, textField, deleteButton, insertButton), false);
|
|
119 repEditor.start();
|
|
120 repEditor.setLogTarget(this);
|
|
121 putButton.setEnabled(false);
|
|
122 joinButton.setEnabled(false);
|
|
123 }
|
|
124
|
|
125 public void printLog(String msg) {
|
|
126 console.append(msg + BR);
|
|
127 }
|
418
|
128
|
|
129 public static void main(String[] args){
|
|
130 SimpleEditorForREPEditor editor = new SimpleEditorForREPEditor("Simple Editor");
|
|
131 editor.setVisible(true);
|
|
132 }
|
417
|
133
|
|
134 }
|