com.intellij.ui.EditorTextField Java Examples

The following examples show how to use com.intellij.ui.EditorTextField. 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: DarculaEditorTextFieldUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(JComponent c) {
  EditorTextField editorTextField = (EditorTextField)c;

  Editor editor = editorTextField.getEditor();

  Dimension size = JBUI.size(1, 10);
  if (editor != null) {
    size.height = editor.getLineHeight();

    size.height = Math.max(size.height, JBUIScale.scale(16));

    JBInsets.addTo(size, editorTextField.getInsets());
    JBInsets.addTo(size, editor.getInsets());
  }

  return size;
}
 
Example #2
Source File: ParameterNameHintsConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static EditorTextField createEditorField(@Nonnull String text, @Nullable TextRange rangeToSelect) {
  Document document = EditorFactory.getInstance().createDocument(text);
  EditorTextField field = new EditorTextField(document, null, PlainTextFileType.INSTANCE, false, false);
  field.setPreferredSize(new Dimension(200, 350));
  field.addSettingsProvider(editor -> {
    editor.setVerticalScrollbarVisible(true);
    editor.setHorizontalScrollbarVisible(true);
    editor.getSettings().setAdditionalLinesCount(2);
    if (rangeToSelect != null) {
      editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset());
      editor.getScrollingModel().scrollVertically(document.getTextLength() - 1);
      editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset());
    }
  });
  return field;
}
 
Example #3
Source File: CSharpParameterTableModel.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column)
{
	final EditorTextField textField = (EditorTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
	/*textField.registerKeyboardAction(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			PsiType type = getRowType(table, row);
			if(type != null)
			{
				completeVariable(textField, type);
			}
		}
	}, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);*/
	textField.setBorder(new LineBorder(table.getSelectionBackground()));
	return textField;
}
 
Example #4
Source File: MultilinePopupBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static EditorTextField createTextField(@Nonnull Project project,
                                               Collection<String> values,
                                               boolean supportsNegativeValues,
                                               @Nonnull String initialValue) {
  TextFieldWithCompletion textField =
          new TextFieldWithCompletion(project, new MyCompletionProvider(values, supportsNegativeValues), initialValue, false, true, false) {
            @Override
            protected EditorEx createEditor() {
              EditorEx editor = super.createEditor();
              SoftWrapsEditorCustomization.ENABLED.customize(editor);
              return editor;
            }
          };
  textField.setBorder(new CompoundBorder(JBUI.Borders.empty(2), textField.getBorder()));
  return textField;
}
 
Example #5
Source File: ClassCompletionPanelWrapper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void init() {
    this.field = new EditorTextField("", project, com.jetbrains.php.lang.PhpFileType.INSTANCE);

    PhpCompletionUtil.installClassCompletion(this.field, null, getDisposable());

    this.field.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent e) {
            String text = field.getText();
            if (StringUtil.isEmpty(text) || StringUtil.endsWith(text, "\\")) {
                return;
            }

            addUpdateRequest(250, () -> consumer.consume(field.getText()));
        }
    });

    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.fill = 1;
    gbConstraints.weightx = 1.0D;
    gbConstraints.gridx = 1;
    gbConstraints.gridy = 1;

    panel.add(field, gbConstraints);
}
 
Example #6
Source File: ImmediatePainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean canPaintImmediately(final DesktopEditorImpl editor) {
  final CaretModel caretModel = editor.getCaretModel();
  final Caret caret = caretModel.getPrimaryCaret();
  final Document document = editor.getDocument();

  return document instanceof DocumentImpl &&
         editor.getHighlighter() instanceof LexerEditorHighlighter &&
         !(editor.getComponent().getParent() instanceof EditorTextField) &&
         editor.myView.getTopOverhang() <= 0 && editor.myView.getBottomOverhang() <= 0 &&
         !editor.getSelectionModel().hasSelection() &&
         caretModel.getCaretCount() == 1 &&
         !isInVirtualSpace(editor, caret) &&
         !isInsertion(document, caret.getOffset()) &&
         !caret.isAtRtlLocation() &&
         !caret.isAtBidiRunBoundary();
}
 
Example #7
Source File: BlazeAndroidTestRunConfigurationStateEditor.java    From intellij with Apache License 2.0 6 votes vote down vote up
BlazeAndroidTestRunConfigurationStateEditor(
    RunConfigurationStateEditor commonStateEditor, Project project) {
  this.commonStateEditor = commonStateEditor;
  doSetupUI(project);

  packageComponent.setComponent(new EditorTextField());

  classComponent.setComponent(new EditorTextField());

  runnerComponent.setComponent(new EditorTextField());

  methodComponent.setComponent(new EditorTextField());

  addTestingType(BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_TARGET, allInTargetButton);
  addTestingType(TEST_ALL_IN_PACKAGE, allInPackageButton);
  addTestingType(TEST_CLASS, classButton);
  addTestingType(TEST_METHOD, testMethodButton);
}
 
Example #8
Source File: StringTableCellEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  final EditorTextField editorTextField = new EditorTextField((String) value, myProject, InternalStdFileTypes.JAVA) {
          @Override
          protected boolean shouldHaveBorder() {
            return false;
          }
        };
  myDocument = editorTextField.getDocument();
  if (myDocument != null) {
    for (DocumentListener listener : myListeners) {
      editorTextField.addDocumentListener(listener);
    }
  }
  return editorTextField;
}
 
Example #9
Source File: ScriptDialog.java    From PackageTemplates with Apache License 2.0 6 votes vote down vote up
private void createViews() {
    etfName = new EditorTextField(Localizer.get("ExampleName"));
    btnTry = new JButton(Localizer.get("TryIt"));
    jlResult = new JBLabel(Localizer.get("ResultWillBeHere"));

    etfName.setAlignmentX(Component.CENTER_ALIGNMENT);
    etfName.setAlignmentY(Component.CENTER_ALIGNMENT);
    btnTry.setAlignmentX(Component.CENTER_ALIGNMENT);
    btnTry.setAlignmentY(Component.CENTER_ALIGNMENT);
    jlResult.setAlignmentX(Component.CENTER_ALIGNMENT);
    jlResult.setAlignmentY(Component.CENTER_ALIGNMENT);

    btnTry.addMouseListener(new ClickListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            jlResult.setText(ScriptExecutor.runScript(etfCode.getText(), etfName.getText()));
        }
    });
}
 
Example #10
Source File: ModuleSelector.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
private static TextComponentAccessor<EditorTextField> getTextComponentAccessor() {
    return new TextComponentAccessor<EditorTextField>() {
        @Override
        public String getText(EditorTextField component) {
            String text = component.getText();
            final VirtualFile file = VirtualFileManager.getInstance()
                            .findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/')));
            if (file != null && !file.isDirectory()) {
                final VirtualFile parent = file.getParent();
                assert parent != null;
                return parent.getPresentableUrl();
            }
            return text;
        }

        @Override
        public void setText(EditorTextField component, String text) {
            component.setText(text);
        }
    };
}
 
Example #11
Source File: IJSwingUtilities.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void adjustComponentsOnMac(@Nullable JLabel label, @Nullable JComponent component) {
  if (component == null) return;
  if (!UIUtil.isUnderAquaLookAndFeel()) return;

  if (component instanceof JComboBox) {
    UIUtil.addInsets(component, new Insets(0,-2,0,0));
    if (label != null) {
      UIUtil.addInsets(label, new Insets(0,2,0,0));
    }
  }
  if (component instanceof JCheckBox) {
    UIUtil.addInsets(component, new Insets(0,-5,0,0));
  }
  if (component instanceof JTextField || component instanceof EditorTextField) {
    if (label != null) {
      UIUtil.addInsets(label, new Insets(0,3,0,0));
    }
  }
}
 
Example #12
Source File: LibraryDialog.java    From PackageTemplates with Apache License 2.0 6 votes vote down vote up
private void initBinaryFilesTab() {
    pTabBinaryFiles = new JPanel(new MigLayout(new LC()));

    // List
    createBinaryFileList();

    //Content (right panel)
    JPanel panelBinaryFilesContent = new JPanel(new MigLayout());
    btnBinaryFilePath = new TextFieldWithBrowseButton();
    btnBinaryFilePath.setText("");
    btnBinaryFilePath.addBrowseFolderListener(Localizer.get("library.ChooseBinaryFile"), "", project, FileReaderUtil.getBinaryFileDescriptor());

    tfBinaryFileAlias = new EditorTextField("ExampleAlias");

    panelBinaryFilesContent.add(tfBinaryFileAlias, new CC().wrap());
    panelBinaryFilesContent.add(btnBinaryFilePath, new CC().wrap().gapY("8pt", "0"));

    //Splitter
    JBSplitter splitter = new JBSplitter(0.3f);
    splitter.setFirstComponent(listBinaryFiles);
    splitter.setSecondComponent(panelBinaryFilesContent);

    pTabBinaryFiles.add(splitter, new CC().push().grow());
    tabbedPane.addTab("Tab1", pTabBinaryFiles);
}
 
Example #13
Source File: FileEditorRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public FileEditor getData(@Nonnull DataProvider dataProvider) {
  final Editor editor = dataProvider.getDataUnchecked(PlatformDataKeys.EDITOR);
  if (editor == null) {
    return null;
  }

  final Boolean aBoolean = editor.getUserData(EditorTextField.SUPPLEMENTARY_KEY);
  if (aBoolean != null && aBoolean.booleanValue()) {
    return null;
  }

  return TextEditorProvider.getInstance().getTextEditor(editor);
}
 
Example #14
Source File: TextFieldCompletionProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EditorTextField createEditor(Project project,
                                    final boolean shouldHaveBorder,
                                    @Nullable final Consumer<Editor> editorConstructionCallback)
{
  return new EditorTextField(createDocument(project, ""), project, PlainTextLanguage.INSTANCE.getAssociatedFileType()) {
    @Override
    protected boolean shouldHaveBorder() {
      return shouldHaveBorder;
    }

    @Override
    protected void updateBorder(@Nonnull EditorEx editor) {
      if (shouldHaveBorder) {
        super.updateBorder(editor);
      }
      else {
        editor.setBorder(null);
      }
    }

    @Override
    protected EditorEx createEditor() {
      EditorEx result = super.createEditor();
      if (editorConstructionCallback != null) {
        editorConstructionCallback.consume(result);
      }
      return result;
    }
  };
}
 
Example #15
Source File: ShowTextPopupHyperlinkInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
  Application.get().invokeLater(() -> {
    Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText));
    EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) {
      @Override
      protected EditorEx createEditor() {
        EditorEx editor = super.createEditor();
        editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        editor.getSettings().setUseSoftWraps(true);
        return editor;
      }
    };

    Window frame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
    if(frame != null) {
      Dimension size = frame.getSize();
      if(size != null) {
        textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2));
      }
    }

    JBPopupFactory.getInstance()
            .createComponentPopupBuilder(textField, textField)
            .setTitle(myTitle)
            .setResizable(true)
            .setMovable(true)
            .setRequestFocus(true)
            .createPopup()
            .showCenteredInCurrentWindow(project);
  });
}
 
Example #16
Source File: ExternalProjectPathField.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MyPathAndProjectButtonPanel(@Nonnull EditorTextField textField,
                                   @Nonnull FixedSizeButton registeredProjectsButton)
{
  super(new GridBagLayout());
  myTextField = textField;
  myRegisteredProjectsButton = registeredProjectsButton;
  add(myTextField, new GridBag().weightx(1).fillCellHorizontally());
  add(myRegisteredProjectsButton, new GridBag().insets(0, 3, 0, 0));
}
 
Example #17
Source File: UIHelper.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
public static EditorTextField getEditorTextField(String defValue, Project project, boolean isOneLineMode) {
    EditorTextField etfName = new EditorTextField();
    etfName.setAlignmentX(Component.LEFT_ALIGNMENT);
    etfName.setOneLineMode(isOneLineMode);

    addHighlightListener(project, etfName);

    etfName.setText(defValue);
    return etfName;
}
 
Example #18
Source File: GlobalVariableWrapper.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
public void buildView(PackageTemplateWrapper ptWrapper, JPanel container) {
        jlVariable = new JLabel(AllIcons.Nodes.Variable, JLabel.LEFT);
        jlVariable.setDisabledIcon(jlVariable.getIcon());
        jlVariable.setText("variable");

        tfKey = new EditorTextField(globalVariable.getName());
        tfKey.setAlignmentX(Component.LEFT_ALIGNMENT);
//        UIHelper.setRightPadding(tfKey, PADDING_LABEL);

        tfValue = UIHelper.getEditorTextField(globalVariable.getValue(), ptWrapper.getProject());

        if (ptWrapper.getMode() == PackageTemplateWrapper.ViewMode.USAGE) {
            tfKey.setEnabled(false);
        } else {
            jlVariable.addMouseListener(new ClickListener() {
                @Override
                public void mouseClicked(MouseEvent eventOuter) {
                    if (SwingUtilities.isRightMouseButton(eventOuter)) {
                        JPopupMenu popupMenu = getPopupMenu(ptWrapper);
                        popupMenu.show(jlVariable, eventOuter.getX(), eventOuter.getY());
                    }
                }
            });
        }

        // Lock modifying BASE_NAME
        if (getGlobalVariable().getName().equals(ATTRIBUTE_BASE_NAME)) {
            tfKey.setEnabled(false);
        }

        container.add(createOptionsBlock(), new CC().spanX().split(3));
        container.add(tfKey, new CC().width("0").pushX().growX());
        container.add(tfValue, new CC().width("0").pushX().growX().wrap());
    }
 
Example #19
Source File: DebuggerUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showValuePopup(@Nonnull XFullValueEvaluator evaluator, @Nonnull MouseEvent event, @Nonnull Project project, @Nullable Editor editor) {
  EditorTextField textArea = new TextViewer("Evaluating...", project);
  textArea.setBackground(HintUtil.INFORMATION_COLOR);

  final FullValueEvaluationCallbackImpl callback = new FullValueEvaluationCallbackImpl(textArea);
  evaluator.startEvaluation(callback);

  Dimension size = DimensionService.getInstance().getSize(FULL_VALUE_POPUP_DIMENSION_KEY, project);
  if (size == null) {
    Dimension frameSize = TargetAWT.to(WindowManager.getInstance().getWindow(project)).getSize();
    size = new Dimension(frameSize.width / 2, frameSize.height / 2);
  }

  textArea.setPreferredSize(size);

  JBPopup popup = createValuePopup(project, textArea, callback);
  if (editor == null) {
    Rectangle bounds = new Rectangle(event.getLocationOnScreen(), size);
    ScreenUtil.fitToScreenVertical(bounds, 5, 5, true);
    if (size.width != bounds.width || size.height != bounds.height) {
      size = bounds.getSize();
      textArea.setPreferredSize(size);
    }
    popup.showInScreenCoordinates(event.getComponent(), bounds.getLocation());
  }
  else {
    popup.showInBestPositionFor(editor);
  }
}
 
Example #20
Source File: XDebuggerExpressionEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public XDebuggerExpressionEditor(Project project,
                                 @Nonnull XDebuggerEditorsProvider debuggerEditorsProvider,
                                 @Nullable @NonNls String historyId,
                                 @Nullable XSourcePosition sourcePosition,
                                 @Nonnull XExpression text,
                                 final boolean multiline,
                                 boolean editorFont,
                                 boolean showEditor) {
  super(project, debuggerEditorsProvider, multiline ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION, historyId, sourcePosition);
  myExpression = XExpressionImpl.changeMode(text, getMode());
  myEditorTextField =
          new EditorTextField(createDocument(myExpression), project, debuggerEditorsProvider.getFileType(), false, !multiline) {
            @Override
            protected EditorEx createEditor() {
              final EditorEx editor = super.createEditor();
              editor.setVerticalScrollbarVisible(multiline);
              editor.getColorsScheme().setEditorFontName(getFont().getFontName());
              editor.getColorsScheme().setEditorFontSize(getFont().getSize());
              return editor;
            }

            @Override
            public Object getData(@Nonnull Key dataId) {
              if (LangDataKeys.CONTEXT_LANGUAGES == dataId) {
                return new Language[]{myExpression.getLanguage()};
              } else if (CommonDataKeys.PSI_FILE == dataId) {
                return PsiDocumentManager.getInstance(getProject()).getPsiFile(getDocument());
              }
              return super.getData(dataId);
            }
          };
  if (editorFont) {
    myEditorTextField.setFontInheritedFromLAF(false);
    myEditorTextField.setFont(EditorUtil.getEditorFont());
  }
  myComponent = decorate(myEditorTextField, multiline, showEditor);
}
 
Example #21
Source File: BasicEditorTextFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getMinimumSize(JComponent c) {
  EditorTextField editorTextField = (EditorTextField)c;
  Editor editor = editorTextField.getEditor();
  Dimension size = new Dimension(1, 20);
  if (editor != null) {
    size.height = editor.getLineHeight();

    JBInsets.addTo(size, editorTextField.getInsets());
    JBInsets.addTo(size, editor.getInsets());
  }

  return size;
}
 
Example #22
Source File: UpDownHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(AnActionEvent e) {
  final LookupEx lookup;
  if (myInput instanceof EditorTextField) {
    lookup = LookupManager.getActiveLookup(((EditorTextField)myInput).getEditor());
  } else if (myInput instanceof EditorComponentImpl) {
    lookup = LookupManager.getActiveLookup(((EditorComponentImpl)myInput).getEditor());
  } else {
    lookup = null;
  }

  e.getPresentation().setEnabled(lookup == null);
}
 
Example #23
Source File: ViewStructureAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    e.getPresentation().setEnabled(false);
    return;
  }

  FileEditor fileEditor = e.getData(PlatformDataKeys.FILE_EDITOR);
  Editor editor = fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : e.getData(CommonDataKeys.EDITOR);

  boolean enabled = fileEditor != null && (!Boolean.TRUE.equals(EditorTextField.SUPPLEMENTARY_KEY.get(editor))) && fileEditor.getStructureViewBuilder() != null;
  e.getPresentation().setEnabled(enabled);
}
 
Example #24
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 5 votes vote down vote up
public String getEnteredName() {
  if (myComponent instanceof JComboBox) {
    return (String)((JComboBox)myComponent).getEditor().getItem();
  } else {
    return ((EditorTextField) myComponent).getText();
  }
}
 
Example #25
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 5 votes vote down vote up
private JComponent createTextFieldForName(String[] nameSuggestions, FileType fileType) {
  final String text;
  if (nameSuggestions != null && nameSuggestions.length > 0 && nameSuggestions[0] != null) {
    text = nameSuggestions[0];
  }
  else {
    text = "";
  }

  EditorTextField field = new EditorTextField(text, myProject, fileType);
  field.selectAll();
  return field;
}
 
Example #26
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Editor getEditor() {
  if (myComponent instanceof EditorTextField) {
    return ((EditorTextField)myComponent).getEditor();
  }
  else {
    return ((EditorTextField)((JComboBox)myComponent).getEditor().getEditorComponent()).getEditor();
  }
}
 
Example #27
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void attachListeners() {
  if (myDocumentListener == null) {
    myDocumentListener = new MyDocumentListener();
    ((EditorTextField) getFocusableComponent()).addDocumentListener(myDocumentListener);
  }
  if (myComboBoxItemListener == null && myComponent instanceof JComboBox) {
    myComboBoxItemListener = new MyComboBoxItemListener();
    ((JComboBox) myComponent).addItemListener(myComboBoxItemListener);
  }
}
 
Example #28
Source File: NameSuggestionsField.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void detachListeners() {
  if (myDocumentListener != null) {
    ((EditorTextField) getFocusableComponent()).removeDocumentListener(myDocumentListener);
    myDocumentListener = null;
  }
  if (myComboBoxItemListener != null) {
    ((JComboBox) myComponent).removeItemListener(myComboBoxItemListener);
    myComboBoxItemListener = null;
  }
}
 
Example #29
Source File: CodeFragmentTableCellEditorBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected EditorTextField createEditorField(Document document) {
  EditorTextField field = new EditorTextField(document, myProject, myFileType) {
    @Override
    protected boolean shouldHaveBorder() {
      return false;
    }
  };
  field.setBorder(new EmptyBorder(1, 1, 1, 1));
  return field;
}
 
Example #30
Source File: DarculaEditorTextFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintBackground(Graphics g, EditorTextField field) {
  if (DarculaUIUtil.isComboBoxEditor(field)) {
    super.paintBackground(g, field);
    return;
  }

 // DarculaTextFieldUI.paintBackground(g, field);
}