📄 aenv.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.apps;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.rmi.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import org.compiere.db.*;
import org.compiere.interfaces.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Windows Application Environment and utilities
*
* @author Jorg Janke
* @version $Id: AEnv.java,v 1.80 2006/02/12 02:18:25 jjanke Exp $
*/
public final class AEnv
{
/**
* Show in the center of the screen.
* (pack, set location and set visibility)
* @param window Window to position
*/
public static void showCenterScreen(Window window)
{
positionCenterScreen(window);
window.setVisible(true);
window.toFront();
} // showCenterScreen
/**
* Position window in center of the screen
* @param window Window to position
*/
public static void positionCenterScreen(Window window)
{
positionScreen (window, SwingConstants.CENTER);
} // positionCenterScreen
/**
* Show in the center of the screen.
* (pack, set location and set visibility)
* @param window Window to position
* @param position SwingConstants
*/
public static void showScreen(Window window, int position)
{
positionScreen(window, position);
window.setVisible(true);
window.toFront();
} // showScreen
/**
* Position window in center of the screen
* @param window Window to position
* @param position SwingConstants
*/
public static void positionScreen (Window window, int position)
{
window.pack();
Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wSize = window.getSize();
int maxWidth = (int)(sSize.width*.97);
int maxHeight = (int)(sSize.height*.97);
// fit on window
if (wSize.height > maxHeight)
wSize.height = maxHeight;
if (wSize.width > maxWidth)
wSize.width = maxWidth;
window.setSize(wSize);
// Center
int x = (sSize.width - wSize.width) / 2;
int y = (sSize.height - wSize.height) / 2;
if (position == SwingConstants.CENTER)
;
else if (position == SwingConstants.NORTH_WEST)
{
x = 0;
y = 0;
}
else if (position == SwingConstants.NORTH)
{
y = 0;
}
else if (position == SwingConstants.NORTH_EAST)
{
x = (sSize.width - wSize.width);
y = 0;
}
else if (position == SwingConstants.WEST)
{
x = 0;
}
else if (position == SwingConstants.EAST)
{
x = (sSize.width - wSize.width);
}
else if (position == SwingConstants.SOUTH)
{
y = (sSize.height - wSize.height);
}
else if (position == SwingConstants.SOUTH_WEST)
{
x = 0;
y = (sSize.height - wSize.height);
}
else if (position == SwingConstants.SOUTH_EAST)
{
x = (sSize.width - wSize.width);
y = (sSize.height - wSize.height);
}
//
window.setLocation(x, y);
} // positionScreen
/**
* Position in center of the parent window.
* (pack, set location and set visibility)
* @param parent Parent Window
* @param window Window to position
*/
public static void showCenterWindow(Window parent, Window window)
{
positionCenterWindow(parent, window);
window.setVisible(true);
window.toFront();
} // showCenterWindow
/**
* Position in center of the parent window
*
* @param parent Parent Window
* @param window Window to position
*/
public static void positionCenterWindow(Window parent, Window window)
{
if (parent == null)
{
positionCenterScreen(window);
return;
}
window.pack();
//
Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension wSize = window.getSize();
int maxWidth = (int)(sSize.width*.97);
int maxHeight = (int)(sSize.height*.97);
// fit on window
if (wSize.height > maxHeight)
wSize.height = maxHeight;
if (wSize.width > maxWidth)
wSize.width = maxWidth;
window.setSize(wSize);
// center in parent
Rectangle pBounds = parent.getBounds();
// Parent is in upper left corner
if (pBounds.x == pBounds.y && pBounds.x == 0)
{
positionCenterScreen(window);
return;
}
// Find middle
int x = pBounds.x + ((pBounds.width-wSize.width)/2);
if (x < 0)
x = 0;
int y = pBounds.y + ((pBounds.height-wSize.height)/2);
if (y < 0)
y = 0;
// Is it on Screen?
if (x + wSize.width > sSize.width)
x = sSize.width - wSize.width;
if (y + wSize.height > sSize.height)
y = sSize.height - wSize.height;
//
// System.out.println("Position: x=" + x + " y=" + y + " w=" + wSize.getWidth() + " h=" + wSize.getHeight()
// + " - Parent loc x=" + pLoc.x + " y=" + y + " w=" + pSize.getWidth() + " h=" + pSize.getHeight());
window.setLocation(x, y);
} // positionCenterScreen
/*************************************************************************
* Get Button
* @param iconName
* @return button
*/
public static CButton getButton (String iconName)
{
CButton button = new CButton(Env.getImageIcon(iconName + "16.gif"));
button.setMargin(new Insets (0, 0, 0, 0));
button.setToolTipText(Msg.getMsg(Env.getCtx(), iconName));
button.setDefaultCapable(false);
return button;
} // getButton
/**
* Create Menu Title (translate it and set Mnemonics).
* Based on MS notation of &Help => H is Mnemonics
*
* @param AD_Message message
* @return JMenu
*/
public static JMenu getMenu (String AD_Message)
{
JMenu menu = new JMenu();
String text = Msg.getMsg(Env.getCtx(), AD_Message);
int pos = text.indexOf("&");
if (pos != -1 && text.length() > pos) // We have a nemonic
{
char ch = text.toUpperCase().charAt(pos+1);
if (ch != ' ')
{
text = text.substring(0, pos) + text.substring(pos+1);
menu.setMnemonic(ch);
}
}
menu.setText(text);
return menu;
} // getMenu
/**
* Create Menu Item.
* @param actionName action command
* @param iconName optional name of the icon, defaults to action if null
* @param ks optional key stroke
* @param menu menu to add menu item to
* @param al action listener to register
* @return MenuItem
*/
public static JMenuItem addMenuItem (String actionName, String iconName, KeyStroke ks,
JMenu menu, ActionListener al)
{
if (iconName == null)
iconName = actionName;
String text = Msg.getMsg(Env.getCtx(), actionName);
CMenuItem mi = new CMenuItem(text, Env.getImageIcon(iconName + "16.gif"));
mi.setActionCommand(actionName);
if (ks != null)
mi.setAccelerator(ks);
if (menu != null)
menu.add(mi);
if (al != null)
mi.addActionListener(al);
return mi;
} // addMeniItem
/**
* Perform action command for common menu items.
* Created in AMenu.createMenu(), APanel.createMenu(), FormFrame.createMenu()
* @param actionCommand known action command
* @param WindowNo window no
* @param c Container parent
* @return true if actionCommand was found and performed
*/
public static boolean actionPerformed (String actionCommand, int WindowNo, Container c)
{
MRole role = MRole.getDefault();
// File Menu ------------------------
if (actionCommand.equals("PrintScreen"))
{
PrintScreenPainter.printScreen (Env.getFrame(c));
}
else if (actionCommand.equals("ScreenShot"))
{
ScreenShot.createJPEG(Env.getFrame(c), null);
}
// else if (actionCommand.equals("Report"))
// {
// AEnv.showCenterScreen (new ProcessStart());
// }
else if (actionCommand.equals("Exit"))
{
if (ADialog.ask(WindowNo, c, "ExitApplication?"))
Env.exitEnv(0);
}
// View Menu ------------------------
else if (actionCommand.equals("InfoProduct"))
{
org.compiere.apps.search.Info.showProduct (Env.getFrame(c), WindowNo);
}
else if (actionCommand.equals("InfoBPartner"))
{
org.compiere.apps.search.Info.showBPartner (Env.getFrame(c), WindowNo);
}
else if (actionCommand.equals("InfoAsset"))
{
org.compiere.apps.search.Info.showAsset (Env.getFrame(c), WindowNo);
}
else if (actionCommand.equals("InfoAccount") && MRole.getDefault().isShowAcct())
{
new org.compiere.acct.AcctViewer();
}
else if (actionCommand.equals("InfoSchedule"))
{
new org.compiere.apps.search.InfoSchedule (Env.getFrame(c), null, false);
}
else if (actionCommand.equals("InfoOrder"))
{
org.compiere.apps.search.Info.showOrder (Env.getFrame(c), WindowNo, "");
}
else if (actionCommand.equals("InfoInvoice"))
{
org.compiere.apps.search.Info.showInvoice (Env.getFrame(c), WindowNo, "");
}
else if (actionCommand.equals("InfoInOut"))
{
org.compiere.apps.search.Info.showInOut (Env.getFrame(c), WindowNo, "");
}
else if (actionCommand.equals("InfoPayment"))
{
org.compiere.apps.search.Info.showPayment (Env.getFrame(c), WindowNo, "");
}
else if (actionCommand.equals("InfoCashLine"))
{
org.compiere.apps.search.Info.showCashLine (Env.getFrame(c), WindowNo, "");
}
else if (actionCommand.equals("InfoAssignment"))
{
org.compiere.apps.search.Info.showAssignment (Env.getFrame(c), WindowNo, "");
}
// Go Menu ------------------------
else if (actionCommand.equals("WorkFlow"))
{
startWorkflowProcess(0,0);
}
else if (actionCommand.equals("Home"))
{
Env.getWindow(0).toFront();
}
// Tools Menu ------------------------
else if (actionCommand.equals("Calculator"))
{
AEnv.showCenterScreen (new org.compiere.grid.ed.Calculator(Env.getFrame(c)));
}
else if (actionCommand.equals("Calendar"))
{
AEnv.showCenterScreen (new org.compiere.grid.ed.Calendar(Env.getFrame(c)));
}
else if (actionCommand.equals("Editor"))
{
AEnv.showCenterScreen (new org.compiere.grid.ed.Editor(Env.getFrame(c)));
}
else if (actionCommand.equals("Script"))
{
new ScriptEditor();
}
else if (actionCommand.equals("Preference"))
{
if (role.isShowPreference())
AEnv.showCenterScreen(new Preference (Env.getFrame(c), WindowNo));
}
// Help Menu ------------------------
else if (actionCommand.equals("Online"))
{
Env.startBrowser(org.compiere.Compiere.getURL());
}
else if (actionCommand.equals("EMailSupport"))
{
ADialog.createSupportEMail(Env.getFrame(c), Env.getFrame(c).getTitle(), "\n\n");
}
else if (actionCommand.equals("About"))
{
AEnv.showCenterScreen(new AboutBox(Env.getFrame(c)));
}
else
return false;
//
return true;
} // actionPerformed
/**
* Set Text and Mnemonic for Button.
* Create Mnemonics of text containing "&".
* Based on MS notation of &Help => H is Mnemonics
* @param b The button
* @param text The text with optional Mnemonics
*/
public static void setTextMnemonic (JButton b, String text)
{
if (text == null || b == null)
return;
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic
{
char ch = text.charAt(pos+1);
b.setMnemonic(ch);
b.setText(text.substring(0, pos) + text.substring(pos+1));
}
b.setText(text);
} // setTextMnemonic
/**
* Get Mnemonic character from text.
* @param text text with "&"
* @return Mnemonic or 0
*/
public static char getMnemonic (String text)
{
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic
return text.charAt(pos+1);
return 0;
} // getMnemonic
/*************************************************************************
* Zoom
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -