Java tutorial
/* Copyright (C) 2006 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.composite.action; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.widgets.Text; import com.clustercontrol.util.Messages; import com.clustercontrol.util.WidgetTestUtil; /** * VerifyListener<BR> * * @version 2.1.0 * @since 2.1.0 */ public class TimeVerifyListener implements VerifyListener { private static final String NUMBER_CHAR = "0123456789:-"; private static final String COLON_CHAR = ":"; private static final Integer LENGTH = Integer.valueOf(9); /* * (non-Javadoc) * * @see org.eclipse.swt.events.VerifyListener#verifyText(org.eclipse.swt.events.VerifyEvent) */ @Override public void verifyText(VerifyEvent e) { //???? Text text = (Text) e.getSource(); WidgetTestUtil.setTestId(this, null, text); StringBuilder input = new StringBuilder(text.getText()); //??? if (e.keyCode == 0) { //?????? // input.replace(e.start, e.end, e.text); } else { //BackspaceDelete?????????? if (e.character == SWT.BS || e.character == SWT.DEL) { input.delete(e.start, e.end); } //??? else if (NUMBER_CHAR.indexOf(Character.toString(e.character)) == -1) { e.doit = false; return; } //':'????????????? else if (COLON_CHAR.indexOf(Character.toString(e.character)) == 0) { if (text.getText().length() == 0) { e.doit = false; } return; } else { // input.replace(e.start, e.end, e.text); } } //? checkRange(e, input.toString()); } /** * ? * * @param e * @param inputText */ private void checkRange(VerifyEvent e, String inputText) { //?? //try { //if(inputText.getBytes("UTF-8").length > LENGTH){ if (inputText.length() > LENGTH) { //? e.doit = false; String[] args = { LENGTH.toString() }; // MessageDialog.openWarning(null, Messages.getString("message.hinemos.1"), Messages.getString("message.hinemos.7", args)); } /*} catch (UnsupportedEncodingException e1) { //? e.doit = false; }*/ } }