Home | History | Annotate | Download | only in model
      1 /*
      2  * Copyright (C) 2009 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.hierarchyviewer.ui.model;
     18 
     19 import javax.swing.table.DefaultTableModel;
     20 import java.text.NumberFormat;
     21 
     22 public class ProfilesTableModel extends DefaultTableModel {
     23     private static final String[] NAMES = { "measure", "layout", "draw" };
     24 
     25     private final double[] profiles;
     26     private final NumberFormat formatter;
     27 
     28     public ProfilesTableModel(double[] profiles) {
     29         this.profiles = profiles;
     30         formatter = NumberFormat.getNumberInstance();
     31     }
     32 
     33     @Override
     34     public int getRowCount() {
     35         return profiles == null ? 0 : profiles.length;
     36     }
     37 
     38     @Override
     39     public Object getValueAt(int row, int column) {
     40         if (profiles == null) return "";
     41 
     42         if (column == 0) {
     43             return NAMES[row];
     44         }
     45 
     46 
     47         return formatter.format(profiles[row]) + "";
     48     }
     49 
     50     @Override
     51     public int getColumnCount() {
     52         return 2;
     53     }
     54 
     55     @Override
     56     public String getColumnName(int column) {
     57         return column == 0 ? "Operation" : "Duration (ms)";
     58     }
     59 
     60     @Override
     61     public boolean isCellEditable(int arg0, int arg1) {
     62         return false;
     63     }
     64 
     65     @Override
     66     public void setValueAt(Object arg0, int arg1, int arg2) {
     67     }
     68 }
     69