Skip to content

Commit

Permalink
Merge pull request #82 from vincenzopalazzo/workingonversion1.0
Browse files Browse the repository at this point in the history
Create version 1.0 BETA
  • Loading branch information
atarw authored Apr 21, 2019
2 parents 31e6bb3 + fea9194 commit 6823f3b
Show file tree
Hide file tree
Showing 21 changed files with 928 additions and 534 deletions.
Binary file added demo/Demo-Swing-set3.tar
Binary file not shown.
510 changes: 351 additions & 159 deletions src/main/java/mdlaf/MaterialLookAndFeel.java

Large diffs are not rendered by default.

33 changes: 25 additions & 8 deletions src/main/java/mdlaf/animation/MaterialUIStaticMovement.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* MIT License
*
* Copyright (c) 2019 Vincent Palazzo [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package mdlaf.animation;

import javax.swing.*;
Expand All @@ -24,16 +47,11 @@ public MaterialUIStaticMovement(Color before, Color after, Color strongOnClick)

@Override
public void mouseClicked(MouseEvent e) {
/*For effect click, need create a timer ?*/
/* if(e == null){
throw new IllegalArgumentException("MouseEvent null");
}
setColorComponent(e, after);*/
// do nothing
}

@Override
public void mousePressed(MouseEvent e) {
/*For effect click, need create a timer ?*/
if(e == null){
throw new IllegalArgumentException("MouseEvent null");
}
Expand All @@ -42,7 +60,6 @@ public void mousePressed(MouseEvent e) {

@Override
public void mouseReleased(MouseEvent e) {
/*For effect click, need create a timer ?*/
if(e == null){
throw new IllegalArgumentException("MouseEvent null");
}
Expand All @@ -65,7 +82,7 @@ public void mouseExited(MouseEvent e) {
setColorComponent(e, before);
}

/***
/**
* This is service method for recicle code
*/
private void setColorComponent(MouseEvent e, Color colorComponent){
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/mdlaf/animation/MaterialUITimer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* MIT License
*
* Copyright (c) 2018 atharva washimkar, Vincent Palazzo
* Copyright (c) 2018 atharva washimkar
* Copyright (c) 2019 Vincent Palazzo [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,7 +28,7 @@
import java.awt.Color;
import java.awt.event.*;

public class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener {
class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener {

private Color from, to;
private boolean forward;
Expand Down Expand Up @@ -60,7 +61,6 @@ protected MaterialUITimer(JComponent component, Color to, int steps, int interva
this.steps = steps;

this.component = component;
this.component.addMouseListener(this);
timer = new Timer(interval, this);
component.setBackground(from);
}
Expand Down Expand Up @@ -90,6 +90,9 @@ public void mousePressed(MouseEvent me) {
}
alpha = steps - 1;
forward = false;
if(timer.isRunning()){
timer.stop();
}
timer.start();

alpha = 0;
Expand All @@ -99,19 +102,22 @@ public void mousePressed(MouseEvent me) {

@Override
public void mouseReleased(MouseEvent me) {

//do nothing
}

@Override
public void mouseClicked(MouseEvent me) {

//do nothing
}

@Override
public void mouseExited(MouseEvent me) {
if (!me.getComponent().isEnabled()) {
return;
}
if(timer.isRunning()){
timer.stop();
}
alpha = steps - 1;
forward = false;
timer.start();
Expand All @@ -124,6 +130,9 @@ public void mouseEntered(MouseEvent me) {
}
alpha = 0;
forward = true;
if(timer.isRunning()){
timer.stop();
}
timer.start();
}

Expand All @@ -138,7 +147,9 @@ public void actionPerformed(ActionEvent ae) {
}

if (alpha == steps + 1 || alpha == -1) {
timer.stop();
if(timer.isRunning()){
timer.stop();
}
}
}

Expand Down
56 changes: 40 additions & 16 deletions src/main/java/mdlaf/components/button/MaterialButtonUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,64 @@

import mdlaf.animation.MaterialUIMovement;
import mdlaf.utils.MaterialDrawingUtils;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.UIManager;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.plaf.metal.MetalButtonUI;
import java.awt.*;

/**
* @contributor https://github.com/vincenzopalazzo
*/

public class MaterialButtonUI extends BasicButtonUI {

public class MaterialButtonUI extends MetalButtonUI {
public static ComponentUI createUI(final JComponent c) {
return new MaterialButtonUI();
}

private Color foreground;
private Color background;

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

AbstractButton button = (AbstractButton) c;
button.setOpaque(UIManager.getBoolean("Button.opaque"));
button.setBorder(UIManager.getBorder("Button.border"));
button.setBackground(UIManager.getColor("Button.background"));
button.setForeground(UIManager.getColor("Button.foreground"));
foreground = UIManager.getColor("Button.foreground");
background = UIManager.getColor("Button.background");
button.setBackground(background);
button.setForeground(foreground);
button.setFont(UIManager.getFont("Button.font"));
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor("Button.mouseHoverColor")));
button.setFocusable(UIManager.getBoolean("Button.focusable"));
}

@Override
public void paint(Graphics g, JComponent c) {
AbstractButton b = (AbstractButton) c;
g = MaterialDrawingUtils.getAliasedGraphics(g);
JButton b = (JButton) c;
if (b.isContentAreaFilled()) {
paintBackground(MaterialDrawingUtils.getAliasedGraphics(g), b);
}

super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c);
}
//Fix to #73 border were pixeled, fixde by https://github.com/vincenzopalazzo

private void paintBackground(Graphics g, JComponent c) {
//g.setColor(c.getBackground());
//g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7);
Graphics2D graphics2D = (Graphics2D) g;
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g = graphics2D;
g.setColor(c.getBackground());
g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7);

paintStateButton(c, g);
}

@Override
protected void paintButtonPressed(Graphics g, AbstractButton b) {
super.paintButtonPressed(g, b);
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
super.paintFocus(g, b, viewRect, textRect, iconRect);
driveLine(g, (JButton) b);
}

@Override
Expand All @@ -64,5 +68,25 @@ public void update(Graphics g, JComponent c) {
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
protected void paintButtonPressed(Graphics g, AbstractButton b) {
g.fillRoundRect(0, 0, b.getWidth(), b.getHeight(), 7, 7);
}

protected void driveLine(Graphics g, JButton b){
g.setColor(UIManager.getColor("Button[focus].color"));
g.drawLine(20 , (b.getHeight() / 2) + 10, b.getWidth() - 20, (b.getHeight() / 2) + 10);
}

protected void paintStateButton(JComponent component, Graphics graphics) {
if(component == null){
throw new IllegalArgumentException("Input null");
}
JButton b = (JButton) component;
if(b.isDefaultButton()){
driveLine(graphics, b);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import mdlaf.utils.MaterialDrawingUtils;

import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicCheckBoxUI;
import java.awt.*;

//TODO cambio colore icone combo box
public class MaterialCheckBoxUI extends BasicCheckBoxUI {

public static ComponentUI createUI (JComponent c) {
Expand All @@ -26,8 +23,7 @@ public void installUI (JComponent c) {
checkBox.setForeground (UIManager.getColor ("CheckBox.foreground"));
checkBox.setIcon (UIManager.getIcon ("CheckBox.icon"));
checkBox.setSelectedIcon (UIManager.getIcon ("CheckBox.selectedIcon"));
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

checkBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/**
* @author https://github.com/vincenzopalazzo
*/

public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {

public static ComponentUI createUI (JComponent c) {
Expand All @@ -23,6 +22,11 @@ public static ComponentUI createUI (JComponent c) {
@Override
public void installUI (JComponent c) {
super.installUI (c);

c.setBackground(UIManager.getColor("CheckBoxMenuItem.background"));
c.setForeground(UIManager.getColor("CheckBoxMenuItem.foreground"));
c.setBorder(UIManager.getBorder("CheckBoxMenuItem.border"));
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
Expand All @@ -33,7 +37,6 @@ public void paint (Graphics g, JComponent c) {
@Override
protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c;
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
if (checkBoxMenuItem.isSelected ()) {
super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public Component getListCellRendererComponent (JList list, Object value, int ind
component.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5));
component.setForeground (UIManager.getColor ("ComboBox.foreground"));
component.setBackground (isSelected || cellHasFocus ?
UIManager.getColor ("ComboBox.selectedInDropDownBackground") :
UIManager.getColor ("ComboBox.background"));
UIManager.getColor("ComboBox.selectedInDropDownBackground") :
UIManager.getColor("ComboBox.background"));

return component;
}



}
17 changes: 7 additions & 10 deletions src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
import mdlaf.utils.MaterialBorders;
import mdlaf.utils.MaterialDrawingUtils;
import mdlaf.utils.MaterialManagerListener;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.*;

/**
* @contributor https://github.com/vincenzopalazzo
Expand All @@ -35,7 +30,6 @@ public void installUI (JComponent c) {
comboBox.setForeground (UIManager.getColor ("ComboBox.foreground"));
comboBox.setBorder (UIManager.getBorder ("ComboBox.border"));
comboBox.setLightWeightPopupEnabled (true);
comboBox.setRenderer (new MaterialComboBoxRenderer ());
comboBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

Expand Down Expand Up @@ -64,5 +58,8 @@ public void paint (Graphics g, JComponent c) {
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}


@Override
protected ListCellRenderer createRenderer() {
return new MaterialComboBoxRenderer();
}
}
Loading

0 comments on commit 6823f3b

Please sign in to comment.