Back to index

wims  3.65+svn20090927
GraphicContext.java
Go to the documentation of this file.
00001 /*
00002 $Id: GraphicContext.java,v 1.3 2003/02/18 11:48:46 sander Exp $
00003 */
00004 
00005 
00006 /*
00007 Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2.1 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 For further information on the GNU Lesser General Public License,
00024 see: http://www.gnu.org/copyleft/lesser.html
00025 For further information on this library, contact: mainline@essi.fr
00026 */
00027 
00028 
00029 package fr.ove.openmath.jome.ctrlview.bidim;
00030 
00031 import java.awt.*;
00032 
00039 public class GraphicContext implements java.io.Serializable {
00043     private Font font;
00044     
00048     private int sizeRef; // Serves as the reference font size for font scales.
00049     
00053     private Color foregroundColor;
00054     
00058     private Color backgroundColor;
00059     
00063     private static Color selectionColor;
00064     
00068     private int nbTime = 0;
00069     
00080     public GraphicContext() {
00081         this(new Font("Times New Roman", Font.PLAIN, 14), Color.black, Color.white, Color.yellow);
00082     }
00083     
00092     public GraphicContext(Font font, Color foregroundColor, Color backgroundColor, Color selectionColor) {
00093         this.font = font;
00094         sizeRef = font.getSize();
00095         this.foregroundColor = foregroundColor;
00096         this.backgroundColor = backgroundColor;
00097         this.selectionColor = selectionColor;
00098     }
00099     
00104     public GraphicContext(GraphicContext gc) {
00105         font = gc.getFont();
00106         sizeRef = gc.getSizeRef();
00107         foregroundColor = gc.getForegroundColor();
00108         backgroundColor = gc.getBackgroundColor();
00109         selectionColor = gc.getSelectionColor();
00110     }
00111     
00112     // ### The getters ###
00113     
00117     public Font getFont() {
00118         return font;
00119     }
00120     
00124     public int getSizeRef() {
00125         return sizeRef;
00126     }
00127     
00131     public Color getForegroundColor() {
00132         return foregroundColor;
00133     }
00134     
00138     public Color getBackgroundColor() {
00139         return backgroundColor;
00140     }
00141     
00146     public Color getSelectionColor() {
00147         return selectionColor;
00148     }
00149     
00150     // ### The setters ###
00151     
00156     public void setFont(Font font) {
00157         this.font = font;
00158         sizeRef = font.getSize();
00159     }
00160     
00165     public void setForegroundColor(Color foregroundColor) {
00166         this.foregroundColor = foregroundColor;
00167     }
00168     
00173     public void setBackgroundColor(Color backgroundColor) {
00174         this.backgroundColor = backgroundColor;
00175     }
00176     
00181     public void setSelectionColor(Color selectionColor) {
00182         this.selectionColor = selectionColor;
00183     }
00184     
00190     public Font scaleFont(int nbTime) {
00191         if (this.nbTime != nbTime) {
00192             String name = font.getName();
00193             int style = font.getStyle();
00194             int size = sizeRef;
00195             
00196             this.nbTime = nbTime;
00197             
00198             for (int i = 0; i < nbTime; i++) {
00199                 size = (int) Math.round( ((float) size) * 0.7f );
00200                 if (size < 10)
00201                     break;
00202             }
00203             
00204             size = (size < 10) ? 10 : size;
00205             
00206             font = new Font(name, style, size);
00207         }
00208         
00209         return font;
00210     }
00211     
00212 }