FileDocCategorySizeDatePackage
LogCatView.javaAPI DocAndroid 1.5 API11241Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.ddms.views

LogCatView

public final class LogCatView extends SelectionDependentViewPart
The log cat view displays log output from the current device selection.

Fields Summary
public static final String
ID
private static final String
PREFS_COL_TIME
private static final String
PREFS_COL_LEVEL
private static final String
PREFS_COL_PID
private static final String
PREFS_COL_TAG
private static final String
PREFS_COL_MESSAGE
private static final String
PREFS_FILTERS
private static LogCatView
sThis
private com.android.ddmuilib.logcat.LogPanel
mLogPanel
private com.android.ide.eclipse.ddms.CommonAction
mCreateFilterAction
private com.android.ide.eclipse.ddms.CommonAction
mDeleteFilterAction
private com.android.ide.eclipse.ddms.CommonAction
mEditFilterAction
private com.android.ide.eclipse.ddms.CommonAction
mExportAction
private com.android.ide.eclipse.ddms.CommonAction[]
mLogLevelActions
private String[]
mLogLevelIcons
private org.eclipse.jface.action.Action
mClearAction
private org.eclipse.swt.dnd.Clipboard
mClipboard
Constructors Summary
public LogCatView()

        sThis = this;
        LogPanel.PREFS_TIME = PREFS_COL_TIME;
        LogPanel.PREFS_LEVEL = PREFS_COL_LEVEL;
        LogPanel.PREFS_PID = PREFS_COL_PID;
        LogPanel.PREFS_TAG = PREFS_COL_TAG;
        LogPanel.PREFS_MESSAGE = PREFS_COL_MESSAGE;
    
Methods Summary
public voidcreatePartControl(org.eclipse.swt.widgets.Composite parent)

        Display d = parent.getDisplay();
        LogColors colors = new LogColors();

        ImageLoader loader = DdmsPlugin.getImageLoader();

        colors.infoColor = new Color(d, 0, 127, 0);
        colors.debugColor = new Color(d, 0, 0, 127);
        colors.errorColor = new Color(d, 255, 0, 0);
        colors.warningColor = new Color(d, 255, 127, 0);
        colors.verboseColor = new Color(d, 0, 0, 0);

        mCreateFilterAction = new CommonAction("Create Filter") {
            @Override
            public void run() {
                mLogPanel.addFilter();
            }
        };
        mCreateFilterAction.setToolTipText("Create Filter");
        mCreateFilterAction.setImageDescriptor(loader
                .loadDescriptor("add.png")); // $NON-NLS-1$

        mEditFilterAction = new CommonAction("Edit Filter") {
            @Override
            public void run() {
                mLogPanel.editFilter();
            }
        };
        mEditFilterAction.setToolTipText("Edit Filter");
        mEditFilterAction.setImageDescriptor(loader
                .loadDescriptor("edit.png")); // $NON-NLS-1$

        mDeleteFilterAction = new CommonAction("Delete Filter") {
            @Override
            public void run() {
                mLogPanel.deleteFilter();
            }
        };
        mDeleteFilterAction.setToolTipText("Delete Filter");
        mDeleteFilterAction.setImageDescriptor(loader
                .loadDescriptor("delete.png")); // $NON-NLS-1$

        mExportAction = new CommonAction("Export Selection As Text...") {
            @Override
            public void run() {
                mLogPanel.save();
            }
        };
        mExportAction.setToolTipText("Export Selection As Text...");
        mExportAction.setImageDescriptor(loader.loadDescriptor("save.png")); // $NON-NLS-1$

        LogLevel[] levels = LogLevel.values();
        mLogLevelActions = new CommonAction[mLogLevelIcons.length];
        for (int i = 0 ; i < mLogLevelActions.length; i++) {
            String name = levels[i].getStringValue();
            mLogLevelActions[i] = new CommonAction(name, IAction.AS_CHECK_BOX) {
                @Override
                public void run() {
                    // disable the other actions and record current index
                    for (int i = 0 ; i < mLogLevelActions.length; i++) {
                        Action a = mLogLevelActions[i];
                        if (a == this) {
                            a.setChecked(true);

                            // set the log level
                            mLogPanel.setCurrentFilterLogLevel(i+2);
                        } else {
                            a.setChecked(false);
                        }
                    }
                }
            };

            mLogLevelActions[i].setToolTipText(name);
            mLogLevelActions[i].setImageDescriptor(loader.loadDescriptor(mLogLevelIcons[i]));
        }

        mClearAction = new Action("Clear Log") {
            @Override
            public void run() {
                mLogPanel.clear();
            }
        };
        mClearAction.setImageDescriptor(loader
                .loadDescriptor("clear.png")); // $NON-NLS-1$


        // now create the log view
        mLogPanel = new LogPanel(loader, colors, new FilterStorage(), LogPanel.FILTER_MANUAL);
        mLogPanel.setActions(mDeleteFilterAction, mEditFilterAction, mLogLevelActions);

        // get the font
        String fontStr = DdmsPlugin.getDefault().getPreferenceStore().getString(
                PreferenceInitializer.ATTR_LOGCAT_FONT);
        if (fontStr != null) {
            FontData data = new FontData(fontStr);

            if (fontStr != null) {
                mLogPanel.setFont(new Font(parent.getDisplay(), data));
            }
        }

        mLogPanel.createPanel(parent);
        setSelectionDependentPanel(mLogPanel);

        // place the actions.
        placeActions();

        // setup the copy action
        mClipboard = new Clipboard(d);
        IActionBars actionBars = getViewSite().getActionBars();
        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), new Action("Copy") {
            @Override
            public void run() {
                mLogPanel.copy(mClipboard);
            }
        });

        // setup the select all action
        actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
                new Action("Select All") {
            @Override
            public void run() {
                mLogPanel.selectAll();
            }
        });
    
public voiddispose()

        mLogPanel.stopLogCat(true);
        mClipboard.dispose();
    
public static com.android.ide.eclipse.ddms.views.LogCatViewgetInstance()
Returns the singleton instance.

        return sThis;
    
private voidplaceActions()
Place the actions in the ui.

        IActionBars actionBars = getViewSite().getActionBars();

        // first in the menu
        IMenuManager menuManager = actionBars.getMenuManager();
        menuManager.add(mCreateFilterAction);
        menuManager.add(mEditFilterAction);
        menuManager.add(mDeleteFilterAction);
        menuManager.add(new Separator());
        menuManager.add(mClearAction);
        menuManager.add(new Separator());
        menuManager.add(mExportAction);

        // and then in the toolbar
        IToolBarManager toolBarManager = actionBars.getToolBarManager();
        for (CommonAction a : mLogLevelActions) {
            toolBarManager.add(a);
        }
        toolBarManager.add(new Separator());
        toolBarManager.add(mCreateFilterAction);
        toolBarManager.add(mEditFilterAction);
        toolBarManager.add(mDeleteFilterAction);
        toolBarManager.add(new Separator());
        toolBarManager.add(mClearAction);
    
public voidsetFocus()

        mLogPanel.setFocus();
    
public static voidsetFont(org.eclipse.swt.graphics.Font font)
Sets the display font.

param
font The font.

        if (sThis != null && sThis.mLogPanel != null) {
            sThis.mLogPanel.setFont(font);
        }