001: /**
002: * $RCSfile: XuiOptionPane.java,v $
003: * @creation 01/02/00
004: * @modification $Date: 2002/06/20 17:35:45 $
005: */package com.memoire.vainstall.xui;
006:
007: import com.memoire.vainstall.*;
008: import java.awt.*;
009: import java.awt.event.*;
010: import javax.swing.*;
011: import javax.swing.border.*;
012:
013: /**
014: * @version $Id: XuiOptionPane.java,v 1.5 2002/06/20 17:35:45 desnoix Exp $
015: * @author Guillaume Desnoix
016: */
017:
018: public class XuiOptionPane extends JDialog implements ActionListener {
019: public final static int YES = 1;
020: public final static int NO = 2;
021: public final static int CANCEL = 4;
022: public final static int CONTINUE = 8;
023:
024: int reponse_;
025: XuiButton btYes_, btNo_, btCancel_, btContinue_;
026:
027: public XuiOptionPane(Dialog _parent, String _msg, String _title,
028: int _bts) {
029: super (_parent, _title);
030:
031: reponse_ = 0;
032:
033: JPanel mp = new XuiPanel();
034: mp.setBorder(new EmptyBorder(0, 10, 0, 10));
035: mp.setBackground(new Color(255, 128, 128));
036: mp.setForeground(new Color(255, 255, 0));
037:
038: if (_msg.indexOf('\n') < 0)
039: _msg = "\n" + _msg + "\n\n";
040:
041: {
042: mp.setLayout(new GridLayout(0, 1));
043: String s = _msg;
044: int n = 0;
045: while (!"".equals(s)) {
046: int i = s.indexOf('\n');
047: String t;
048: if (i >= 0) {
049: t = s.substring(0, i);
050: s = s.substring(i + 1);
051: } else {
052: t = s;
053: s = "";
054: }
055:
056: if (t.length() > 45) {
057: i = t.indexOf(' ', t.length() / 2 - 5);
058: if (i > 0) {
059: s = t.substring(i + 1)
060: + ("".equals(s) ? "" : "\n" + s);
061: t = t.substring(0, i);
062: }
063: }
064:
065: if ((n == 0) || t.startsWith("^")) {
066: if (t.startsWith("^"))
067: t = t.substring(1);
068: XuiTitle lb = new XuiTitle(t, 1);
069: lb.setFont(new Font("SansSerif", Font.PLAIN, 16));
070: mp.add(lb, n++);
071: } else {
072: XuiLabel lb = new XuiLabel(t);
073: lb.setHorizontalAlignment(SwingConstants.CENTER);
074: mp.add(lb, n++);
075: }
076: }
077: }
078: /*
079: else
080: {
081: mp.setLayout(new GridLayout(1,1));
082: XuiLabel lb=new XuiLabel(_msg);
083: lb.setHorizontalAlignment(SwingConstants.CENTER);
084: mp.add(lb,0);
085: }
086: */
087:
088: JPanel bp = new XuiPanel();
089: bp.setLayout(new FlowLayout(FlowLayout.RIGHT, 4, 0));
090: bp.setBackground(Color.black);
091: bp.setBorder(new EmptyBorder(5, 5, 5, 5));
092:
093: btYes_ = new XuiButton(VAGlobals
094: .i18n("Common_OptionPane.yesButtonText"));
095: btNo_ = new XuiButton(VAGlobals
096: .i18n("Common_OptionPane.noButtonText"));
097: btCancel_ = new XuiButton(VAGlobals
098: .i18n("Common_OptionPane.cancelButtonText"));
099: btContinue_ = new XuiButton(VAGlobals.i18n("Common_Continue"));
100:
101: btYes_.addActionListener(this );
102: btNo_.addActionListener(this );
103: btCancel_.addActionListener(this );
104: btContinue_.addActionListener(this );
105:
106: if ((_bts & YES) != 0)
107: bp.add(btYes_);
108: if ((_bts & NO) != 0)
109: bp.add(btNo_);
110: if ((_bts & CONTINUE) != 0)
111: bp.add(btContinue_);
112: if ((_bts & CANCEL) != 0)
113: bp.add(btCancel_);
114:
115: JComponent cp = (JComponent) getContentPane();
116: cp.setLayout(new BorderLayout());
117: cp.add(mp, BorderLayout.CENTER);
118: cp.add(bp, BorderLayout.SOUTH);
119:
120: setLocation(220, 60);
121: setLocationRelativeTo(_parent);
122: pack();
123: Dimension sz = getSize();
124: if (sz.width < 400)
125: sz.width = 400;
126: if (sz.height < 200)
127: sz.height = 200;
128: setSize(sz);
129: setResizable(false);
130: doLayout();
131: validate();
132: setModal(true);
133: }
134:
135: public void actionPerformed(ActionEvent _evt) {
136: Object source = _evt.getSource();
137:
138: if (source == btYes_)
139: reponse_ = YES;
140: if (source == btNo_)
141: reponse_ = NO;
142: if (source == btCancel_)
143: reponse_ = CANCEL;
144: if (source == btContinue_)
145: reponse_ = CONTINUE;
146:
147: hide();
148: }
149:
150: public int activate() {
151: show();
152: return reponse_;
153: }
154:
155: public static int showConfirmDialog(Dialog _parent, String _msg,
156: String _title) {
157: XuiOptionPane op = new XuiOptionPane(_parent, _msg, _title, YES
158: | NO);
159: return op.activate();
160: }
161:
162: public static void showErrorDialog(Dialog _parent, String _msg,
163: String _title) {
164: XuiOptionPane op = new XuiOptionPane(_parent, _msg, _title,
165: CONTINUE);
166: op.activate();
167: }
168:
169: public static void showMessageDialog(Dialog _parent, String _msg,
170: String _title) {
171: XuiOptionPane op = new XuiOptionPane(_parent, _msg, _title,
172: CONTINUE);
173: op.activate();
174: }
175: }
|