use of javax.swing.text.JTextComponent in project zaproxy by zaproxy.
the class PopupFlagCustomPageIndicatorMenu method isEnableForComponent.
@Override
public boolean isEnableForComponent(Component invoker) {
if (invoker instanceof JTextComponent) {
// Is it the HttpPanelResponse?
JTextComponent txtComponent = (JTextComponent) invoker;
boolean responsePanel = (SwingUtilities.getAncestorOfClass(HttpPanelResponse.class, txtComponent) != null);
if (!responsePanel) {
selectedText = null;
return false;
}
// Is anything selected?
selectedText = txtComponent.getSelectedText();
this.setEnabled(selectedText != null && selectedText.length() != 0);
return true;
} else {
selectedText = null;
return false;
}
}
use of javax.swing.text.JTextComponent in project zaproxy by zaproxy.
the class PopupFlagLoggedInIndicatorMenu method isEnableForComponent.
@Override
public boolean isEnableForComponent(Component invoker) {
if (invoker instanceof JTextComponent) {
// Is it the HttpPanelResponse?
JTextComponent txtComponent = (JTextComponent) invoker;
boolean responsePanel = (SwingUtilities.getAncestorOfClass(HttpPanelResponse.class, txtComponent) != null);
if (!responsePanel) {
selectedText = null;
return false;
}
// Is anything selected?
selectedText = txtComponent.getSelectedText();
if (selectedText == null || selectedText.length() == 0) {
this.setEnabled(false);
} else {
this.setEnabled(true);
}
return true;
} else {
selectedText = null;
return false;
}
}
use of javax.swing.text.JTextComponent in project ats-framework by Axway.
the class SwingElementLocator method buildLocator.
private static <T extends Component> GenericTypeMatcher<T> buildLocator(Class<T> componentClass, final UiElementProperties properties, boolean requireVisible, final String[] propertyNamesToUseForMatch) {
// nested class not to be anonymous in stack traces
class MyGenericTypeMatcher<Type1 extends Component> extends GenericTypeMatcher<Type1> {
private int currentIndex = 0;
public MyGenericTypeMatcher(Class<Type1> componentClass, boolean requireVisible) {
super(componentClass, requireVisible);
}
/**
* In addition to the type check in constructor adds check by other component properties
* @param component
* @return
*/
@Override
protected boolean isMatching(Component component) {
// here we are sure that we do not search by label and
// also property "visible" and class are tracked additionally by FEST
// Having several properties means match ALL of them
int propertiesMatching = 0;
int currentPropIdxToProcess = 0;
for (currentPropIdxToProcess = 0; currentPropIdxToProcess < propertyNamesToUseForMatch.length; currentPropIdxToProcess++) {
String keyName = propertyNamesToUseForMatch[currentPropIdxToProcess];
if ("visible".equals(keyName) || "class".equals(keyName)) {
// already considered as parameter in search
propertiesMatching++;
continue;
}
String propertyValue = properties.getProperty(keyName);
if (propertyValue != null) {
if ("name".equals(keyName)) {
if (propertyValue.equals(component.getName())) {
propertiesMatching++;
log.debug("Found element with 'name' property: " + component);
continue;
} else {
return false;
}
} else if ("text".equals(keyName)) {
// Search by specific component properties
if (component instanceof JButton) {
JButton button = (JButton) component;
if (propertyValue.equals(button.getText())) {
propertiesMatching++;
log.debug("Found element by 'text' property: " + button);
continue;
} else {
return false;
}
} else if (component instanceof JMenuItem) {
JMenuItem menuItem = (JMenuItem) component;
if (propertyValue.equals(menuItem.getText())) {
log.debug("Found element by 'text' property: " + menuItem);
propertiesMatching++;
continue;
} else {
return false;
}
} else if (component instanceof JPopupMenu) {
JPopupMenu popupMenu = (JPopupMenu) component;
if (propertyValue.equals(popupMenu.getLabel())) {
log.debug("Found element by 'text' property: " + popupMenu);
propertiesMatching++;
continue;
} else {
return false;
}
} else if (component instanceof JToggleButton) {
JToggleButton toggleButton = (JToggleButton) component;
if (propertyValue.equals(toggleButton.getText())) {
log.debug("Found element by 'text' property: " + toggleButton);
propertiesMatching++;
continue;
} else {
return false;
}
} else if (component instanceof JTextComponent) {
JTextComponent textComponent = (JTextComponent) component;
if (propertyValue.equals(textComponent.getText())) {
log.debug("Found element by 'text' property: " + textComponent);
propertiesMatching++;
continue;
} else {
return false;
}
} else if (component instanceof JLabel) {
JLabel label = (JLabel) component;
if (propertyValue.equals(label.getText())) {
log.debug("Found element by 'text' property: " + label);
propertiesMatching++;
continue;
}
}
// Attempt to search for 'text' for unsupported component type
return false;
} else if ("tooltip".equals(keyName)) {
// Search by specific component properties
if (component instanceof JButton) {
JButton button = (JButton) component;
if (propertyValue.equals(button.getToolTipText())) {
propertiesMatching++;
log.debug("Found element by 'tooltip' property: " + button);
continue;
} else {
return false;
}
}
} else if ("index".equals(keyName)) {
if (Integer.parseInt(propertyValue) == currentIndex++) {
propertiesMatching++;
continue;
}
} else {
throw new IllegalStateException("Attempt to search for not supported property: " + keyName + ", component: " + component);
}
}
// if property != null
}
if (propertyNamesToUseForMatch.length == propertiesMatching) {
return true;
} else {
if (propertiesMatching > 0 && log.isDebugEnabled()) {
log.debug("Not all properties matched. Only " + propertiesMatching + " instead of " + properties.getPropertiesSize());
}
return false;
}
}
}
return new MyGenericTypeMatcher<T>(componentClass, requireVisible);
}
use of javax.swing.text.JTextComponent in project ats-framework by Axway.
the class SwingElementLocator method findFixture.
public static ComponentFixture<? extends Component> findFixture(UiElement uiElement) {
SwingDriverInternal driver = (SwingDriverInternal) uiElement.getUiDriver();
ContainerFixture<?> containerFixture = (ContainerFixture<?>) driver.getActiveContainerFixture();
Class<? extends Component> componentClass = componentsMap.get(uiElement.getClass());
try {
if (componentClass.equals(JButton.class)) {
return (ComponentFixture<? extends Component>) new JButtonFixture(containerFixture.robot, (JButton) findElement(uiElement));
} else if (componentClass.equals(JTextComponent.class)) {
return (ComponentFixture<? extends Component>) new JTextComponentFixture(containerFixture.robot, (JTextComponent) findElement(uiElement));
} else if (componentClass.equals(JMenuItem.class)) {
if (uiElement.getElementProperty("path") != null) {
return containerFixture.menuItemWithPath(uiElement.getElementProperty("path").split("[\\,\\/]+"));
} else {
return (ComponentFixture<? extends Component>) new JMenuItemFixture(containerFixture.robot, (JMenuItem) findElement(uiElement));
}
} else if (componentClass.equals(JPopupMenu.class)) {
return (ComponentFixture<? extends Component>) new JPopupMenuFixture(containerFixture.robot, (JPopupMenu) findElement(uiElement));
} else if (componentClass.equals(JTree.class)) {
return (ComponentFixture<? extends Component>) new JTreeFixture(containerFixture.robot, (JTree) findElement(uiElement));
} else if (componentClass.equals(JList.class)) {
return (ComponentFixture<? extends Component>) new JListFixture(containerFixture.robot, (JList) findElement(uiElement));
} else if (componentClass.equals(JCheckBox.class)) {
return (ComponentFixture<? extends Component>) new JCheckBoxFixture(containerFixture.robot, (JCheckBox) findElement(uiElement));
} else if (componentClass.equals(JToggleButton.class)) {
return (ComponentFixture<? extends Component>) new JToggleButtonFixture(containerFixture.robot, (JToggleButton) findElement(uiElement));
} else if (componentClass.equals(JComboBox.class)) {
return (ComponentFixture<? extends Component>) new JComboBoxFixture(containerFixture.robot, (JComboBox) findElement(uiElement));
} else if (componentClass.equals(JRadioButton.class)) {
return (ComponentFixture<? extends Component>) new JRadioButtonFixture(containerFixture.robot, (JRadioButton) findElement(uiElement));
} else if (componentClass.equals(JTable.class)) {
return (ComponentFixture<? extends Component>) new JTableFixture(containerFixture.robot, (JTable) findElement(uiElement));
} else if (componentClass.equals(JSpinner.class)) {
return (ComponentFixture<? extends Component>) new JSpinnerFixture(containerFixture.robot, (JSpinner) findElement(uiElement));
} else if (componentClass.equals(JTabbedPane.class)) {
return (ComponentFixture<? extends Component>) new JTabbedPaneFixture(containerFixture.robot, (JTabbedPane) findElement(uiElement));
} else if (componentClass.equals(JOptionPane.class)) {
return (ComponentFixture<? extends Component>) containerFixture.optionPane();
} else if (componentClass.equals(JLabel.class)) {
return (ComponentFixture<? extends Component>) new JLabelFixture(containerFixture.robot, (JLabel) findElement(uiElement));
} else if (componentClass.equals(Component.class)) {
return new ComponentFixture<Component>(containerFixture.robot, findElement(uiElement)) {
};
} else if (componentClass.equals(JFileChooser.class)) {
// TODO - might be searched by name too
return containerFixture.fileChooser(Timeout.timeout(UiEngineConfigurator.getInstance().getElementStateChangeDelay()));
} else {
throw new ElementNotFoundException(uiElement.toString() + " not found. No such Fixture");
}
} catch (ComponentLookupException cle) {
throw new ElementNotFoundException(uiElement.toString() + " not found.", cle);
} catch (WaitTimedOutError exc) {
// thrown for OptionPane search, wait for Window (BasicRobot.waitForWindow), AbstractJTableCellWriter, JTreeDriver.waitForChildrenToShowUp, each Pause wait
throw new ElementNotFoundException(uiElement.toString() + " not found.", exc);
}
}
use of javax.swing.text.JTextComponent in project SKMCLauncher by SKCraft.
the class TextFieldPopupMenu method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JTextComponent textComponent = (JTextComponent) getInvoker();
textComponent.requestFocus();
boolean haveSelection = textComponent.getSelectionStart() != textComponent.getSelectionEnd();
if (e.getSource() == cutItem) {
if (!haveSelection)
textComponent.selectAll();
textComponent.cut();
} else if (e.getSource() == copyItem) {
if (!haveSelection)
textComponent.selectAll();
textComponent.copy();
} else if (e.getSource() == pasteItem) {
textComponent.paste();
} else if (e.getSource() == deleteItem) {
if (!haveSelection)
textComponent.selectAll();
textComponent.replaceSelection("");
} else if (e.getSource() == selectAllItem) {
textComponent.selectAll();
}
}
Aggregations