Skip to content

Commit

Permalink
Correcciones para los componentes jtabbedpane y spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel-ICM committed Oct 20, 2021
1 parent 3ec3a12 commit 03e6d19
Show file tree
Hide file tree
Showing 13 changed files with 482 additions and 84 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/UITabbedPane.class
Binary file not shown.
Binary file modified build/classes/icm/sphynx/ui/components/metro/UITextArea.class
Binary file not shown.
21 changes: 13 additions & 8 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/MetroUIConfigTheme.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITabbedPane.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIPanel.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIList.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UILabel.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITools.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIProgressBar.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UISplitPane.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIButton.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIToggleButton.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIComboBox.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIFormattedTextField.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIPasswordField.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITextField.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/styles/MetroUI.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UICheckBox.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/tools/ToolsHeaderCellRendererTable.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/tools/IconsMetroUI.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIList.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIProgressBar.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UISplitPane.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UISlider.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITableHeader.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIRadioButton.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/tools/ThemeMetroUI.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UIPasswordField.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/styles/MyStyles.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITextField.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITextArea.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/tools/StyleColorsMetro.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/UITable.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/components/metro/MetroUIComponent.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/styles/MetroUI.java</file>
<file>file:/C:/Users/josue2/Documents/NetBeansProjects/MyStyles/src/icm/sphynx/ui/tools/ToolsHeaderCellRendererTable.java</file>
</group>
</open-files>
</project-private>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.awt.Insets;
import java.awt.RenderingHints;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;

/**
*
Expand Down
35 changes: 34 additions & 1 deletion src/icm/sphynx/ui/components/metro/UIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,50 @@ private void installButtonStyles() {
break;
}
}
/**
* Estilos para los botones del componente Spinner
*/
private void installButtonStylesSpinner() {
switch (currentStateButton) {
case STATE_DEFAULT:
g2d.setColor(Color.decode("#FFFFFF"));
g2d.fillRect(0, 0, width, height);

g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.decode("#CCCCCC"));
g2d.drawRect(1, 1, width - 2, height - 2);
break;
case STATE_OVER:
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.decode("#7C7D7D"));
g2d.drawRect(1, 1, width - 2, height - 2);
break;
case STATE_PRESSED:
g2d.setColor(Color.decode("#D3D4D3"));
g2d.fillRect(0, 0, width, height);

g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.decode("#D3D4D3"));
g2d.drawRect(1, 1, width - 2, height - 2);
break;
}
}
private void installProperties() {
// ButtonEmpty
if (MetroUIComponent.getPropertyButtonEmpty(button.getName())) {
button.setBackground(null);
button.setBorder(null);
}
// ButtonLink
else if (MetroUIComponent.getPropertyButtonLink(button.getName())) {
button.setBackground(null);
button.setBorder(null);

}
// Estilo personalizado para los botones del componente Spinner
else if (button.getName() != null && (button.getName().equals(UISpinner.BUTTON_NAME_PREVIOUS) || button.getName().equals(UISpinner.BUTTON_NAME_NEXT))) {
installButtonStylesSpinner();
}
// ButtonNormal
else
installButtonStyles();

Expand Down
44 changes: 27 additions & 17 deletions src/icm/sphynx/ui/components/metro/UIComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
* @author israel-icm
*/
public class UIComboBox extends BasicComboBoxUI {
private final String _colorBackground = StyleColorsMetro.COLOR_BACKGROUND_COMBOBOX;
private final String _colorBorder = StyleColorsMetro.COLOR_BORDER_COMBOBOX;
private final String _colorText = "#000000";
private final String _colorTextSelection = "#000000";
private String COLOR_BACKGROUND = StyleColorsMetro.COMBOBOX_COLOR_BACKGROUND;
private String COLOR_BORDER = StyleColorsMetro.COMBOBOX_COLOR_BORDER;
private String COLOR_FOREGROUND = StyleColorsMetro.COMBOBOX_COLOR_FOREGROUND;
private final String _colorIconButton = "#838383";

public static final String BUTTON_NAME = "ButtonComboboxMetroUI";

private static final int STATE_DEFAULT = 1;
Expand All @@ -51,28 +51,37 @@ public static ComponentUI createUI(JComponent c) {
@Override
public void paint(Graphics g, JComponent c) {
super.paint(g, c);
installColors();
installEvents();
installBackground();
installBorder();
installSize();
}

private void installColors() {
if (MetroUIConfigTheme.isDarkMode()) {
COLOR_BACKGROUND = StyleColorsMetro.COMBOBOX_COLOR_BACKGROUND_DARK;
COLOR_FOREGROUND = StyleColorsMetro.COMBOBOX_COLOR_FOREGROUND_DARK;
COLOR_BORDER = StyleColorsMetro.COMBOBOX_COLOR_BORDER_DARK;
}
}

private void installSize() {
// if (comboBox.getHeight() <= 26)
comboBox.setPreferredSize(new Dimension(comboBox.getWidth(), 28));
// c.setBorder(BorderFactory.createCompoundBorder(c.getBorder(), BorderFactory.createEmptyBorder(UITools.PADDING_CONTENTS, UITools.PADDING_CONTENTS, UITools.PADDING_CONTENTS, UITools.PADDING_CONTENTS)));
}

private void installBackground() {
comboBox.setBackground(Color.decode(_colorBackground));
comboBox.setForeground(Color.decode(_colorText));
comboBox.setBackground(Color.decode(COLOR_BACKGROUND));
comboBox.setForeground(Color.decode(COLOR_FOREGROUND));
}

private void installBorder() {
if (currentStateTextField == STATE_DEFAULT)
comboBox.setBorder(new LineBorder(Color.decode(_colorBorder), 2));
comboBox.setBorder(new LineBorder(Color.decode(COLOR_BORDER), 2));
else
comboBox.setBorder(new LineBorder(Color.decode(UITools.bajarBrillo(_colorBorder)), 2));
comboBox.setBorder(new LineBorder(Color.decode(UITools.bajarBrillo(COLOR_BORDER)), 2));
}

private void installEvents() {
Expand Down Expand Up @@ -107,11 +116,11 @@ protected JButton createArrowButton() {
button.setName(BUTTON_NAME); // Se le asigna un nombre para aplicar la propiedad empty del botón
MetroUIComponent.setButtonEmpty(button.getName());
button.setText("");
button.setBorder(BorderFactory.createLineBorder(Color.decode(_colorBackground), 0));
button.setBorder(BorderFactory.createLineBorder(Color.decode(COLOR_BACKGROUND), 0));
button.setContentAreaFilled(false);
button.setIcon(createCbxImage(20, 20));
button.setFocusable(false);
button.setBackground(Color.decode(_colorBackground));
button.setBackground(Color.decode(COLOR_BACKGROUND));
return button;
}

Expand Down Expand Up @@ -194,7 +203,8 @@ private Point getPopupLocation() {
}
};

popupCombobox.setBorder(new MetroUIBorderShadow(Color.decode("#D8D8D8"), 10));
if (!MetroUIConfigTheme.isDarkMode())
popupCombobox.setBorder(new MetroUIBorderShadow(Color.decode("#D8D8D8"), 10));
popupCombobox.getAccessibleContext().setAccessibleParent(comboBox);

return popupCombobox;
Expand All @@ -203,7 +213,7 @@ private Point getPopupLocation() {
@Override
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus){
// Establecemos los estilos para el item seleccionado con el combobox cerrado (La primera vez)
g.setColor(Color.decode(_colorBackground));
g.setColor(Color.decode(COLOR_BACKGROUND));
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
}

Expand All @@ -214,20 +224,20 @@ protected ListCellRenderer createRenderer(){
public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

list.setSelectionBackground(Color.decode(_colorBackground)); // Este color es del item seleccionado después de la primera apertura
list.setSelectionForeground(Color.decode(_colorText));
list.setSelectionBackground(Color.decode(COLOR_BACKGROUND)); // Este color es del item seleccionado después de la primera apertura
list.setSelectionForeground(Color.decode(COLOR_FOREGROUND));

if (comboBox.getSelectedIndex() == index) { // Si el item esta seleccionado
setBackground(MetroUIConfigTheme.getThirdColor());
setForeground(Color.decode(_colorTextSelection));
setForeground(Color.decode(COLOR_FOREGROUND));
}
else if (isSelected && comboBox.getSelectedIndex() != index) { // Si el item no esta seleccionado pero el cursor esta encima
setBackground(Color.decode("#CCCCCC"));
setForeground(Color.decode(_colorTextSelection));
setForeground(Color.decode(COLOR_FOREGROUND));
}
if (isSelected && comboBox.getSelectedIndex() == index) { // Si el item esta seleccionado y el cursor esta encima
setBackground(MetroUIConfigTheme.getFourthColor());
setForeground(Color.decode(_colorTextSelection));
setForeground(Color.decode(COLOR_FOREGROUND));
}
else if (!isSelected && comboBox.getSelectedIndex() != index) { // Si el item no esta seleccionado
setBackground(Color.decode("#F3F3F3"));
Expand Down
61 changes: 61 additions & 0 deletions src/icm/sphynx/ui/components/metro/UISpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import icm.sphynx.ui.tools.IconsMetroUI;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JTextArea;
Expand All @@ -21,6 +25,9 @@
* @author israel-icm
*/
public class UISpinner extends BasicSpinnerUI {
public static final String BUTTON_NAME_PREVIOUS = "ButtonSpinnerPreviousMetroUI";
public static final String BUTTON_NAME_NEXT = "ButtonSpinnerNextMetroUI";

public static ComponentUI createUI(JComponent c) {
return new UISpinner();
}
Expand Down Expand Up @@ -63,4 +70,58 @@ protected JComponent createEditor() {
a.setBackground(Color.decode("#E0E0E0"));*/
return super.createEditor();
}

@Override
protected Component createPreviousButton() {
JButton btnPrevious = new JButton();
btnPrevious.setName(BUTTON_NAME_PREVIOUS); // Se le asigna un nombre específico para poder estilzarlo desde la clase UIButton
btnPrevious.setIcon(createPreviousImage(20, 20));
installPreviousButtonListeners(btnPrevious);
return btnPrevious;
// return super.createPreviousButton(); //If this UI is added to a non CustomJSpinner, then return default implementation.
}

@Override
protected Component createNextButton() {
JButton btnNext = new JButton();
btnNext.setName(BUTTON_NAME_NEXT); // Se le asigna un nombre específico para poder estilzarlo desde la clase UIButton
btnNext.setIcon(createNextImage(20, 20));
installNextButtonListeners(btnNext);
return btnNext;
// return super.createNextButton(); //If this UI is added to a non CustomJSpinner, then return default implementation.
}

private ImageIcon createPreviousImage(int width, int height) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D)image.getGraphics();

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

int yIniFin = (height / 2) - 2;
int yPuntoMedio = (height / 2) + 3;
int xPuntoMedio = width / 2;

g2d.setColor(Color.decode("#838383"));
g2d.setStroke(new BasicStroke(1));
g2d.drawLine(5, yIniFin, xPuntoMedio, yPuntoMedio);
g2d.drawLine(xPuntoMedio, yPuntoMedio, width - 5, yIniFin);
return new ImageIcon(image);
}

private ImageIcon createNextImage(int width, int height) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D)image.getGraphics();

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

int yIniFin = (height / 2) + 2;
int yPuntoMedio = 7;
int xPuntoMedio = width / 2;

g2d.setColor(Color.decode("#838383"));
g2d.setStroke(new BasicStroke(1));
g2d.drawLine(5, yIniFin, xPuntoMedio, yPuntoMedio);
g2d.drawLine(xPuntoMedio, yPuntoMedio, width - 5, yIniFin);
return new ImageIcon(image);
}
}
64 changes: 60 additions & 4 deletions src/icm/sphynx/ui/components/metro/UISplitPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JComponent;
import javax.swing.border.LineBorder;
import javax.swing.plaf.ComponentUI;
Expand All @@ -12,19 +14,46 @@
* @author israel-icm
*/
public class UISplitPane extends BasicSplitPaneUI {
private static final int STATE_DEFAULT = 1;
private static final int STATE_OVER = 2;
private static final int STATE_PRESSED = 3;
private int currentStateDivider = 1; // Controla los estados del textfield

private boolean componenteIniciado = false;

public static ComponentUI createUI(JComponent b) {
return new UISplitPane();
}

@Override
public void paint(Graphics g, JComponent jc) {
splitPane.setBackground(Color.decode("#404141"));
splitPane.setDividerSize(5);
installBackground();
if (!componenteIniciado) {
installEvents();
componenteIniciado = true;
}
}

private void installBackground() {
splitPane.setDividerSize(4);
switch (currentStateDivider) {
case STATE_DEFAULT:
splitPane.setBackground(MetroUIConfigTheme.getSecondColor());
break;
case STATE_OVER:
splitPane.setBackground(Color.decode("#404141"));
break;
case STATE_PRESSED:
splitPane.setBackground(Color.decode("#404141"));
break;
}
}

private void installBorder() {
splitPane.setBorder(new LineBorder(Color.decode(UITools.COLOR_BORDER_DEFAULT), 0));
divider.setBorder(new LineBorder(Color.decode(UITools.COLOR_BORDER_DEFAULT), 0));
// System.out.println("ver " + splitPane.getDividerLocation());
// divider.set
}

@Override
protected void dragDividerTo(int location) {
// esto es para que se agranden los paneles al realizar el drag
Expand All @@ -36,4 +65,31 @@ protected void startDragging() {
// Este método no tiene nada porque su función es mostrar esa sombra que se queda cuando se arrastra el divider
// Sobreescribiendola ya no muestra nada
}

private void installEvents() {
divider.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) { }

@Override
public void mousePressed(MouseEvent e) {
currentStateDivider = STATE_PRESSED;
}

@Override
public void mouseReleased(MouseEvent e) {
currentStateDivider = STATE_DEFAULT;
}

@Override
public void mouseEntered(MouseEvent e) {
currentStateDivider = STATE_OVER;
}

@Override
public void mouseExited(MouseEvent e) {
currentStateDivider = STATE_DEFAULT;
}
});
}
}
Loading

0 comments on commit 03e6d19

Please sign in to comment.