use of javax.swing.text.JTextComponent in project intellij-plugins by JetBrains.
the class DartSdkUtil method initDartSdkAndDartiumControls.
public static void initDartSdkAndDartiumControls(@Nullable final Project project, @NotNull final ComboboxWithBrowseButton dartSdkPathComponent, @NotNull final JBLabel versionLabel, @NotNull final ComboboxWithBrowseButton dartiumPathComponent, @NotNull final Computable<ChromeSettings> currentDartiumSettingsRetriever, @NotNull final JButton dartiumSettingsButton, @NotNull final Computable<Boolean> isResettingControlsComputable) {
dartSdkPathComponent.getComboBox().setEditable(true);
addKnownPathsToCombo(dartSdkPathComponent.getComboBox(), DART_SDK_KNOWN_PATHS, DartSdkUtil::isDartSdkHome);
if (SystemInfo.isMac && getItemFromCombo(dartSdkPathComponent.getComboBox()).isEmpty()) {
// no need to check folder presence here; even if it doesn't exist - that's the best we can suggest
dartSdkPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/libexec");
}
dartiumPathComponent.getComboBox().setEditable(true);
addKnownPathsToCombo(dartiumPathComponent.getComboBox(), DARTIUM_KNOWN_PATHS, path -> !path.isEmpty() && new File(path).exists());
if (SystemInfo.isMac && getItemFromCombo(dartiumPathComponent.getComboBox()).isEmpty()) {
// Dartium path is optional, so set it only if valid
if (new File("/usr/local/opt/dart/Chromium.app").isDirectory()) {
dartiumPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/Chromium.app");
}
}
final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
final TextComponentAccessor<JComboBox> textComponentAccessor = new TextComponentAccessor<JComboBox>() {
@Override
public String getText(final JComboBox component) {
return getItemFromCombo(component);
}
@Override
public void setText(@NotNull final JComboBox component, @NotNull final String text) {
if (!text.isEmpty() && !isDartSdkHome(text)) {
final String probablySdkPath = text + "/dart-sdk";
if (isDartSdkHome(probablySdkPath)) {
component.getEditor().setItem(FileUtilRt.toSystemDependentName(probablySdkPath));
return;
}
}
component.getEditor().setItem(FileUtilRt.toSystemDependentName(text));
}
};
final ComponentWithBrowseButton.BrowseFolderActionListener<JComboBox> browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select Dart SDK path", null, dartSdkPathComponent, project, FileChooserDescriptorFactory.createSingleFolderDescriptor(), textComponentAccessor);
dartSdkPathComponent.addActionListener(browseFolderListener);
dartiumPathComponent.addBrowseFolderListener("Select Dartium browser path", null, project, FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
final JTextComponent editorComponent = (JTextComponent) dartSdkPathComponent.getComboBox().getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final DocumentEvent e) {
final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
if (!isResettingControlsComputable.compute() && isDartSdkHome(sdkHomePath)) {
final String dartiumPath = DartiumUtil.getDartiumPathForSdk(sdkHomePath);
if (dartiumPath != null) {
dartiumPathComponent.getComboBox().getEditor().setItem(FileUtilRt.toSystemDependentName(dartiumPath));
}
}
}
});
dartiumSettingsButton.addActionListener(e -> ShowSettingsUtil.getInstance().editConfigurable(dartiumSettingsButton, currentDartiumSettingsRetriever.compute().createConfigurable()));
// we decided to save one line in settings and always use Dartium in checked mode
//checkedModeCheckBox.addActionListener(new ActionListener() {
// public void actionPerformed(final ActionEvent e) {
// DartiumUtil.setCheckedMode(currentDartiumSettingsRetriever.compute().getEnvironmentVariables(), checkedModeCheckBox.isSelected());
// }
//});
}
use of javax.swing.text.JTextComponent in project android by JetBrains.
the class ResourceChooserDialogFixture method setDirectoryName.
public void setDirectoryName(@NotNull String directory) {
Container parent = robot().finder().find(target(), JLabelMatcher.withText("Directory name:")).getParent();
JTextComponent directoryField = robot().finder().findByType(parent, JTextComponent.class, true);
JTextComponentDriver driver = new JTextComponentDriver(robot());
driver.selectAll(directoryField);
driver.setText(directoryField, directory);
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class AbstractPopup method show.
public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) {
if (ApplicationManagerEx.getApplicationEx() != null && ApplicationManager.getApplication().isHeadlessEnvironment())
return;
if (isDisposed()) {
throw new IllegalStateException("Popup was already disposed. Recreate a new instance to show again");
}
assert ApplicationManager.getApplication().isDispatchThread();
assert myState == State.INIT : "Popup was already shown. Recreate a new instance to show again.";
debugState("show popup", State.INIT);
myState = State.SHOWING;
installWindowHook(this);
installProjectDisposer();
addActivity();
final Component prevOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
final boolean shouldShow = beforeShow();
if (!shouldShow) {
removeActivity();
debugState("rejected to show popup", State.SHOWING);
myState = State.INIT;
return;
}
prepareToShow();
if (myInStack) {
myFocusTrackback = new FocusTrackback(this, owner, true);
myFocusTrackback.setMustBeShown(true);
}
Dimension sizeToSet = null;
if (myDimensionServiceKey != null) {
sizeToSet = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
}
if (myForcedSize != null) {
sizeToSet = myForcedSize;
}
Rectangle screen = ScreenUtil.getScreenRectangle(aScreenX, aScreenY);
if (myLocateWithinScreen) {
Dimension size = sizeToSet != null ? sizeToSet : myContent.getPreferredSize();
if (size.width > screen.width) {
size.width = screen.width;
sizeToSet = size;
}
if (size.height > screen.height) {
size.height = screen.height;
sizeToSet = size;
}
}
if (sizeToSet != null) {
sizeToSet.width = Math.max(sizeToSet.width, myContent.getMinimumSize().width);
sizeToSet.height = Math.max(sizeToSet.height, myContent.getMinimumSize().height);
myContent.setSize(sizeToSet);
myContent.setPreferredSize(sizeToSet);
}
Point xy = new Point(aScreenX, aScreenY);
boolean adjustXY = true;
if (myUseDimServiceForXYLocation && myDimensionServiceKey != null) {
final Point storedLocation = DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject);
if (storedLocation != null) {
xy = storedLocation;
adjustXY = false;
}
}
if (adjustXY) {
final Insets insets = myContent.getInsets();
if (insets != null) {
xy.x -= insets.left;
xy.y -= insets.top;
}
}
if (considerForcedXY && myForcedLocation != null) {
xy = myForcedLocation;
}
fixLocateByContent(xy, false);
Rectangle targetBounds = new Rectangle(xy, myContent.getPreferredSize());
if (targetBounds.width > screen.width || targetBounds.height > screen.height) {
LOG.warn("huge popup requested: " + targetBounds.width + " x " + targetBounds.height);
}
Rectangle original = new Rectangle(targetBounds);
if (myLocateWithinScreen) {
ScreenUtil.moveToFit(targetBounds, screen, null);
}
if (myMouseOutCanceller != null) {
myMouseOutCanceller.myEverEntered = targetBounds.equals(original);
}
// use correct popup owner for non-modal dialogs too
myOwner = getFrameOrDialog(owner);
if (myOwner == null) {
myOwner = owner;
}
myRequestorComponent = owner;
boolean forcedDialog = myMayBeParent || SystemInfo.isMac && !(myOwner instanceof IdeFrame) && myOwner != null && myOwner.isShowing();
PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog);
myNativePopup = factory.isNativePopup();
Component popupOwner = myOwner;
if (popupOwner instanceof RootPaneContainer && !(popupOwner instanceof IdeFrame && !Registry.is("popup.fix.ide.frame.owner"))) {
// JDK uses cached heavyweight popup for a window ancestor
RootPaneContainer root = (RootPaneContainer) popupOwner;
popupOwner = root.getRootPane();
LOG.debug("popup owner fixed for JDK cache");
}
if (LOG.isDebugEnabled()) {
LOG.debug("expected preferred size: " + myContent.getPreferredSize());
}
myPopup = factory.getPopup(popupOwner, myContent, targetBounds.x, targetBounds.y, this);
if (LOG.isDebugEnabled()) {
LOG.debug(" actual preferred size: " + myContent.getPreferredSize());
}
if ((targetBounds.width != myContent.getWidth()) || (targetBounds.height != myContent.getHeight())) {
// JDK uses cached heavyweight popup that is not initialized properly
LOG.debug("the expected size is not equal to the actual size");
Window popup = myPopup.getWindow();
if (popup != null) {
popup.setSize(targetBounds.width, targetBounds.height);
if (myContent.getParent().getComponentCount() != 1) {
LOG.debug("unexpected count of components in heavy-weight popup");
}
} else {
LOG.debug("cannot fix size for non-heavy-weight popup");
}
}
if (myResizable) {
final JRootPane root = myContent.getRootPane();
final IdeGlassPaneImpl glass = new IdeGlassPaneImpl(root);
root.setGlassPane(glass);
int i = Registry.intValue("ide.popup.resizable.border.sensitivity", 4);
WindowResizeListener resizeListener = new WindowResizeListener(myContent, myMovable ? JBUI.insets(i, i, i, i) : JBUI.insets(0, 0, i, i), isToDrawMacCorner() ? AllIcons.General.MacCorner : null) {
private Cursor myCursor;
@Override
protected void setCursor(Component content, Cursor cursor) {
if (myCursor != cursor || myCursor != Cursor.getDefaultCursor()) {
glass.setCursor(cursor, this);
myCursor = cursor;
}
}
};
glass.addMousePreprocessor(resizeListener, this);
glass.addMouseMotionPreprocessor(resizeListener, this);
myResizeListener = resizeListener;
}
if (myCaption != null && myMovable) {
final WindowMoveListener moveListener = new WindowMoveListener(myCaption) {
@Override
public void mousePressed(final MouseEvent e) {
if (e.isConsumed())
return;
if (UIUtil.isCloseClick(e) && myCaption.isWithinPanel(e)) {
cancel();
} else {
super.mousePressed(e);
}
}
};
myCaption.addMouseListener(moveListener);
myCaption.addMouseMotionListener(moveListener);
final MyContentPanel saved = myContent;
Disposer.register(this, new Disposable() {
@Override
public void dispose() {
ListenerUtil.removeMouseListener(saved, moveListener);
ListenerUtil.removeMouseMotionListener(saved, moveListener);
}
});
myMoveListener = moveListener;
}
for (JBPopupListener listener : myListeners) {
listener.beforeShown(new LightweightWindowEvent(this));
}
myPopup.setRequestFocus(myRequestFocus);
myPopup.show();
WindowAction.setEnabledFor(myPopup.getWindow(), myResizable);
final Window window = getContentWindow(myContent);
myWindow = window;
myWindowListener = new MyWindowListener();
window.addWindowListener(myWindowListener);
if (myFocusable) {
window.setFocusableWindowState(true);
window.setFocusable(true);
}
if (myWindow != null) {
// we still have to be able to use IdeFrame as parent
if (!myMayBeParent && !(myWindow instanceof Frame)) {
WindowManager.getInstance().doNotSuggestAsParent(myWindow);
}
}
setMinimumSize(myMinSize);
final Runnable afterShow = () -> {
if (myPreferredFocusedComponent != null && myInStack && myFocusable) {
myFocusTrackback.registerFocusComponent(myPreferredFocusedComponent);
if (myPreferredFocusedComponent instanceof JTextComponent) {
IJSwingUtilities.moveMousePointerOn(myPreferredFocusedComponent);
}
}
removeActivity();
afterShow();
};
if (myRequestFocus) {
getPopupWindow().setFocusableWindowState(true);
getPopupWindow().setFocusable(true);
getFocusManager().requestFocus(new FocusCommand() {
@NotNull
@Override
public ActionCallback run() {
if (isDisposed()) {
removeActivity();
return ActionCallback.DONE;
}
_requestFocus();
final ActionCallback result = new ActionCallback();
final Runnable afterShowRunnable = () -> {
afterShow.run();
result.setDone();
};
if (myNativePopup) {
final FocusRequestor furtherRequestor = getFocusManager().getFurtherRequestor();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (isDisposed()) {
result.setRejected();
return;
}
furtherRequestor.requestFocus(new FocusCommand() {
@NotNull
@Override
public ActionCallback run() {
if (isDisposed()) {
return ActionCallback.REJECTED;
}
_requestFocus();
afterShowRunnable.run();
return ActionCallback.DONE;
}
}, true).notify(result).doWhenProcessed(() -> removeActivity());
});
} else {
afterShowRunnable.run();
}
return result;
}
}, true).doWhenRejected(() -> afterShow.run());
} else {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (isDisposed()) {
removeActivity();
return;
}
if (X_WINDOW_FOCUS_BUG && !myRequestFocus && prevOwner != null && Registry.is("actionSystem.xWindow.remove.focus.from.nonFocusable.popups")) {
new Alarm().addRequest(() -> {
if (isFocused()) {
IdeFocusManager.getInstance(myProject).requestFocus(prevOwner, false);
}
}, Registry.intValue("actionSystem.xWindow.remove.focus.from.nonFocusable.popups.delay"));
}
afterShow.run();
});
}
debugState("popup shown", State.SHOWING);
myState = State.SHOWN;
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class InputDialogFixture method enterTextAndClickOk.
public void enterTextAndClickOk(@NotNull String text) {
JTextComponent input = robot().finder().find(target(), JTextComponentMatcher.any());
assertNotNull(input);
JTextComponentFixture inputFixture = new JTextComponentFixture(robot(), input);
inputFixture.enterText(text);
GuiTestUtil.findAndClickOkButton(this);
}
use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.
the class ResourceChooserDialogFixture method setDirectoryName.
public void setDirectoryName(@NotNull String directory) {
Container parent = robot().finder().find(target(), JLabelMatcher.withText("Directory name:")).getParent();
JTextComponent directoryField = robot().finder().findByType(parent, JTextComponent.class, true);
JTextComponentDriver driver = new JTextComponentDriver(robot());
driver.selectAll(directoryField);
driver.setText(directoryField, directory);
}
Aggregations