Code was formatted
This commit is contained in:
parent
8823b7d856
commit
824f6fb702
@ -10,11 +10,8 @@ import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
@ -31,6 +28,7 @@ public class AnalogClock extends JPanel {
|
||||
private boolean coloured = false;
|
||||
private boolean mouseOver = false;
|
||||
private int side;
|
||||
private final Color[] colors = Utils.getRandomColors();
|
||||
|
||||
public AnalogClock() {
|
||||
setPreferredSize(new Dimension(400, 300));
|
||||
@ -65,7 +63,7 @@ public class AnalogClock extends JPanel {
|
||||
mouseOver = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -76,6 +74,34 @@ public class AnalogClock extends JPanel {
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static Color modifyColourALittleBit(Color colorIn) {
|
||||
int r = colorIn.getRed();
|
||||
int g = colorIn.getGreen();
|
||||
int b = colorIn.getBlue();
|
||||
Color color = new Color(
|
||||
modifyByteALittleBit(r),
|
||||
modifyByteALittleBit(g),
|
||||
modifyByteALittleBit(b)
|
||||
);
|
||||
return color;
|
||||
}
|
||||
|
||||
private static int modifyByteALittleBit(int n) {
|
||||
// if(Math.random() <= 0.75) {
|
||||
// return n;
|
||||
// }
|
||||
boolean negative = Math.random() > 0.5;
|
||||
int result = n + ((negative ? (-1) : 1)) * ((int) (Math.random() * (
|
||||
Math.random() * 20)));
|
||||
if (result > 255) {
|
||||
return 255;
|
||||
}
|
||||
if (result < 0) {
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
@ -96,19 +122,24 @@ public class AnalogClock extends JPanel {
|
||||
drawClockFace(g2d, centerX, centerY, side / 2 - 40);
|
||||
|
||||
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED);
|
||||
drawHand(g2d, (side / 2 - 10) / 4, (second > 30 ? second - 30 : second + 30) / 60.0, 0.5f, Color.RED);
|
||||
drawHand(g2d, (side / 2 - 10) / 4,
|
||||
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
|
||||
Color.RED);
|
||||
//
|
||||
double minutes = minute / 60.0 + second / 60.0 / 60.0;
|
||||
drawHand(g2d, side / 2 - 20, minutes, 2.0f,
|
||||
Color.BLUE);
|
||||
drawHand(g2d, (side / 2 - 20)/4, minutes + minutes > 0.5 ?minutes - 0.5 : minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f,
|
||||
drawHand(g2d, (side / 2 - 20) / 4,
|
||||
minutes + minutes > 0.5 ? minutes - 0.5 :
|
||||
minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f,
|
||||
Color.BLUE);
|
||||
//
|
||||
double hours = hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12;
|
||||
drawHand(g2d, side / 2 - 40,
|
||||
hours, 4.0f,
|
||||
Color.BLACK);
|
||||
drawHand(g2d, (side / 2 - 40)/4, hours + hours > 0.5 ?hours - 0.5 : hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f,
|
||||
drawHand(g2d, (side / 2 - 40) / 4, hours + hours > 0.5 ? hours - 0.5 :
|
||||
hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f,
|
||||
Color.BLACK);
|
||||
|
||||
}
|
||||
@ -120,41 +151,17 @@ 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((Utils.highlighted.get() || mouseOver) ? color : FOREGROUND_COLOR);
|
||||
g2d.setColor((Utils.highlighted.get() || mouseOver) ? color :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setStroke(new BasicStroke(stroke));
|
||||
g2d.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
|
||||
}
|
||||
|
||||
private Color[] colors = Utils.getRandomColors();
|
||||
private static Color modifyColourALittleBit(Color colorIn) {
|
||||
int r = colorIn.getRed();
|
||||
int g = colorIn.getGreen();
|
||||
int b = colorIn.getBlue();
|
||||
Color color = new Color(
|
||||
modifyByteALittleBit(r),
|
||||
modifyByteALittleBit(g),
|
||||
modifyByteALittleBit(b)
|
||||
);
|
||||
return color;
|
||||
}
|
||||
private static int modifyByteALittleBit(int n) {
|
||||
// if(Math.random() <= 0.75) {
|
||||
// return n;
|
||||
// }
|
||||
boolean negative = Math.random() > 0.5;
|
||||
int result = n + ((negative ? (-1) : 1)) * ((int)(Math.random() * (Math.random() * 20)));
|
||||
if(result > 255) {
|
||||
return 255;
|
||||
}
|
||||
if(result < 0) {
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private void drawClockFace(Graphics2D g2d, int centerX, int centerY,
|
||||
int radius) {
|
||||
g2d.setStroke(new BasicStroke(2.0f));
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||
FOREGROUND_COLOR);
|
||||
// System.out.println("centerX=" + centerX);
|
||||
// System.out.println("centerY=" + centerY);
|
||||
// System.out.println("radius=" + radius);
|
||||
@ -163,27 +170,29 @@ public class AnalogClock extends JPanel {
|
||||
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
|
||||
// g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8);
|
||||
|
||||
|
||||
// if(highlight && Math.random()>0.9) {colors = getRandomColors();}
|
||||
if(Utils.highlighted.get() && coloured) {
|
||||
for(int i = 0; i<12; i++) {
|
||||
// if(highlight && Math.random()>0.9) {colors = getRandomColors();}
|
||||
if (Utils.highlighted.get() && coloured) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
//if(Math.random() > 0.75) {
|
||||
colors[i] = modifyColourALittleBit(colors[i]);
|
||||
colors[i] = modifyColourALittleBit(colors[i]);
|
||||
//}
|
||||
}
|
||||
}
|
||||
// if(Math.random() > (1 - (1/200))) {
|
||||
// for(int i = 0; i<12; i++) {
|
||||
// colors[i] = i == 11 ? colors[0] :colors[i + 1];
|
||||
// }
|
||||
// }
|
||||
DateFormat formatter2 = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
|
||||
// if(Math.random() > (1 - (1/200))) {
|
||||
// for(int i = 0; i<12; i++) {
|
||||
// colors[i] = i == 11 ? colors[0] :colors[i + 1];
|
||||
// }
|
||||
// }
|
||||
DateFormat formatter2 =
|
||||
new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
|
||||
String now = formatter2.format(new Date());
|
||||
|
||||
if (coloured) {
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setFont(new Font("sans", Font.PLAIN, 12));
|
||||
DateFormat formatter = new SimpleDateFormat("EEEE : yyyy-MM-dd", Locale.ENGLISH);
|
||||
DateFormat formatter =
|
||||
new SimpleDateFormat("EEEE : yyyy-MM-dd", Locale.ENGLISH);
|
||||
g2d.drawString(formatter.format(new Date()), ((int) (side * 0.25)),
|
||||
((int) (side * 0.35)));
|
||||
//
|
||||
@ -202,8 +211,6 @@ public class AnalogClock extends JPanel {
|
||||
g2d.drawString(Integer.toString(i), dx, dy);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -9,14 +9,11 @@ import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
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(253, 130, 130);
|
||||
public static final Color MEDIUM = new Color(255, 204, 153);
|
||||
public static final Color HIGH = new Color(204, 255, 204);
|
||||
@ -25,12 +22,13 @@ public class Battery extends JPanel {
|
||||
public static final Color MEDIUM_HIGHLIGHTED = Color.ORANGE;
|
||||
public static final Color HIGH_HIGHLIGHTED = new Color(158, 227, 158);
|
||||
public static final Color HIGHEST_HIGHLIGHTED = Color.green;
|
||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
NumberFormat formatter3 = new DecimalFormat("#0.000");
|
||||
private int height_ = 0;
|
||||
private double donePercent = 0;
|
||||
private boolean mouseOver = false;
|
||||
|
||||
private int width_;
|
||||
NumberFormat formatter3 = new DecimalFormat("#0.000");
|
||||
|
||||
public Battery() {
|
||||
setPreferredSize(new Dimension(40, 100));
|
||||
@ -72,28 +70,36 @@ public class Battery extends JPanel {
|
||||
public void paintComponent(Graphics g) {
|
||||
if (height_ == 0) {
|
||||
this.height_ = Math.min(getWidth(), getHeight());
|
||||
this.width_= (int)(this.height_* 0.6);
|
||||
this.width_ = (int) (this.height_ * 0.6);
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.YELLOW : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.YELLOW :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
g2d.fillRect(width_/4,1,width_, height_ - 2);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK : Color.LIGHT_GRAY);
|
||||
g2d.drawRect(width_/4 - 1,0,width_+1, height_ + 0);
|
||||
if(Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
||||
MEDIUM_HIGHLIGHTED : (donePercent < 0.9 ? HIGH_HIGHLIGHTED : HIGHEST_HIGHLIGHTED)));
|
||||
g2d.fillRect(width_ / 4, 1, width_, height_ - 2);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||
Color.LIGHT_GRAY);
|
||||
g2d.drawRect(width_ / 4 - 1, 0, width_ + 1, height_ + 0);
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(
|
||||
donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
||||
MEDIUM_HIGHLIGHTED :
|
||||
(donePercent < 0.9 ? HIGH_HIGHLIGHTED :
|
||||
HIGHEST_HIGHLIGHTED)));
|
||||
} else {
|
||||
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(Utils.highlighted.get() || mouseOver ? Color.BLACK : Color.LIGHT_GRAY);
|
||||
g2d.fillRect(width_ / 4, height_ - (int) (height_ * donePercent),
|
||||
width_, (int) (height_ * donePercent));
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||
Color.LIGHT_GRAY);
|
||||
g2d.drawString(
|
||||
formatter3.format(donePercent * 100) + "%",((int)(width_ * 0.4)), height_ / 2);
|
||||
formatter3.format(donePercent * 100) + "%",
|
||||
((int) (width_ * 0.4)), height_ / 2);
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,15 @@ package rvc.timecalc;
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -21,16 +21,18 @@ public class HttpProxy {
|
||||
public HttpProxy(File proxyTxt) {
|
||||
try {
|
||||
String[] str = Utils.readTextFromFile(proxyTxt).split(":");
|
||||
if(str.length < 4) {
|
||||
if (str.length < 4) {
|
||||
proxyTxt.delete();
|
||||
throw new IOException("Invalid content of proxy.txt: str.length < 4");
|
||||
throw new IOException(
|
||||
"Invalid content of proxy.txt: str.length < 4");
|
||||
}
|
||||
this.url = str[0];
|
||||
this.port = str[1];
|
||||
this.user = str[2];
|
||||
this.password = str[3];
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Sorry, reading file proxy.txt failed. " + e.getMessage());
|
||||
throw new RuntimeException(
|
||||
"Sorry, reading file proxy.txt failed. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,18 +4,16 @@ import javax.swing.JPanel;
|
||||
import javax.swing.Timer;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
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 ProgressCircle extends JPanel {
|
||||
|
||||
private static final Color FOREGROUND_COLOR = new Color(220,220,220);
|
||||
private static final Color FOREGROUND_COLOR2 = new Color(210,210,210);
|
||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||
private static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
|
||||
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
private int side = 0;
|
||||
private double donePercent = 0;
|
||||
@ -64,24 +62,27 @@ public class ProgressCircle extends JPanel {
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.darkGray : FOREGROUND_COLOR);
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.darkGray :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// if (highlight) {
|
||||
// g2d.setColor(Color.BLUE);
|
||||
// }
|
||||
// if (highlight) {
|
||||
// g2d.setColor(Color.BLUE);
|
||||
// }
|
||||
|
||||
double angleDouble = donePercent * 360;
|
||||
// System.out.println("angleDouble=" + angleDouble);
|
||||
// System.out.println("angleDouble=" + angleDouble);
|
||||
////
|
||||
|
||||
double angleDouble2 = (angleDouble - (int)(angleDouble)) * 360;
|
||||
// System.out.println("remainingAngle=" + angleDouble2);
|
||||
double angleDouble2 = (angleDouble - (int) (angleDouble)) * 360;
|
||||
// System.out.println("remainingAngle=" + angleDouble2);
|
||||
|
||||
g2d.fillArc(0,0,side,side,90, -(int) angleDouble);
|
||||
int side2 = ((int)(side/2));
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? new Color(105, 175, 236) : FOREGROUND_COLOR2);
|
||||
g2d.fillArc(0+(side2/2),0+(side2/2),side2, side2,90, -(int) angleDouble2);
|
||||
g2d.fillArc(0, 0, side, side, 90, -(int) angleDouble);
|
||||
int side2 = side / 2;
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ?
|
||||
new Color(105, 175, 236) : FOREGROUND_COLOR2);
|
||||
g2d.fillArc(0 + (side2 / 2), 0 + (side2 / 2), side2, side2, 90,
|
||||
-(int) angleDouble2);
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,6 @@ import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ProgressSquare extends JPanel {
|
||||
|
||||
@ -78,42 +77,50 @@ public class ProgressSquare extends JPanel {
|
||||
// System.out.println("x=" + x);
|
||||
// System.out.println("y=" + y);
|
||||
if (y > 1) {
|
||||
if(Utils.highlighted.get() || mouseOver) g2d.setColor(Color.GRAY);
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
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(Utils.highlighted.get() || mouseOver) g2d.setColor(Color.GRAY);
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(Color.GRAY);
|
||||
}
|
||||
g2d.drawRect(1, y, x - 1, 1);
|
||||
}
|
||||
if(Utils.highlighted.get() || mouseOver) g2d.setColor(Color.GRAY);
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(Color.GRAY);
|
||||
}
|
||||
g2d.fillRect(side - 4, 1, 4, 4);
|
||||
g2d.fillRect(1, 1, 4, 4);
|
||||
|
||||
if(Utils.highlighted.get() || mouseOver) g2d.setColor(Color.GRAY);
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
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(Utils.highlighted.get() || mouseOver) {
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(Color.BLUE);
|
||||
g2d.drawLine(x - 10, y - 10, x + 10, y + 10);
|
||||
g2d.drawLine(x + 10, y - 10, x - 10, y + 10);
|
||||
}
|
||||
g2d.setColor(FOREGROUND_COLOR);
|
||||
}
|
||||
// int nextX = (int) (Math.random() * 200);
|
||||
// int nextY = (int) (Math.random() * (yOrig- 1));
|
||||
// for(int i = 0;i< yOrig / 8;i++) {
|
||||
// g2d.setColor(Color.GRAY/*Utils.getRandomColor()*/);
|
||||
// g2d.drawLine(x, y, nextX, nextY);
|
||||
// x = nextX;
|
||||
// y = nextY;
|
||||
// nextX = (int) (Math.random() * 200);
|
||||
// nextY = (int) (Math.random() * (yOrig - 1));
|
||||
// }
|
||||
// int nextX = (int) (Math.random() * 200);
|
||||
// int nextY = (int) (Math.random() * (yOrig- 1));
|
||||
// for(int i = 0;i< yOrig / 8;i++) {
|
||||
// g2d.setColor(Color.GRAY/*Utils.getRandomColor()*/);
|
||||
// g2d.drawLine(x, y, nextX, nextY);
|
||||
// x = nextX;
|
||||
// y = nextY;
|
||||
// nextX = (int) (Math.random() * 200);
|
||||
// nextY = (int) (Math.random() * (yOrig - 1));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -49,7 +49,6 @@ import java.awt.Rectangle;
|
||||
* Class to show tosters in multiplatform
|
||||
*
|
||||
* @author daniele piras
|
||||
*
|
||||
*/
|
||||
public class Toaster {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -89,7 +88,6 @@ public class Toaster {
|
||||
* Constructor to initialized toaster component...
|
||||
*
|
||||
* @author daniele piras
|
||||
*
|
||||
*/
|
||||
public Toaster() {
|
||||
// Set default font...
|
||||
@ -102,7 +100,7 @@ public class Toaster {
|
||||
// Verify AlwaysOnTop Flag...
|
||||
try {
|
||||
JWindow.class
|
||||
.getMethod("setAlwaysOnTop", new Class[] {Boolean.class});
|
||||
.getMethod("setAlwaysOnTop", Boolean.class);
|
||||
} catch (Exception e) {
|
||||
useAlwaysOnTop = false;
|
||||
}
|
||||
@ -284,16 +282,15 @@ public class Toaster {
|
||||
* Class that rappresent a single toaster
|
||||
*
|
||||
* @author daniele piras
|
||||
*
|
||||
*/
|
||||
class SingleToaster extends JWindow {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// Label to store Icon
|
||||
private JLabel iconLabel = new JLabel();
|
||||
private final JLabel iconLabel = new JLabel();
|
||||
|
||||
// Text area for the message
|
||||
private JTextArea message = new JTextArea();
|
||||
private final JTextArea message = new JTextArea();
|
||||
|
||||
/***
|
||||
* Simple costructor that initialized components...
|
||||
@ -370,6 +367,7 @@ public class Toaster {
|
||||
/**
|
||||
* Animate vertically the toaster. The toaster could be moved from bottom
|
||||
* to upper or to upper to bottom
|
||||
*
|
||||
* @param posx
|
||||
* @param fromY
|
||||
* @param toY
|
||||
@ -400,7 +398,7 @@ public class Toaster {
|
||||
.getLocalGraphicsEnvironment();
|
||||
Rectangle screenRect = ge.getMaximumWindowBounds();
|
||||
|
||||
int screenHeight = (int) screenRect.height;
|
||||
int screenHeight = screenRect.height;
|
||||
|
||||
int startYPosition;
|
||||
int stopYPosition;
|
||||
@ -411,7 +409,7 @@ public class Toaster {
|
||||
|
||||
maxToasterInSceen = screenHeight / toasterHeight;
|
||||
|
||||
int posx = (int) screenRect.width - toasterWidth - 1;
|
||||
int posx = screenRect.width - toasterWidth - 1;
|
||||
|
||||
toaster.setLocation(posx, screenHeight);
|
||||
toaster.setVisible(true);
|
||||
|
@ -2,10 +2,8 @@ package rvc.timecalc;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@ -14,18 +12,18 @@ import java.nio.file.Files;
|
||||
* @since 15.02.2024
|
||||
*/
|
||||
public class Utils {
|
||||
public static final BooleanHolder highlighted = new BooleanHolder();
|
||||
/**
|
||||
* Count of bytes per one kilobyte.
|
||||
*/
|
||||
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
||||
private Utils() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
|
||||
/**
|
||||
* Count of bytes per one kilobyte.
|
||||
*/
|
||||
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
||||
public static final BooleanHolder highlighted = new BooleanHolder();
|
||||
|
||||
/**
|
||||
* Writes text to a file.
|
||||
*
|
||||
* @param file file
|
||||
* @param text text
|
||||
*/
|
||||
@ -46,26 +44,31 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* Reads text from file.
|
||||
*
|
||||
* @param file file
|
||||
* @return String
|
||||
* @throws IOException thrown, if an error during reading happens
|
||||
*/
|
||||
public static String readTextFromFile(final File file)
|
||||
throws IOException {
|
||||
if(!file.exists()) {
|
||||
if (!file.exists()) {
|
||||
//nothing to do
|
||||
return null;
|
||||
}
|
||||
return new String(Files.readAllBytes(file.toPath()), "UTF-8");
|
||||
return new String(Files.readAllBytes(file.toPath()),
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Color[] getRandomColors() {
|
||||
Color[] result = new Color[12];
|
||||
for(int i = 0; i<12; i++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
result[i] = getRandomColor();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Color getRandomColor() {
|
||||
return new Color(((int)(Math.random() * 256)),((int)(Math.random() * 256)),((int)(Math.random() * 256)));
|
||||
return new Color(((int) (Math.random() * 256)),
|
||||
((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ public class Vtipy {
|
||||
static {
|
||||
try {
|
||||
array = VtipyTxt.getAsArray();
|
||||
Set<String> set =new HashSet<>();
|
||||
for(String vtip:array) {
|
||||
if(vtip.trim().isEmpty()) {
|
||||
Set<String> set = new HashSet<>();
|
||||
for (String vtip : array) {
|
||||
if (vtip.trim().isEmpty()) {
|
||||
//nothing to do
|
||||
continue;
|
||||
}
|
||||
@ -46,23 +46,24 @@ public class Vtipy {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
StringBuilder sb =new StringBuilder();
|
||||
Arrays.stream(array).forEach(l-> {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Arrays.stream(array).forEach(l -> {
|
||||
sb.append(l + "\n -----SEPARATOR-----\n");
|
||||
});
|
||||
JFrame window = new JFrame();
|
||||
window.setSize(1400,1000);
|
||||
window.setSize(1400, 1000);
|
||||
window.setVisible(true);
|
||||
JTextPane text = new JTextPane();
|
||||
text.setBounds(10, 10, 1300, 950);
|
||||
window.add(text);
|
||||
text.setText(sb.toString());
|
||||
}
|
||||
|
||||
public static void showRandom() {
|
||||
Toaster t = new Toaster();
|
||||
t.setToasterWidth(800);
|
||||
t.setToasterHeight(800);
|
||||
t.setDisplayTime(60000*5);
|
||||
t.setDisplayTime(60000 * 5);
|
||||
t.setToasterColor(Color.GRAY);
|
||||
Font font = new Font("sans", Font.PLAIN, 16);
|
||||
t.setToasterMessageFont(font);
|
||||
|
@ -4,6 +4,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
@ -13,15 +14,17 @@ public class VtipyTxt {
|
||||
private VtipyTxt() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
|
||||
public static String[] getAsArray() throws IOException {
|
||||
InputStream inputStream = ClassLoader.getSystemClassLoader().
|
||||
getSystemResourceAsStream("vtipy.txt");
|
||||
InputStreamReader
|
||||
streamReader = new InputStreamReader(inputStream, "UTF-8");
|
||||
streamReader = new InputStreamReader(inputStream,
|
||||
StandardCharsets.UTF_8);
|
||||
BufferedReader in = new BufferedReader(streamReader);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line; (line = in.readLine()) != null;) {
|
||||
for (String line; (line = in.readLine()) != null; ) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
return sb.toString().split("-----SEPARATOR-----");
|
||||
|
@ -15,11 +15,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.Authenticator;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
@ -36,19 +32,19 @@ public class WeatherWindow extends JFrame {
|
||||
scrollPane.setBounds(10, 10, 750, 550);
|
||||
getContentPane().add(scrollPane);
|
||||
|
||||
// File proxyTxt = new File("proxy.txt");
|
||||
// if (!proxyTxt.exists()) {
|
||||
// jep.setText("Sorry, file proxy.txt was not found.");
|
||||
// return;
|
||||
// }
|
||||
// final HttpProxy httpProxy;
|
||||
// try {
|
||||
// httpProxy = new HttpProxy(proxyTxt);
|
||||
// } catch (RuntimeException e) {
|
||||
// jep.setContentType("text/html");
|
||||
// jep.setText(e.getMessage());
|
||||
// return;
|
||||
// }
|
||||
// File proxyTxt = new File("proxy.txt");
|
||||
// if (!proxyTxt.exists()) {
|
||||
// jep.setText("Sorry, file proxy.txt was not found.");
|
||||
// return;
|
||||
// }
|
||||
// final HttpProxy httpProxy;
|
||||
// try {
|
||||
// httpProxy = new HttpProxy(proxyTxt);
|
||||
// } catch (RuntimeException e) {
|
||||
// jep.setContentType("text/html");
|
||||
// jep.setText(e.getMessage());
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
String pocasiHtml = null;
|
||||
@ -59,21 +55,25 @@ public class WeatherWindow extends JFrame {
|
||||
Utils.writeTextToFile(pocasiHtmlFile, pocasiHtml);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
pocasiHtml = pocasiHtmlFile.exists() ? Utils.readTextFromFile(pocasiHtmlFile) : "Sorry, pocasi.html was not found.";
|
||||
pocasiHtml = pocasiHtmlFile.exists() ?
|
||||
Utils.readTextFromFile(pocasiHtmlFile) :
|
||||
"Sorry, pocasi.html was not found.";
|
||||
}
|
||||
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean ogm_detailed_forecast_Started = false;
|
||||
for(String line:pocasiHtml.split("\\r?\\n|\\r")) {
|
||||
for (String line : pocasiHtml.split("\\r?\\n|\\r")) {
|
||||
|
||||
if(line.contains("ogm-detailed-forecast")) {
|
||||
if (line.contains("ogm-detailed-forecast")) {
|
||||
ogm_detailed_forecast_Started = true;
|
||||
}
|
||||
if(ogm_detailed_forecast_Started && line.contains("<button aria-label=")) {
|
||||
if (ogm_detailed_forecast_Started && line
|
||||
.contains("<button aria-label=")) {
|
||||
String l = line
|
||||
.trim()
|
||||
.replace("<button aria-label=\"","").split("class")[0];
|
||||
.replace("<button aria-label=\"", "")
|
||||
.split("class")[0];
|
||||
sb.append(l);
|
||||
sb.append("<br>\n\n");
|
||||
System.out.println("Found another line");
|
||||
@ -83,8 +83,11 @@ public class WeatherWindow extends JFrame {
|
||||
}
|
||||
|
||||
jep.setContentType("text/html");
|
||||
jep.setText("<html><head><meta charset=\"UTF-8\"></head><body>" + pocasiHtml + "</body></html>");
|
||||
Utils.writeTextToFile(new File("aaa"),"<html><head><meta charset=\"UTF-8\"></head><body>" + pocasiHtml + "</body></html>");
|
||||
jep.setText("<html><head><meta charset=\"UTF-8\"></head><body>"
|
||||
+ pocasiHtml + "</body></html>");
|
||||
Utils.writeTextToFile(new File("aaa"),
|
||||
"<html><head><meta charset=\"UTF-8\"></head><body>"
|
||||
+ pocasiHtml + "</body></html>");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jep.setContentType("text/html");
|
||||
@ -92,6 +95,41 @@ public class WeatherWindow extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
private static String prettyFormatXml(final String input,
|
||||
final int indent) {
|
||||
try {
|
||||
Source xmlInput = new StreamSource(new StringReader(input));
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||
TransformerFactory transformerFactory =
|
||||
TransformerFactory.newInstance();
|
||||
|
||||
transformerFactory.setAttribute("indent-number", indent);
|
||||
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.transform(xmlInput, xmlOutput);
|
||||
return xmlOutput.getWriter().toString();
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
Source xmlInput = new StreamSource(new StringReader(input));
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||
TransformerFactory transformerFactory =
|
||||
TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty(
|
||||
"{http://xml.apache.org/xslt}indent-amount",
|
||||
String.valueOf(indent));
|
||||
transformer.transform(xmlInput, xmlOutput);
|
||||
return xmlOutput.getWriter().toString();
|
||||
} catch (Throwable t) {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String downloadFile(String urlString)
|
||||
throws IOException {
|
||||
|
||||
@ -117,34 +155,4 @@ public class WeatherWindow extends JFrame {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String prettyFormatXml(final String input, final int indent) {
|
||||
try {
|
||||
Source xmlInput = new StreamSource(new StringReader(input));
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
|
||||
transformerFactory.setAttribute("indent-number", indent);
|
||||
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.transform(xmlInput, xmlOutput);
|
||||
return xmlOutput.getWriter().toString();
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
Source xmlInput = new StreamSource(new StringReader(input));
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
|
||||
transformer.transform(xmlInput, xmlOutput);
|
||||
return xmlOutput.getWriter().toString();
|
||||
} catch (Throwable t) {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user