2023-04-02 22:30:52 +02:00

208 lines
6.4 KiB
Java

package at.fos.ermodel.gui;
import javafx.scene.Node;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import java.io.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
public class T3 {
public static HashMap<String, ArrayList<String>> randomData = new HashMap<>();
public static String[] dsfsdfsdf4353534 = new String[]{
"No",
"Extern",
"Random Integer",
"Random Decimal",
"Random Text",
"Random Date",
"Random Boolean",
"Random Color",
"Random Company",
"Random Country",
"Random Departmentname",
"Random Firstname",
"Random Jobname",
"Random Language",
"Random Lastname",
"Random Mediacategory",
"Random Mediapublisher",
"Random Mediatitle",
"Random Mediatype",
"Random Place",
"Random Profession",
"Random Rentalequipment",
"Random Street"};
public static Object copyObject(Graphic_Main_Elem objSource) {
Object objDest = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(objSource);
oos.flush();
oos.close();
bos.close();
byte[] byteData = bos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(byteData);
try {
objDest = (new ObjectInputStream(bais)).readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return objDest;
}
public static void asdasda345435ertretr(Node node, double yScale, double xScale, double contrast, double hue, double brightness, double saturation) {
ImageView iv = (ImageView) node;
iv.setScaleY(yScale);
iv.setScaleX(xScale);
ColorAdjust colorAdjust = new ColorAdjust();
colorAdjust.setContrast(contrast);
colorAdjust.setHue(hue);
colorAdjust.setBrightness(brightness);
colorAdjust.setSaturation(saturation);
iv.setEffect(colorAdjust);
}
public static void buttonMouseExited(Node node) {
ImageView iv = (ImageView) node;
iv.setScaleX(1.0D);
iv.setScaleY(1.0D);
iv.setEffect(null);
}
public static void fdssdf4354(Node node, Color color) {
DropShadow borderGlow = new DropShadow();
borderGlow.setOffsetY(0.0D);
borderGlow.setOffsetX(0.0D);
borderGlow.setColor(color);
borderGlow.setWidth(10.0D);
borderGlow.setHeight(10.0D);
node.setEffect(borderGlow);
}
public static String replaceSpecialChars(String text) {
text = text.replaceAll("ä", "ae");
text = text.replaceAll("ö", "oe");
text = text.replaceAll("ü", "ue");
text = text.replaceAll("ß", "ss");
text = text.replaceAll("[^\\w\\_]", "");
return text;
}
public static String getRandomDouble(double valuesVon, double valuesBis) {
return String.valueOf(valuesVon + (new Random()).nextDouble(valuesBis - valuesVon) + 1);
}
public static String getRandomInteger(int valuesVon, int valuesBis) {
return getRandomDouble(valuesVon, valuesBis);
}
public static String getRandomBoolean() {
return getRandomInteger(0,1);
}
public static String getRandomDecimal(int digitsBeforeComma, int digitsAfterComma) {
return getRandomDouble(0,Math.pow(10,digitsBeforeComma)-1) + "." + getRandomDouble(0,Math.pow(10,digitsAfterComma)-1);
}
public static String getRandomTextGivenLength(int textLength) {
String str = "abcdefghijklmnopqrstuvwxyz";
StringBuilder randomText = new StringBuilder();
for (int j = 0; j < textLength; j++) {
randomText.append(str.charAt((new Random()).nextInt(26)));
}
return randomText.toString();
}
public static String getRandomDate(LocalDate from, LocalDate till) {
Random random = new Random();
int minDay = (int) LocalDate.of(from.getYear(), from.getMonth(), from.getDayOfMonth()).toEpochDay();
int maxDay = (int) LocalDate.of(till.getYear(), till.getMonth(), till.getDayOfMonth()).toEpochDay();
long randomDay = (minDay + random.nextInt(maxDay - minDay));
LocalDate randomDate = LocalDate.ofEpochDay(randomDay);
String datesAsString;
datesAsString = randomDate.getYear() + "-" + randomDate.getMonthValue() + "-" + randomDate.getDayOfMonth();
return datesAsString;
}
public static void readRandomData(String which, String keyExtern) {
ArrayList<String> randomDataAsList;
try {
BufferedReader fr;
if (which.equals("Extern")) {
fr = C2.randomDataFilesExtern.get(keyExtern);
} else {
fr = new BufferedReader(new InputStreamReader(C2.randomDataFiles.get(which)));
}
randomDataAsList = new ArrayList<>();
String next = fr.readLine();
while (next != null) {
randomDataAsList.add(next);
next = fr.readLine();
}
fr.close();
if (which.equals("Extern")) {
randomData.put(keyExtern, randomDataAsList);
} else {
randomData.put(which, randomDataAsList);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getRandomData(String which, String keyExtern) {
ArrayList<String> randomDataAsList;
if (which.equals("Extern")) {
randomDataAsList = randomData.get(keyExtern);
} else {
randomDataAsList = randomData.get(which);
}
if (randomDataAsList == null) {
readRandomData(which, keyExtern);
}
if (which.equals("Extern")) {
randomDataAsList = randomData.get(keyExtern);
} else {
randomDataAsList = randomData.get(which);
}
return randomDataAsList.get((new Random()).nextInt(randomDataAsList.size()));
}
}