// Copyright 1996, Marimba Inc. All Rights Reserved.


// Confidential and Proprietary Information of Marimba, Inc.


// @(#)StyleChange.java, 1.8, 12/15/96





package marimba.text;





import java.awt.*;





/**


 * This represents a change that you would like to inflict on a range


 * of characters in a text view.  Operations such as adding and


 * subtracting from the font face, changing the size, changing the


 * family, etc.


 *


 * @author	Jonathan Payne


 * @version 1.8, 12/15/96


 */


public class StyleChange {


    FontFamily family;	/* null or a family to set */


    short fontFaceAdd;


    short fontFaceDel;


    short fontSize;	/* -1 or a font size to use */


    boolean setSize;	/* true means set font size, false means add */


    Color color;	/* null or a color */





    public StyleChange() {}





    StyleChange(Font f) {


	if (f.isPlain()) {


	    makePlain();


	} else {


	    if (f.isItalic()) {


		makeItalic();


	    }


	    if (f.isBold()) {


		makeBold();


	    }


	}


	setSize = true;


	fontSize = (short) f.getSize();


    }





    StyleChange(Color color) {


	this.color = color;


    }





    Style makeStyleFrom(Style style) {


	Style newStyle = (Style) style.clone();





	if (family != null) {


	    newStyle.family = family;


	}


	newStyle.fontFace &= ~fontFaceDel;


	newStyle.fontFace |= fontFaceAdd;





	/* Adjust the font size.  If we end up with a bogus


	   new value, silently (for now) reset the value to


	   what it was in the source. */


	if (fontSize != 0) {


	    if (setSize) {


		if (fontSize > 0)


		    newStyle.fontSize = fontSize;


	    } else {


		newStyle.fontSize += fontSize;


		if (newStyle.fontSize <= 0) {


		    newStyle.fontSize = style.fontSize;


		}


	    }


	}


	if (color != null) {


	    newStyle.color = color;


	}





	return newStyle;


    }





    final public StyleChange makeItalic() {


	fontFaceAdd |= FontFamily.ITALIC;


	return this;


    }





    final public StyleChange makeBold() {


	fontFaceAdd |= FontFamily.BOLD;


	return this;


    }





    final public StyleChange makePlain() {


	fontFaceDel = (short) (FontFamily.ITALIC | FontFamily.BOLD);


	return this;


    }





    final public StyleChange makeEmbossed() {


	fontFaceAdd |= FontFamily.EMBOSS;


	return this;


    }





    final public StyleChange changeFontSize(int amnt) {


	fontSize = (short) amnt;


	setSize = false;


	return this;


    }





    final public StyleChange setColor(Color color) {


	this.color = color;


	return this;


    }


}


