4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Kangho Kim <kh5325.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 package org.tizen.common.swt;
28 import org.eclipse.jface.action.ContributionItem;
29 import org.eclipse.jface.action.ToolBarManager;
30 import org.eclipse.jface.dialogs.DialogTray;
31 import org.eclipse.jface.dialogs.TrayDialog;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.graphics.Color;
34 import org.eclipse.swt.graphics.GC;
35 import org.eclipse.swt.graphics.Image;
36 import org.eclipse.swt.graphics.ImageData;
37 import org.eclipse.swt.graphics.PaletteData;
38 import org.eclipse.swt.graphics.RGB;
39 import org.eclipse.swt.layout.GridData;
40 import org.eclipse.swt.layout.GridLayout;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.swt.widgets.Control;
43 import org.eclipse.swt.widgets.Display;
44 import org.eclipse.swt.widgets.Event;
45 import org.eclipse.swt.widgets.Label;
46 import org.eclipse.swt.widgets.Listener;
47 import org.eclipse.swt.widgets.Shell;
48 import org.eclipse.swt.widgets.ToolBar;
49 import org.eclipse.swt.widgets.ToolItem;
53 * a extended DialogTray class that user can be closing
55 * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core)
57 public abstract class ClosableTray extends DialogTray {
58 private Image closeNormal;
59 private Image closeHover;
62 private void createImages() {
63 Display display = Display.getCurrent();
64 int[] shape = new int[] {
65 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10, 8, 12, 10,
66 12, 12, 10, 12, 8, 10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5
70 Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
71 Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
72 Color backgroundHot = new Color(display, new RGB(252, 160, 160));
73 Color transparent = display.getSystemColor(SWT.COLOR_MAGENTA);
75 PaletteData palette = new PaletteData(new RGB[] {
76 transparent.getRGB(), border.getRGB(), background.getRGB(), backgroundHot.getRGB()
78 ImageData data = new ImageData(16, 16, 8, palette);
79 data.transparentPixel = 0;
82 closeNormal = new Image(display, data);
83 closeNormal.setBackground(transparent);
84 GC gc = new GC(closeNormal);
85 gc.setBackground(background);
86 gc.fillPolygon(shape);
87 gc.setForeground(border);
88 gc.drawPolygon(shape);
91 // create hovered close image
92 closeHover = new Image(display, data);
93 closeHover.setBackground(transparent);
94 gc = new GC(closeHover);
95 gc.setBackground(backgroundHot);
96 gc.fillPolygon(shape);
97 gc.setForeground(border);
98 gc.drawPolygon(shape);
101 backgroundHot.dispose();
105 protected Control createContents(Composite parent) {
106 shell = parent.getShell();
108 // appearence composite
109 Composite container = new Composite(parent, SWT.NONE);
110 GridLayout layout = new GridLayout();
111 layout.marginWidth = layout.marginHeight = 0;
112 layout.verticalSpacing = 0;
113 container.setLayout(layout);
114 container.addListener(SWT.Dispose, new Listener() {
116 public void handleEvent(Event event) {
121 // top toolbar composite
122 ToolBarManager tbm = new ToolBarManager(SWT.FLAT);
123 tbm.createControl(container);
124 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
125 gd.grabExcessHorizontalSpace = true;
126 tbm.getControl().setLayoutData(gd);
128 // horizontal separator
129 Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
130 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
132 separator.setLayoutData(gd);
134 // create external composite
135 createExternalControl(container);
137 // create close button image
141 tbm.add(new ContributionItem() {
143 public void fill(ToolBar parent, int index) {
144 final ToolItem item = new ToolItem(parent, SWT.PUSH);
145 item.setImage(closeNormal);
146 item.setHotImage(closeHover);
147 item.addListener(SWT.Selection, new Listener() {
149 public void handleEvent(Event event) {
150 TrayDialog dialog = (TrayDialog) shell.getData();
162 public abstract void createExternalControl(Composite parent);
164 protected void dispose() {
165 if (closeNormal != null) {
166 closeNormal.dispose();
168 if (closeHover != null) {
169 closeHover.dispose();