Package jpianotrain.gui

Source Code of jpianotrain.gui.ScaleTableModel

package jpianotrain.gui;

import java.util.HashMap;
import java.util.Map;

import javax.swing.table.DefaultTableModel;

import jpianotrain.staff.Note;
import jpianotrain.staff.NoteName;
import jpianotrain.staff.Scale;
import jpianotrain.staff.ScaleName;

/**
* Table model to render a non-editable table of notes.
*
* @author methke01
* @since 0.0.3
*/
public class ScaleTableModel extends DefaultTableModel {
  public ScaleTableModel(ScaleName sn, NoteName[] columnNames) {
    super(sn.getMapping().length+1, columnNames.length);
    scaleBuffer=new HashMap<Integer, Scale>();
    scaleName=sn;
    this.columnNames=columnNames;
  }

  @Override
  public Class<?> getColumnClass(int col) {
    return Note.class;
  }
 
  @Override
  public int getColumnCount() {
    return columnNames.length;
  }
 
  @Override
  public String getColumnName(int idx) {
    return columnNames[idx].toString();
  }
 
  @Override
  public int getRowCount() {
    return scaleName==null?0:scaleName.getMapping().length+1;
  }
 
  @Override
  public Object getValueAt(int row, int col) {
    Scale s=scaleBuffer.get(col);
    if (s==null) {
      s=new Scale(columnNames[col], scaleName);
      scaleBuffer.put(col, s);
    }
    return s.getNote(row);
  }
 
  @Override
  public boolean isCellEditable(int row, int col) {
    return false;
  }
 
  private Map<Integer, Scale> scaleBuffer;
  private ScaleName scaleName;
  private NoteName[] columnNames;
}
TOP

Related Classes of jpianotrain.gui.ScaleTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.