Added some improvements

This commit is contained in:
Robert Vokac 2024-03-09 17:57:20 +00:00
parent c611f514e4
commit 2af864e0e3
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
4 changed files with 42 additions and 83 deletions

View File

@ -1,12 +1,7 @@
package org.nanoboot.utils.timecalc.swing.common;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import static org.nanoboot.utils.timecalc.swing.common.Widget.CLOSE_BUTTON_SIDE;
/**
* @author Robert Vokac
@ -25,41 +20,6 @@ public class SwingUtils {
//Not meant to be instantiated.
}
public static void paintCloseIcon(Graphics brush, int width,
boolean mouseOver, boolean mouseOverCloseButton) {
if(!mouseOver) {
//nothing to do
return;
}
if(!mouseOverCloseButton) {
//nothing to do
return;
}
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
// if(!mouseOverCloseButton) {
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
// CLOSE_BUTTON_SIDE);
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1+1, 0 + 1 +1, CLOSE_BUTTON_SIDE - 2,
// CLOSE_BUTTON_SIDE - 2);
// return;
// }
brush.fillOval(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
CLOSE_BUTTON_SIDE);
brush.setColor(Color.LIGHT_GRAY);
Graphics2D brush2d = (Graphics2D) brush;
brush2d.setStroke(new BasicStroke(2f));
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2, 0 + 1 + 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2);
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2, 0 + 1 + 2);
}
public static final Color getColorFromString(String s) {
if (s.isEmpty()) {
System.out.println("error: empty string for color");

View File

@ -1,5 +1,6 @@
package org.nanoboot.utils.timecalc.swing.common;
import java.awt.BasicStroke;
import org.nanoboot.utils.timecalc.app.GetProperty;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Visibility;
@ -52,7 +53,7 @@ public class Widget extends JPanel implements
protected int side = 0;
protected double donePercent = 0;
protected boolean mouseOver = false;
protected boolean mouseOverCloseButton = false;
private boolean mouseOverCloseButton = false;
protected JLabel smileyIcon;
public Widget() {
@ -165,9 +166,44 @@ public class Widget extends JPanel implements
visibility != Visibility.NONE && visibleProperty.isEnabled());
paintWidget(brush);
SwingUtils.paintCloseIcon(brush, getWidth(), mouseOver, mouseOverCloseButton);
paintCloseIcon(brush, getWidth(), mouseOver, mouseOverCloseButton);
}
private static void paintCloseIcon(Graphics brush, int width,
boolean mouseOver, boolean mouseOverCloseButton) {
if(!mouseOver) {
//nothing to do
return;
}
if(!mouseOverCloseButton) {
//nothing to do
return;
}
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
// if(!mouseOverCloseButton) {
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
// CLOSE_BUTTON_SIDE);
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1+1, 0 + 1 +1, CLOSE_BUTTON_SIDE - 2,
// CLOSE_BUTTON_SIDE - 2);
// return;
// }
brush.fillOval(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
CLOSE_BUTTON_SIDE);
brush.setColor(Color.LIGHT_GRAY);
Graphics2D brush2d = (Graphics2D) brush;
brush2d.setStroke(new BasicStroke(2f));
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2, 0 + 1 + 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2);
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2, 0 + 1 + 2);
}
protected void paintWidget(Graphics g) {
}

View File

@ -244,8 +244,6 @@ public class Battery extends Widget {
brush.setFont(currentFont);
}
if (percentProgressVisibleProperty.isEnabled()) {
brush.drawString(
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
@ -327,10 +325,12 @@ public class Battery extends Widget {
this.label = label;
}
@Override
public void setBounds(int x, int y, int height) {
setBounds(x, y, (int) (40d / 100d * ((double) height)), height);
}
@Override
public int getTimerDelay() {
return 25;
}

View File

@ -36,54 +36,17 @@ public class WalkingHumanProgress extends Widget implements
public WalkingHumanProgress() {
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
putClientProperty("mouseEntered", "false");
setFocusable(false);
setForeground(Color.GRAY);
setBackground(MainWindow.BACKGROUND_COLOR);
addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (visibilitySupportedColoredProperty.isDisabled()) {
//nothing to do
return;
}
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
if (visibility.isStronglyColored()) {
visibilityProperty
.setValue(Visibility.WEAKLY_COLORED.name());
} else {
visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
putClientProperty("mouseEntered", "true");
}
@Override
public void mouseExited(MouseEvent e) {
putClientProperty("mouseEntered", "false");
}
});
new Timer(100, e -> {
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
setForeground(
visibility.isStronglyColored()
|| getClientProperty("mouseEntered").equals("true")
|| mouseOver
? Color.BLACK : Color.LIGHT_GRAY);
}).start();