001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.wings.border.SBorder;
018: import org.wings.plaf.ComponentCG;
019: import org.wings.plaf.FormCG;
020: import org.wings.plaf.WindowCG;
021:
022: /**
023: * The <code>SWindow</code> is currently just a placeholder for further implementations like
024: * MDI windows or dialogs.
025: * <p/>
026: * User: rrd
027: * Date: Oct 2, 2007
028: * Time: 6:59:44 PM
029: *
030: * @author <a href="mailto:rrd@wilken.de">Roman Rädle</a>
031: * @version $Id
032: */
033: public class SWindow extends SForm implements LowLevelEventListener {
034:
035: private static final Log LOG = LogFactory.getLog(SWindow.class);
036:
037: /**
038: * Action command if window window was closed
039: */
040: public static final String CLOSE_ACTION = "CLOSE";
041:
042: /**
043: * Action command if user hit return
044: */
045: public static final String DEFAULT_ACTION = "DEFAULT";
046:
047: protected SRootContainer owner;
048:
049: /**
050: * Returns the root container in which this dialog is to be displayed.
051: *
052: * @return The root container in which this dialog is to be displayed.
053: * @see this#getParent()
054: */
055: public SRootContainer getOwner() {
056: return owner;
057: }
058:
059: public void setVisible(boolean visible) {
060: if (visible) {
061: show(owner);
062: } else {
063: hide();
064: }
065: super .setVisible(visible);
066: }
067:
068: /**
069: * Removes all <code>SComponents</code> from the pane
070: */
071: public void dispose() {
072: if (isVisible()) {
073: hide();
074: }
075: removeAll();
076: }
077:
078: /**
079: * shows this window in the given SRootContainer. If the component is
080: * not a root container, then the root container the component is in
081: * is used.
082: * If the component is null, the root frame of the session will be used.
083: */
084: public void show(SComponent c) {
085: LOG.debug("show window");
086:
087: // If the owner is empty get the components root container.
088: if (owner == null) {
089: if (c != null) {
090: while (!(c instanceof SRootContainer)) {
091: c = c.getParent();
092: }
093: owner = (SRootContainer) c;
094: }
095: }
096:
097: if (owner == null) {
098: owner = getSession().getRootFrame();
099: }
100: owner.pushWindow(this );
101:
102: /*
103: if (isUpdatePossible() && SWindow.class.isAssignableFrom(getClass())) {
104: update(((WindowCG) getCG()).getWindowAddedUpdate(this));
105: }
106: */
107: }
108:
109: /**
110: * Remove this window from its frame.
111: */
112: public void hide() {
113: LOG.debug("hide window");
114: if (owner != null) {
115: owner.removeWindow(this );
116: }
117: }
118:
119: // LowLevelEventListener interface. Handle own events.
120: public void processLowLevelEvent(String action, String[] values) {
121: processKeyEvents(values);
122: if (action.endsWith("_keystroke"))
123: return;
124:
125: // is this a window event?
126: try {
127: switch (new Integer(values[0]).intValue()) {
128: case org.wings.event.SInternalFrameEvent.INTERNAL_FRAME_CLOSED:
129: actionCommand = CLOSE_ACTION;
130: break;
131:
132: default:
133: // form event
134: actionCommand = DEFAULT_ACTION;
135: }
136: } catch (NumberFormatException ex) {
137: // no window event...
138: }
139: SForm.addArmedComponent(this ); // trigger later invocation of fire*()
140: }
141: }
|