2024-01-21 13:04:48 +00:00
|
|
|
package rvc.timecalc;
|
|
|
|
|
2024-01-27 16:07:27 +00:00
|
|
|
import java.awt.Color;
|
2024-01-21 13:04:48 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Robert
|
|
|
|
* @since 15.02.2024
|
|
|
|
*/
|
|
|
|
public class Utils {
|
2024-01-27 23:41:48 +00:00
|
|
|
public static final BooleanHolder highlighted = new BooleanHolder();
|
2024-01-28 15:48:24 +00:00
|
|
|
public static final BooleanHolder ultraLight = new BooleanHolder();
|
|
|
|
public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216);
|
2024-01-21 13:04:48 +00:00
|
|
|
/**
|
|
|
|
* Count of bytes per one kilobyte.
|
|
|
|
*/
|
|
|
|
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
2024-01-27 23:41:48 +00:00
|
|
|
private Utils() {
|
|
|
|
//Not meant to be instantiated.
|
|
|
|
}
|
2024-01-27 19:40:45 +00:00
|
|
|
|
2024-01-21 13:04:48 +00:00
|
|
|
/**
|
|
|
|
* Writes text to a file.
|
2024-01-27 23:41:48 +00:00
|
|
|
*
|
2024-01-21 13:04:48 +00:00
|
|
|
* @param file file
|
|
|
|
* @param text text
|
|
|
|
*/
|
|
|
|
public static void writeTextToFile(final File file, final String text) {
|
|
|
|
FileOutputStream outputStream;
|
|
|
|
try {
|
|
|
|
outputStream = new FileOutputStream(file.getAbsolutePath());
|
|
|
|
byte[] strToBytes = text.getBytes();
|
|
|
|
outputStream.write(strToBytes);
|
|
|
|
|
|
|
|
outputStream.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.err.println(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads text from file.
|
2024-01-27 23:41:48 +00:00
|
|
|
*
|
2024-01-21 13:04:48 +00:00
|
|
|
* @param file file
|
|
|
|
* @return String
|
|
|
|
* @throws IOException thrown, if an error during reading happens
|
|
|
|
*/
|
|
|
|
public static String readTextFromFile(final File file)
|
|
|
|
throws IOException {
|
2024-01-27 23:41:48 +00:00
|
|
|
if (!file.exists()) {
|
2024-01-27 13:15:48 +00:00
|
|
|
//nothing to do
|
|
|
|
return null;
|
|
|
|
}
|
2024-01-27 23:41:48 +00:00
|
|
|
return new String(Files.readAllBytes(file.toPath()),
|
|
|
|
StandardCharsets.UTF_8);
|
2024-01-21 13:04:48 +00:00
|
|
|
}
|
2024-01-27 23:41:48 +00:00
|
|
|
|
2024-01-27 16:07:27 +00:00
|
|
|
public static Color[] getRandomColors() {
|
|
|
|
Color[] result = new Color[12];
|
2024-01-27 23:41:48 +00:00
|
|
|
for (int i = 0; i < 12; i++) {
|
2024-01-27 16:07:27 +00:00
|
|
|
result[i] = getRandomColor();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2024-01-27 23:41:48 +00:00
|
|
|
|
2024-01-27 16:07:27 +00:00
|
|
|
public static Color getRandomColor() {
|
2024-01-27 23:41:48 +00:00
|
|
|
return new Color(((int) (Math.random() * 256)),
|
|
|
|
((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
|
2024-01-27 16:07:27 +00:00
|
|
|
}
|
2024-01-21 13:04:48 +00:00
|
|
|
}
|