diff --git a/Learning_is_keyboard/graphics/IMG_3473.afphoto b/Learning_is_keyboard/graphics/IMG_3473.afphoto index 5f9dfc7..0f279df 100644 Binary files a/Learning_is_keyboard/graphics/IMG_3473.afphoto and b/Learning_is_keyboard/graphics/IMG_3473.afphoto differ diff --git a/Learning_is_keyboard/graphics/light_mode/light_default.png b/Learning_is_keyboard/graphics/light_mode/light_default.png new file mode 100644 index 0000000..1b260ab Binary files /dev/null and b/Learning_is_keyboard/graphics/light_mode/light_default.png differ diff --git a/Learning_is_keyboard/src/Controller/Main.java b/Learning_is_keyboard/src/Controller/Main.java new file mode 100644 index 0000000..b43d2b0 --- /dev/null +++ b/Learning_is_keyboard/src/Controller/Main.java @@ -0,0 +1,35 @@ +package Controller; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import Model.ModelData; +import Model.MyModel; + +import View.MyView; + +public class Main { + public static void main(String[] args) { + ConcurrentLinkedQueue qCommands = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue qDataFromModel = new ConcurrentLinkedQueue(); + + Object oThreadLock = new Object(); + + MyModel oModel = new MyModel(oThreadLock, qDataFromModel); + + ModelData oModelData = new ModelData(""); + + MyView oView = new MyView(oModelData); + + + + oModel.start(); + + while (true) { + + //Wake up model thread if new task to execute. + synchronized(oThreadLock) { + oThreadLock.notifyAll(); + } + } + } +} diff --git a/Learning_is_keyboard/src/Controller/MyController.java b/Learning_is_keyboard/src/Controller/MyController.java deleted file mode 100644 index 83bc040..0000000 --- a/Learning_is_keyboard/src/Controller/MyController.java +++ /dev/null @@ -1,5 +0,0 @@ -package Controller; - -public class MyController { - -} diff --git a/Learning_is_keyboard/src/Main.java b/Learning_is_keyboard/src/Main.java deleted file mode 100644 index 52f889c..0000000 --- a/Learning_is_keyboard/src/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) throws Exception { - System.out.println("Hello, World!"); - } -} diff --git a/Learning_is_keyboard/src/Model/ModelData.java b/Learning_is_keyboard/src/Model/ModelData.java new file mode 100644 index 0000000..3f77e71 --- /dev/null +++ b/Learning_is_keyboard/src/Model/ModelData.java @@ -0,0 +1,9 @@ +package Model; + +public class ModelData { + private String sText; + + public ModelData(String sText) { + this.sText = sText; + } +} diff --git a/Learning_is_keyboard/src/Model/MyModel.java b/Learning_is_keyboard/src/Model/MyModel.java index 06ae8e1..28ae2dd 100644 --- a/Learning_is_keyboard/src/Model/MyModel.java +++ b/Learning_is_keyboard/src/Model/MyModel.java @@ -1,5 +1,56 @@ package Model; -public class MyModel { - +import java.util.concurrent.ConcurrentLinkedQueue; + +public class MyModel extends Thread { + + private Object oThreadLock; + + private long liStart; + private long liStop; + + private ConcurrentLinkedQueue qDataToMain; + + private int iModelCommand; + + private ModelData oModelData; + + public MyModel(Object oThreadLock, ConcurrentLinkedQueue qDataToMain) { + this.oThreadLock = oThreadLock; + this.qDataToMain = qDataToMain; + } + + @Override + public void run() { + this.setName("Model"); + System.out.println("Model running"); + while (iModelCommand != 0) { + //Model will be suspended at start until main notifies, that new task has to be executed. + synchronized(oThreadLock) { + try { + liStart = System.nanoTime(); + System.out.println("Model suspended"); + oThreadLock.wait(); + } catch (InterruptedException e) { + System.out.println("Error at oThreadLock.wait() at MyModel"); + e.printStackTrace(); + } + } + liStop = System.nanoTime(); + System.out.println("Model unsuspended"); + System.out.println("Time suspended: " + ((liStop - liStart) / 1000000) + "ms"); + switch (iModelCommand) { + case (1): { + oModelData = new ModelData(RandomTextCreator.createText(300)); + }break; + case (2): { + + }break; + } + } + } + + public void setModelCommand(int iModelCommand) { + this.iModelCommand = iModelCommand; + } } diff --git a/Learning_is_keyboard/src/Model/RandomTextCreator.java b/Learning_is_keyboard/src/Model/RandomTextCreator.java new file mode 100644 index 0000000..29f0ce9 --- /dev/null +++ b/Learning_is_keyboard/src/Model/RandomTextCreator.java @@ -0,0 +1,79 @@ +package Model; + +public class RandomTextCreator { + public static String createText(int iTextLength) { + String sReturn = ""; + int iLastOption = 0; + + for (int i = 0; i < iTextLength; i++) { + //Formula to calculate random value between max and min. Math.random() * (max - min + 1) + min + int iMin = 0; + int iMax = 3; + int iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + while (iOption == iLastOption) { + iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + } + + switch (iOption) { + //48-57 0-9 + case (0): { + sReturn += createText0(); + }break; + //65-90 A-Z + case (1): { + sReturn += createText1(); + }break; + //97-122 a-z + case (2): { + sReturn += createText2(); + }break; + //?!()=+,-[]{} + case (3): { + sReturn += createText3(); + }break; + } + + iLastOption = iOption; + } + + return sReturn; + } + + //48-57 0-9 + private static String createText0() { + //Formula to calculate random value between max and min. Math.random() * (max - min + 1) + min + int iMin = 48; + int iMax = 57; + int iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + return Integer.toString(iOption); + } + + //65-90 A-Z + private static String createText1() { + //Formula to calculate random value between max and min. Math.random() * (max - min + 1) + min + int iMin = 65; + int iMax = 90; + int iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + return Integer.toString(iOption); + } + + //97-122 a-z + private static String createText2() { + //Formula to calculate random value between max and min. Math.random() * (max - min + 1) + min + int iMin = 97; + int iMax = 122; + int iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + return Integer.toString(iOption); + } + + //?!()=+,-[]{} + //63 33 40 41 61 43 44 45 91 93 123 125 + private static String createText3() { + int [] aiOptions = {63, 33, 40, 41, 61, 43, 44, 45, 91, 93, 123, 125}; + //Formula to calculate random value between max and min. Math.random() * (max - min + 1) + min + int iMin = 0; + int iMax = 11; + int iOption = (int)(Math.random() * (iMax - iMin + 1) + iMin); + return Integer.toString(aiOptions[iOption]); + } +} \ No newline at end of file diff --git a/Learning_is_keyboard/src/View/MainFrame/MyColor.java b/Learning_is_keyboard/src/View/MainFrame/MyColor.java new file mode 100644 index 0000000..30a150f --- /dev/null +++ b/Learning_is_keyboard/src/View/MainFrame/MyColor.java @@ -0,0 +1,29 @@ +package View.MainFrame; + +import java.awt.Color; + +public class MyColor { + + private static Color[] oLightTheme = {new Color(76, 78, 82), new Color(255, 253, 250), new Color(173, 216, 230)}; + private static Color[] oDarkTheme = {new Color(255, 253, 250), new Color(76, 78, 82), new Color(47, 47, 47)}; + + //Color for separators is always the same. + private static Color oColorSeparators = new Color(47, 47, 47); + + public static Color[] getTheme(int iThemeNr) { + Color[] oThemeToReturn = oLightTheme; + switch (iThemeNr) { + case (0): { + oThemeToReturn = oLightTheme; + }break; + case (1): { + oThemeToReturn = oDarkTheme; + }break; + } + return oThemeToReturn; + } + + public static Color getSeparatorsColor() { + return oColorSeparators; + } +} \ No newline at end of file diff --git a/Learning_is_keyboard/src/View/MainFrame/MyKeyboardPanel.java b/Learning_is_keyboard/src/View/MainFrame/MyKeyboardPanel.java new file mode 100644 index 0000000..9ec60bf --- /dev/null +++ b/Learning_is_keyboard/src/View/MainFrame/MyKeyboardPanel.java @@ -0,0 +1,7 @@ +package View.MainFrame; + +import javax.swing.JPanel; + +public class MyKeyboardPanel extends JPanel { + +} diff --git a/Learning_is_keyboard/src/View/MainFrame/MyMainFrame.java b/Learning_is_keyboard/src/View/MainFrame/MyMainFrame.java new file mode 100644 index 0000000..70e6ede --- /dev/null +++ b/Learning_is_keyboard/src/View/MainFrame/MyMainFrame.java @@ -0,0 +1,13 @@ +package View.MainFrame; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +public class MyMainFrame extends JFrame { + JPanel[] aoPanels = new JPanel[2]; + + public MyMainFrame() { + aoPanels[0] = new JPanel(); + aoPanels[1] = new JPanel(); + } +} diff --git a/Learning_is_keyboard/src/View/MainFrame/MyMenuBar.java b/Learning_is_keyboard/src/View/MainFrame/MyMenuBar.java new file mode 100644 index 0000000..d6b5289 --- /dev/null +++ b/Learning_is_keyboard/src/View/MainFrame/MyMenuBar.java @@ -0,0 +1,7 @@ +package View.MainFrame; + +import javax.swing.JMenuBar; + +public class MyMenuBar extends JMenuBar { + +} diff --git a/Learning_is_keyboard/src/View/MainFrame/MyNextLetterPanel.java b/Learning_is_keyboard/src/View/MainFrame/MyNextLetterPanel.java new file mode 100644 index 0000000..dadaca2 --- /dev/null +++ b/Learning_is_keyboard/src/View/MainFrame/MyNextLetterPanel.java @@ -0,0 +1,10 @@ +package View.MainFrame; + +import javax.swing.JPanel; + +public class MyNextLetterPanel extends JPanel { + + public MyNextLetterPanel() { + + } +} diff --git a/Learning_is_keyboard/src/View/MyView.java b/Learning_is_keyboard/src/View/MyView.java index ec92127..756442b 100644 --- a/Learning_is_keyboard/src/View/MyView.java +++ b/Learning_is_keyboard/src/View/MyView.java @@ -1,4 +1,21 @@ package View; + +import Model.ModelData; +import View.MainFrame.MyMainFrame; + public class MyView { - + + private ModelData oModelData; + + private MyMainFrame oMainFrame; + + public MyView(ModelData oModelData) { + this.oModelData = oModelData; + + + } + + public void updateView(ModelData oModelData) { + + } }