WordDetailScreen update

public class WordDetailScreen extends BaseScreen implements WindowListener, ActionListener {
	private static final long serialVersionUID = 1L;
	private WordDetailScreen thisFrame;

	// Component declare
	private JLabel lbl_WordId;
	private JLabel lbl_WordEn;
	private JLabel lbl_WordCn;
	private JLabel lbl_Symbol;
	private JLabel lbl_WordFrom;
	private JLabel lbl_Relevance;
	private JLabel lbl_Priority;
	private JLabel lbl_TestTimes;
	private JLabel lbl_CreateDate;
	private JLabel lbl_LastTestDate;
	private JLabel lbl_ErrorTest;
	private JLabel lbl_Attributes;
	private JLabel lbl_Remark;
	// XXX change name
	private JLabel lbl_Forgettag;
	private JLabel lbl_Errortimes;
	private JLabel lbl_isChange;

	private JTextField txt_WordId;
	private JTextField txt_WordEn;
	private JTextField txt_Symbol;
	private JTextField txt_WordFrom;
	private JTextField txt_Relevance;
	private JTextField txt_Priority;
	private JTextField txt_TestTimes;
	private JTextField txt_CreateDate;
	private JTextField txt_LastTestDate;
	private JTextField txt_Attributes;
	private JTextField txt_ErrorTest;
	private JTextArea txt_Remark;

	// XXX change name
	private JTextField txt_Forgettag;
	private JTextField txt_Errortimes;
	private JTextField txt_Changetag;

	private JButton btn_save;
	private JButton btn_cancel;
	// XXX change name
	private JButton btn_previou;
	private JButton btn_next;
	private JButton btn_cnUp;
	private JButton btn_cnDown;
	private JButton btn_cnAdd;
	private JButton btn_cnSub;
	private JButton btn_del;
	private JButton btn_addNext;
	
	private List<Word> dataList;
	private int currIndex;
	private Word currWord = new Word();
	private Word editWord = new Word();
	
	private boolean addModel = false;
	private int currSelectRowIndex = 0;
	
	private WordDetailScreenService service = new WordDetailScreenService();
	private Vector<Vector<Object>> wordCNDatas;
	private JTable wordCNTable;
	private DefaultTableModel wordCNModel;

	private Vector<Object> columnVector = new Vector<Object>();
	
	public WordDetailScreen(JFrame parenFrame, List<Word> dataList, Integer currIndex) {
		super(parenFrame);
		this.dataList = dataList;
		this.currIndex = currIndex;
		initialJFrame();
		parenFrame.setVisible(false);
	}

	private void initialJFrame() {
		thisFrame = this;
		thisFrame.setSize(new Dimension(535, 470));
		thisFrame.setTitle("Word Detail Screen");
		initialData();
		initialBody();
		updateUI();
	}

	private void updateUI() {
		if(dataList.size()>0){
			currWord = dataList.get(currIndex);
		}
		if(addModel==true){
			addModel = false;
		}else{
			txt_WordEn.setText(currWord.getFldWorden());
			txt_WordId.setText(currWord.getFldWordid() + "");
			txt_Priority.setText(currWord.getFldPriority() + "");
			txt_Symbol.setText(currWord.getFldSymbol());
			txt_TestTimes.setText(currWord.getFldTesttimes() + "");
			txt_WordFrom.setText(currWord.getFldFrom());
			txt_CreateDate.setText(currWord.getFldCreatdate());
			txt_Relevance.setText(currWord.getFldRelevance());
			txt_ErrorTest.setText(currWord.getFldErrorfag());
			txt_LastTestDate.setText(currWord.getFldLasttestdate());
			txt_Attributes.setText(service.getTureAttribs(currWord.getFldAttr()));
			txt_Forgettag.setText(currWord.getFldForgettag());
			txt_Changetag.setText(currWord.getFldForgettag());
			txt_Errortimes.setText(currWord.getFldErrortimes()+"");
			wordCNDatas = service.wordCNtoTableData(currWord.getFldWordcn());
			wordCNModel.setDataVector(wordCNDatas,columnVector );
			wordCNTable.updateUI();
		}
	}

	private void initialData() {
		if (dataList == null || dataList.size() == 0) {
			addModel = true;
			dataList = new ArrayList<Word>();
			currWord = new Word();
		} else {
			addModel = false;
			currWord = dataList.get(currIndex);
		}
		columnVector.add("");
	}

	private void initialBody() {
		ComponentFactory compFactory = new ComponentFactory();
		int left_label_width = 80;
		int left_txt_width = 160;
		int right_label_width = 75;
		int right_txt_width = 160;
		int line_heigh = 5;
		// line 1
		lbl_WordEn = new JLabel("Word EN *");
		// lbl_WordEn.setBorder(new LineBorder(Color.black));
		ComponentUtil.setBounds(left_label_width, 20, thisFrame, lbl_WordEn, ComponentUtil.INNER_LEFT_TOP, 15);
		thisFrame.add(lbl_WordEn);

		txt_WordEn = compFactory.getJTextField();
		ComponentUtil.setBounds(420, 20, lbl_WordEn, txt_WordEn, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_WordEn);

		// line2
		lbl_WordId = new JLabel("Word ID");

		ComponentUtil.setBounds(left_label_width, 20, lbl_WordEn, lbl_WordId, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_WordId);

		txt_WordId = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_WordId, txt_WordId, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_WordId);

		lbl_Priority = new JLabel("Priority");
		ComponentUtil.setBounds(right_label_width, 20, txt_WordId, lbl_Priority, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_Priority);

		txt_Priority = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_Priority, txt_Priority, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Priority);

		// line3
		lbl_Symbol = new JLabel("Symbol");
		ComponentUtil.setBounds(left_label_width, 20, lbl_WordId, lbl_Symbol, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_Symbol);

		txt_Symbol = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_Symbol, txt_Symbol, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Symbol);

		lbl_TestTimes = new JLabel("Test Times");
		ComponentUtil.setBounds(right_label_width, 20, txt_Symbol, lbl_TestTimes, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_TestTimes);

		txt_TestTimes = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_TestTimes, txt_TestTimes, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_TestTimes);

		// line4
		lbl_WordFrom = new JLabel("Word From");
		ComponentUtil.setBounds(left_label_width, 20, lbl_Symbol, lbl_WordFrom, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_WordFrom);

		txt_WordFrom = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_WordFrom, txt_WordFrom, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_WordFrom);

		lbl_CreateDate = new JLabel("Create Date");
		ComponentUtil.setBounds(right_label_width, 20, txt_WordFrom, lbl_CreateDate, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_CreateDate);

		txt_CreateDate = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_CreateDate, txt_CreateDate, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_CreateDate);

		// line5
		lbl_Relevance = new JLabel("Relevance");
		ComponentUtil.setBounds(left_label_width, 20, lbl_WordFrom, lbl_Relevance, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_Relevance);

		txt_Relevance = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_Relevance, txt_Relevance, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Relevance);

		lbl_ErrorTest = new JLabel("Error Test");
		ComponentUtil.setBounds(right_label_width, 20, txt_Relevance, lbl_ErrorTest, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_ErrorTest);

		txt_ErrorTest = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_ErrorTest, txt_ErrorTest, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_ErrorTest);

		// line6
		// lbl_LastTestDate
		lbl_LastTestDate = new JLabel("L-T Date");
		ComponentUtil.setBounds(left_label_width, 20, lbl_Relevance, lbl_LastTestDate, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_LastTestDate);

		txt_LastTestDate = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_LastTestDate, txt_LastTestDate, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_LastTestDate);

		lbl_Attributes = new JLabel("Attributes");
		ComponentUtil.setBounds(right_label_width, 20, txt_LastTestDate, lbl_Attributes, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_Attributes);

		txt_Attributes = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_Attributes, txt_Attributes, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Attributes);

		// line7
		lbl_Forgettag = new JLabel("Forget tag");
		ComponentUtil.setBounds(left_label_width, 20, lbl_LastTestDate, lbl_Forgettag, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_Forgettag);

		txt_Forgettag = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_Forgettag, txt_Forgettag, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Forgettag);

		lbl_Errortimes = new JLabel("Error times");
		ComponentUtil.setBounds(right_label_width, 20, txt_Forgettag, lbl_Errortimes, ComponentUtil.RIGHT_CENTER, 25);
		thisFrame.add(lbl_Errortimes);

		txt_Errortimes = compFactory.getJTextField();
		ComponentUtil.setBounds(right_txt_width, 20, lbl_Errortimes, txt_Errortimes, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Errortimes);

		// line8
		lbl_isChange = new JLabel("Is change");
		ComponentUtil.setBounds(left_label_width, 20, lbl_Forgettag, lbl_isChange, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_isChange);

		txt_Changetag = compFactory.getJTextField();
		ComponentUtil.setBounds(left_txt_width, 20, lbl_isChange, txt_Changetag, ComponentUtil.RIGHT_CENTER);
		thisFrame.add(txt_Changetag);

		// line9
		lbl_WordCn = new JLabel("Word CN *");
		ComponentUtil.setBounds(left_label_width, 20, lbl_isChange, lbl_WordCn, ComponentUtil.BOTTOM_LEFT, line_heigh);
		thisFrame.add(lbl_WordCn);

		Vector<Object> column = new Vector<Object>();
		column.add("");

		wordCNDatas = service.wordCNtoTableData("");
		wordCNModel = new DefaultTableModel(wordCNDatas, column);
		wordCNTable = new JTable(wordCNModel);
		wordCNTable.setShowGrid(false);
		wordCNTable.addFocusListener(new FocusAdapter() {
			@SuppressWarnings("unchecked")
			public void focusLost(FocusEvent arg0) {
				wordCNDatas = wordCNModel.getDataVector();
			}
		});

		wordCNTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		wordCNTable.setRowHeight(20);
		JScrollPane scroll = compFactory.getScrollableJTextArea(wordCNTable, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		scroll.getViewport().setBackground(Color.white);
		ComponentUtil.setBounds(420, 120, lbl_WordCn, scroll, ComponentUtil.RIGHT_TOP);
		thisFrame.add(scroll);

		btn_cnSub = new JButton("x");
		btn_cnSub.setMargin(new Insets(-5, -5, -5, -5));
		ComponentUtil.setBounds(17, 17, scroll, btn_cnSub, ComponentUtil.LEFT_BOTTOM, 5);
		btn_cnSub.addActionListener(this);
		thisFrame.add(btn_cnSub);

		btn_cnAdd = new JButton("+");
		btn_cnAdd.setMargin(new Insets(-5, -5, -5, -5));
		ComponentUtil.setBounds(17, 17, btn_cnSub, btn_cnAdd, ComponentUtil.TOP_CENTER, 5);
		btn_cnAdd.addActionListener(this);
		thisFrame.add(btn_cnAdd);

		btn_cnDown = new JButton("↓");
		btn_cnDown.setMargin(new Insets(-5, -5, -5, -5));
		ComponentUtil.setBounds(17, 17, btn_cnAdd, btn_cnDown, ComponentUtil.TOP_CENTER, 5);
		btn_cnDown.addActionListener(this);
		thisFrame.add(btn_cnDown);

		btn_cnUp = new JButton("↑");
		btn_cnUp.setMargin(new Insets(-5, -5, -5, -5));
		btn_cnUp.setVerticalAlignment(SwingConstants.CENTER);
		ComponentUtil.setBounds(17, 17, btn_cnDown, btn_cnUp, ComponentUtil.TOP_CENTER, 5);
		btn_cnUp.addActionListener(this);
		thisFrame.add(btn_cnUp);
		
		// line10
		lbl_Remark = new JLabel("Remark");
		ComponentUtil.setBounds(left_label_width, 20, lbl_WordCn, lbl_Remark, ComponentUtil.BOTTOM_LEFT, 105);
		thisFrame.add(lbl_Remark);

		txt_Remark = new JTextArea();
		JScrollPane scroll2 = compFactory.getScrollableJTextArea(txt_Remark, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		ComponentUtil.setBounds(420, 60, lbl_Remark, scroll2, ComponentUtil.RIGHT_TOP);
		txt_Remark.setText(currWord.getFldRemark());
		thisFrame.add(scroll2);

		// line 11
		btn_cancel = new JButton("Cancel");
		ComponentUtil.setBounds(80, 25, scroll2, btn_cancel, ComponentUtil.BOTTOM_RIGHT, 8);
		btn_cancel.addActionListener(this);
		thisFrame.add(btn_cancel);

		btn_save = new JButton("Save");
		ComponentUtil.setBounds(80, 25, btn_cancel, btn_save, ComponentUtil.LEFT_CENTER, line_heigh);
		btn_save.addActionListener(this);
		thisFrame.add(btn_save);

		btn_del = new JButton("Delete");
		ComponentUtil.setBounds(80, 25, btn_save, btn_del, ComponentUtil.LEFT_CENTER, line_heigh);
		btn_del.addActionListener(this);
		thisFrame.add(btn_del);
		
		btn_next = new JButton("Next");
		ComponentUtil.setBounds(80, 25,btn_del , btn_next, ComponentUtil.LEFT_CENTER, line_heigh);
		btn_next.addActionListener(this);
		thisFrame.add(btn_next);
		
		btn_previou = new JButton("Previou");
		ComponentUtil.setBounds(80, 25,btn_next , btn_previou, ComponentUtil.LEFT_CENTER, line_heigh);
		btn_previou.addActionListener(this);
		thisFrame.add(btn_previou);

		btn_addNext= new JButton("Add Next");
		btn_addNext.setMargin(new Insets(-5, -5, -5, -5));
		ComponentUtil.setBounds(75, 25, btn_previou, btn_addNext, ComponentUtil.LEFT_CENTER, line_heigh);
		btn_addNext.addActionListener(this);
		thisFrame.add(btn_addNext);

		
	}

	private void nextWord() {
		if(currIndex!=-1 && currIndex < dataList.size()-1){
			currIndex++;
		}
		updateUI();
	}

	private void prevWord() {
		if(currIndex!=-1 && currIndex > 0){
			currIndex--;
		}
		updateUI();
	}

	public void actionPerformed(ActionEvent e) {
		String actionCommand = "";
		if (e.getSource() instanceof JButton) {
			actionCommand = ((JButton) e.getSource()).getText();
		}
		if (actionCommand.equals("Cancel")) {
			((WordSearchScreen)parentFrame).search();
			thisFrame.exitScreen();
		} else if (actionCommand.equals("Save")) {
			thisFrame.update();
		} else if (actionCommand.equals("Previou")) {
			thisFrame.update();
			prevWord();
		} else if (actionCommand.equals("Next")) {
			thisFrame.update();
			nextWord();
		} else if (actionCommand.equals("x")) {
			int selectIndex = wordCNTable.getSelectedRow();
			if(selectIndex !=-1){
				wordCNDatas.remove(selectIndex);
				wordCNTable.updateUI();
			}
		} else if (actionCommand.equals("+")) {
			Vector<Object> record = new Vector<Object>();
			record.add("");
			wordCNDatas.add(record);
			wordCNTable.updateUI();
			wordCNTable.setRowSelectionInterval(0, wordCNDatas.size()-1);
		} else if (actionCommand.equals("↓")) {
			int selectIndex = wordCNTable.getSelectedRow();
			if(selectIndex<wordCNDatas.size()-1 && selectIndex !=-1){
				Vector<Object> record1 = wordCNDatas.get(selectIndex);
				Vector<Object> record2 = wordCNDatas.get(selectIndex+1);
				wordCNDatas.set(selectIndex, record2);
				wordCNDatas.set(++selectIndex, record1);
				wordCNTable.setRowSelectionInterval(0, selectIndex);
				wordCNTable.updateUI();
			}
		} else if (actionCommand.equals("↑")) {
			int selectIndex = wordCNTable.getSelectedRow();
			if(selectIndex>0){
				Vector<Object> record1 = wordCNDatas.get(selectIndex);
				Vector<Object> record2 = wordCNDatas.get(selectIndex-1);
				wordCNDatas.set(selectIndex, record2);
				wordCNDatas.set(--selectIndex, record1);
				wordCNTable.setRowSelectionInterval(0, selectIndex);
				wordCNTable.updateUI();
			}
		}
	}
	private void previou(){
		
	}
	private void next(){
		
	}
	private void update(){
		editWord.setFldWordid(currWord.getFldWordid());
		editWord.setFldAttr(service.getDBAttribs(txt_Attributes.getText()));// atts
		editWord.setFldChangetag(txt_Changetag.getText());
		editWord.setFldCreatdate(txt_CreateDate.getText());
		editWord.setFldErrorfag(txt_ErrorTest.getText());
		editWord.setFldErrortimes(service.checkNumber(txt_Errortimes.getText()));
		editWord.setFldForgettag(txt_Forgettag.getText());
		editWord.setFldFrom(txt_WordFrom.getText());// null
		editWord.setFldLasttestdate(txt_LastTestDate.getText());
		editWord.setFldPriority(service.checkNumber(txt_Priority.getText()));
		editWord.setFldRelevance(txt_Relevance.getText());// null
		editWord.setFldRemark(txt_Remark.getText()); // null
		editWord.setFldSymbol(txt_Symbol.getText()); // null
		editWord.setFldTesttimes(service.checkNumber(txt_TestTimes.getText()));
		editWord.setFldWordcn(service.getDBCN(wordCNDatas));
		editWord.setFldWorden(txt_WordEn.getText());
//		System.out.println(editWord);
//		System.out.println(wordCNDatas.size());
//		System.out.println(currWord.getFldWordcn() +","+ editWord.getFldWordcn());
		if(!service.checkNoChange(currWord,editWord)){
			currWord = editWord;
			service.updateWord(currWord);
			System.out.println("change");
		}else{
			System.out.println("no change");
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值