Mercurial > projects > dwt2
changeset 30:93b0e7382fd5
SWT Snippets build on windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 23 Mar 2009 10:17:19 +0100 |
parents | 4e5843b771cc |
children | 5d87d4191adf |
files | org.eclipse.swt.snippets/res/eclipse.png org.eclipse.swt.snippets/res/links_obj.gif org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.d org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.d org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.d rakefile |
diffstat | 6 files changed, 289 insertions(+), 267 deletions(-) [+] |
line wrap: on
line diff
--- a/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.d Sun Mar 22 19:55:00 2009 +0100 +++ b/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.d Mon Mar 23 10:17:19 2009 +0100 @@ -11,7 +11,7 @@ * Adam Chrapkowski <adam DOT chrapkowski AT gmail DOT com> *******************************************************************************/ module org.eclipse.swt.snippets.Snippet133; - + /* * Printing example snippet: print text to printer, with word wrap and pagination * @@ -52,21 +52,21 @@ // tango import tango.core.Thread; -import tango.io.File; +import tango.io.device.File; import tango.text.Unicode; public void main(String[] args){ (new Snippet133).open(); } - + class Snippet133{ Display display; Shell shell; Text text; Font font; Color foregroundColor, backgroundColor; - + Printer printer; GC gc; FontData[] printerFontData; @@ -80,96 +80,88 @@ String textToPrint; String tabs; StringBuffer wordBuffer; - + public void - open(){ - display = new Display(); - shell = new Shell(display); - shell.setLayout(new FillLayout()); - shell.setText("Print Text"); - text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + open(){ + display = new Display(); + shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setText("Print Text"); + text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); - Menu menuBar = new Menu(shell, SWT.BAR); - shell.setMenuBar(menuBar); - MenuItem item = new MenuItem(menuBar, SWT.CASCADE); - item.setText("&File"); - Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); - item.setMenu(fileMenu); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("&Open..."); - item.setAccelerator(SWT.CTRL + 'O'); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event) { - menuOpen(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Font..."); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event){ - menuFont(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Foreground Color..."); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event){ - menuForegroundColor(); + Menu menuBar = new Menu(shell, SWT.BAR); + shell.setMenuBar(menuBar); + MenuItem item = new MenuItem(menuBar, SWT.CASCADE); + item.setText("&File"); + Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); + item.setMenu(fileMenu); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("&Open..."); + item.setAccelerator(SWT.CTRL + 'O'); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event) { + menuOpen(); + } + }); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("Font..."); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event){ + menuFont(); + } + }); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("Foreground Color..."); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event){ + menuForegroundColor(); + } + }); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("Background Color..."); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event) { + menuBackgroundColor(); + } + }); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("&Print..."); + item.setAccelerator(SWT.CTRL + 'P'); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event) { + menuPrint(); + } + }); + new MenuItem(fileMenu, SWT.SEPARATOR); + item = new MenuItem(fileMenu, SWT.PUSH); + item.setText("E&xit"); + item.addSelectionListener(new class() SelectionAdapter{ + public void widgetSelected(SelectionEvent event){ + System.exit(0); + } + }); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("Background Color..."); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event) { - menuBackgroundColor(); - } - }); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("&Print..."); - item.setAccelerator(SWT.CTRL + 'P'); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event) { - menuPrint(); - } - }); - new MenuItem(fileMenu, SWT.SEPARATOR); - item = new MenuItem(fileMenu, SWT.PUSH); - item.setText("E&xit"); - item.addSelectionListener(new class() SelectionAdapter{ - public void - widgetSelected(SelectionEvent event){ - System.exit(0); - } - }); - - shell.open(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) display.sleep(); + if (font !is null) font.dispose(); + if (foregroundColor !is null) foregroundColor.dispose(); + if (backgroundColor !is null) backgroundColor.dispose(); + display.dispose(); } - if (font !is null) font.dispose(); - if (foregroundColor !is null) foregroundColor.dispose(); - if (backgroundColor !is null) backgroundColor.dispose(); - display.dispose(); - } - - private void - menuOpen(){ + + private void menuOpen(){ String textString; FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterExtensions(["*.java", "*.*"]); String name = dialog.open(); if(name is null) return; - + try{ - scope File file = new File(name); try{ - textString = cast(char[])file.read; - } + textString = cast(char[])File.get(name); + } catch (IOException e){ MessageBox box = new MessageBox(shell, SWT.ICON_ERROR); box.setMessage("Error reading file:\n" ~ name); @@ -185,181 +177,181 @@ } text.setText(textString); } - + private void - menuFont(){ - FontDialog fontDialog = new FontDialog(shell); - fontDialog.setFontList(text.getFont().getFontData()); - FontData fontData = fontDialog.open(); - if(fontData !is null){ - if(font !is null) font.dispose(); - font = new Font(display, fontData); - text.setFont(font); + menuFont(){ + FontDialog fontDialog = new FontDialog(shell); + fontDialog.setFontList(text.getFont().getFontData()); + FontData fontData = fontDialog.open(); + if(fontData !is null){ + if(font !is null) font.dispose(); + font = new Font(display, fontData); + text.setFont(font); + } } - } - - private void - menuForegroundColor(){ - ColorDialog colorDialog = new ColorDialog(shell); - colorDialog.setRGB(text.getForeground().getRGB()); - RGB rgb = colorDialog.open(); - if(rgb !is null){ - if(foregroundColor !is null) foregroundColor.dispose(); - foregroundColor = new Color(display, rgb); - text.setForeground(foregroundColor); - } - } private void - menuBackgroundColor(){ - ColorDialog colorDialog = new ColorDialog(shell); - colorDialog.setRGB(text.getBackground().getRGB()); - RGB rgb = colorDialog.open(); - if(rgb !is null){ - if(backgroundColor !is null) backgroundColor.dispose(); - backgroundColor = new Color(display, rgb); - text.setBackground(backgroundColor); + menuForegroundColor(){ + ColorDialog colorDialog = new ColorDialog(shell); + colorDialog.setRGB(text.getForeground().getRGB()); + RGB rgb = colorDialog.open(); + if(rgb !is null){ + if(foregroundColor !is null) foregroundColor.dispose(); + foregroundColor = new Color(display, rgb); + text.setForeground(foregroundColor); + } } - } + + private void + menuBackgroundColor(){ + ColorDialog colorDialog = new ColorDialog(shell); + colorDialog.setRGB(text.getBackground().getRGB()); + RGB rgb = colorDialog.open(); + if(rgb !is null){ + if(backgroundColor !is null) backgroundColor.dispose(); + backgroundColor = new Color(display, rgb); + text.setBackground(backgroundColor); + } + } private void - menuPrint(){ - PrintDialog dialog = new PrintDialog(shell, SWT.NONE); - PrinterData data = dialog.open(); - if(data is null) return; - if(data.printToFile){ - data.fileName = "print.out"; // you probably want to ask the user for a filename - } - - /* Get the text to print from the Text widget (you could get it from anywhere, i.e. your java model) */ - textToPrint = text.getText(); - - /* Get the font & foreground & background data. */ - printerFontData = text.getFont().getFontData(); - printerForeground = text.getForeground().getRGB(); - printerBackground = text.getBackground().getRGB(); - - /* Do the printing in a background thread so that spooling does not freeze the UI. */ - printer = new Printer(data); - Thread printingThread = new class ("Printing") Thread{ - private void - run(){ - print(printer); - printer.dispose(); + menuPrint(){ + PrintDialog dialog = new PrintDialog(shell, SWT.NONE); + PrinterData data = dialog.open(); + if(data is null) return; + if(data.printToFile){ + data.fileName = "print.out"; // you probably want to ask the user for a filename } - public - this(char[] o_name){ - this.name = o_name; - super(&run); - } - }; - printingThread.start(); - } - + + /* Get the text to print from the Text widget (you could get it from anywhere, i.e. your java model) */ + textToPrint = text.getText(); + + /* Get the font & foreground & background data. */ + printerFontData = text.getFont().getFontData(); + printerForeground = text.getForeground().getRGB(); + printerBackground = text.getBackground().getRGB(); + + /* Do the printing in a background thread so that spooling does not freeze the UI. */ + printer = new Printer(data); + Thread printingThread = new class ("Printing") Thread{ + private void + run(){ + print(printer); + printer.dispose(); + } + public + this(char[] o_name){ + this.name = o_name; + super(&run); + } + }; + printingThread.start(); + } + private void - print(Printer printer){ - if(printer.startJob("Text")){ // the string is the job name - shows up in the printer's job list - Rectangle clientArea = printer.getClientArea(); - Rectangle trim = printer.computeTrim(0, 0, 0, 0); - Point dpi = printer.getDPI(); - leftMargin = dpi.x + trim.x; // one inch from left side of paper - rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper - topMargin = dpi.y + trim.y; // one inch from top edge of paper - bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper - - /* Create a buffer for computing tab width. */ - int tabSize = 4; // is tab width a user setting in your UI? - StringBuffer tabBuffer = new StringBuffer(tabSize); - for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); - tabs = tabBuffer.toString(); + print(Printer printer){ + if(printer.startJob("Text")){ // the string is the job name - shows up in the printer's job list + Rectangle clientArea = printer.getClientArea(); + Rectangle trim = printer.computeTrim(0, 0, 0, 0); + Point dpi = printer.getDPI(); + leftMargin = dpi.x + trim.x; // one inch from left side of paper + rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper + topMargin = dpi.y + trim.y; // one inch from top edge of paper + bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper + + /* Create a buffer for computing tab width. */ + int tabSize = 4; // is tab width a user setting in your UI? + StringBuffer tabBuffer = new StringBuffer(tabSize); + for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); + tabs = tabBuffer.toString(); - /* Create printer GC, and create and set the printer font & foreground color. */ - gc = new GC(printer); - Font printerFont = new Font(printer, printerFontData); - Color printerForegroundColor = new Color(printer, printerForeground); - Color printerBackgroundColor = new Color(printer, printerBackground); - - gc.setFont(printerFont); - gc.setForeground(printerForegroundColor); - gc.setBackground(printerBackgroundColor); - tabWidth = gc.stringExtent(tabs).x; - lineHeight = gc.getFontMetrics().getHeight(); - - /* Print text to current gc using word wrap */ - printText(); - printer.endJob(); + /* Create printer GC, and create and set the printer font & foreground color. */ + gc = new GC(printer); + Font printerFont = new Font(printer, printerFontData); + Color printerForegroundColor = new Color(printer, printerForeground); + Color printerBackgroundColor = new Color(printer, printerBackground); + + gc.setFont(printerFont); + gc.setForeground(printerForegroundColor); + gc.setBackground(printerBackgroundColor); + tabWidth = gc.stringExtent(tabs).x; + lineHeight = gc.getFontMetrics().getHeight(); - /* Cleanup graphics resources used in printing */ - printerFont.dispose(); - printerForegroundColor.dispose(); - printerBackgroundColor.dispose(); - gc.dispose(); + /* Print text to current gc using word wrap */ + printText(); + printer.endJob(); + + /* Cleanup graphics resources used in printing */ + printerFont.dispose(); + printerForegroundColor.dispose(); + printerBackgroundColor.dispose(); + gc.dispose(); + } } - } - + private void - printText(){ - printer.startPage(); - wordBuffer = new StringBuffer(); - x = leftMargin; - y = topMargin; - index = 0; - end = textToPrint.length; - while(index < end){ - char c = textToPrint.charAt(index); - index++; - if(c != 0){ - if(c == 0x0a || c == 0x0d){ - if(c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a){ - index++; // if this is cr-lf, skip the lf - } - printWordBuffer(); - newline(); - } - else{ - if(c != '\t'){ - wordBuffer.append(c); - } - if(isPrintable(c)){ + printText(){ + printer.startPage(); + wordBuffer = new StringBuffer(); + x = leftMargin; + y = topMargin; + index = 0; + end = textToPrint.length; + while(index < end){ + char c = textToPrint.charAt(index); + index++; + if(c != 0){ + if(c == 0x0a || c == 0x0d){ + if(c == 0x0d && index < end && textToPrint.charAt(index) == 0x0a){ + index++; // if this is cr-lf, skip the lf + } printWordBuffer(); - if (c == '\t'){ - x += tabWidth; + newline(); + } + else{ + if(c != '\t'){ + wordBuffer.append(c); + } + if(isPrintable(c)){ + printWordBuffer(); + if (c == '\t'){ + x += tabWidth; + } } } } } + if (y + lineHeight <= bottomMargin) { + printer.endPage(); + } } - if (y + lineHeight <= bottomMargin) { - printer.endPage(); - } - } private void - printWordBuffer(){ - if(wordBuffer.length > 0){ - String word = wordBuffer.toString(); - int wordWidth = gc.stringExtent(word).x; - if(x + wordWidth > rightMargin){ - /* word doesn't fit on current line, so wrap */ - newline(); + printWordBuffer(){ + if(wordBuffer.length > 0){ + String word = wordBuffer.toString(); + int wordWidth = gc.stringExtent(word).x; + if(x + wordWidth > rightMargin){ + /* word doesn't fit on current line, so wrap */ + newline(); + } + gc.drawString(word, x, y, false); + x += wordWidth; + wordBuffer = new StringBuffer(); } - gc.drawString(word, x, y, false); - x += wordWidth; - wordBuffer = new StringBuffer(); } - } private void - newline(){ - x = leftMargin; - y += lineHeight; - if(y + lineHeight > bottomMargin){ - printer.endPage(); - if(index + 1 < end){ - y = topMargin; - printer.startPage(); + newline(){ + x = leftMargin; + y += lineHeight; + if(y + lineHeight > bottomMargin){ + printer.endPage(); + if(index + 1 < end){ + y = topMargin; + printer.startPage(); + } } } - } }
--- a/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.d Sun Mar 22 19:55:00 2009 +0100 +++ b/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.d Mon Mar 23 10:17:19 2009 +0100 @@ -29,8 +29,10 @@ import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.FileDialog; +import java.lang.all; + import tango.io.FilePath; -import tango.io.FileConst; +import tango.io.model.IFile; import tango.core.Thread; import tango.io.Stdout; import tango.util.Convert;
--- a/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.d Sun Mar 22 19:55:00 2009 +0100 +++ b/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.d Mon Mar 23 10:17:19 2009 +0100 @@ -35,7 +35,7 @@ import org.eclipse.swt.ole.win32.OlePropertyDescription; import tango.io.Stdout; -import tango.io.Print; +import tango.io.stream.Format; import tango.text.convert.Format; int main() { @@ -73,7 +73,7 @@ return iRes; } -private static void printTypeInfo(OleAutomation oOleAutoObj, Print!(char) oOut) +private static void printTypeInfo(OleAutomation oOleAutoObj, FormatOutput!(char) oOut) { org.eclipse.swt.internal.ole.win32.OAIDL.TYPEATTR * pTypeAttr = oOleAutoObj.getTypeInfoAttributes(); if (pTypeAttr !is null) {
--- a/rakefile Sun Mar 22 19:55:00 2009 +0100 +++ b/rakefile Mon Mar 23 10:17:19 2009 +0100 @@ -203,23 +203,28 @@ desc "Build SWT Snippet Collection" -task :swtsnippets do +task :swtsnippets, :explicit_snp do | t, args | snps_browser = [ "Snippet128", "Snippet136" ] snps_opengl = [ "Snippet174", "Snippet195" ] snps_exclude = snps_browser + snps_opengl allsnippets = FileList[ File.join("org.eclipse.swt.snippets", "src", "**/Snippet*.d" )] - allsnippets.each do | snp | - puts "Building #{snp}" - if snp =~ /.*(Snippet\w+)\.d$/ - snpname = $1 - if !snps_exclude.include? snpname - buildApp( "org.eclipse.swt.snippets", "src", "res", "", snpname ) + if args.explicit_snp != nil + puts "Building #{args.explicit_snp}" + buildApp( "org.eclipse.swt.snippets", "src", "res", "", args.explicit_snp ) + else + allsnippets.each do | snp | + puts "Building #{snp}" + if snp =~ /.*(Snippet\w+)\.d$/ + snpname = $1 + if !snps_exclude.include? snpname + buildApp( "org.eclipse.swt.snippets", "src", "res", "", snpname ) + end + else + puts snp + raise "Name does not match" end - else - puts snp - raise "Name does not match" end end end @@ -242,28 +247,51 @@ ALL_RESDIRS.each do | dir | rsp.puts "-J#{File.expand_path(dir).to_path}" end - rsp.print "-L" - rsp.print "+advapi32" - rsp.print "+comctl32" - rsp.print "+comdlg32" - rsp.print "+gdi32" - rsp.print "+kernel32" - rsp.print "+shell32" - rsp.print "+ole32" - rsp.print "+oleaut32" - rsp.print "+olepro32" - rsp.print "+oleacc" - rsp.print "+user32" - rsp.print "+usp10" - rsp.print "+msimg32" - rsp.print "+opengl32" - rsp.print "+shlwapi" - rsp.print "+tango-user-dmd.lib" - rsp.print "+zlib.lib" - rsp.print "+dwt-base.lib" - rsp.print "+org.eclipse.swt.win32.win32.x86.lib" - rsp.print "+#{LIBDIR.to_path}\\" - rsp.puts + #rsp.puts "-L/NOMAP" + #rsp.print "-L" + #rsp.print "+advapi32" + #rsp.print "+comctl32" + #rsp.print "+comdlg32" + #rsp.print "+gdi32" + #rsp.print "+kernel32" + #rsp.print "+shell32" + #rsp.print "+ole32" + #rsp.print "+oleaut32" + #rsp.print "+olepro32" + #rsp.print "+oleacc" + #rsp.print "+user32" + #rsp.print "+usp10" + #rsp.print "+msimg32" + #rsp.print "+opengl32" + #rsp.print "+shlwapi" + #rsp.print "+tango-user-dmd.lib" + #rsp.print "+zlib.lib" + #rsp.print "+dwt-base.lib" + #rsp.print "+org.eclipse.swt.win32.win32.x86.lib" + #rsp.print "+#{LIBDIR.to_path}\\" + #rsp.puts + + rsp.puts "-L/NOM" + rsp.puts "-L+advapi32" + rsp.puts "-L+comctl32" + rsp.puts "-L+comdlg32" + rsp.puts "-L+gdi32" + rsp.puts "-L+kernel32" + rsp.puts "-L+shell32" + rsp.puts "-L+ole32" + rsp.puts "-L+oleaut32" + rsp.puts "-L+olepro32" + rsp.puts "-L+oleacc" + rsp.puts "-L+user32" + rsp.puts "-L+usp10" + rsp.puts "-L+msimg32" + rsp.puts "-L+opengl32" + rsp.puts "-L+shlwapi" + rsp.puts "-L+tango-user-dmd.lib" + rsp.puts "-L+zlib.lib" + rsp.puts "-L+dwt-base.lib" + rsp.puts "-L+org.eclipse.swt.win32.win32.x86.lib" + rsp.puts "-L+#{LIBDIR.to_path}\\" rsp.puts "-op" rsp.puts "-od#{OBJDIR.to_path}"