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

📄 preference.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.apps;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

import org.compiere.util.*;
import org.compiere.grid.ed.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.print.*;

/**
 *	Customize settings like L&F, AutoCommit, etc. & Diagnostics
 *
 *  @author 	Jorg Janke
 *  @version 	$Id: Preference.java,v 1.17 2002/10/08 04:28:56 jjanke Exp $
 */
public final class Preference extends JDialog
	implements ActionListener, ListSelectionListener
{
	/**
	 *	Standard Constructor
	 *  @param frame frame
	 *  @param WindowNo window
	 *  @param modal modal
	 */
	public Preference(Frame frame, int WindowNo, boolean modal)
	{
		super(frame, Msg.getMsg(Env.getCtx(), "Preference"), modal);
		Log.trace(Log.l2_Sub, "Preference");
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		try
		{
			jbInit();
		}
		catch(Exception ex)
		{
			Log.error("Preference - " + ex.getMessage());
		}
		load();
		//
		StringBuffer sta = new StringBuffer("#");
		sta.append(Env.getCtx().size()).append(" - ")
			.append(Msg.translate(Env.getCtx(), "AD_Window_ID"))
			.append("=").append(WindowNo);
		statusBar.setStatusLine(sta.toString());
		statusBar.setStatusDB("");
		AEnv.positionCenterWindow(frame, this);
	}	//	Preference

	/**
	 *	Minimum Constructor
	 */
	public Preference()
	{
		this(null, 0, false);
	}	//	Preference

	private CPanel panel = new CPanel();
	private BorderLayout panelLayout = new BorderLayout();
	private CTabbedPane tabPane = new CTabbedPane();
	private CPanel customize = new CPanel();
	private CPanel info = new CPanel();
	private GridBagLayout customizeLayout = new GridBagLayout();
	private CCheckBox autoCommit = new CCheckBox();
	private CCheckBox printPreview = new CCheckBox();
	private CPanel southPanel = new CPanel();
	private BorderLayout southLayout = new BorderLayout();
	private BorderLayout infoLayout = new BorderLayout();
	private JList infoList = new JList();
	private JScrollPane infoListScrollPane = new JScrollPane(infoList);
	private CPanel infoSouthPanel = new CPanel();
	private CText infoHeader = new CText(4,15);
	private CText infoDetail = new CText(4,35);
	private CText infoArea = new CText();
	private BorderLayout infoSouthLayout = new BorderLayout();
	private StatusBar statusBar = new StatusBar();
	private ConfirmPanel confirm = new ConfirmPanel(true);
	private JSlider debugLevel = new JSlider();
	private CLabel debugLabel = new CLabel();
	private CCheckBox autoLogin = new CCheckBox();
	private CCheckBox storePassword = new CCheckBox();
	private CCheckBox showTrl = new CCheckBox();
	private CCheckBox showAcct = new CCheckBox();
	private CButton uiTheme = new CButton();
	private CLabel lPrinter = new CLabel();
	private CPrinter fPrinter = new CPrinter();
	private CLabel lDate = new CLabel();
	private VDate fDate = new VDate();
	private CCheckBox serverObjects = new CCheckBox();

	/**
	 *	Static Init.
	 *  <pre>
	 *  - panel
	 *      - tabPane
	 *          - customize
	 *              - infoArea
	 *              - fields ...
	 *          - info
	 *              - infoList
	 *              - infoSouthPanel
	 *                  - infoHeader
	 *                  - infoDetail
	 *      - southPanel
	 *  </pre>
	 *  @throws Exception
	 */
	void jbInit() throws Exception
	{
		CompiereColor.setBackground(this);
		debugLabel.setRequestFocusEnabled(false);
		debugLabel.setText(Msg.getMsg(Env.getCtx(), "DebugLevel"));
		debugLevel.setMinorTickSpacing(1);
		debugLevel.setMajorTickSpacing(2);
		debugLevel.setPaintLabels(true);
		debugLevel.setValue(5);
		debugLevel.setPaintTicks(true);
		debugLevel.setMaximum(10);
		debugLevel.setSnapToTicks(true);
		debugLevel.setOpaque(false);

		uiTheme.setText(Msg.getMsg(Env.getCtx(), "UITheme", true));
		uiTheme.setToolTipText(Msg.getMsg(Env.getCtx(), "UITheme", false));
		autoCommit.setText(Msg.getMsg(Env.getCtx(), "AutoCommit", true));
		autoCommit.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoCommit", false));
		printPreview.setText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", true));
		printPreview.setToolTipText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", false));
		autoLogin.setText(Msg.getMsg(Env.getCtx(), "AutoLogin", true));
		autoLogin.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoLogin", false));
		storePassword.setText(Msg.getMsg(Env.getCtx(), "StorePassword", true));
		storePassword.setToolTipText(Msg.getMsg(Env.getCtx(), "StorePassword", false));
		showTrl.setText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", true));
		showTrl.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", false));
		showAcct.setText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", true));
		showAcct.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", false));
		serverObjects.setText(Msg.getMsg(Env.getCtx(), "ServerObjects", true));
		serverObjects.setToolTipText(Msg.getMsg(Env.getCtx(), "ServerObjects", false));
		lPrinter.setText(Msg.getMsg(Env.getCtx(), "Printer"));
		lDate.setText(Msg.getMsg(Env.getCtx(), "Date"));
		infoArea.setReadWrite(false);
		getContentPane().add(panel);
		panel.setLayout(panelLayout);
		panel.add(tabPane, BorderLayout.CENTER);
		//	Customize
//		tabPane.add(customize,  Msg.getMsg(Env.getCtx(), "Preference"));
		tabPane.add(customize,  Msg.getMsg(Env.getCtx(), "Preference"));
		customize.setLayout(customizeLayout);
		customize.add(infoArea,         new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0
			,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(uiTheme,    new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

		customize.add(autoCommit,     new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(autoLogin,      new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(storePassword,     new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(showAcct,     new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(showTrl,   new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(serverObjects,    new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(printPreview,    new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));

		customize.add(debugLevel,      new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(debugLabel,    new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
			,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
		customize.add(lPrinter,     new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(fPrinter,         new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(lDate,       new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
			,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		customize.add(fDate,        new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0
			,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
		//	Info
//		tabPane.add(info,  Msg.getMsg(Env.getCtx(), "Info"));
		tabPane.add(info,  Msg.getMsg(Env.getCtx(), "Info"));
		info.setLayout(infoLayout);
		info.add(infoListScrollPane, BorderLayout.CENTER);
		infoListScrollPane.setPreferredSize(new Dimension(200, 300));
		infoList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		infoList.setBackground(CompierePLAF.getFieldBackground_Inactive());
		infoList.addListSelectionListener(this);
		info.add(infoSouthPanel, BorderLayout.SOUTH);
		infoSouthPanel.setLayout(infoSouthLayout);
		infoSouthPanel.add(infoHeader, BorderLayout.WEST);
		infoHeader.setBackground(SystemColor.info);
		infoHeader.setReadWrite(false);
		infoHeader.setLineWrap(true);
		infoHeader.setWrapStyleWord(true);
		infoHeader.setBorder(BorderFactory.createLoweredBevelBorder());
		infoSouthPanel.add(infoDetail, BorderLayout.CENTER);
		infoDetail.setBackground(SystemColor.info);
		infoDetail.setReadWrite(false);
		infoDetail.setLineWrap(true);
		infoDetail.setWrapStyleWord(true);
		infoDetail.setBorder(BorderFactory.createLoweredBevelBorder());
		//	South
		panel.add(southPanel, BorderLayout.SOUTH);
		southPanel.setLayout(southLayout);
		southPanel.add(statusBar, BorderLayout.SOUTH);
		southPanel.add(confirm, BorderLayout.CENTER);
		//
		confirm.addActionListener(this);
	}	//	jbInit


	/**
	 *	List Selection Listener - show info in header/detail fields
	 *  @param e evant
	 */
	public void valueChanged(ListSelectionEvent e)
	{
		if (e.getValueIsAdjusting())
			return;

		String value = (String)infoList.getSelectedValue();
		if (value == null)
			return;
		int pos = value.indexOf("==");
		if (pos == -1)
		{
			infoHeader.setText("");
			infoDetail.setText(value);
		}
		else
		{
			infoHeader.setText(value.substring(0, pos).replace('|','\n'));
			infoDetail.setText(value.substring(pos+3));
		}
	}	//	valueChanged


	/**
	 *	ActionListener
	 *  @param e event
	 */
	public void actionPerformed(ActionEvent e)
	{
		//	UI Change
		if (e.getSource() == uiTheme)
			new CompierePLAFEditor(this, false);
		else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
			dispose();
		else if (e.getActionCommand().equals(ConfirmPanel.A_OK))
			save();
	}	//	actionPerformed


	/**
	 *	Load Settings - and Context
	 */
	private void load()
	{
		Log.trace(Log.l3_Util, "Preference.load");
		infoArea.setText(AboutBox.getInfo());
		infoArea.setCaretPosition(0);

		//	--	Load Settings	--
		//	UI
		uiTheme.addActionListener(this);
		//	AutoCommit
		autoCommit.setSelected(Env.isAutoCommit(Env.getCtx()));
		//	AutoLogin
		autoLogin.setSelected(Ini.getPropertyBool(Ini.P_A_LOGIN));
		//	Save Password
		storePassword.setSelected(Ini.getPropertyBool(Ini.P_STORE_PWD));
		//	Show Acct Tab
		showAcct.setSelected(Ini.getPropertyBool(Ini.P_SHOW_ACCT));
		//	Show Trl Tab
		showTrl.setSelected(Ini.getPropertyBool(Ini.P_SHOW_TRL));
		//  Server Objects
		serverObjects.setSelected(Ini.getPropertyBool(Ini.P_OBJECTS));
		//  Print Preview
		printPreview.setSelected(Ini.getPropertyBool(Ini.P_PRINTPREVIEW));

		//	DebugLevel
		debugLevel.setValue(Log.getTraceLevel());
		//  Printer
		fPrinter.setValue(Env.getContext(Env.getCtx(), "#Printer"));
		//  Date
		fDate.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));

		//	--	Load and sort Context	--
		String[] context = Env.getEntireContext(Env.getCtx());
		Arrays.sort(context);
		infoList.setListData(context);
	}	//	load

	/**
	 *	Save Settings
	 */
	private void save()
	{
		Log.trace(Log.l3_Util, "Preference.save");
		//  UI
		//	AutoCommit
		Ini.setProperty(Ini.P_A_COMMIT, (autoCommit.isSelected()));
		Env.setAutoCommit(Env.getCtx(), autoCommit.isSelected());
		//	AutoLogin
		Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected()));
		//	Save Password
		Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected()));
		//	Show Acct Tab
		Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected()));
		Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected()));
		//	Show Trl Tab
		Ini.setProperty(Ini.P_SHOW_TRL, (showTrl.isSelected()));
		Env.setContext(Env.getCtx(), "#ShowTrl", (showTrl.isSelected()));
		//  Server Objects
		Ini.setProperty(Ini.P_OBJECTS, (serverObjects.isSelected()));
		//  Print Preview
		Ini.setProperty(Ini.P_PRINTPREVIEW, (printPreview.isSelected()));
		//	DebugLevel
		Log.setTraceLevel(debugLevel.getValue());
		Ini.setProperty(Ini.P_DEBUGLEVEL, String.valueOf(debugLevel.getValue()));
		//  Printer
		String printer = (String)fPrinter.getSelectedItem();
		Env.setContext(Env.getCtx(), "#Printer", printer);
		Ini.setProperty(Ini.P_PRINTER, printer);
		//  Date (remove seconds)
		java.sql.Timestamp ts = (java.sql.Timestamp)fDate.getValue();
		if (ts != null)
		{
			java.sql.Date sd = new java.sql.Date(ts.getTime());
			Env.setContext(Env.getCtx(), "#Date", sd.toString());	//	YYYY-MM-DD
		}

		Ini.saveProperties(true);
		if (!Ini.isClient())
			Ini.saveProperties(false);

		dispose();
	}	//	save

}	//	Preference

⌨️ 快捷键说明

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