mirror of https://github.com/FreeCol/freecol.git
Adds styling for radio buttons and checkbox/radio menu items.
This commit is contained in:
parent
bf59cd7245
commit
fe99698c1e
|
@ -89,6 +89,8 @@ image.border.button.simple.sw=resources/images/ui/simplebuttonborder-sw.png
|
|||
image.border.button.simple.se=resources/images/ui/simplebuttonborder-se.png
|
||||
|
||||
# Interface
|
||||
image.ui.button.radio=resources/images/ui/button-radio.png
|
||||
image.ui.button.radio.selected=resources/images/ui/button-radio-selected.png
|
||||
image.ui.checkmark=resources/images/ui/checkmark.png
|
||||
image.ui.includesSpecification=resources/images/ui/includes-specification.png
|
||||
image.ui.noSpecification=resources/images/ui/no-specification.png
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (C) 2002-2022 The FreeCol Team
|
||||
*
|
||||
* This file is part of FreeCol.
|
||||
*
|
||||
* FreeCol is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FreeCol is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with FreeCol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.sf.freecol.client.gui.plaf;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
||||
|
||||
|
||||
/**
|
||||
* UI-class for menu items.
|
||||
*/
|
||||
public class FreeColCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
|
||||
|
||||
public static ComponentUI createUI(@SuppressWarnings("unused") JComponent c) {
|
||||
return new FreeColCheckBoxMenuItemUI();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
|
||||
c.setOpaque(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
LAFUtilities.setProperties(g, c);
|
||||
super.paint(g, c);
|
||||
}
|
||||
}
|
|
@ -28,9 +28,9 @@ import java.awt.Graphics2D;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
|
@ -81,7 +81,7 @@ public class FreeColCheckBoxUI extends MetalCheckBoxUI {
|
|||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final int mainFontSize = FontLibrary.getMainFont().getSize();
|
||||
|
||||
final ButtonModel model = ((JCheckBox) c).getModel();
|
||||
final ButtonModel model = ((AbstractButton) c).getModel();
|
||||
final int widgetSize = getWidgetSize();
|
||||
|
||||
ImageUtils.fillTexture(((Graphics2D) g),
|
||||
|
|
|
@ -114,6 +114,7 @@ public class FreeColLookAndFeel extends MetalLookAndFeel {
|
|||
|
||||
private static final Class uiClasses[] = {
|
||||
FreeColButtonUI.class,
|
||||
FreeColCheckBoxMenuItemUI.class,
|
||||
FreeColCheckBoxUI.class,
|
||||
FreeColComboBoxUI.class,
|
||||
FreeColFileChooserUI.class,
|
||||
|
@ -125,6 +126,7 @@ public class FreeColLookAndFeel extends MetalLookAndFeel {
|
|||
FreeColOptionPaneUI.class,
|
||||
FreeColPanelUI.class,
|
||||
FreeColPopupMenuUI.class,
|
||||
FreeColRadioButtonMenuItemUI.class,
|
||||
FreeColRadioButtonUI.class,
|
||||
FreeColScrollPaneUI.class,
|
||||
FreeColTableHeaderUI.class,
|
||||
|
@ -212,6 +214,10 @@ public class FreeColLookAndFeel extends MetalLookAndFeel {
|
|||
u.put("cursor.go", ImageLibrary.getCursor());
|
||||
|
||||
u.put("CheckBox.icon", (LazyValue) t -> FreeColCheckBoxUI.createCheckBoxIcon());
|
||||
u.put("CheckBoxMenuItem.checkIcon", (LazyValue) t -> FreeColCheckBoxUI.createCheckBoxIcon());
|
||||
|
||||
u.put("RadioButton.icon", (LazyValue) t -> FreeColRadioButtonUI.createRadioButtonIcon());
|
||||
u.put("RadioButtonMenuItem.checkIcon", (LazyValue) t -> FreeColRadioButtonUI.createRadioButtonIcon());
|
||||
|
||||
// TODO: We might want to allow overriding font colors for the menu:
|
||||
//u.put("Menu.foreground", java.awt.Color.WHITE);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (C) 2002-2022 The FreeCol Team
|
||||
*
|
||||
* This file is part of FreeCol.
|
||||
*
|
||||
* FreeCol is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FreeCol is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with FreeCol. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.sf.freecol.client.gui.plaf;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
||||
|
||||
|
||||
/**
|
||||
* UI-class for menu items.
|
||||
*/
|
||||
public class FreeColRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI {
|
||||
|
||||
public static ComponentUI createUI(@SuppressWarnings("unused") JComponent c) {
|
||||
return new FreeColRadioButtonMenuItemUI();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
|
||||
c.setOpaque(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
LAFUtilities.setProperties(g, c);
|
||||
super.paint(g, c);
|
||||
}
|
||||
}
|
|
@ -19,11 +19,26 @@
|
|||
|
||||
package net.sf.freecol.client.gui.plaf;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Component;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonUI;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
|
||||
import net.sf.freecol.client.gui.FontLibrary;
|
||||
import net.sf.freecol.common.resources.ResourceManager;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -48,4 +63,64 @@ public class FreeColRadioButtonUI extends BasicRadioButtonUI {
|
|||
LAFUtilities.setProperties(g, c);
|
||||
super.paint(g, c);
|
||||
}
|
||||
|
||||
public static Icon createRadioButtonIcon() {
|
||||
return new RadioButtonIcon();
|
||||
}
|
||||
|
||||
private static class RadioButtonIcon implements Icon, UIResource, Serializable {
|
||||
|
||||
protected int getWidgetSize() {
|
||||
return FontLibrary.getMainFont().getSize() * 3 / 2;
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
final Graphics2D g2d = (Graphics2D) g;
|
||||
final ButtonModel model = ((AbstractButton) c).getModel();
|
||||
final int widgetSize = getWidgetSize();
|
||||
|
||||
if (!model.isEnabled()) {
|
||||
g.setColor(MetalLookAndFeel.getControlDisabled());
|
||||
g.fillRect(x, y, widgetSize - 1, widgetSize - 1);
|
||||
} else if (model.isPressed() && model.isArmed() ) {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.fillRect(x, y, widgetSize - 1, widgetSize - 1);
|
||||
}
|
||||
|
||||
if (c.hasFocus()) {
|
||||
g.setColor(MetalLookAndFeel.getControlHighlight());
|
||||
g.drawRect(x, y, widgetSize - 1, widgetSize - 1);
|
||||
}
|
||||
|
||||
if (model.isSelected()) {
|
||||
final BufferedImage radioButtonImage = ResourceManager.getImage("image.ui.button.radio.selected",
|
||||
new Dimension(getIconWidth(), getIconHeight()), false);
|
||||
|
||||
final Composite origComposite = g2d.getComposite();
|
||||
if (!model.isEnabled()) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
||||
}
|
||||
|
||||
if (radioButtonImage != null) {
|
||||
g2d.drawImage(radioButtonImage, x, y, null);
|
||||
}
|
||||
|
||||
g2d.setComposite(origComposite);
|
||||
} else {
|
||||
final BufferedImage radioButtonImage = ResourceManager.getImage("image.ui.button.radio",
|
||||
new Dimension(getIconWidth(), getIconHeight()), false);
|
||||
if (radioButtonImage != null) {
|
||||
g2d.drawImage(radioButtonImage, x, y, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return getWidgetSize();
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return getWidgetSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue