📄 adialog.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 javax.swing.*;
import java.awt.event.*;
import java.util.*;
import org.compiere.util.*;
/**
* Info Dialog Management
*
* @author Jorg Janke
* @version $Id: ADialog.java,v 1.11 2002/08/12 04:52:53 jjanke Exp $
*/
public final class ADialog
{
/** Show ADialogADialog - if false use JOptionPane */
public static boolean showDialog = true;
/**
* Show plain message
* @param WindowNo Number of Window
* @param c Container (owner)
* @param clearHeading Translated Title of window
* @param clearMessage Translated message
* @param clearText Additional message
*/
public static void info (int WindowNo, Container c, String clearHeading, String clearMessage, String clearText)
{
Log.trace(Log.l1_User, "Dialog.info: " + clearHeading,
clearMessage + " " + clearText);
String out = clearMessage;
if (clearText != null && !clearText.equals(""))
out += "\n" + clearText;
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
//
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
new ADialogDialog ((JFrame)parent,
clearHeading,
out,
JOptionPane.INFORMATION_MESSAGE);
else
new ADialogDialog ((JDialog)parent,
clearHeading,
out,
JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(parent,
out + "\n", // message
clearHeading, // title
JOptionPane.INFORMATION_MESSAGE);
} // info
/**
* Show message with info icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
* @param msg Additional message
*/
public static void info (int WindowNo, Container c, String AD_Message, String msg)
{
Log.trace(Log.l1_User, "Dialog.info: " + AD_Message, msg);
Properties ctx = Env.getCtx();
StringBuffer out = new StringBuffer();
if (AD_Message != null && !AD_Message.equals(""))
out.append(Msg.getMsg(ctx, AD_Message));
if (msg != null && msg.length() > 0)
out.append("\n").append(msg);
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
//
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
new ADialogDialog ((JFrame)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.INFORMATION_MESSAGE);
else
new ADialogDialog ((JDialog)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(parent,
out.toString() + "\n", // message
Env.getHeader(ctx, WindowNo), // title
JOptionPane.INFORMATION_MESSAGE);
} // info
/**
* Show message with info icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
*/
public static void info (int WindowNo, Container c, String AD_Message)
{
info (WindowNo, c, AD_Message, null);
} // info
/*************************************************************************/
/**
* Display warning with warning icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
* @param msg Additional message
*/
public static void warn (int WindowNo, Container c, String AD_Message, String msg)
{
Log.trace(Log.l1_User, "Dialog.warn: " + AD_Message, msg);
Properties ctx = Env.getCtx();
StringBuffer out = new StringBuffer();
if (AD_Message != null && !AD_Message.equals(""))
out.append(Msg.getMsg(ctx, AD_Message));
if (msg != null && msg.length() > 0)
out.append("\n").append(msg);
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
//
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
new ADialogDialog ((JFrame)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.WARNING_MESSAGE);
else
new ADialogDialog ((JDialog)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.WARNING_MESSAGE);
}
else
JOptionPane.showMessageDialog(parent,
out.toString() + "\n", // message
Env.getHeader(ctx, WindowNo), // title
JOptionPane.WARNING_MESSAGE);
} // warn (int, String)
/**
* Display warning with warning icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
*/
public static void warn (int WindowNo, Container c, String AD_Message)
{
warn (WindowNo, c, AD_Message, null);
} // warn (int, String)
/*************************************************************************/
/**
* Display error with error icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
* @param msg Additional message
*/
public static void error (int WindowNo, Container c, String AD_Message, String msg)
{
Log.trace(Log.l1_User, "Dialog.error: " + AD_Message, msg);
Properties ctx = Env.getCtx();
StringBuffer out = new StringBuffer();
if (AD_Message != null && !AD_Message.equals(""))
out.append(Msg.getMsg(ctx, AD_Message));
if (msg != null && msg.length() > 0)
out.append("\n").append(msg);
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
//
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
new ADialogDialog ((JFrame)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.ERROR_MESSAGE);
else if (parent instanceof JDialog)
new ADialogDialog ((JDialog)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(Env.getWindow(WindowNo),
out.toString() + "\n", // message
Env.getHeader(ctx, WindowNo), // title
JOptionPane.ERROR_MESSAGE);
} // error (int, String)
/**
* Display error with error icon
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
*/
public static void error (int WindowNo, Container c, String AD_Message)
{
error (WindowNo, c, AD_Message, null);
} // error (int, String)
/*************************************************************************/
/**
* Ask Question with question icon and (OK) (Cancel) buttons
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
* @param msg Additional clear text message
* @returns true, if OK
*/
public static boolean ask (int WindowNo, Container c, String AD_Message, String msg)
{
Log.trace(Log.l1_User, "Dialog.ask: " + AD_Message, msg);
Properties ctx = Env.getCtx();
StringBuffer out = new StringBuffer();
if (AD_Message != null && !AD_Message.equals(""))
out.append(Msg.getMsg(ctx, AD_Message));
if (msg != null && msg.length() > 0)
out.append("\n").append(msg);
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
boolean retValue = false;
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
{
ADialogDialog d = new ADialogDialog ((JFrame)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.QUESTION_MESSAGE);
retValue = d.getReturnCode() == ADialogDialog.A_OK;
}
else
{
ADialogDialog d = new ADialogDialog ((JDialog)parent,
Env.getHeader(ctx, WindowNo),
out.toString(),
JOptionPane.QUESTION_MESSAGE);
retValue = d.getReturnCode() == ADialogDialog.A_OK;
}
}
else
{
Object[] optionsOC = {Msg.getMsg(ctx, "OK"), Msg.getMsg(ctx, "Cancel")};
int i = JOptionPane.showOptionDialog(parent,
out.toString() + "\n", // message
Env.getHeader(ctx, WindowNo), // title
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
optionsOC,
optionsOC[0]);
retValue = i == 0;
}
return retValue;
} // ask
/**
* Ask Question with question icon and (OK) (Cancel) buttons
* @param WindowNo Number of Window
* @param c Container (owner)
* @param AD_Message Message to be translated
* @returns true, if OK
*/
public static boolean ask (int WindowNo, Container c, String AD_Message)
{
return ask (WindowNo, c, AD_Message, null);
} // ask
/*************************************************************************/
/**
* Display parsed development info Message string
* @param WindowNo Number of parent window (if zero, no parent window)
* @param c Container (owner)
* @param ParseString String to be parsed
*/
public static void clear (int WindowNo, Container c, String ParseString)
{
Log.trace(Log.l1_User, "Dialog.clear: " + ParseString);
Properties ctx = Env.getCtx();
String parse = Env.parseContext(ctx, WindowNo, ParseString, false);
if (parse.length() == 0)
parse = "ERROR parsing: " + ParseString;
//
Window parent = Env.getParent(c);
if (parent == null)
parent = Env.getWindow(WindowNo);
//
if (showDialog && parent != null)
{
if (parent instanceof JFrame)
new ADialogDialog ((JFrame)parent,
Env.getHeader(ctx, WindowNo),
"=> " + parse,
JOptionPane.INFORMATION_MESSAGE);
else
new ADialogDialog ((JDialog)parent,
Env.getHeader(ctx, WindowNo),
"=> " + parse,
JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(parent,
"=> " + parse + "\n", // message
Env.getHeader(ctx, WindowNo), // title
JOptionPane.INFORMATION_MESSAGE);
} // clear
/**
* Display parsed development info Message string <x> if condition is true
* @param WindowNo Number of parent window (if zero, no parent window)
* @param c Container (owner)
* @param ParseString Parsed Message
* @param condition to print must be true and debugging enabled
*/
public static void clear (int WindowNo, Container c, String ParseString, boolean condition)
{
if (!condition || Log.getTraceLevel() < 1)
return;
clear(WindowNo, c, ParseString);
if (WindowNo == 0)
Log.error("WIndowNo == 0");
} // clear
/**
* Display parsed development info Message string
* @param ParseString String to be parsed
* @deprecated
*/
public static void clear (String ParseString)
{
clear(0, null, ParseString);
} // clear
/*************************************************************************/
/**
* Beep
*/
public static void beep()
{
Toolkit.getDefaultToolkit().beep();
} // beep
} // Dialog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -