Update of /cvsroot/compiere/client/Src/org/compiere/grid/ed
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3556/Src/org/compiere/grid/ed
Modified Files:
VPAttribute.java VString.java VLookup.java VEditorFactory.java
Added Files:
VURL.java
Log Message:
--- NEW FILE: VURL.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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2006 Jorg Janke.
* All parts are Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid.ed;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* URL Editor
*
* @author Jorg Janke
* @version $Id: VURL.java,v 1.1 2006/03/17 05:55:14 jjanke Exp $
*/
public class VURL extends JComponent
implements VEditor, ActionListener, KeyListener
{
/**
* IDE Constructor
*/
public VURL ()
{
this ("URL", false, false, true, 20, 60);
} // VURL
/**
* Detail Constructor
* @param columnName column name
* @param mandatory mandatory
* @param isReadOnly read only
* @param isUpdateable updateable
* @param displayLength display length
* @param fieldLength field length
*/
public VURL (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
int displayLength, int fieldLength)
{
super.setName(columnName);
m_columnName = columnName;
m_fieldLength = fieldLength;
m_mandatory = mandatory;
LookAndFeel.installBorder(this, "TextField.border");
this.setLayout(new BorderLayout());
// Size
this.setPreferredSize(m_text.getPreferredSize());
int height = m_text.getPreferredSize().height;
// *** Text ***
m_text = new CTextField(displayLength>VString.MAXDISPLAY_LENGTH ? VString.MAXDISPLAY_LENGTH : displayLength);
m_text.setEditable(isReadOnly);
m_text.setFocusable(true);
m_text.setBorder(null);
m_text.setHorizontalAlignment(JTextField.LEADING);
// Background
setMandatory(mandatory);
this.add(m_text, BorderLayout.CENTER);
// *** Button ***
m_button.setIcon(Env.getImageIcon("Translate16.gif")); // should be 10
m_button.setMargin(new Insets(0, 0, 0, 0));
m_button.setPreferredSize(new Dimension(height, height));
m_button.addActionListener(this);
m_button.setFocusable(false);
this.add(m_button, BorderLayout.EAST);
// Prefereed Size
this.setPreferredSize(this.getPreferredSize()); // causes r/o to be the same length
// ReadWrite
if (isReadOnly || !isUpdateable)
setReadWrite(false);
else
setReadWrite(true);
m_text.addKeyListener(this);
m_text.addActionListener(this);
// Popup for Editor
if (fieldLength > displayLength)
{
addMouseListener(new VURL_mouseAdapter(this));
mEditor = new CMenuItem (Msg.getMsg(Env.getCtx(), "Editor"), Env.getImageIcon("Editor16.gif"));
mEditor.addActionListener(this);
popupMenu.add(mEditor);
}
setForeground(CompierePLAF.getTextColor_Normal());
setBackground(CompierePLAF.getFieldBackground_Normal());
} // VURL
/** Logger */
private static CLogger log = CLogger.getCLogger (VURL.class);
/** Column Name */
private String m_columnName;
/** The Text */
private CTextField m_text = new CTextField();
private boolean m_readWrite;
private boolean m_mandatory;
/** The Button */
private CButton m_button = new CButton();
/** Popup Menu */
JPopupMenu popupMenu = new JPopupMenu();
/** Editor Menu Item */
private CMenuItem mEditor;
/** Grid Field */
private GridField m_mField = null;
private String m_oldText;
private String m_initialText;
/** Setting new value */
private volatile boolean m_setting = false;
/** Field in focus */
private volatile boolean m_infocus = false;
/** Field Length */
private int m_fieldLength;
/**
* Dispose resources
*/
public void dispose()
{
m_text = null;
m_button = null;
m_mField = null;
} // dispose
/**
* Set Mandatory
* @param mandatory mandatory
*/
public void setMandatory (boolean mandatory)
{
m_mandatory = mandatory;
m_text.setMandatory(mandatory);
setBackground (false);
} // setMandatory
/**
* Get Mandatory
* @return mandatory
*/
public boolean isMandatory()
{
return m_mandatory;
} // isMandatory
/**
* Set ReadWrite
* @param rw read rwite
*/
public void setReadWrite (boolean rw)
{
m_readWrite = rw;
m_text.setReadWrite(rw);
setBackground (false);
} // setReadWrite
/**
* Is Read Write
* @return read write
*/
public boolean isReadWrite()
{
return m_readWrite;
} // isReadWrite
/**
* Set Foreground
* @param color color
*/
public void setForeground (Color color)
{
m_text.setForeground(color);
} // SetForeground
/**
* Set Background
* @param error Error
*/
public void setBackground (boolean error)
{
if (error)
setBackground(CompierePLAF.getFieldBackground_Error());
else if (!m_readWrite)
setBackground(CompierePLAF.getFieldBackground_Inactive());
else if (m_mandatory)
setBackground(CompierePLAF.getFieldBackground_Mandatory());
else
setBackground(CompierePLAF.getInfoBackground());
} // setBackground
/**
* Set Background
* @param color Color
*/
public void setBackground (Color color)
{
m_text.setBackground(color);
} // setBackground
/**
* Set Editor to value
* @param value value
*/
public void setValue(Object value)
{
// log.config( "VString.setValue", value);
if (value == null)
m_oldText = "";
else
m_oldText = value.toString();
// only set when not updated here
if (m_setting)
return;
setText (m_oldText);
m_initialText = m_oldText;
// If R/O left justify
if (!m_text.isEditable() || !isEnabled())
m_text.setCaretPosition(0);
} // setValue
/**
* Property Change Listener
* @param evt event
*/
public void propertyChange (PropertyChangeEvent evt)
{
if (evt.getPropertyName().equals(org.compiere.model.GridField.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 m_text.getText();
} // getDisplay
/**
* Key Released.
* if Escape Restore old Text
* @param e event
*/
public void keyReleased(KeyEvent e)
{
log.finest("Key=" + e.getKeyCode() + " - " + e.getKeyChar()
+ " -> " + getText());
// ESC
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
setText(m_initialText);
m_setting = true;
try
{
String clear = getText();
if (clear.length() > m_fieldLength)
clear = clear.substring(0, m_fieldLength);
fireVetoableChange (m_columnName, m_oldText, clear);
}
catch (PropertyVetoException pve)
{
}
m_setting = false;
} // keyReleased
/**
* Key Pressed
* @param e ignored
*/
public void keyPressed (KeyEvent e)
{
} // keyPressed
/**
* Key Typed
* @param e ignored
*/
public void keyTyped (KeyEvent e)
{
} // keyTyped
/**
* Add Action Listener
* @param listener listener
*/
public void addActionListener (ActionListener listener)
{
m_text.addActionListener(listener);
} // addActionListener
/**
* Data Binding to MTable (via GridController) - Enter pressed
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ValuePreference.NAME))
{
if (MRole.getDefault().isShowPreference())
ValuePreference.start (m_mField, getValue());
return;
}
// Invoke Editor
if (e.getSource() == mEditor)
{
String s = Editor.startEditor(this, Msg.translate(Env.getCtx(), m_columnName),
getText(), m_text.isEditable(), m_fieldLength);
setText(s);
}
// Data Binding
try
{
fireVetoableChange(m_columnName, m_oldText, getText());
}
catch (PropertyVetoException pve)
{
}
} // actionPerformed
/**
* Set Field/WindowNo for ValuePreference
* @param mField field
*/
public void setField (GridField mField)
{
m_mField = mField;
if (m_mField != null
&& MRole.getDefault().isShowPreference())
ValuePreference.addMenu (this, popupMenu);
} // setField
/**
* Set Text
* @param text text
*/
public void setText (String text)
{
m_text.setText (text);
} // setText
/**
* Get Text (clear)
* @return text
*/
public String getText ()
{
String text = m_text.getText();
return text;
} // getText
/**
* Focus Gained.
* Enabled with Obscure
* @param e event
*/
public void focusGained (FocusEvent e)
{
m_infocus = true;
setText(getText()); // clear
} // focusGained
/**
* Focus Lost
* Enabled with Obscure
* @param e event
*/
public void focusLost (FocusEvent e)
{
m_infocus = false;
setText(getText()); // obscure
} // focus Lost
/******************************************************************************
* Mouse Listener
*/
final class VURL_mouseAdapter extends MouseAdapter
{
/**
* Constructor
* @param adaptee adaptee
*/
VURL_mouseAdapter(VURL adaptee)
{
m_adaptee = adaptee;
} // VString_mouseAdapter
private VURL m_adaptee;
/**
* Mouse Listener
* @param e event
*/
public void mouseClicked(MouseEvent e)
{
// popup menu
if (SwingUtilities.isRightMouseButton(e))
m_adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouseClicked
} // VURL_mouseAdapter
} // VURL
Index: VPAttribute.java
===================================================================
RCS file: /cvsroot/compiere/client/Src/org/compiere/grid/ed/VPAttribute.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** VPAttribute.java 21 Feb 2006 20:40:46 -0000 1.26
--- VPAttribute.java 17 Mar 2006 05:55:14 -0000 1.27
***************
*** 404,411 ****
VPAttribute_mouseAdapter(VPAttribute adaptee)
{
! this.adaptee = adaptee;
} // VPAttribute_mouseAdapter
! private VPAttribute adaptee;
/**
--- 404,411 ----
VPAttribute_mouseAdapter(VPAttribute adaptee)
{
! m_adaptee = adaptee;
} // VPAttribute_mouseAdapter
! private VPAttribute m_adaptee;
/**
***************
*** 417,424 ****
// Double Click
if (e.getClickCount() > 1)
! adaptee.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "Mouse"));
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouse Clicked
--- 417,424 ----
// Double Click
if (e.getClickCount() > 1)
! m_adaptee.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "Mouse"));
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! m_adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouse Clicked
Index: VString.java
===================================================================
RCS file: /cvsroot/compiere/client/Src/org/compiere/grid/ed/VString.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** VString.java 21 Feb 2006 20:40:46 -0000 1.30
--- VString.java 17 Mar 2006 05:55:14 -0000 1.31
***************
*** 36,39 ****
--- 36,40 ----
implements VEditor, ActionListener, FocusListener
{
+ /** Max Display Length - 60 */
public static final int MAXDISPLAY_LENGTH = org.compiere.model.GridField.MAXDISPLAY_LENGTH;
***************
*** 55,58 ****
--- 56,60 ----
* @param fieldLength field length
* @param VFormat format
+ * @param ObscureType obscure type
*/
public VString (String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable,
***************
*** 109,121 ****
} // dispose
JPopupMenu popupMenu = new JPopupMenu();
private CMenuItem mEditor;
!
private GridField m_mField = null;
!
private String m_columnName;
private String m_oldText;
private String m_initialText;
private String m_VFormat;
private int m_fieldLength;
/** Obcure Setting */
--- 111,126 ----
} // dispose
+ /** Popup Menu */
JPopupMenu popupMenu = new JPopupMenu();
+ /** Editor Menu Item */
private CMenuItem mEditor;
! /** Grid Field */
private GridField m_mField = null;
! /** Column Name */
private String m_columnName;
private String m_oldText;
private String m_initialText;
private String m_VFormat;
+ /** Field Length */
private int m_fieldLength;
/** Obcure Setting */
***************
*** 197,200 ****
--- 202,207 ----
{
String clear = getText();
+ if (clear.length() > m_fieldLength)
+ clear = clear.substring(0, m_fieldLength);
fireVetoableChange (m_columnName, m_oldText, clear);
}
***************
*** 323,330 ****
VString_mouseAdapter(VString adaptee)
{
! this.adaptee = adaptee;
} // VString_mouseAdapter
! private VString adaptee;
/**
--- 330,337 ----
VString_mouseAdapter(VString adaptee)
{
! m_adaptee = adaptee;
} // VString_mouseAdapter
! private VString m_adaptee;
/**
***************
*** 336,340 ****
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouseClicked
--- 343,347 ----
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! m_adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouseClicked
Index: VLookup.java
===================================================================
RCS file: /cvsroot/compiere/client/Src/org/compiere/grid/ed/VLookup.java,v
retrieving revision 1.88
retrieving revision 1.89
diff -C2 -d -r1.88 -r1.89
*** VLookup.java 21 Feb 2006 20:40:46 -0000 1.88
--- VLookup.java 17 Mar 2006 05:55:14 -0000 1.89
***************
*** 1277,1284 ****
VLookup_mouseAdapter(VLookup adaptee)
{
! this.adaptee = adaptee;
} // VLookup_mouseAdapter
! private VLookup adaptee;
/**
--- 1277,1284 ----
VLookup_mouseAdapter(VLookup adaptee)
{
! m_adaptee = adaptee;
} // VLookup_mouseAdapter
! private VLookup m_adaptee;
/**
***************
*** 1291,1295 ****
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouse Clicked
--- 1291,1295 ----
// popup menu
if (SwingUtilities.isRightMouseButton(e))
! m_adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY());
} // mouse Clicked
Index: VEditorFactory.java
===================================================================
RCS file: /cvsroot/compiere/client/Src/org/compiere/grid/ed/VEditorFactory.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** VEditorFactory.java 21 Feb 2006 20:40:46 -0000 1.29
--- VEditorFactory.java 17 Mar 2006 05:55:14 -0000 1.30
***************
*** 67,71 ****
// String (clear/password)
if (displayType == DisplayType.String
- || displayType == DisplayType.URL
|| displayType == DisplayType.PrinterName
|| (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong)) )
--- 67,70 ----
***************
*** 89,92 ****
--- 88,100 ----
}
}
+ // URL
+ else if (displayType == DisplayType.URL)
+ {
+ VURL vs = new VURL (columnName, mandatory, readOnly, updateable,
+ mField.getDisplayLength(), mField.getFieldLength());
+ vs.setName (columnName);
+ vs.setField (mField);
+ editor = vs;
+ }
/** Printer Name
|