%%%%%%%%%%%%%%% control how things look. These guys are used all over the place

\def\fl{tbp} % try to fudge decent layout of figures. Pretty touchy stuff

\newif\ifdebugtext


\newcommand\twelve[2]{#2} % #1 for long version
\newcommand\HIDE[1]{}

%%%%%%%%%%%%%%%

% ah. No use without meta font packages oh well
\DeclareFontShape{OT1}{cmtt}{bx}{n}
 {<5><6><7><8>cmbtt8%
  <9>cmbtt9%
  <10><10.95>cmbtt10%
  <12><14.4><17.28><20.74><24.88>cmbtt10%
 }{}

\usepackage{listings}
\lstset{frame=tb, labelstyle=\tiny, labelstep=1, labelsep=5pt, indent=10pt} 
\lstset{
  language=Java, 
  keywords={package,class,expected,collaboration,collab,participant,public,return,this,limited,extends,with,attach,import,provide,for,in,do,match,around,rename,export,as,aspectual,shared,reshared,where,role,mutex,abstract,aspect,pointcut,before,interface,declare,parents,implements,target,call,args,replace,becoming,while,if,else,throws,throw,new,void,static,null},  % int,boolean
  escapeinside={/*}{*/},
%  fontadjust,
%  flexiblecolumns,
%  lineskip=-0.5pt,
  basicstyle=\footnotesize,
%  stringstyle=\ttfamily,
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% johan: Nifty! only full name on first use per section (or subsection)

% didn't work. Oh well. 
%\newcommand\newterm[3]{ % ac AC aspectual component
% \newcounter{intro{1}}\newcounter{{1}}[section]
% \def\the#2{#3}
% \def\#2{\ifnum\value{intro#1}=0
%           \emph{\the#2} (henceforth #2)\stepcounter{intro#1}
%           \else{\ifnum\value{#1}=0\the#2\stepcounter{#1}\else{#2}\fi}
%          \fi}
%\newterm{ac}{AC}{aspectual component}

\newcounter{aop}[section]\def\theAOP{Aspect-Oriented Program\-ming}\def\AOP{\ifnum\value{aop}=0\emph{\theAOP}~(AOP)\stepcounter{aop}\else{AOP}\fi}
\newcounter{ao}[section]\def\theAO{Aspect-Oriented}\def\AO{\ifnum\value{ao}=0\emph{\theAO}~(AO)\stepcounter{ao}\else{AO}\fi}
\newcounter{mp}[section]\def\theMP{Modular Program\-ming}\def\MP{\ifnum\value{mp}=0\emph{\theMP}~(MP)\stepcounter{mp}\else{MP}\fi}
\newcounter{ap}[section]\def\theAP{Adaptive Programming}\def\AP{\ifnum\value{ap}=0\emph{\theAP}~(AP)\stepcounter{ap}\else{AP}\fi}
\newcounter{app}[section]\def\theAPP{Adaptive Plug\&Play}\def\APP{\ifnum\value{app}=0\emph{\theAPP}~(AP\&P)\stepcounter{app}\else{AP\&P}\fi}
\newcounter{oo}[section]\def\theOO{Object-Oriented}\def\OO{\ifnum\value{oo}=0\emph{\theOO}~(OO)\stepcounter{oo}\else{OO}\fi}
\newcounter{oop}[section]\def\theOOP{Object-Oriented Programming}\def\OOP{\ifnum\value{oop}=0\emph{\theOOP}~(OOP)\stepcounter{oop}\else{OOP}\fi}
\newcounter{oopl}[section]\def\theOOPL{Object-Oriented Programming Languages}\def\OOPL{\ifnum\value{oopl}=0\emph{\theOOPL}~(OOPL)\stepcounter{oopl}\else{OOPL}\fi}
\newcounter{appc}[section]\def\theAPPC{Adaptive Plug\&Play Components}\def\APPC{\ifnum\value{appc}=0\emph{\theAPPC}~(AP\&P Components)\stepcounter{appc}\else{AP\&P Components}\fi}
\newcounter{jg}[section]\def\theJG{Join Graph}\def\JG{\ifnum\value{jg}=0\emph{\theJG}~(JG)\stepcounter{jg}\else{JG}\fi}

%Johan: these are new and improved. First ever use in the paper is emph and defined short form, first use per section after that is unemph, and all subsequent refs are short 


\def\AC{\ifnum\value{introac}=0\emph{\longAC} (henceforth \shortAC)\stepcounter{introac}\stepcounter{ac}\else{\ifnum\value{ac}=0\longAC\stepcounter{ac}\else{\shortAC}\fi}\fi}
\newcounter{introac}\newcounter{ac}[section]\def\longAC{Aspectual Collaboration}\def\shortAC{AC}\def\ACs{\ifnum\value{introac}=0\emph{{\AC}s}\stepcounter{introac}\stepcounter{ac}\else{\ifnum\value{ac}=0{\longAC}s\stepcounter{ac}\else{{\shortAC}s}\fi}\fi}
\newcounter{intropg}\newcounter{pg}[section]\def\longPG{participant graph}\def\shortPG{PG}\def\PG{\ifnum\value{intropg}=0\emph{\longPG} (henceforth \shortPG)\stepcounter{intropg}\stepcounter{pg}\else{\ifnum\value{pg}=0\longPG\stepcounter{pg}\else{\shortPG}\fi}\fi}
\newcounter{introcg}\newcounter{cg}[section]\def\longCG{class graph}\def\shortCG{CG}\def\CG{\ifnum\value{introcg}=0\emph{\longCG} (henceforth \shortCG)\stepcounter{introcg}\stepcounter{cg}\else{\ifnum\value{cg}=0\longCG\stepcounter{cg}\else{\shortCG}\fi}\fi}


%old, keep while testing
%\newcounter{pg}[section]\def\thePG{participant graph}\def\PG{\ifnum\value{pg}=0\emph{\thePG}\stepcounter{pg}\else{PG}\fi}
%\newcounter{cg}[section]\def\theCG{class graph}\def\CG{\ifnum\value{cg}=0\emph{\theCG}\stepcounter{cg}\else{CG}\fi}


\def\APPC{{\APP} component}\def\APPCs{{\APP} components}

\newcommand{\hj}{\mbox{Hyper\hspace{-0.7pt}/\hspace{-1pt}J}}
\newcommand{\aj}{AspectJ}
% johan: You know, I defined a new macro for a reason.
%\newcommand{\ac}{Aspect\-ual Collab\-oration}
\newcommand{\ac}{\AC}
\newcommand{\ji}{Jiazzi}
\newcommand{\AOLs}{Aspect-Oriented languages}

\newtheorem{thm}{Theorem}
\newtheorem{lma}{Lemma}[thm]




%\pagestyle{plain}

%\renewcommand{\textfraction}{0.15}
%\renewcommand{\topfraction}{0.85}
%\renewcommand{\bottomfraction}{0.65}
%\renewcommand{\floatpagefraction}{0.60}

\newcommand{\scalefigfrom}[2]{ \centerline{\includegraphics[scale=#1]{Figs/#2.eps}} }
\newcommand{\figfrom}[1]{\scalefigfrom{1}{#1}}
%\newcommand{\figfrom}[1]{ \centerline{\leavevmode\epsfbox{#1.eps}}   } 


\newcommand\type[1]{\textsf{#1}}
\newcommand\java[1]{\texttt{#1}}
\newcommand\collab[1]{\textsf{#1}}
\newcommand\keywrd[1]{\textbf{#1}}




\newcommand\optionaltext[1]{\ifdebugtext{#1}\fi} 
% sig style hates margin pars I think
\newcommand\annotate[2]{\optionaltext{ % --dl: margin/footnote annotation

    \noindent{\footnotesize \begin{minipage}{\linewidth}
      \noindent\textbf{#1}$\Rightarrow$~\emph{#2}\newline
    \end{minipage} } %\vspace{-0.5\baselineskip}
 }
}
\newcommand\fixme[1]{% --dl: to make it easier on the eyes...
        \annotate{FIXME}{#1}}
%\newcommand\fixed[1]{}% --dl: not printed
\newcommand\fixed[1]{\annotate{Fixed}{#1}}% --dl: printed


\newcommand\gripe[2]{\optionaltext{{\bf (gripe:#1)}{#2}}}
\newcommand\remove[2]{\optionaltext{\annotate{Removed}{#1}{}} }
\newcommand\toolong[1]{\optionaltext{ {\scriptsize {\bf (Cut to save length)} #1}}}


\newcommand\johan[1]{\annotate{Johan}{#1}}
\newcommand\david[1]{\annotate{David}{#1}}
\newcommand\review[2]{\annotate{Reviewer #1}{#2}}
\newcommand\Review[2]{ 
%\annotate{Okay}{#2} % once fixed, make 'em go away
}

\usepackage[usenames]{color}
\newcommand\revA[1]{\annotate{BCS A}{\color{red}  #1}}
\newcommand\revB[1]{\annotate{BCS B}{\color{blue} #1}}
\newcommand\revC[1]{\annotate{BCS C}{\color{magenta} #1}}
\newcommand\RevA[1]{}
\newcommand\RevB[1]{}
\newcommand\RevC[1]{}

%% why turn them off this way? this is _precisely_ what ifdebugtext is for!

\renewcommand\johan[1]{}
\renewcommand\david[1]{}
\renewcommand\review[2]{}
\renewcommand\Review[2]{}
\renewcommand\revA[1]{}
\renewcommand\revB[1]{}
\renewcommand\revC[1]{}

\newcounter{smallenumctr}
\renewcommand{\thesmallenumctr}{\alph{smallenumctr}}
\newenvironment{smallenum}[1][{}]
  { \resetitem[#1] }
  { }
\newcommand{\resetitem}[1][{}] { \setcounter{smallenumctr}{0} \def\sitemvar{#1} }
\newcommand{\citem}{\refstepcounter{smallenumctr}\sitemvar(\thesmallenumctr)~}
\newcommand{\litem}[1]{\sitemvar\mbox{\bf #1}~}


\def\itme{\item}
\def\tiem{\item}
\newcommand\being[1]{\begin{#1}}

\newcommand\bookmark{
\optionaltext{  \vspace{3mm} \begin{center}\textbf{bookmark}\end{center} \vspace{3mm} }
}

%\newcommand\tinycomment[1]{\optionaltext{\raisebox{-0.9ex}[0pt][0pt]{\makebox[0pt][c]{\tiny #1}}}}
\newcommand\tinycomment[1]{}
\newcommand\Listing[1]{Listing~\mbox{\tinycomment{Listing:#1}\ref{Listing:#1}}}
\newcommand\LineB[2]{\mbox{\tinycomment{Listing:#1.line:#2}\ref{Listing:#1}.\ref{line:#2}}}
\newcommand\Line[2]{line \LineB{#1}{#2}}
\newcommand\Lines[3]{lines \mbox{\tinycomment{Listing:#1.line:#2--line:#3}\ref{Listing:#1}.\ref{line:#2}--\ref{line:#3}}}
\newcommand\LinesAnd[3]{lines \mbox{\tinycomment{Listing:#1.line:#2 and line:#3}\ref{Listing:#1}.\ref{line:#2} and \ref{line:#3}}}
\newcommand\Ref[2]{{#1}~\mbox{\tinycomment{#1:#2}\ref{#1:#2}}}
\newcommand\Cite[1]{\mbox{\tinycomment{#1}\cite{#1}}}

\newcommand\sect[1]{\section{#1}}
\newcommand\Section[2]{\sect{#1} \label{Section:#2}\tinycomment{Section:#2}}
\newcommand\ssect[1]{\subsection{#1}}
\newcommand\Ssect[2]{\ssect{#1} \label{Section:#2}\tinycomment{Section:#2}}
\newcommand\sssect[1]{\subsubsection{#1}}  
\newcommand\Sssect[2]{\sssect{#1} \label{Section:#2}\tinycomment{Section:#2}}  
\newcommand\subsubsubsection[1]{\vspace{.05in}\noindent\emph{\textbf{#1}}}
\newcommand\ssssect[1]{\subsubsubsection{#1}}
\newcommand\Ssssect[2]{\ssssect{#1} \label{Section:#2}\tinycomment{Section:#2}}

% how-to-use: \btwofig takes optional argument of fraction of line to give to
% the left figure. will calculate the amount to give to the right
\def\fudge2{-10pt} % 2*fudge2 should be the space added between two cols in a table
\newlength{\twowidtha}
\newlength{\twowidthb}
\newcommand\btwofig[1][.5]{ 
 \begin{figure*}[tb] 
 \setlength{\twowidtha}{#1\linewidth}
 \setlength{\twowidthb}{\linewidth}
 \addtolength{\twowidthb}{-1\twowidtha}
 \addtolength{\twowidtha}{\fudge2}
 \addtolength{\twowidthb}{\fudge2}
 \begin{tabular}{l r}\begin{minipage}[t]{\twowidtha} 
}
\newcommand\ttwofig{ \end{minipage} & \begin{minipage}[t]{\twowidthb} } 
\newcommand\etwofig{ \end{minipage} \end{tabular} \end{figure*} }

\newcommand\bvfig{ \begin{figure}[t] }
\newcommand\tvfig{ \end{figure}\begin{figure}[t] } 
\newcommand\evfig{ \end{figure} }

\newcommand\url[1]{\textsl{#1}}

