|
|
|
@ -10,7 +10,6 @@ import javax.swing.text.JTextComponent;
|
|
|
|
|
import javax.swing.text.PlainDocument; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
public class JDateDocument extends PlainDocument{ |
|
|
|
|
private JTextComponent textComponent; //日期输入文本框
|
|
|
|
@ -36,39 +35,19 @@ public class JDateDocument extends PlainDocument {
|
|
|
|
|
SimpleDateFormat dateFormat, |
|
|
|
|
String initDateTime) throws |
|
|
|
|
UnsupportedOperationException { |
|
|
|
|
this(tc, dateFormat, initDateTime, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param tc |
|
|
|
|
* @param dateFormat |
|
|
|
|
* @param initDateTime |
|
|
|
|
* @param initTime 判断是不是要通过insertString设置默认值 |
|
|
|
|
* @throws UnsupportedOperationException |
|
|
|
|
*/ |
|
|
|
|
public JDateDocument(JTextComponent tc, |
|
|
|
|
SimpleDateFormat dateFormat, |
|
|
|
|
String initDateTime, |
|
|
|
|
boolean initTime) throws |
|
|
|
|
UnsupportedOperationException { |
|
|
|
|
//设置当前日期格式
|
|
|
|
|
setDateFormat(dateFormat); |
|
|
|
|
//保存操作的文本框
|
|
|
|
|
textComponent = tc; |
|
|
|
|
//设置显示为当前日期,同时完成显示的格式化,如果emptyDateTime为true就设时间为空
|
|
|
|
|
if (!initTime) { |
|
|
|
|
try { |
|
|
|
|
insertString(0, initDateTime, null); |
|
|
|
|
} catch (BadLocationException ex) { |
|
|
|
|
throw new UnsupportedOperationException(ex.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置当前日期格式 |
|
|
|
|
* |
|
|
|
|
* @param dateFormat SimpleDateFormat |
|
|
|
|
*/ |
|
|
|
|
public void setDateFormat(SimpleDateFormat dateFormat){ |
|
|
|
@ -77,7 +56,6 @@ public class JDateDocument extends PlainDocument {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 取得当前日期格式 |
|
|
|
|
* |
|
|
|
|
* @return SimpleDateFormat |
|
|
|
|
*/ |
|
|
|
|
public SimpleDateFormat getDateFormat(){ |
|
|
|
@ -86,7 +64,6 @@ public class JDateDocument extends PlainDocument {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 取得当前系统日时 |
|
|
|
|
* |
|
|
|
|
* @return String |
|
|
|
|
*/ |
|
|
|
|
public static String getCurrentDate(SimpleDateFormat smFormat){ |
|
|
|
|