Browse Source

Improved ColorChooser layout.

pull/127/head
weisj 5 years ago
parent
commit
50b8ea1d2d
  1. 6
      core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java
  2. 4
      core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java
  3. 7
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java
  4. 22
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java
  5. 19
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java

6
core/src/main/java/com/github/weisj/darklaf/color/DarkColorModelCMYK.java

@ -98,9 +98,9 @@ public class DarkColorModelCMYK extends DarkColorModel {
private static int[] CMYKtoRGB(final double c, final double m, final double y, final double k) { private static int[] CMYKtoRGB(final double c, final double m, final double y, final double k) {
rgb[0] = (int) Math.round(255 * (1.0f + c * k - k - c)); rgb[0] = (int) Math.round(255 * (1 - c) * (1 - k));
rgb[1] = (int) Math.round(255 * (1.0f + m * k - k - m)); rgb[1] = (int) Math.round(255 * (1 - m) * (1 - k));
rgb[2] = (int) Math.round(255 * (1.0f + y * k - k - y)); rgb[2] = (int) Math.round(255 * (1 - y) * (1 - k));
return rgb; return rgb;
} }

4
core/src/main/java/com/github/weisj/darklaf/components/color/SmallColorChooser.java

@ -288,7 +288,7 @@ public class SmallColorChooser extends JPanel {
} }
protected ColorPreviewComponent createPreviewComponent() { protected ColorPreviewComponent createPreviewComponent() {
ColorPreviewComponent comp = new ColorPreviewComponent() { return new ColorPreviewComponent() {
@Override @Override
public Dimension getMaximumSize() { public Dimension getMaximumSize() {
return getPreferredSize(); return getPreferredSize();
@ -303,8 +303,6 @@ public class SmallColorChooser extends JPanel {
return size; return size;
} }
}; };
comp.setBorder(null);
return comp;
} }
protected static class Descriptor extends JLabel { protected static class Descriptor extends JLabel {

7
core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/ColorPreviewComponent.java

@ -34,7 +34,6 @@ public class ColorPreviewComponent extends JComponent {
private Color color; private Color color;
public ColorPreviewComponent() { public ColorPreviewComponent() {
setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
borderColor = UIManager.getColor("ColorChooser.previewBorderColor"); borderColor = UIManager.getColor("ColorChooser.previewBorderColor");
} }
@ -63,10 +62,4 @@ public class ColorPreviewComponent extends JComponent {
g.fillRect(i.left + width - 1, i.top, 1, height); g.fillRect(i.left + width - 1, i.top, 1, height);
g.fillRect(i.left, i.top + height - 1, width, 1); g.fillRect(i.left, i.top + height - 1, width, 1);
} }
@Override
public Dimension getPreferredSize() {
return new Dimension(100, 32);
}
} }

22
core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkColorChooserPanel.java

@ -26,7 +26,6 @@ package com.github.weisj.darklaf.ui.colorchooser;
import com.github.weisj.darklaf.color.DarkColorModel; import com.github.weisj.darklaf.color.DarkColorModel;
import com.github.weisj.darklaf.components.DefaultColorPipette; import com.github.weisj.darklaf.components.DefaultColorPipette;
import com.github.weisj.darklaf.components.uiresource.JButtonUIResource;
import com.github.weisj.darklaf.decorators.AncestorAdapter; import com.github.weisj.darklaf.decorators.AncestorAdapter;
import com.github.weisj.darklaf.decorators.UpdateDocumentListener; import com.github.weisj.darklaf.decorators.UpdateDocumentListener;
import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.ui.button.DarkButtonUI;
@ -84,7 +83,7 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
initInputFields(colorModels); initInputFields(colorModels);
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); setBorder(BorderFactory.createEmptyBorder(20, 20, 0, 21));
add(buildTopPanel(UIManager.getBoolean("ColorChooser.pipetteEnabled")), BorderLayout.NORTH); add(buildTopPanel(UIManager.getBoolean("ColorChooser.pipetteEnabled")), BorderLayout.NORTH);
add(colorWheelPanel, BorderLayout.CENTER); add(colorWheelPanel, BorderLayout.CENTER);
add(Box.createVerticalStrut(10), BorderLayout.SOUTH); add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
@ -114,7 +113,11 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
colorChanged(getColorFromHex(), textHex); colorChanged(getColorFromHex(), textHex);
}); });
for (JFormattedTextField inputField : valueFields) { for (JFormattedTextField inputField : valueFields) {
inputField.addPropertyChangeListener(e -> colorChanged(getColorFromFields(), inputField)); inputField.addPropertyChangeListener(e -> {
if ("value".equals(e.getPropertyName())) {
colorChanged(getColorFromFields(), inputField);
}
});
} }
colorWheelPanel.addListener(this); colorWheelPanel.addListener(this);
} }
@ -268,7 +271,6 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
return c == null ? currentColor : c; return c == null ? currentColor : c;
} }
protected DarkColorModel getDarkColorModel() { protected DarkColorModel getDarkColorModel() {
return (DarkColorModel) formatBox.getSelectedItem(); return (DarkColorModel) formatBox.getSelectedItem();
} }
@ -281,9 +283,13 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
if (enablePipette && pipette != null) { if (enablePipette && pipette != null) {
previewPanel.add(createPipetteButton(), BorderLayout.WEST); previewPanel.add(createPipetteButton(), BorderLayout.WEST);
} }
previewComponent.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
previewComponent.setPreferredSize(new Dimension(100, 25));
previewPanel.add(previewComponent, BorderLayout.CENTER); previewPanel.add(previewComponent, BorderLayout.CENTER);
result.add(previewPanel, BorderLayout.NORTH); result.add(previewPanel, BorderLayout.NORTH);
final JPanel valuePanel = new JPanel(); final JPanel valuePanel = new JPanel();
valuePanel.setLayout(new BoxLayout(valuePanel, BoxLayout.X_AXIS)); valuePanel.setLayout(new BoxLayout(valuePanel, BoxLayout.X_AXIS));
valuePanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); valuePanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
@ -314,15 +320,17 @@ public class DarkColorChooserPanel extends AbstractColorChooserPanel implements
} }
private JButton createPipetteButton() { private JButton createPipetteButton() {
JButton pipetteButton = new JButtonUIResource(); JButton pipetteButton = new JButton();
pipetteButton.putClientProperty(DarkButtonUI.KEY_VARIANT, DarkButtonUI.VARIANT_ONLY_LABEL);
pipetteButton.putClientProperty(DarkButtonUI.KEY_THIN, Boolean.TRUE); pipetteButton.putClientProperty(DarkButtonUI.KEY_THIN, Boolean.TRUE);
pipetteButton.putClientProperty(DarkButtonUI.KEY_SQUARE, Boolean.TRUE);
pipetteButton.putClientProperty(DarkButtonUI.KEY_ALT_ARC, Boolean.TRUE);
pipetteButton.setRolloverEnabled(true); pipetteButton.setRolloverEnabled(true);
pipetteButton.setFocusable(false);
pipetteButton.setIcon(getPipetteIcon()); pipetteButton.setIcon(getPipetteIcon());
pipetteButton.setRolloverIcon(getPipetteRolloverIcon()); pipetteButton.setRolloverIcon(getPipetteRolloverIcon());
pipetteButton.setDisabledIcon(getPipetteRolloverIcon()); pipetteButton.setDisabledIcon(getPipetteRolloverIcon());
pipetteButton.setPressedIcon(getPipetteRolloverIcon()); pipetteButton.setPressedIcon(getPipetteRolloverIcon());
pipetteButton.setFocusable(false);
pipetteButton.addActionListener(e -> { pipetteButton.addActionListener(e -> {
pipetteButton.setEnabled(false); pipetteButton.setEnabled(false);
pipette.setInitialColor(getColorFromModel()); pipette.setInitialColor(getColorFromModel());

19
core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkSwatchesChooserPanel.java

@ -26,7 +26,6 @@ package com.github.weisj.darklaf.ui.colorchooser;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import javax.swing.colorchooser.AbstractColorChooserPanel; import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.colorchooser.ColorSelectionModel; import javax.swing.colorchooser.ColorSelectionModel;
@ -59,11 +58,9 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
@Override @Override
protected void buildChooser() { protected void buildChooser() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
String recentStr = UIManager.getString("ColorChooser.swatchesRecentText", getLocale()); String recentStr = UIManager.getString("ColorChooser.swatchesRecentText", getLocale());
JPanel superHolder = new JPanel();
superHolder.setLayout(new BorderLayout());
previewPanel = new ColorPreviewComponent(); previewPanel = new ColorPreviewComponent();
previewPanel.setColor(getColorFromModel()); previewPanel.setColor(getColorFromModel());
@ -83,13 +80,13 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
recentSwatchPanel.addMouseListener(recentSwatchListener); recentSwatchPanel.addMouseListener(recentSwatchListener);
recentSwatchPanel.addKeyListener(recentSwatchKeyListener); recentSwatchPanel.addKeyListener(recentSwatchKeyListener);
JPanel mainHolder = new JPanel(new FlowLayout(FlowLayout.CENTER)); JPanel mainHolder = new JPanel(new GridBagLayout());
Border border = new LineBorder(UIManager.getColor("ColorChooser.swatchBorderColor")); Border border = new LineBorder(UIManager.getColor("ColorChooser.swatchBorderColor"));
swatchPanel.setBorder(border); swatchPanel.setBorder(border);
mainHolder.add(swatchPanel); mainHolder.add(swatchPanel);
recentSwatchPanel.setInheritsPopupMenu(true); recentSwatchPanel.setInheritsPopupMenu(true);
JPanel recentHolder = new JPanel(new FlowLayout(FlowLayout.CENTER)); JPanel recentHolder = new JPanel(new GridBagLayout());
recentSwatchPanel.setBorder(border); recentSwatchPanel.setBorder(border);
recentHolder.setInheritsPopupMenu(true); recentHolder.setInheritsPopupMenu(true);
recentHolder.add(recentSwatchPanel); recentHolder.add(recentSwatchPanel);
@ -100,8 +97,9 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
labelHolder.add(l); labelHolder.add(l);
JPanel previewHolder = new JPanel(new BorderLayout()); JPanel previewHolder = new JPanel(new BorderLayout());
previewHolder.setBorder(new EmptyBorder(0, 5, 10, 5)); previewHolder.add(Box.createVerticalStrut(25), BorderLayout.WEST);
previewHolder.add(previewPanel, BorderLayout.CENTER); previewHolder.add(previewPanel, BorderLayout.CENTER);
previewHolder.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
JPanel swatches = new JPanel(); JPanel swatches = new JPanel();
swatches.setInheritsPopupMenu(true); swatches.setInheritsPopupMenu(true);
@ -110,11 +108,8 @@ public class DarkSwatchesChooserPanel extends AbstractColorChooserPanel {
swatches.add(labelHolder); swatches.add(labelHolder);
swatches.add(recentHolder); swatches.add(recentHolder);
superHolder.add(previewHolder, BorderLayout.NORTH); add(previewHolder);
superHolder.add(swatches, BorderLayout.CENTER); add(swatches);
superHolder.setInheritsPopupMenu(true);
add(superHolder);
} }
public String getDisplayName() { public String getDisplayName() {

Loading…
Cancel
Save