Home | History | Annotate | Download | only in state
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.gltrace.state;
     18 
     19 import com.android.annotations.NonNull;
     20 import com.android.annotations.Nullable;
     21 import com.android.utils.SdkUtils;
     22 
     23 public class StatePrettyPrinter {
     24     private static final int SPACES_PER_INDENT = 4;
     25     private final String mLineSeparator = SdkUtils.getLineSeparator();
     26 
     27     private StringBuilder mSb = new StringBuilder(1000);
     28     private int mIndentLevel = 0;
     29 
     30     public void prettyPrint(@NonNull GLStateType name, @Nullable String value) {
     31         indentLine(mIndentLevel * SPACES_PER_INDENT);
     32 
     33         mSb.append(name.toString());
     34 
     35         if (value != null) {
     36             mSb.append(':');
     37             mSb.append(value);
     38         }
     39         mSb.append(mLineSeparator);
     40     }
     41 
     42     public void prettyPrint(@NonNull String s) {
     43         indentLine(mIndentLevel * SPACES_PER_INDENT);
     44 
     45         mSb.append(s);
     46         mSb.append(mLineSeparator);
     47     }
     48 
     49     private void indentLine(int spaces) {
     50         for (int i = 0; i < spaces; i++) {
     51             mSb.append(' ');
     52         }
     53     }
     54 
     55     public void incrementIndentLevel() {
     56         mIndentLevel++;
     57     }
     58 
     59     public void decrementIndentLevel() {
     60         mIndentLevel--;
     61     }
     62 
     63     @Override
     64     public String toString() {
     65         return mSb.toString();
     66     }
     67 }
     68