/************************************************************************ * * BeforeAfter.java * * Copyright: 2002-2011 by Henrik Just * * This file is part of Writer2LaTeX. * * Writer2LaTeX is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Writer2LaTeX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Writer2LaTeX. If not, see . * * Version 1.2 (2011-03-29) * */ package writer2latex.latex.util; /** Utility class to hold LaTeX code to put before/after other LaTeX code */ public class BeforeAfter { private String sBefore=""; private String sAfter=""; /** Constructor to initialize the object with a pair of strings * @param sBefore1 LaTeX code to put before * @param sAfter1 LaTeX code to put after */ public BeforeAfter(String sBefore1, String sAfter1) { sBefore=sBefore1; sAfter=sAfter1; } /** Default constructor: Create with empty strings */ public BeforeAfter() { } /**

Add data to the BeforeAfter

*

The new data will be be added "inside", thus for example

* *

will create the pair \textsf{\textit{, }}

* * @param sBefore1 LaTeX code to put before * @param sAfter1 LaTeX code to put after */ public void add(String sBefore1, String sAfter1) { sBefore+=sBefore1; sAfter=sAfter1+sAfter; } /**

Add data to the BeforeAfter

*

The new data will be be added "outside", thus for example

* *

will create the pair \textit{\textsf{, }}

* * @param sBefore1 LaTeX code to put before * @param sAfter1 LaTeX code to put after */ public void enclose(String sBefore1, String sAfter1) { sBefore=sBefore1+sBefore; sAfter+=sAfter1; } /**

Add the content of another BeforeAfter to this BeforeAfter

*

The new data will be be added "inside"

* * @param ba the code to add */ public void add(BeforeAfter ba) { add(ba.getBefore(), ba.getAfter()); } /** Get LaTeX code to put before * @return then LaTeX code */ public String getBefore() { return sBefore; } /** Get LaTeX code to put after * @return then LaTeX code */ public String getAfter() { return sAfter; } /** Check if this BeforeAfter contains any data * @return true if there is data in at least one part */ public boolean isEmpty() { return sBefore.length()==0 && sAfter.length()==0; } }