Home | History | Annotate | Download | only in preload
      1 /*
      2  * Copyright (C) 2015 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.preload;
     18 
     19 import java.util.ArrayList;
     20 import java.util.List;
     21 
     22 import javax.swing.table.AbstractTableModel;
     23 
     24 /**
     25  * A table model for collected DumpData. This is both the internal storage as well as the model
     26  * for display.
     27  */
     28 public class DumpTableModel extends AbstractTableModel {
     29 
     30     private List<DumpData> data = new ArrayList<DumpData>();
     31 
     32     public void addData(DumpData d) {
     33         data.add(d);
     34         fireTableRowsInserted(data.size() - 1, data.size() - 1);
     35     }
     36 
     37     public void clear() {
     38         int size = data.size();
     39         if (size > 0) {
     40             data.clear();
     41             fireTableRowsDeleted(0, size - 1);
     42         }
     43     }
     44 
     45     public List<DumpData> getData() {
     46         return data;
     47     }
     48 
     49     @Override
     50     public int getRowCount() {
     51         return data.size();
     52     }
     53 
     54     @Override
     55     public int getColumnCount() {
     56         return 4;
     57     }
     58 
     59     @Override
     60     public String getColumnName(int column) {
     61         switch (column) {
     62             case 0:
     63                 return "Package";
     64             case 1:
     65                 return "Date";
     66             case 2:
     67                 return "# All Classes";
     68             case 3:
     69                 return "# Boot Classpath Classes";
     70 
     71             default:
     72                 throw new IndexOutOfBoundsException(String.valueOf(column));
     73         }
     74     }
     75 
     76     @Override
     77     public Object getValueAt(int rowIndex, int columnIndex) {
     78         DumpData d = data.get(rowIndex);
     79         switch (columnIndex) {
     80             case 0:
     81                 return d.packageName;
     82             case 1:
     83                 return d.date;
     84             case 2:
     85                 return d.dumpData.size();
     86             case 3:
     87                 return d.bcpClasses;
     88 
     89             default:
     90                 throw new IndexOutOfBoundsException(String.valueOf(columnIndex));
     91         }
     92     }
     93 }