author | dadubrow |
Tue, 27 Jul 2010 15:29:41 -0500 | |
changeset 1705 | 71a151b1b515 |
parent 1684 | c2eba6dabd38 |
child 2031 | 736964f28d2a |
permissions | -rw-r--r-- |
1609 | 1 |
/* |
2 |
* Copyright (c) 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 the License "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 |
*/ |
|
17 |
package com.nokia.carbide.internal.discovery.ui.editor; |
|
18 |
||
19 |
import java.util.LinkedHashMap; |
|
20 |
import java.util.Map; |
|
21 |
||
22 |
import org.eclipse.jface.layout.RowDataFactory; |
|
23 |
import org.eclipse.jface.layout.RowLayoutFactory; |
|
1618 | 24 |
import org.eclipse.jface.resource.FontDescriptor; |
25 |
import org.eclipse.jface.resource.JFaceResources; |
|
1609 | 26 |
import org.eclipse.swt.SWT; |
27 |
import org.eclipse.swt.events.SelectionAdapter; |
|
28 |
import org.eclipse.swt.events.SelectionEvent; |
|
29 |
import org.eclipse.swt.events.SelectionListener; |
|
30 |
import org.eclipse.swt.graphics.Font; |
|
1618 | 31 |
import org.eclipse.swt.graphics.FontData; |
1609 | 32 |
import org.eclipse.swt.widgets.Button; |
33 |
import org.eclipse.swt.widgets.Composite; |
|
34 |
||
35 |
class NavigationBar extends RoundedCornerComposite { |
|
36 |
||
37 |
private PortalEditor portalEditor; |
|
38 |
||
39 |
||
40 |
private final class ButtonListener extends SelectionAdapter { |
|
41 |
@Override |
|
42 |
public void widgetSelected(SelectionEvent e) { |
|
43 |
Button button = (Button) e.getSource(); |
|
44 |
selectNavButton(button); |
|
45 |
} |
|
46 |
} |
|
47 |
||
1684
c2eba6dabd38
refactor to allow better support for multiple layers
dadubrow
parents:
1634
diff
changeset
|
48 |
private Map<Button, PortalPage> buttonToPageMap; |
1609 | 49 |
private SelectionListener listener; |
50 |
private Font buttonFont; |
|
51 |
private Font selectedButtonFont; |
|
52 |
||
53 |
NavigationBar(PortalEditor portalEditor, Composite parent) { |
|
54 |
super(parent, portalEditor.getBackgroundParent(), |
|
55 |
parent.getDisplay().getSystemColor(SWT.COLOR_BLACK), |
|
56 |
parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
|
57 |
this.portalEditor = portalEditor; |
|
1684
c2eba6dabd38
refactor to allow better support for multiple layers
dadubrow
parents:
1634
diff
changeset
|
58 |
buttonToPageMap = new LinkedHashMap<Button, PortalPage>(); |
1618 | 59 |
RowLayoutFactory.swtDefaults().margins(3, 3).wrap(false).applyTo(this); |
1609 | 60 |
listener = new ButtonListener(); |
1618 | 61 |
selectedButtonFont = JFaceResources.getHeaderFont(); |
62 |
FontData[] fontData = selectedButtonFont.getFontData(); |
|
63 |
for (FontData fd : fontData) { |
|
64 |
fd.setStyle(SWT.NORMAL); |
|
65 |
} |
|
66 |
FontDescriptor desc = FontDescriptor.createFrom(fontData); |
|
67 |
buttonFont = portalEditor.createFont(desc); |
|
1609 | 68 |
} |
69 |
||
70 |
public void initUI() { |
|
71 |
if (buttonToPageMap.isEmpty()) |
|
72 |
return; |
|
73 |
selectNavButton(buttonToPageMap.keySet().iterator().next()); |
|
74 |
} |
|
75 |
||
1684
c2eba6dabd38
refactor to allow better support for multiple layers
dadubrow
parents:
1634
diff
changeset
|
76 |
public void addNavButton(NavigationBar bar, PortalPage page) { |
1609 | 77 |
Button b = new Button(bar, SWT.TOGGLE | SWT.FLAT); |
78 |
b.setFont(buttonFont); |
|
1705 | 79 |
b.setText(page.getTitle()); |
80 |
b.setImage(portalEditor.createImage(page.getImageDescriptor(), 16, 16)); |
|
1609 | 81 |
b.addSelectionListener(listener); |
1618 | 82 |
RowDataFactory.swtDefaults().applyTo(b); |
1609 | 83 |
buttonToPageMap.put(b, page); |
84 |
} |
|
85 |
||
86 |
||
87 |
public void selectNavButton(Button button) { |
|
88 |
for (Button other : buttonToPageMap.keySet()) { |
|
89 |
other.setSelection(false); |
|
90 |
other.setFont(buttonFont); |
|
91 |
} |
|
92 |
button.setSelection(true); |
|
1618 | 93 |
portalEditor.showPage(buttonToPageMap.get(button)); |
1609 | 94 |
button.setFont(selectedButtonFont); |
1618 | 95 |
layout(); |
96 |
} |
|
97 |
||
98 |
@Override |
|
99 |
public void layout() { |
|
100 |
super.layout(); |
|
101 |
pack(); |
|
1609 | 102 |
} |
103 |
} |