diff --git a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingAction.java b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingAction.java index e5acfca5b30e..c67359942bd5 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/runAnything/RunAnythingAction.java @@ -1436,7 +1436,7 @@ public class RunAnythingAction extends AnAction implements CustomComponentAction } @Override - protected boolean customSetupUIAndTextField(@NotNull TextFieldWithProcessing textField, @NotNull Consumer uiConsumer) { + protected boolean customSetupUIAndTextField(@NotNull TextFieldWithProcessing textField, @NotNull Consumer uiConsumer) { if (UIUtil.isUnderDarcula()) { uiConsumer.consume(new MyDarcula()); textField.setBorder(new DarculaTextBorder()); diff --git a/platform/platform-api/src/com/intellij/ui/SearchTextField.java b/platform/platform-api/src/com/intellij/ui/SearchTextField.java index ae9a27dad8e5..67d45353a203 100644 --- a/platform/platform-api/src/com/intellij/ui/SearchTextField.java +++ b/platform/platform-api/src/com/intellij/ui/SearchTextField.java @@ -59,7 +59,7 @@ public class SearchTextField extends JPanel { public static final CustomShortcutSet ALT_SHOW_HISTORY_SHORTCUT = new CustomShortcutSet(ALT_SHOW_HISTORY_KEYSTROKE); private int myHistorySize = 5; - private int myCurrentHistoryIndex = 0; + private int myCurrentHistoryIndex; private final MyModel myModel; private final TextFieldWithProcessing myTextField; @@ -68,7 +68,7 @@ public class SearchTextField extends JPanel { private JLabel myToggleHistoryLabel; private JPopupMenu myNativeSearchPopup; private JMenuItem myNoItems; - private String myHistoryPropertyName = null; + private String myHistoryPropertyName; public SearchTextField() { this(true); @@ -192,12 +192,9 @@ public class SearchTextField extends JPanel { if (isSearchControlUISupported()) { myTextField.putClientProperty("JTextField.variant", "search"); - myTextField.putClientProperty("JTextField.Search.CancelAction", new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - myTextField.setText(""); - onFieldCleared(); - } + myTextField.putClientProperty("JTextField.Search.CancelAction", (ActionListener)e -> { + myTextField.setText(""); + onFieldCleared(); }); if (historyPopupEnabled) { @@ -214,6 +211,7 @@ public class SearchTextField extends JPanel { myToggleHistoryLabel.setOpaque(true); myToggleHistoryLabel.setToolTipText("Search History (" + KeymapUtil.getKeystrokeText(SHOW_HISTORY_KEYSTROKE)+ ")"); myToggleHistoryLabel.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { togglePopup(); } @@ -226,6 +224,7 @@ public class SearchTextField extends JPanel { myClearFieldLabel.setOpaque(true); add(myClearFieldLabel, BorderLayout.EAST); myClearFieldLabel.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { myTextField.setText(""); onFieldCleared(); @@ -233,13 +232,7 @@ public class SearchTextField extends JPanel { }); if (!hasIconsOutsideOfTextField()) { - final Border originalBorder; - if (SystemInfo.isMac) { - originalBorder = BorderFactory.createLoweredBevelBorder(); - } - else { - originalBorder = myTextField.getBorder(); - } + Border originalBorder = SystemInfo.isMac ? BorderFactory.createLoweredBevelBorder() : myTextField.getBorder(); myToggleHistoryLabel.setBackground(myTextField.getBackground()); myClearFieldLabel.setBackground(myTextField.getBackground()); @@ -262,7 +255,7 @@ public class SearchTextField extends JPanel { } } - protected boolean toClearTextOnEscape() { + private boolean toClearTextOnEscape() { return ApplicationManager.getApplication() != null; } @@ -293,14 +286,14 @@ public class SearchTextField extends JPanel { } protected boolean isSearchControlUISupported() { - return (SystemInfo.isMacOSLeopard && UIUtil.isUnderAquaLookAndFeel()) || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF(); + return SystemInfo.isMacOSLeopard && UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF(); } protected boolean hasIconsOutsideOfTextField() { return UIUtil.isUnderGTKLookAndFeel(); } - protected boolean customSetupUIAndTextField(@NotNull TextFieldWithProcessing textField, @NotNull Consumer uiConsumer) { + protected boolean customSetupUIAndTextField(@NotNull TextFieldWithProcessing textField, @NotNull Consumer uiConsumer) { if (SystemInfo.isMac) { try { Class uiClass = UIUtil.isUnderIntelliJLaF() ? Class.forName("com.intellij.ide.ui.laf.intellij.MacIntelliJTextFieldUI") @@ -333,6 +326,7 @@ public class SearchTextField extends JPanel { getTextEditor().addKeyListener(listener); } + @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); if (myToggleHistoryLabel != null) { @@ -368,6 +362,7 @@ public class SearchTextField extends JPanel { return getTextEditor().getText(); } + @Override public void removeNotify() { super.removeNotify(); hidePopup(); @@ -384,11 +379,9 @@ public class SearchTextField extends JPanel { myNativeSearchPopup.remove(myNoItems); final JMenuItem menuItem = new JBMenuItem(item); myNativeSearchPopup.add(menuItem); - menuItem.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - myTextField.setText(item); - addCurrentTextToHistory(); - } + menuItem.addActionListener(e -> { + myTextField.setText(item); + addCurrentTextToHistory(); }); } } @@ -401,17 +394,18 @@ public class SearchTextField extends JPanel { return myTextField; } + @Override public boolean requestFocusInWindow() { return myTextField.requestFocusInWindow(); } + @Override public void requestFocus() { - IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { - IdeFocusManager.getGlobalInstance().requestFocus(getTextEditor(), true); - }); + IdeFocusManager.getGlobalInstance() + .doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(getTextEditor(), true)); } - public void setHistoryPropertyName(String historyPropertyName) { + private void setHistoryPropertyName(String historyPropertyName) { myHistoryPropertyName = historyPropertyName; myTextField.putClientProperty("JTextField.Search.InplaceHistory", myHistoryPropertyName); reset(); @@ -440,10 +434,12 @@ public class SearchTextField extends JPanel { private String mySelectedItem; + @Override public String getElementAt(int index) { return myFullList.get(index); } + @Override public int getSize() { return Math.min(myHistorySize, myFullList.size()); } @@ -466,7 +462,7 @@ public class SearchTextField extends JPanel { // item is already at the top of the list return false; } - else if (index > 0) { + if (index > 0) { // move item to top of the list myFullList.remove(index); } @@ -568,12 +564,13 @@ public class SearchTextField extends JPanel { } protected static class TextFieldWithProcessing extends JBTextField { + @Override public void processKeyEvent(KeyEvent e) { super.processKeyEvent(e); } } - public final void keyEventToTextField(KeyEvent e) { + protected final void keyEventToTextField(KeyEvent e) { myTextField.processKeyEvent(e); } diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index f5845e337909..e804e9740ea1 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -50,15 +50,14 @@ import java.util.List; public class SimpleColoredComponent extends JComponent implements Accessible, ColoredTextContainer { private static final Logger LOG = Logger.getInstance("#com.intellij.ui.SimpleColoredComponent"); - public static final Color SHADOW_COLOR = new JBColor(new Color(250, 250, 250, 140), Gray._0.withAlpha(50)); - @SuppressWarnings("unused") public static final Color STYLE_SEARCH_MATCH_BACKGROUND = SHADOW_COLOR; //api compatibility + private static final Color SHADOW_COLOR = new JBColor(new Color(250, 250, 250, 140), Gray._0.withAlpha(50)); public static final int FRAGMENT_ICON = -2; private final List myFragments; private final List myLayouts; private Font myLayoutFont; private final List myAttributes; - private List myFragmentTags = null; + private List myFragmentTags; private final TIntIntHashMap myFragmentAlignment; /** @@ -96,11 +95,11 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co @JdkConstants.HorizontalAlignment private int myTextAlign = SwingConstants.LEFT; - private boolean myIconOpaque = false; + private boolean myIconOpaque; private boolean myAutoInvalidate = !(this instanceof TreeCellRenderer); - private boolean myIconOnTheRight = false; + private boolean myIconOnTheRight; private boolean myTransparentIconBackground; public SimpleColoredComponent() { @@ -411,7 +410,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co return new Dimension(width, height); } - public final synchronized int computePreferredHeight() { + final synchronized int computePreferredHeight() { int height = myIpad.top + myIpad.bottom; Font font = getBaseFont(); @@ -422,12 +421,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co Insets borderInsets = myBorder != null ? myBorder.getBorderInsets(this) : JBUI.emptyInsets(); textHeight += borderInsets.top + borderInsets.bottom; - if (myIcon != null) { - height += Math.max(myIcon.getIconHeight(), textHeight); - } - else { - height += textHeight; - } + height += myIcon == null ? textHeight : Math.max(myIcon.getIconHeight(), textHeight); // Take into account that the component itself can have a border final Insets insets = getInsets(); @@ -501,12 +495,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co if (StringUtil.isEmpty(text)) return 0; FontRenderContext fontRenderContext = getFontMetrics(font).getFontRenderContext(); TextLayout layout = getTextLayout(fragmentIndex, font, fontRenderContext); - if (layout != null) { - return layout.getAdvance(); - } - else { - return (float)font.getStringBounds(text, fontRenderContext).getWidth(); - } + return layout != null ? layout.getAdvance() : (float)font.getStringBounds(text, fontRenderContext).getWidth(); } private TextLayout createAndCacheTextLayout(int fragmentIndex, Font basefont, FontRenderContext fontRenderContext) { @@ -759,8 +748,15 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co } offset += getInsets().left; - class Frag { int index; float start; float end; float baseLine; Font font; Frag next; - public Frag(int index, float start, float end, float baseLine, Font font, Frag next) { + class Frag { + private final int index; + private final float start; + private final float end; + private final float baseLine; + private final Font font; + private final Frag next; + + private Frag(int index, float start, float end, float baseLine, @NotNull Font font, Frag next) { this.index = index; this.start = start; this.end = end; @@ -769,7 +765,6 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co this.next = next; } } - Frag secondPassFrag = null; int height = getHeight(); applyAdditionalHints(g); @@ -781,6 +776,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co Rectangle area = computePaintArea(); final int textBaseline = area.y + getTextBaseLine(baseMetrics, area.height); boolean wasSmaller = false; + Frag secondPassFrag = null; for (int i = 0; i < myFragments.size(); i++) { final SimpleTextAttributes attributes = myAttributes.get(i); @@ -963,7 +959,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co if (myTextAlign == SwingConstants.CENTER) { return excessiveWidth / 2; } - else if (myTextAlign == SwingConstants.RIGHT || myTextAlign == SwingConstants.TRAILING) { + if (myTextAlign == SwingConstants.RIGHT || myTextAlign == SwingConstants.TRAILING) { return excessiveWidth; } return 0; @@ -1156,7 +1152,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co myFragmentTags.add(myIndex, myFragments.get(myIndex)); } if (myIndex < myLayouts.size()) myLayouts.set(myIndex, null); - if ((myIndex + 1) < myLayouts.size()) myLayouts.add(myIndex + 1, null); + if (myIndex + 1 < myLayouts.size()) myLayouts.add(myIndex + 1, null); myIndex++; } myOffset += offset; diff --git a/plugins/stream-debugger/src/com/intellij/debugger/streams/ui/impl/TraceTreeCellRenderer.java b/plugins/stream-debugger/src/com/intellij/debugger/streams/ui/impl/TraceTreeCellRenderer.java index f251ccf7553f..55b8dfa74a6d 100644 --- a/plugins/stream-debugger/src/com/intellij/debugger/streams/ui/impl/TraceTreeCellRenderer.java +++ b/plugins/stream-debugger/src/com/intellij/debugger/streams/ui/impl/TraceTreeCellRenderer.java @@ -177,6 +177,7 @@ public class TraceTreeCellRenderer extends ColoredTreeCellRenderer { int row, boolean hasFocus) {} + @Override @SuppressWarnings("EmptyMethod") protected void doPaint(Graphics2D g) { super.doPaint(g);