mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
patch24
This commit is contained in:
parent
f28ca92503
commit
e56d7cf00c
@ -1,5 +1,6 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.common;
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||||
import org.nanoboot.utils.timecalc.entity.Progress;
|
import org.nanoboot.utils.timecalc.entity.Progress;
|
||||||
@ -38,7 +39,7 @@ import java.util.function.Consumer;
|
|||||||
public class Widget extends JPanel implements
|
public class Widget extends JPanel implements
|
||||||
GetProperty {
|
GetProperty {
|
||||||
|
|
||||||
private static final int CLOSE_BUTTON_SIDE = 25;
|
private static final int CLOSE_OR_MINIMIZE_BUTTON_SIDE = 25;
|
||||||
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||||
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
|
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
|
||||||
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
@ -49,8 +50,11 @@ public class Widget extends JPanel implements
|
|||||||
protected static final String LEGS = " /\\ ";
|
protected static final String LEGS = " /\\ ";
|
||||||
public static final Color CLOSE_BUTTON_FOREGROUND_COLOR
|
public static final Color CLOSE_BUTTON_FOREGROUND_COLOR
|
||||||
= new Color(127, 127, 127);
|
= new Color(127, 127, 127);
|
||||||
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = Color.LIGHT_GRAY;
|
public static final Color CLOSE_OR_MINIMIZE_BUTTON_BACKGROUND_COLOR = Color.LIGHT_GRAY;
|
||||||
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON = new Color(255, 153, 153);
|
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON = new Color(255, 153, 153);
|
||||||
|
public static final Color MINIMIZE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON = new Color(
|
||||||
|
126, 179, 227);
|
||||||
|
private static final Color VERY_LIGHT_GRAY = new Color(220, 220, 220);
|
||||||
public final BooleanProperty visibilitySupportedColoredProperty
|
public final BooleanProperty visibilitySupportedColoredProperty
|
||||||
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
||||||
public final BooleanProperty visibleProperty
|
public final BooleanProperty visibleProperty
|
||||||
@ -72,12 +76,16 @@ public class Widget extends JPanel implements
|
|||||||
protected Progress progress = null;
|
protected Progress progress = null;
|
||||||
protected boolean mouseOver = false;
|
protected boolean mouseOver = false;
|
||||||
private boolean mouseOverCloseButton = false;
|
private boolean mouseOverCloseButton = false;
|
||||||
|
private boolean mouseOverMinimizeButton = false;
|
||||||
protected JLabel smileyIcon;
|
protected JLabel smileyIcon;
|
||||||
protected JLabel smileyIcon2;
|
protected JLabel smileyIcon2;
|
||||||
private long lastUpdate = System.nanoTime();
|
private long lastUpdate = System.nanoTime();
|
||||||
private static final Color PURPLE_STRONGLY_COLORED = new Color(153,51,255);
|
private static final Color PURPLE_STRONGLY_COLORED = new Color(153,51,255);
|
||||||
private static final Color PURPLE_WEAKLY_COLORED = new Color(204,153,255);
|
private static final Color PURPLE_WEAKLY_COLORED = new Color(204,153,255);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private boolean hidden;
|
||||||
|
|
||||||
private WidgetMenu widgetMenu = null;
|
private WidgetMenu widgetMenu = null;
|
||||||
public Widget() {
|
public Widget() {
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
@ -93,35 +101,36 @@ public class Widget extends JPanel implements
|
|||||||
|
|
||||||
int x = e.getX();
|
int x = e.getX();
|
||||||
int y = e.getY();
|
int y = e.getY();
|
||||||
mouseOverCloseButton = x >= getWidth() - CLOSE_BUTTON_SIDE
|
mouseOverCloseButton = x >= getWidth() - CLOSE_OR_MINIMIZE_BUTTON_SIDE
|
||||||
&& y <= CLOSE_BUTTON_SIDE;
|
&& y <= CLOSE_OR_MINIMIZE_BUTTON_SIDE;
|
||||||
|
mouseOverMinimizeButton = x < getWidth() - CLOSE_OR_MINIMIZE_BUTTON_SIDE
|
||||||
|
&& x > getWidth() - 2 * CLOSE_OR_MINIMIZE_BUTTON_SIDE
|
||||||
|
&& y <= CLOSE_OR_MINIMIZE_BUTTON_SIDE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addMouseListener(new MouseListener() {
|
addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if(hidden) {
|
||||||
|
hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (mouseOverCloseButton) {
|
if (mouseOverCloseButton) {
|
||||||
visibleProperty.setValue(false);
|
visibleProperty.setValue(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mouseOverMinimizeButton) {
|
||||||
|
hidden = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (visibilitySupportedColoredProperty.isDisabled()) {
|
if (visibilitySupportedColoredProperty.isDisabled()) {
|
||||||
//nothing to do
|
//nothing to do
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if (visibleProperty.isEnabled()) {
|
|
||||||
// Visibility visibility
|
|
||||||
// = Visibility.valueOf(visibilityProperty.getValue());
|
|
||||||
// if (visibility.isStronglyColored()) {
|
|
||||||
// visibilityProperty
|
|
||||||
// .setValue(Visibility.WEAKLY_COLORED.name());
|
|
||||||
// } else {
|
|
||||||
// visibilityProperty
|
|
||||||
// .setValue(Visibility.STRONGLY_COLORED.name());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -227,20 +236,29 @@ public class Widget extends JPanel implements
|
|||||||
@Override
|
@Override
|
||||||
public final void paintComponent(Graphics brush) {
|
public final void paintComponent(Graphics brush) {
|
||||||
super.paintComponent(brush);
|
super.paintComponent(brush);
|
||||||
|
|
||||||
setVisible(visibleProperty.isEnabled());
|
setVisible(visibleProperty.isEnabled());
|
||||||
|
Visibility visibility
|
||||||
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
|
|
||||||
if (visibleProperty.isDisabled()) {
|
if (visibleProperty.isDisabled() || hidden) {
|
||||||
|
if(hidden) {
|
||||||
|
if (mouseOver) {
|
||||||
|
Color currentColor = brush.getColor();
|
||||||
|
brush.setColor(VERY_LIGHT_GRAY);
|
||||||
|
brush.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
|
||||||
|
brush.setColor(currentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
//nothing to do
|
//nothing to do
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Visibility visibility
|
|
||||||
= Visibility.valueOf(visibilityProperty.getValue());
|
|
||||||
super.setVisible(
|
super.setVisible(
|
||||||
visibility != Visibility.NONE && visibleProperty.isEnabled());
|
visibility != Visibility.NONE && visibleProperty.isEnabled());
|
||||||
paintWidget(brush);
|
paintWidget(brush);
|
||||||
|
|
||||||
paintCloseIcon(brush, getWidth(), mouseOver, mouseOverCloseButton);
|
paintCloseIcon(brush, getWidth(), mouseOver, mouseOverCloseButton);
|
||||||
|
paintMinimizeIcon(brush, getWidth(), mouseOver, mouseOverMinimizeButton);
|
||||||
|
|
||||||
if (mouseOver) {
|
if (mouseOver) {
|
||||||
Color currentColor = brush.getColor();
|
Color currentColor = brush.getColor();
|
||||||
@ -264,7 +282,8 @@ public class Widget extends JPanel implements
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
brush.setColor(mouseOverCloseButton ? CLOSE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON : CLOSE_BUTTON_BACKGROUND_COLOR);
|
brush.setColor(mouseOverCloseButton ? CLOSE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON :
|
||||||
|
CLOSE_OR_MINIMIZE_BUTTON_BACKGROUND_COLOR);
|
||||||
|
|
||||||
// if(!mouseOverCloseButton) {
|
// if(!mouseOverCloseButton) {
|
||||||
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
|
// brush.drawRect(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
|
||||||
@ -273,18 +292,45 @@ public class Widget extends JPanel implements
|
|||||||
// CLOSE_BUTTON_SIDE - 2);
|
// CLOSE_BUTTON_SIDE - 2);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
brush.fillOval(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
|
brush.fillOval(width - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1, 0 + 1,
|
||||||
CLOSE_BUTTON_SIDE);
|
CLOSE_OR_MINIMIZE_BUTTON_SIDE,
|
||||||
|
CLOSE_OR_MINIMIZE_BUTTON_SIDE);
|
||||||
brush.setColor(CLOSE_BUTTON_FOREGROUND_COLOR);
|
brush.setColor(CLOSE_BUTTON_FOREGROUND_COLOR);
|
||||||
Graphics2D brush2d = (Graphics2D) brush;
|
Graphics2D brush2d = (Graphics2D) brush;
|
||||||
brush2d.setStroke(new BasicStroke(2f));
|
brush2d.setStroke(new BasicStroke(2f));
|
||||||
int offset = 6;
|
int offset = 6;
|
||||||
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + offset, 0 + 1 + offset,
|
brush.drawLine(width - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 + offset, 0 + 1 + offset,
|
||||||
width - 0 * CLOSE_BUTTON_SIDE - 1 - offset,
|
width - 0 * CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 - offset,
|
||||||
0 + CLOSE_BUTTON_SIDE + 1 - offset);
|
0 + CLOSE_OR_MINIMIZE_BUTTON_SIDE + 1 - offset);
|
||||||
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + offset,
|
brush.drawLine(width - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 + offset,
|
||||||
0 + CLOSE_BUTTON_SIDE + 1 - offset,
|
0 + CLOSE_OR_MINIMIZE_BUTTON_SIDE + 1 - offset,
|
||||||
width - 0 * CLOSE_BUTTON_SIDE - 1 - offset, 0 + 1 + offset);
|
width - 0 * CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 - offset, 0 + 1 + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void paintMinimizeIcon(Graphics brush, int width,
|
||||||
|
boolean mouseOver, boolean mouseOverMinimizeButton) {
|
||||||
|
|
||||||
|
if (!mouseOver) {
|
||||||
|
//nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
brush.setColor(mouseOverMinimizeButton ? MINIMIZE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON :
|
||||||
|
CLOSE_OR_MINIMIZE_BUTTON_BACKGROUND_COLOR);
|
||||||
|
|
||||||
|
brush.fillOval(width - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1, 0 + 1,
|
||||||
|
CLOSE_OR_MINIMIZE_BUTTON_SIDE,
|
||||||
|
CLOSE_OR_MINIMIZE_BUTTON_SIDE);
|
||||||
|
brush.setColor(CLOSE_BUTTON_FOREGROUND_COLOR);
|
||||||
|
Graphics2D brush2d = (Graphics2D) brush;
|
||||||
|
brush2d.setStroke(new BasicStroke(2f));
|
||||||
|
int offset = 6;
|
||||||
|
int y = ((int)(0 + 1 + CLOSE_OR_MINIMIZE_BUTTON_SIDE / 2d)) + 2;
|
||||||
|
brush.drawLine(width - CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 - CLOSE_OR_MINIMIZE_BUTTON_SIDE
|
||||||
|
- 1 + offset, y,
|
||||||
|
width - 0 * CLOSE_OR_MINIMIZE_BUTTON_SIDE - 1 - offset - CLOSE_OR_MINIMIZE_BUTTON_SIDE
|
||||||
|
- 1,
|
||||||
|
y);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintWidget(Graphics g) {
|
protected void paintWidget(Graphics g) {
|
||||||
@ -478,4 +524,8 @@ public class Widget extends JPanel implements
|
|||||||
//brush.setBackground(currentBackgroundColor);
|
//brush.setBackground(currentBackgroundColor);
|
||||||
brush.setFont(currentFont);
|
brush.setFont(currentFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideWidget() {
|
||||||
|
this.hidden = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,12 @@ public class WidgetMenu extends JPopupMenu {
|
|||||||
//if(!aClass.getSimpleName().contains("Battery")) {
|
//if(!aClass.getSimpleName().contains("Battery")) {
|
||||||
add(typeMenuItem);
|
add(typeMenuItem);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
JMenuItem hideMenuItem = new JMenuItem("Hide");
|
||||||
|
add(hideMenuItem);
|
||||||
|
hideMenuItem.addActionListener(e -> {
|
||||||
|
this.widget.hideWidget();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public void markAsSelected(WidgetType widgetType) {
|
public void markAsSelected(WidgetType widgetType) {
|
||||||
this.typeMinuteMenuItem.setText(WidgetType.MINUTE.name());
|
this.typeMinuteMenuItem.setText(WidgetType.MINUTE.name());
|
||||||
|
@ -58,6 +58,10 @@ public class ProgressMoney extends Widget implements GetProperty {
|
|||||||
//nothing to do
|
//nothing to do
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
if(progress == null) {
|
||||||
|
//nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
double workDaysInMonth = progress.getWorkDaysInMonth();
|
double workDaysInMonth = progress.getWorkDaysInMonth();
|
||||||
boolean isWeekend = progress.isWeekend();
|
boolean isWeekend = progress.isWeekend();
|
||||||
double perDay = perMonth / workDaysInMonth;
|
double perDay = perMonth / workDaysInMonth;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user