diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..feca861 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..659bf43 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..213e9f6 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..4c8540a --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b79914a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index fdddb29..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,24 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to diff --git a/README.md b/README.md deleted file mode 100644 index 6cfb2fb..0000000 --- a/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

TaskTimer

-

- - - - - -

- -

An accurate timer utility for running tasks/commands on the given interval Hours, Minutes, Seconds.

- -

- Owner & Author: Hudaifa Abdullah
-

- -# Gitrting Started -Task Timer is a Java project uses a ```jdk-16.0.2```, and ```Gradle``` Bulide, along with ```JavaFX 16``` for it's Interface - -it can send a Command to CMD on the end of a given time interval e.g. Shutdown the Computer - - -## Coming Fetures -* Enter a custom command -* Multi-Langague support -* new themes - - -## Usage - -## How it works - diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/HuimangTech/App.java b/src/main/java/HuimangTech/App.java new file mode 100644 index 0000000..68642d5 --- /dev/null +++ b/src/main/java/HuimangTech/App.java @@ -0,0 +1,73 @@ +package HuimangTech; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import java.io.IOException; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @Authour 7odaifa_ab + */ +public class App extends Application { + + private static Scene scene; + public static Stage primaryStage = null; + + @Override + public void start(Stage stage) throws IOException { + scene = new Scene(loadFXML("MainUI")); + stage.setScene(scene); + stage.initStyle(StageStyle.UNDECORATED); + stage.show(); + primaryStage = stage; + makeStageDraggable(); + } + + static void setRoot(String fxml) throws IOException { + scene.setRoot(loadFXML(fxml)); + } + + private static Parent loadFXML(String fxml) throws IOException { + ResourceBundle bundle = ResourceBundle.getBundle("resources.bundles.TaskTimer", new Locale("en","US")); + FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("/resources/" + fxml + ".fxml"), bundle); + return fxmlLoader.load(); + } + + private void makeStageDraggable() { + AtomicReference xOffset = new AtomicReference<>((double) 0); + AtomicReference yOffset = new AtomicReference<>((double) 0); + + scene.setOnMousePressed(event -> { + xOffset.set(event.getSceneX()); + yOffset.set(event.getSceneY()); + }); + scene.setOnMouseDragged(event -> { + App.primaryStage.setX(event.getScreenX() - xOffset.get()); + App.primaryStage.setY(event.getScreenY() - yOffset.get()); + }); + scene.setOnDragDone((e) -> App.primaryStage.setOpacity(1.0f)); + scene.setOnMouseDragReleased((e) -> { + if (e.isConsumed()) { + App.primaryStage.setOpacity(1.0f); + } + }); + } + + + static public void runCMDCommand(String command) throws IOException { + ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command); + builder.redirectErrorStream(true); + builder.start(); + } + + public static void main(String[] args) { + launch(); + } + +} diff --git a/src/main/java/HuimangTech/MainUIController.java b/src/main/java/HuimangTech/MainUIController.java new file mode 100644 index 0000000..6046d5d --- /dev/null +++ b/src/main/java/HuimangTech/MainUIController.java @@ -0,0 +1,61 @@ +package HuimangTech; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +public class MainUIController implements Initializable { + + public MainUIController() { + } + + + public static String getTaskName() { + return TaskName; + } + + + static String TaskName = ""; + + @FXML + void CLOSE_APP() { + App.primaryStage.close(); + System.exit(0); + } + + @FXML + void MINIMIZE_APP() { + App.primaryStage.setIconified(true); + } + + @FXML + void switchToShutdown() throws IOException { + TaskName = "ShutDown"; + App.setRoot("Timer"); + } + + @FXML + void switchToRestart() throws IOException { + TaskName = "Restart"; + App.setRoot("Timer"); + } + + @FXML + void switchToHibernate() throws IOException { + TaskName = "Hibernate"; + App.setRoot("Timer"); + } + + @FXML + void switchToSleep() throws IOException { + TaskName = "Sleep"; + App.setRoot("Timer"); + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + + } +} diff --git a/src/main/java/HuimangTech/TimerController.java b/src/main/java/HuimangTech/TimerController.java new file mode 100644 index 0000000..ca3dfc9 --- /dev/null +++ b/src/main/java/HuimangTech/TimerController.java @@ -0,0 +1,235 @@ +package HuimangTech; + +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.Timeline; +import javafx.beans.binding.Bindings; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.value.ChangeListener; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.util.Duration; +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; +import com.jfoenix.controls.JFXButton; + + +public class TimerController implements Initializable { + + private String command; + private String extraCommand; + private int STARTTIME = 0; + private Timeline timeline; + private final IntegerProperty timeSeconds = new SimpleIntegerProperty(STARTTIME); + ChangeListener listener = ((observable, oldValue, newValue) -> ResetTimer()); + + + @FXML + private JFXButton StartBtn; + @FXML + private JFXButton pauseBtn; + @FXML + private JFXButton resetBtn; + @FXML + private TextField HoursTxtField; + @FXML + private TextField MinTxtField; + @FXML + private TextField SecTxtField; + @FXML + private Label taskLbl; + + @FXML + void StartBtn() { + if (timeline != null) { + checkTimerStatus(); + return; + } + StartTimer(); + StartBtn.setVisible(false); + resetBtn.setVisible(true); + pauseBtn.setVisible(true); + bindTimeToTextField(); + runCMDCommand(); + + } + + @FXML + void resetBtn() throws IOException { + ResetTimer(); + App.setRoot("Timer"); + } + + @FXML + void CLOSE_APP() { + App.primaryStage.close(); + System.exit(0); + } + + @FXML + void BACK() throws IOException { + App.setRoot("MainUI"); + } + + @FXML + void MINIMIZE_APP() { + App.primaryStage.setIconified(true); + } + + void checkTimerStatus() { + if (timeline.getStatus().toString().equals("RUNNING")) { + timeline.pause(); + pauseBtn.setText("Start"); + unBindTimeToTextField(); + RestoreStyleClass(); + + } else if (timeline.getStatus().toString().equals("PAUSED")) { + bindTimeToTextField(); + addStyleClass(); + timeline.play(); + pauseBtn.setText("Pause"); + } + } + + private Integer TimerTimeInSeconds() { + int HoursToSec = 0; + int MinToSec = 0; + int SecToSec = 0; + + if (!HoursTxtField.getText().isEmpty()) + HoursToSec = (Integer.parseInt(HoursTxtField.getText()) * 60 * 60); + if (!MinTxtField.getText().isEmpty()) + MinToSec = (Integer.parseInt(MinTxtField.getText()) * 60); + if (!SecTxtField.getText().isEmpty()) + SecToSec = Integer.parseInt(SecTxtField.getText()); + + // System.out.println(HoursTxtField.getText()); + //System.out.println(MinTxtField.getText()); + //System.out.println(SecTxtField.getText()); + + HoursTxtField.setEditable(false); + MinTxtField.setEditable(false); + SecTxtField.setEditable(false); + + return HoursToSec + MinToSec + SecToSec; + } + + void StartTimer() { + STARTTIME = TimerTimeInSeconds(); + + timeSeconds.set(STARTTIME); + timeline = new Timeline(); + timeline.getKeyFrames().add( + new KeyFrame(Duration.seconds(STARTTIME + 1), + new KeyValue(timeSeconds, 0))); + timeline.playFromStart(); + + } + + void runCMDCommand() { + + timeline.setOnFinished(event1 -> { + try { + App.setRoot("Timer"); + if (MainUIController.getTaskName().equals("Sleep") || MainUIController.getTaskName().equals("Hibernate")) { + App.runCMDCommand(extraCommand); + } + App.runCMDCommand(command); + CLOSE_APP(); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + + void ResetTimer() { + timeline = null; + } + + void bindTimeToTextField() { + removeChangeListener(); + addStyleClass(); + + // Bind the Timer TextFields text property to the timeSeconds property + HoursTxtField.textProperty().bind(timeSeconds.divide(3600).asString()); + MinTxtField.textProperty().bind(timeSeconds.divide(60).subtract(timeSeconds.divide(3600).multiply(60)).asString()); + SecTxtField.textProperty().bind(timeSeconds.subtract(timeSeconds.divide(60).multiply(60)).asString()); + } + + void unBindTimeToTextField() { + // Bind the Timer TextFields text property to the timeSeconds property + HoursTxtField.textProperty().unbind(); + MinTxtField.textProperty().unbind(); + SecTxtField.textProperty().unbind(); + + HoursTxtField.setEditable(true); + MinTxtField.setEditable(true); + SecTxtField.setEditable(true); + + addChangeListener(); + } + + void addChangeListener() { + HoursTxtField.textProperty().addListener(listener); + MinTxtField.textProperty().addListener(listener); + SecTxtField.textProperty().addListener(listener); + } + + void addStyleClass() { + + HoursTxtField.getStyleClass().add("profileText-field"); + MinTxtField.getStyleClass().add("profileText-field"); + SecTxtField.getStyleClass().add("profileText-field"); + + } + + void RestoreStyleClass() { + HoursTxtField.getStyleClass().clear(); + MinTxtField.getStyleClass().clear(); + SecTxtField.getStyleClass().clear(); + + HoursTxtField.getStyleClass().add("accountText-field"); + MinTxtField.getStyleClass().add("accountText-field"); + SecTxtField.getStyleClass().add("accountText-field"); + } + + void removeChangeListener() { + HoursTxtField.textProperty().removeListener(listener); + MinTxtField.textProperty().removeListener(listener); + SecTxtField.textProperty().removeListener(listener); + } + + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + StartBtn.disableProperty().bind(Bindings.isEmpty(HoursTxtField.textProperty()) + .and(Bindings.isEmpty(MinTxtField.textProperty())) + .and(Bindings.isEmpty(SecTxtField.textProperty()))); + + + switch (MainUIController.getTaskName()) { + case "ShutDown" -> { + taskLbl.setText(resourceBundle.getString("tskShutDownLbl")); + command = "start shutdown /s"; + } + case "Restart" -> { + taskLbl.setText(resourceBundle.getString("tskRestartLbl")); + command = "start shutdown /r"; + } + case "Hibernate" -> { + taskLbl.setText(resourceBundle.getString("tskHibernateLbl")); + extraCommand = "powercfg -h on"; + command = "start shutdown /h"; + } + case "Sleep" -> { + taskLbl.setText(resourceBundle.getString("tskSleepLbl")); + extraCommand = "powercfg -h off"; + command = "rundll32.exe powrprof.dll, SetSuspendState Sleep"; + } + } + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..304cc5e --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,11 @@ +module TaskTimer { + + requires javafx.controls; + requires javafx.fxml; + requires com.jfoenix; + + opens HuimangTech to javafx.graphics, javafx.fxml; + + exports HuimangTech; + +} \ No newline at end of file diff --git a/src/main/java/resources/FXML.css b/src/main/java/resources/FXML.css new file mode 100644 index 0000000..822b1fe --- /dev/null +++ b/src/main/java/resources/FXML.css @@ -0,0 +1,96 @@ +@font-face { + +} + +.parent { + -fx-background-color: #fff; +} + +.sidebar { + -fx-background-color: #325288; +} + +.HomeLbl { + -fx-font-family: 'Adobe Devanagari'; +} + +.jfxButton { + -fx-background-color: #325288; + -fx-text-fill: #FFF; +} + +.jfxButton:hover { + -fx-background-color: #fff; + -fx-background-radius: 5px; + -fx-text-fill: #325288; + -fx-border-color: #325288; + -fx-border-width: 1px; + -fx-border-radius: 5px; + -fx-border-style: solid; +} + +.jfxButton:focused:hover { + -fx-background-color: #fff; + -fx-background-radius: 5px; + -fx-text-fill: #325288; + -fx-border-color: #325288; + -fx-border-width: 1px; + -fx-border-radius: 5px; + -fx-border-style: solid; +} + + +.closeBtn { + -fx-background-color: #325288; +} + +.closeBtn:hover { + -fx-background-color: #f17b7b; +} + +.aboutUsBtn { + -fx-fill: #FFF; +} + +.aboutUsBtn:hover { + -fx-fill: #f1c64e; +} + +.backBtn { +} + +.backBtn:hover { + -fx-background-color: #21365b; +} + +.homeUI { + -fx-background-color: white; + -fx-border-color: #325288; + -fx-border-width: 5px 5px 5px 5px +} + +.choice-box { + -fx-fill: #f1c64e; + -fx-text-fill: #f1c64e; + -fx-color-label-visible: #f1c64e; + -fx-font-size: 28px; + -fx-font-family: "Times New Roman"; + -fx-background-color: -fx-text-box-border, -fx-background, #fff; + -fx-background-insets: 0, 0 0 0 0; + -fx-background-radius: 0; +} + +.choice-box:focused { + -fx-text-fill: #f1c64e; + -fx-background-insets: 0, 0 0 1 0; + -fx-background-radius: 0; + -fx-background-color: -fx-focus-color, -fx-background; +} + +.choice-box:hover { + -fx-text-fill: #f1c64e; + -fx-background-insets: 0, 0 0 1 0; + -fx-background-radius: 0; + -fx-background-color: -fx-focus-color, -fx-background; +} + diff --git a/src/main/java/resources/Images/TaskTimer.ico b/src/main/java/resources/Images/TaskTimer.ico new file mode 100644 index 0000000..e02fee5 Binary files /dev/null and b/src/main/java/resources/Images/TaskTimer.ico differ diff --git a/src/main/java/resources/Images/delete.png b/src/main/java/resources/Images/delete.png new file mode 100644 index 0000000..28baa32 Binary files /dev/null and b/src/main/java/resources/Images/delete.png differ diff --git a/src/main/java/resources/Images/left-arrow.png b/src/main/java/resources/Images/left-arrow.png new file mode 100644 index 0000000..f748f8e Binary files /dev/null and b/src/main/java/resources/Images/left-arrow.png differ diff --git a/src/main/java/resources/Images/minus.png b/src/main/java/resources/Images/minus.png new file mode 100644 index 0000000..c2db0b1 Binary files /dev/null and b/src/main/java/resources/Images/minus.png differ diff --git a/src/main/java/resources/MainUI.fxml b/src/main/java/resources/MainUI.fxml new file mode 100644 index 0000000..60b4813 --- /dev/null +++ b/src/main/java/resources/MainUI.fxml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
diff --git a/src/main/java/resources/Timer.fxml b/src/main/java/resources/Timer.fxml new file mode 100644 index 0000000..c9c7330 --- /dev/null +++ b/src/main/java/resources/Timer.fxml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/src/main/java/resources/bundles/TaskTimer_ar_SA.properties b/src/main/java/resources/bundles/TaskTimer_ar_SA.properties new file mode 100644 index 0000000..ad19cf2 --- /dev/null +++ b/src/main/java/resources/bundles/TaskTimer_ar_SA.properties @@ -0,0 +1,13 @@ +Hibernate=إسبات +Restart=إعادة تشغيل +ShutDown=إيقاف تشغيل +Sleep=سكون +Hours=ساعات +Seconds=ثواني +Minutes=دقائق +Start=البدء +tskLbl=ادخل الوقت للمهمة +tskShutDownLbl=أدخل الوقت المراد ل إيقاف التشغيل +tskRestartLbl=أدخل الوقت المراد ل إعادة التشغيل +tskHibernateLbl=أدخل الوقت المراد للإسبات +tskSleepLbl=أدخل الوقت المراد للسكون \ No newline at end of file diff --git a/src/main/java/resources/bundles/TaskTimer_en_US.properties b/src/main/java/resources/bundles/TaskTimer_en_US.properties new file mode 100644 index 0000000..e0f36d5 --- /dev/null +++ b/src/main/java/resources/bundles/TaskTimer_en_US.properties @@ -0,0 +1,13 @@ +Hibernate=Hibernate +Restart=Restart +ShutDown=ShutDown +Sleep=Sleep +Hours=Hours +Seconds=Seconds +Minutes=Minutes +Start=Start +tskLbl=Enter Time to Task +tskShutDownLbl=Enter Time to ShutDown +tskRestartLbl=Enter Time to Restart +tskHibernateLbl=Enter Time to Hibernate +tskSleepLbl=Enter Time to Sleep