1554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe/* 2554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Copyright (C) 2015 The Android Open Source Project 3554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * 4554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License"); 5554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * you may not use this file except in compliance with the License. 6554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * You may obtain a copy of the License at 7554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * 8554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * http://www.apache.org/licenses/LICENSE-2.0 9554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * 10554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * Unless required by applicable law or agreed to in writing, software 11554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS, 12554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * See the License for the specific language governing permissions and 14554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * limitations under the License. 15554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe */ 16554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 17554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampepackage com.android.preload; 18554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 19554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.util.ArrayList; 20554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport java.util.List; 21554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 22554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampeimport javax.swing.table.AbstractTableModel; 23554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 24554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe/** 25554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * A table model for collected DumpData. This is both the internal storage as well as the model 26554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe * for display. 27554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe */ 28554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampepublic class DumpTableModel extends AbstractTableModel { 29554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 30554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe private List<DumpData> data = new ArrayList<DumpData>(); 31554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 32554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public void addData(DumpData d) { 33554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe data.add(d); 34554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe fireTableRowsInserted(data.size() - 1, data.size() - 1); 35554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 36554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 37554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public void clear() { 38554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe int size = data.size(); 39554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe if (size > 0) { 40554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe data.clear(); 41554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe fireTableRowsDeleted(0, size - 1); 42554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 43554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 44554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 45554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public List<DumpData> getData() { 46554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return data; 47554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 48554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 49554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe @Override 50554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public int getRowCount() { 51554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return data.size(); 52554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 53554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 54554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe @Override 55554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public int getColumnCount() { 56554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return 4; 57554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 58554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 59554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe @Override 60554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public String getColumnName(int column) { 61554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe switch (column) { 62554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 0: 63554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return "Package"; 64554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 1: 65554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return "Date"; 66554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 2: 67554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return "# All Classes"; 68554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 3: 69554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return "# Boot Classpath Classes"; 70554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 71554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe default: 72554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe throw new IndexOutOfBoundsException(String.valueOf(column)); 73554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 74554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 75554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 76554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe @Override 77554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe public Object getValueAt(int rowIndex, int columnIndex) { 78554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe DumpData d = data.get(rowIndex); 79554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe switch (columnIndex) { 80554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 0: 81554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return d.packageName; 82554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 1: 83554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return d.date; 84554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 2: 85554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return d.dumpData.size(); 86554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe case 3: 87554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe return d.bcpClasses; 88554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe 89554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe default: 90554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe throw new IndexOutOfBoundsException(String.valueOf(columnIndex)); 91554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 92554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe } 93554d7ee0f5d177b6c0bce805f5a5917b6b211978Andreas Gampe}