org.wings.SDialog Maven / Gradle / Ivy
/*
* Copyright 2000,2005 wingS development team.
*
* This file is part of wingS (http://wingsframework.org).
*
* wingS 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.
*
* Please see COPYING for the complete licence.
*/
package org.wings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wings.plaf.DialogCG;
/**
* Top-level window with a title and a border that is typically used to take
* some form of input from the user. As opposed to Swing, wingS dialogs are
* non modal. However, the dismission of the dialog is propagated by means of
* ActionEvents. The action command of the event tells, what kind of user
* activity caused the dialog to dismiss.
*
* @author Holger Engels
* @author Roman Rädle
*/
public class SDialog extends SWindow {
private final transient static Logger log = LoggerFactory.getLogger(SDialog.class);
/**
* Action command if dialog window was closed
*/
public static final String CLOSE_ACTION = "CLOSE";
/**
* Action command if user hit return
*/
public static final String DEFAULT_ACTION = "DEFAULT";
/**
* The Title of the Dialog Frame
*/
protected String title;
protected SIcon icon = null;
protected boolean modal = false;
protected boolean draggable = true;
private boolean closable = true;
private boolean closed = false;
/**
* Creates a Dialog without parent SFrame
or
* SDialog
and without Title
*/
public SDialog() {
}
/**
* Creates a dialog with the specifed parent SFrame
as its
* owner.
*
* @param owner
* the parent SFrame
*/
public SDialog(SFrame owner) {
this(owner, null, false);
}
/**
* Creates a modal or non-modal dialog without a title and with the
* specified owner Frame
. If owner
is
* null
, a shared, hidden frame will be set as the owner of
* the dialog.
*
* This constructor sets the component's locale property to the value
* returned by JComponent.getDefaultLocale
.
*
* @param owner
* the Frame
from which the dialog is displayed
* @param modal
* true for a modal dialog, false for one that allows others
* windows to be active at the same time returns true.
*/
public SDialog(SFrame owner, boolean modal) {
this(owner, null, modal);
}
/**
* Creates a dialog with the specified title and the specified owner frame.
*
* @param owner
* the parent SFrame
* @param title
* the String
to display as titke
*/
public SDialog(SFrame owner, String title) {
this(owner, title, false);
}
/**
* Creates a modal or non-modal dialog with the specified title and the
* specified owner Frame
. If owner
is
* null
, a shared, hidden frame will be set as the owner of
* this dialog. All constructors defer to this one.
*
* NOTE: Any popup components (JComboBox
,
* JPopupMenu
, JMenuBar
) created within a
* modal dialog will be forced to be lightweight.
*
* This constructor sets the component's locale property to the value
* returned by JComponent.getDefaultLocale
.
*
* @param owner
* the Frame
from which the dialog is displayed
* @param title
* the String
to display in the dialog's title bar
* @param modal
* true for a modal dialog, false for one that allows other
* windows to be active at the same time returns true.
*/
public SDialog(SFrame owner, String title, boolean modal) {
this.owner = owner;
this.title = title;
this.modal = modal;
}
/**
* Sets the title of the dialog.
*
* @param t
* the title displayed in the dialog's border; a null value
* results in an empty title
*/
public void setTitle(String t) {
String oldTitle = title;
title = t;
if ((title == null && oldTitle != null)
|| (title != null && !title.equals(oldTitle)))
reload();
propertyChangeSupport.firePropertyChange("title", oldTitle, this.title);
}
/**
* Gets the title of the dialog. The title is displayed in the dialog's
* border.
*
* @return the title of this dialog window. The title may be null.
*/
public String getTitle() {
return title;
}
public void setIcon(SIcon i) {
if (i != icon || i != null && !i.equals(icon)) {
SIcon oldVal = this.icon;
icon = i;
reload();
propertyChangeSupport.firePropertyChange("icon", oldVal, this.icon);
}
}
public SIcon getIcon() {
return icon;
}
public boolean isModal() {
return modal;
}
public void setModal(boolean modal) {
boolean oldVal = this.modal;
this.modal = modal;
propertyChangeSupport.firePropertyChange("modal", oldVal, this.modal);
}
public boolean isDraggable() {
return draggable;
}
public void setDraggable(boolean draggable) {
boolean oldVal = this.draggable;
this.draggable = draggable;
propertyChangeSupport.firePropertyChange("draggable", oldVal, this.draggable);
}
@Override
public void hide() {
super.hide();
}
public void setClosable(boolean v) {
boolean old = closable;
closable = v;
if (old != closable)
reload();
}
public boolean isClosable() {
return closable;
}
// public void setClosed(boolean v) {
// v &= isClosable();
// boolean old = closed;
// closed = v;
// if (old != closed)
// reload();
// }
//
// public boolean isClosed() {
// return closed;
// }
public void setCG(DialogCG cg) {
super.setCG(cg);
}
}