diff --git a/bin/Control/MyControlModel.class b/bin/Control/MyControlModel.class deleted file mode 100644 index cf8cfa6..0000000 Binary files a/bin/Control/MyControlModel.class and /dev/null differ diff --git a/bin/Control/MyControlModelPIC.class b/bin/Control/MyControlModelPIC.class new file mode 100644 index 0000000..69c01fa Binary files /dev/null and b/bin/Control/MyControlModelPIC.class differ diff --git a/bin/Control/MyControlModelRuntime.class b/bin/Control/MyControlModelRuntime.class new file mode 100644 index 0000000..7a686dc Binary files /dev/null and b/bin/Control/MyControlModelRuntime.class differ diff --git a/bin/Control/MyControlView.class b/bin/Control/MyControlView.class index a96256d..79e4aaf 100644 Binary files a/bin/Control/MyControlView.class and b/bin/Control/MyControlView.class differ diff --git a/bin/Model/MyModel.class b/bin/Model/MyModel.class index 704f103..29e6739 100644 Binary files a/bin/Model/MyModel.class and b/bin/Model/MyModel.class differ diff --git a/bin/Model/Runtime/Environment.class b/bin/Model/Runtime/Environment.class deleted file mode 100644 index 241f943..0000000 Binary files a/bin/Model/Runtime/Environment.class and /dev/null differ diff --git a/bin/Model/Runtime/Main.class b/bin/Model/Runtime/Main.class index 5a45b75..df06311 100644 Binary files a/bin/Model/Runtime/Main.class and b/bin/Model/Runtime/Main.class differ diff --git a/bin/View/GUIMainFrame.class b/bin/View/GUIMainFrame.class index e56573e..7d34899 100644 Binary files a/bin/View/GUIMainFrame.class and b/bin/View/GUIMainFrame.class differ diff --git a/bin/View/GUIMenuBar.class b/bin/View/GUIMenuBar.class index 1987f46..2dc7dd5 100644 Binary files a/bin/View/GUIMenuBar.class and b/bin/View/GUIMenuBar.class differ diff --git a/bin/View/GUIRegister.class b/bin/View/GUIRegister.class index db88222..74779b9 100644 Binary files a/bin/View/GUIRegister.class and b/bin/View/GUIRegister.class differ diff --git a/bin/View/GUITestFileTable.class b/bin/View/GUITestFileTable.class index 15257ba..bb51c58 100644 Binary files a/bin/View/GUITestFileTable.class and b/bin/View/GUITestFileTable.class differ diff --git a/bin/View/GUITime.class b/bin/View/GUITime.class index ec249ae..62d381c 100644 Binary files a/bin/View/GUITime.class and b/bin/View/GUITime.class differ diff --git a/bin/View/MyColors.class b/bin/View/MyColors.class new file mode 100644 index 0000000..b2ccf60 Binary files /dev/null and b/bin/View/MyColors.class differ diff --git a/bin/View/MyView.class b/bin/View/MyView.class index ee033eb..948961c 100644 Binary files a/bin/View/MyView.class and b/bin/View/MyView.class differ diff --git a/src/Control/MyControlModel.java b/src/Control/MyControlModelPIC.java similarity index 80% rename from src/Control/MyControlModel.java rename to src/Control/MyControlModelPIC.java index 93841eb..56a9805 100644 --- a/src/Control/MyControlModel.java +++ b/src/Control/MyControlModelPIC.java @@ -5,13 +5,13 @@ import java.util.ArrayList; import Model.MyModel; import View.MyView; -public class MyControlModel { +public class MyControlModelPIC { MyModel oModel; MyView oView; //put Objects to manipulate here - public MyControlModel(MyModel model, MyView view) { + public MyControlModelPIC(MyModel model, MyView view) { oModel = model; oView = view; } @@ -73,28 +73,7 @@ public class MyControlModel { public void setRamModel(int[][] aiiRam) { } - - - public void startProgramModel() { - - } - - public void stepProgramModel() { - - } - - public void pauseProgramModel() { - - } - - public void resetProgramModel() { - - } - - public void controlWDTModel(boolean bEnabled) { - - } public void setQuarzModel(int iElement) { diff --git a/src/Control/MyControlModelRuntime.java b/src/Control/MyControlModelRuntime.java new file mode 100644 index 0000000..0f737d2 --- /dev/null +++ b/src/Control/MyControlModelRuntime.java @@ -0,0 +1,85 @@ +package Control; + +import Model.MyModel; +import View.MyView; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; + +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JCheckBox; + +public class MyControlModelRuntime implements ActionListener { + + MyModel oMyModel; + + ArrayList oBreakpoints; + ArrayList oControlButtons; + + public MyControlModelRuntime(MyModel model, MyView view) { + oMyModel = model; + oControlButtons = view.getGUIMCMenu().getControlButtons(); + oBreakpoints = view.getGUITestFileTable().getCheckboxes(); + addActionListeners(); + } + + private void startProgramEnvironment() { + oMyModel.start(); + } + + private void stepProgramEnvironment() { + oMyModel.step(); + } + + private void pauseProgramEnvironment() { + oMyModel.pause(); + } + + private void resetProgramEnvironment() { + + } + + public void controlWDTEnvironment(boolean bEnabled) { + + } + + @Override + public void actionPerformed(ActionEvent e) { + int i = 0; + for (JCheckBox oBreakpoint : oBreakpoints) { + if (e.getSource() == oBreakpoint) { + oMyModel.controlBreakpoint(i); + } + i++; + } + if (e.getSource() == oControlButtons.get(0)) { + //startProgramEnvironment(); + System.out.println("Test"); + } + if (e.getSource() == oControlButtons.get(1)) { + + } + if (e.getSource() == oControlButtons.get(2)) { + + } + + // TODO Auto-generated method stub + + } + + private void addActionListeners() { + if (oBreakpoints != null) { + for (JCheckBox oBreakpoint : oBreakpoints) { + oBreakpoint.addActionListener(this); + } + } + if (oControlButtons != null) { + for (JButton oButton : oControlButtons) { + oButton.addActionListener(this); + } + } + } +} \ No newline at end of file diff --git a/src/Control/MyControlView.java b/src/Control/MyControlView.java index ce24bc1..e916029 100644 --- a/src/Control/MyControlView.java +++ b/src/Control/MyControlView.java @@ -10,7 +10,7 @@ public class MyControlView { MyView oMyView; MyModel oMyModel; - public MyControlView(MyView view, MyModel model) { + public MyControlView(MyModel model, MyView view) { oMyView = view; oMyModel = model; } diff --git a/src/Model/MyModel.java b/src/Model/MyModel.java index f3c9151..a189ff9 100644 --- a/src/Model/MyModel.java +++ b/src/Model/MyModel.java @@ -1,22 +1,160 @@ package Model; +import java.util.ArrayList; + +import Model.Microcontroller.Bitmask; import Model.Microcontroller.PIC; -import Model.Runtime.Environment; +import Model.Microcontroller.WATCHDOG; +import View.GUIMainFrame; public class MyModel { - PIC oPIC; - Environment oEnvironment; - - public MyModel(PIC pic, Environment env) { - oPIC = pic; - oEnvironment = env; + private PIC oPIC; + + private int iModelState = 3; + private int iActualLine; + private int iLastLine; + + private ArrayList listBreakpoints = new ArrayList(); + + private long liRuntimeRun; + private long liRuntimeStep; + + private boolean[] bBreakpoints; + + private WATCHDOG watchdog; + GUIMainFrame oMainFrame; + + public MyModel() { + oPIC = new PIC(); } public PIC getPIC() { return this.oPIC; } - public Environment getEnvironment() { - return this.oEnvironment; + private int getModelState() { + return iModelState; + } + + /** + * -1 == ERROR, 0 == END, 1 == START, 2 == PAUSE, 3 == RESET + * @param i + */ + public void setModelState(int i) { + iModelState = i; + } + + public ArrayList getBreakpointsList() { + return listBreakpoints; + } + + public void setBreakpointsList(ArrayList liBreakpoints) { + listBreakpoints = liBreakpoints; + bBreakpoints = new boolean[listBreakpoints.size()]; + } + + /** + * + * @return + */ + public int getActualLine() { + return iActualLine; + } + + /** + * + * @return + */ + public int getLastLine() { + return iLastLine; + } + + /** + * + * @return + */ + public long getRuntimeRun() { + return liRuntimeRun; + } + + /** + * + * @return + */ + public long getRuntimeStep() { + return liRuntimeStep; + } + + /** + * + * @return + */ + public WATCHDOG getWatchdog() { + return watchdog; + } + + public void step() { + //Check if step valid + if (oPIC.getRam().get_Programcounter() < (oPIC.getEeprom().getLengthEEPROM() - 1)) { + final long timeStart = System.nanoTime(); + + //Makes one step through the eeprom. + Bitmask oBitmask = new Bitmask(); + oBitmask.bitMaskDecoderAndExecuteCommand(oPIC.getEeprom().getElement(oPIC.getRam().get_Programcounter()), oPIC); + + final long timeEnd = System.nanoTime(); + + liRuntimeStep += (timeEnd - timeStart); + + } else { + System.out.println("Step invalid, end of file reached!"); + } + } + + public void start() { + if (getModelState() != 2) { //Do not start again if paused, instead call start to unpause only. + final long timeStart = System.nanoTime(); + + //workWithWatchdog(1, 1); + //Check if set breakpoint reached or program was stopped or interrupt + + while (getModelState() != 0) { + switch (iModelState) { + + case 1: { //START + step(); + // + //workWithWatchdog(1, 2); + final long timeEnd = System.nanoTime(); + liRuntimeRun += timeEnd - timeStart; + oMainFrame.updateWindow(); + }break; + + case 2: { //PAUSE resume() has to be called to continue + while (iModelState == 2) {} + }break; + } + } + } else { //Unpause + iModelState = 1; + } + } + + public void reset() { + if (getModelState() != 1) { + oPIC.resetPIC(); + iModelState = 3; //RESET + } + } + + public void pause() { + iModelState = 2; + } + + public void controlBreakpoint(int iBreakpoint) { + if (bBreakpoints != null) { + bBreakpoints[iBreakpoint] = !bBreakpoints[iBreakpoint]; + System.out.println("Breakpoint " + iBreakpoint + " was set to " + bBreakpoints[iBreakpoint]); + } } } diff --git a/src/Model/Runtime/Environment.java b/src/Model/Runtime/Environment.java deleted file mode 100755 index 6693784..0000000 --- a/src/Model/Runtime/Environment.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * @author Aaron Moser - * @date 21.02.2022 - * @lastchange 21.02.2022 - */ - -package Model.Runtime; - -import java.util.ArrayList; - -import Model.Microcontroller.WATCHDOG; -import Model.Microcontroller.PIC; -import View.GUIMainFrame; - -public class Environment { - - private PIC oPIC; - - private String sEepromDataFile; - private String sActualCommand; - - private int iEnvironmentState; - private int iActualLine; - private int iLastLine; - - private ArrayList listBreakpoints = new ArrayList(); - - private long liRuntime; - - private WATCHDOG watchdog; - - public Environment() { - - oPIC = new PIC(); - - GUIMainFrame oMainFrame = new GUIMainFrame(this); - - watchdog = new WATCHDOG(); - - - - - - sEepromDataFile = ""; - sActualCommand = ""; - - iEnvironmentState = 0; - - while (iEnvironmentState > -1) { - - // loadfile command readEepromFile.readFileAndWriteToEEPROM(new File(sEepromDataFile), oPIC); - } - } - - public PIC getPIC() { - return oPIC; - } - - public ArrayList getBreakpoints() { - return listBreakpoints; - } - - /** - * - * @param iBreakpoint - * @param bState - */ - public void changeListBreakpoints(int iBreakpoint, boolean bState) { - if (iBreakpoint > -1) { - if (bState) { - //add new breakpoint to list - boolean bExists = false; - for (int i = 0; i < listBreakpoints.size(); i++) { - if (listBreakpoints.get(i) == iBreakpoint) - bExists = true; - } - if (!bExists) { - listBreakpoints.add(iBreakpoint); - } - } else { - //remove breakpoint from list - int iIndex = -1; - for (int i = 0; i < listBreakpoints.size(); i++) { - if (listBreakpoints.get(i) == iBreakpoint) { - iIndex = i; - i = listBreakpoints.size(); - } - } - if (iIndex > -1) { - listBreakpoints.remove(iIndex); - } - } - } else { - //remove all breakpoints from list - while (listBreakpoints.size() > 0) { - listBreakpoints.remove(0); - } - } - - } - - /** - * - * @return - */ - public int getActualLine() { - return iActualLine; - } - - /** - * - * @return - */ - public int getLastLine() { - return iLastLine; - } - - /** - * - * @return - */ - public long getRuntime() { - return liRuntime; - } - - /** - * - * @return - */ - public WATCHDOG getWatchdog() { - return watchdog; - } - - public void step() { - - } -} - diff --git a/src/Model/Runtime/Main.java b/src/Model/Runtime/Main.java index fb143fa..73fce95 100755 --- a/src/Model/Runtime/Main.java +++ b/src/Model/Runtime/Main.java @@ -1,7 +1,17 @@ package Model.Runtime; +import Control.MyControlModelPIC; +import Control.MyControlModelRuntime; +import Control.MyControlView; +import Model.MyModel; +import View.MyView; + public class Main { public static void main(String[] args) { - Environment env = new Environment(); + MyModel oModel = new MyModel(); + MyView oView = new MyView(oModel); + MyControlView oControlView = new MyControlView(oModel, oView); + MyControlModelRuntime oControlModelRuntime = new MyControlModelRuntime(oModel, oView); + MyControlModelPIC oControlModelPIC = new MyControlModelPIC(oModel, oView); } } \ No newline at end of file diff --git a/src/View/GUIMainFrame.java b/src/View/GUIMainFrame.java index 6bc1a5a..f6dfd9c 100755 --- a/src/View/GUIMainFrame.java +++ b/src/View/GUIMainFrame.java @@ -10,42 +10,8 @@ import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; -import Control.MyControlModel; -import Control.MyControlView; -import Model.MyModel; -import Model.Runtime.Environment; - public class GUIMainFrame extends JFrame { - /** - * Color oWhite = new Color(255, 253, 250); - * Color oDarkGray = new Color(76, 78, 82); - * Color oDarkGrayB = new Color(47, 47, 47); - * Color oLightBlue = new Color(173, 216, 230); - * Color oOrangeDM = new Color(255, 170, 0); - * Color oLightBlueDM = new Color(0, 213, 255); - * Color oOrangeDMB = new Color(255, 85, 0); - * First Color == TextColor - * Second Color == BackgroundColor - * Third Color == BorderColor - * Fourth Color == TextColor Marked - * Fifth Color == BackgroundColor Marked - * Sixth Color == BorderColor Marked - */ - Color[] aoDarkTheme = {new Color(255, 253, 250), new Color(76, 78, 82), new Color(47, 47, 47), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; - Color[] aoLightTheme = {new Color(76, 78, 82), new Color(255, 253, 250), new Color(173, 216, 230), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; - - //Components of gui-main-frame - GUITestFileTable oGUITestFileTable = new GUITestFileTable(); - GUIMenuBar oGUIMenuBar; - GUIRegister oGUIRegister = new GUIRegister(); - GUIRegistersDetailed oGUIRegistersDetailed = new GUIRegistersDetailed(); - GUIRamTable oGUIRamTable = new GUIRamTable(); - GUIPorts oGUIPorts = new GUIPorts(); - GUIStack oGUIStack = new GUIStack(); - GUIMCMenu oGUIMCMenu = new GUIMCMenu(); - GUITime oGUITime = new GUITime(); - //Panels of gui-main-frame JPanel oMainPanel = new JPanel(); JPanel oPanel0 = new JPanel(); @@ -53,27 +19,31 @@ public class GUIMainFrame extends JFrame { JPanel oPanel2 = new JPanel(); JPanel oPanel3 = new JPanel(); + ArrayList oPanels = new ArrayList(); + /** * Object for storing all components, will be overhanded to menubar, to set theme. - * */ MyView oMyView; - MyModel oMyModel; - - MyControlView mcv; - - ArrayList oPanels = new ArrayList(); - /** * Constructor */ - public GUIMainFrame(Environment oEnvironment) { + public GUIMainFrame(GUIMenuBar oGUIMenuBar, MyView view) { + oMyView = view; + + // sets title of frame + this.setTitle("PIC-Simulator GUI"); + + // if x is pressed, exit application (HIDE_ON_CLOSE-hides application, DO_NOTHING_ON_CLOSE-prevents user from closing application) + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + //prevent frame from beeing resized + this.setResizable(false); + + //sets x and y dimension of frame + this.setSize(1400, 800); - this.setTitle("PIC-Simulator GUI"); // sets title of frame - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if x is pressed, exit application (HIDE_ON_CLOSE-hides application, DO_NOTHING_ON_CLOSE-prevents user from closing application) - this.setResizable(false); // prevent frame from beeing resized - this.setSize(1400, 800); //sets x and y dimension of frame //Set Icon ImageIcon guiLogo = new ImageIcon("./pictures/gui_logo.png"); // create an ImageIcon this.setIconImage(guiLogo.getImage()); // change icon of frame @@ -81,19 +51,16 @@ public class GUIMainFrame extends JFrame { //Adds components to frame, sets layouts,... buildGUIMainFrame(); - //Init view object with components of main frame. - oMyView = new MyView(this, oGUIMCMenu, oGUIPorts, oGUIRamTable, oGUIRegister, oGUIRegistersDetailed, oGUIStack, oGUITestFileTable, oGUITime, oMainPanel, oEnvironment); - //Set menubar - oGUIMenuBar = new GUIMenuBar(oMyModel, oMyView); this.setJMenuBar(oGUIMenuBar); setTheme(0); - updateWindow(); this.setVisible(true); //make frame visible - oMyModel = new MyModel(oEnvironment.getPIC(), oEnvironment); - mcv = new MyControlView(oMyView, oMyModel); - mcv.updateView(); + updateWindow(); + } + + public JPanel getMainPanel() { + return oMainPanel; } private void buildGUIMainFrame() { @@ -114,30 +81,30 @@ public class GUIMainFrame extends JFrame { oConstraints.gridx = 0; oConstraints.gridy = 0; oConstraints.insets = new Insets(10,10,0,0); - oPanel0.add(oGUITestFileTable, oConstraints); + oPanel0.add(oMyView.getGUITestFileTable(), oConstraints); //Build 2nd Panel from left oConstraints.gridx = 0; oConstraints.gridy = 0; oConstraints.insets = new Insets(10,10,0,0); - oPanel1.add(oGUIRegister, oConstraints); + oPanel1.add(oMyView.getGUIRegister(), oConstraints); oConstraints.gridy = 1; oConstraints.insets = new Insets(36,10,0,0); - oPanel1.add(oGUIRegistersDetailed, oConstraints); + oPanel1.add(oMyView.getGUIRegistersDetailed(), oConstraints); oConstraints.gridy = 2; oConstraints.insets = new Insets(47,10,0,0); - oPanel1.add(oGUIRamTable, oConstraints); + oPanel1.add(oMyView.getGUIRamTable(), oConstraints); //Build 3rd Panel from left oConstraints.gridx = 0; oConstraints.gridy = 0; oConstraints.insets = new Insets(10,10,0,0); - oPanel2.add(oGUIPorts, oConstraints); + oPanel2.add(oMyView.getGUIPorts(), oConstraints); oConstraints.gridy = 1; oPanel2.add(oPanel3, oConstraints); oConstraints.gridy = 2; oConstraints.insets = new Insets(45,90,0,0); - oPanel2.add(oGUIMCMenu, oConstraints); + oPanel2.add(oMyView.getGUIMCMenu(), oConstraints); //Build lower panel of 3rd panel oConstraints.gridx = 0; @@ -145,10 +112,10 @@ public class GUIMainFrame extends JFrame { oConstraints.insets = new Insets(0,0,0,0); oConstraints.weightx = 1; oConstraints.weighty = 1; - oPanel3.add(oGUIStack, oConstraints); + oPanel3.add(oMyView.getGUIStack(), oConstraints); oConstraints.insets = new Insets(0,40,0,0); oConstraints.gridx = 1; - oPanel3.add(oGUITime, oConstraints); + oPanel3.add(oMyView.getGUITime(), oConstraints); //Build MainPanel oConstraints.gridx = 0; @@ -181,30 +148,22 @@ public class GUIMainFrame extends JFrame { public void setTheme(int iThemeNr) { switch (iThemeNr) { case 0: { + Color[] aoLightTheme = MyColors.getTheme(0); for (JPanel oPanel : oPanels) { oPanel.setForeground(aoLightTheme[0]); oPanel.setBackground(aoLightTheme[1]); } this.setForeground(aoLightTheme[0]); this.setBackground(aoLightTheme[1]); - oGUIMCMenu.setTheme(0); - oGUIStack.setTheme(0); - oGUIPorts.setTheme(0); - oGUIRamTable.setTheme(0); - oGUITime.setTheme(0); }break; case 1: { + Color[] aoDarkTheme = MyColors.getTheme(1); for (JPanel oPanel : oPanels) { oPanel.setForeground(aoDarkTheme[0]); oPanel.setBackground(aoDarkTheme[1]); } this.setForeground(aoDarkTheme[0]); this.setBackground(aoDarkTheme[1]); - oGUIMCMenu.setTheme(1); - oGUIStack.setTheme(1); - oGUIPorts.setTheme(1); - oGUIRamTable.setTheme(1); - oGUITime.setTheme(1); }break; } } diff --git a/src/View/GUIMenuBar.java b/src/View/GUIMenuBar.java index a70bde7..f05a6e6 100644 --- a/src/View/GUIMenuBar.java +++ b/src/View/GUIMenuBar.java @@ -15,38 +15,21 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import Control.MyControlModel; -import Model.Backend.MyModel; -import Model.Backend.EepromLoader.ReadEepromFile; +import Model.MyModel; +import Model.EepromLoader.ReadEepromFile; public class GUIMenuBar extends JMenuBar implements ActionListener { - /** - * Color oWhite = new Color(255, 253, 250); - * Color oDarkGray = new Color(76, 78, 82); - * Color oDarkGrayB = new Color(47, 47, 47); - * Color oLightBlue = new Color(173, 216, 230); - * Color oOrangeDM = new Color(255, 170, 0); - * Color oLightBlueDM = new Color(0, 213, 255); - * Color oOrangeDMB = new Color(255, 85, 0); - * First Color == TextColor - * Second Color == BackgroundColor - * Third Color == BorderColor - * Fourth Color == TextColor Marked - * Fifth Color == BackgroundColor Marked - * Sixth Color == BorderColor Marked - */ - Color[] aoDarkTheme = {new Color(255, 253, 250), new Color(76, 78, 82), new Color(47, 47, 47), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; - Color[] aoLightTheme = {new Color(76, 78, 82), new Color(255, 253, 250), new Color(173, 216, 230), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; MyView oMyView; - MyControlModel oMyControl; + MyModel oMyModel; ArrayList oBreakpoints; ReadEepromFile oRef; boolean[] bBreakpointSet; int iTestFileLoaded = 0; + ArrayList oMenuItems = new ArrayList(); //Custom separators because addSeparator(default) looks not nice. JMenuItem oSeparator0; JMenuItem oSeparator1; @@ -123,7 +106,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { //Referrence to change different parts of gui for theme. oMyView = view; - oMyControl = new MyControlModel(model, view); + oMyModel = model; //File oFileMenu = new JMenu(sGermanLang[0]); @@ -157,6 +140,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { oManual = new JMenuItem(sGermanLang[22]); oAbout = new JMenuItem(sGermanLang[23]); + fillList(); setActionListeners(); setGerMnemonics(); buildMenubar(); @@ -394,7 +378,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { System.out.println("oResetProg"); //TODO } if (e.getSource() == oStepProg) { - oMyView.getEnvironment().step(); + System.out.println("oStepProg"); //TODO } if (e.getSource() == oIntervalASAP) { System.out.println("oIntervalASAP"); //TODO @@ -411,11 +395,13 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { if (e.getSource() == oGerLangItem) { changeLangMenuBar(sGermanLang); setGerMnemonics(); + oMyView.setLanguage(0); //TODO rest of gui } if (e.getSource() == oEngLangItem) { changeLangMenuBar(sEnglishLang); setEngMnemonics(); + oMyView.setLanguage(1); //TODO rest of gui } //Show manual @@ -430,9 +416,31 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { controlBreakpoints(e); } + private void fillList() { + //Fill list oMenuitems + oMenuItems.add(oLoadTestFile); + oMenuItems.add(oLoadProgStateItem); + oMenuItems.add(oSaveProgStateItem); + oMenuItems.add(oExitItem); + oMenuItems.add(oDarkTheme); + oMenuItems.add(oLightTheme); + oMenuItems.add(oStartProg); + oMenuItems.add(oPauseProg); + oMenuItems.add(oResetProg); + oMenuItems.add(oStepProg); + oMenuItems.add(oIntervalASAP); + oMenuItems.add(oInterval1Sec); + oMenuItems.add(oInterval2Sec); + oMenuItems.add(oGerLangItem); + oMenuItems.add(oEngLangItem); + oMenuItems.add(oManual); + oMenuItems.add(oAbout); + } + public void setTheme(int iThemeNr) { switch (iThemeNr) { case 0: { + Color[] aoLightTheme = MyColors.getTheme(0); this.setBackground(aoLightTheme[1]); this.setBorder(BorderFactory.createLineBorder(aoLightTheme[1], 2)); this.setOpaque(true); @@ -531,6 +539,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { oSeparator3.setBorder(BorderFactory.createLineBorder(oColorSeparators, 2)); }break; case 1: { + Color[] aoDarkTheme = MyColors.getTheme(1); this.setBackground(aoDarkTheme[1]); this.setBorder(BorderFactory.createLineBorder(aoDarkTheme[1], 2)); this.setOpaque(true); @@ -644,36 +653,40 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { oRef.setOPCode(oRef.getData()); oMyView.getGUITestFileTable().setData(oRef.getData()); - - ArrayList data = oRef.getData(); - int iDataSize = data.size(); - ArrayList opcode = oRef.getOPCode(); - - int iOPCodeSize = opcode.size(); - //If testfile was loaded before, reset all checkboxes - if (iTestFileLoaded > 0) { - oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); - for (int i = 0; i < iDataSize; i++) { - oBreakpoints.get(i).setEnabled(false); - } - } - //Enable only checkboxes which belong to real code - for (int i = 0; i < iDataSize; i++) { - for (int j = 0; j < iOPCodeSize; j++) { - if (data.get(i).equals(opcode.get(j))) { - oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); - oBreakpoints.get(i).setEnabled(true); - oBreakpoints.get(i).addActionListener(this); - } - } - } - bBreakpointSet = new boolean[iOPCodeSize]; - oRef.readFileAndWriteToEEPROM(oMyView.getEnvironment().getPIC()); + setBreakpointsActionListeners(); + + oRef.readFileAndWriteToEEPROM(oMyModel.getPIC()); oMyView.getGUIMainFrame().updateWindow(); iTestFileLoaded = 1; } } + private void setBreakpointsActionListeners() { + ArrayList data = oRef.getData(); + int iDataSize = data.size(); + ArrayList opcode = oRef.getOPCode(); + + int iOPCodeSize = opcode.size(); + //If testfile was loaded before, reset all checkboxes + if (iTestFileLoaded > 0) { + oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); + for (int i = 0; i < iDataSize; i++) { + oBreakpoints.get(i).setEnabled(false); + } + } + //Enable only checkboxes which belong to real code + for (int i = 0; i < iDataSize; i++) { + for (int j = 0; j < iOPCodeSize; j++) { + if (data.get(i).equals(opcode.get(j))) { + oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); + oBreakpoints.get(i).setEnabled(true); + oBreakpoints.get(i).addActionListener(this); + } + } + } + bBreakpointSet = new boolean[iOPCodeSize]; + } + private void controlBreakpoints(ActionEvent e) { if (oRef != null) { int iOPCode = oRef.getOPCode().size(); diff --git a/src/View/GUIRegister.java b/src/View/GUIRegister.java index 934c27c..a4c136c 100644 --- a/src/View/GUIRegister.java +++ b/src/View/GUIRegister.java @@ -64,6 +64,7 @@ public class GUIRegister extends JPanel { buildGUIRegister(); setWidth(); setTheme(0); + setLanguage(0); } private void addComponents() { @@ -151,6 +152,18 @@ public class GUIRegister extends JPanel { } } + public void setLanguage(int iLangNr) { + switch (iLangNr) { + case 0: { + oSFRRegisters.setValueAt("Vorteiler", 3, 2); + }break; + case 1: { + oSFRRegisters.setValueAt("Prescaler", 3, 2); + }break; + } + + } + public void setTheme(int iThemeNr) { switch (iThemeNr) { case 0: { diff --git a/src/View/GUITestFileTable.java b/src/View/GUITestFileTable.java index 96786e9..1b52df6 100644 --- a/src/View/GUITestFileTable.java +++ b/src/View/GUITestFileTable.java @@ -22,6 +22,7 @@ public class GUITestFileTable extends JScrollPane { JPanel oTable = new JPanel(); int iTheme = 0; boolean bFileLoaded = false; + JTextField oFill; /** * Color oWhite = new Color(255, 253, 250); @@ -46,7 +47,7 @@ public class GUITestFileTable extends JScrollPane { */ public GUITestFileTable() { - JTextField oFill = new JTextField("Please load testfile!"); + oFill = new JTextField(); oFill.setEditable(false); oLineInformation.add(oFill); @@ -57,6 +58,7 @@ public class GUITestFileTable extends JScrollPane { this.setPreferredSize(new Dimension(600, 700)); this.setViewportView(oTestPanel); setTheme(0); + setLanguage(0); } /** @@ -212,6 +214,17 @@ public class GUITestFileTable extends JScrollPane { } } + public void setLanguage(int iLangNr) { + switch (iLangNr) { + case 0: { + oFill.setText("Bitte Testdatei laden!"); + }break; + case 1: { + oFill.setText("Please load testfile!"); + }break; + } + } + /** * @return Color to set for testfiletable */ diff --git a/src/View/GUITime.java b/src/View/GUITime.java index 4a9865b..e25ad82 100644 --- a/src/View/GUITime.java +++ b/src/View/GUITime.java @@ -33,7 +33,8 @@ public class GUITime extends JPanel { JLabel oLabelWDT = new JLabel("Watchdog Timer"); JCheckBox oEnableWDT = new JCheckBox("WDT"); - JLabel oLabelRuntime = new JLabel("Runtime: 0"); + int iRuntime = 0; + JLabel oLabelRuntime = new JLabel("Runtime: " + iRuntime); JLabel oLabelQuarz = new JLabel("Quarzfrequency"); String[] asIntervals = {"32 kHz", "100 kHz", "500 kHz", "1 MHz", "2 MHz", "4 MHz", "8 MHz", "12 MHz", "16 MHz", "20 MHz"}; @@ -41,6 +42,7 @@ public class GUITime extends JPanel { public GUITime() { buildGUITime(); + setLanguage(0); } private void buildGUITime() { @@ -67,6 +69,27 @@ public class GUITime extends JPanel { this.add(oIntervals, oConstraints); } + public void setLanguage(int iLangNr) { + switch (iLangNr) { + case 0: { + oLabelRuntime.setText("Laufzeit: " + iRuntime); + oLabelQuarz.setText("Quarzfrequenz"); + }break; + case 1: { + oLabelRuntime.setText("Runtime: " + iRuntime); + oLabelQuarz.setText("Quarzfrequency"); + }break; + } + } + + public void setRuntime(int iRuntime) { + this.iRuntime = iRuntime; + } + + public int getRuntime() { + return iRuntime; + } + public void setTheme(int iThemeNr) { switch (iThemeNr) { case 0: { diff --git a/src/View/MyColors.java b/src/View/MyColors.java new file mode 100644 index 0000000..5582d52 --- /dev/null +++ b/src/View/MyColors.java @@ -0,0 +1,42 @@ +package View; + +import java.awt.Color; + +public class MyColors { + + /** + * Color oWhite = new Color(255, 253, 250); + * Color oDarkGray = new Color(76, 78, 82); + * Color oDarkGrayB = new Color(47, 47, 47); + * Color oLightBlue = new Color(173, 216, 230); + * Color oOrangeDM = new Color(255, 170, 0); + * Color oLightBlueDM = new Color(0, 213, 255); + * Color oOrangeDMB = new Color(255, 85, 0); + * First Color == TextColor + * Second Color == BackgroundColor + * Third Color == BorderColor + * Fourth Color == TextColor Marked + * Fifth Color == BackgroundColor Marked + * Sixth Color == BorderColor Marked + */ + static Color[] aoDarkTheme = {new Color(255, 253, 250), new Color(76, 78, 82), new Color(47, 47, 47), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; + static Color[] aoLightTheme = {new Color(76, 78, 82), new Color(255, 253, 250), new Color(173, 216, 230), new Color(0, 213, 255), new Color(255, 170, 0), new Color(255, 85, 0)}; + + public static Color[] getTheme(int iThemeNr) { + Color[] oTheme; + switch (iThemeNr) { + case 0: { + oTheme = aoLightTheme; + }break; + + case 1: { + oTheme = aoDarkTheme; + }break; + + default: { + oTheme = null; + }break; + } + return oTheme; + } +} diff --git a/src/View/MyView.java b/src/View/MyView.java index 2ddfaa4..6a2c6fb 100644 --- a/src/View/MyView.java +++ b/src/View/MyView.java @@ -2,36 +2,36 @@ package View; import javax.swing.JPanel; -import Model.Backend.Runtime.Environment; +import Model.MyModel; public class MyView implements IMyView { - GUIMainFrame oGUIMainFrame; - GUIMCMenu oGUIMCMenu; - GUIPorts oGUIPorts; - GUIRamTable oGUIRamTable; - GUIRegister oGUIRegister; - GUIRegistersDetailed oGUIRegistersDetailed; - GUIStack oGUIStack; - GUITestFileTable oGUITestFileTable; - GUITime oGUITime; + private GUIMainFrame oGUIMainFrame; + private GUIMCMenu oGUIMCMenu; + private GUIPorts oGUIPorts; + private GUIRamTable oGUIRamTable; + private GUIRegister oGUIRegister; + private GUIRegistersDetailed oGUIRegistersDetailed; + private GUIStack oGUIStack; + private GUITestFileTable oGUITestFileTable; + private GUITime oGUITime; + private GUIMenuBar oGUIMenuBar; - JPanel oGUIMainPanel; + private JPanel oGUIMainPanel; - Environment oEnvironment; - - public MyView(GUIMainFrame oGUIMainFrame, GUIMCMenu oGUIMCMenu, GUIPorts oGUIPorts, GUIRamTable oGUIRamTable, GUIRegister oGUIRegister, GUIRegistersDetailed oGUIRegistersDetailed, GUIStack oGUIStack, GUITestFileTable oGUITestFileTable, GUITime oGUITime, JPanel oGUIMainPanel, Environment oEnvironment) { - this.oGUIMainFrame = oGUIMainFrame; - this.oGUIMCMenu = oGUIMCMenu; - this.oGUIPorts = oGUIPorts; - this.oGUIRamTable = oGUIRamTable; - this.oGUIRegister = oGUIRegister; - this.oGUIRegistersDetailed = oGUIRegistersDetailed; - this.oGUIStack = oGUIStack; - this.oGUITestFileTable = oGUITestFileTable; - this.oGUITime = oGUITime; - this.oGUIMainPanel = oGUIMainPanel; - this.oEnvironment = oEnvironment; + public MyView(MyModel model) { + oGUIMenuBar = new GUIMenuBar(model, this); + oGUIMCMenu = new GUIMCMenu(); + oGUIPorts = new GUIPorts(); + oGUIRamTable = new GUIRamTable(); + oGUIRegister = new GUIRegister(); + oGUIRegistersDetailed = new GUIRegistersDetailed(); + oGUIStack = new GUIStack(); + oGUITestFileTable = new GUITestFileTable(); + oGUITime = new GUITime(); + oGUIMainFrame = new GUIMainFrame(oGUIMenuBar, this); + oGUIMainPanel = oGUIMainFrame.getMainPanel(); + setTheme(0); } public void setTheme(int iThemeNr) { @@ -44,6 +44,14 @@ public class MyView implements IMyView { oGUIStack.setTheme(iThemeNr); oGUITestFileTable.setTheme(iThemeNr); oGUITime.setTheme(iThemeNr); + oGUIMenuBar.setTheme(iThemeNr); + } + + public void setLanguage(int iLangNr) { + oGUIMCMenu.setLanguage(iLangNr); + oGUIRegister.setLanguage(iLangNr); + oGUITestFileTable.setLanguage(iLangNr); + oGUITime.setLanguage(iLangNr); } public GUIMainFrame getGUIMainFrame() { @@ -74,6 +82,10 @@ public class MyView implements IMyView { return this.oGUIStack; } + public GUITime getGUITime() { + return this.oGUITime; + } + public GUITestFileTable getGUITestFileTable() { return this.oGUITestFileTable; } @@ -81,8 +93,4 @@ public class MyView implements IMyView { public JPanel getGUIMainPanel() { return this.oGUIMainPanel; } - - public Environment getEnvironment() { - return this.oEnvironment; - } } \ No newline at end of file