📄 printelement.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.print.layout;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.*;
import org.compiere.print.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* Print Element
*
* @author Jorg Janke
* @version $Id: PrintElement.java,v 1.9 2003/03/21 02:38:31 jjanke Exp $
*/
public abstract class PrintElement implements ImageObserver
{
/**
* Constructor
*/
protected PrintElement ()
{
} // PrintElement
/** Link Color */
public static final Color LINK_COLOR = Color.blue;
/** Calculated Size of Element */
protected float p_width = 0f;
protected float p_height = 0f;
protected boolean p_sizeCalculated = false;
/** Max Size of Element */
protected float p_maxWidth = 0f;
protected float p_maxHeight = 0f;
/** Field Align Type */
protected String p_FieldAlignmentType;
/** Location on Page */
protected Point2D.Double p_pageLocation = null;
/*************************************************************************/
/**
* Get Calculated Width
* @return Width
*/
public float getWidth()
{
if (!p_sizeCalculated)
p_sizeCalculated = calculateSize();
return p_width;
} // getWidth
/**
* Get Calculated Height
* @return Height
*/
public float getHeight()
{
if (!p_sizeCalculated)
p_sizeCalculated = calculateSize();
return p_height;
} // getHeight
/**
* Get Calculated Height on page
* @param pageNo page number
* @return Height
*/
public float getHeight (int pageNo)
{
return getHeight();
} // getHeight
/**
* Get number of pages
* @return page count (1)
*/
public int getPageCount()
{
return 1;
} // getPageCount
/**
* Layout and Calculate Size
* Set p_width & p_height
* @return true if calculated
*/
protected abstract boolean calculateSize();
/**
* Layout Element
* @param maxWidth max width
* @param maxHeight max height
* @param isHeightOneLine just one line
* @param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
*/
public void layout (float maxWidth, float maxHeight, boolean isHeightOneLine,
String FieldAlignmentType)
{
if (isHeightOneLine)
p_maxHeight = -1f;
else if (maxHeight > 0f)
p_maxHeight = maxHeight;
p_maxWidth = maxWidth;
//
p_FieldAlignmentType = FieldAlignmentType;
if (p_FieldAlignmentType == null || p_FieldAlignmentType == MPrintFormatItem.FIELD_ALIGN_DEFAULT)
p_FieldAlignmentType = MPrintFormatItem.FIELD_ALIGN_LEADING;
//
p_sizeCalculated = calculateSize();
} // layout
/**
* Set Maximum Height
* @param maxHeight maximum height (0) is no limit
*/
public void setMaxHeight (float maxHeight)
{
p_maxHeight = maxHeight;
} // setMaxHeight
/**
* Set Maximum Width
* @param maxWidth maximum width (0) is no limit
*/
public void setMaxWidth (float maxWidth)
{
p_maxWidth = maxWidth;
} // setMaxWidth
/**
* Set Location within page
* @param pageLocation location within page
*/
public void setLocation (Point2D pageLocation)
{
p_pageLocation = new Point2D.Double(pageLocation.getX(), pageLocation.getY());
} // setLocation
/**
* Get Location within page
* @return location within page
*/
public Point2D getLocation()
{
return p_pageLocation;
} // getLocation
/**
* Return Absolute Position
* @param pageStart start of page
* @return absolite position
*/
protected Point2D.Double getAbsoluteLocation(Point2D pageStart)
{
Point2D.Double retValue = new Point2D.Double(
p_pageLocation.x + pageStart.getX(), p_pageLocation.y + pageStart.getY());
// Log.trace(9, "PrintElement.getAbsoluteLocation", "PageStart=" + pageStart.getX() + "/" + pageStart.getY()
// + ",PageLocaton=" + p_pageLocation.x + "/" + p_pageLocation.y + " => " + retValue.x + "/" + retValue.y);
return retValue;
} // getAbsoluteLocation
/**
* Get relative Bounds of Element
* @return bounds relative position on page
*/
public Rectangle getBounds()
{
if (p_pageLocation == null)
return new Rectangle (0,0, (int)p_width, (int)p_height);
return new Rectangle ((int)p_pageLocation.x, (int)p_pageLocation.y, (int)p_width, (int)p_height);
} // getBounds
/**
* Get Drill Down value
* @param relativePoint relative Point
* @param pageNo page number
* @return null (subclasses overwrite)
*/
public MQuery getDrillDown (Point relativePoint, int pageNo)
{
return null;
} // getDrillDown
/**
* Get Drill Across value
* @param relativePoint relative Point
* @param pageNo page number
* @return null (subclasses overwrite)
*/
public MQuery getDrillAcross (Point relativePoint, int pageNo)
{
return null;
} // getDrillAcross
/*************************************************************************/
/**
* Translate Context if required.
* If content is translated, the element needs to stay in the bounds
* of the originally calculated size and need to align the field.
* @param ctx context
*/
public void translate (Properties ctx)
{
// noop
} // translate
/**
* Content is translated
* @return false
*/
public boolean isTranslated()
{
return false;
} // translate
/*************************************************************************/
/**
* Paint/Print.
* @param g2D Graphics
* @param pageNo page number for multi page support (0 = header/footer)
* @param pageStart top left Location of page
* @param ctx context
* @param isView true if online view (IDs are links)
*/
public abstract void paint (Graphics2D g2D, int pageNo, Point2D pageStart, Properties ctx, boolean isView);
/*************************************************************************/
/**
* Image Observer
* @param img image
* @param infoflags Observer flags
* @param x x coordinate
* @param y y coordinate
* @param width image width
* @param height image height
* @return false if the infoflags indicate that the image is completely loaded; true otherwise
*/
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
{
// copied from java.awt.component
boolean imageNotLoaded = (infoflags & (ALLBITS|ABORT)) == 0;
// Log.trace(Log.l6_Database, "PrintElement.imageUpdate - Flags=" + infoflags
// + ", x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + " => " + m_imageNotLoaded);
return imageNotLoaded;
} // imageUpdate
/**
* Wait until Image is loaded.
* @param image image
*/
public void waitForLoad (Image image)
{
long start = System.currentTimeMillis();
int count = 0;
while (!Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, this))
{
try
{
Thread.sleep(1);
}
catch (InterruptedException ex)
{
Log.error("PrintElement.waitForLoad", ex);
break;
}
count++;
}
if (count > 0)
Log.trace(Log.l6_Database, "PrintElement.waitForLoad - " + (System.currentTimeMillis()-start) + "ms - #" + count);
} // waitForLoad
/**
* String Representation
* @return info
*/
public String toString()
{
String cn = getClass().getName();
StringBuffer sb = new StringBuffer();
sb.append(cn.substring(cn.lastIndexOf('.')+1)).append("[");
sb.append("Bounds=").append(getBounds())
.append(",Height=").append(p_height).append("(").append(p_maxHeight)
.append("),Width=").append(p_width).append("(").append(p_maxHeight)
.append("),PageLocation=").append(p_pageLocation);
sb.append("]");
return sb.toString();
} // toString
} // PrintElement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -