java.awt.TextComponent Java Examples

The following examples show how to use java.awt.TextComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.selectAll()} through queue
 */
public void selectAll() {
    runMapping(new MapVoidAction("selectAll") {
        @Override
        public void map() {
            ((TextComponent) getSource()).selectAll();
        }
    });
}
 
Example #2
Source File: WToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isComponentValidForTouchKeyboard(Component comp) {
    if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
        (((comp instanceof TextComponent) &&
                ((TextComponent) comp).isEditable()) ||
            ((comp instanceof JTextComponent) &&
                ((JTextComponent) comp).isEditable()))) {
        return true;
    }
    return false;
}
 
Example #3
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.getCaretPosition()} through queue
 */
public int getCaretPosition() {
    return (runMapping(new MapIntegerAction("getCaretPosition") {
        @Override
        public int map() {
            return ((TextComponent) getSource()).getCaretPosition();
        }
    }));
}
 
Example #4
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.getSelectedText()} through queue
 */
public String getSelectedText() {
    return (runMapping(new MapAction<String>("getSelectedText") {
        @Override
        public String map() {
            return ((TextComponent) getSource()).getSelectedText();
        }
    }));
}
 
Example #5
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.getSelectionEnd()} through queue
 */
public int getSelectionEnd() {
    return (runMapping(new MapIntegerAction("getSelectionEnd") {
        @Override
        public int map() {
            return ((TextComponent) getSource()).getSelectionEnd();
        }
    }));
}
 
Example #6
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.getSelectionStart()} through queue
 */
public int getSelectionStart() {
    return (runMapping(new MapIntegerAction("getSelectionStart") {
        @Override
        public int map() {
            return ((TextComponent) getSource()).getSelectionStart();
        }
    }));
}
 
Example #7
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.getText()} through queue
 */
public String getText() {
    return (runMapping(new MapAction<String>("getText") {
        @Override
        public String map() {
            return ((TextComponent) getSource()).getText();
        }
    }));
}
 
Example #8
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.isEditable()} through queue
 */
public boolean isEditable() {
    return (runMapping(new MapBooleanAction("isEditable") {
        @Override
        public boolean map() {
            return ((TextComponent) getSource()).isEditable();
        }
    }));
}
 
Example #9
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.removeTextListener(TextListener)} through queue
 */
public void removeTextListener(final TextListener textListener) {
    runMapping(new MapVoidAction("removeTextListener") {
        @Override
        public void map() {
            ((TextComponent) getSource()).removeTextListener(textListener);
        }
    });
}
 
Example #10
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.select(int, int)} through queue
 */
public void select(final int i, final int i1) {
    runMapping(new MapVoidAction("select") {
        @Override
        public void map() {
            ((TextComponent) getSource()).select(i, i1);
        }
    });
}
 
Example #11
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.addTextListener(TextListener)} through queue
 */
public void addTextListener(final TextListener textListener) {
    runMapping(new MapVoidAction("addTextListener") {
        @Override
        public void map() {
            ((TextComponent) getSource()).addTextListener(textListener);
        }
    });
}
 
Example #12
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.setCaretPosition(int)} through queue
 */
public void setCaretPosition(final int i) {
    runMapping(new MapVoidAction("setCaretPosition") {
        @Override
        public void map() {
            ((TextComponent) getSource()).setCaretPosition(i);
        }
    });
}
 
Example #13
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.setEditable(boolean)} through queue
 */
public void setEditable(final boolean b) {
    runMapping(new MapVoidAction("setEditable") {
        @Override
        public void map() {
            ((TextComponent) getSource()).setEditable(b);
        }
    });
}
 
Example #14
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.setSelectionEnd(int)} through queue
 */
public void setSelectionEnd(final int i) {
    runMapping(new MapVoidAction("setSelectionEnd") {
        @Override
        public void map() {
            ((TextComponent) getSource()).setSelectionEnd(i);
        }
    });
}
 
Example #15
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.setSelectionStart(int)} through queue
 */
public void setSelectionStart(final int i) {
    runMapping(new MapVoidAction("setSelectionStart") {
        @Override
        public void map() {
            ((TextComponent) getSource()).setSelectionStart(i);
        }
    });
}
 
Example #16
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code TextComponent.setText(String)} through queue
 */
public void setText(final String string) {
    runMapping(new MapVoidAction("setText") {
        @Override
        public void map() {
            ((TextComponent) getSource()).setText(string);
        }
    });
}
 
Example #17
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean checkComponent(Component comp) {
    if (comp instanceof TextComponent) {
        if (((TextComponent) comp).getText() != null) {
            return (comparator.equals(((TextComponent) comp).getText(),
                    label));
        }
    }
    return false;
}
 
Example #18
Source File: WToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isComponentValidForTouchKeyboard(Component comp) {
    if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
        (((comp instanceof TextComponent) &&
                ((TextComponent) comp).isEditable()) ||
            ((comp instanceof JTextComponent) &&
                ((JTextComponent) comp).isEditable()))) {
        return true;
    }
    return false;
}
 
Example #19
Source File: WToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if (!(comp instanceof TextComponent) &&
        !(comp instanceof JTextComponent)) {
        return;
    }

    if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
        MouseEvent me = (MouseEvent) e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = new WeakReference<>(comp);
            } else {
                compOnMousePressedEvent = new WeakReference<>(comp);
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent.get() == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = NULL_COMPONENT_WR;
            } else {
                if (compOnMousePressedEvent.get() == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = NULL_COMPONENT_WR;
            }
        }
    } else if (e instanceof FocusEvent) {
        FocusEvent fe = (FocusEvent) e;
        if (fe.getID() == FocusEvent.FOCUS_LOST) {
            // Hide the touch keyboard, if not a text component gains focus.
            if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
                hideTouchKeyboard();
            }
        }
    }
}
 
Example #20
Source File: Awt.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public static void setCursor(Container container, int cursor) {
   Component[] cmps = container.getComponents();
   container.setCursor(Cursor.getPredefinedCursor(cursor));
   for(int i = 0; i < cmps.length; i++) {
     if(cmps[i] instanceof Container)
setCursor((Container)cmps[i], cursor);
     else if (cmps[i] instanceof TextComponent && 
       cursor == Cursor.DEFAULT_CURSOR)
cmps[i].setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
     else
cmps[i].setCursor(Cursor.getPredefinedCursor(cursor));
   }
 }
 
Example #21
Source File: WToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if (!(comp instanceof TextComponent) &&
        !(comp instanceof JTextComponent)) {
        return;
    }

    if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
        MouseEvent me = (MouseEvent) e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = new WeakReference<>(comp);
            } else {
                compOnMousePressedEvent = new WeakReference<>(comp);
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent.get() == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = NULL_COMPONENT_WR;
            } else {
                if (compOnMousePressedEvent.get() == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = NULL_COMPONENT_WR;
            }
        }
    } else if (e instanceof FocusEvent) {
        FocusEvent fe = (FocusEvent) e;
        if (fe.getID() == FocusEvent.FOCUS_LOST) {
            // Hide the touch keyboard, if not a text component gains focus.
            if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
                hideTouchKeyboard();
            }
        }
    }
}
 
Example #22
Source File: WToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isComponentValidForTouchKeyboard(Component comp) {
    if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
        (((comp instanceof TextComponent) &&
                ((TextComponent) comp).isEditable()) ||
            ((comp instanceof JTextComponent) &&
                ((JTextComponent) comp).isEditable()))) {
        return true;
    }
    return false;
}
 
Example #23
Source File: WToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if (!(comp instanceof TextComponent) &&
        !(comp instanceof JTextComponent)) {
        return;
    }

    if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
        MouseEvent me = (MouseEvent) e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = new WeakReference<>(comp);
            } else {
                compOnMousePressedEvent = new WeakReference<>(comp);
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent.get() == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = NULL_COMPONENT_WR;
            } else {
                if (compOnMousePressedEvent.get() == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = NULL_COMPONENT_WR;
            }
        }
    } else if (e instanceof FocusEvent) {
        FocusEvent fe = (FocusEvent) e;
        if (fe.getID() == FocusEvent.FOCUS_LOST) {
            // Hide the touch keyboard, if not a text component gains focus.
            if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
                hideTouchKeyboard();
            }
        }
    }
}
 
Example #24
Source File: WToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean isComponentValidForTouchKeyboard(Component comp) {
    if ((comp != null) && comp.isEnabled() && comp.isFocusable() &&
        (((comp instanceof TextComponent) &&
                ((TextComponent) comp).isEditable()) ||
            ((comp instanceof JTextComponent) &&
                ((JTextComponent) comp).isEditable()))) {
        return true;
    }
    return false;
}
 
Example #25
Source File: WToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if (!(comp instanceof TextComponent) &&
        !(comp instanceof JTextComponent)) {
        return;
    }

    if ((e instanceof MouseEvent) && isComponentValidForTouchKeyboard(comp)) {
        MouseEvent me = (MouseEvent) e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = new WeakReference<>(comp);
            } else {
                compOnMousePressedEvent = new WeakReference<>(comp);
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor().isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent.get() == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = NULL_COMPONENT_WR;
            } else {
                if (compOnMousePressedEvent.get() == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = NULL_COMPONENT_WR;
            }
        }
    } else if (e instanceof FocusEvent) {
        FocusEvent fe = (FocusEvent) e;
        if (fe.getID() == FocusEvent.FOCUS_LOST) {
            // Hide the touch keyboard, if not a text component gains focus.
            if (!isComponentValidForTouchKeyboard(fe.getOppositeComponent())) {
                hideTouchKeyboard();
            }
        }
    }
}
 
Example #26
Source File: AbstractJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void _clear() {
    verifyCanInteractWithElement();
    final Component active = Device.getActiveComponent(component);
    if (active instanceof JTextComponent) {
        ((JTextComponent) active).setText("");
    } else if (active instanceof TextComponent) {
        ((TextComponent) active).setText("");
    } else {
        throw new UnsupportedCommandException("Clear not supported on " + active.getClass().getName(), null);
    }
}
 
Example #27
Source File: Downsampler.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Displays a dialog to harvest user input, allowing scaling from a
 * specified image width and height.
 * 
 * @param imgWidth Base image width
 * @param imgHeight Base image height
 */
public void getInput(int imgWidth, int imgHeight) {
	originalWidth = imgWidth;
	originalHeight = imgHeight;
	final GenericDialogPlus gdDownSample = new GenericDialogPlus("Downsample");
	String[] methods = ImageProcessor.getInterpolationMethods();

	gdDownSample.addNumericField("x scale", 1, 1);
	gdDownSample.addNumericField("y scale", 1, 1);
	gdDownSample.addNumericField("width (pixels)", imgWidth, 0);
	gdDownSample.addNumericField("height (pixels)", imgHeight, 0);
	gdDownSample.addChoice("Interpolation:", methods,
		methods[methods.length - 1]);
	gdDownSample.addCheckbox("Average when downsizing", true);
	Vector<?> fields = gdDownSample.getNumericFields();
	xField = (TextComponent) fields.get(0);
	yField = (TextComponent) fields.get(1);
	widthField = (TextComponent) fields.get(2);
	heightField = (TextComponent) fields.get(3);

	xField.addTextListener(textListener);
	xField.addFocusListener(focusListener);
	yField.addTextListener(textListener);
	yField.addFocusListener(focusListener);
	widthField.addTextListener(textListener);
	widthField.addFocusListener(focusListener);
	heightField.addTextListener(textListener);
	heightField.addFocusListener(focusListener);
	gdDownSample.showDialog();

	if (gdDownSample.wasOKed()) {
		xScale = gdDownSample.getNextNumber();
		yScale = gdDownSample.getNextNumber();
		double width = gdDownSample.getNextNumber();
		double height = gdDownSample.getNextNumber();
		String method = gdDownSample.getNextChoice();
		String average = gdDownSample.getNextBoolean() ? " average" : "";
		params =
			"width=" + width + " height=" +
				height + average + " interpolation=" + method;
	}
}
 
Example #28
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs TextComponentFinder.
 */
public TextComponentFinder() {
    super(TextComponent.class);
}
 
Example #29
Source File: WToolkit.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void showOrHideTouchKeyboard(Component comp, AWTEvent e) {
    if ((comp == null) || (e == null) ||
        (!(comp instanceof TextComponent) &&
            !(comp instanceof JTextComponent))) {
        return;
    }

    if ((e instanceof MouseEvent) && comp.isEnabled() &&
        (((comp instanceof TextComponent) &&
                ((TextComponent)comp).isEditable()) ||
            ((comp instanceof JTextComponent) &&
                ((JTextComponent)comp).isEditable()))) {
        MouseEvent me = (MouseEvent)e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
            if (AWTAccessor.getMouseEventAccessor()
                    .isCausedByTouchEvent(me)) {
                compOnTouchDownEvent = comp;
            } else {
                compOnMousePressedEvent = comp;
            }
        } else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
            if (AWTAccessor.getMouseEventAccessor()
                    .isCausedByTouchEvent(me)) {
                if (compOnTouchDownEvent == comp) {
                    showTouchKeyboard(true);
                }
                compOnTouchDownEvent = null;
            } else {
                if (compOnMousePressedEvent == comp) {
                    showTouchKeyboard(false);
                }
                compOnMousePressedEvent = null;
            }
        }
    } else if (e instanceof FocusEvent) {
        if (e.getID() == FocusEvent.FOCUS_LOST) {
            hideTouchKeyboard();
        }
    }
}
 
Example #30
Source File: TextComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    result.put(TEXT_DPROP, ((TextComponent) getSource()).getText());
    return result;
}