Added some classes, Implemented a class that creates random strings
This commit is contained in:
Binary file not shown.
BIN
Learning_is_keyboard/graphics/light_mode/light_default.png
Normal file
BIN
Learning_is_keyboard/graphics/light_mode/light_default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 585 KiB |
35
Learning_is_keyboard/src/Controller/Main.java
Normal file
35
Learning_is_keyboard/src/Controller/Main.java
Normal file
@@ -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<Integer> qCommands = new ConcurrentLinkedQueue<Integer>();
|
||||
ConcurrentLinkedQueue<ModelData> qDataFromModel = new ConcurrentLinkedQueue<ModelData>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package Controller;
|
||||
|
||||
public class MyController {
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
9
Learning_is_keyboard/src/Model/ModelData.java
Normal file
9
Learning_is_keyboard/src/Model/ModelData.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Model;
|
||||
|
||||
public class ModelData {
|
||||
private String sText;
|
||||
|
||||
public ModelData(String sText) {
|
||||
this.sText = sText;
|
||||
}
|
||||
}
|
||||
@@ -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<ModelData> qDataToMain;
|
||||
|
||||
private int iModelCommand;
|
||||
|
||||
private ModelData oModelData;
|
||||
|
||||
public MyModel(Object oThreadLock, ConcurrentLinkedQueue<ModelData> 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;
|
||||
}
|
||||
}
|
||||
|
||||
79
Learning_is_keyboard/src/Model/RandomTextCreator.java
Normal file
79
Learning_is_keyboard/src/Model/RandomTextCreator.java
Normal file
@@ -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]);
|
||||
}
|
||||
}
|
||||
29
Learning_is_keyboard/src/View/MainFrame/MyColor.java
Normal file
29
Learning_is_keyboard/src/View/MainFrame/MyColor.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package View.MainFrame;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyKeyboardPanel extends JPanel {
|
||||
|
||||
}
|
||||
13
Learning_is_keyboard/src/View/MainFrame/MyMainFrame.java
Normal file
13
Learning_is_keyboard/src/View/MainFrame/MyMainFrame.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
7
Learning_is_keyboard/src/View/MainFrame/MyMenuBar.java
Normal file
7
Learning_is_keyboard/src/View/MainFrame/MyMenuBar.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package View.MainFrame;
|
||||
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
public class MyMenuBar extends JMenuBar {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package View.MainFrame;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyNextLetterPanel extends JPanel {
|
||||
|
||||
public MyNextLetterPanel() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user