New improvements
This commit is contained in:
parent
b1301a1bda
commit
ab8f96a1c9
@ -28,7 +28,6 @@ public class AnalogClock extends JPanel {
|
||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
|
||||
private boolean highlight = false;
|
||||
private boolean coloured = false;
|
||||
private int side;
|
||||
|
||||
@ -40,17 +39,7 @@ public class AnalogClock extends JPanel {
|
||||
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();
|
||||
}
|
||||
Utils.highlighted.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,10 +73,6 @@ public class AnalogClock extends JPanel {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void setHighlight(boolean highlight) {
|
||||
this.highlight = highlight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
@ -122,7 +107,7 @@ public class AnalogClock extends JPanel {
|
||||
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
|
||||
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
|
||||
|
||||
g2d.setColor(highlight ? color : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() ? color : FOREGROUND_COLOR);
|
||||
g2d.setStroke(new BasicStroke(stroke));
|
||||
g2d.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
|
||||
}
|
||||
@ -156,7 +141,7 @@ public class AnalogClock extends JPanel {
|
||||
private void drawClockFace(Graphics2D g2d, int centerX, int centerY,
|
||||
int radius) {
|
||||
g2d.setStroke(new BasicStroke(2.0f));
|
||||
g2d.setColor(highlight ? Color.BLACK : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() ? Color.BLACK : FOREGROUND_COLOR);
|
||||
// System.out.println("centerX=" + centerX);
|
||||
// System.out.println("centerY=" + centerY);
|
||||
// System.out.println("radius=" + radius);
|
||||
@ -167,7 +152,7 @@ public class AnalogClock extends JPanel {
|
||||
|
||||
|
||||
// if(highlight && Math.random()>0.9) {colors = getRandomColors();}
|
||||
if(highlight && coloured) {
|
||||
if(Utils.highlighted.get() && coloured) {
|
||||
for(int i = 0; i<12; i++) {
|
||||
//if(Math.random() > 0.75) {
|
||||
colors[i] = modifyColourALittleBit(colors[i]);
|
||||
@ -184,12 +169,12 @@ public class AnalogClock extends JPanel {
|
||||
int dx = centerX + (int) ((radius + 20) * Math.cos(angle)) - 4;
|
||||
int dy = centerY + (int) ((radius + 20) * Math.sin(angle)) + 4;
|
||||
|
||||
if(highlight && coloured) {g2d.setColor(colors[i - 1]);};
|
||||
if(Utils.highlighted.get() && coloured) {g2d.setColor(colors[i - 1]);};
|
||||
g2d.setFont(new Font("sans", Font.BOLD, 16));
|
||||
g2d.drawString(Integer.toString(i), dx, dy);
|
||||
}
|
||||
if (coloured) {
|
||||
g2d.setColor(highlight ? Color.BLACK : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() ? Color.BLACK : FOREGROUND_COLOR);
|
||||
g2d.setFont(new Font("sans", Font.BOLD, 12));
|
||||
DateFormat formatter = new SimpleDateFormat("EEEE : yyyy-MM-dd", Locale.ENGLISH);
|
||||
g2d.drawString(formatter.format(new Date()), ((int) (side * 0.25)),
|
||||
|
@ -28,24 +28,9 @@ public class Battery extends JPanel {
|
||||
private int height_ = 0;
|
||||
private double donePercent = 0;
|
||||
|
||||
private boolean highlight = false;
|
||||
private int width_;
|
||||
NumberFormat formatter3 = new DecimalFormat("#0.000");
|
||||
|
||||
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);
|
||||
@ -53,17 +38,7 @@ public class Battery extends JPanel {
|
||||
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();
|
||||
}
|
||||
Utils.highlighted.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -94,7 +69,6 @@ public class Battery extends JPanel {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
highlight = Utils.highlightTxt.exists();
|
||||
if (height_ == 0) {
|
||||
this.height_ = Math.min(getWidth(), getHeight());
|
||||
this.width_= (int)(this.height_* 0.6);
|
||||
@ -106,7 +80,7 @@ public class Battery extends JPanel {
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
g2d.fillRect(width_/4,0,width_, height_);
|
||||
if(highlight) {
|
||||
if(Utils.highlighted.get()) {
|
||||
g2d.setColor(donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
||||
MEDIUM_HIGHLIGHTED : (donePercent < 0.9 ? HIGH_HIGHLIGHTED : HIGHEST_HIGHLIGHTED)));
|
||||
} else {
|
||||
@ -114,7 +88,7 @@ public class Battery extends JPanel {
|
||||
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
|
||||
}
|
||||
g2d.fillRect(width_/4,height_ - (int)(height_ * donePercent),width_, (int)(height_ * donePercent));
|
||||
g2d.setColor(highlight ? Color.BLACK : Color.LIGHT_GRAY);
|
||||
g2d.setColor(Utils.highlighted.get() ? Color.BLACK : Color.LIGHT_GRAY);
|
||||
g2d.drawString(
|
||||
formatter3.format(donePercent * 100) + "%",((int)(width_ * 0.4)), height_ / 2);
|
||||
|
||||
|
18
src/main/java/rvc/timecalc/BooleanHolder.java
Normal file
18
src/main/java/rvc/timecalc/BooleanHolder.java
Normal file
@ -0,0 +1,18 @@
|
||||
package rvc.timecalc;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class BooleanHolder {
|
||||
private boolean b;
|
||||
public void set(boolean b) {
|
||||
this.b = b;
|
||||
}
|
||||
public boolean get() {
|
||||
return b;
|
||||
}
|
||||
public void flip() {
|
||||
this.b = !b;
|
||||
}
|
||||
}
|
@ -20,22 +20,6 @@ public class ProgressCircle extends JPanel {
|
||||
private int side = 0;
|
||||
private double donePercent = 0;
|
||||
|
||||
private boolean highlight = false;
|
||||
|
||||
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 ProgressCircle() {
|
||||
setPreferredSize(new Dimension(200, 200));
|
||||
setBackground(BACKGROUND_COLOR);
|
||||
@ -43,17 +27,7 @@ public class ProgressCircle extends JPanel {
|
||||
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();
|
||||
}
|
||||
Utils.highlighted.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,13 +58,12 @@ public class ProgressCircle extends JPanel {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
highlight = Utils.highlightTxt.exists();
|
||||
if (side == 0) {
|
||||
this.side = Math.min(getWidth(), getHeight());
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(highlight ? Color.darkGray : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() ? Color.darkGray : FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// if (highlight) {
|
||||
@ -106,7 +79,7 @@ public class ProgressCircle extends JPanel {
|
||||
|
||||
g2d.fillArc(0,0,side,side,90, -(int) angleDouble);
|
||||
int side2 = ((int)(side/2));
|
||||
g2d.setColor(highlight ? new Color(105, 175, 236) : FOREGROUND_COLOR2);
|
||||
g2d.setColor(Utils.highlighted.get() ? new Color(105, 175, 236) : FOREGROUND_COLOR2);
|
||||
g2d.fillArc(0+(side2/2),0+(side2/2),side2, side2,90, -(int) angleDouble2);
|
||||
}
|
||||
|
||||
|
@ -19,22 +19,6 @@ public class ProgressSquare extends JPanel {
|
||||
private int square;
|
||||
private double donePercent = 0;
|
||||
|
||||
private boolean highlight = false;
|
||||
|
||||
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 ProgressSquare() {
|
||||
setPreferredSize(new Dimension(400, 400));
|
||||
setBackground(BACKGROUND_COLOR);
|
||||
@ -42,17 +26,7 @@ public class ProgressSquare extends JPanel {
|
||||
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();
|
||||
}
|
||||
Utils.highlighted.flip();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,26 +77,26 @@ public class ProgressSquare extends JPanel {
|
||||
// System.out.println("x=" + x);
|
||||
// System.out.println("y=" + y);
|
||||
if (y > 1) {
|
||||
if(highlight) g2d.setColor(Color.GRAY);
|
||||
if(Utils.highlighted.get()) g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(side - 4, side - 4, 4, 4);
|
||||
g2d.fillRect(1, side - 4, 4, 4);
|
||||
|
||||
g2d.setColor(FOREGROUND_COLOR);
|
||||
g2d.fillRect(1, 1, side, y - 1);
|
||||
if (x > 1) {
|
||||
if(highlight) g2d.setColor(Color.GRAY);
|
||||
if(Utils.highlighted.get()) g2d.setColor(Color.GRAY);
|
||||
g2d.drawRect(1, y, x - 1, 1);
|
||||
}
|
||||
if(highlight) g2d.setColor(Color.GRAY);
|
||||
if(Utils.highlighted.get()) g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(side - 4, 1, 4, 4);
|
||||
g2d.fillRect(1, 1, 4, 4);
|
||||
|
||||
if(highlight) g2d.setColor(Color.GRAY);
|
||||
if(Utils.highlighted.get()) g2d.setColor(Color.GRAY);
|
||||
g2d.drawLine(1, 1, x, y);
|
||||
// g2d.drawLine(1+1, 1+1, x+1, y+1);
|
||||
g2d.drawLine(1, 1 + 1, x, y + 1);
|
||||
g2d.drawLine(1, 1 + 1, x, y + 1);
|
||||
if(highlight) {
|
||||
if(Utils.highlighted.get()) {
|
||||
g2d.setColor(Color.BLUE);
|
||||
g2d.drawLine(x - 10, y - 10, x + 10, y + 10);
|
||||
g2d.drawLine(x + 10, y - 10, x - 10, y + 10);
|
||||
|
@ -129,15 +129,6 @@ public class TimeCalcWindow {
|
||||
batteryForWeek.setBounds(battery.getBounds().x + battery.getWidth(), battery.getY(), 90, 140);
|
||||
window.add(batteryForWeek);
|
||||
|
||||
|
||||
|
||||
if(Utils.highlightTxt.exists()) {
|
||||
analogClock.setHighlight(true);
|
||||
progressSquare.setHighlight(true);
|
||||
progressCircle.setHighlight(true);
|
||||
battery.setHighlight(true);
|
||||
batteryForWeek.setHighlight(true);
|
||||
}
|
||||
StringBuilder sb = null;
|
||||
while (true) {
|
||||
if (stopBeforeEnd) {
|
||||
@ -221,8 +212,7 @@ public class TimeCalcWindow {
|
||||
Vtipy.showRandom();
|
||||
}
|
||||
if (hourRemains == 0 && minuteRemains <= 3) {
|
||||
analogClock.setHighlight(true);
|
||||
progressSquare.setHighlight(true);
|
||||
Utils.highlighted.set(true);
|
||||
text.setForeground(Color.BLUE);
|
||||
}
|
||||
|
||||
@ -257,10 +247,8 @@ public class TimeCalcWindow {
|
||||
|
||||
}
|
||||
|
||||
boolean exists = Utils.highlightTxt.exists();
|
||||
analogClock.setHighlight(exists);
|
||||
progressSquare.setHighlight(exists);
|
||||
text.setForeground(exists ? Color.BLACK : Color.GRAY);
|
||||
|
||||
text.setForeground(Utils.highlighted.get() ? Color.BLACK : Color.GRAY);
|
||||
}
|
||||
window.setVisible(false);
|
||||
window.dispose();
|
||||
|
@ -21,7 +21,8 @@ public class Utils {
|
||||
* Count of bytes per one kilobyte.
|
||||
*/
|
||||
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
||||
public static final File highlightTxt = new File("highlight.txt");
|
||||
public static final BooleanHolder highlighted = new BooleanHolder();
|
||||
|
||||
/**
|
||||
* Writes text to a file.
|
||||
* @param file file
|
||||
|
Loading…
x
Reference in New Issue
Block a user