Modify combobox size and combobox editor placing in Mac LaF

This commit is contained in:
Kirill Kirichenko
2018-01-16 17:52:24 +03:00
parent 860ee24826
commit e358ab9c61
5 changed files with 34 additions and 92 deletions
@@ -64,7 +64,6 @@ class FileEncodingConfigurable extends PerFileConfigurableBase<Charset> {
FileEncodingConfigurable(@NotNull Project project) {
super(project, createMappings(project));
myBOMForUTF8Combo.setModel(new EnumComboBoxModel<>(EncodingProjectManagerImpl.BOMForNewUTF8Files.class));
myBOMForUTF8Combo.setRenderer((list, value, index, isSelected, cellHasFocus) -> new JLabel(value.toString()));
myBOMForUTF8Combo.addItemListener(e -> updateExplanationLabelText());
myExplanationLabel.setHyperlinkTarget("https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8");
}
@@ -27,13 +27,13 @@ import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import static com.intellij.ide.ui.laf.intellij.MacIntelliJComboBoxUI.VALUE_OFFSET;
/**
* @author Konstantin Bulenkov
*/
public class MacComboBoxBorder extends MacIntelliJTextBorder {
private static final int VALUE_OFFSET = 5;
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
if (!(c instanceof JComponent)) return;
@@ -66,9 +66,10 @@ public class MacComboBoxBorder extends MacIntelliJTextBorder {
height - (i.top + i.bottom));
g2.fill(shape);
} else {
int vo = JBUI.scale(VALUE_OFFSET);
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
path.moveTo(i.left + VALUE_OFFSET, i.top);
path.lineTo(i.left + VALUE_OFFSET, height - i.bottom);
path.moveTo(i.left + vo, i.top);
path.lineTo(i.left + vo, height - i.bottom);
path.lineTo(i.left + arc, height - i.bottom);
path.quadTo(i.left, height - i.bottom, i.left, height - arc - i.bottom);
path.lineTo(i.left, arc + i.top);
@@ -15,7 +15,7 @@
*/
package com.intellij.ide.ui.laf.intellij;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI;
import com.intellij.ui.Gray;
import com.intellij.util.IconUtil;
import com.intellij.util.ui.EmptyIcon;
@@ -28,7 +28,10 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
@@ -40,12 +43,10 @@ import java.beans.PropertyChangeListener;
/**
* @author Konstantin Bulenkov
*/
public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
public class MacIntelliJComboBoxUI extends DarculaComboBoxUI {
private static final Border ourDefaultEditorBorder = JBUI.Borders.empty(1, 0);
static final float VALUE_OFFSET = JBUI.scale(5f);
private Icon DEFAULT_ICON;
private PropertyChangeListener myEditorChangeListener;
private PropertyChangeListener myEditorBorderChangeListener;
private PropertyChangeListener myEditableChangeListener;
@@ -146,32 +147,21 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
return button;
}
@Override
public Dimension getMinimumSize(JComponent c) {
return getSizeWithIcon(super.getMinimumSize(c));
}
private Dimension getSizeWithIcon(Dimension d) {
protected Dimension getSizeWithButton(Dimension d) {
Insets i = comboBox.getInsets();
int iconWidth = DEFAULT_ICON.getIconWidth() + i.right;
int iconHeight = DEFAULT_ICON.getIconHeight() + i.top + i.bottom;
int editorHeight = editor != null ? editor.getPreferredSize().height + i.top + i.bottom : 0;
return new Dimension(Math.max(d.width + JBUI.scale(7), iconWidth), Math.max(iconHeight, editorHeight));
return new Dimension(Math.max(d.width + JBUI.scale(7), iconWidth),
Math.max(Math.max(iconHeight, editorHeight), JBUI.scale(26)));
}
@Override
public Dimension getPreferredSize(JComponent c) {
return getSizeWithIcon(super.getPreferredSize(c));
}
@Override
protected ComboBoxEditor createEditor() {
final ComboBoxEditor comboBoxEditor = new BasicComboBoxEditor.UIResource() {
@Override
protected JTextField createEditorComponent() {
return new JTextField() {
{
setOpaque(false);
setBorder(ourDefaultEditorBorder);
@@ -250,38 +240,9 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
return comboBoxEditor;
}
@Override
protected Rectangle rectangleForCurrentValue() {
Rectangle rect = super.rectangleForCurrentValue();
rect.x += VALUE_OFFSET;
rect.width -= VALUE_OFFSET;
return rect;
}
@Override
protected Dimension getDefaultSize() {
return super.getDefaultSize();
}
@Override
protected LayoutManager createLayoutManager() {
return new LayoutManager() {
@Override
public void addLayoutComponent(String name, Component comp) {}
@Override
public void removeLayoutComponent(Component comp) {}
@Override
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return parent.getMinimumSize();
}
return new ComboBoxLayoutManager() {
@Override
public void layoutContainer(Container parent) {
JComboBox cb = (JComboBox)parent;
@@ -306,10 +267,7 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
arrowButton.setBounds(bounds.width - buttonWidth - cbInsets.right + offset, cbInsets.top, buttonWidth, buttonHeight);
}
if (editor != null ) {
bounds = rectangleForCurrentValue();
editor.setBounds(bounds);
}
layoutEditor();
}
};
}
@@ -345,22 +303,6 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
};
}
class ComboBoxRendererWrapper implements ListCellRenderer<Object> {
private final ListCellRenderer<Object> myRenderer;
public ComboBoxRendererWrapper(@NotNull ListCellRenderer<Object> renderer) {
myRenderer = renderer;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = myRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
BorderLayoutPanel panel = JBUI.Panels.simplePanel(c).withBorder(JBUI.Borders.empty(0, 8));
panel.setBackground(c.getBackground());
return panel;
}
}
@SuppressWarnings("unchecked")
private void wrapRenderer() {
ListCellRenderer<Object> renderer = list.getCellRenderer();
@@ -371,6 +313,22 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
};
}
private static class ComboBoxRendererWrapper implements ListCellRenderer<Object> {
private final ListCellRenderer<Object> myRenderer;
public ComboBoxRendererWrapper(@NotNull ListCellRenderer<Object> renderer) {
myRenderer = renderer;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = myRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
BorderLayoutPanel panel = JBUI.Panels.simplePanel(c).withBorder(JBUI.Borders.empty(0, 8));
panel.setBackground(c.getBackground());
return panel;
}
}
@Override
public void paint(Graphics g, JComponent c) {
Rectangle bounds = rectangleForCurrentValue();
@@ -384,18 +342,4 @@ public class MacIntelliJComboBoxUI extends BasicComboBoxUI {
@Nullable Rectangle getArrowButtonBounds() {
return arrowButton != null ? arrowButton.getBounds() : null;
}
@Override
protected void configureEditor() {
super.configureEditor();
if (Registry.is("ide.ui.composite.editor.for.combobox")) {
// BasicComboboxUI sets focusability depending on the combobox focusability.
// JPanel usually is unfocusable and uneditable.
// It could be set as an editor when people want to have a composite component as an editor.
// In such cases we should restore unfocusable state for panels.
if (editor instanceof JPanel) {
editor.setFocusable(false);
}
}
}
}
@@ -49,7 +49,7 @@ public class MacIntelliJTextFieldUI extends DarculaTextFieldUI {
@Override
protected int getMinimumHeight() {
return DarculaEditorTextFieldBorder.isComboBoxEditor(getComponent()) ? JBUI.scale(18) : JBUI.scale(28);
return DarculaEditorTextFieldBorder.isComboBoxEditor(getComponent()) ? JBUI.scale(18) : JBUI.scale(26);
}
@Override
@@ -660,9 +660,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener,
if (myEditor != null) {
size.height = myEditor.getLineHeight();
if (UIUtil.isUnderDefaultMacTheme()) {
size.height = Math.max(size.height, JBUI.scale(18));
} else if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
if (UIUtil.isUnderDefaultMacTheme() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
size.height = Math.max(size.height, JBUI.scale(16));
}