Initial Commit

This commit is contained in:
Ghoti 2019-01-01 20:57:33 -06:00
commit a50c548f71
12 changed files with 519 additions and 0 deletions

7
.classpath Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/libs"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bin/

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ModuleScanner</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

40
DraySlip.txt Normal file
View File

@ -0,0 +1,40 @@
DRAY SLIP -- Example Form
From Example
Tag No. Tag No. Tag No.
---------------------------------------------
1: 1000 35: 1034 69: 1068
2: 1001 36: 1035 70: 1069
3: 1002 37: 1036 71: 1070
4: 1003 38: 1037 72: 1071
5: 1004 39: 1038 73: 1072
6: 1005 40: 1039 74: 1073
7: 1006 41: 1040 75: 1074
8: 1007 42: 1041 76: 1075
9: 1008 43: 1042 77: 1076
10: 1009 44: 1043 78: 1077
11: 1010 45: 1044 79: 1078
12: 1011 46: 1045 80: 1079
13: 1012 47: 1046 81: 1080
14: 1013 48: 1047 82: 1081
15: 1014 49: 1048 83: 1082
16: 1015 50: 1049 84: 1083
17: 1016 51: 1050 85: 1084
18: 1017 52: 1051 86: 1085
19: 1018 53: 1052 87: 1086
20: 1019 54: 1053 88: 1087
21: 1020 55: 1054 89: 1088
22: 1021 56: 1055 90: 1089
23: 1022 57: 1056 91: 1090
24: 1023 58: 1057 92: 1091
25: 1024 59: 1058 93: 1092
26: 1025 60: 1059 94: 1093
27: 1026 61: 1060 95: 1094
28: 1027 62: 1061 96: 1095
29: 1028 63: 1062 97: 1096
30: 1029 64: 1063 98: 1097
31: 1030 65: 1064 99: 1098
32: 1031 66: 1065 100: 1099
33: 1032 67: 1066
34: 1033 68: 1067

View File

@ -0,0 +1,19 @@
package gin.rgv.module;
import gin.rgv.module.scanner.Scan;
public class Main {
private static Scan scan;
public static void main(String[] args){
System.out.println("\nDRAY SLIP GENERATOR v2.0");
System.out.println("------------------------\n");
while(true){
scan = new Scan();
scan.newScan();
scan = null;
}
}
}

View File

@ -0,0 +1,35 @@
package gin.rgv.module.scanner;
import java.util.Scanner;
import gin.rgv.module.util.CharUtil;
public class Input {
@SuppressWarnings("resource")
public String getInput(){
System.out.println("Please scan the barcode on the Module Tag.\n");
String strcode = "";
Scanner input = new Scanner(System.in);
String init = "";
if(input.hasNext()){
init = input.next();
}
System.out.println("\nENTERED: " + init + "\n");
if(!init.isEmpty()){
for(int i = 0; i < init.length() - 1; i++){
if(i != 0){
char ch = init.charAt(i);
strcode += ch;
}
}
}
if(strcode.isEmpty() || CharUtil.hasAlpha(strcode)){
return "error";
}else{
return strcode;
}
}
}

View File

@ -0,0 +1,36 @@
package gin.rgv.module.scanner;
import gin.rgv.module.util.MathUtil;
import gin.rgv.module.write.Write;
public class Scan {
private Input input;
private MathUtil mu;
private Write write;
public void newScan(){
input = new Input();
String strcode = input.getInput();
if(strcode.equals("error")){
System.out.println("\nThis barcode is not valid.\nPlease try again.");
input = null;
mu = null;
write = null;
}else{
int code = Integer.parseInt(strcode);
System.out.println("\nBARCODE " + ((Integer)code).toString() + " ACCEPTED\n\n");
mu = new MathUtil();
mu.getData(code);
write = new Write();
write.writeFile(mu);
System.out.println("\n\n-----------------\n");
input = null;
mu = null;
write = null;
System.out.println("TO PRINT: Click FILE --> PRINT ---> Click the printer with \"ENVY\" in the name --> Set the box in the corner to 2 --> Click PRINT");
}
System.out.println("\n\n-----------------\nRestarting program...\n\n");
}
}

View File

@ -0,0 +1,20 @@
package gin.rgv.module.util;
public class CharUtil {
public static String letters = "abcdefghijklmnop";
public static boolean hasAlpha(String str){
str = str.toLowerCase();
boolean check = false;
for(char c : letters.toCharArray()){
for(char h : str.toCharArray()){
if(h == c){
check = true;
}
}
}
return check;
}
}

View File

@ -0,0 +1,45 @@
package gin.rgv.module.util;
import java.util.ArrayList;
import java.util.List;
public class MathUtil {
public List<String> col1 = new ArrayList<>();
public List<String> col2 = new ArrayList<>();
public List<String> col3 = new ArrayList<>();
public void getData(int code){
for(int count = 0; count < 102; count++){
Integer countplus = count + 1;
String countstr = countplus.toString();
if(count + 1 < 10){
countstr = " " + countstr;
}else if(count + 1 > 9 && count + 1 < 100){
countstr = " " + countstr;
}
String cc = (countstr + ": " + (Integer)(code + count)).toString();
if(count < 34){
col1.add(cc);
}else if(count >= 34 && count < 68){
col2.add(cc);
}else if(count >= 68 && count < 100){
col3.add(cc);
}else if(count >= 100 && count < 102){
col3.add(" ");
}
}
System.out.println("PREVIEW");
System.out.println("-------");
for(int i = 0; i < 34; i++){
System.out.println(col1.get(i) + " " + col2.get(i) + " " + col3.get(i));
}
}
public void clearData(){
col1.clear();
col2.clear();
col3.clear();
}
}

View File

@ -0,0 +1,35 @@
package gin.rgv.module.write;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import gin.rgv.module.util.MathUtil;
import net.mightypork.rpack.utils.DesktopApi;
public class Write {
public void writeFile(MathUtil mu){
try{
File file = new File("DraySlip.txt");
PrintWriter cleaner = new PrintWriter(file);
cleaner.print("");
cleaner.close();
PrintWriter write = new PrintWriter(file);
write.println("DRAY SLIP -- Example Form\n");
write.println("From Example\n");
write.println(" Tag No. Tag No. Tag No.");
write.println("---------------------------------------------");
for(int i = 0; i < 34; i++){
write.println(mu.col1.get(i) + " " + mu.col2.get(i) + " " + mu.col3.get(i));
}
write.close();
mu.clearData();
System.out.println("\nFILE INFO:\n");
DesktopApi.edit(file);
}catch(FileNotFoundException e){
System.out.println("AN ERROR HAS OCCURRED. PLEASE CLOSE AND REOPEN THE PROGRAM TO TRY AGAIN");
}
}
}

View File

@ -0,0 +1,253 @@
package net.mightypork.rpack.utils;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
//AUTHOR MIGHTYPORK
public class DesktopApi {
public static boolean browse(URI uri) {
if (openSystemSpecific(uri.toString())) return true;
if (browseDESKTOP(uri)) return true;
return false;
}
public static boolean open(File file) {
if (openSystemSpecific(file.getPath())) return true;
if (openDESKTOP(file)) return true;
return false;
}
public static boolean edit(File file) {
// you can try something like
// runCommand("gimp", "%s", file.getPath())
// based on user preferences.
if (openSystemSpecific(file.getPath())) return true;
if (editDESKTOP(file)) return true;
return false;
}
private static boolean openSystemSpecific(String what) {
EnumOS os = getOs();
if (os.isLinux()) {
//if (runCommand("kde-open", "%s", what)) return true;
if (runCommand("gnome-open", "%s", what)) return true;
if (runCommand("xdg-open", "%s", what)) return true;
}
if (os.isMac()) {
if (runCommand("open", "%s", what)) return true;
}
if (os.isWindows()) {
if (runCommand("explorer", "%s", what)) return true;
}
return false;
}
private static boolean browseDESKTOP(URI uri) {
logOut("Trying to use Desktop.getDesktop().browse() with " + uri.toString());
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
logErr("BROWSE is not supported.");
return false;
}
Desktop.getDesktop().browse(uri);
return true;
} catch (Throwable t) {
logErr("Error using desktop browse.", t);
return false;
}
}
private static boolean openDESKTOP(File file) {
logOut("Trying to use Desktop.getDesktop().open() with " + file.toString());
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
logErr("OPEN is not supported.");
return false;
}
Desktop.getDesktop().open(file);
return true;
} catch (Throwable t) {
logErr("Error using desktop open.", t);
return false;
}
}
private static boolean editDESKTOP(File file) {
logOut("Trying to use Desktop.getDesktop().edit() with " + file);
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) {
logErr("EDIT is not supported.");
return false;
}
Desktop.getDesktop().edit(file);
return true;
} catch (Throwable t) {
logErr("Error using desktop edit.", t);
return false;
}
}
private static boolean runCommand(String command, String args, String file) {
logOut("Trying to exec:\n cmd = " + command + "\n args = " + args + "\n %s = " + file);
String[] parts = prepareCommand(command, args, file);
try {
Process p = Runtime.getRuntime().exec(parts);
if (p == null) return false;
try {
int retval = p.exitValue();
if (retval == 0) {
logErr("Process ended immediately.");
return false;
} else {
logErr("Process crashed.");
return false;
}
} catch (IllegalThreadStateException itse) {
logErr("Process is running.");
return true;
}
} catch (IOException e) {
logErr("Error running command.", e);
return false;
}
}
private static String[] prepareCommand(String command, String args, String file) {
List<String> parts = new ArrayList<String>();
parts.add(command);
if (args != null) {
for (String s : args.split(" ")) {
s = String.format(s, file); // put in the filename thing
parts.add(s.trim());
}
}
return parts.toArray(new String[parts.size()]);
}
private static void logErr(String msg, Throwable t) {
System.err.println(msg);
t.printStackTrace();
}
private static void logErr(String msg) {
System.err.println(msg);
}
private static void logOut(String msg) {
System.out.println(msg);
}
public static enum EnumOS {
linux, macos, solaris, unknown, windows;
public boolean isLinux() {
return this == linux || this == solaris;
}
public boolean isMac() {
return this == macos;
}
public boolean isWindows() {
return this == windows;
}
}
public static EnumOS getOs() {
String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
return EnumOS.windows;
}
if (s.contains("mac")) {
return EnumOS.macos;
}
if (s.contains("solaris")) {
return EnumOS.solaris;
}
if (s.contains("sunos")) {
return EnumOS.solaris;
}
if (s.contains("linux")) {
return EnumOS.linux;
}
if (s.contains("unix")) {
return EnumOS.linux;
} else {
return EnumOS.unknown;
}
}
}