This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NoahJelen
committed
Jan 23, 2018
0 parents
commit 2e57856
Showing
16 changed files
with
887 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry exported="true" kind="lib" path="/home/nethernoah/Desktop/Sleep Timer/Sleep Timer/json-simple-1.1.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Sleep Timer</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package sleepTimer; | ||
|
||
import java.io.FileWriter; | ||
|
||
import javax.swing.JComponent; | ||
import javax.swing.JLabel; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JTextField; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
public class CFGWindow { | ||
@SuppressWarnings({ "unchecked", "resource" }) | ||
public static void Config() { | ||
System.out.println("You are running "+System.getProperty("os.name")); | ||
JTextField shdHour = new JTextField(); | ||
JTextField shdMinute = new JTextField(); | ||
JTextField rmdHour = new JTextField(); | ||
JTextField rmdMinute = new JTextField(); | ||
final JComponent[] inputs = new JComponent[] { | ||
new JLabel("Shut Down Hour"), | ||
shdHour, | ||
new JLabel("Shut Down Minute"), | ||
shdMinute, | ||
new JLabel("Reminder Hour"), | ||
rmdHour, | ||
new JLabel("Reminder Minute"), | ||
rmdMinute, | ||
new JLabel("Version 1.0") | ||
}; | ||
int result = JOptionPane.showConfirmDialog(null, inputs, "Configuration", JOptionPane.PLAIN_MESSAGE); | ||
if (result == JOptionPane.OK_OPTION) { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("shutdownhr", Long.parseLong(shdHour.getText())); | ||
jsonObject.put("shutdownmin", Long.parseLong(shdMinute.getText())); | ||
jsonObject.put("remindhr", Long.parseLong(rmdHour.getText())); | ||
jsonObject.put("remindmin", Long.parseLong(rmdMinute.getText())); | ||
try { | ||
FileWriter fileWriter = new FileWriter("config.json"); | ||
fileWriter.write(jsonObject.toJSONString()); | ||
fileWriter.flush(); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sleepTimer; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
|
||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
public class ConfigLoad { | ||
@SuppressWarnings("unchecked") | ||
public static long[] readJson(String file) { | ||
JSONParser parser = new JSONParser(); | ||
long[] options = {0,0,0,0}; | ||
|
||
try { | ||
FileReader fileReader = new FileReader(file); | ||
JSONObject json = (JSONObject) parser.parse(fileReader); | ||
|
||
long shutdownhr = (long) json.get("shutdownhr"); | ||
long shutdownmin = (long) json.get("shutdownmin"); | ||
long remindhr = (long) json.get("remindhr"); | ||
long remindmin = (long) json.get("remindmin"); | ||
|
||
options[0] =shutdownhr; | ||
options[1]=shutdownmin; | ||
options[2]=remindhr; | ||
options[3]=remindmin; | ||
return options; | ||
} | ||
catch (Exception ex) { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("shutdownhr", 23); | ||
jsonObject.put("shutdownmin", 0); | ||
jsonObject.put("remindhr", 22); | ||
jsonObject.put("remindmin", 50); | ||
options[0] =23; | ||
options[1]=0; | ||
options[2]=22; | ||
options[3]=50; | ||
try { | ||
@SuppressWarnings("resource") | ||
FileWriter fileWriter = new FileWriter("config.json"); | ||
fileWriter.write(jsonObject.toJSONString()); | ||
fileWriter.flush(); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package sleepTimer; | ||
|
||
public class Init { | ||
public static void main(String[] args) { | ||
try { | ||
if (args[0].equals("config")||args[0].equals("c")||args[0].equals("cfg")){ | ||
CFGWindow.Config(); | ||
return; | ||
} | ||
} | ||
catch (Exception e){} | ||
PCQuit.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package sleepTimer; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
|
||
import javax.swing.JOptionPane; | ||
|
||
public class PCQuit{ | ||
@SuppressWarnings("deprecation") | ||
public static void run() { | ||
Date today= new Date(); | ||
long[] options=ConfigLoad.readJson("resources/config.json"); | ||
String quitHr=Long.toString(options[0]); | ||
String quitMin=Long.toString(options[1]); | ||
|
||
boolean sawWarning=false; | ||
|
||
if (options[0]<10) | ||
quitHr="0"+quitHr; | ||
|
||
if (options[1]<10) | ||
quitMin="0"+quitMin; | ||
while (true) { | ||
if (today.getMinutes()==options[3]&&today.getHours()==options[2]&&!sawWarning) { | ||
JOptionPane.showMessageDialog(null,"You need to go to bed!\nThis machine will automatically shut down at "+quitHr+":"+quitMin,"Bed Time!",JOptionPane.WARNING_MESSAGE); | ||
System.exit(0); | ||
sawWarning=true; | ||
} | ||
if (today.getMinutes()==options[1]&&today.getMinutes()==options[0]) { | ||
try { | ||
shutDown.shutdown(); | ||
} | ||
catch (RuntimeException|IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sleepTimer; | ||
|
||
import java.io.IOException; | ||
|
||
public class shutDown { | ||
public static void shutdown() throws RuntimeException, IOException { | ||
String shutdownCommand; | ||
String operatingSystem = System.getProperty("os.name"); | ||
|
||
if ("Linux".equals(operatingSystem) || "Mac OS X".equals(operatingSystem)) { | ||
shutdownCommand = "shutdown -h now"; | ||
} | ||
|
||
else if ("Windows".equals(operatingSystem)||"ReactOS".equals(operatingSystem)) { | ||
shutdownCommand = "shutdown.exe -s -t 0"; | ||
} | ||
|
||
else { | ||
throw new RuntimeException("Unsupported operating system."); | ||
} | ||
|
||
Runtime.getRuntime().exec(shutdownCommand); | ||
System.exit(0); | ||
} | ||
} |