001: /*
002: * $Id: TextComponentExample.java 2750 2006-08-02 08:10:54Z hengels $
003: * Copyright 2006 wingS development team.
004: *
005: * This file is part of wingS (http://wingsframework.org).
006: *
007: * wingS is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014:
015: package org.wingx.example;
016:
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019: import org.wings.SButton;
020: import org.wings.SComponent;
021: import org.wings.SForm;
022: import org.wings.SGridLayout;
023: import org.wings.SIcon;
024: import org.wings.SLabel;
025: import org.wings.SPanel;
026: import org.wings.STextField;
027: import org.wings.SURLIcon;
028: import org.wings.plaf.WingSetExample;
029: import org.wings.border.SLineBorder;
030: import org.wings.event.SDocumentEvent;
031: import org.wings.event.SDocumentListener;
032: import org.wingx.XInplaceEditor;
033:
034: /**
035: * Example demonstrating the use of component XInplaceEditor.
036: * @author Christian Schyma
037: */
038: public class XInplaceEditorExample implements WingSetExample {
039: private final String someText = "\"There is a theory which states that if anybody ever discovers "
040: + "exactly what the Universe is for and why it is here, it will "
041: + "instantly disappear and be replaced by something even more "
042: + "bizarre and inexplicable. There is another theory which states "
043: + "that this has already happened.\" \n-- Douglas Adams";
044:
045: private final SIcon HZ_PICTURE = new SURLIcon(
046: "../icons/Hohenzollern.jpg");
047: private SForm form;
048:
049: public void activateExample() {
050: SLabel picture = new SLabel(HZ_PICTURE);
051: XInplaceEditor pictureDescription = new XInplaceEditor(
052: "click here to give me a name!", 49, 1);
053:
054: SPanel picturePanel = new SPanel(new SGridLayout(1));
055: picturePanel.add(picture);
056: picturePanel.add(pictureDescription);
057:
058: final XInplaceEditor editor = new XInplaceEditor(someText, 80,
059: 2);
060: editor.addAjaxDocumentListener(new SDocumentListener() {
061: public void changedUpdate(SDocumentEvent e) {
062: }
063:
064: public void insertUpdate(SDocumentEvent e) {
065: e.getDocument()
066: .setText(
067: e.getDocument().getText().replaceAll(
068: "foo", ""));
069: }
070:
071: public void removeUpdate(SDocumentEvent e) {
072: }
073: });
074:
075: final STextField rowsTextField = new STextField("2");
076: final STextField colsTextField = new STextField("80");
077:
078: SButton saveChanges = new SButton("apply changes");
079: saveChanges.addActionListener(new ActionListener() {
080: public void actionPerformed(ActionEvent e) {
081: editor.setRows(Integer
082: .parseInt(rowsTextField.getText()));
083: editor.setCols(Integer
084: .parseInt(colsTextField.getText()));
085: }
086: });
087:
088: SPanel configPanel = new SPanel(new SGridLayout(2));
089: configPanel.setBorder(new SLineBorder(1));
090: configPanel.add(new SLabel(
091: "In-Place Editor configuration of above example"));
092: configPanel.add(saveChanges);
093: configPanel.add(new SLabel("# rows:"));
094: configPanel.add(rowsTextField);
095: configPanel.add(new SLabel("# cols:"));
096: configPanel.add(colsTextField);
097:
098: SGridLayout gridLayout = new SGridLayout(1);
099: gridLayout.setHgap(10);
100: gridLayout.setVgap(20);
101: form = new SForm(gridLayout);
102: form.add(picturePanel);
103: form.add(editor);
104: form.add(configPanel);
105: }
106:
107: public void passivateExample() {
108: //To change body of implemented methods use File | Settings | File Templates.
109: }
110:
111: public SComponent getExample() {
112: return form;
113: }
114:
115: public String getExampleName() {
116: return "XInplaceEditor";
117: }
118:
119: public String getExampleGroup() {
120: return "Experiment";
121: }
122: }
|