1 package thinlet.drafts; 2 3 import thinlet.*; 4 import java.awt.*; 5 6 public class ModalDemo { 7 8 public void start(Thinlet thinlet, Object previousfield) { 9 Object modaldialog = null; 10 try { 11 modaldialog = thinlet.parse("/thinlet/drafts/modaldialog.xml", this); 12 } catch (Exception exc) { exc.printStackTrace(); return; } 13 Object field = thinlet.find(modaldialog, "field"); 14 thinlet.setString(field, "text", String.valueOf(System.currentTimeMillis())); 15 thinlet.add(modaldialog); 16 17 startModal(thinlet, modaldialog); 18 19 String text = thinlet.getString(field, "text"); 20 thinlet.setString(previousfield, "text", text); 21 } 22 23 public void close(Thinlet thinlet, Object dialog) { 24 thinlet.remove(dialog); 25 stopModal(); 26 } 27 28 private void startModal(Thinlet thinlet, Object modaldialog) { 29 try { 30 EventQueue queue = thinlet.getToolkit().getSystemEventQueue(); 31 while (thinlet.getParent(modaldialog) != null) { 32 AWTEvent event = queue.getNextEvent(); 33 Object src = event.getSource(); 34 if (src instanceof Component) { 38 ((Component) src).dispatchEvent(event); 39 } else if (src instanceof MenuComponent) { 40 ((MenuComponent) src).dispatchEvent(event); 41 } 42 } 43 } catch(InterruptedException ie) { ie.printStackTrace(); } 44 } 45 46 private void stopModal() { 47 synchronized (this) { 48 notifyAll(); 49 } 50 } 51 } | Popular Tags |