|
From: <de...@us...> - 2003-07-04 14:32:52
|
Update of /cvsroot/fudaa/fudaa_devel/ebli/src/org/fudaa/ebli/dialog
In directory sc8-pr-cvs1:/tmp/cvs-serv930/dialog
Modified Files:
EbliSimpleDialog.java
Added Files:
EbliSimpleDialogPanel.java EnhancedDialog.java
Log Message:
ZCalqueLongPolygone : permet de dessiner des polygones qui seraient long.
EnhancedDialog dialogue pouvant etre ferme avec la touche esc
--- NEW FILE: EbliSimpleDialogPanel.java ---
/*
* @file PrertPnDialog.java
* @creation 2002-09-03
* @modification $Date: 2003/07/04 14:32:48 $
* @license GNU General Public License 2
* @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
* @mail de...@fu...
*/
package org.fudaa.ebli.dialog;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import com.memoire.bu.BuBorderLayout;
import com.memoire.bu.BuButton;
import com.memoire.bu.BuCharValidator;
import com.memoire.bu.BuCommonImplementation;
import com.memoire.bu.BuCommonInterface;
import com.memoire.bu.BuFileChooser;
import com.memoire.bu.BuHorizontalLayout;
import com.memoire.bu.BuInformationsSoftware;
import com.memoire.bu.BuLabel;
import com.memoire.bu.BuLabelMultiLine;
import com.memoire.bu.BuLib;
import com.memoire.bu.BuPanel;
import com.memoire.bu.BuPicture;
import com.memoire.bu.BuStringValidator;
import com.memoire.bu.BuTextField;
import com.memoire.bu.BuValueValidator;
import com.memoire.bu.BuVerticalLayout;
import org.fudaa.ebli.commun.EbliLib;
/**
* Un panneau qui peut etre facilement affichable dans une boite de dialogue.
* Cette classe reprend le mode de fonctionnement de JOptionPane.
* Les methodes valide(), actionOk(), actionApply() et actionCancel() peuvent être
*
* @version $Id: EbliSimpleDialogPanel.java,v 1.1 2003/07/04 14:32:48 deniger Exp $
* @author Bertrand Marchand,Fred Deniger
*/
public class EbliSimpleDialogPanel
extends BuPanel
implements ActionListener, WindowListener
{
/**
* Option : uniquement un bouton ok sera affiche. Reponse donnee par le
* dialogue si le bouton "ok" utilise.
*/
public static final int OK_OPTION = 0;
public static final int OK_CANCEL_OPTION = 1;
public static final int OK_APPLY_OPTION = 2;
public static final int OK_CANCEL_APPLY_OPTION = 3;
public static final int CANCEL_OPTION = 4;
public static final String CHOOSE_FILE_TXT_FIELD_PROPERTY =
"fudaaChooseFileTxtField";
public static final String CHOOSE_FILE_OPEN_DIR = "fudaaChooseFileopenDir";
protected int option_;
protected boolean modale_;
protected JDialog dialog_;
private int response_;
private BuLabelMultiLine lbError_;
String title_;
private File lastFile_;
private BuInformationsSoftware isoft_;
public EbliSimpleDialogPanel()
{
this(OK_CANCEL_OPTION);
}
/**
* Les options possibles les variables statiques <code>OK_OPTION</code>
* (un bouton ok unique,
* <code>OK_CANCEL_OPTION</code>,...
*/
public EbliSimpleDialogPanel(int _option)
{
option_ = _option;
lbError_ = new BuLabelMultiLine();
lbError_.setVisible(false);
lbError_.setForeground(Color.red);
title_ = "";
response_ = JOptionPane.CANCEL_OPTION;
}
public void setErrorText(String _error)
{
if ((!lbError_.isVisible()) || (!_error.equals(lbError_.getText())))
{
lbError_.setVisible(true);
lbError_.setText(_error);
doLayout();
}
}
public void cancelErrorText()
{
if (lbError_.isVisible())
{
lbError_.setVisible(false);
lbError_.setText("");
doLayout();
}
}
public void setInfos(BuInformationsSoftware _is)
{
isoft_ = _is;
}
public void setInfos(BuCommonInterface _is)
{
if (_is != null)
setInfos(_is.getInformationsSoftware());
}
/**
* Permet d'initialiser ce dialogue a l'aide d'un objet : envoie une exception par defaut.
*/
public void setValue(Object _f)
{
throw new NoSuchMethodError("Methode non implantee");
}
/**
* Renvoie la chaine caracterisant le contenu de ce dialogue.
*/
public Object getValue()
{
throw new NoSuchMethodError("Methode non implantee");
}
public void setModale(boolean _modale)
{
modale_ = _modale;
}
public boolean valide()
{
return true;
}
/**
* Affiche le panel dans une boite de dialogue.
* @param _parent la boite de dialogue parent
* @param _titre le titre de la boite de dialogue
*/
public void affiche(Dialog _parent)
{
createDialog(_parent);
afficheDialog(_parent);
}
/**
* Affiche le panel dans une boite de dialogue.
* @param _parent la fenetre parent
*/
public void affiche(Frame _parent)
{
createDialog(_parent);
afficheDialog(_parent);
}
/**
* Affiche le panel dans une boite de dialogue.
* @param _parent la fenetre parent
*/
public void affiche(Component _parent)
{
createDialog();
afficheDialog(_parent);
}
private void createDialog()
{
if (dialog_ != null)
{
if (EbliLib.DEBUG)
System.err.println("Cet element est deja visualise");
dialog_.dispose();
}
dialog_ = new EbliSimpleDialog(this);
dialog_.setTitle(title_);
}
private void createDialog(Frame _parent)
{
if (dialog_ != null)
{
if (EbliLib.DEBUG)
System.err.println("Cet element est deja visualise");
}
dialog_ = new EbliSimpleDialog(_parent, this);
}
private void createDialog(Dialog _parent)
{
if (dialog_ != null)
{
if (EbliLib.DEBUG)
System.err.println("Cet element est deja visualise");
//dialog_.dispose();
}
dialog_ = new EbliSimpleDialog(_parent, this);
}
/**
* Affiche le panel dans une boite de dialogue modale.
* @param _parent la boite de dialogue parent
*/
public int afficheModale(Dialog _parent)
{
createDialog(_parent);
modale_ = true;
return afficheDialog(_parent);
}
/**
* Affiche le panel dans une boite de dialogue modale.
* @param _parent la fenetre parent
*/
public int afficheModale(Frame _parent)
{
createDialog(_parent);
modale_ = true;
return afficheDialog(_parent);
}
public int afficheModale(Dialog _parent, String _title)
{
setTitle(_title);
return afficheModale(_parent);
}
public int afficheModale(Frame _parent, String _title)
{
setTitle(_title);
return afficheModale(_parent);
}
public int afficheModale(Component _parent, String _title)
{
setTitle(_title);
return afficheModale(_parent);
}
/**
* Affiche le panel dans une boite de dialogue modale.
* @param _parent la fenetre parent
*/
public int afficheModale(Component _parent)
{
createDialog();
modale_ = true;
return afficheDialog(_parent);
}
public void addEmptyBorder(int _b)
{
addEmptyBorder(this, _b);
}
public void addEmptyBorder(JComponent _c, int _b)
{
_c.setBorder(BorderFactory.createEmptyBorder(_b, _b, _b, _b));
}
/**
* Affiche le dialogue et le positionne par rapport a <code>_parent</code>.
*/
private int afficheDialog(Component _parent)
{
dialog_.setModal(modale_);
dialog_.addWindowListener(this);
dialog_.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog_.setContentPane(construitDialogPanel());
dialog_.setLocationRelativeTo(_parent);
dialog_.pack();
dialog_.show();
return response_;
}
public static BuPanel getInfosPanel(BuInformationsSoftware _isoft)
{
BuPanel mpi = new BuPanel();
mpi.setLayout(new BuVerticalLayout(5));
mpi.setBorder(new EmptyBorder(5, 5, 5, 5));
mpi.setBackground(mpi.getBackground().darker());
mpi.setForeground(Color.white);
BuPicture ml_logo = null;
if (_isoft.logo != null)
{
ml_logo = new BuPicture(_isoft.logo);
}
BuLabelMultiLine ml_isoft =
new BuLabelMultiLine(
_isoft.name
+ "\nversion: "
+ _isoft.version
+ "\ndate: "
+ _isoft.date);
ml_isoft.setFont(BuLib.deriveFont("Label", Font.PLAIN, -2));
ml_isoft.setForeground(Color.white);
if (ml_logo != null)
mpi.add(ml_logo);
mpi.add(ml_isoft);
return mpi;
}
/**
* Construit le panel de la boite de dialogue.
*/
private BuPanel construitDialogPanel()
{
BuPanel princ = new BuPanel();
princ.setLayout(new BuBorderLayout());
if (isoft_ != null)
{
princ.add(getInfosPanel(isoft_), BuBorderLayout.WEST);
}
princ.add(lbError_, BuBorderLayout.NORTH);
princ.add(this, BuBorderLayout.CENTER);
BuPanel pnAction = new BuPanel();
pnAction.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
pnAction.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
switch (option_)
{
case OK_CANCEL_APPLY_OPTION :
pnAction.add(construireOk());
pnAction.add(construireApply());
pnAction.add(construireCancel());
break;
case OK_CANCEL_OPTION :
pnAction.add(construireOk());
pnAction.add(construireCancel());
break;
case OK_OPTION :
pnAction.add(construireOk());
break;
case OK_APPLY_OPTION :
pnAction.add(construireOk());
pnAction.add(construireApply());
break;
case CANCEL_OPTION :
pnAction.add(construireCancel());
break;
}
princ.add(pnAction, BuBorderLayout.SOUTH);
princ.doLayout();
return princ;
}
protected JTextField addLabelFileChooserPanel(String _label)
{
return addLabelFileChooserPanel(this, _label, null, false);
}
protected JTextField addLabelFileChooserPanel(
String _label,
String _initValue)
{
return addLabelFileChooserPanel(this, _label, _initValue, false);
}
protected JTextField addLabelFileChooserPanel(
String _label,
String _initValue,
boolean _chooseDir)
{
return addLabelFileChooserPanel(this, _label, _initValue, _chooseDir);
}
protected JTextField addLabelFileChooserPanel(
Container _c,
String _label,
String _initValue,
boolean _chooseDir)
{
JLabel lb = addLabel(_c, _label);
lb.setVerticalTextPosition(JLabel.CENTER);
JTextField r = new BuTextField(_initValue);
r.setToolTipText(_initValue);
r.setColumns(15);
lb.setLabelFor(r);
BuPanel pn = new BuPanel();
pn.setLayout(new BuHorizontalLayout(0, false, true));
pn.add(r);
JButton j = new BuButton("...");
if (_chooseDir)
{
j.putClientProperty(CHOOSE_FILE_OPEN_DIR, Boolean.TRUE);
}
j.putClientProperty(CHOOSE_FILE_TXT_FIELD_PROPERTY, r);
j.setActionCommand("...");
j.addActionListener(this);
pn.add(j);
_c.add(pn);
return r;
}
/**
* Construit un bouton ayant comme label <code>_text</code> et comme
* "ActionCommand" <code>_action</code>.
*/
protected JButton construireBuButton(String _text, String _action)
{
BuButton r = new BuButton(_text);
r.setActionCommand(_action);
r.addActionListener(this);
return r;
}
protected JButton construireOk()
{
JButton bt = construireBuButton("Continuer", "OK");
bt.setMnemonic(KeyEvent.VK_C);
return bt;
}
protected JButton construireCancel()
{
JButton bt = construireBuButton("Annuler", "CANCEL");
bt.setMnemonic(KeyEvent.VK_N);
return bt;
}
private JButton construireApply()
{
JButton bt = construireBuButton("Appliquer", "APPLY");
bt.setMnemonic(KeyEvent.VK_A);
return bt;
}
/**
* ajoute au panel un label dont la couleur de texte est rouge.
*/
protected BuLabel addRedLabel()
{
return addRedLabel(this);
}
protected BuLabel addRedLabel(Container _c)
{
BuLabel r = new BuLabel();
r.setForeground(Color.red);
_c.add(r);
return r;
}
protected BuLabel addLabel(String _l)
{
return addLabel(this, _l);
}
protected BuLabel addLabel(Container _c, String _l)
{
BuLabel r = new BuLabel(_l);
_c.add(r);
return r;
}
protected BuTextField addLabelDoubleText(String _label)
{
return addLabelDoubleText(this, _label);
}
protected BuTextField addLabelDoubleText(Container _c, String _label)
{
addLabel(_c, _label);
return addDoubleText(_c);
}
protected BuTextField addLabelIntegerText(String _label)
{
return addLabelIntegerText(this, _label);
}
protected BuTextField addLabelIntegerText(Container _c, String _label)
{
addLabel(_c, _label);
return addIntegerText(_c);
}
protected BuTextField addLabelStringText(String _label)
{
addLabel(_label);
return addStringText();
}
protected BuTextField addDoubleText()
{
return addDoubleText(this);
}
protected BuTextField addDoubleText(Container _c)
{
BuTextField r = new BuTextField(20);
r.setCharValidator(BuCharValidator.DOUBLE);
r.setStringValidator(BuStringValidator.DOUBLE);
r.setValueValidator(BuValueValidator.DOUBLE);
_c.add(r);
return r;
}
protected BuTextField addDoubleText(Container _c, double _d)
{
BuTextField r = addDoubleText(_c);
r.setText(_d + "");
return r;
}
protected BuTextField addStringText()
{
return addStringText(this);
}
protected BuTextField addStringText(Container _c)
{
BuTextField txt = new BuTextField();
_c.add(txt);
return txt;
}
protected BuTextField addIntegerText()
{
return addIntegerText(this);
}
protected BuTextField addIntegerText(Container _c)
{
BuTextField r = new BuTextField(20);
r.setCharValidator(BuCharValidator.INTEGER);
r.setStringValidator(BuStringValidator.INTEGER);
r.setValueValidator(BuValueValidator.INTEGER);
_c.add(r);
return r;
}
protected BuTextField addIntegerText(int _d)
{
return addIntegerText(this, _d);
}
protected BuTextField addIntegerText(Container _c, int _d)
{
BuTextField r = addIntegerText(_c);
r.setText(_d + "");
return r;
}
public static final boolean isOkResponse(int r)
{
return r == JOptionPane.OK_OPTION;
}
public static final boolean isCancelResponse(int r)
{
return r == JOptionPane.CANCEL_OPTION;
}
/**
* Recupere les evt des boutons ok,cancel et apply.
* bouton OK : valide(), actionApply(),actionOK() et actionClose() )<br/>
* bouton cancel : actionCancel() et et actionClose()<br/>
* bouton apply : valide(), actionApply()<br/>
*/
public void actionPerformed(ActionEvent _evt)
{
String com = _evt.getActionCommand();
if ("OK".equals(com))
{
actionOK();
}
else if ("CANCEL".equals(com))
{
actionCancel();
}
else if ("APPLY".equals(com))
{
apply();
}
else if ("...".equals(com))
{
JComponent jsrc = (JComponent) _evt.getSource();
Object o = jsrc.getClientProperty(CHOOSE_FILE_TXT_FIELD_PROPERTY);
if (o instanceof JTextField)
{
JTextField txt = (JTextField) o;
JLabel l = (JLabel) txt.getClientProperty("labeledBy");
File initFile = null;
File dir = null;
String txtText = txt.getText();
if ((txtText != null) && (txtText.trim().length() > 0))
{
initFile = new File(txt.getText());
dir = initFile.getParentFile();
}
else
{
dir = lastFile_;
}
BuFileChooser bf = new BuFileChooser();
Boolean b = (Boolean) jsrc.getClientProperty(CHOOSE_FILE_OPEN_DIR);
if ((b != null) && (b.equals(Boolean.TRUE)))
{
bf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
if ((dir != null) && (dir.isDirectory()))
{
bf.setCurrentDirectory(dir);
}
if (l != null)
bf.setDialogTitle(l.getText());
bf.setMultiSelectionEnabled(false);
int r = bf.showOpenDialog(this);
if (r == BuFileChooser.APPROVE_OPTION)
{
File out = bf.getSelectedFile();
setLastFile(out.getParentFile());
if ((initFile == null) || (!out.equals(initFile)))
{
String s = out.getAbsolutePath();
txt.setText(s);
txt.setToolTipText(s);
}
}
}
}
}
protected void fermerDialog()
{
closeDialog();
if (dialog_ != null)
{
dialog_.dispose();
}
dialog_ = null;
}
/**
* maj du layout et de la boite de dialogue.
*/
public void actualiseAffichage()
{
doLayout();
if (dialog_ != null)
dialog_.pack();
}
/**
* Méthode à surcharger : elle est appelee si le bouton APPLY est
* active.
*/
public void apply()
{
}
public void ok()
{
apply();
}
public void cancel()
{
}
public void closeDialog()
{
}
/**
* intialise la reponse (JOptionPane.CANCEL_OPTION)
* puis ferme le dialogue.
*/
public final void actionCancel()
{
response_ = JOptionPane.CANCEL_OPTION;
cancel();
fermerDialog();
}
/**
* Si valide, intialise la reponse (JOptionPane.OK_OPTION)
* ,appelle la fonction actionApply() puis ferme le dialogue.
*/
public final void actionOK()
{
if (valide())
{
response_ = JOptionPane.OK_OPTION;
ok();
fermerDialog();
}
}
public void windowActivated(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
actionCancel();
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
/**
*
*/
public String getTitle()
{
return title_;
}
/**
*
*/
public void setTitle(String _string)
{
if (_string != null)
{
title_ = _string;
}
}
/**
*
*/
public File getLastFile()
{
return lastFile_;
}
/**
*
*/
public void setLastFile(File _file)
{
lastFile_ = _file;
}
}
--- NEW FILE: EnhancedDialog.java ---
/*
* EnhancedDialog.java - Handles OK/Cancel for you
* Copyright (C) 1998, 1999, 2001 Slava Pestov
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fudaa.ebli.dialog;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
* A dialog box that handles window closing, the ENTER key and the ESCAPE
* key for you. All you have to do is implement ok() (called when
* Enter is pressed) and cancel() (called when Escape is pressed, or window
* is closed).
* @author Slava Pestov
* @version $Id: EnhancedDialog.java,v 1.1 2003/07/04 14:32:48 deniger Exp $
*/
public class EnhancedDialog extends JDialog
{
public EnhancedDialog(Frame parent)
{
super(parent);
init();
}
public EnhancedDialog(Dialog _c)
{
super(_c);
init();
}
public EnhancedDialog()
{
super();
init();
}
private void init()
{
((Container)getLayeredPane()).addContainerListener(
new ContainerHandler());
getContentPane().addContainerListener(new ContainerHandler());
keyHandler = new KeyHandler();
addKeyListener(keyHandler);
addWindowListener(new WindowHandler());
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}
public void ok()
{
}
public void cancel()
{
}
// protected members
protected KeyHandler keyHandler;
// Recursively adds our key listener to sub-components
class ContainerHandler extends ContainerAdapter
{
public void componentAdded(ContainerEvent evt)
{
componentAdded(evt.getChild());
}
public void componentRemoved(ContainerEvent evt)
{
componentRemoved(evt.getChild());
}
private void componentAdded(Component comp)
{
comp.addKeyListener(keyHandler);
if(comp instanceof Container)
{
Container cont = (Container)comp;
cont.addContainerListener(this);
Component[] comps = cont.getComponents();
for(int i = 0; i < comps.length; i++)
{
componentAdded(comps[i]);
}
}
}
private void componentRemoved(Component comp)
{
comp.removeKeyListener(keyHandler);
if(comp instanceof Container)
{
Container cont = (Container)comp;
cont.removeContainerListener(this);
Component[] comps = cont.getComponents();
for(int i = 0; i < comps.length; i++)
{
componentRemoved(comps[i]);
}
}
}
}
class KeyHandler extends KeyAdapter
{
public void keyPressed(KeyEvent evt)
{
if(evt.isConsumed())
return;
if(evt.getKeyCode() == KeyEvent.VK_ENTER)
{
// crusty workaround
Component comp = getFocusOwner();
while(comp != null)
{
if(comp instanceof JComboBox)
{
JComboBox combo = (JComboBox)comp;
if(combo.isEditable())
{
Object selected = combo.getEditor().getItem();
if(selected != null)
combo.setSelectedItem(selected);
}
break;
}
comp = comp.getParent();
}
ok();
evt.consume();
}
else if(evt.getKeyCode() == KeyEvent.VK_ESCAPE)
{
cancel();
evt.consume();
}
}
}
class WindowHandler extends WindowAdapter
{
public void windowClosing(WindowEvent evt)
{
cancel();
}
}
}
Index: EbliSimpleDialog.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/ebli/src/org/fudaa/ebli/dialog/EbliSimpleDialog.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** EbliSimpleDialog.java 19 May 2003 14:21:19 -0000 1.4
--- EbliSimpleDialog.java 4 Jul 2003 14:32:48 -0000 1.5
***************
*** 1,455 ****
/*
! * @file PrertPnDialog.java
! * @creation 2002-09-03
! * @modification $Date$
! * @license GNU General Public License 2
! * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
! * @mail de...@fu...
*/
package org.fudaa.ebli.dialog;
! import java.awt.Color;
! import java.awt.Component;
import java.awt.Dialog;
- import java.awt.FlowLayout;
import java.awt.Frame;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
-
- import javax.swing.BorderFactory;
- import javax.swing.JDialog;
- import javax.swing.JOptionPane;
-
- import com.memoire.bu.BuBorderLayout;
- import com.memoire.bu.BuButton;
- import com.memoire.bu.BuCharValidator;
- import com.memoire.bu.BuLabel;
- import com.memoire.bu.BuPanel;
- import com.memoire.bu.BuStringValidator;
- import com.memoire.bu.BuTextField;
- import com.memoire.bu.BuValueValidator;
-
- import org.fudaa.ebli.commun.EbliLib;
/**
! * Un panneau qui peut etre facilement affichable dans une boite de dialogue.
! * Cette classe reprend le mode de fonctionnement de JOptionPane.
! * Les methodes valide(), actionApply() et actionCancel() peuvent être
! * redefinies : valide() est appele avant d'appliquer les changements
! * ( la methode actionApply() ).
! *
! * @version $Id$
! * @author Bertrand Marchand,Fred Deniger
*/
! public class EbliSimpleDialog
! extends BuPanel
! implements ActionListener, WindowListener
{
- /**
- * Option : uniquement un bouton ok sera affiche. Reponse donnee par le
- * dialogue si le bouton "ok" utilise.
- */
- public static final int OK_OPTION = 0;
- public static final int OK_CANCEL_OPTION = 1;
- public static final int OK_APPLY_OPTION = 2;
- public static final int OK_CANCEL_APPLY_OPTION = 3;
- protected int option_;
- protected boolean modale_;
- protected JDialog dialog_;
- private int response_;
- public EbliSimpleDialog()
- {
- this(OK_CANCEL_OPTION);
- }
- /**
- * Les options possibles les variables statiques <code>OK_OPTION</code>
- * (un bouton ok unique,
- * <code>OK_CANCEL_OPTION</code>,...
- */
- public EbliSimpleDialog(int _option)
- {
- option_ = _option;
- response_ = JOptionPane.CANCEL_OPTION;
- }
-
-
- /**
- * Permet d'initialiser ce dialogue a l'aide d'une chaine. Envoie une exception si non implante.
- */
- public void setValue(String _f)
- {
- throw new NoSuchMethodError("Methode non implantee");
- }
-
- /**
- * Renvoie la chaine caracterisant le contenu de ce dialogue.
- */
- public String getValue()
- {
- throw new NoSuchMethodError("Methode non implantee");
- }
-
-
-
- public void setModale(boolean _modale)
- {
- modale_ = _modale;
- }
-
- public boolean valide()
- {
- return true;
- }
- /**
- * Affiche le panel dans une boite de dialogue.
- * @param _parent la boite de dialogue parent
- * @param _titre le titre de la boite de dialogue
- */
- public void affiche(Dialog _parent, String _titre)
- {
- createDialog(_parent,_titre);
- afficheDialog(_parent);
- }
! /**
! * Affiche le panel dans une boite de dialogue.
! * @param _parent la fenetre parent
! * @param _titre le titre de la boite de dialogue
! */
! public void affiche(Frame _parent, String _titre)
! {
! createDialog(_parent,_titre);
! afficheDialog(_parent);
! }
!
! /**
! * Affiche le panel dans une boite de dialogue.
! * @param _parent la fenetre parent
! * @param _titre le titre de la boite de dialogue
! */
! public void affiche(Component _parent, String _titre)
! {
! createDialog(_titre);
! afficheDialog(_parent);
! }
!
!
! private void createDialog(String _titre)
! {
! if (dialog_ != null)
! {
! if(EbliLib.DEBUG)
! System.err.println("Cet element est deja visualise");
! dialog_.dispose();
! }
! dialog_ = new JDialog();
! dialog_.setTitle(_titre);
! }
!
! private void createDialog(Frame _parent, String _titre)
{
! if (dialog_ != null)
! {
! if(EbliLib.DEBUG)
! System.err.println("Cet element est deja visualise");
! // dialog_.dispose();
! }
! dialog_ = new JDialog(_parent, _titre);
}
!
! private void createDialog(Dialog _parent, String _titre)
! {
! if (dialog_ != null)
{
! if(EbliLib.DEBUG)
! System.err.println("Cet element est deja visualise");
! //dialog_.dispose();
}
- dialog_ = new JDialog(_parent, _titre);
- }
-
-
!
! /**
! * Affiche le panel dans une boite de dialogue modale.
! * @param _parent la boite de dialogue parent
! * @param _titre le titre de la boite de dialogue
! */
! public int afficheModale(Dialog _parent, String _titre)
! {
! createDialog(_parent,_titre);
! modale_=true;
! return afficheDialog(_parent);
! }
!
! /**
! * Affiche le panel dans une boite de dialogue modale.
! * @param _parent la fenetre parent
! * @param _titre le titre de la boite de dialogue
! */
! public int afficheModale(Frame _parent, String _titre)
! {
! createDialog(_parent,_titre);
! modale_=true;
! return afficheDialog(_parent);
! }
!
! /**
! * Affiche le panel dans une boite de dialogue modale.
! * @param _parent la fenetre parent
! * @param _titre le titre de la boite de dialogue
! */
! public int afficheModale(Component _parent, String _titre)
! {
! createDialog(_titre);
! modale_=true;
! return afficheDialog(_parent);
! }
!
! public void addEmptyBorder(int _b)
! {
! setBorder(BorderFactory.createEmptyBorder(_b, _b, _b, _b));
! }
! /**
! * Affiche le dialogue et le positionne par rapport a <code>_parent</code>.
! */
! private int afficheDialog(Component _parent)
! {
! dialog_.setModal(modale_);
! dialog_.addWindowListener(this);
! dialog_.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
! dialog_.setContentPane(construitDialogPanel());
! // Dimension dParent;
! // Point pParent;
! // Dimension dThis = dialog_.getPreferredSize();
! // Point pThis = new Point();
! // if (_parent == null)
! // {
! // dParent = Toolkit.getDefaultToolkit().getScreenSize();
! // pParent = new Point(0, 0);
! // }
! // else
! // {
! // dParent = _parent.getPreferredSize();
! // pParent = _parent.getLocation();
! // }
! // pThis.x = pParent.x + (dParent.width - dThis.width) / 2;
! // pThis.y = pParent.y + (dParent.height - dThis.height) / 2;
! // dialog_.setLocation(pThis);
! dialog_.setLocationRelativeTo(_parent);
! dialog_.pack();
! dialog_.show();
! return response_;
! }
! /**
! * Construit le panel de la boite de dialogue.
! */
! private BuPanel construitDialogPanel()
! {
! BuPanel princ = new BuPanel();
! princ.setLayout(new BuBorderLayout());
! princ.add(this, BuBorderLayout.CENTER);
! BuPanel pnAction = new BuPanel();
! pnAction.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
! pnAction.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
! switch (option_)
! {
! case OK_OPTION :
! construireOk(pnAction);
! ...
[truncated message content] |