Java源码示例:com.intellij.ui.SearchTextField
示例1
public SearchFilter() {
filerLabel = new JLabel(TfPluginBundle.message(TfPluginBundle.KEY_TOOLBAR_FILTER_TITLE));
searchField = new SearchTextField(true);
setLayout(new BorderLayout(JBUI.scale(3), 0)); //adds vertical padding so search field isn't crammed in the panel
add(filerLabel, BorderLayout.LINE_START);
add(searchField, BorderLayout.LINE_END);
}
示例2
@NotNull
private SearchTextField createSearchTextField() {
final LogFilterTextField logFilterTextField = new LogFilterTextField();
logFilterTextField.setOnFilterListener(this::doFilter);
return logFilterTextField;
}
示例3
@NotNull
private SearchTextField createSearchTextField() {
final LogFilterTextField logFilterTextField = new LogFilterTextField();
logFilterTextField.setOnFilterListener(this::doFilter);
return logFilterTextField;
}
示例4
@Nonnull
public SearchTextField createTextFilter() {
return new TextFilterField(myTextFilterModel);
}
示例5
public SearchFieldAction(String text) {
super("Find: ");
myField = new SearchTextField(true) {
@Override
protected boolean preprocessEventForTextField(KeyEvent e) {
if ((KeyEvent.VK_ENTER == e.getKeyCode()) || ('\n' == e.getKeyChar())) {
e.consume();
addCurrentTextToHistory();
actionPerformed(null);
}
return super.preprocessEventForTextField(e);
}
@Override
protected void onFocusLost() {
myField.addCurrentTextToHistory();
actionPerformed(null);
}
@Override
protected void onFieldCleared() {
actionPerformed(null);
}
};
Border border = myField.getBorder();
Border emptyBorder = IdeBorderFactory.createEmptyBorder(3, 0, 2, 0);
if (border instanceof CompoundBorder) {
if (!UIUtil.isUnderDarcula()) {
myField.setBorder(new CompoundBorder(emptyBorder, ((CompoundBorder)border).getInsideBorder()));
}
}
else {
myField.setBorder(emptyBorder);
}
myField.setSearchIcon(AllIcons.Actions.Filter_small);
myComponent = new JPanel();
final BoxLayout layout = new BoxLayout(myComponent, BoxLayout.X_AXIS);
myComponent.setLayout(layout);
if (text.length() > 0) {
final JLabel label = new JLabel(text);
//label.setFont(label.getFont().deriveFont(Font.ITALIC));
label.setForeground(UIUtil.isUnderDarcula() ? UIUtil.getLabelForeground() : UIUtil.getInactiveTextColor());
label.setBorder(BorderFactory.createEmptyBorder(0,3,0,0));
myComponent.add(label);
}
myComponent.add(myField);
}
示例6
private SearchEverywhereUI createView(Project project, List<? extends SearchEverywhereContributor<?>> contributors) {
SearchEverywhereUI view = new SearchEverywhereUI(project, contributors);
view.setSearchFinishedHandler(() -> {
if (isShown()) {
myBalloon.cancel();
}
});
view.addViewTypeListener(viewType -> {
if (!isShown()) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
if (myBalloon == null || myBalloon.isDisposed()) return;
Dimension minSize = view.getMinimumSize();
JBInsets.addTo(minSize, myBalloon.getContent().getInsets());
myBalloon.setMinimumSize(minSize);
if (viewType == SearchEverywhereUI.ViewType.SHORT) {
myBalloonFullSize = myBalloon.getSize();
JBInsets.removeFrom(myBalloonFullSize, myBalloon.getContent().getInsets());
myBalloon.pack(false, true);
}
else {
if (myBalloonFullSize == null) {
myBalloonFullSize = view.getPreferredSize();
JBInsets.addTo(myBalloonFullSize, myBalloon.getContent().getInsets());
}
myBalloonFullSize.height = Integer.max(myBalloonFullSize.height, minSize.height);
myBalloonFullSize.width = Integer.max(myBalloonFullSize.width, minSize.width);
myBalloon.setSize(myBalloonFullSize);
}
});
});
DumbAwareAction.create(__ -> showHistoryItem(true)).registerCustomShortcutSet(SearchTextField.SHOW_HISTORY_SHORTCUT, view);
DumbAwareAction.create(__ -> showHistoryItem(false)).registerCustomShortcutSet(SearchTextField.ALT_SHOW_HISTORY_SHORTCUT, view);
return view;
}