📄 vdate.java
字号:
Timestamp ts = null;
try
{
java.util.Date date = m_format.parse(value);
ts = new Timestamp(date.getTime());
}
catch (ParseException pe)
{
Log.trace(Log.l6_Database, "VDate.getTimestamp - " + pe.getMessage());
}
return ts;
} // getValue
/**
* Return Editor value (Timestamp)
* @return value
*/
public Object getValue()
{
return getTimestamp();
} // getValue
/**
* Return Display Value
* @return display value
*/
public String getDisplay()
{
return m_text.getText();
} // getDisplay
/*************************************************************************/
/**
* Action Listener (Button)
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == m_button)
{
m_button.setEnabled(false);
requestFocus();
setValue(startCalendar(this, getTimestamp(), m_format, m_displayType, m_title));
fireChange(false);
m_button.setEnabled(true);
requestFocus();
}
} // actionPerformed
/**
* Action Listener Interface (Text)
* @param listener listener
*/// addActionListener
/**************************************************************************
* Key Listener Interface
* @param e Event
*/
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
/**
* Key Listener.
* - Escape - Restore old Text
* - firstChange - signal change
* @param e event
*/
public void keyReleased(KeyEvent e)
{
// System.out.println("VDate " + e);
// Enter
if (e.getKeyCode() == KeyEvent.VK_ENTER)
fireChange(false);
// Esc
else if (e.getKeyCode() == KeyEvent.VK_ESCAPE && !m_text.getText().equals(m_oldText))
{
m_text.setText(m_oldText);
m_firstChange = true;
}
// Change
else if (m_firstChange && !m_text.getText().equals(m_oldText))
{
fireChange(true);
m_firstChange = false;
}
} // keyReleased
/**
* Focus Gained - Save for Escape
* @param e event
*/
public void focusGained (FocusEvent e)
{
if (e.isTemporary())
return;
Log.trace(Log.l4_Data, "VDate.focusGained");
if (e.getSource() == this)
m_text.requestFocus();
else
m_oldText = m_text.getText();
} // focusGained
/**
* Data Binding to to GridController.
* @param e event
*/
public void focusLost (FocusEvent e)
{
Log.trace(Log.l4_Data, "VDate.focusLost");
return;
} // focusLost
/**
* Initiate Change
* @param first true if first
*/
private void fireChange (boolean first)
{
try
{
if (first)
fireVetoableChange(m_columnName, getValue(), null);
else
{
fireVetoableChange(m_columnName, null, getValue());
m_oldText = m_text.getText();
fireActionPerformed();
}
}
catch (PropertyVetoException pve)
{
Log.error("VDate.fireChange", pve);
}
} // fireChange
/**
* Invalid Entry - Start Calendar
* @param jc parent
* @param value value
* @param format format
* @param displayType display type
* @param title title
* @return formatted Date
*/
public static Timestamp startCalendar(Container jc, Timestamp value,
SimpleDateFormat format, int displayType, String title)
{
Log.trace(Log.l3_Util, "VDate.startCalendar", value);
// Find frame
Frame frame = Env.getFrame(jc);
// Actual Call
Calendar cal = new Calendar(frame, title, value, displayType);
AEnv.showCenterWindow(frame, cal);
Timestamp result = cal.getTimestamp();
cal = null;
//
Log.trace(Log.l4_Data, "Result=" + result);
if (result != null)
return result;
else
return value; // original value
} // startCalendar
/**
* Set Field/WindowNo for ValuePreference (NOP)
* @param mField MField
*/
public void setField (org.compiere.model.MField mField)
{
} // setField
/*************************************************************************/
/**
* Remove Action Listner
* @param l Action Listener
*/
public void removeActionListener(ActionListener l)
{
listenerList.remove(ActionListener.class, l);
} // removeActionListener
/**
* Add Action Listner
* @param l Action Listener
*/
public void addActionListener(ActionListener l)
{
listenerList.add(ActionListener.class, l);
} // addActionListener
/**
* Fire Action Event to listeners
*/
protected void fireActionPerformed()
{
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent)
modifiers = ((InputEvent)currentEvent).getModifiers();
else if (currentEvent instanceof ActionEvent)
modifiers = ((ActionEvent)currentEvent).getModifiers();
ActionEvent ae = new ActionEvent (this, ActionEvent.ACTION_PERFORMED,
"VDate", EventQueue.getMostRecentEventTime(), modifiers);
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2)
{
if (listeners[i]==ActionListener.class)
{
((ActionListener)listeners[i+1]).actionPerformed(ae);
}
}
} // fireActionPerformed
class CInputVerifier extends InputVerifier {
public boolean verify(JComponent input) {
/*There is a known issue with the InputVerifier. If the verification returns false the
button that is pressed will be in a semi-pressed state. It will appear pressed
when the mouse cursor moves over it. This only has a cosmetic effect and will disappear
when the button is reset.*/
//No date is valid
if (m_text == null || m_text.getText() == null)
{
return true;
}
//Check if a valid date was entered - this will force a date dialog
try
{
m_format.parse(m_text.getText());
}
catch (ParseException pe)
{
return false;
}
//Check if a mandatory date was not entered - this will force a date dialog
Object value = getValue();
if (value == null && isMandatory() )
{
return false;
}
// If there was no problem above CInputVerifier returns true
return true;
} // verify
public boolean shouldYieldFocus(JComponent input) {
if (verify(input))
{
// Everything was OK during verification - we can pass on the focus
// Set Value
fireChange(false);
return true;
}
//There was a problem during the verification
//We temporarily remove the InputVerifier so that we can show the DateDialog
input.setInputVerifier(null);
//We start the DateDialog
setValue(startCalendar(VDate.this, getTimestamp(), m_format, m_displayType, m_title));
//We activate the InputVerifier again
input.setInputVerifier(this);
// Set Value
fireChange(false);
//The problem should now be rectified so we pass on the focus
return true;
} //shouldYieldFocus
} // CInputVerifier
} // VDate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -