Package org.beryl.gui.test

Source Code of org.beryl.gui.test.Test

/*
* Beryl - A web platform based on XML, XSLT and Java
* This file is part of the Beryl XML GUI
*
* Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
*/

package org.beryl.gui.test;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

import org.beryl.gui.Controller;
import org.beryl.gui.GUIEvent;
import org.beryl.gui.GUIException;
import org.beryl.gui.GUIUtils;
import org.beryl.gui.ImageIconFactory;
import org.beryl.gui.InternationalizationManager;
import org.beryl.gui.MessageDialog;
import org.beryl.gui.model.ListDataModel;
import org.beryl.gui.model.MapChangeEvent;
import org.beryl.gui.model.MapDataModel;
import org.beryl.gui.model.ModelChangeEvent;
import org.beryl.gui.model.ModelChangeListener;
import org.beryl.gui.model.TableChangeEvent;
import org.beryl.gui.model.TableDataModel;
import org.beryl.gui.model.TableRow;
import org.beryl.gui.swing.CommandEvent;
import org.beryl.gui.swing.ConsoleAttribute;
import org.beryl.gui.widgets.ComboBox;
import org.beryl.gui.widgets.Frame;
import org.beryl.gui.widgets.List;
import org.beryl.gui.widgets.Table;

/**
* Beryl XML GUI test program
*/
public class Test extends Controller {
  private MapDataModel model = null;
  private Table table = null;
  private TableDataModel tableModel = null;
  private Frame frame = null;
  private ConsoleAttribute boldAttribute = null;

  public Test() throws GUIException {
    /* Create a new data model and initialize it
     * with default values for the main window */
    model = new MapDataModel();
    model.setValue("username", "wazlaf");
    model.setValue("password", "blubb");
    model.setValue("combo.index", new Integer(1));
    model.setValue("list.index", new int[] { 1 });
    model.setValue("icon.index", new Integer(1));
    model.setValue("radio", "choice3");
    model.setValue("ssl", new Boolean(true));
    model.setValue("table.index", new int[] { 1 } );

    /* Create some items for the combo box / list */
    ListDataModel listModel = new ListDataModel();
    for (int i = 1; i < 11; i++)
      listModel.addValue("MVC item " + i);

    /* Create a table data model for the table widget and add
     * some rows to it */
    tableModel = new TableDataModel();
    tableModel.addRow(
      new Person("Wenzel", "Jakob", "wazlaf@tigris.org", new GregorianCalendar(1983, 11, 04).getTime()));
    tableModel.addRow(new Person("Hans", "Mustermann", "asdf@asdf.com", new Date()));
    tableModel.addRow(new Person("Test", "Person", "test@test.de", new Date()));

    /* Add a debugging model change listener to the table data model */
    tableModel.addModelChangeListener(new ModelChangeListener() {
      public void modelChanged(ModelChangeEvent e) {
        TableChangeEvent event = (TableChangeEvent) e;
        log.debug(
          "Table data model change : "
            + event.getKey()
            + "["
            + event.getFirstIndex()
            + "] -> '"
            + ((TableDataModel) event.getModel()).getValue(event.getFirstIndex(), event.getKey())
            + "'");
      }
    });

    /* Add a debugging model change listener to the window data model */
    model.addModelChangeListener(new ModelChangeListener() {
      public void modelChanged(ModelChangeEvent e) {
        MapChangeEvent event = (MapChangeEvent) e;
        log.debug("Data model change : '" + event.getKey() + "' => '" + event.getNewValue() + "'");
      }
    });

    /* Create the window */
    frame = constructFrame("TestFrame", model);

    /* Associate the table data model with the table */
    table = (Table) frame.getWidget("Table1");
    table.setTableDataModel(tableModel);

    /* Associate the list data model with a combo box and a list */
    ((ComboBox) frame.getWidget("Combo1")).setListDataModel(listModel);
    ((List) frame.getWidget("List1")).setListDataModel(listModel);

    /* Initialize the console */
    boldAttribute = new ConsoleAttribute();
    boldAttribute.setBold(true);

    /* Show the frame */
    frame.show();
  }

  /**
   * Called when events occur inside the GUI
   */
  public void eventOccured(GUIEvent e) {
    String name = e.getName();
    try {
      log.debug("Caught event : " + e.toString());
      if (name.equals("quit")) {
        System.exit(0);
      } else if (name.equals("wizard")) {
        new WizardTest();
      } else if (name.equals("outlook")) {
        new OutlookBarTest();
      } else if (name.equals("about")) {
        new About(frame);
      } else if (name.equals("dnd")) {
        new DnDTest();
      } else if (name.equals("message.info")) {
        new MessageDialog(frame, getString("test.message.info.title"), getString("test.message.info.message"));
      } else if (name.equals("message.warning")) {
        new MessageDialog(frame, MessageDialog.WARNING_MESSAGE, getString("test.message.warning.title"), getString("test.message.warning.message"), null);
      } else if (name.equals("message.error")) {
        throw new GUIException("This is an example error");
      } else if (name.equals("edit")) {
        TableRow selection[] = (TableRow[]) model.getValue("table.value");
        for (int i = 0; i < selection.length; i++) {
          new PersonEditor(selection[i]);
        }
      } else if (name.equals("consoleCommand")) {
        CommandEvent event = (CommandEvent) e.getSwingEvent();
        event.getSource().appendText(getString("test.console.command"));
        event.getSource().appendText(event.getCommand(), boldAttribute);
        event.getSource().appendText(getString("test.console.notfound")+"\n");
      } else if (name.equals("login")) {
        log.debug(
          "Login has been clicked. username ["
            + model.getValue("username")
            + "], password ["
            + model.getValue("password")
            + "], ssl ["
            + model.getValue("ssl")
            + "], verbose ["
            + model.getValue("verbose")
            + "]");
      }
    } catch (GUIException ex) {
      new MessageDialog(ex);
    }
  }

  public static void main(String args[]) {
    try {
      Locale locale = Locale.US;
     
      if (Locale.getDefault().getLanguage().equals("de"))
        locale = new Locale("de", "DE");
      GUIUtils.defaultInitialization(locale);
      ImageIconFactory.addSearchPath("resources/test/icons");
      InternationalizationManager.addLanguageFile("resources/test/test");

      new Test();
    } catch (Exception e) {
      new MessageDialog(e);
    }
  }
}
TOP

Related Classes of org.beryl.gui.test.Test

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.