Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 06bd60490b42a18a6b5f765b7385185c33185fb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsdl.ui.internal.util.flatui;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.TableTree;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;


public class WidgetFactory {	
  public static final String DEFAULT_HEADER_COLOR = "__default__header__";
  public static final String COLOR_BACKGROUND = "__bg";
  public static final String COLOR_BORDER = "__border";
  public static final String COLOR_COMPOSITE_SEPARATOR = "__compSep";
  public static final String COLOR_HYPERLINK="__hyperlink";
    
  private Hashtable colorRegistry = new Hashtable();
  private Color backgroundColor;
  private Color clientAreaColor;
  private KeyListener deleteListener;
  private Color foregroundColor;
  private Color fReadOnlyColor;
  private Display fDisplay;
  public static final int BORDER_STYLE = SWT.NONE;
  private BorderPainter borderPainter;
  private Color borderColor;
  private HyperlinkHandler hyperlinkHandler;
  private static Image fBanner;
  

  class BorderPainter implements PaintListener {
        public void paintControl(PaintEvent event) {
            Composite composite = (Composite) event.widget;
            Control[] children = composite.getChildren();
            for (int i = 0; i < children.length; i++) {
                Control c = children[i];
                //if (c.isEnabled()==false) continue;
                if (c instanceof Text
                    || c instanceof Canvas
                    || c instanceof CCombo) {
                    Rectangle b = c.getBounds();
                    GC gc = event.gc;
                    gc.setForeground(c.getBackground());
                    gc.drawRectangle(b.x - 1, b.y - 1, b.width + 1, b.height + 1);
                    gc.setForeground(foregroundColor);
                    gc.drawRectangle(b.x - 2, b.y - 2, b.width + 3, b.height + 3);
                }
                else if (c instanceof Table
                    || c instanceof Tree
                    || c instanceof TableTree) {
                    Rectangle b = c.getBounds();
                    GC gc = event.gc;
                    gc.setForeground(borderColor);
                    //gc.drawRectangle(b.x - 2, b.y - 2, b.width + 3, b.height + 3);
                    gc.drawRectangle(b.x-1, b.y-1, b.width+2, b.height+2);
                }
            }
        }
    }


public WidgetFactory() {
 	fDisplay = Display.getDefault();
    initialize();
}

public Button createButton(Composite parent, String text, int style) {
    int flatStyle = BORDER_STYLE == SWT.BORDER ? SWT.NULL : SWT.FLAT;
    //int flatStyle = SWT.NULL;
    Button button = new Button(parent, style | flatStyle);
    button.setBackground(backgroundColor);
    button.setForeground(foregroundColor);
    if (text!=null) button.setText(text);
    return button;
}
public Composite createComposite(Composite parent) {
    return createComposite(parent, SWT.NULL);
}
public Composite createComposite(Composite parent, int style) {
    Composite composite = new Composite(parent, style);
    composite.setBackground(backgroundColor);
    return composite;
}
public Composite createCompositeSeparator(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setBackground(getColor(COLOR_COMPOSITE_SEPARATOR));
    return composite;
}
public Group createGroup(Composite parent, String text) {
	Group group = new Group(parent, SWT.SHADOW_NONE);
	group.setText(text);
    group.setBackground(backgroundColor);
    group.setForeground(foregroundColor);
	return group;
}
public Label createHeadingLabel(Composite parent, String text, Color bg) {
    return createHeadingLabel(parent, text, bg, SWT.NONE);
}
public Label createHeadingLabel(Composite parent, String text, Color bg, int style) {
    Label label = new Label(parent, style);
    label.setText(text);
    label.setBackground(backgroundColor);
    label.setForeground(foregroundColor);
    label.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT));
    return label;
}
public Label createHyperlinkLabel(Composite parent, String text, IHyperlinkListener listener) {
    return createHyperlinkLabel(parent, text, listener, SWT.NULL);
}
public Label createHyperlinkLabel(Composite parent, String text, IHyperlinkListener listener, int style) {
    Label label = createLabel(parent, text, style);
    turnIntoHyperlink(label, listener);
    return label;
}
public Label createLabel(Composite parent, String text) {
    return createLabel(parent, text, SWT.NONE);
}
public Label createLabel(Composite parent, String text, int style) {
    Label label = new Label(parent, style);
    if (text!=null) label.setText(text);
    label.setBackground(backgroundColor);
    label.setForeground(foregroundColor);
    return label;
}
public Label createSeparator(Composite parent, int style) {
    Label label = new Label(parent, SWT.SEPARATOR | style);
    label.setBackground(backgroundColor);
    label.setForeground(borderColor);
    return label;
}
public ScrolledComposite createScrolledComposite (Composite parent) {
	ScrolledComposite scrolledcomposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    scrolledcomposite.setBackground(backgroundColor);
    scrolledcomposite.setForeground(foregroundColor);
    return scrolledcomposite;
}
public Table createTable(Composite parent, int style) {
    Table table = new Table(parent, BORDER_STYLE | style);
    table.setBackground(backgroundColor);
    table.setForeground(foregroundColor);
    //hookDeleteListener(table);
    return table;
}
public Text createText(Composite parent, String value) {
    return createText(parent, value, BORDER_STYLE | SWT.SINGLE);
}
public Text createText(Composite parent, String value, int style) {
    Text text = new Text(parent, style);
    text.setText(value);
    text.setBackground(clientAreaColor);
    text.setForeground(foregroundColor);
    if ((style & SWT.READ_ONLY) != 0)
    	text.setForeground(fReadOnlyColor);
    return text;
}
public Tree createTree(Composite parent, int style) {
    Tree tree = new Tree(parent, BORDER_STYLE | style);
    tree.setBackground(backgroundColor);
    tree.setForeground(foregroundColor);
    //hookDeleteListener(tree);
    return tree;
}
/* 
private void deleteKeyPressed(Widget widget) {
    if (!(widget instanceof Control)) return;
    Control control = (Control)widget;
    for (Control parent = control.getParent();
        parent != null;
        parent = parent.getParent()) {
        if (parent.getData() instanceof FormSection) {
            FormSection section = (FormSection) parent.getData();
            section.doGlobalAction(IWorkbenchActionConstants.DELETE);
            break;
        }
    }
}
*/
public ViewForm createViewForm(Composite parent) {
	ViewForm viewForm = new ViewForm(parent, SWT.NULL);
    viewForm.setBackground(clientAreaColor);
    viewForm.setForeground(foregroundColor);
    return viewForm;
}
public void dispose() {
    Enumeration colors= colorRegistry.elements();
    while (colors.hasMoreElements()) {
        Color c = (Color)colors.nextElement();
        c.dispose();
    }
    hyperlinkHandler.dispose();
    colorRegistry=null;
    if (fBanner != null)
    {
      fBanner.dispose();
      fBanner = null;
    }
}
public Color getBackgroundColor() {
    return backgroundColor;
}
public Image getBanner() {
  if (fBanner == null)
  {
    try {
      fBanner = (ImageDescriptor.createFromURL(new URL((WSDLEditorPlugin.getInstance().getDescriptor().getInstallURL()), "icons\form_banner.gif"))).createImage();
      System.out.println("Created Image!!!! ");
    } catch (MalformedURLException e) {
      System.out.println("Exception!!!! " + e);
    }
  }
  return fBanner;
}
public Color getBorderColor() {
    return borderColor;
}
public Cursor getBusyCursor() {
    return hyperlinkHandler.getBusyCursor();
}
public Color getClientAreaColor() {
    return clientAreaColor;
}
public Color getColor(String key) {
    return (Color)colorRegistry.get(key);
}
public Color getForegroundColor() {
    return foregroundColor;
}
public Color getHyperlinkColor() {
    return hyperlinkHandler.getForeground();
}
public Cursor getHyperlinkCursor() {
    return hyperlinkHandler.getHyperlinkCursor();
}
public Color getHyperlinkHoverColor() {
    return hyperlinkHandler.getActiveForeground();
}
public int getHyperlinkUnderlineMode() {
    return hyperlinkHandler.getHyperlinkUnderlineMode();
}
/*
public void hookDeleteListener(Control control) {
    if (deleteListener == null) {
        deleteListener = new KeyAdapter() {
            public void keyPressed(KeyEvent event) {
                if (event.character == SWT.DEL && event.stateMask == 0) {
                    deleteKeyPressed(event.widget);
                }
            }
        };
    }
    control.addKeyListener(deleteListener);
}
*/
  private void initStaticColors()
  {
    if (colorRegistry == null)
    {
      colorRegistry = new Hashtable();
      registerColor(COLOR_BACKGROUND, 0xff, 0xfe, 0xf9);
      registerColor(COLOR_BORDER, 195, 191, 179);
      registerColor(COLOR_COMPOSITE_SEPARATOR, 152, 170, 203);
      registerColor(DEFAULT_HEADER_COLOR, 0x48, 0x70, 0x98);
      registerColor(COLOR_HYPERLINK, 0, 0, 153);
    }
  }

private void initialize() {
    clientAreaColor = fDisplay.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    fReadOnlyColor = fDisplay.getSystemColor(SWT.COLOR_DARK_GRAY);
    initStaticColors();
    backgroundColor = clientAreaColor;
    borderColor = getColor(COLOR_BORDER);
    foregroundColor = fDisplay.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
    hyperlinkHandler = new HyperlinkHandler();
    hyperlinkHandler.setForeground(getColor(COLOR_HYPERLINK));
    hyperlinkHandler.setBackground(backgroundColor);
}
public void paintBordersFor(Composite parent) {
    if (BORDER_STYLE == SWT.BORDER) return;
    if (borderPainter==null) borderPainter = new BorderPainter();
    parent.addPaintListener(borderPainter);
}
public Color registerColor(String key, int r, int g, int b) {
    Color c = new Color(fDisplay, r, g, b);
    colorRegistry.put(key, c);
    return c;
}

public void setClientAreaColor(Color color)
{
  clientAreaColor = color;
  backgroundColor = clientAreaColor;
}

public void setHyperlinkColor(Color color) {
    hyperlinkHandler.setForeground(color);
}
public void setHyperlinkHoverColor(org.eclipse.swt.graphics.Color hoverColor) {
    hyperlinkHandler.setActiveForeground(hoverColor);
}
public void setHyperlinkUnderlineMode(int newHyperlinkUnderlineMode) {
    hyperlinkHandler.setHyperlinkUnderlineMode(newHyperlinkUnderlineMode);
}
public void turnIntoHyperlink(Control control, IHyperlinkListener listener) {
    hyperlinkHandler.registerHyperlink(control, listener);
}

}





Back to the top