PageRenderTime 35ms CodeModel.GetById 15ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/src/org/ictclas4j/run/FrmMain.java

http://ictclas4j.googlecode.com/
Java | 289 lines | 217 code | 52 blank | 20 comment | 21 complexity | 2478815698e5cb28a12c873449ffe1a3 MD5 | raw file
  1package org.ictclas4j.run;
  2
  3import java.awt.BorderLayout;
  4import java.awt.GridLayout;
  5import java.io.BufferedReader;
  6import java.io.File;
  7import java.io.FileInputStream;
  8import java.io.IOException;
  9import java.io.InputStreamReader;
 10import java.util.ArrayList;
 11
 12import javax.swing.JButton;
 13import javax.swing.JFrame;
 14import javax.swing.JLabel;
 15import javax.swing.JPanel;
 16import javax.swing.JScrollPane;
 17import javax.swing.JTabbedPane;
 18import javax.swing.JTextArea;
 19
 20import org.ictclas4j.bean.SegResult;
 21
 22public class FrmMain {
 23
 24	private static FrmMain frmMain;
 25
 26	private JFrame jFrame = null;
 27
 28	private JPanel jContentPane = null;
 29
 30	private JTabbedPane jTabbedPane = null;
 31
 32	private JPanel jpSplit = null;
 33
 34	private JLabel jlSrcMsg = null;
 35
 36	private JLabel jlSplitMsg = null;
 37
 38	private JLabel jlSegPathCount = null;
 39
 40	private JTextArea jtSegPathCount = null;
 41
 42	private JTextArea jtSrcMsg = null;
 43
 44	private JTextArea jtSplitMsg = null;
 45	
 46	private JTextArea jtFor=null;
 47
 48	private JButton jbSplitOK = null;
 49
 50	private JButton jbTest = null;
 51
 52	private FrmMain() {
 53
 54	}
 55
 56	public static FrmMain getInstance() {
 57		if (frmMain == null)
 58			frmMain = new FrmMain();
 59
 60		return frmMain;
 61	}
 62
 63	private JPanel getJpSplit() {
 64		if (jpSplit == null) {
 65
 66			jpSplit = new JPanel();
 67			jpSplit.add(getJpSplit0(), BorderLayout.CENTER);
 68			jpSplit.add(getJbSplitOK(), BorderLayout.SOUTH);
 69			jpSplit.add(getJbTest(), BorderLayout.SOUTH);
 70
 71		}
 72		return jpSplit;
 73	}
 74
 75	private JPanel getJpSplit0() {
 76		JPanel jpSplit0 = new JPanel();
 77		jpSplit0.add(getJpSegPathCount(), null);
 78		jpSplit0.add(getJpSrcMsg(), null);
 79		jpSplit0.add(getJpSplitMsg(), null);
 80
 81		jpSplit0.setSize(400, 200);
 82		jpSplit0.setLayout(new GridLayout(3, 1));
 83
 84		return jpSplit0;
 85
 86	}
 87
 88	private JPanel getJpSplitMsg() {
 89		jlSplitMsg = new JLabel();
 90		jlSplitMsg.setText("?????");
 91	
 92
 93		JPanel jpSplitMsg = new JPanel();
 94		jpSplitMsg.add(jlSplitMsg);
 95		jpSplitMsg.add(getJtSplitMsg());
 96		JScrollPane jsp = new JScrollPane(jtSplitMsg);
 97		jpSplitMsg.add(jsp, jsp.getName());
 98		return jpSplitMsg;
 99	}
100
101	private JPanel getJpSegPathCount() {
102		jlSegPathCount = new JLabel();
103		jlSegPathCount.setText("?????");
104		JLabel jtf=new JLabel();
105		jtf.setText("?????????");
106
107		JPanel jpSegPath = new JPanel();
108		jpSegPath.add(jlSegPathCount);
109		jpSegPath.add(getJtSegPathCount());
110		
111		JPanel jpFor=new JPanel();
112		jpFor.add(jtf);
113		jpFor.add(getJtForCount());
114		 
115		JPanel jpanel=new JPanel();
116		jpanel.add(jpSegPath);
117		jpanel.add(jpFor);
118		return jpanel;
119	}
120
121	private JTextArea getJtSegPathCount() {
122		jtSegPathCount = new JTextArea(1, 4);
123		jtSegPathCount.setText("1");
124		return jtSegPathCount;
125	}
126	
127	private JTextArea getJtForCount() {
128		jtFor = new JTextArea(1, 4);
129		jtFor.setText("1000");
130		return jtFor;
131	}
132
133	private JTextArea getJtSrcMsg() {
134		jtSrcMsg = new JTextArea(6, 40);
135		jtSrcMsg.setText("??????????");
136		jtSrcMsg.setLineWrap(true);
137		return jtSrcMsg;
138	}
139
140	private JTextArea getJtSplitMsg() {
141		jtSplitMsg = new JTextArea(6, 40);
142		jtSplitMsg.setLineWrap(true);
143
144		return jtSplitMsg;
145	}
146
147	private JPanel getJpSrcMsg() {
148		jlSrcMsg = new JLabel();
149		jlSrcMsg.setText("?????");
150
151		JPanel jpSrcMsg = new JPanel();
152		jpSrcMsg.add(jlSrcMsg);
153		jpSrcMsg.add(getJtSrcMsg());
154		JScrollPane jsp = new JScrollPane(jtSrcMsg);
155		jpSrcMsg.add(jsp, jsp.getName());
156		return jpSrcMsg;
157	}
158
159	/**
160	 * This method initializes jbSendOK
161	 * 
162	 * @return javax.swing.JButton
163	 */
164	private JButton getJbSplitOK() {
165		if (jbSplitOK == null) {
166			jbSplitOK = new JButton();
167			jbSplitOK.setText("??");
168			jbSplitOK.addActionListener(new java.awt.event.ActionListener() {
169				public void actionPerformed(java.awt.event.ActionEvent e) {
170					int segPathCount = Integer.parseInt(jtSegPathCount.getText());
171					SegMain.seg.setSegPathCount(segPathCount);
172					SegResult sr = SegMain.seg.split(jtSrcMsg.getText());
173					jtSplitMsg.setText("[Time:" + sr.getSpendTime() + "ms]:\n" + sr.getFinalResult());
174				}
175			});
176		}
177		return jbSplitOK;
178	}
179
180	private JButton getJbTest() {
181		if (jbTest == null) {
182			jbTest = new JButton();
183			jbTest.setText("????");
184			jbTest.addActionListener(new java.awt.event.ActionListener() {
185				public void actionPerformed(java.awt.event.ActionEvent e) {
186					try {
187						int count=0;
188						long times=0;
189						long bytes=0;
190						int segPathCount = Integer.parseInt(jtSegPathCount.getText());
191						SegMain.seg.setSegPathCount(segPathCount);
192						int forCount=Integer.parseInt(jtFor.getText());
193						ArrayList<String> testCases = readTxtFile2("test\\case1.txt");
194						for (int i = 0; i < forCount; i++) {
195							for (String src : testCases) {
196								SegResult sr = SegMain.seg.split(src);
197								count++;
198								bytes+=src.getBytes().length;
199								times+=sr.getSpendTime();
200								jtSrcMsg.setText("total_count:"+count+"\ntotal_time:"+times+"\ntotal_bytes:"+bytes
201										+"\navg_time:"+(times/count)+"\navg_bytes:"+(bytes/times)+"b/ms");
202								jtSplitMsg.setText("[time:" + sr.getSpendTime() + "ms]:\n" + sr.getFinalResult());
203							}
204						}
205					} catch (IOException e1) {
206						e1.printStackTrace();
207					}
208				}
209			});
210		}
211		return jbTest;
212	}
213
214	public static ArrayList<String> readTxtFile2(String fileName) throws IOException {
215		ArrayList<String> result = null;
216		FileInputStream fin = null;
217		InputStreamReader in = null;
218		BufferedReader br = null;
219		File file = null;
220		String value = null;
221
222		if (fileName != null) {
223			file = new File(fileName);
224			if (file.exists()) {
225				result = new ArrayList<String>();
226				try {
227					fin = new FileInputStream(file);
228					in = new InputStreamReader(fin);
229					br = new BufferedReader(in);
230					while ((value = br.readLine()) != null) {
231						result.add(value);
232					}
233				} catch (IOException e) {
234					throw new IOException();
235				}
236			}
237		}
238		return result;
239	}
240
241	/**
242	 * This method initializes jFrame
243	 * 
244	 * @return javax.swing.JFrame
245	 */
246	public JFrame getJFrame() {
247		if (jFrame == null) {
248			jFrame = new JFrame();
249			jFrame.setSize(new java.awt.Dimension(624, 215));
250			jFrame.setTitle("ICTCLAS4J????");
251			jFrame.setContentPane(getJContentPane());
252			jFrame.addWindowListener(new java.awt.event.WindowAdapter() {
253				public void windowClosing(java.awt.event.WindowEvent e) {
254					System.exit(0);
255				}
256			});
257
258		}
259		return jFrame;
260	}
261
262	/**
263	 * This method initializes jContentPane
264	 * 
265	 * @return javax.swing.JPanel
266	 */
267	private JPanel getJContentPane() {
268		if (jContentPane == null) {
269			jContentPane = new JPanel();
270			jContentPane.setLayout(new BorderLayout());
271			jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
272		}
273		return jContentPane;
274	}
275
276	/**
277	 * This method initializes jTabbedPane
278	 * 
279	 * @return javax.swing.JTabbedPane
280	 */
281	private JTabbedPane getJTabbedPane() {
282		if (jTabbedPane == null) {
283			jTabbedPane = new JTabbedPane();
284			jTabbedPane.addTab("??", null, getJpSplit(), null);
285		}
286		return jTabbedPane;
287	}
288
289}