1 package rero.gui.script; 2 3 import rero.gui.*; 4 import rero.gui.windows.*; 5 import rero.gui.input.*; 6 import rero.ircfw.*; 7 8 import rero.gui.mdi.*; 9 10 import sleep.engine.*; 11 import sleep.runtime.*; 12 import sleep.interfaces.*; 13 14 import javax.swing.*; 15 16 import java.awt.*; 17 import java.util.*; 18 19 import text.*; 20 import text.list.*; 21 22 import rero.util.*; 23 24 public class WindowManagementOperators implements Function, Loadable 25 { 26 protected IRCSession session; 27 28 public WindowManagementOperators(IRCSession _session) 29 { 30 session = _session; 31 } 32 33 public boolean scriptLoaded(ScriptInstance script) 34 { 35 String [] contents = new String [] { 36 "&openWindow", 37 "&closeWindow", 38 "&setWindowState", 39 "&getWindowState", 40 "&activateWindow", 41 "&getActiveWindow", 42 "&getCurrentWindow", 43 "&getWindows", 44 "&tileWindows", 45 "&cascadeWindows" 46 }; 47 48 for (int x = 0; x < contents.length; x++) 49 { 50 script.getScriptEnvironment().getEnvironment().put(contents[x], this); 51 } 52 53 return true; 54 } 55 56 public boolean scriptUnloaded(ScriptInstance script) 57 { 58 return true; 59 } 60 61 public Scalar evaluate(String function, ScriptInstance script, Stack locals) 62 { 63 if (function.equals("&openWindow")) 64 { 65 String parms = locals.pop().toString(); 66 InternalDataList ircData = (InternalDataList)session.getCapabilities().getDataStructure("clientInformation"); 67 68 if (ClientUtils.isChannel(parms)) 69 { 70 session.getCapabilities().getUserInterface().openChannelWindow(ircData.getChannel(parms)); 71 } 72 else 73 { 74 session.getCapabilities().getUserInterface().openQueryWindow(parms, locals.isEmpty()); } 77 } 78 else if (function.equals("&closeWindow")) 79 { 80 String window = locals.pop().toString(); 81 82 if (session.isWindow(window)) 83 { 84 session.getWindow(window).getWindow().closeWindow(); 85 } 86 } 87 else if (function.equals("&setWindowState") && locals.size() == 2) 88 { 89 String window = locals.pop().toString(); 90 String state = locals.pop().toString().toUpperCase(); 91 92 if (session.isWindow(window)) 93 { 94 if (state.equals("NORMAL")) 95 { 96 session.getWindow(window).getWindow().setMaximum(false); 97 session.getWindow(window).getWindow().setIcon(false); 98 } 99 else if (state.equals("MAXIMIZED")) 100 { 101 session.getWindow(window).getWindow().setIcon(false); 102 session.getWindow(window).getWindow().setMaximum(true); 103 } 104 else if (state.equals("MINIMIZED")) 105 { 106 session.getWindow(window).getWindow().setIcon(true); 107 } 108 } 109 } 110 else if (function.equals("&setWindowState") && locals.size() == 1) 111 { 112 String state = locals.pop().toString().toUpperCase(); 113 114 JFrame window = SessionManager.getGlobalCapabilities().getFrame(); 115 116 if (state.equals("NORMAL")) 117 { 118 window.setExtendedState(JFrame.NORMAL); 119 } 120 else if (state.equals("MAXIMIZED")) 121 { 122 window.setExtendedState(JFrame.MAXIMIZED_BOTH); 123 } 124 else if (state.equals("MINIMIZED")) 125 { 126 window.setExtendedState(JFrame.ICONIFIED); 127 } 128 } 129 else if (function.equals("&getWindowState") && locals.size() == 0) 130 { 131 JFrame window = SessionManager.getGlobalCapabilities().getFrame(); 132 int state = window.getExtendedState(); 133 134 if ((state & JFrame.ICONIFIED) == JFrame.ICONIFIED) 135 { 136 return SleepUtils.getScalar("MINIMIZED"); 137 } 138 else if ((state & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) 139 { 140 return SleepUtils.getScalar("MAXIMIZED"); 141 } 142 else 143 { 144 return SleepUtils.getScalar("NORMAL"); 145 } 146 } 147 else if (function.equals("&getWindowState") && locals.size() == 1) 148 { 149 String window = locals.pop().toString(); 150 151 if (session.isWindow(window)) 152 { 153 if (session.getWindow(window).getWindow().isMaximum()) 154 { 155 return SleepUtils.getScalar("MAXIMIZED"); 156 } 157 else if (session.getWindow(window).getWindow().isIcon()) 158 { 159 return SleepUtils.getScalar("MINIMIZED"); 160 } 161 else 162 { 163 return SleepUtils.getScalar("NORMAL"); 164 } 165 } 166 } 167 else if (function.equals("&getActiveWindow")) 168 { 169 if (session.getRealActiveWindow() == null) 170 return SleepUtils.getScalar(StatusWindow.STATUS_NAME); 171 172 return SleepUtils.getScalar(session.getRealActiveWindow().getName()); 173 } 174 else if (function.equals("&getCurrentWindow")) 175 { 176 return SleepUtils.getScalar(session.getActiveWindow().getName()); 177 } 178 else if (function.equals("&getWindows")) 179 { 180 Set returnValue = new LinkedHashSet(); 181 Iterator i = session.getAllWindows().iterator(); 182 while (i.hasNext()) 183 { 184 StatusWindow temp = (StatusWindow)i.next(); 185 returnValue.add(temp.getName()); 186 } 187 188 return SleepUtils.getArrayWrapper(returnValue); 189 } 190 else if (function.equals("&activateWindow") && locals.size() == 1) 191 { 192 String window = locals.pop().toString(); 193 194 if (session.isWindow(window)) 195 { 196 session.getWindow(window).getWindow().activate(); 197 } 198 } 199 else if (function.equals("&tileWindows")) 200 { 201 if (session.getDesktop() instanceof ClientDesktop) 202 { 203 ClientUtils.invokeLater(new Runnable () { public void run() { 204 ((ClientDesktop)session.getDesktop()).tileWindows(); 205 } }); 206 } 207 } 208 else if (function.equals("&cascadeWindows")) 209 { 210 if (session.getDesktop() instanceof ClientDesktop) 211 { 212 ClientUtils.invokeLater(new Runnable () { public void run() { 213 ((ClientDesktop)session.getDesktop()).cascadeWindows(); 214 } }); 215 } 216 } 217 218 return SleepUtils.getEmptyScalar(); 219 } 220 } 221 | Popular Tags |