Skip to content

Commit

Permalink
added support for jspinners, slightly changed jtextfield behaviour for
Browse files Browse the repository at this point in the history
jtables and possibly fixed pixelated fonts
  • Loading branch information
atarw committed Jun 13, 2018
1 parent 761d071 commit 867ad4c
Show file tree
Hide file tree
Showing 26 changed files with 560 additions and 253 deletions.
426 changes: 275 additions & 151 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified lib/material-ui-swing.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/MaterialUISwingDemo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mdlaf.MaterialLookAndFeel;
import mdlaf.MaterialUIMovement;
import mdlaf.animation.MaterialUIMovement;

import javax.swing.JButton;
import javax.swing.JFrame;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void main (String[] args) {
MaterialUIMovement.add (item1, gray);

// you can also pass in extra parameters indicating how many intermediate colors to display, as well as the "frame rate" of the animation
// there will be 5 intermediate colors displayed in the transition from the original component color to the new one specified
// there will be 5 intermediate colors displayed in the transition from the original components color to the new one specified
// the "frame rate" of the transition will be 1000 / 30, or 30 FPS
// the animation will take 5 * 1000 / 30 = 166.666... milliseconds to complete
Color blue = new Color (34, 167, 240);
Expand Down
Binary file added src/imgs/up_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions src/mdlaf/MaterialLookAndFeel.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package mdlaf;

import mdlaf.button.MaterialButtonUI;
import mdlaf.password.MaterialPasswordFieldUI;
import mdlaf.table.MaterialTableHeaderUI;
import mdlaf.table.MaterialTableUI;
import mdlaf.textfield.MaterialTextFieldUI;
import mdlaf.tree.MaterialTreeUI;
import mdlaf.components.button.MaterialButtonUI;
import mdlaf.components.panel.MaterialPanelUI;
import mdlaf.components.password.MaterialPasswordFieldUI;
import mdlaf.components.spinner.MaterialSpinnerUI;
import mdlaf.components.table.MaterialTableHeaderUI;
import mdlaf.components.table.MaterialTableUI;
import mdlaf.components.textfield.MaterialTextFieldUI;
import mdlaf.components.tree.MaterialTreeUI;
import mdlaf.resources.MaterialBorders;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialFonts;

import javax.swing.BorderFactory;
import javax.swing.UIDefaults;
Expand All @@ -20,9 +25,10 @@ public class MaterialLookAndFeel extends BasicLookAndFeel {
private static final String tableUI = MaterialTableUI.class.getCanonicalName ();
private static final String tableHeaderUI = MaterialTableHeaderUI.class.getCanonicalName ();
private static final String treeUI = MaterialTreeUI.class.getCanonicalName ();
private static final String spinnerUI = MaterialSpinnerUI.class.getCanonicalName ();
private static final String panelUI = MaterialPanelUI.class.getCanonicalName ();

@Override

public String getName () {
return "Material Look And Feel";
}
Expand Down Expand Up @@ -56,6 +62,8 @@ protected void initClassDefaults (UIDefaults table) {
table.put ("TableUI", tableUI);
table.put ("TableHeaderUI", tableHeaderUI);
table.put ("TreeUI", treeUI);
table.put ("SpinnerUI", spinnerUI);
table.put ("PanelUI", panelUI);
}

@Override
Expand All @@ -67,10 +75,6 @@ protected void initSystemColorDefaults (UIDefaults table) {
protected void initComponentDefaults (UIDefaults table) {
super.initComponentDefaults (table);

System.setProperty ("awt.useSystemAAFontSettings", "on");
System.setProperty ("swing.aatext", "true");
System.setProperty ("sun.java2d.xrender", "true");

table.put ("RadioButton.font", MaterialFonts.REGULAR);
table.put ("CheckBox.font", MaterialFonts.REGULAR);
table.put ("ComboBox.font", MaterialFonts.REGULAR);
Expand All @@ -79,13 +83,9 @@ protected void initComponentDefaults (UIDefaults table) {
table.put ("MenuItem.font", MaterialFonts.MEDIUM);
table.put ("Menu.font", MaterialFonts.BOLD);
table.put ("OptionPane.font", MaterialFonts.REGULAR);
table.put ("Panel.font", MaterialFonts.REGULAR);
table.put ("ScrollPane.font", MaterialFonts.REGULAR);
table.put ("TextArea.font", MaterialFonts.REGULAR);

table.put ("Panel.background", Color.WHITE);
table.put ("Panel.border", BorderFactory.createEmptyBorder ());

table.put ("MenuItem.background", Color.WHITE);
table.put ("MenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5));
table.put ("MenuItem.disabledForeground", new Color (0, 0, 0, 100));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mdlaf;
package mdlaf.animation;

import javax.swing.JComponent;
import java.awt.Color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mdlaf;
package mdlaf.animation;

import javax.swing.JComponent;
import javax.swing.Timer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package mdlaf.button;
package mdlaf.components.button;

import mdlaf.MaterialColors;
import mdlaf.MaterialFonts;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialDrawingUtils;
import mdlaf.resources.MaterialFonts;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
Expand All @@ -10,8 +11,6 @@
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

public class MaterialButtonUI extends BasicButtonUI {

Expand All @@ -35,15 +34,12 @@ public void installUI (JComponent c) {
@Override
public void paint (Graphics g, JComponent c) {
AbstractButton b = (AbstractButton) c;
g = MaterialDrawingUtils.getAliasedGraphics (g);
paintBackground (g, b);
super.paint (g, c);
}

private void paintBackground (final Graphics g, final JComponent c) {
Graphics2D g2 = (Graphics2D) g;

g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));

private void paintBackground (Graphics g, JComponent c) {
g.setColor (c.getBackground ());
g.fillRoundRect (0, 0, c.getWidth (), c.getHeight (), 7, 7);
}
Expand Down
35 changes: 35 additions & 0 deletions src/mdlaf/components/panel/MaterialPanelUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package mdlaf.components.panel;

import mdlaf.resources.MaterialDrawingUtils;
import mdlaf.resources.MaterialFonts;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPanelUI;
import java.awt.Color;
import java.awt.Graphics;

public class MaterialPanelUI extends BasicPanelUI {

public static ComponentUI createUI (final JComponent c) {
return new MaterialPanelUI ();
}

@Override
public void installUI (JComponent c) {
super.installUI (c);

JPanel panel = (JPanel) c;
panel.setOpaque (true);
panel.setFont (MaterialFonts.REGULAR);
panel.setBackground (Color.WHITE);
panel.setBorder (BorderFactory.createEmptyBorder ());
}

@Override
public void paint (Graphics g, JComponent c) {
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mdlaf.password;
package mdlaf.components.password;

import mdlaf.MaterialColors;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialDrawingUtils;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -116,9 +117,7 @@ public void actionPerformed (ActionEvent e) {
@Override
public void paintSafely (Graphics g) {
JPasswordField c = (JPasswordField) getComponent ();
Graphics2D g2 = (Graphics2D) g;

g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
g = MaterialDrawingUtils.getAliasedGraphics (g);

if (getComponent ().hasFocus ()) {
c.setBackground (focusedBackground);
Expand All @@ -140,8 +139,8 @@ public void paintSafely (Graphics g) {
}

@Override
public void paintBackground (final Graphics g) {
super.paintBackground (g);
public void paintBackground (Graphics g) {
super.paintBackground (MaterialDrawingUtils.getAliasedGraphics (g));
}

@Override
Expand Down
75 changes: 75 additions & 0 deletions src/mdlaf/components/spinner/MaterialSpinnerUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package mdlaf.components.spinner;

import mdlaf.components.textfield.MaterialTextFieldUI;
import mdlaf.resources.MaterialBorders;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialDrawingUtils;
import mdlaf.resources.MaterialFonts;
import mdlaf.resources.MaterialImages;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JSpinner;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSpinnerUI;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

public class MaterialSpinnerUI extends BasicSpinnerUI {

public static ComponentUI createUI (final JComponent c) {
return new MaterialSpinnerUI ();
}

@Override
public void installUI (JComponent c) {
super.installUI (c);

JSpinner spinner = (JSpinner) c;
spinner.setOpaque (false);
spinner.setFont (MaterialFonts.REGULAR);
spinner.setBackground (Color.WHITE);
spinner.setForeground (Color.BLACK);
spinner.setBorder (MaterialBorders.LIGHT_LINE_BORDER);
}

@Override
protected JComponent createEditor () {
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) super.createEditor ();
editor.getTextField ().setUI (new MaterialTextFieldUI (false));

return editor;
}

@Override
public void paint (Graphics g, JComponent c) {
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}

@Override
protected Component createNextButton () {
JButton button = new JButton (new ImageIcon (MaterialImages.UP_ARROW));

button.setOpaque (true);
button.setBackground (MaterialColors.LIGHT_GRAY);
button.setBorder (BorderFactory.createEmptyBorder ());
installNextButtonListeners (button);

return button;
}

@Override
protected Component createPreviousButton () {
JButton button = new JButton (new ImageIcon (MaterialImages.DOWN_ARROW));

button.setOpaque (true);
button.setBackground (MaterialColors.LIGHT_GRAY);
button.setBorder (BorderFactory.createEmptyBorder ());
installPreviousButtonListeners (button);

return button;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package mdlaf.table;
package mdlaf.components.table;

import mdlaf.components.textfield.MaterialTextFieldUI;

import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
Expand All @@ -7,6 +9,13 @@

public class MaterialTableCellEditor extends DefaultCellEditor {

private static JTextField init () {
JTextField textField = new JTextField ();
textField.setUI (new MaterialTextFieldUI (false));

return textField;
}

@Override
public Component getTableCellEditorComponent (JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) {
JTextField textField = (JTextField) super.getTableCellEditorComponent (table, value, isSelected, rowIndex, vColIndex);
Expand All @@ -16,6 +25,6 @@ public Component getTableCellEditorComponent (JTable table, Object value, boolea
}

public MaterialTableCellEditor () {
super (new JTextField ());
super (init ());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mdlaf.table;
package mdlaf.components.table;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mdlaf.table;
package mdlaf.components.table;

import mdlaf.MaterialBorders;
import mdlaf.MaterialColors;
import mdlaf.MaterialFonts;
import mdlaf.resources.MaterialBorders;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialFonts;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package mdlaf.table;
package mdlaf.components.table;

import mdlaf.resources.MaterialDrawingUtils;

import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
Expand All @@ -17,12 +19,11 @@ public void installUI (JComponent c) {
super.installUI (c);

JTableHeader header = (JTableHeader) c;

header.setDefaultRenderer (new MaterialTableHeaderCellRenderer ());
}

@Override
public void paint (Graphics g, JComponent c) {
super.paint (g, c);
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mdlaf.table;
package mdlaf.components.table;

import mdlaf.MaterialBorders;
import mdlaf.MaterialColors;
import mdlaf.MaterialFonts;
import mdlaf.resources.MaterialBorders;
import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialDrawingUtils;
import mdlaf.resources.MaterialFonts;

import javax.swing.JComponent;
import javax.swing.JTable;
Expand Down Expand Up @@ -45,6 +46,6 @@ public void installUI (JComponent c) {

@Override
public void paint (Graphics g, JComponent c) {
super.paint (g, c);
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}
}
Loading

0 comments on commit 867ad4c

Please sign in to comment.