001package com.hfg.graphics; 002 003 004import java.awt.*; 005import java.awt.geom.AffineTransform; 006 007//------------------------------------------------------------------------------ 008/** 009 * A convenience container for tracking Graphics2D states. 010 * <div> 011 * @author J. Alex Taylor, hairyfatguy.com 012 * </div> 013 */ 014//------------------------------------------------------------------------------ 015// com.hfg XML/HTML Coding Library 016// 017// This library is free software; you can redistribute it and/or 018// modify it under the terms of the GNU Lesser General Public 019// License as published by the Free Software Foundation; either 020// version 2.1 of the License, or (at your option) any later version. 021// 022// This library is distributed in the hope that it will be useful, 023// but WITHOUT ANY WARRANTY; without even the implied warranty of 024// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 025// Lesser General Public License for more details. 026// 027// You should have received a copy of the GNU Lesser General Public 028// License along with this library; if not, write to the Free Software 029// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030// 031// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 032// jataylor@hairyfatguy.com 033//------------------------------------------------------------------------------ 034 035public class Graphics2DState 036{ 037 private Font mFont; 038 private Paint mPaint; 039 private Stroke mStroke; 040 private Color mBackground; 041 private Composite mComposite; 042 private AffineTransform mTransform; 043 044 //########################################################################## 045 // CONSTRUCTORS 046 //########################################################################## 047 048 //-------------------------------------------------------------------------- 049 public Graphics2DState(Graphics2D inGraphics2D) 050 { 051 mFont = inGraphics2D.getFont(); 052 mPaint = inGraphics2D.getPaint(); 053 mStroke = inGraphics2D.getStroke(); 054 mBackground = inGraphics2D.getBackground(); 055 mComposite = inGraphics2D.getComposite(); 056 mTransform = inGraphics2D.getTransform(); 057 } 058 059 //########################################################################## 060 // PUBLIC METHODS 061 //########################################################################## 062 063 //-------------------------------------------------------------------------- 064 public void applyTo(Graphics2D inGraphics2D) 065 { 066 inGraphics2D.setFont(mFont); 067 inGraphics2D.setPaint(mPaint); 068 inGraphics2D.setStroke(mStroke); 069 inGraphics2D.setBackground(mBackground); 070 inGraphics2D.setComposite(mComposite); 071 inGraphics2D.setTransform(mTransform); 072 } 073 074 //-------------------------------------------------------------------------- 075 public Font getFont() 076 { 077 return mFont; 078 } 079 080 //-------------------------------------------------------------------------- 081 public Paint getPaint() 082 { 083 return mPaint; 084 } 085 086 //-------------------------------------------------------------------------- 087 public Stroke getStroke() 088 { 089 return mStroke; 090 } 091 092 //-------------------------------------------------------------------------- 093 public Color getBackground() 094 { 095 return mBackground; 096 } 097 098 //-------------------------------------------------------------------------- 099 public Composite getComposite() 100 { 101 return mComposite; 102 } 103 104 //-------------------------------------------------------------------------- 105 public AffineTransform getTransform() 106 { 107 return mTransform; 108 } 109 110 111 112}