1 package com.ca.directory.jxplorer.tree; 2 3 import com.ca.commons.cbutil.*; 4 5 import javax.swing.*; 6 import java.awt.*; 7 import java.awt.event.ActionEvent ; 8 import java.awt.event.ActionListener ; 9 import java.util.Properties ; 10 import java.util.logging.Logger ; 11 12 18 public class ConfirmDialog extends JDialog implements ActionListener 19 { 20 21 CBPanel display; 22 JCheckBox showAgain; 23 Properties myProperties; 24 String binaryProperty = ""; 25 CBButton OK, Cancel; 26 boolean userResponse = false; 27 28 private static Logger log = Logger.getLogger(ConfirmDialog.class.getName()); 29 44 45 public ConfirmDialog(String Msg, String binaryProperty, Frame parent) 46 { 47 super(parent); 48 this.myProperties = com.ca.directory.jxplorer.JXplorer.myProperties; 49 this.binaryProperty = binaryProperty; 50 setSize(new Dimension(300,120)); 52 getContentPane().add(display = new CBPanel()); 53 54 display.addln(new JLabel(Msg)); 55 JPanel buttons = new JPanel(); 56 buttons.add(OK = new CBButton(CBIntText.get("OK"), CBIntText.get("Click here to confirm."))); 57 buttons.add(Cancel = new CBButton(CBIntText.get("Cancel"), CBIntText.get("Click here to cancel."))); 58 display.addln(buttons); 59 60 OK.addActionListener(this); 61 Cancel.addActionListener(this); 62 63 if ((myProperties != null) && (binaryProperty != null) && (myProperties.getProperty(binaryProperty) != null)) 64 { 65 showAgain = new JCheckBox(CBIntText.get("show this dialog every time"), true); 66 display.addln(showAgain); 67 showAgain.addActionListener(this); 68 } 69 else 70 showAgain = null; 71 72 setVisible(false); 73 } 74 75 80 public boolean getUserResponse() 81 { 82 System.out.println("binary prop " + binaryProperty); 83 System.out.println("myProperties " + !(myProperties==null)); 84 85 if ("false".equals(myProperties.getProperty(binaryProperty))) 86 return true; 88 if (showAgain == null) return true; 90 showAgain.setSelected(true); 91 92 setVisible(true); 93 showAgain.setSelected(true); 94 95 startModal(); showAgain.setSelected(true); 97 98 return userResponse; 100 } 101 102 106 public void actionPerformed(ActionEvent ev) 107 { 108 109 if (ev.getSource() == showAgain) 110 { 111 myProperties.setProperty(binaryProperty, String.valueOf(showAgain.isSelected())); 113 showAgain.repaint(); 114 } 115 else if (ev.getSource() == OK) 116 { 117 userResponse = true; 119 stopModal(); 120 setVisible(false); 121 } 122 else if (ev.getSource() == Cancel) 123 { 124 userResponse = false; 126 stopModal(); 127 setVisible(false); 128 } 129 else 130 { 131 } 133 } 134 135 136 141 synchronized void startModal() { 142 150 if (isVisible() && !isShowing()) { 151 Container parent = this.getParent(); 152 while (parent != null) { 153 if (parent.isVisible() == false) { 154 parent.setVisible(true); 155 } 156 parent = parent.getParent(); 157 } 158 } 159 160 try { 161 if (SwingUtilities.isEventDispatchThread()) { 162 EventQueue theQueue = getToolkit().getSystemEventQueue(); 163 while (isVisible()) { 164 AWTEvent event = theQueue.getNextEvent(); 166 Object src = event.getSource(); 167 if (src instanceof Component) { 168 ((Component) src).dispatchEvent(event); 169 } else if (src instanceof MenuComponent) { 170 ((MenuComponent) src).dispatchEvent(event); 171 } else { 172 log.warning("unable to dispatch event: " + event); 173 } 174 } 175 } else 176 while (isVisible()) 177 wait(); 178 } catch(InterruptedException e){} 179 } 180 181 185 synchronized void stopModal() { 186 notifyAll(); 187 } 188 189 190 } | Popular Tags |