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