1 /*******************************************************************************
2  * Copyright (c) 2010 - 2013 by Timotei Dolean <timotei21@gmail.com>
3  *
4  * This program and the accompanying materials are made available
5  * under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *******************************************************************************/
9 package org.wesnoth.ui.labeling.wmldoc;
10 
11 import org.eclipse.jface.dialogs.PopupDialog;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.custom.StyledText;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Shell;
20 
21 /**
22  * Presents WMLDoc to the user
23  */
24 public class WMLDocInformationPresenter extends PopupDialog
25 {
26     private Point           bounds_;
27     private IWMLDocProvider currentDocProvider_;
28     private Composite       panel_;
29 
30     /**
31      * Creates a new WMLDocumentation information presenter
32      *
33      * @param parent
34      *        The parent shell
35      * @param docProvider
36      *        The WMLDoc provider
37      * @param bounds
38      *        The bounds of the presented dialog
39      */
WMLDocInformationPresenter( Shell parent, IWMLDocProvider docProvider, Point bounds )40     public WMLDocInformationPresenter( Shell parent,
41         IWMLDocProvider docProvider, Point bounds )
42     {
43         super( parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true,
44             true, false, false, docProvider.getTitle( ), docProvider
45                 .getInfoText( ) );
46 
47         bounds_ = bounds;
48         currentDocProvider_ = docProvider;
49     }
50 
51     @Override
createDialogArea( Composite parent )52     protected Control createDialogArea( Composite parent )
53     {
54         panel_ = new Composite( parent, SWT.None );
55         panel_.setBackground( parent.getDisplay( ).getSystemColor(
56             SWT.COLOR_INFO_BACKGROUND ) );
57         panel_.setForeground( parent.getDisplay( ).getSystemColor(
58             SWT.COLOR_INFO_FOREGROUND ) );
59 
60         GridLayout grid = new GridLayout( );
61         grid.numColumns = 5;
62         panel_.setLayout( grid );
63 
64         StyledText text = new StyledText( panel_, SWT.NONE );
65 
66         text.setText( currentDocProvider_.getContents( ) );
67         text.setEditable( false );
68         text.setStyleRanges( currentDocProvider_.getStyleRanges( ) );
69 
70         text.setLayoutData( createDefaultGridData( 4 ) );
71         return panel_;
72     }
73 
createDefaultGridData( int columnspan )74     private GridData createDefaultGridData( int columnspan )
75     {
76         GridData gd = new GridData( );
77         gd.horizontalSpan = columnspan;
78         gd.verticalAlignment = SWT.BEGINNING;
79         gd.verticalIndent = 0;
80         gd.horizontalIndent = 5;
81         return gd;
82     }
83 
84     @Override
getInitialLocation( Point initialSize )85     protected Point getInitialLocation( Point initialSize )
86     {
87         return bounds_;
88     }
89 }
90