blob: 6ea60ef963a26d184a51837ef93e275a25d0aa0f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Patrick Chuong (Texas Instruments) - Checkbox support for Flexible Hierachy view (Bug 286310)
*******************************************************************************/
package org.eclipse.debug.examples.ui.midi.adapters;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.ShortMessage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.jface.viewers.TreePath;
/**
* Provides labels for MIDI tracks.
*
* @since 1.0
*/
public class MidiEventLabelProvider extends ElementLabelProvider {
/* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getLabel(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
*/
protected String getLabel(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
MidiEvent event = (MidiEvent) elementPath.getLastSegment();
MidiMessage message = event.getMessage();
if (TrackColumnPresentation.COL_TICK.equals(columnId)) {
return Long.toString(event.getTick());
} else if (TrackColumnPresentation.COL_BYTES.equals(columnId)) {
byte[] bytes = message.getMessage();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < message.getLength(); i++) {
buffer.append(' ');
appendByte(buffer, bytes[i]);
}
return buffer.toString();
} else if (TrackColumnPresentation.COL_COMMAND.equals(columnId)) {
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
StringBuffer buf = new StringBuffer();
appendByte(buf, (byte)sm.getCommand());
return buf.toString();
}
} else if (TrackColumnPresentation.COL_CHANNEL.equals(columnId)) {
if (message instanceof ShortMessage) {
return Integer.toString(((ShortMessage)message).getChannel());
}
}
return "";
}
/*
* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getChecked(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
*/
public boolean getChecked(TreePath path, IPresentationContext presentationContext) throws CoreException {
Boolean result = (Boolean) MidiEventModelProxy.gChecked.get(path);
return result == null ? false : result.booleanValue();
}
/**
* Appends a byte to the buffer with 2 hex characters.
*
* @param buffer
* @param b
*/
private void appendByte(StringBuffer buffer, byte b) {
String hex = Integer.toHexString(b & 0xFF).toUpperCase();
for (int i = hex.length(); i < 2; i++) {
buffer.append('0');
}
buffer.append(hex);
}
}