KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > swt > PageFormWithNavigation


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.intro.impl.swt;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Image;
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.Label;
20 import org.eclipse.ui.forms.IFormColors;
21 import org.eclipse.ui.forms.widgets.Form;
22 import org.eclipse.ui.forms.widgets.FormToolkit;
23 import org.eclipse.ui.forms.widgets.ImageHyperlink;
24 import org.eclipse.ui.forms.widgets.ScrolledPageBook;
25 import org.eclipse.ui.internal.intro.impl.model.IntroLink;
26 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
27 import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
28
29 /**
30  * Extends the UI of a PageForm and adds a navigation toolbar UI for the root
31  * page links.
32  */

33 public class PageFormWithNavigation extends PageForm {
34
35     private PageStyleManager rootPageStyleManager;
36
37     // Id to this page. There is only a single instance of this page in the
38
// main page book.
39
public static String JavaDoc PAGE_FORM_WITH_NAVIGATION_ID = "pageFormWithNavigationId"; //$NON-NLS-1$
40

41
42     /**
43      *
44      */

45     public PageFormWithNavigation(FormToolkit toolkit,
46             IntroModelRoot modelRoot, Form parentForm) {
47         super(toolkit, modelRoot, parentForm);
48     }
49
50     /**
51      * Extend parent behavior and add navigation.
52      *
53      * @param pageBook
54      */

55     public void createPartControl(ScrolledPageBook mainPageBook,
56             SharedStyleManager sharedStyleManager) {
57
58         super.createPartControl(mainPageBook, sharedStyleManager);
59
60         // Create a style manager from shared style manager. We only need it
61
// for the UI navigation composite.
62
rootPageStyleManager = new PageStyleManager(model.getHomePage(),
63             sharedStyleManager.getProperties());
64
65         // Now create Navigation bar.
66
Composite navigationComposite = toolkit.createComposite(pageForm
67             .getBody());
68         navigationComposite.setLayoutData(new GridData(
69             GridData.HORIZONTAL_ALIGN_CENTER));
70         int numberOfLinks = model.getHomePage().getLinks().length;
71         GridLayout layout = new GridLayout();
72         layout.numColumns = numberOfLinks;
73         navigationComposite.setLayout(layout);
74         createSmallNavigator(navigationComposite, model.getHomePage()
75             .getLinks());
76
77         pageForm.setText(rootPageStyleManager.getPageSubTitle());
78     }
79
80     /**
81      * Override parent id.
82      */

83     protected String JavaDoc getId() {
84         return PAGE_FORM_WITH_NAVIGATION_ID;
85     }
86
87     private void createSmallNavigator(Composite parent, IntroLink[] links) {
88         for (int i = 0; i < links.length; i++) {
89             Control c = createImageHyperlink(parent, links[i]);
90             c.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
91         }
92         for (int i = 0; i < links.length; i++) {
93             Label text = toolkit.createLabel(parent, links[i].getLabel());
94             text.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
95             text.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
96         }
97     }
98
99     /**
100      * Creates an Image Hyperlink from an IntroLink. Model object is NOT cached.
101      *
102      * @param body
103      * @param link
104      */

105     private Control createImageHyperlink(Composite body, IntroLink link) {
106         ImageHyperlink imageLink = toolkit.createImageHyperlink(body, SWT.NULL);
107
108         // set link image.
109
Image image = rootPageStyleManager.getImage(link, "small-link-icon", //$NON-NLS-1$
110
ImageUtil.DEFAULT_SMALL_ROOT_LINK);
111         imageLink.setImage(image);
112
113         // set link hover image.
114
image = rootPageStyleManager.getImage(link, "small-hover-icon", null); //$NON-NLS-1$
115
imageLink.setHoverImage(image);
116         imageLink.setToolTipText(link.getLabel());
117         // each link is centered in cell.
118
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
119         imageLink.setLayoutData(gd);
120         imageLink.setHref(link.getUrl());
121         imageLink.addHyperlinkListener(hyperlinkAdapter);
122         return imageLink;
123     }
124
125
126 }
127
Popular Tags