Add copy/cut/paste menus to Editor, move Language selector to Run menu, move clear button

master
skylarmt 10 years ago
parent b733d695f5
commit 15b70aa227

@ -108,15 +108,55 @@
<Property name="text" type="java.lang.String" value="Edit"/> <Property name="text" type="java.lang.String" value="Edit"/>
</Properties> </Properties>
<SubComponents> <SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="clrOutputMenu"> <MenuItem class="javax.swing.JMenuItem" name="copyBtn">
<Properties> <Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor"> <Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+W"/> <KeyStroke key="Ctrl+C"/>
</Property> </Property>
<Property name="text" type="java.lang.String" value="Clear output"/> <Property name="text" type="java.lang.String" value="Copy"/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clrOutputMenuActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="copyBtnActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="cutBtn">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+X"/>
</Property>
<Property name="text" type="java.lang.String" value="Cut"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cutBtnActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="pasteBtn">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+V"/>
</Property>
<Property name="text" type="java.lang.String" value="Paste"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="pasteBtnActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="runMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Run"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="runCodeBtn">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="F5"/>
</Property>
<Property name="text" type="java.lang.String" value="Run code"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runCodeBtnActionPerformed"/>
</Events> </Events>
</MenuItem> </MenuItem>
<Menu class="javax.swing.JMenu" name="codeLangMenu"> <Menu class="javax.swing.JMenu" name="codeLangMenu">
@ -151,24 +191,6 @@
</Menu> </Menu>
</SubComponents> </SubComponents>
</Menu> </Menu>
<Menu class="javax.swing.JMenu" name="runMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Run"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="runCodeBtn">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="F5"/>
</Property>
<Property name="text" type="java.lang.String" value="Run code"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runCodeBtnActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents> </SubComponents>
</Menu> </Menu>
</NonVisualComponents> </NonVisualComponents>
@ -256,7 +278,8 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
<Component id="clearBtn" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Component id="jScrollPane1" pref="532" max="32767" attributes="0"/> <Component id="jScrollPane1" pref="532" max="32767" attributes="0"/>
</Group> </Group>
@ -264,9 +287,12 @@
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="98" max="32767" attributes="0"/> <Component id="clearBtn" min="-2" pref="18" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="100" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -298,6 +324,15 @@
</Component> </Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Component class="javax.swing.JButton" name="clearBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Clear"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clearBtnActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="editPanel"> <Container class="javax.swing.JPanel" name="editPanel">

@ -149,6 +149,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
outputBox = new javax.swing.JTextArea(); outputBox = new javax.swing.JTextArea();
clearBtn = new javax.swing.JButton();
editPanel = new javax.swing.JPanel(); editPanel = new javax.swing.JPanel();
jMenuBar1 = new javax.swing.JMenuBar(); jMenuBar1 = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu(); fileMenu = new javax.swing.JMenu();
@ -160,12 +161,14 @@ public class CodeEditor extends javax.swing.JInternalFrame {
saveAsMenu = new javax.swing.JMenuItem(); saveAsMenu = new javax.swing.JMenuItem();
exportMenu = new javax.swing.JMenuItem(); exportMenu = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu(); editMenu = new javax.swing.JMenu();
clrOutputMenu = new javax.swing.JMenuItem(); copyBtn = new javax.swing.JMenuItem();
cutBtn = new javax.swing.JMenuItem();
pasteBtn = new javax.swing.JMenuItem();
runMenu = new javax.swing.JMenu();
runCodeBtn = new javax.swing.JMenuItem();
codeLangMenu = new javax.swing.JMenu(); codeLangMenu = new javax.swing.JMenu();
javascriptOption = new javax.swing.JRadioButtonMenuItem(); javascriptOption = new javax.swing.JRadioButtonMenuItem();
pythonOption = new javax.swing.JRadioButtonMenuItem(); pythonOption = new javax.swing.JRadioButtonMenuItem();
runMenu = new javax.swing.JMenu();
runCodeBtn = new javax.swing.JMenuItem();
jMenuItem4.setText("jMenuItem4"); jMenuItem4.setText("jMenuItem4");
@ -207,21 +210,32 @@ public class CodeEditor extends javax.swing.JInternalFrame {
}); });
jScrollPane1.setViewportView(outputBox); jScrollPane1.setViewportView(outputBox);
clearBtn.setText("Clear");
clearBtn.setToolTipText("");
clearBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout outputPanelLayout = new javax.swing.GroupLayout(outputPanel); javax.swing.GroupLayout outputPanelLayout = new javax.swing.GroupLayout(outputPanel);
outputPanel.setLayout(outputPanelLayout); outputPanel.setLayout(outputPanelLayout);
outputPanelLayout.setHorizontalGroup( outputPanelLayout.setHorizontalGroup(
outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outputPanelLayout.createSequentialGroup() .addGroup(outputPanelLayout.createSequentialGroup()
.addComponent(jLabel1) .addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clearBtn))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
); );
outputPanelLayout.setVerticalGroup( outputPanelLayout.setVerticalGroup(
outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outputPanelLayout.createSequentialGroup() .addGroup(outputPanelLayout.createSequentialGroup()
.addComponent(jLabel1) .addGroup(outputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)) .addComponent(clearBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, 0)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
); );
jSplitPane1.setRightComponent(outputPanel); jSplitPane1.setRightComponent(outputPanel);
@ -302,14 +316,45 @@ public class CodeEditor extends javax.swing.JInternalFrame {
editMenu.setText("Edit"); editMenu.setText("Edit");
clrOutputMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK)); copyBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
clrOutputMenu.setText("Clear output"); copyBtn.setText("Copy");
clrOutputMenu.addActionListener(new java.awt.event.ActionListener() { copyBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
copyBtnActionPerformed(evt);
}
});
editMenu.add(copyBtn);
cutBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
cutBtn.setText("Cut");
cutBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cutBtnActionPerformed(evt);
}
});
editMenu.add(cutBtn);
pasteBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
pasteBtn.setText("Paste");
pasteBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pasteBtnActionPerformed(evt);
}
});
editMenu.add(pasteBtn);
jMenuBar1.add(editMenu);
runMenu.setText("Run");
runCodeBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
runCodeBtn.setText("Run code");
runCodeBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
clrOutputMenuActionPerformed(evt); runCodeBtnActionPerformed(evt);
} }
}); });
editMenu.add(clrOutputMenu); runMenu.add(runCodeBtn);
codeLangMenu.setText("Language"); codeLangMenu.setText("Language");
@ -332,20 +377,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
}); });
codeLangMenu.add(pythonOption); codeLangMenu.add(pythonOption);
editMenu.add(codeLangMenu); runMenu.add(codeLangMenu);
jMenuBar1.add(editMenu);
runMenu.setText("Run");
runCodeBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
runCodeBtn.setText("Run code");
runCodeBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
runCodeBtnActionPerformed(evt);
}
});
runMenu.add(runCodeBtn);
jMenuBar1.add(runMenu); jMenuBar1.add(runMenu);
@ -515,17 +547,12 @@ public class CodeEditor extends javax.swing.JInternalFrame {
} }
} }
private void clrOutputMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clrOutputMenuActionPerformed
outputBox.setText("");
}//GEN-LAST:event_clrOutputMenuActionPerformed
private void exportMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportMenuActionPerformed private void exportMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportMenuActionPerformed
String lang = "js"; String lang = "js";
if (pythonOption.isSelected()) { if (pythonOption.isSelected()) {
lang = "python"; lang = "python";
} }
CodeExport ce = new CodeExport(codeBox.getText(), lang); MainGUI.loadFrame(new CodeExport(codeBox.getText(), lang));
MainGUI.loadFrame(ce);
}//GEN-LAST:event_exportMenuActionPerformed }//GEN-LAST:event_exportMenuActionPerformed
private void javascriptOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javascriptOptionActionPerformed private void javascriptOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javascriptOptionActionPerformed
@ -552,6 +579,22 @@ public class CodeEditor extends javax.swing.JInternalFrame {
openSample("graph"); openSample("graph");
}//GEN-LAST:event_sampleGraphActionPerformed }//GEN-LAST:event_sampleGraphActionPerformed
private void pasteBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteBtnActionPerformed
codeBox.paste();
}//GEN-LAST:event_pasteBtnActionPerformed
private void copyBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyBtnActionPerformed
codeBox.copy();
}//GEN-LAST:event_copyBtnActionPerformed
private void cutBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cutBtnActionPerformed
codeBox.cut();
}//GEN-LAST:event_cutBtnActionPerformed
private void clearBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearBtnActionPerformed
outputBox.setText("");
}//GEN-LAST:event_clearBtnActionPerformed
/** /**
* Open a sample code file with the given name.<p> * Open a sample code file with the given name.<p>
* Uses the current language. * Uses the current language.
@ -619,8 +662,10 @@ public class CodeEditor extends javax.swing.JInternalFrame {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem clrOutputMenu; private javax.swing.JButton clearBtn;
private javax.swing.JMenu codeLangMenu; private javax.swing.JMenu codeLangMenu;
private javax.swing.JMenuItem copyBtn;
private javax.swing.JMenuItem cutBtn;
private javax.swing.JMenu editMenu; private javax.swing.JMenu editMenu;
private javax.swing.JPanel editPanel; private javax.swing.JPanel editPanel;
private javax.swing.JMenuItem exportMenu; private javax.swing.JMenuItem exportMenu;
@ -640,6 +685,7 @@ public class CodeEditor extends javax.swing.JInternalFrame {
private javax.swing.JMenu openSampleBtn; private javax.swing.JMenu openSampleBtn;
private javax.swing.JTextArea outputBox; private javax.swing.JTextArea outputBox;
private javax.swing.JPanel outputPanel; private javax.swing.JPanel outputPanel;
private javax.swing.JMenuItem pasteBtn;
private javax.swing.JRadioButtonMenuItem pythonOption; private javax.swing.JRadioButtonMenuItem pythonOption;
private javax.swing.JMenuItem runCodeBtn; private javax.swing.JMenuItem runCodeBtn;
private javax.swing.JMenu runMenu; private javax.swing.JMenu runMenu;

Loading…
Cancel
Save