use of javax.swing.event.InternalFrameEvent in project browsermator by pcalkins.
the class OpenFileThread method BuildNewWindow.
public void BuildNewWindow(Document doc, String full_filename) {
ArrayList<Procedure> newBugArray = new ArrayList<>();
// ArrayList<ProcedureView> newBugViewArray = new ArrayList<>();
NamedNodeMap NewAttributes = doc.getElementsByTagName("BrowserMatorWindow").item(0).getAttributes();
STAppData = new SeleniumTestToolData(newBugArray);
String filename_read = NewAttributes.getNamedItem("Filename").getNodeValue();
STAppData.setFilenames(full_filename);
if (hasGUI) {
STAppFrame = new SeleniumTestTool(STAppData);
STAppFrame.setResizable(true);
STAppFrame.setClosable(true);
STAppFrame.setMaximizable(true);
STAppFrame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() {
@Override
public void internalFrameClosing(InternalFrameEvent e) {
int closed = mainAppController.CheckToSaveChanges(STAppFrame, STAppData, false);
if (closed == 1) {
STAppFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
} else {
int thisMDIIndex = mainAppController.GetCurrentWindow();
mainAppController.RemoveWindow(thisMDIIndex);
// mainApp.RemoveWindow(MDIClasses.size()-1);
STAppFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}
});
}
NodeList FileSettingsNode = doc.getElementsByTagName("FileSettings");
String thisSettingsNodeName;
String thisSettingsNodeValue;
String stShowReport = "false";
String stEmailReport = "false";
String stEmailReportFail = "false";
String stIncludeScreenshots = "false";
String stExitAfter = "false";
String SMTPHostname = "";
String EmailLoginName = "";
String stPromptToClose = "false";
String TargetBrowser = "Firefox";
String WaitTime = "3";
String Sessions = "1";
String OSType = "Windows32";
String EmailPassword = "";
String unepassword = "";
String EmailTo = "";
String EmailFrom = "";
String EmailSubject = "";
String Timeout = "";
String stUniqueList = "false";
if (FileSettingsNode != null) {
try {
NodeList SettingsNodes = FileSettingsNode.item(0).getChildNodes();
for (int k = 0; k < SettingsNodes.getLength(); k++) {
thisSettingsNodeName = SettingsNodes.item(k).getNodeName();
thisSettingsNodeValue = SettingsNodes.item(k).getTextContent();
switch(thisSettingsNodeName) {
case "ShowReport":
stShowReport = thisSettingsNodeValue;
Boolean ShowReport = false;
if (stShowReport.equals("true")) {
ShowReport = true;
}
STAppData.setShowReport(ShowReport);
break;
case "IncludeScreenshots":
stIncludeScreenshots = thisSettingsNodeValue;
Boolean IncludeScreenshots = false;
if (stIncludeScreenshots.equals("true")) {
IncludeScreenshots = true;
}
STAppData.setIncludeScreenshots(IncludeScreenshots);
break;
case "EmailReport":
stEmailReport = thisSettingsNodeValue;
Boolean EmailReport = false;
if (stEmailReport.equals("true")) {
EmailReport = true;
}
STAppData.setEmailReport(EmailReport);
break;
case "EmailReportFail":
stEmailReportFail = thisSettingsNodeValue;
Boolean EmailReportFail = false;
if (stEmailReportFail.equals("true")) {
EmailReportFail = true;
}
STAppData.setEmailReportFail(EmailReportFail);
break;
case "ExitAfter":
stExitAfter = thisSettingsNodeValue;
Boolean ExitAfter = false;
if (stExitAfter.equals("true")) {
ExitAfter = true;
}
STAppData.setExitAfter(ExitAfter);
break;
case "SMTPHostname":
SMTPHostname = thisSettingsNodeValue;
STAppData.setSMTPHostname(SMTPHostname);
break;
case "EmailLoginName":
EmailLoginName = thisSettingsNodeValue;
STAppData.setEmailLoginName(EmailLoginName);
break;
case "PromptToClose":
stPromptToClose = thisSettingsNodeValue;
Boolean PromptToClose = false;
if (stPromptToClose.equals("true")) {
PromptToClose = true;
}
STAppData.setPromptToClose(PromptToClose);
break;
case "UniqueList":
stUniqueList = thisSettingsNodeValue;
Boolean UniqueList = false;
if (stUniqueList.equals("true")) {
UniqueList = true;
}
STAppData.setUniqueList(UniqueList);
break;
case "UniqueFileOption":
STAppData.setUniqueFileOption(thisSettingsNodeValue);
break;
case "TargetBrowser":
TargetBrowser = thisSettingsNodeValue;
STAppData.setTargetBrowser(TargetBrowser);
break;
case "WaitTime":
WaitTime = thisSettingsNodeValue;
int intWaitTime = Integer.parseInt(WaitTime);
STAppData.setWaitTime(intWaitTime);
break;
case "Sessions":
Sessions = thisSettingsNodeValue;
int intSessions = Integer.parseInt(Sessions);
STAppData.setSessions(intSessions);
break;
case "OSType":
OSType = thisSettingsNodeValue;
STAppData.setOSType(OSType);
break;
case "EmailPassword":
EmailPassword = thisSettingsNodeValue;
try {
unepassword = Protector.decrypt(EmailPassword);
} catch (GeneralSecurityException | IOException e) {
// System.out.println("decrypt error" + e.toString());
}
STAppData.setEmailPassword(unepassword);
break;
case "EmailTo":
EmailTo = thisSettingsNodeValue;
STAppData.setEmailTo(EmailTo);
break;
case "EmailFrom":
EmailFrom = thisSettingsNodeValue;
STAppData.setEmailFrom(EmailFrom);
break;
case "EmailSubject":
EmailSubject = thisSettingsNodeValue;
STAppData.setSubject(EmailSubject);
}
}
} catch (Exception e) {
System.out.println("exception reading file settings: " + e.toString());
}
}
try {
NodeList ProcedureList = doc.getElementsByTagName("Procedure");
boolean hasDataloop = false;
boolean hasURLList = false;
for (int i = 0; i < ProcedureList.getLength(); ++i) {
Element Procedure = (Element) ProcedureList.item(i);
String ProcType = "Procedure";
if (Procedure.hasAttribute("Type")) {
ProcType = Procedure.getAttribute("Type");
}
String DataLoopSource = "urllist";
if (Procedure.hasAttribute("DataLoopSource")) {
DataLoopSource = Procedure.getAttribute("DataLoopSource");
}
if ("Dataloop".equals(ProcType)) {
hasDataloop = true;
String DataFile = "";
if (Procedure.hasAttribute("DataLoopFile")) {
DataFile = Procedure.getAttribute("DataLoopFile");
// legacy support...
if (DataFile.contains(File.separator)) {
DataLoopSource = "file";
}
}
// failsafe
if (DataLoopSource.equals("") || DataLoopSource.equals("none")) {
DataLoopSource = "file";
}
if ("file".equals(DataLoopSource)) {
File DataFile_file = new File(DataFile);
if (hasGUI) {
STAppFrame.AddNewDataLoopFileView(DataFile_file);
}
STAppData.AddNewDataLoopFile(DataFile_file);
int last_added_bug_index = STAppData.BugArray.size() - 1;
Procedure newbug = STAppData.BugArray.get(last_added_bug_index);
if (hasGUI) {
ProcedureView newbugview = STAppFrame.BugViewArray.get(last_added_bug_index);
newbugview.populateJComboBoxStoredArrayLists(STAppData.VarLists);
mainAppController.AddNewHandlers(STAppFrame, STAppData, newbugview, newbug);
STAppFrame.UpdateDisplay();
}
}
if ("urllist".equals(DataLoopSource)) {
hasURLList = true;
STAppData.AddNewDataLoopURLList(DataFile);
int last_added_bug_index = STAppData.BugArray.size() - 1;
Procedure newbug = STAppData.BugArray.get(last_added_bug_index);
if (hasGUI) {
STAppFrame.AddNewDataLoopURLListView(DataFile);
ProcedureView newbugview = STAppFrame.BugViewArray.get(last_added_bug_index);
newbugview.populateJComboBoxStoredArrayLists(STAppData.VarLists);
mainAppController.AddNewHandlers(STAppFrame, STAppData, newbugview, newbug);
STAppFrame.UpdateDisplay();
}
}
if (Procedure.hasAttribute("Random")) {
String stRand = Procedure.getAttribute("Random");
Boolean Rand = false;
if (stRand.equals("true")) {
Rand = true;
}
STAppData.BugArray.get(i).setRandom(Rand);
if (hasGUI) {
STAppFrame.BugViewArray.get(i).setRandom(Rand);
}
}
if (Procedure.hasAttribute("Limit")) {
int limit = Integer.parseInt(Procedure.getAttribute("Limit"));
STAppData.BugArray.get(i).setLimit(limit);
if (hasGUI) {
STAppFrame.BugViewArray.get(i).setLimit(limit);
}
}
} else {
STAppData.AddNewBug();
int last_added_bug_index = STAppData.BugArray.size() - 1;
Procedure newbug = STAppData.BugArray.get(last_added_bug_index);
if (hasGUI) {
STAppFrame.AddNewBugView();
ProcedureView newbugview = STAppFrame.BugViewArray.get(last_added_bug_index);
mainAppController.AddNewHandlers(STAppFrame, STAppData, newbugview, newbug);
STAppFrame.UpdateDisplay();
}
}
String BugTitle = "";
if (Procedure.hasAttribute("Title")) {
BugTitle = Procedure.getAttribute("Title");
}
STAppData.BugArray.get(i).setBugTitle(BugTitle);
if (hasGUI) {
STAppFrame.BugViewArray.get(i).setBugTitle(BugTitle);
}
String BugURL = "";
if (Procedure.hasAttribute("URL")) {
BugURL = Procedure.getAttribute("URL");
}
STAppData.BugArray.get(i).setBugURL(BugURL);
// needed?
// String stPass = Procedure.getAttribute("Pass");
// Boolean Pass = false;
// if (stPass.equals("true"))
// {
// Pass = true;
// }
// STAppData.BugArray.get(i).setPass(Pass);
NodeList ActionsList = Procedure.getElementsByTagName("Action");
for (int j = 0; j < ActionsList.getLength(); j++) {
Element Action = (Element) ActionsList.item(j);
NodeList ActionNodes = Action.getChildNodes();
String thisActionNodeName = "none";
String thisActionNodeValue = "none";
String Variable1 = "";
String Variable2 = "";
String LOCKED = "false";
String BoolVal1 = "false";
String BoolVal2 = "false";
String TimeOfTest;
String ActionType = "none";
String ActionIndex;
String ActionPass;
String Password = "";
Boolean RealBoolVal1 = false;
Boolean RealBoolVal2 = false;
Boolean boolLOCKED = false;
for (int k = 0; k < ActionNodes.getLength(); k++) {
thisActionNodeName = ActionNodes.item(k).getNodeName();
thisActionNodeValue = ActionNodes.item(k).getTextContent();
switch(thisActionNodeName) {
case "Pass":
ActionPass = thisActionNodeValue;
break;
case "ActionIndex":
ActionIndex = thisActionNodeValue;
break;
case "Type":
ActionType = thisActionNodeValue;
break;
case "Variable1":
Variable1 = thisActionNodeValue;
break;
case "Variable2":
Variable2 = thisActionNodeValue;
break;
case "BoolVal1":
BoolVal1 = thisActionNodeValue;
if (BoolVal1.equals("true")) {
RealBoolVal1 = true;
}
break;
case "BoolVal2":
BoolVal2 = thisActionNodeValue;
if (BoolVal2.equals("true")) {
RealBoolVal2 = true;
}
break;
case "LOCKED":
LOCKED = thisActionNodeValue;
if (LOCKED.equals("true")) {
boolLOCKED = true;
}
break;
case "TimeOfTest":
TimeOfTest = thisActionNodeValue;
break;
}
}
if (ActionType.contains("Password")) {
try {
Password = Protector.decrypt(Variable2);
Variable2 = Password;
} catch (Exception e) {
// System.out.println("Load/decrypt error: " + e.toString());
}
}
ActionsMaster NewActionsMaster = new ActionsMaster();
HashMap<String, Action> thisActionHashMap = NewActionsMaster.ActionHashMap;
HashMap<String, ActionView> thisActionViewHashMap = NewActionsMaster.ActionViewHashMap;
HashMap<String, Action> thisPassFailActionHashMap = NewActionsMaster.PassFailActionHashMap;
HashMap<String, ActionView> thisPassFailActionViewHashMap = NewActionsMaster.PassFailActionViewHashMap;
Procedure NewProcedure = STAppData.BugArray.get(i);
if (hasGUI) {
ProcedureView NewProcedureView = STAppFrame.BugViewArray.get(i);
if (thisActionHashMap.containsKey(ActionType)) {
Action thisActionToAdd = (Action) thisActionHashMap.get(ActionType);
ActionView thisActionViewToAdd = (ActionView) thisActionViewHashMap.get(ActionType);
thisActionToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.AddListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
thisActionViewToAdd.AddLoopListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
STAppFrame.AddActionViewToArray(thisActionViewToAdd, NewProcedureView);
STAppData.AddActionToArray(thisActionToAdd, NewProcedure, NewProcedureView);
NewProcedureView.refreshjComboBoxAddAtPosition();
}
if (thisPassFailActionHashMap.containsKey(ActionType)) {
Action thisActionToAdd = (Action) thisPassFailActionHashMap.get(ActionType);
ActionView thisActionViewToAdd = (ActionView) thisPassFailActionViewHashMap.get(ActionType);
thisActionToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.AddListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
thisActionViewToAdd.AddLoopListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
STAppFrame.AddActionViewToArray(thisActionViewToAdd, NewProcedureView);
STAppData.AddActionToArray(thisActionToAdd, NewProcedure, NewProcedureView);
NewProcedureView.refreshjComboBoxAddAtPosition();
}
} else {
if (thisActionHashMap.containsKey(ActionType)) {
Action thisActionToAdd = (Action) thisActionHashMap.get(ActionType);
ActionView thisActionViewToAdd = (ActionView) thisActionViewHashMap.get(ActionType);
thisActionToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
// thisActionViewToAdd.AddListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
// thisActionViewToAdd.AddLoopListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
// STAppFrame.AddActionViewToArray (thisActionViewToAdd, NewProcedureView);
STAppData.AddActionToArray(thisActionToAdd, NewProcedure);
}
if (thisPassFailActionHashMap.containsKey(ActionType)) {
Action thisActionToAdd = (Action) thisPassFailActionHashMap.get(ActionType);
ActionView thisActionViewToAdd = (ActionView) thisPassFailActionViewHashMap.get(ActionType);
thisActionToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
thisActionViewToAdd.SetVars(Variable1, Variable2, Password, RealBoolVal1, RealBoolVal2, boolLOCKED);
// thisActionViewToAdd.AddListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
// thisActionViewToAdd.AddLoopListeners(thisActionToAdd, STAppFrame, STAppData, NewProcedure, NewProcedureView);
// STAppFrame.AddActionViewToArray (thisActionViewToAdd, NewProcedureView);
STAppData.AddActionToArray(thisActionToAdd, NewProcedure);
}
}
}
}
if (hasDataloop) {
if (hasGUI) {
STAppFrame.setJButtonFlattenFileEnabled(true);
}
}
} catch (Exception e) {
System.out.println("Exception parsing procedure node" + e.toString());
e.printStackTrace();
}
if (hasGUI) {
STAppFrame.addTargetBrowserItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if ((e.getStateChange() == ItemEvent.SELECTED)) {
Object ActionType = e.getItem();
String TargetBrowser = ActionType.toString();
STAppFrame.setTargetBrowserView(TargetBrowser);
STAppData.setTargetBrowser(TargetBrowser);
STAppData.changes = true;
}
}
});
STAppFrame.addjButtonBrowseForFireFoxExeActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String TargetBrowser = STAppData.getTargetBrowser();
FireFoxProperties FFProperties = new FireFoxProperties(TargetBrowser);
FFProperties.BrowseforFFPath();
}
});
STAppFrame.addjButtonDoStuffActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
mainAppController.RunActions(STAppFrame, STAppData);
}
});
STAppFrame.addjButtonFlattenFileActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
mainAppController.ThreadSaveFile(mainAppFrame, STAppFrame, STAppData, true, true);
}
});
STAppFrame.addjButtonClearEmailSettingsListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
STAppFrame.ClearEmailSettings();
}
});
STAppFrame.addjButtonLoadEmailSettingsListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
STAppData.loadGlobalEmailSettings();
STAppFrame.setEmailSettings(STAppData);
} catch (Exception ex) {
System.out.println("Exception loading global email settings: " + ex.toString());
}
}
});
STAppFrame.addjButtonGutsViewActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
mainAppController.showGuts(STAppFrame, STAppData);
}
});
STAppFrame.addjButtonNewBugActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
STAppFrame.saveState();
int insertionPoint = STAppFrame.getInsertionPoint();
STAppData.AddNewBug(insertionPoint);
STAppFrame.AddNewBugView(insertionPoint);
int last_added_bug_index = insertionPoint - 1;
ProcedureView newbugview = STAppFrame.BugViewArray.get(last_added_bug_index);
Procedure newbug = STAppData.BugArray.get(last_added_bug_index);
mainAppController.AddNewHandlers(STAppFrame, STAppData, newbugview, newbug);
STAppFrame.UpdateDisplay();
JComponent component = (JComponent) STAppFrame.MainScrollPane.getViewport().getView();
Rectangle bounds = STAppFrame.BugViewArray.get(last_added_bug_index).JPanelBug.getBounds();
component.scrollRectToVisible(bounds);
}
});
STAppFrame.addjButtonNewDataLoopActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
STAppFrame.saveState();
int insertionPoint = STAppFrame.getInsertionPoint();
STAppData.AddNewDataLoop(insertionPoint);
STAppFrame.AddNewDataLoopView(insertionPoint);
int last_added_bug_index = insertionPoint - 1;
ProcedureView newbugview = STAppFrame.BugViewArray.get(last_added_bug_index);
Procedure newbug = STAppData.BugArray.get(last_added_bug_index);
mainAppController.AddNewHandlers(STAppFrame, STAppData, newbugview, newbug);
STAppFrame.UpdateDisplay();
JComponent component = (JComponent) STAppFrame.MainScrollPane.getViewport().getView();
Rectangle bounds = STAppFrame.BugViewArray.get(last_added_bug_index).JPanelBug.getBounds();
component.scrollRectToVisible(bounds);
}
});
for (ProcedureView PV : STAppFrame.BugViewArray) {
int avlockcount = 0;
for (ActionView AV : PV.ActionsViewList) {
if (AV.Locked) {
avlockcount++;
}
}
if (avlockcount == PV.ActionsViewList.size()) {
PV.setLocked(true);
}
}
STAppFrame.initializeDisplay();
}
}
use of javax.swing.event.InternalFrameEvent in project opt4j by felixreimann.
the class Viewport method createInternalFrame.
/**
* Creates a widget as a {@link JInternalFrame}.
*
* @param widget
* the widget
* @return the constructed JInternalFrame
*/
protected JInternalFrame createInternalFrame(final Widget widget) {
final JPanel panel = widget.getPanel();
final String frameTitle;
final Icon frameIcon;
boolean resizable = true;
boolean closable = true;
boolean maximizable = true;
boolean iconifiable = true;
WidgetParameters parameters = widget.getClass().getAnnotation(WidgetParameters.class);
if (parameters != null) {
frameTitle = parameters.title();
if (!parameters.icon().equals("")) {
frameIcon = Icons.getIcon(parameters.icon());
} else {
frameIcon = null;
}
resizable = parameters.resizable();
closable = parameters.closable();
maximizable = parameters.maximizable();
iconifiable = parameters.iconifiable();
} else {
frameTitle = null;
frameIcon = null;
}
final JInternalFrame inFrame = new JInternalFrame(frameTitle, resizable, closable, maximizable, iconifiable);
widget.init(this);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
inFrame.addInternalFrameListener(new InternalFrameAdapter() {
@Override
public void internalFrameClosed(InternalFrameEvent arg0) {
widgets.remove(widget);
}
});
inFrame.setFrameIcon(frameIcon);
inFrame.getContentPane().setLayout(new BorderLayout());
inFrame.getContentPane().add(panel, BorderLayout.CENTER);
int windows = desktop.getAllFrames().length;
windows = windows % 6;
inFrame.setLocation(OFFSET * windows, OFFSET * windows);
}
});
widgets.put(widget, inFrame);
return inFrame;
}
Aggregations