www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - ui demo: CustomComponents

reply yidabu <yidabu.spam gmail.com> writes:
TODO: FormText demo not works.

code:

module ui.CustomComponents;

/*******************************************************************************
 * All Right Reserved. Copyright (c) 1998, 2004 Jackwind Li Guojie
 * 
 * Created on 2004-6-14 10:55:42 by JACK $Id$
 *  
 * Port to the D programming language:
 *     yidabu at gmail dot com  ( D China
http://www.d-programming-language-china.org/ ) 
 ******************************************************************************/
import dwtx.jface.window.ApplicationWindow;
import dwt.DWT;
import dwt.graphics.Image;
import dwt.layout.FillLayout;
import dwt.layout.GridData;
import dwt.layout.GridLayout;
import dwt.widgets.Composite;
import dwt.widgets.Control;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwtx.ui.forms.HyperlinkGroup;
import dwtx.ui.forms.events.ExpansionAdapter;
import dwtx.ui.forms.events.ExpansionEvent;
import dwtx.ui.forms.events.HyperlinkAdapter;
import dwtx.ui.forms.events.HyperlinkEvent;
import dwtx.ui.forms.events.IHyperlinkListener;
import dwtx.ui.forms.widgets.ExpandableComposite;
import dwtx.ui.forms.widgets.Form;
import dwtx.ui.forms.widgets.FormText;
import dwtx.ui.forms.widgets.FormToolkit;
import dwtx.ui.forms.widgets.Hyperlink;
import dwtx.ui.forms.widgets.ImageHyperlink;
import dwtx.ui.forms.widgets.Section;
import dwtx.ui.forms.widgets.TableWrapLayout;

import dwt.graphics.ImageData;
import dwt.dwthelper.utils;
import dwt.dwthelper.ByteArrayInputStream;

import tango.util.log.Trace;

void main(String[] args) {
    CustomWidgets win = new CustomWidgets(null);
    win.setBlockOnOpen(true);
    win.open();
    //Display.getCurrent().dispose();
}

public class CustomWidgets : ApplicationWindow {
    FormToolkit toolkit;
    Form form;

    /**
    *  param parentShell
    */
    public this(Shell parentShell) {
        super(parentShell);
    }

    /// TODO : tango.core.Exception.NoSuchElementException: no matching key
    private void demoSections() {
        form.getBody().setLayout(new TableWrapLayout());

        Section section = toolkit.createSection(form.getBody(),
Section.DESCRIPTION | 
            Section.TREE_NODE | Section.EXPANDED);

        section.setText("This is the title");
        toolkit.createCompositeSeparator(section);
        section.setDescription("-= This is a description -=");

        FormText text = toolkit.createFormText(section, false);
        text.setText(
          "This is a long text. The user can show or hide this text "
            ~ "by expanding or collapsing the expandable composite.",
          false,
          false);
        section.setClient(text);
    }

    private void demoExpandableComposite() {
        form.getBody().setLayout(new TableWrapLayout());

        ExpandableComposite ec1 =
          toolkit.createExpandableComposite(
            form.getBody(),
            ExpandableComposite.TREE_NODE | ExpandableComposite.EXPANDED);
        ec1.setText("This is the title");

        FormText text = toolkit.createFormText(ec1, false);
        text.setText(
          "This is a long text. The user can show or hide this text "
            ~ "by expanding or collapsing the expandable composite.",
          false,
          false);
        ec1.setClient(text);

        ec1.addExpansionListener(new class(getShell()) ExpansionAdapter {
            Shell shell;
            this(Shell shell_)
            {
                shell = shell_;
            }
            public void expansionStateChanged(ExpansionEvent e) {
            // resizes the application window.
                shell.pack(true);
            }
        });
    }

    private void demoFormTextXML() {
        form.getBody().setLayout(new TableWrapLayout());
        FormText text = toolkit.createFormText(form.getBody(), true);

        Image image = new Image(form.getDisplay(), new ImageData(new
ByteArrayInputStream(cast(byte[]) import("eclipse.png"))));
        text.setImage("eclipse", image);
        text.setText(
          "<form>"
            ~ "<p><img href=\"eclipse\"/> Eclipse Projects: </p>"
            ~ "<li><b>Platform</b> - Eclipse frameworks</li>"
            ~ "<li><b>JDT</b> - Java development tools</li>"
            ~ "<li><b>PDE</b> - Plug-in development environment</li>"
            ~ "</form>",
          true,
          false);

    }

    // TODO: tango.core.Exception.NoSuchElementException: no matching key
    private void demoFormTextNormal() {
        form.getBody().setLayout(new TableWrapLayout());

        FormText text = toolkit.createFormText(form.getBody(), true);
        // text.setLayoutData(new TableWrapData(TableWrapData.FILL));

        
        text.setText(
          "Eclipse is a kind of universal tool platform - an open extensible "
            ~ "IDE for anything and nothing in particular. For more details,
please "
            ~ "visit http://www.eclipse.org for more details.",
          false,
          false);
        
    }

    // TODO: tango.core.Exception.NoSuchElementException: no matching key
    private void demoFormTextURL() {
        form.getBody().setLayout(new TableWrapLayout());

        FormText text = toolkit.createFormText(form.getBody(), true);

        HyperlinkGroup group = new HyperlinkGroup(form.getDisplay());
        group.setForeground(form.getDisplay().getSystemColor(DWT.COLOR_BLUE));
        group.setActiveForeground(
          form.getDisplay().getSystemColor(DWT.COLOR_BLUE));

        text.setHyperlinkSettings(group);

        text.setText(
          "Eclipse is a kind of universal tool platform - an open extensible "
            ~ "IDE for anything and nothing in particular. For more details,
please "
            ~ "visit http://www.eclipse.org web site.",
          false,
          true);

        text.addHyperlinkListener(new class() HyperlinkAdapter {
          public void linkActivated(HyperlinkEvent e) {
            //Trace.formatln("Link activated: {}", stringcast(e.getHref()));
          }
        });

    }

    private void demoHyperlinks() {
        form.getBody().setLayout(new GridLayout());

        Hyperlink hyperlink =
          toolkit.createHyperlink(
            form.getBody(),
            "This is a hyperlink to Eclipse.org",
            DWT.NULL);
        hyperlink.setHref(new ArrayWrapperString("http://www.eclipse.org"));
        hyperlink.setForeground(
          getShell().getDisplay().getSystemColor(DWT.COLOR_BLUE));
        hyperlink.addHyperlinkListener(new class() IHyperlinkListener {
          public void linkEntered(HyperlinkEvent e) {
            Trace.formatln("Mouse entered.");
          }

          public void linkExited(HyperlinkEvent e) {
            Trace.formatln("Mouse left.");
          }

          public void linkActivated(HyperlinkEvent e) {
              Trace.formatln("Hyperlink activated.");
              Trace.formatln("HREF = {}", stringcast(e.getHref()));
          }
        });

        ImageHyperlink imageHyperlink =
          toolkit.createImageHyperlink(form.getBody(), DWT.NULL);
        imageHyperlink.setText("This is an image hyperlink.");
        imageHyperlink.setForeground(
          getShell().getDisplay().getSystemColor(DWT.COLOR_BLUE));
        imageHyperlink.setImage(
          new Image(getShell().getDisplay(), new ImageData(new
ByteArrayInputStream(cast(byte[]) import("eclipse.png")))));
        imageHyperlink.addHyperlinkListener(new class() HyperlinkAdapter {
          public void linkActivated(HyperlinkEvent e) {
              Trace.formatln("Image hyperlink activated.");
          }
        });

        HyperlinkGroup group = new HyperlinkGroup(getShell().getDisplay());
        group.add(hyperlink);
        group.add(imageHyperlink);

        group.setActiveBackground(
          getShell().getDisplay().getSystemColor(DWT.COLOR_YELLOW));
        group.setActiveForeground(
          getShell().getDisplay().getSystemColor(DWT.COLOR_RED));
        group.setForeground(
          getShell().getDisplay().getSystemColor(DWT.COLOR_BLUE));
    }

    /*
    * (non-Javadoc)
    * 
    *  see dwtx.jface.window.Window#createContents(dwt.widgets.Composite)
    */
    protected Control createContents(Composite parent) {
        Composite composite = new Composite(parent, DWT.NULL);
        composite.setLayout(new FillLayout());

        // Sets up the toolkit.
        toolkit = new FormToolkit(getShell().getDisplay());

        // Creates a form instance.
        form = toolkit.createForm(composite);
        form.setLayoutData(new GridData(GridData.FILL_BOTH));

        // Sets title.
        form.setText("Custom Form Widgets Demo");

        
        /// only works demo
        demoHyperlinks();
        
        /// BUG: tango.core.Exception.NoSuchElementException: no matching key
        //demoSections();  
        //demoFormTextNormal();
        //demoFormTextURL();
        //demoFormTextXML();
        //demoExpandableComposite();
        
        return composite;
    }

}

           
       

-- 
yidabu <yidabu.spam gmail.com>
http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese):
http://www.d-programming-language-china.org/
http://bbs.d-programming-language-china.org/
http://dwin.d-programming-language-china.org/
http://scite4d.d-programming-language-china.org/
Jun 12 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
  * All Right Reserved. 
Hmmm :/ Nevertheless, i will take a look. The other two are working?
Jun 13 2008
parent reply yidabu <yidabu.spam gmail.com> writes:
On Fri, 13 Jun 2008 13:44:01 +0200
Frank Benoit <keinfarbton googlemail.com> wrote:

  * All Right Reserved. 
Hmmm :/ Nevertheless, i will take a look. The other two are working?
The other two works fine. -- yidabu <yidabu.spam gmail.com> http://www.dsource.org/projects/dwin D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/
Jun 13 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
yidabu schrieb:
 On Fri, 13 Jun 2008 13:44:01 +0200
 Frank Benoit <keinfarbton googlemail.com> wrote:
 
  * All Right Reserved. 
Hmmm :/ Nevertheless, i will take a look. The other two are working?
The other two works fine.
I have not forgotten about this, but i want to rework bigger parts or Forms and JFace with the new tango containers or wrappers for them. Also the XML processing in dwtx\ui\internal\forms\widgets\FormsTextModel.d is missing (see "implMissing"). Perhaps someone else is interested in doing it? ;)
Jun 19 2008
parent reply Frank Benoit <keinfarbton googlemail.com> writes:
Frank Benoit schrieb:
 yidabu schrieb:
 On Fri, 13 Jun 2008 13:44:01 +0200
 Frank Benoit <keinfarbton googlemail.com> wrote:

  * All Right Reserved. 
Hmmm :/ Nevertheless, i will take a look. The other two are working?
The other two works fine.
I have not forgotten about this, but i want to rework bigger parts or Forms and JFace with the new tango containers or wrappers for them. Also the XML processing in dwtx\ui\internal\forms\widgets\FormsTextModel.d is missing (see "implMissing"). Perhaps someone else is interested in doing it? ;)
Most of them are now working. I tested on linux. demoSections(); demoFormTextNormal(); demoFormTextURL(); //demoFormTextXML(); // implementation missing demoExpandableComposite(); On windows there might be still problems with null strings. In dwt-linux i adjusted the methods to allow them. This changes still need to be applied to dwt-win. http://www.dsource.org/projects/dwt/wiki/DiffToOriginal Another open issue is the word boundary analysis in two of the ui.forms classes. This affects how lines are broken.
Jun 20 2008
parent yidabu <yidabu.spam gmail.com> writes:
On Fri, 20 Jun 2008 15:12:14 +0200
Frank Benoit <keinfarbton googlemail.com> wrote:

 
 Most of them are now working. I tested on linux.
 
          demoSections();
          demoFormTextNormal();
          demoFormTextURL();
          //demoFormTextXML(); // implementation missing
          demoExpandableComposite();
 
 On windows there might be still problems with null strings.
 In dwt-linux i adjusted the methods to allow them. This changes still 
 need to be applied to dwt-win.
 http://www.dsource.org/projects/dwt/wiki/DiffToOriginal
 
 Another open issue is the word boundary analysis in two of the ui.forms 
 classes. This affects how lines are broken.
demoSections(); demoFormTextNormal(); demoFormTextURL(); //demoFormTextXML(); // implementation missing demoExpandableComposite(); Tested on Windows today, all cause "Argument cannot be null" -- yidabu <yidabu.spam gmail.com> http://www.dsource.org/projects/dwin D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/
Jun 20 2008