📄 vlocationdialog.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-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid.ed;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import org.compiere.apps.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Dialog to enter Location Info (Address)
*
* @author Jorg Janke
* @version $Id: VLocationDialog.java,v 1.24 2005/12/27 06:18:36 jjanke Exp $
*/
public class VLocationDialog extends CDialog
implements ActionListener
{
/**
* Constructor
*
* @param frame parent
* @param title title (field name)
* @param location Model Location
*/
public VLocationDialog (Frame frame, String title, MLocation location)
{
super(frame, title, true);
try
{
jbInit();
}
catch(Exception ex)
{
log.log(Level.SEVERE, ex.getMessage());
}
m_location = location;
if (m_location == null)
m_location = new MLocation (Env.getCtx(), 0, null);
// Overwrite title
if (m_location.getC_Location_ID() == 0)
setTitle(Msg.getMsg(Env.getCtx(), "LocationNew"));
else
setTitle(Msg.getMsg(Env.getCtx(), "LocationUpdate"));
// Current Country
MCountry.setDisplayLanguage(Env.getAD_Language(Env.getCtx()));
fCountry = new CComboBox(MCountry.getCountries(Env.getCtx()));
fCountry.setSelectedItem(m_location.getCountry());
m_origCountry_ID = m_location.getC_Country_ID();
// Current Region
fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), m_origCountry_ID));
if (m_location.getCountry().isHasRegion())
lRegion.setText(m_location.getCountry().getRegionName()); // name for region
fRegion.setSelectedItem(m_location.getRegion());
//
initLocation();
fCountry.addActionListener(this);
AEnv.positionCenterWindow(frame, this);
} // VLocationDialog
private boolean m_change = false;
private MLocation m_location;
private int m_origCountry_ID;
private int s_oldCountry_ID = 0;
/** Logger */
private static CLogger log = CLogger.getCLogger(VLocationDialog.class);
private CPanel panel = new CPanel();
private CPanel mainPanel = new CPanel();
private CPanel southPanel = new CPanel();
private BorderLayout panelLayout = new BorderLayout();
private GridBagLayout gridBagLayout = new GridBagLayout();
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private BorderLayout southLayout = new BorderLayout();
//
private CLabel lAddress1 = new CLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 1");
private CLabel lAddress2 = new CLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 2");
private CLabel lAddress3 = new CLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 3");
private CLabel lAddress4 = new CLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 4");
private CLabel lCity = new CLabel(Msg.getMsg(Env.getCtx(), "City"));
private CLabel lCountry = new CLabel(Msg.getMsg(Env.getCtx(), "Country"));
private CLabel lRegion = new CLabel(Msg.getMsg(Env.getCtx(), "Region"));
private CLabel lPostal = new CLabel(Msg.getMsg(Env.getCtx(), "Postal"));
private CLabel lPostalAdd = new CLabel(Msg.getMsg(Env.getCtx(), "PostalAdd"));
private CTextField fAddress1 = new CTextField(20); // length=60
private CTextField fAddress2 = new CTextField(20); // length=60
private CTextField fAddress3 = new CTextField(20); // length=60
private CTextField fAddress4 = new CTextField(20); // length=60
private CTextField fCity = new CTextField(15); // length=60
private CComboBox fCountry;
private CComboBox fRegion;
private CTextField fPostal = new CTextField(5); // length=10
private CTextField fPostalAdd = new CTextField(5); // length=10
//
private GridBagConstraints gbc = new GridBagConstraints();
private Insets labelInsets = new Insets(2,15,2,0); // top,left,bottom,right
private Insets fieldInsets = new Insets(2,5,2,10);
/**
* Static component init
* @throws Exception
*/
void jbInit() throws Exception
{
panel.setLayout(panelLayout);
southPanel.setLayout(southLayout);
mainPanel.setLayout(gridBagLayout);
panelLayout.setHgap(5);
panelLayout.setVgap(10);
getContentPane().add(panel);
panel.add(mainPanel, BorderLayout.CENTER);
panel.add(southPanel, BorderLayout.SOUTH);
southPanel.add(confirmPanel, BorderLayout.NORTH);
//
confirmPanel.addActionListener(this);
} // jbInit
/**
* Dynanmic Init & fill fields - Called when Country changes!
*/
private void initLocation()
{
MCountry country = m_location.getCountry();
log.fine(country.getName() + ", Region=" + country.isHasRegion() + " " + country.getDisplaySequence()
+ ", C_Location_ID=" + m_location.getC_Location_ID());
// new Region
if (m_location.getC_Country_ID() != s_oldCountry_ID && country.isHasRegion())
{
fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), country.getC_Country_ID()));
if (m_location.getRegion() != null)
fRegion.setSelectedItem(m_location.getRegion());
lRegion.setText(country.getRegionName());
s_oldCountry_ID = m_location.getC_Country_ID();
}
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridy = 0; // line
gbc.gridx = 0;
gbc.gridwidth = 1;
gbc.insets = fieldInsets;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0;
gbc.weighty = 0;
mainPanel.add(Box.createVerticalStrut(5), gbc); // top gap
int line = 1;
addLine(line++, lAddress1, fAddress1);
addLine(line++, lAddress2, fAddress2);
addLine(line++, lAddress3, fAddress3);
addLine(line++, lAddress4, fAddress4);
// sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
String ds = country.getDisplaySequence();
if (ds == null || ds.length() == 0)
{
log.log(Level.SEVERE, "DisplaySequence empty - " + country);
ds = ""; // @C@, @P@
}
StringTokenizer st = new StringTokenizer(ds, "@", false);
while (st.hasMoreTokens())
{
String s = st.nextToken();
if (s.startsWith("C"))
addLine(line++, lCity, fCity);
else if (s.startsWith("P"))
addLine(line++, lPostal, fPostal);
else if (s.startsWith("A"))
addLine(line++, lPostalAdd, fPostalAdd);
else if (s.startsWith("R") && m_location.getCountry().isHasRegion())
addLine(line++, lRegion, fRegion);
}
// Country Last
addLine(line++, lCountry, fCountry);
// Fill it
if (m_location.getC_Location_ID() != 0)
{
fAddress1.setText(m_location.getAddress1());
fAddress2.setText(m_location.getAddress2());
fAddress3.setText(m_location.getAddress3());
fAddress4.setText(m_location.getAddress4());
fCity.setText(m_location.getCity());
fPostal.setText(m_location.getPostal());
fPostalAdd.setText(m_location.getPostal_Add());
if (m_location.getCountry().isHasRegion())
{
lRegion.setText(m_location.getCountry().getRegionName());
fRegion.setSelectedItem(m_location.getRegion());
}
fCountry.setSelectedItem(country);
}
// Update UI
pack();
} // initLocation
/**
* Add Line to screen
*
* @param line line number (zero based)
* @param label label
* @param field field
*/
private void addLine(int line, JLabel label, JComponent field)
{
gbc.gridy = line;
// label
gbc.insets = labelInsets;
gbc.gridx = 0;
gbc.weightx = 0.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
label.setHorizontalAlignment(SwingConstants.RIGHT);
mainPanel.add(label, gbc);
// Field
gbc.insets = fieldInsets;
gbc.gridx = 1;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.NONE;
mainPanel.add(field, gbc);
} // addLine
/**
* ActionListener
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
action_OK();
m_change = true;
dispose();
}
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
{
m_change = false;
dispose();
}
// Country Changed - display in new Format
else if (e.getSource() == fCountry)
{
// Modifier for Mouse selection is 16 - for any key selection 0
MCountry c = (MCountry)fCountry.getSelectedItem();
m_location.setCountry(c);
// refrseh
mainPanel.removeAll();
initLocation();
fCountry.requestFocus(); // allows to use Keybord selection
}
} // actionPerformed
/**
* OK - check for changes (save them) & Exit
*/
private void action_OK()
{
m_location.setAddress1(fAddress1.getText());
m_location.setAddress2(fAddress2.getText());
m_location.setAddress3(fAddress3.getText());
m_location.setAddress4(fAddress4.getText());
m_location.setCity(fCity.getText());
m_location.setPostal(fPostal.getText());
m_location.setPostal_Add(fPostalAdd.getText());
// Country/Region
MCountry c = (MCountry)fCountry.getSelectedItem();
m_location.setCountry(c);
if (m_location.getCountry().isHasRegion())
{
MRegion r = (MRegion)fRegion.getSelectedItem();
m_location.setRegion(r);
}
else
m_location.setC_Region_ID(0);
// Save chnages
m_location.save();
} // actionOK
/**
* Get result
* @return true, if changed
*/
public boolean isChanged()
{
return m_change;
} // getChange
/**
* Get edited Value (MLocation)
* @return location
*/
public MLocation getValue()
{
return m_location;
} // getValue
} // VLocationDialog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -