trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/dialog/ShowTraceInfoDialog.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     1 /*
       
     2  * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  * Show Trace Information Dialog class
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.dialog;
       
    20 
       
    21 import java.util.List;
       
    22 
       
    23 import org.eclipse.swt.SWT;
       
    24 import org.eclipse.swt.custom.StyleRange;
       
    25 import org.eclipse.swt.custom.StyledText;
       
    26 import org.eclipse.swt.graphics.Font;
       
    27 import org.eclipse.swt.graphics.FontData;
       
    28 import org.eclipse.swt.graphics.Point;
       
    29 import org.eclipse.swt.layout.GridData;
       
    30 import org.eclipse.swt.layout.GridLayout;
       
    31 import org.eclipse.swt.widgets.Shell;
       
    32 import org.eclipse.ui.PlatformUI;
       
    33 
       
    34 import com.nokia.traceviewer.TraceViewerHelpContextIDs;
       
    35 
       
    36 /**
       
    37  * Show Trace Information Dialog class
       
    38  * 
       
    39  */
       
    40 public final class ShowTraceInfoDialog extends BaseDialog {
       
    41 
       
    42 	/**
       
    43 	 * Font to use
       
    44 	 */
       
    45 	private static final String FONT = "Courier New"; //$NON-NLS-1$
       
    46 
       
    47 	/**
       
    48 	 * View font size
       
    49 	 */
       
    50 	public static final int FONT_SIZE = 8;
       
    51 
       
    52 	/**
       
    53 	 * Contents of the dialog
       
    54 	 */
       
    55 	private final String contents;
       
    56 
       
    57 	/**
       
    58 	 * List containing style ranges
       
    59 	 */
       
    60 	private final List<StyleRange> styleRanges;
       
    61 
       
    62 	/**
       
    63 	 * Constructor
       
    64 	 * 
       
    65 	 * @param parent
       
    66 	 *            parent shell
       
    67 	 * @param text
       
    68 	 *            contents of the dialog
       
    69 	 * @param styleRanges
       
    70 	 *            style ranges
       
    71 	 */
       
    72 	public ShowTraceInfoDialog(Shell parent, String text,
       
    73 			List<StyleRange> styleRanges) {
       
    74 		super(parent, SWT.DIALOG_TRIM | SWT.MODELESS | SWT.RESIZE);
       
    75 		this.contents = text;
       
    76 		this.styleRanges = styleRanges;
       
    77 	}
       
    78 
       
    79 	/*
       
    80 	 * (non-Javadoc)
       
    81 	 * 
       
    82 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createDialogContents()
       
    83 	 */
       
    84 	@Override
       
    85 	protected void createDialogContents() {
       
    86 		// Shell
       
    87 		GridLayout shellGridLayout = new GridLayout();
       
    88 		getShell().setText(Messages.getString("ShowTraceInfoDialog.ShellName")); //$NON-NLS-1$
       
    89 		composite.setLayout(shellGridLayout);
       
    90 
       
    91 		// Text field
       
    92 		GridData textGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
       
    93 		StyledText text = new StyledText(composite, SWT.MULTI | SWT.BORDER
       
    94 				| SWT.WRAP | SWT.V_SCROLL);
       
    95 		Font font = new Font(getShell().getDisplay(), new FontData(FONT,
       
    96 				FONT_SIZE, SWT.NORMAL));
       
    97 		text.setFont(font);
       
    98 		text.setBackground(getShell().getDisplay().getSystemColor(
       
    99 				SWT.COLOR_WHITE));
       
   100 		text.setEditable(false);
       
   101 		text.setText(contents);
       
   102 		text.setLayoutData(textGridData);
       
   103 
       
   104 		// Color header and data parts
       
   105 		StyleRange[] ranges = new StyleRange[styleRanges.size()];
       
   106 		for (int i = 0; i < styleRanges.size(); i++) {
       
   107 			ranges[i] = styleRanges.get(i);
       
   108 		}
       
   109 
       
   110 		// Run this inside try catch to still show dialog if style ranges are
       
   111 		// invalid
       
   112 		try {
       
   113 			text.setStyleRanges(ranges);
       
   114 		} catch (Exception e) {
       
   115 		}
       
   116 
       
   117 		// Set help
       
   118 		PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(),
       
   119 				TraceViewerHelpContextIDs.TRACE_INFO_DIALOG);
       
   120 	}
       
   121 
       
   122 	/*
       
   123 	 * (non-Javadoc)
       
   124 	 * 
       
   125 	 * @see org.eclipse.jface.dialogs.Dialog#initializeBounds()
       
   126 	 */
       
   127 	@Override
       
   128 	protected void initializeBounds() {
       
   129 		getShell().setSize(new Point(300, 360));
       
   130 		super.initializeBounds();
       
   131 	}
       
   132 
       
   133 	/*
       
   134 	 * (non-Javadoc)
       
   135 	 * 
       
   136 	 * @see com.nokia.traceviewer.dialog.BaseDialog#createActionListeners()
       
   137 	 */
       
   138 	@Override
       
   139 	protected void createActionListeners() {
       
   140 	}
       
   141 }