📄 vstring.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid.ed;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.beans.*;
import org.compiere.apps.*;
import org.compiere.util.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.model.*;
/**
* Data Binding:
* VEditors call fireVetoableChange(m_columnName, null, getText());
* GridController (for Single-Row) and VCellExitor (for Multi-Row)
* listen to Vetoable Change Listener (vetoableChange)
* then set the value for that column in the current row in the table
*
* @author Jorg Janke
* @version $Id: VString.java,v 1.15 2003/04/29 09:21:41 jpedersen Exp $
*/
public final class VString extends CTextField
implements VEditor, KeyListener, FocusListener, ActionListener
{
public static final int MAXDISPLAY_LENGTH = org.compiere.model.MField.MAXDISPLAY_LENGTH;
/**
* IDE Bean Constructor for 30 character updateable field
*/
public VString()
{
this("String", false, false, true, 30, 30, "");
} // VString
/**
* Detail Constructor
* @param columnName
* @param mandatory
* @param isReadOnly
* @param isUpdateable
* @param displayLength
* @param fieldLength
* @param VFormat
*/
public VString (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
int displayLength, int fieldLength, String VFormat)
{
super(displayLength>MAXDISPLAY_LENGTH ? MAXDISPLAY_LENGTH : displayLength);
m_columnName = columnName;
if (VFormat == null)
VFormat = "";
m_VFormat = VFormat;
m_fieldLength = fieldLength;
if (m_VFormat.length() != 0 || m_fieldLength != 0)
setDocument(new MDocString(m_VFormat, m_fieldLength, this));
if (m_VFormat.length() != 0)
setCaret(new VOvrCaret());
//
setMandatory(mandatory);
// Editable
if (isReadOnly || !isUpdateable)
{
setEditable(false);
setBackground(CompierePLAF.getFieldBackground_Inactive());
}
this.addKeyListener(this);
this.addFocusListener(this);
this.addActionListener(this);
setInputVerifier(new CInputVerifier()); //Must be called AFTER FocusListener in order to work
// Popup for Editor
if (fieldLength > displayLength)
{
addMouseListener(new VString_mouseAdapter(this));
mEditor = new JMenuItem (Msg.getMsg(Env.getCtx(), "Editor"), Env.getImageIcon("Editor16.gif"));
mEditor.addActionListener(this);
popupMenu.add(mEditor);
}
setForeground(CompierePLAF.getTextColor_Normal());
setBackground(CompierePLAF.getFieldBackground_Normal());
} // VString
/**
* Dispose
*/
public void dispose()
{
m_mField = null;
} // dispose
JPopupMenu popupMenu = new JPopupMenu();
private JMenuItem mEditor;
private MField m_mField = null;
private String m_columnName;
private String m_oldText;
private boolean m_firstChange;
private String m_VFormat;
private int m_fieldLength;
/**
* Set Editor to value
* @param value
*/
public void setValue(Object value)
{
// Log.trace(Log.l4_Data, "VString.setValue", value);
if (value == null)
m_oldText = "";
else
m_oldText = value.toString();
setText (m_oldText);
m_firstChange = true;
} // setValue
/**
* Property Change Listener
* @param evt
*/
public void propertyChange (PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY))
setValue(evt.getNewValue());
} // propertyChange
/**
* Return Editor value
* @return value
*/
public Object getValue()
{
return getText();
} // getValue
/**
* Return Display Value
* @return value
*/
public String getDisplay()
{
return getText();
} // getDisplay
/**************************************************************************
* Key Listener Interface
* @param e
*/
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
/**
* Key Listener.
* - Escape - Restore old Text
* - firstChange - signal change
* @param e
*/
public void keyReleased(KeyEvent e)
{
// ESC
if (e.getKeyCode() == KeyEvent.VK_ESCAPE
&& !getText().equals(m_oldText))
{
setText(m_oldText);
return;
}
// first change - indicate
if (m_firstChange && !m_oldText.equals(getText()))
{
m_firstChange = false;
try
{
fireVetoableChange(m_columnName, getText(), null);
}
catch (PropertyVetoException pve) {}
} // firstChange
} // keyReleased
/**
* Focus Gained - Save for Escape
* @param e
*/
public void focusGained (FocusEvent e)
{
// Log.trace(this,Log.l4_Data, "VString.focusGained", e.paramString());
m_oldText = getText();
} // focusGained
/**
* Data Binding to MTable (via GridController)
* @param e
*/
public void focusLost (FocusEvent e)
{
// Log.trace(this,Log.l4_Data, "VString.focusLost", e.paramString());
return;
} // focusLost
/**
* Data Binding to MTable (via GridController) - Enter pressed
* @param e
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ValuePreference.NAME))
{
ValuePreference.start (m_mField, getValue());
return;
}
// Invoke Editor
if (e.getSource() == mEditor)
{
String s = Editor.startEditor(this, Msg.translate(Env.getCtx(), m_columnName), getText(), isEditable());
setText(s);
}
// Data Binding
try
{
fireVetoableChange(m_columnName, null, getText());
m_oldText = getText();
}
catch (PropertyVetoException pve) {}
} // actionPerformed
/**
* Set Field/WindowNo for ValuePreference
* @param mField
*/
public void setField (MField mField)
{
m_mField = mField;
if (m_mField != null)
ValuePreference.addMenu (this, popupMenu);
} // setField
class CInputVerifier extends InputVerifier {
public boolean verify(JComponent input) {
//Note: We always return true since Inputverifier is just used to guarantee that fireChange is called in due time
if (getText() == null && m_oldText == null)
return true;
else if (getText().equals(m_oldText))
return true;
//
try
{
String text = getText();
fireVetoableChange(m_columnName, null, text);
m_oldText = text;
return true;
}
catch (PropertyVetoException pve) {}
return true;
} // verify
} // CInputVerifier
} // VString
/*****************************************************************************/
/**
* Mouse Listener
*/
final class VString_mouseAdapter extends MouseAdapter
{
/**
* Constructor
* @param adaptee
*/
VString_mouseAdapter(VString adaptee)
{
this.adaptee = adaptee;
} // VString_mouseAdapter
private VString adaptee;
/**
* Mouse Listener
* @param e
*/
public void mouseClicked(MouseEvent e)
{
// popup menu
if (SwingUtilities.isRightMouseButton(e))
adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouse Clicked
} // VText_mouseAdapter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -