comparison examples/texteditor/Images.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children 8a1930f94cbb
comparison
equal deleted inserted replaced
76:04f122e90b0a 78:4a04b6759f98
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language:
11 * Thomas Graber <d4rkdragon@gmail.com>
12 *******************************************************************************/
13 module examples.texteditor.Images;
14
15 import dwt.dwthelper.InputStream;
16
17 import dwt.graphics.Image;
18 import dwt.graphics.ImageData;
19 import dwt.widgets.Display;
20 import dwt.dwthelper.ByteArrayInputStream;
21
22 import tango.core.Exception;
23 import tango.io.Stdout;
24
25 public class Images {
26
27 // Bitmap Images
28 public Image Bold;
29 public Image Italic;
30 public Image Underline;
31 public Image Strikeout;
32 public Image Red;
33 public Image Green;
34 public Image Blue;
35 public Image Erase;
36
37 Image[] AllBitmaps;
38
39 this () {
40 }
41
42 public void freeAll () {
43 for (int i=0; i<AllBitmaps.length; i++) AllBitmaps [i].dispose ();
44 AllBitmaps = null;
45 }
46
47 Image createBitmapImage(Display display, void[] iImage, void[] iMask) {
48 InputStream sourceStream = new ByteArrayInputStream(cast(byte[]) iImage);
49 InputStream maskStream = new ByteArrayInputStream(cast(byte[])iMask );
50
51 ImageData source = new ImageData (sourceStream);
52 ImageData mask = new ImageData (maskStream);
53 Image result = new Image (null, source, mask);
54 try {
55 sourceStream.close ();
56 maskStream.close ();
57 } catch (IOException e) {
58 Stderr.formatln( "Stacktrace: {}", e.toString );
59 }
60 return result;
61 }
62
63 public void loadAll (Display display) {
64 // Bitmap Images
65 Bold = createBitmapImage (display, import( "dwtexamples.texteditor.bold.bmp" ), import( "dwtexamples.texteditor.bold_mask.bmp" ));
66 Italic = createBitmapImage (display, import( "dwtexamples.texteditor.italic.bmp" ), import( "dwtexamples.texteditor.italic_mask.bmp" ));
67 Underline = createBitmapImage (display, import( "dwtexamples.texteditor.underline.bmp" ), import( "dwtexamples.texteditor.underline_mask.bmp" ));
68 Strikeout = createBitmapImage (display, import( "dwtexamples.texteditor.strikeout.bmp" ), import( "dwtexamples.texteditor.strikeout_mask.bmp" ));
69 Red = createBitmapImage (display, import( "dwtexamples.texteditor.red.bmp" ), import( "dwtexamples.texteditor.red_mask.bmp" ));
70 Green = createBitmapImage (display, import( "dwtexamples.texteditor.green.bmp" ), import( "dwtexamples.texteditor.green_mask.bmp" ));
71 Blue = createBitmapImage (display, import( "dwtexamples.texteditor.blue.bmp" ), import( "dwtexamples.texteditor.blue_mask.bmp" ));
72 Erase = createBitmapImage (display, import( "dwtexamples.texteditor.erase.bmp" ), import( "dwtexamples.texteditor.erase_mask.bmp" ));
73
74 AllBitmaps = [ Bold,
75 Italic,
76 Underline,
77 Strikeout,
78 Red,
79 Green,
80 Blue,
81 Erase
82 ];
83 }
84 }