Skip to content

Commit

Permalink
Animaciones para combobox y scrollbar, borde para sombra
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel-ICM committed Oct 18, 2021
1 parent 35d489b commit e8b4aa3
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 89 deletions.
Binary file modified build/classes/icm/sphynx/ui/components/metro/UIButton.class
Binary file not shown.
Binary file modified build/classes/icm/sphynx/ui/components/metro/UIComboBox.class
Binary file not shown.
Binary file modified build/classes/icm/sphynx/ui/components/metro/UIScrollBar.class
Binary file not shown.
Binary file modified build/classes/icm/sphynx/ui/components/metro/UITools.class
Binary file not shown.
57 changes: 57 additions & 0 deletions src/icm/sphynx/ui/components/metro/MetroUIBorderShadow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package icm.sphynx.ui.components.metro;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;

/**
*
* @author israel-icm
*/
public class MetroUIBorderShadow extends LineBorder {
public MetroUIBorderShadow(Color color, int thickness) {
super(color, thickness);
}


@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D)g;

Insets insets = getBorderInsets(c);
g2d.setColor(lineColor);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

float transparencia = 1;
float div = (1.0f / insets.top);

int bajarSombra = 4; // Establece si se bajará la sombra y cuantos puntos se bajará para hacer el cálculo y no dejar espacios en blanco

int top = insets.top;
int bottom = height - (insets.bottom + insets.top) - bajarSombra;
int left = insets.left;
int right = width - (insets.left + insets.right);
for (int i = insets.left; i > 0; i--) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparencia));
g2d.drawRect(left, top + bajarSombra, right, bottom);
top--;
left--;
right+=2;
bottom+=2;
transparencia = transparencia - div;
}

// Agregamos un borde complementario para el componente
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.decode("#CCCCCC"));
g2d.drawRect(insets.left - 1, insets.top - 1, (width - (insets.left * 2)) + 1, (height - (insets.top * 2)) + 1);
}
}
18 changes: 18 additions & 0 deletions src/icm/sphynx/ui/components/metro/MetroUIComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
public class MetroUIComponent {
private static final String TEXT_FIELD = "MetroTextField";
private static final String PASSWORD_FIELD = "MetroPasswordField";
private static final String BUTTON = "MetroButton";

private static final String TEXT_FIELD_PROPERTY_PLACEHOLDER = "placeholder";
private static final String TEXT_FIELD_PROPERTY_ICON = "icon";
public static final String ICON_SEARCH = "search";
private static final String BUTTON_EMPTY = "empty";

/**
* Agrega el ícono predeterminado a un textfield
Expand Down Expand Up @@ -41,6 +43,14 @@ public static void setTextFieldPlaceholder(String nameComponent, String value) {
public static void setPasswordFieldPlaceholder(String nameComponent, String value) {
UIManager.put(PASSWORD_FIELD + "." + nameComponent + "." + TEXT_FIELD_PROPERTY_PLACEHOLDER, value);
}
/**
* Estable el botón sin bordes y sin relleno
* @param nameComponent
*/
public static void setEmpyButton(String nameComponent) {
UIManager.put(BUTTON + "." + nameComponent + "." + BUTTON_EMPTY, true);
}

/**
* Retorna el valor de la propiedad icon
* @param nameComponent
Expand All @@ -65,4 +75,12 @@ public static String getPropertyTextFieldPlaceholder(String nameComponent) {
public static String getPropertyPasswordFieldPlaceholder(String nameComponent) {
return UIManager.getString(PASSWORD_FIELD + "." + nameComponent + "." + TEXT_FIELD_PROPERTY_PLACEHOLDER);
}
/**
* Retorna el valor de la propiedad empty button
* @param nameComponent
* @return
*/
public static boolean getEmptyButton(String nameComponent) {
return UIManager.getBoolean(BUTTON + "." + nameComponent + "." + BUTTON_EMPTY);
}
}
18 changes: 18 additions & 0 deletions src/icm/sphynx/ui/components/metro/MetroUIConfigTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ public class MetroUIConfigTheme {
public static void setPrimaryColor(String colorHex) {
UIManager.put("MetroUI.primaryColor", Color.decode(colorHex));
setSecondColor(colorHex);
setThirdColor(colorHex);
setFourthColor(colorHex);
}

private static void setSecondColor(String colorHex) {
UIManager.put("MetroUI.secondColor", Color.decode(UITools.getSecondColor(colorHex)));
}

private static void setThirdColor(String colorHex) {
UIManager.put("MetroUI.thirdColor", Color.decode(UITools.getThirdColor(colorHex)));
}

private static void setFourthColor(String colorHex) {
UIManager.put("MetroUI.fourthColor", Color.decode(UITools.getFourthColor(colorHex)));
}

public static void setDarkMode(boolean dark) {
UIManager.put("MetroUI.darkMode", dark);
}
Expand All @@ -29,6 +39,14 @@ public static Color getSecondColor() {
return UIManager.getColor("MetroUI.secondColor");
}

public static Color getThirdColor() {
return UIManager.getColor("MetroUI.thirdColor");
}

public static Color getFourthColor() {
return UIManager.getColor("MetroUI.fourthColor");
}

public static boolean isDarkMode() {
return UIManager.getBoolean("MetroUI.darkMode");
}
Expand Down
37 changes: 21 additions & 16 deletions src/icm/sphynx/ui/components/metro/UIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,28 @@ public void paint(Graphics g, JComponent c) {
g2d = (Graphics2D)g;
width = c.getWidth();
height = c.getHeight();

if (estado == 0) {
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
g2d.setComposite(ac);
g.setColor(MetroUIConfigTheme.getPrimaryColor());
g.fillRect(0, 0, width, height);
/*LineBorder border = new LineBorder(Color.decode(UITools.COLOR_BUTTON_DEFAULT), 3);
c.setBorder(border);*/
if (MetroUIComponent.getEmptyButton(c.getName())) {
c.setBackground(null);
c.setBorder(null);
}
else {
if (estado == 0) {
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
g2d.setComposite(ac);
g.setColor(MetroUIConfigTheme.getPrimaryColor());
g.fillRect(0, 0, width, height);
/*LineBorder border = new LineBorder(Color.decode(UITools.COLOR_BUTTON_DEFAULT), 3);
c.setBorder(border);*/
}
/*else {
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f);
g2d.setComposite(ac);
g.setColor(Color.decode(UITools.COLOR_BUTTON_DEFAULT));
g.fillRect(0, 0, width, height);
LineBorder border = new LineBorder(Color.RED, 3);
c.setBorder(border);
}*/
}
/*else {
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f);
g2d.setComposite(ac);
g.setColor(Color.decode(UITools.COLOR_BUTTON_DEFAULT));
g.fillRect(0, 0, width, height);
LineBorder border = new LineBorder(Color.RED, 3);
c.setBorder(border);
}*/
super.paint(g, c);
}

Expand Down
Loading

0 comments on commit e8b4aa3

Please sign in to comment.