⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vlocationdialog.java

📁 Java写的ERP系统
💻 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 java.awt.event.*;
import javax.swing.*;
import java.util.*;

import org.compiere.apps.*;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;

/**
 *	Dialog to enter Location Info (Address)
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: VLocationDialog.java,v 1.8 2002/11/26 06:25:38 jjanke Exp $
 */
public class VLocationDialog extends JDialog implements ActionListener
{
	/**
	 *	Constructor
	 *
	 * @param frame parent
	 * @param title title (field name)
	 * @param mLocation Model Location
	 */
	public VLocationDialog (Frame frame, String title, MLocation mLocation)
	{
		super(frame, title, true);
		try
		{
			jbInit();
			setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		}
		catch(Exception ex)
		{
			Log.error("VLocationDialog - " + ex.getMessage());
		}
		//
		m_mLocation = mLocation;
		if (mLocation.C_Location_ID == 0)
			setTitle(Msg.getMsg(Env.getCtx(), "LocationNew"));
		else
			setTitle(Msg.getMsg(Env.getCtx(), "LocationUpdate"));

		//	Current Country
		fCountry = new CComboBox(m_mLocation.getCountries());
		fCountry.setSelectedItem(m_mLocation.mCountry);
		m_origCountry_ID = m_mLocation.C_Country_ID;
		//	Current Region
		fRegion = new CComboBox(m_mLocation.getRegions(m_origCountry_ID));
		if (m_mLocation.mCountry.HasRegion)
			lRegion.setText(m_mLocation.mCountry.RegionName);
		s_oldCountry_ID = m_mLocation.C_Country_ID;
		//
		initLocation();
		fCountry.addActionListener(this);
		AEnv.positionCenterWindow(frame, this);
	}	//	VLocationDialog

	private boolean 	m_change = false;
	private MLocation	m_mLocation;
	private int			m_origCountry_ID;
	private int			s_oldCountry_ID = 0;

	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 JLabel		lAddress1   = new JLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 1");
	private JLabel		lAddress2   = new JLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 2");
	private JLabel		lCity       = new JLabel(Msg.getMsg(Env.getCtx(), "City"));
	private JLabel		lCountry    = new JLabel(Msg.getMsg(Env.getCtx(), "Country"));
	private JLabel		lRegion     = new JLabel(Msg.getMsg(Env.getCtx(), "Region"));
	private JLabel		lPostal     = new JLabel(Msg.getMsg(Env.getCtx(), "Postal"));
	private JLabel		lPostalAdd  = new JLabel(Msg.getMsg(Env.getCtx(), "PostalAdd"));
	private CTextField	fAddress1 = new CTextField(15);		//	length=60
	private CTextField	fAddress2 = new CTextField(15);		//	length=60
	private CTextField	fCity  = new CTextField(10);		//	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
	{
		CompiereColor.setBackground(this);
		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_mLocation.mCountry;
		Log.trace(Log.l5_DData, "VLocationDialog.initLocation",
			country.Name + ", Region=" + country.HasRegion + " " + country.DisplaySequence
			+ ", ID=" + m_mLocation.C_Location_ID);
		//	new Region
		if (m_mLocation.C_Location_ID != s_oldCountry_ID && country.HasRegion)
		{
			fRegion = new CComboBox(m_mLocation.getRegions(country.C_Country_ID));
			if (m_mLocation.mRegion != null)
				fRegion.setSelectedItem(m_mLocation.mRegion);
			lRegion.setText(country.RegionName);
			s_oldCountry_ID = m_mLocation.C_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);

		//  sequence of City Postal Region - @P@ @C@ - @C@, @R@ @P@
		StringTokenizer st = new StringTokenizer(country.DisplaySequence, "@", 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("R") && m_mLocation.mCountry.HasRegion)
				addLine(line++, lRegion, fRegion);
		}
		//  Country Last
		addLine(line++, lCountry, fCountry);

		//	Fill it
		if (m_mLocation.C_Location_ID != 0)
		{
			fAddress1.setText(m_mLocation.Address1);
			fAddress2.setText(m_mLocation.Address2);
			fCity.setText(m_mLocation.City);
			fPostal.setText(m_mLocation.Postal);
			if (m_mLocation.mCountry.HasRegion)
			{
				lRegion.setText(m_mLocation.mCountry.RegionName);
				fRegion.setSelectedItem(m_mLocation.mRegion);
			}
			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.fill = GridBagConstraints.HORIZONTAL;
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		mainPanel.add(label, gbc);
		//	Field
		gbc.insets = fieldInsets;
		gbc.gridx = 1;
		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)
		{
			MCountry c = (MCountry)fCountry.getSelectedItem();
			m_mLocation.mCountry = c;
			m_mLocation.C_Country_ID = c.C_Country_ID;
			//	refrseh
			mainPanel.removeAll();
			initLocation();
		}
	}	//	actionPerformed

	/**
	 * 	OK - check for changes (save them) & Exit
	 */
	private void action_OK()
	{
		m_change = false;
		if (m_origCountry_ID != m_mLocation.C_Country_ID)
			m_change = true;
		//  Address
		if (!m_mLocation.Address1.equals(fAddress1.getText()))
		{
			m_mLocation.Address1 = fAddress1.getText();
			m_change = true;
		}
		if (!m_mLocation.Address2.equals(fAddress2.getText()))
		{
			m_mLocation.Address2 = fAddress2.getText();
			m_change = true;
		}
		//  City
		if (!m_mLocation.City.equals(fCity.getText()))
		{
			m_mLocation.City = fCity.getText();
			m_change = true;
		}
		//  Postal
		if (!m_mLocation.Postal.equals(fPostal.getText()))
		{
			m_mLocation.Postal = fPostal.getText();
			m_change = true;
		}
//			if (!m_mLocation.PostalAdd.equals(fPostalAdd.getText()))
//			{
//				m_mLocation.PostalAdd = fPostalAdd.getText();
//				m_change = true;
//			}
		//  Region
		if (m_mLocation.mCountry.HasRegion)
		{
			MRegion r = (MRegion)fRegion.getSelectedItem();
			if (r != null && m_mLocation.C_Region_ID != r.C_Region_ID)
			{
				m_mLocation.C_Region_ID = r.C_Region_ID;
				m_change = true;
			}
		}
		else
			m_mLocation.C_Region_ID = 0;
		//  Country
		MCountry c = (MCountry)fCountry.getSelectedItem();
		m_mLocation.C_Country_ID = c.C_Country_ID;
		//	Save chnages
		if (m_change)
			m_mLocation.save();
	}	//	actionOK

	/**
	 *	Get result
	 *  @return true, if changed
	 */
	public boolean isChanged()
	{
		return m_change;
	}	//	getChange

}	//	VLocationDialog

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -