New improvements
This commit is contained in:
parent
e87c0177fe
commit
ff5e9d4ccb
@ -1 +1 @@
|
||||
0:00
|
||||
0:09
|
110
src/main/java/rvc/timecalc/Battery.java
Normal file
110
src/main/java/rvc/timecalc/Battery.java
Normal file
@ -0,0 +1,110 @@
|
||||
package rvc.timecalc;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Battery extends JPanel {
|
||||
|
||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
public static final Color LOW = new Color(255, 102, 102);
|
||||
public static final Color MEDIUM = new Color(255, 204, 153);
|
||||
public static final Color HIGH = new Color(204, 255, 204);
|
||||
public static final Color HIGHEST = new Color(153, 255, 153);
|
||||
private int height_ = 0;
|
||||
private int square;
|
||||
private double donePercent = 0;
|
||||
|
||||
private boolean highlight = false;
|
||||
private int width_;
|
||||
|
||||
public void setHighlight(boolean highlight) {
|
||||
this.highlight = highlight;
|
||||
if(highlight && !Utils.highlightTxt.exists()) {
|
||||
try {
|
||||
Utils.highlightTxt.createNewFile();
|
||||
} catch (IOException ioException) {
|
||||
System.out.println(ioException);
|
||||
}
|
||||
}
|
||||
if(!highlight && Utils.highlightTxt.exists()) {
|
||||
Utils.highlightTxt.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public Battery() {
|
||||
setPreferredSize(new Dimension(40, 100));
|
||||
setBackground(BACKGROUND_COLOR);
|
||||
new Timer(1000, e -> repaint()).start();
|
||||
addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
highlight = !highlight;
|
||||
if(highlight && !Utils.highlightTxt.exists()) {
|
||||
try {
|
||||
Utils.highlightTxt.createNewFile();
|
||||
} catch (IOException ioException) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
if(!highlight && Utils.highlightTxt.exists()) {
|
||||
Utils.highlightTxt.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setDonePercent(double donePercent) {
|
||||
this.donePercent = donePercent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
if (height_ == 0) {
|
||||
this.height_ = Math.min(getWidth(), getHeight());
|
||||
this.width_= (int)(this.height_* 0.6);
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
g2d.fillRect(width_/4,0,width_, height_);
|
||||
g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ?
|
||||
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
|
||||
g2d.fillRect(width_/4,height_ - (int)(height_ * donePercent),width_, (int)(height_ * donePercent));
|
||||
g2d.setColor(Color.LIGHT_GRAY);
|
||||
g2d.drawString(String.valueOf((int)(donePercent * 100)) + "%",width_/2, height_/2);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -122,11 +122,17 @@ public class TimeCalcWindow {
|
||||
.setBounds(10 + progressSquare.getBounds().x + progressSquare.getWidth() + 10, 10, 80, 80);
|
||||
window.add(progressCircle);
|
||||
|
||||
Battery battery = new Battery();
|
||||
battery.setBounds(progressCircle.getBounds().x, progressCircle.getY() + 10 + progressCircle.getHeight(), 90, 140);
|
||||
window.add(battery);
|
||||
|
||||
|
||||
|
||||
if(Utils.highlightTxt.exists()) {
|
||||
analogClock.setHighlight(true);
|
||||
progressSquare.setHighlight(true);
|
||||
progressCircle.setHighlight(true);
|
||||
battery.setHighlight(true);
|
||||
}
|
||||
StringBuilder sb = null;
|
||||
while (true) {
|
||||
@ -183,6 +189,7 @@ public class TimeCalcWindow {
|
||||
/ ((double) totalMilliseconds);
|
||||
progressSquare.setDonePercent(done);
|
||||
progressCircle.setDonePercent(done);
|
||||
battery.setDonePercent(done);
|
||||
|
||||
int totalSecondsRemains = (hourRemains * 60 * 60 + minuteRemains * 60 + secondsRemains);
|
||||
int totalMillisecondsRemains = totalSecondsRemains * 1000 + millisecondsRemains;
|
||||
@ -273,12 +280,12 @@ public class TimeCalcWindow {
|
||||
if (!alreadyShownPercents.contains((int) (percent * 100))) {
|
||||
alreadyShownPercents.add((int) (percent * 100));
|
||||
Toaster toasterManager = new Toaster();
|
||||
Font font = new Font("sans", Font.BOLD, 32);
|
||||
Font font = new Font("sans", Font.PLAIN, 16);
|
||||
toasterManager.setToasterMessageFont(font);
|
||||
toasterManager.setDisplayTime(10000);
|
||||
toasterManager.setToasterWidth(600);
|
||||
toasterManager.setToasterHeight(400);
|
||||
toasterManager.setToasterColor(new Color(255,255,102));
|
||||
toasterManager.setToasterColor(new Color(255,255,204));
|
||||
Base64.Decoder base64Decoder = Base64.getDecoder();
|
||||
|
||||
byte[] btDataFile = base64Decoder
|
||||
|
@ -1 +1 @@
|
||||
7:00
|
||||
6:39
|
Loading…
x
Reference in New Issue
Block a user