FileDocCategorySizeDatePackage
DisplayLog.javaAPI DocAndroid 1.5 API14077Wed May 06 22:41:08 BST 2009com.android.ddmuilib.log.event

DisplayLog

public class DisplayLog extends EventDisplay

Fields Summary
private static final String
PREFS_COL_DATE
private static final String
PREFS_COL_PID
private static final String
PREFS_COL_EVENTTAG
private static final String
PREFS_COL_VALUENAME
private static final String
PREFS_COL_VALUE
private static final String
PREFS_COL_TYPE
Constructors Summary
public DisplayLog(String name)

        super(name);
    
Methods Summary
private voidaddToLog(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser)
Adds an {@link EventContainer} to the log.

param
event the event.
param
logParser the log parser.

        ScrollBar bar = mLogTable.getVerticalBar();
        boolean scroll = bar.getMaximum() == bar.getSelection() + bar.getThumb();

        // get the date.
        Calendar c = Calendar.getInstance();
        long msec = (long) event.sec * 1000L;
        c.setTimeInMillis(msec);

        // convert the time into a string
        String date = String.format("%1$tF %1$tT", c);

        String eventName = logParser.getTagMap().get(event.mTag);
        String pidName = Integer.toString(event.pid);

        // get the value description
        EventValueDescription[] valueDescription = logParser.getEventInfoMap().get(event.mTag);
        if (valueDescription != null) {
            for (int i = 0; i < valueDescription.length; i++) {
                EventValueDescription description = valueDescription[i];
                try {
                    String value = event.getValueAsString(i);

                    logValue(date, pidName, eventName, description.getName(), value,
                            description.getEventValueType(), description.getValueType());
                } catch (InvalidTypeException e) {
                    logValue(date, pidName, eventName, description.getName(), e.getMessage(),
                            description.getEventValueType(), description.getValueType());
                }
            }

            // scroll if needed, by showing the last item
            if (scroll) {
                int itemCount = mLogTable.getItemCount();
                if (itemCount > 0) {
                    mLogTable.showItem(mLogTable.getItem(itemCount - 1));
                }
            }
        }
    
protected voidaddToLog(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser, java.util.ArrayList valueDescriptors, java.util.ArrayList occurrenceDescriptors)
Adds an {@link EventContainer} to the log. Only add the values/occurrences defined by the list of descriptors. If an event is configured to be displayed by value and occurrence, only the values are displayed (as they mark an event occurrence anyway).

This method is only called when at least one of the descriptor list is non empty.

param
event
param
logParser
param
valueDescriptors
param
occurrenceDescriptors

        ScrollBar bar = mLogTable.getVerticalBar();
        boolean scroll = bar.getMaximum() == bar.getSelection() + bar.getThumb();

        // get the date.
        Calendar c = Calendar.getInstance();
        long msec = (long) event.sec * 1000L;
        c.setTimeInMillis(msec);

        // convert the time into a string
        String date = String.format("%1$tF %1$tT", c);

        String eventName = logParser.getTagMap().get(event.mTag);
        String pidName = Integer.toString(event.pid);

        if (valueDescriptors.size() > 0) {
            for (ValueDisplayDescriptor descriptor : valueDescriptors) {
                logDescriptor(event, descriptor, date, pidName, eventName, logParser);
            }
        } else {
            // we display the event. Since the StringBuilder contains the header (date, event name,
            // pid) at this point, there isn't anything else to display.
        }

        // scroll if needed, by showing the last item
        if (scroll) {
            int itemCount = mLogTable.getItemCount();
            if (itemCount > 0) {
                mLogTable.showItem(mLogTable.getItem(itemCount - 1));
            }
        }
    
org.eclipse.swt.widgets.ControlcreateComposite(org.eclipse.swt.widgets.Composite parent, com.android.ddmlib.log.EventLogParser logParser, ILogColumnListener listener)
Creates the UI for the event display.

param
parent the parent composite.
param
logParser the current log parser.
return
the created control (which may have children).

        return createLogUI(parent, listener);
    
private org.eclipse.swt.widgets.ControlcreateLogUI(org.eclipse.swt.widgets.Composite parent, ILogColumnListener listener)
Creates the UI for a log display.

param
parent the parent {@link Composite}
param
listener the {@link ILogColumnListener} to notify on column resize events.
return
the top Composite of the UI.

        Composite mainComp = new Composite(parent, SWT.NONE);
        GridLayout gl;
        mainComp.setLayout(gl = new GridLayout(1, false));
        gl.marginHeight = gl.marginWidth = 0;
        mainComp.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                mLogTable = null;
            }
        });

        Label l = new Label(mainComp, SWT.CENTER);
        l.setText(mName);
        l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        mLogTable = new Table(mainComp, SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL |
                SWT.BORDER);
        mLogTable.setLayoutData(new GridData(GridData.FILL_BOTH));

        IPreferenceStore store = DdmUiPreferences.getStore();

        TableColumn col = TableHelper.createTableColumn(
                mLogTable, "Time",
                SWT.LEFT, "0000-00-00 00:00:00", PREFS_COL_DATE, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(0, (TableColumn) source);
                }
            }
        });

        col = TableHelper.createTableColumn(
                mLogTable, "pid",
                SWT.LEFT, "0000", PREFS_COL_PID, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(1, (TableColumn) source);
                }
            }
        });

        col = TableHelper.createTableColumn(
                mLogTable, "Event",
                SWT.LEFT, "abcdejghijklmno", PREFS_COL_EVENTTAG, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(2, (TableColumn) source);
                }
            }
        });

        col = TableHelper.createTableColumn(
                mLogTable, "Name",
                SWT.LEFT, "Process Name", PREFS_COL_VALUENAME, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(3, (TableColumn) source);
                }
            }
        });

        col = TableHelper.createTableColumn(
                mLogTable, "Value",
                SWT.LEFT, "0000000", PREFS_COL_VALUE, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(4, (TableColumn) source);
                }
            }
        });

        col = TableHelper.createTableColumn(
                mLogTable, "Type",
                SWT.LEFT, "long, seconds", PREFS_COL_TYPE, store); //$NON-NLS-1$
        col.addControlListener(new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
                Object source = e.getSource();
                if (source instanceof TableColumn) {
                    listener.columnResized(5, (TableColumn) source);
                }
            }
        });

        mLogTable.setHeaderVisible(true);
        mLogTable.setLinesVisible(true);

        return mainComp;
    
intgetDisplayType()
Gets display type

return
display type as an integer

        return DISPLAY_TYPE_LOG_ALL;
    
private voidlogDescriptor(com.android.ddmlib.log.EventContainer event, ValueDisplayDescriptor descriptor, java.lang.String date, java.lang.String pidName, java.lang.String eventName, com.android.ddmlib.log.EventLogParser logParser)
Logs a value from an {@link EventContainer} as defined by the {@link ValueDisplayDescriptor}.

param
event the EventContainer
param
descriptor the ValueDisplayDescriptor defining which value to display.
param
date the date of the event in a string.
param
pidName
param
eventName
param
logParser


        String value;
        try {
            value = event.getValueAsString(descriptor.valueIndex);
        } catch (InvalidTypeException e) {
            value = e.getMessage();
        }

        EventValueDescription[] values = logParser.getEventInfoMap().get(event.mTag);

        EventValueDescription valueDescription = values[descriptor.valueIndex];

        logValue(date, pidName, eventName, descriptor.valueName, value,
                valueDescription.getEventValueType(), valueDescription.getValueType());
    
private voidlogValue(java.lang.String date, java.lang.String pid, java.lang.String event, java.lang.String valueName, java.lang.String value, EventContainer.EventValueType eventValueType, EventValueDescription.ValueType valueType)
Logs a value in the ui.

param
date
param
pid
param
event
param
valueName
param
value
param
eventValueType
param
valueType


        TableItem item = new TableItem(mLogTable, SWT.NONE);
        item.setText(0, date);
        item.setText(1, pid);
        item.setText(2, event);
        item.setText(3, valueName);
        item.setText(4, value);

        String type;
        if (valueType != EventValueDescription.ValueType.NOT_APPLICABLE) {
            type = String.format("%1$s, %2$s", eventValueType.toString(), valueType.toString());
        } else {
            type = eventValueType.toString();
        }

        item.setText(5, type);
    
voidnewEvent(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser)
Adds event to the display.

        addToLog(event, logParser);
    
voidresetUI()
Resets the display.

 //$NON-NLS-1$

            
    
      
        mLogTable.removeAll();
    
voidresizeColumn(int index, org.eclipse.swt.widgets.TableColumn sourceColumn)
Resizes the index-th column of the log {@link Table} (if applicable).

This does nothing if the Table object is null (because the display type does not use a column) or if the index-th column is in fact the originating column passed as argument.

param
index the index of the column to resize
param
sourceColumn the original column that was resize, and on which we need to sync the index-th column width.

        if (mLogTable != null) {
            TableColumn col = mLogTable.getColumn(index);
            if (col != sourceColumn) {
                col.setWidth(sourceColumn.getWidth());
            }
        }