1 14 package org.compiere.print; 15 16 import java.awt.*; 17 import java.awt.print.*; 18 import java.util.*; 19 import javax.swing.*; 20 import javax.print.attribute.*; 21 22 import org.compiere.swing.*; 23 import org.compiere.util.*; 24 import org.compiere.model.*; 25 import org.compiere.print.layout.*; 26 27 33 public class View extends CPanel 34 { 35 39 public View (LayoutEngine layout) 40 { 41 m_layout = layout; 42 } 44 45 private LayoutEngine m_layout; 46 47 48 49 private int m_zoomLevel = 0; 50 51 public static final String [] ZOOM_OPTIONS = new String [] 52 {"100%", "75%", "50%"}; 53 54 public static int MARGIN = 5; 55 56 private static Color COLOR_BACKGROUND = Color.lightGray; 57 58 59 60 61 65 public Dimension getMinimumSize() 66 { 67 return getMaximumSize(); 68 } 70 74 public Dimension getMaximumSize() 75 { 76 return new Dimension (getPaperWidth()+(2*MARGIN), 77 (getPaperHeight()+MARGIN)*getPageCount()+MARGIN); 78 } 80 84 public Dimension getPreferredSize() 85 { 86 return getMaximumSize(); 87 } 89 90 94 public void paintComponent (Graphics g) 95 { 96 Graphics2D g2D = (Graphics2D)g; 98 Rectangle bounds = g2D.getClipBounds(); 99 g2D.setColor(COLOR_BACKGROUND); 101 g2D.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); 102 103 for (int page = 0; page < m_layout.getPages().size(); page++) 105 { 106 Rectangle pageRectangle = getRectangleOfPage(page+1); 107 if (bounds.intersects(pageRectangle)) 108 { 109 Page p = (Page)m_layout.getPages().get(page); 110 p.paint (g2D, pageRectangle, true, false); m_layout.getHeaderFooter().paint(g2D, pageRectangle, true); 112 } } } 116 117 118 119 123 public void setZoomLevel(int level) 124 { 125 m_zoomLevel = level; 126 } 128 132 public void setZoomLevel(String levelString) 133 { 134 for (int i = 0; i < ZOOM_OPTIONS.length; i++) 135 { 136 if (ZOOM_OPTIONS[i].equals(levelString)) 137 { 138 m_zoomLevel = i; 139 break; 140 } 141 } 142 } 144 148 public int getZoomLevel() 149 { 150 return m_zoomLevel; 151 } 153 158 public Rectangle getRectangleOfPage(int pageNo) 159 { 160 int y = MARGIN + ((pageNo-1) * (getPaperHeight() + MARGIN)); 161 return new Rectangle (MARGIN, y, getPaperWidth(), getPaperHeight()); 162 } 164 165 170 public float getPageNoAt (Point p) 171 { 172 float y = p.y; 173 float pageHeight = getPaperHeight() + MARGIN; 174 return 1f + (y/pageHeight); 175 } 177 181 public int getPageCount() 182 { 183 return m_layout.getPages().size(); 184 } 186 191 public String getPageInfo(int pageNo) 192 { 193 return m_layout.getPageInfo(pageNo); 194 } 196 200 public String getPageInfoMax() 201 { 202 return m_layout.getPageInfoMax(); 203 } 205 209 public CPaper getPaper() 210 { 211 return m_layout.getPaper(); 212 } 214 218 public int getPaperHeight() 219 { 220 return (int)m_layout.getPaper().getHeight(true); 221 } 223 227 public int getPaperWidth() 228 { 229 return (int)m_layout.getPaper().getWidth(true); 230 } 232 237 public MQuery getDrillDown (Point absolutePoint) 238 { 239 int pageNo = (int)getPageNoAt(absolutePoint); 240 Rectangle pageRectangle = getRectangleOfPage(pageNo); 241 Point relativePoint = new Point (absolutePoint.x-pageRectangle.x, 242 absolutePoint.y-pageRectangle.y); 243 Page page = (Page)m_layout.getPages().get(pageNo-1); 244 Log.trace(Log.l4_Data, "View.getDrillDown", "RelativePoint=" + relativePoint + ", Page=" + page); 246 MQuery retValue = page.getDrillDown (relativePoint); 248 if (retValue == null) 249 retValue = m_layout.getHeaderFooter().getDrillDown (relativePoint); 250 return retValue; 251 } 253 258 public MQuery getDrillAcross (Point absolutePoint) 259 { 260 int pageNo = (int)getPageNoAt(absolutePoint); 261 Rectangle pageRectangle = getRectangleOfPage(pageNo); 262 Point relativePoint = new Point (absolutePoint.x-pageRectangle.x, 263 absolutePoint.y-pageRectangle.y); 264 Page page = (Page)m_layout.getPages().get(pageNo-1); 265 Log.trace(Log.l4_Data, "View.getDrillAcross", "RelativePoint=" + relativePoint + ", Page=" + page); 267 return page.getDrillAcross (relativePoint); 269 } 271 } | Popular Tags |