-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheGUI.java
More file actions
236 lines (211 loc) · 10.5 KB
/
TheGUI.java
File metadata and controls
236 lines (211 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package barebones;
import java.awt.Color;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
/**
*
* @author lpp1g14
*/
public class TheGUI extends javax.swing.JFrame {
/**
* Creates new form TheGUI
*/
//DefaultStyledDocument document = new DefaultStyledDocument();
public TheGUI() {
initComponents();
/* Me trying to set it up so that some words turned blue
*StyleContext context = new StyleContext();
// build a style
*Style style = context.addStyle("test", null);
// set some style properties
*StyleConstants.setForeground(style, Color.BLUE);
*try {
// add some data to the document
* document.insertString(0, "", style);
*} catch (BadLocationException ex) {
* Logger.getLogger(TheGUI.class.getName()).log(Level.SEVERE, null, ex);
*}
*/
}
final StyleContext cont = StyleContext.getDefaultStyleContext();
final AttributeSet attr = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.RED);
final AttributeSet attrBlack = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.BLACK);
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
pnlProgram = new javax.swing.JPanel();
btnExecute = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
txtareaProgram = new javax.swing.JTextPane();
pnlOutput = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
txtareaOutput = new javax.swing.JTextPane();
mnuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Bare Bones Interpreter");
pnlProgram.setBorder(javax.swing.BorderFactory.createTitledBorder("The program"));
btnExecute.setText("Execute");
btnExecute.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnExecuteActionPerformed(evt);
}
});
txtareaProgram.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txtareaProgramKeyReleased(evt);
}
});
jScrollPane3.setViewportView(txtareaProgram);
javax.swing.GroupLayout pnlProgramLayout = new javax.swing.GroupLayout(pnlProgram);
pnlProgram.setLayout(pnlProgramLayout);
pnlProgramLayout.setHorizontalGroup(
pnlProgramLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProgramLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlProgramLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane3)
.addGroup(pnlProgramLayout.createSequentialGroup()
.addGap(0, 572, Short.MAX_VALUE)
.addComponent(btnExecute)))
.addContainerGap())
);
pnlProgramLayout.setVerticalGroup(
pnlProgramLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProgramLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnExecute))
);
pnlOutput.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));
jScrollPane1.setViewportView(txtareaOutput);
javax.swing.GroupLayout pnlOutputLayout = new javax.swing.GroupLayout(pnlOutput);
pnlOutput.setLayout(pnlOutputLayout);
pnlOutputLayout.setHorizontalGroup(
pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlOutputLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1)
.addContainerGap())
);
pnlOutputLayout.setVerticalGroup(
pnlOutputLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
);
jMenu1.setText("File");
mnuBar.add(jMenu1);
jMenu2.setText("Edit");
mnuBar.add(jMenu2);
setJMenuBar(mnuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pnlOutput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProgram, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(pnlProgram, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlOutput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExecuteActionPerformed
String code = txtareaProgram.getText();
BareBones myBareBones = new BareBones();
try {
String[] codeArray = myBareBones.getStringArray(code);
HashMap<String, Integer> variableArray = new HashMap<>();
int pointer = 0;
int line = 1;
int currentLoop = 0;
variableArray = myBareBones.readCode(codeArray, variableArray, pointer, line, currentLoop);
String output = myBareBones.readHashMap(variableArray);
txtareaOutput.setForeground(Color.BLACK);
txtareaOutput.setText(output);
} catch (LanguageException e) {
txtareaOutput.setForeground(Color.RED);
txtareaOutput.setText(e.getMessage());
}
}//GEN-LAST:event_btnExecuteActionPerformed
private void txtareaProgramKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtareaProgramKeyReleased
//More code from when I tried to turn it into a fully featured IDE
/*String code = txtareaProgram.getText();
String [] codeArray = myBareBones.getStringArray(code);
for
if (text.substring(wordL, wordR).matches("(\\W)*(private|public|protected)"))*/
}//GEN-LAST:event_txtareaProgramKeyReleased
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TheGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TheGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TheGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TheGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TheGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnExecute;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JMenuBar mnuBar;
private javax.swing.JPanel pnlOutput;
private javax.swing.JPanel pnlProgram;
private javax.swing.JTextPane txtareaOutput;
private javax.swing.JTextPane txtareaProgram;
// End of variables declaration//GEN-END:variables
}