-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement kw to retrieve all open internal jframes, with test cases
- Loading branch information
Showing
8 changed files
with
130 additions
and
69 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/robotframework/swing/container/ContainerIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.robotframework.swing.container; | ||
|
||
import java.awt.*; | ||
import java.util.ArrayList; | ||
|
||
public abstract class ContainerIterator { | ||
private int level; | ||
private Container container; | ||
protected java.util.List<String> resultComponentList; | ||
|
||
public ContainerIterator(Container container) { | ||
this.container = container; | ||
resultComponentList = new ArrayList<String>(); | ||
} | ||
|
||
public java.util.List<String> iterate() { | ||
processComponent(container); | ||
return resultComponentList; | ||
} | ||
|
||
public abstract void operateOnComponent(Component component, int level); | ||
|
||
private void processComponent(Component component) { | ||
operateOnComponent(component, level); | ||
level++; | ||
if (component instanceof Container) { | ||
Component[] subComponents = ((Container) component).getComponents(); | ||
for (int i = 0; i < subComponents.length; i++) { | ||
processComponent(subComponents[i]); | ||
level--; | ||
} | ||
} | ||
} | ||
|
||
protected String componentToString(Component component) { | ||
String componentString = component.toString(); | ||
int indexToStartOfDetails = componentString.indexOf('['); | ||
if (indexToStartOfDetails == -1) | ||
return componentString; | ||
return componentString.substring(0, indexToStartOfDetails); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/robotframework/swing/container/ContainerIteratorForListing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.robotframework.swing.container; | ||
|
||
import org.robotframework.swing.keyword.development.ComponentOccurences; | ||
|
||
import java.awt.*; | ||
|
||
public class ContainerIteratorForListing extends ContainerIterator { | ||
|
||
private ComponentOccurences occurences = new ComponentOccurences(); | ||
public ContainerIteratorForListing(Container container) { | ||
super(container); | ||
} | ||
|
||
private void printSpacesToFormatOutputAsTree(int level) { | ||
for (int i = 0; i < level; i++) | ||
System.out.print(" "); | ||
} | ||
|
||
public void operateOnComponent(Component component, int level) { | ||
printSpacesToFormatOutputAsTree(level); | ||
String componentName = componentToString(component); | ||
System.out.println(level + " " + componentName + " " + occurences.countIndexOf(component) + ": " + component.getName()); | ||
resultComponentList.add(componentName); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/robotframework/swing/internalframe/InternalFrameIteratorForListing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.robotframework.swing.internalframe; | ||
|
||
import org.robotframework.swing.container.ContainerIterator; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
public class InternalFrameIteratorForListing extends ContainerIterator{ | ||
public InternalFrameIteratorForListing(Container container) { | ||
super(container); | ||
} | ||
|
||
@Override | ||
public void operateOnComponent(Component component, int level) { | ||
if (JInternalFrame.class.isAssignableFrom(component.getClass())) { | ||
if(component.isVisible()) { | ||
resultComponentList.add(componentToString(component)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected String componentToString(Component component) { | ||
String title = ((JInternalFrame)component).getTitle(); | ||
if (title.isEmpty()) { | ||
return super.componentToString(component); | ||
} | ||
return title; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/robotframework/swing/util/ComponentExistenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters