1 6 7 package com.memoire.vainstall.xui; 8 9 import com.memoire.vainstall.*; 10 import java.awt.*; 11 import java.awt.event.*; 12 import javax.swing.*; 13 import javax.swing.border.*; 14 15 19 20 public class XuiOptionPane 21 extends JDialog 22 implements ActionListener 23 { 24 public final static int YES =1; 25 public final static int NO =2; 26 public final static int CANCEL =4; 27 public final static int CONTINUE=8; 28 29 int reponse_; 30 XuiButton btYes_,btNo_,btCancel_,btContinue_; 31 32 public XuiOptionPane(Dialog _parent, String _msg, String _title, int _bts) 33 { 34 super(_parent,_title); 35 36 reponse_=0; 37 38 JPanel mp=new XuiPanel(); 39 mp.setBorder(new EmptyBorder(0,10,0,10)); 40 mp.setBackground(new Color(255,128,128)); 41 mp.setForeground(new Color(255,255, 0)); 42 43 if(_msg.indexOf('\n')<0) _msg="\n"+_msg+"\n\n"; 44 45 { 46 mp.setLayout(new GridLayout(0,1)); 47 String s=_msg; 48 int n=0; 49 while(!"".equals(s)) 50 { 51 int i=s.indexOf('\n'); 52 String t; 53 if(i>=0) { t=s.substring(0,i); s=s.substring(i+1); } 54 else { t=s; s=""; } 55 56 if(t.length()>45) 57 { 58 i=t.indexOf(' ',t.length()/2-5); 59 if(i>0) 60 { 61 s=t.substring(i+1)+("".equals(s) ? "": "\n"+s); 62 t=t.substring(0,i); 63 } 64 } 65 66 if((n==0)||t.startsWith("^")) 67 { 68 if(t.startsWith("^")) t=t.substring(1); 69 XuiTitle lb=new XuiTitle(t,1); 70 lb.setFont(new Font("SansSerif",Font.PLAIN,16)); 71 mp.add(lb,n++); 72 } 73 else 74 { 75 XuiLabel lb=new XuiLabel(t); 76 lb.setHorizontalAlignment(SwingConstants.CENTER); 77 mp.add(lb,n++); 78 } 79 } 80 } 81 90 91 JPanel bp=new XuiPanel(); 92 bp.setLayout(new FlowLayout(FlowLayout.RIGHT,4,0)); 93 bp.setBackground(Color.black); 94 bp.setBorder(new EmptyBorder(5,5,5,5)); 95 96 btYes_ =new XuiButton(VAGlobals.i18n("Common_OptionPane.yesButtonText")); 97 btNo_ =new XuiButton(VAGlobals.i18n("Common_OptionPane.noButtonText")); 98 btCancel_ =new XuiButton(VAGlobals.i18n("Common_OptionPane.cancelButtonText")); 99 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) bp.add(btYes_); 107 if((_bts&NO )!=0) bp.add(btNo_); 108 if((_bts&CONTINUE)!=0) bp.add(btContinue_); 109 if((_bts&CANCEL )!=0) bp.add(btCancel_); 110 111 JComponent cp=(JComponent)getContentPane(); 112 cp.setLayout(new BorderLayout()); 113 cp.add(mp,BorderLayout.CENTER); 114 cp.add(bp,BorderLayout.SOUTH); 115 116 setLocation(220,60); 117 setLocationRelativeTo(_parent); 118 pack(); 119 Dimension sz=getSize(); 120 if(sz.width <400) sz.width =400; 121 if(sz.height<200) sz.height=200; 122 setSize(sz); 123 setResizable(false); 124 doLayout(); 125 validate(); 126 setModal(true); 127 } 128 129 public void actionPerformed(ActionEvent _evt) 130 { 131 Object source=_evt.getSource(); 132 133 if(source==btYes_ ) reponse_=YES; 134 if(source==btNo_ ) reponse_=NO; 135 if(source==btCancel_ ) reponse_=CANCEL; 136 if(source==btContinue_) reponse_=CONTINUE; 137 138 hide(); 139 } 140 141 public int activate() 142 { 143 show(); 144 return reponse_; 145 } 146 147 public static int showConfirmDialog 148 (Dialog _parent, String _msg, String _title) 149 { 150 XuiOptionPane op=new XuiOptionPane(_parent,_msg,_title,YES|NO); 151 return op.activate(); 152 } 153 154 public static void showErrorDialog 155 (Dialog _parent, String _msg, String _title) 156 { 157 XuiOptionPane op=new XuiOptionPane(_parent,_msg,_title,CONTINUE); 158 op.activate(); 159 } 160 161 public static void showMessageDialog 162 (Dialog _parent, String _msg, String _title) 163 { 164 XuiOptionPane op=new XuiOptionPane(_parent,_msg,_title,CONTINUE); 165 op.activate(); 166 } 167 } 168 | Popular Tags |