📄 mprintpaper.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-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.print;
import java.util.*;
import javax.print.attribute.standard.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* AD_PrintPaper Print Paper Model
*
* @author Jorg Janke
* @version $Id: MPrintPaper.java,v 1.9 2002/11/11 07:03:01 jjanke Exp $
*/
public class MPrintPaper extends PO
{
/**
* Constructor
* @param ctx context
* @param AD_PrintPaper_ID ID if 0 A4
*/
private MPrintPaper(Properties ctx, int AD_PrintPaper_ID)
{
super(ctx, AD_PrintPaper_ID);
if (AD_PrintPaper_ID == 0)
{
setDefault (false);
setLandscape (true);
setCode ("iso-a4");
setMarginTop (36);
setMarginBottom (36);
setMarginLeft (36);
setMarginRight (36);
}
} // MPrintPaper
/**
* Initialize and return PO_Info
* @param ctx context
* @return POInfo
*/
protected POInfo initPO (java.util.Properties ctx)
{
int AD_Table_ID = 492;
return POInfo.getPOInfo (ctx, AD_Table_ID);
} // initPO
/*************************************************************************/
/**
* Set Name
* @param name name
*/
public void setName (String name)
{
setValue("Name", name);
} // setName
/**
* Get Name
* @return name
*/
public String getName()
{
return (String)getValue("Name");
} // getName
/**
* Set Default
* @param newDefault default
*/
public void setDefault (boolean newDefault)
{
setValue("IsDefault", new Boolean(newDefault));
} // setDefault
/**
* Get Default
* @return true if default
*/
public boolean isDefault()
{
return ((Boolean)getValue("IsDefault")).booleanValue();
} // isDefault
/**
* Set Default
* @param landscape default
*/
public void setLandscape (boolean landscape)
{
setValue("IsLandscape", new Boolean(landscape));
} // setLandscape
/**
* Get Default
* @return true if default
*/
public boolean isLandscape()
{
Boolean bb = (Boolean)getValue("IsLandscape");
if (bb != null)
return bb.booleanValue();
return true;
} // isLandscape
/**
* Get Code
* @return Code (MediaSizeName)
*/
public String getCode()
{
return (String)getValue("Code");
} // getCode
/**
* Set Code
* @param code (MediaSizeName)
*/
public void setCode (String code)
{
setValue("Code", code);
} // getCode
/*************************************************************************/
/**
* Get Top Margin
* @return Top Margin
*/
public int getMarginTop()
{
return ((Integer)getValue("MarginTop")).intValue();
} // getMarginTop
/**
* Set Top Margin
* @param marginTop Top Margin
*/
public void setMarginTop (int marginTop)
{
setValue ("MarginTop", new Integer(marginTop));
} // setMarginTop
/**
* Get Left Margin
* @return Left Margin
*/
public int getMarginLeft()
{
return ((Integer)getValue("MarginLeft")).intValue();
} // getMarginLeft
/**
* Set Left Margin
* @param marginLeft Left Margin
*/
public void setMarginLeft (int marginLeft)
{
setValue ("MarginLeft", new Integer(marginLeft));
} // setMarginLeft
/**
* Get Right Margin
* @return Right Margin
*/
public int getMarginRight()
{
return ((Integer)getValue("MarginRight")).intValue();
} // getMarginRight
/**
* Set Right Margin
* @param marginRight Right Margin
*/
public void setMarginRight (int marginRight)
{
setValue ("MarginRight", new Integer(marginRight));
} // setMarginRight
/**
* Get Bottom Margin
* @return Bottom Margin
*/
public int getMarginBottom()
{
return ((Integer)getValue("MarginBottom")).intValue();
} // getMarginBottom
/**
* Set Bottom Margin
* @param marginBottom Bottom Margin
*/
public void setMarginBottom (int marginBottom)
{
setValue ("MarginBottom", new Integer(marginBottom));
} // setMarginBottom
/*************************************************************************/
/**
* Get Media Size.
* The search is hard coded as the javax.print.MediaSize* info is private
* @return MediaSize from Code
*/
public MediaSize getMediaSize()
{
String nameCode = getCode();
if (nameCode == null)
return getMediaSizeDefault();
// Get Name
MediaSizeName nameMedia = null;
if (nameCode.equals("iso-a4"))
nameMedia = MediaSizeName.ISO_A4;
else if (nameCode.equals("na-letter"))
nameMedia = MediaSizeName.NA_LETTER;
// other media sizes come here
if (nameMedia == null)
return getMediaSizeDefault();
//
MediaSize retValue = MediaSize.getMediaSizeForName(nameMedia);
if (retValue == null)
retValue = getMediaSizeDefault();
// Log.trace(Log.l6_Database, "MPrintPaper.getMediaSize", retValue);
return retValue;
} // getMediaSize
/**
* Get Media Size
* @return Default Media Size based on Language
*/
public MediaSize getMediaSizeDefault()
{
MediaSize retValue = Language.getLanguage().getMediaSize();
if (retValue == null)
retValue = MediaSize.ISO.A4;
Log.trace(Log.l6_Database, "MPrintPaper.getMediaSizeDefault", retValue);
return retValue;
} // getMediaSizeDefault
/**
* Get CPaper
* @return CPaper
*/
public CPaper getCPaper()
{
CPaper retValue = new CPaper (getMediaSize(), isLandscape(),
getMarginLeft(), getMarginTop(), getMarginRight(), getMarginBottom());
return retValue;
} // getCPaper
/*************************************************************************/
/**
* Create Paper and save
* @param name name
* @param landscape landscape
* @return Paper
*/
static MPrintPaper create (String name, boolean landscape)
{
MPrintPaper pp = new MPrintPaper (Env.getCtx(), 0);
pp.setName(name);
pp.setLandscape(landscape);
pp.save();
return pp;
} // create
/*************************************************************************/
/** Cached Fonts */
static private HashMap s_papers = new HashMap();
/**
* Get Paper
* @param AD_PrintPaper_ID id
* @return Paper
*/
static public MPrintPaper get (int AD_PrintPaper_ID)
{
Integer key = new Integer(AD_PrintPaper_ID);
MPrintPaper pp = (MPrintPaper)s_papers.get(key);
if (pp == null)
{
pp = new MPrintPaper (Env.getCtx(), AD_PrintPaper_ID);
s_papers.put(key, pp);
}
else
Log.trace(Log.l4_Data, "MPrintPaper.get", "AD_PrintPaper_ID=" + AD_PrintPaper_ID);
return pp;
} // get
/*************************************************************************/
/**
* Test
* @param args args
*/
public static void main(String[] args)
{
org.compiere.Compiere.startupClient();
// create ("Standard Landscape", true);
// create ("Standard Portrait", false);
// Read All Colors
int[] IDs = PO.getAllIDs ("AD_PrintPaper", null);
for (int i = 0; i < IDs.length; i++)
{
System.out.println("--");
MPrintPaper pp = new MPrintPaper(Env.getCtx(), IDs[i]);
pp.dump();
}
}
} // MPrintPaper
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -