/* MainGui.java */ package gui; import java.awt.Color; import java.awt.Desktop; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import javax.swing.AbstractAction; import javax.swing.ButtonGroup; import javax.swing.JFileChooser; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.KeyStroke; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.event.UndoableEditEvent; import javax.swing.event.UndoableEditListener; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.text.DefaultEditorKit; import javax.swing.text.JTextComponent; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoManager; import tools.FileIO; import tools.StrTools; import tools.SyntaxColorTools; /** * @author Jiangcheng Oliver Chu */ public class MainGui extends javax.swing.JFrame { //<editor-fold defaultstate="collapsed" desc="Class field declarations"> private static Process prcss = null; private TabManager tabManageObj = new TabManager(); private FileMenuManager fileManageObj = new FileMenuManager(); private FindReplaceManager findReplaceObj = new FindReplaceManager(); private Font textEditFont = new Font("Courier New", 0, 14); private ButtonGroup findTextDirectionButtonGroup; private ButtonGroup findTextDirectionButtonGroup2; private UndoManagerTeam undoManageTeam = new UndoManagerTeam(); private UndoAction undoActionObj = new UndoAction(); private RedoAction redoActionObj = new RedoAction(); private JMenuItem undoItem; private JMenuItem redoItem; private SyntaxColorTools sct = new SyntaxColorTools(); /** Use this class constructor to add startup actions. */ //<editor-fold defaultstate="collapsed" desc="Class constructor"> public MainGui() { super(); if (!System.getProperty("os.name").contains("Windows")) { textEditFont = new Font("FreeMono", 0, 14); } initComponents(); tabManageObj.addTab(); //<editor-fold defaultstate="collapsed" desc="Add buttongroups for Find/Replace"> findTextDirectionButtonGroup = new ButtonGroup(); findTextDirectionButtonGroup.add(searchUpRadioButton); findTextDirectionButtonGroup.add(searchDownRadioButton); findTextDirectionButtonGroup2 = new ButtonGroup(); findTextDirectionButtonGroup2.add(searchUpRadioButton2); findTextDirectionButtonGroup2.add(searchDownRadioButton2); //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Add Undo/Redo menu items"> undoItem = new JMenuItem(undoActionObj); undoItem.setText("Undo"); undoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK)); redoItem = new JMenuItem(redoActionObj); redoItem.setText("Redo"); redoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK)); editMenu.add(redoItem,0); editMenu.add(undoItem,0); //</editor-fold> } //</editor-fold> /** 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() { fileChooser = new javax.swing.JFileChooser(); findTextFrame = new javax.swing.JFrame(); searchForLabel = new javax.swing.JLabel(); query = new javax.swing.JTextField(); findTextButton = new javax.swing.JButton(); countOccurrencesButton = new javax.swing.JButton(); searchUpRadioButton = new javax.swing.JRadioButton(); searchDownRadioButton = new javax.swing.JRadioButton(); matchCaseCheckBox = new javax.swing.JCheckBox(); wrapDocumentAroundCheckBox = new javax.swing.JCheckBox(); findReplaceFrame = new javax.swing.JFrame(); searchForLabel2 = new javax.swing.JLabel(); query2 = new javax.swing.JTextField(); findTextButton2 = new javax.swing.JButton(); countOccurrencesButton2 = new javax.swing.JButton(); searchUpRadioButton2 = new javax.swing.JRadioButton(); searchDownRadioButton2 = new javax.swing.JRadioButton(); matchCaseCheckBox2 = new javax.swing.JCheckBox(); wrapDocumentAroundCheckBox2 = new javax.swing.JCheckBox(); replaceWithLabel = new javax.swing.JLabel(); replaceTextField = new javax.swing.JTextField(); replaceButton = new javax.swing.JButton(); replaceAllButton = new javax.swing.JButton(); changeFontFrame = new javax.swing.JFrame(); fontField = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); changeFontButton = new javax.swing.JButton(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem(); jMenu1 = new javax.swing.JMenu(); jMenuItem15 = new javax.swing.JMenuItem(); jMenuItem24 = new javax.swing.JMenuItem(); jPopupMenu1 = new javax.swing.JPopupMenu(); aboutFrame = new javax.swing.JFrame(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); gotoMintWebsiteOfficialButton = new javax.swing.JButton(); mainTabbedPane = new javax.swing.JTabbedPane(); topMenuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); newFileItem = new javax.swing.JMenuItem(); openFileItem = new javax.swing.JMenuItem(); saveFileItem = new javax.swing.JMenuItem(); saveFileAsItem = new javax.swing.JMenuItem(); separator1 = new javax.swing.JPopupMenu.Separator(); quitItem = new javax.swing.JMenuItem(); editMenu = new javax.swing.JMenu(); cutItem = new javax.swing.JMenuItem(); copyItem = new javax.swing.JMenuItem(); pasteItem = new javax.swing.JMenuItem(); selectAllItem = new javax.swing.JMenuItem(); separator2 = new javax.swing.JPopupMenu.Separator(); findTextItem = new javax.swing.JMenuItem(); findReplaceItem = new javax.swing.JMenuItem(); separator4 = new javax.swing.JPopupMenu.Separator(); changeFontItem = new javax.swing.JMenuItem(); zoomInItem = new javax.swing.JMenuItem(); zoomOutItem = new javax.swing.JMenuItem(); tabMenu = new javax.swing.JMenu(); newTabItem = new javax.swing.JMenuItem(); closeTabItem = new javax.swing.JMenuItem(); closeAllTabsItem = new javax.swing.JMenuItem(); separator3 = new javax.swing.JPopupMenu.Separator(); switchFirstTabItem = new javax.swing.JMenuItem(); switchLastTabItem = new javax.swing.JMenuItem(); mintMenu = new javax.swing.JMenu(); runTabAsMint = new javax.swing.JMenuItem(); jMenuItem8 = new javax.swing.JMenuItem(); runRuby = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem26 = new javax.swing.JMenuItem(); findTextFrame.setTitle("Find text"); searchForLabel.setText("Search for:"); query.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { queryKeyPressed(evt); } }); findTextButton.setText("Find it"); findTextButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findTextButtonActionPerformed(evt); } }); countOccurrencesButton.setText("Count Occurrences"); countOccurrencesButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { countOccurrencesButtonActionPerformed(evt); } }); searchUpRadioButton.setText("Search Up"); searchDownRadioButton.setSelected(true); searchDownRadioButton.setText("Search Down"); matchCaseCheckBox.setText("Match Case"); wrapDocumentAroundCheckBox.setSelected(true); wrapDocumentAroundCheckBox.setText("Wrap Document Around"); javax.swing.GroupLayout findTextFrameLayout = new javax.swing.GroupLayout(findTextFrame.getContentPane()); findTextFrame.getContentPane().setLayout(findTextFrameLayout); findTextFrameLayout.setHorizontalGroup( findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findTextFrameLayout.createSequentialGroup() .addContainerGap() .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findTextFrameLayout.createSequentialGroup() .addComponent(query, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE) .addContainerGap()) .addGroup(findTextFrameLayout.createSequentialGroup() .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchForLabel) .addGroup(findTextFrameLayout.createSequentialGroup() .addComponent(findTextButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(countOccurrencesButton)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, findTextFrameLayout.createSequentialGroup() .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchUpRadioButton) .addComponent(searchDownRadioButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(wrapDocumentAroundCheckBox) .addComponent(matchCaseCheckBox)))) .addGap(24, 24, 24)))) ); findTextFrameLayout.setVerticalGroup( findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findTextFrameLayout.createSequentialGroup() .addContainerGap() .addComponent(searchForLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(query, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(findTextButton) .addComponent(countOccurrencesButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(searchUpRadioButton) .addComponent(matchCaseCheckBox)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(findTextFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(searchDownRadioButton) .addComponent(wrapDocumentAroundCheckBox)) .addContainerGap(15, Short.MAX_VALUE)) ); findReplaceFrame.setTitle("Find and Replace Text"); searchForLabel2.setText("Search for:"); query2.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { query2KeyPressed(evt); } }); findTextButton2.setText("Find it"); findTextButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findTextButton2ActionPerformed(evt); } }); countOccurrencesButton2.setText("Count Occurrences"); countOccurrencesButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { countOccurrencesButton2ActionPerformed(evt); } }); searchUpRadioButton2.setText("Search Up"); searchDownRadioButton2.setSelected(true); searchDownRadioButton2.setText("Search Down"); matchCaseCheckBox2.setText("Match Case"); wrapDocumentAroundCheckBox2.setSelected(true); wrapDocumentAroundCheckBox2.setText("Wrap Document Around"); replaceWithLabel.setText("Replace With:"); replaceButton.setText("Replace Current"); replaceButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { replaceButtonActionPerformed(evt); } }); replaceAllButton.setText("Replace All"); replaceAllButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { replaceAllButtonActionPerformed(evt); } }); javax.swing.GroupLayout findReplaceFrameLayout = new javax.swing.GroupLayout(findReplaceFrame.getContentPane()); findReplaceFrame.getContentPane().setLayout(findReplaceFrameLayout); findReplaceFrameLayout.setHorizontalGroup( findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addContainerGap() .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchUpRadioButton2) .addComponent(searchDownRadioButton2)) .addGap(18, 18, 18) .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(wrapDocumentAroundCheckBox2) .addComponent(matchCaseCheckBox2)) .addContainerGap()) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(searchForLabel2) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addComponent(findTextButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(countOccurrencesButton2))) .addGap(24, 24, 24)) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addComponent(replaceWithLabel) .addContainerGap(209, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, findReplaceFrameLayout.createSequentialGroup() .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(replaceTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE) .addComponent(query2, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)) .addContainerGap()) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addComponent(replaceButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(replaceAllButton) .addContainerGap(74, Short.MAX_VALUE)))) ); findReplaceFrameLayout.setVerticalGroup( findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addContainerGap() .addComponent(searchForLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(query2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(findTextButton2) .addComponent(countOccurrencesButton2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(replaceWithLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(replaceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(replaceButton) .addComponent(replaceAllButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE) .addGroup(findReplaceFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addComponent(searchUpRadioButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(searchDownRadioButton2)) .addGroup(findReplaceFrameLayout.createSequentialGroup() .addComponent(matchCaseCheckBox2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(wrapDocumentAroundCheckBox2))) .addContainerGap()) ); changeFontFrame.setTitle("Change Font"); fontField.setText("Courier New"); jLabel1.setText("Font:"); jLabel2.setText("Suggested Windows Fonts: Courier New, Lucida Console, Consolas"); jLabel3.setText("Suggested Mac Fonts: Andale Mono, Monaco, Menlo "); jLabel4.setText("Suggested Linux Fonts: Andale Mono, Courier New, FreeMono, Nimbus Mono, DejaVu Sans Mono, Liberation Mono"); changeFontButton.setText("Change"); changeFontButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeFontButtonActionPerformed(evt); } }); javax.swing.GroupLayout changeFontFrameLayout = new javax.swing.GroupLayout(changeFontFrame.getContentPane()); changeFontFrame.getContentPane().setLayout(changeFontFrameLayout); changeFontFrameLayout.setHorizontalGroup( changeFontFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(changeFontFrameLayout.createSequentialGroup() .addContainerGap() .addGroup(changeFontFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(changeFontFrameLayout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(fontField, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(changeFontButton)) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); changeFontFrameLayout.setVerticalGroup( changeFontFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(changeFontFrameLayout.createSequentialGroup() .addContainerGap() .addGroup(changeFontFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(fontField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(changeFontButton)) .addGap(18, 18, 18) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jMenuItem2.setText("jMenuItem2"); jMenuItem4.setText("jMenuItem4"); jMenu1.setText("jMenu1"); jMenuItem15.setText("jMenuItem15"); jMenuItem24.setText("jMenuItem24"); jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel5.setForeground(new java.awt.Color(0, 102, 102)); jLabel5.setText("MintChime IDE"); jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel6.setText("A source code editor for multiple languages"); jLabel7.setText("For the latests updates, please check:"); gotoMintWebsiteOfficialButton.setText("http://www.oliverchu.com"); gotoMintWebsiteOfficialButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { gotoMintWebsiteOfficialButtonActionPerformed(evt); } }); javax.swing.GroupLayout aboutFrameLayout = new javax.swing.GroupLayout(aboutFrame.getContentPane()); aboutFrame.getContentPane().setLayout(aboutFrameLayout); aboutFrameLayout.setHorizontalGroup( aboutFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(aboutFrameLayout.createSequentialGroup() .addContainerGap() .addGroup(aboutFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel7) .addComponent(gotoMintWebsiteOfficialButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); aboutFrameLayout.setVerticalGroup( aboutFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(aboutFrameLayout.createSequentialGroup() .addContainerGap() .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(gotoMintWebsiteOfficialButton) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("MintChime Code Editor"); fileMenu.setText("File"); newFileItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK)); newFileItem.setText("New File"); newFileItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newFileItemActionPerformed(evt); } }); fileMenu.add(newFileItem); openFileItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK)); openFileItem.setText("Open File"); openFileItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { openFileItemActionPerformed(evt); } }); fileMenu.add(openFileItem); saveFileItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); saveFileItem.setText("Save File"); saveFileItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveFileItemActionPerformed(evt); } }); fileMenu.add(saveFileItem); saveFileAsItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); saveFileAsItem.setText("Save File As..."); saveFileAsItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveFileAsItemActionPerformed(evt); } }); fileMenu.add(saveFileAsItem); fileMenu.add(separator1); quitItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK)); quitItem.setText("Quit"); quitItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { quitItemActionPerformed(evt); } }); fileMenu.add(quitItem); topMenuBar.add(fileMenu); editMenu.setText("Edit"); cutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK)); cutItem.setText("Cut"); cutItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cutItemActionPerformed(evt); } }); editMenu.add(cutItem); copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK)); copyItem.setText("Copy"); copyItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { copyItemActionPerformed(evt); } }); editMenu.add(copyItem); pasteItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK)); pasteItem.setText("Paste"); pasteItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pasteItemActionPerformed(evt); } }); editMenu.add(pasteItem); selectAllItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); selectAllItem.setText("Select All"); selectAllItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { selectAllItemActionPerformed(evt); } }); editMenu.add(selectAllItem); editMenu.add(separator2); findTextItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK)); findTextItem.setText("Find..."); findTextItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findTextItemActionPerformed(evt); } }); editMenu.add(findTextItem); findReplaceItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK)); findReplaceItem.setText("Find / Replace..."); findReplaceItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findReplaceItemActionPerformed(evt); } }); editMenu.add(findReplaceItem); editMenu.add(separator4); changeFontItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); changeFontItem.setText("Change Font"); changeFontItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeFontItemActionPerformed(evt); } }); editMenu.add(changeFontItem); zoomInItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, java.awt.event.InputEvent.CTRL_MASK)); zoomInItem.setText("Zoom In"); zoomInItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { zoomInItemActionPerformed(evt); } }); editMenu.add(zoomInItem); zoomOutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, java.awt.event.InputEvent.CTRL_MASK)); zoomOutItem.setText("Zoom Out"); zoomOutItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { zoomOutItemActionPerformed(evt); } }); editMenu.add(zoomOutItem); topMenuBar.add(editMenu); tabMenu.setText("Tabs"); newTabItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK)); newTabItem.setText("New Tab"); newTabItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newTabItemActionPerformed(evt); } }); tabMenu.add(newTabItem); closeTabItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK)); closeTabItem.setText("Close Current Tab"); closeTabItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeTabItemActionPerformed(evt); } }); tabMenu.add(closeTabItem); closeAllTabsItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK)); closeAllTabsItem.setText("Close All Tabs"); closeAllTabsItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeAllTabsItemActionPerformed(evt); } }); tabMenu.add(closeAllTabsItem); tabMenu.add(separator3); switchFirstTabItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.CTRL_MASK)); switchFirstTabItem.setText("Switch to First Tab"); switchFirstTabItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { switchFirstTabItemActionPerformed(evt); } }); tabMenu.add(switchFirstTabItem); switchLastTabItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_9, java.awt.event.InputEvent.CTRL_MASK)); switchLastTabItem.setText("Switch to Last Tab"); switchLastTabItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { switchLastTabItemActionPerformed(evt); } }); tabMenu.add(switchLastTabItem); topMenuBar.add(tabMenu); mintMenu.setText("Programming"); runTabAsMint.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK)); runTabAsMint.setText("Run Current Tab as Mint Script"); runTabAsMint.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runTabAsMintActionPerformed(evt); } }); mintMenu.add(runTabAsMint); jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem8.setText("Attempt to Run Python Code"); jMenuItem8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem8ActionPerformed(evt); } }); mintMenu.add(jMenuItem8); runRuby.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); runRuby.setText("Attempt to Run Ruby Code"); runRuby.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runRubyActionPerformed(evt); } }); mintMenu.add(runRuby); topMenuBar.add(mintMenu); jMenu2.setText("About"); jMenuItem26.setText("About MintChime"); jMenuItem26.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem26ActionPerformed(evt); } }); jMenu2.add(jMenuItem26); topMenuBar.add(jMenu2); setJMenuBar(topMenuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 523, Short.MAX_VALUE) ); pack(); }// </editor-fold>//GEN-END:initComponents private void newTabItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTabItemActionPerformed tabManageObj.addTab(); }//GEN-LAST:event_newTabItemActionPerformed private void closeTabItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeTabItemActionPerformed tabManageObj.removeTab(tabManageObj.getCurrentTabIndex()); }//GEN-LAST:event_closeTabItemActionPerformed private void closeAllTabsItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeAllTabsItemActionPerformed mainTabbedPane.removeAll(); tabManageObj = new TabManager(); }//GEN-LAST:event_closeAllTabsItemActionPerformed private void switchFirstTabItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_switchFirstTabItemActionPerformed tabManageObj.switchToFirstTab(); }//GEN-LAST:event_switchFirstTabItemActionPerformed private void switchLastTabItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_switchLastTabItemActionPerformed tabManageObj.switchToLastTab(); }//GEN-LAST:event_switchLastTabItemActionPerformed private void cutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cutItemActionPerformed tabManageObj.getSelectedTextPane().cut(); }//GEN-LAST:event_cutItemActionPerformed private void copyItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyItemActionPerformed tabManageObj.getSelectedTextPane().copy(); }//GEN-LAST:event_copyItemActionPerformed private void pasteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteItemActionPerformed tabManageObj.getSelectedTextPane().paste(); }//GEN-LAST:event_pasteItemActionPerformed private void selectAllItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllItemActionPerformed tabManageObj.getSelectedTextPane().selectAll(); }//GEN-LAST:event_selectAllItemActionPerformed private void newFileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newFileItemActionPerformed tabManageObj.resetCurrentTab(); }//GEN-LAST:event_newFileItemActionPerformed private void quitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitItemActionPerformed System.exit(0); }//GEN-LAST:event_quitItemActionPerformed private void openFileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFileItemActionPerformed fileManageObj.runOpenDialog(); }//GEN-LAST:event_openFileItemActionPerformed private void saveFileAsItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveFileAsItemActionPerformed fileManageObj.runSaveAsDialog(tabManageObj.getSelectedTextPane().getText()); }//GEN-LAST:event_saveFileAsItemActionPerformed private void saveFileItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveFileItemActionPerformed fileManageObj.runSaveDialog(); }//GEN-LAST:event_saveFileItemActionPerformed private void queryKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_queryKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) findReplaceObj.findText(false); }//GEN-LAST:event_queryKeyPressed private void findTextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findTextButtonActionPerformed findReplaceObj.findText(false); }//GEN-LAST:event_findTextButtonActionPerformed private void countOccurrencesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_countOccurrencesButtonActionPerformed findReplaceObj.countOccurrences(false); }//GEN-LAST:event_countOccurrencesButtonActionPerformed private void query2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_query2KeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) findReplaceObj.findText(true); }//GEN-LAST:event_query2KeyPressed private void findTextButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findTextButton2ActionPerformed findReplaceObj.findText(true); }//GEN-LAST:event_findTextButton2ActionPerformed private void countOccurrencesButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_countOccurrencesButton2ActionPerformed findReplaceObj.countOccurrences(false); }//GEN-LAST:event_countOccurrencesButton2ActionPerformed private void replaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceButtonActionPerformed findReplaceObj.replaceCurrent(); }//GEN-LAST:event_replaceButtonActionPerformed private void replaceAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceAllButtonActionPerformed findReplaceObj.replaceAll(); }//GEN-LAST:event_replaceAllButtonActionPerformed private void findTextItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findTextItemActionPerformed findTextFrame.pack(); findTextFrame.setVisible(true); }//GEN-LAST:event_findTextItemActionPerformed private void findReplaceItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findReplaceItemActionPerformed findReplaceFrame.pack(); findReplaceFrame.setVisible(true); }//GEN-LAST:event_findReplaceItemActionPerformed private void changeFontItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeFontItemActionPerformed changeFontFrame.pack(); changeFontFrame.setVisible(true); }//GEN-LAST:event_changeFontItemActionPerformed private void changeFontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeFontButtonActionPerformed tabManageObj.setFont(new Font(fontField.getText(), 0, 13)); Dialog.msgBox("Font changed."); }//GEN-LAST:event_changeFontButtonActionPerformed private void runTabAsMintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runTabAsMintActionPerformed try { Mint.mux(tabManageObj.getSelectedTextPane().getText()); } catch (Throwable t) { JOptionPane.showMessageDialog(null, "Exception Thrown: " + t, "Mint Language Exception", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_runTabAsMintActionPerformed private void zoomInItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomInItemActionPerformed Font current = tabManageObj.getSelectedTextPane().getFont(); String name = current.getName(); int size = current.getSize(); size += 3; tabManageObj.getSelectedTextPane().setFont(new Font(name, 0, size)); }//GEN-LAST:event_zoomInItemActionPerformed private void zoomOutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomOutItemActionPerformed Font current = tabManageObj.getSelectedTextPane().getFont(); String name = current.getName(); int size = current.getSize(); if (size > 7) { size -= 3; tabManageObj.getSelectedTextPane().setFont(new Font(name, 0, size)); } }//GEN-LAST:event_zoomOutItemActionPerformed private void jMenuItem26ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem26ActionPerformed aboutFrame.setResizable(false); aboutFrame.pack(); aboutFrame.setVisible(true); }//GEN-LAST:event_jMenuItem26ActionPerformed private void gotoMintWebsiteOfficialButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gotoMintWebsiteOfficialButtonActionPerformed URI uri = null; String u = "?"; try { u = "http://www.oliverchu.com/"; uri = new URI(u); } catch (URISyntaxException ex) { JOptionPane.showMessageDialog(null, "Bad URI syntax: " + u, "Java Exception", JOptionPane.ERROR_MESSAGE); } try { Desktop.getDesktop().browse(uri); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Bad connection while opening URI:" + u, "Java Exception", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_gotoMintWebsiteOfficialButtonActionPerformed private void runRubyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runRubyActionPerformed FileIO.strToTextFile(tabManageObj.getSelectedTextPane().getText(), "__rb_gem__.rb"); try { prcss = Runtime.getRuntime().exec("irb __rb_gem__.rb"); } catch (IOException ex) {} }//GEN-LAST:event_runRubyActionPerformed private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed FileIO.strToTextFile("" + tabManageObj.getSelectedTextPane().getText().hashCode(), "__py_lang__.pyc"); }//GEN-LAST:event_jMenuItem8ActionPerformed //<editor-fold defaultstate="collapsed" desc="Private class FileMenuManager"> private class FileMenuManager { private void runOpenDialog() { setFileFilterToTextFiles(); String workingDir = System.getProperty("user.dir"); File currentDirObj = new File(workingDir); fileChooser.setCurrentDirectory(currentDirObj); int buttonChoice = fileChooser.showOpenDialog(null); if (buttonChoice == JFileChooser.APPROVE_OPTION) { File fileObj = fileChooser.getSelectedFile(); if (!fileObj.exists()) Dialog.errorBox("That file doesn't exist.", true); String filePath = fileObj.getPath(); String fileContents = FileIO.textFileToStr(filePath); tabManageObj.setCurrentFilePath(filePath); tabManageObj.getSelectedTextPane().setText(fileContents); String fileName = FileIO.fullPathToFileName(filePath); tabManageObj.setCurrentTabTitle(fileName); } } private void setFileFilterToTextFiles() { fileChooser.resetChoosableFileFilters(); /* FileNameExtensionFilter textFileFilter = new FileNameExtensionFilter("Java File (.java)","java"); FileNameExtensionFilter textFileFilter2 = new FileNameExtensionFilter("Text File (.txt)","txt"); fileChooser.addChoosableFileFilter(textFileFilter2); fileChooser.addChoosableFileFilter(textFileFilter); */ } private void runSaveAsDialog(String textContents) { setFileFilterToTextFiles(); //Get the directory where the program is running from. String currentWorkingDir = System.getProperty("user.dir"); File currentDirObj = new File(currentWorkingDir); fileChooser.setCurrentDirectory(currentDirObj); int buttonChoice = fileChooser.showSaveDialog(null); if (buttonChoice == JFileChooser.APPROVE_OPTION) { File fileObj = fileChooser.getSelectedFile(); if (fileObj.exists()) { if (!Dialog.askBox("Replace selected file: " + fileObj.getName() + "?")) { //Return if the user doesn't want to replace the file. return; } } String filePath = fileObj.getPath(); filePath = FileIO.addFileExtensionIfNeeded(filePath,".txt"); FileIO.strToTextFile(textContents,filePath); tabManageObj.setCurrentFilePath(filePath); String fileName = FileIO.fullPathToFileName(filePath); tabManageObj.setCurrentTabTitle(fileName); // setSavedFile(); } } private void runSaveDialog() { String filePath = tabManageObj.getCurrentFilePath(); String text = tabManageObj.getSelectedTextPane().getText(); if (filePath.isEmpty()) { runSaveAsDialog(text); return; } setFileFilterToTextFiles(); FileIO.strToTextFile(text,filePath); // setSavedFile(); } } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Private class TabManager"> private class TabManager { //<editor-fold defaultstate="collapsed" desc="Field declarations"> private ArrayList<JScrollPane> tabList = new ArrayList<JScrollPane>(); private ArrayList<JTextPane> textPaneList = new ArrayList<JTextPane>(); private ArrayList<String> filesBeingEdited = new ArrayList<String>(); private ArrayList<CustomUndoableEditListener> editListeners = new ArrayList<CustomUndoableEditListener>(); //</editor-fold> public void setFont(Font f) { for (JTextPane jtp : textPaneList) { jtp.setFont(f); } } private class KeyManager implements KeyListener { JTextPane tPane; public KeyManager(JTextPane tp) { tPane = tp; } @Override public void keyTyped(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) { new SyntaxColorTools().styleJavaCodeInDocument(tPane, 0); } @Override public void keyReleased(KeyEvent e) {} } //<editor-fold defaultstate="collapsed" desc="Tab methods"> private void addTab() { JScrollPane newScrollPane = new JScrollPane(); JTextPane newTextPane = new JTextPane(); newTextPane.setBackground(Color.BLACK); newTextPane.setForeground(Color.WHITE); newTextPane.setCaretColor(Color.WHITE); tools.SyntaxColorTools.addStylesToTextPane(newTextPane); newTextPane.addKeyListener(new KeyManager(newTextPane)); newScrollPane.setViewportView(newTextPane); textPaneList.add(newTextPane); tabList.add(newScrollPane); mainTabbedPane.addTab("New File",newScrollPane); filesBeingEdited.add(""); undoManageTeam.addManager(); editListeners.add(new CustomUndoableEditListener()); addPropertiesToTextPane(newTextPane); switchToLastTab(); } void removeTab(int index) { if (isInBounds(index)) { mainTabbedPane.remove(index); tabList.remove(index); textPaneList.remove(index); filesBeingEdited.remove(index); undoManageTeam.removeManager(index); editListeners.remove(index); } } void resetCurrentTab() { if (getTabCount() == 0) { addTab(); return; } getSelectedTextPane().setText(""); setCurrentTabTitle("New File"); setCurrentFilePath(""); } int getTabCount() { return tabList.size(); } int getCurrentTabIndex() { return mainTabbedPane.getSelectedIndex(); } boolean isInBounds(int tabIndex) { return (tabIndex >= 0 && tabIndex < getTabCount()); } void switchToLastTab() { int index = getTabCount() - 1; if (isInBounds(index)) mainTabbedPane.setSelectedIndex(index); } void switchToFirstTab() { if (isInBounds(0)) mainTabbedPane.setSelectedIndex(0); } void setCurrentTabTitle(String title) { mainTabbedPane.setTitleAt(getCurrentTabIndex(),title); } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="File name methods"> private void setFilePathAt(int index,String name) { if (isInBounds(index)) filesBeingEdited.set(index,name); } private void setCurrentFilePath(String name) { setFilePathAt(getCurrentTabIndex(),name); } private String getFilePathAt(int index) { if (isInBounds(index)) return filesBeingEdited.get(index); return ""; } private String getCurrentFilePath() { return getFilePathAt(getCurrentTabIndex()); } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="TextPane methods"> private JTextPane getTextPaneAt(int index) { return textPaneList.get(index); } private JTextPane getSelectedTextPane() { if (getTabCount() == 0) { addTab(); return textPaneList.get(0); } return textPaneList.get(getCurrentTabIndex()); } private void addPropertiesToTextPane(JTextPane textPane) { textPane.setFont(textEditFont); //Remove the default Ctrl + H action because we want to use that for //the Find / Replace keyboard shortcut (accelerator). textPane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK),"none"); //Remove the \r\n feature of the textPane and use \n only. //Despite various rumors on the Internet that you need to call this //every keypress or so, this is not true. Do it once and you're done. textPane.getDocument(). putProperty(DefaultEditorKit.EndOfLineStringProperty,"\n"); //TODO : GIVE EACH TEXTPANE ITS OWN editListenObj. int lastIndex = editListeners.size() - 1; textPane.getDocument().addUndoableEditListener( editListeners.get(lastIndex)); // textPane.addFocusListener(new FocusAdapter() { // @Override // public void focusGained(FocusEvent evt) { // focusManageObj.currentTextPaneFocused(); // } // }); } private void focusCurrentTextPane() { getSelectedTextPane().requestFocusInWindow(); } //</editor-fold> } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Private class UndoManagerTeam"> private class UndoManagerTeam { private ArrayList<UndoManager> undoManageTeam = new ArrayList<UndoManager>(); private void addManager() { undoManageTeam.add(new UndoManager()); } private void removeManager(int index) { undoManageTeam.remove(index); } private UndoManager getCurrentManager() { int currentIndex = tabManageObj.getCurrentTabIndex(); return undoManageTeam.get(currentIndex); } } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Private class FindReplaceManager"> private class FindReplaceManager { private void findText(boolean isUsingSecondQuery) { String queryText; if (isUsingSecondQuery) queryText = query2.getText(); else queryText = query.getText(); if (queryText.isEmpty()) { Dialog.msgBox("Please specify some text to find."); return; } boolean isSearchingDownward; boolean isCaseSensitive; boolean isWrappedDocument; if (isUsingSecondQuery) { isSearchingDownward = searchDownRadioButton2.isSelected(); isCaseSensitive = matchCaseCheckBox2.isSelected(); isWrappedDocument = wrapDocumentAroundCheckBox2.isSelected(); } else { isSearchingDownward = searchDownRadioButton.isSelected(); isCaseSensitive = matchCaseCheckBox.isSelected(); isWrappedDocument = wrapDocumentAroundCheckBox.isSelected(); } JTextPane currentPane = tabManageObj.getSelectedTextPane(); findAndSelectTextInTextComponent(currentPane,queryText, isWrappedDocument,isCaseSensitive, isSearchingDownward); } private void countOccurrences(boolean isUsingSecondQuery) { String queryText; if (isUsingSecondQuery) queryText = query2.getText(); else queryText = query.getText(); boolean isIgnoringCase; if (isUsingSecondQuery) isIgnoringCase = !matchCaseCheckBox2.isSelected(); else isIgnoringCase = !matchCaseCheckBox.isSelected(); int occurrences = StrTools.countOccurrences( tabManageObj.getSelectedTextPane().getText(), queryText,isIgnoringCase); Dialog.msgBox("Found "+occurrences+" occurrences of\n\""+queryText+ "\" in this document."); } private void replaceCurrent() { JTextComponent currentComponent = tabManageObj.getSelectedTextPane(); String selectedText = tabManageObj.getSelectedTextPane().getSelectedText(); if (selectedText == null) return; if (selectedText.equalsIgnoreCase(query2.getText())) currentComponent.replaceSelection(replaceTextField.getText()); } private void replaceAll() { JTextComponent currentComponent = tabManageObj.getSelectedTextPane(); String replacementText = replaceTextField.getText(); String targetText = query2.getText(); if (targetText.isEmpty()) return; int targetTextLength = targetText.length(); if (matchCaseCheckBox2.isSelected()) { if (targetText.equals(replacementText)) return; String text = currentComponent.getText(); currentComponent.setText(text.replace(targetText,replacementText)); } else { if (targetText.equalsIgnoreCase(replacementText)) return; String newText = currentComponent.getText(); int position = 0; while (position < newText.length()) { position = StrTools.searchIgnoreCase(newText,position, targetText); if (position == -1) break; newText = StrTools.slice(newText,0,position) + replacementText + StrTools.slice(newText,position+targetTextLength); position += targetTextLength + 1; } currentComponent.setText(newText); } } private void findAndSelectTextInTextComponent(JTextComponent component, String textToFind, boolean isWrappedDocument,boolean isCaseSensitive, boolean isDirectionDown) { int currentPosition = component.getCaretPosition(); int foundPosition = findTextInTextComponent(component,textToFind, currentPosition,isWrappedDocument, isCaseSensitive,isDirectionDown); if (foundPosition == -1 && !isWrappedDocument) { String textBoxContents = component.getText(); boolean doesQueryExistInDocumentIgnoringCase = (!StrTools.containsIgnoreCase(textBoxContents,textToFind) && !isCaseSensitive); boolean doesQueryExistInDocumentWithCase = (!textBoxContents.contains(textToFind) && isCaseSensitive); if (doesQueryExistInDocumentIgnoringCase || doesQueryExistInDocumentWithCase) { Dialog.msgBox("Cannot find \""+textToFind+"\" inside this\n"+ "this document."); } else { if (isDirectionDown) Dialog.msgBox("Reached end of document."); else Dialog.msgBox("Reached beginning of document."); } } else if (foundPosition == -1) { //We know the document must be wrapped. We really can't find the //text: Dialog.msgBox("Cannot find \""+textToFind+"\" inside this\n"+ "this document."); } else { //We successfully found the text. Select it: int endPosition = foundPosition+textToFind.length(); // //We must focus the textBox or else we cannot see what we will // //be selecting: tabManageObj.focusCurrentTextPane(); if (isDirectionDown) { component.setCaretPosition(foundPosition); component.moveCaretPosition(endPosition); } else { component.setCaretPosition(endPosition); component.moveCaretPosition(foundPosition); } } } /** Finds the specified text inside a text component. Will return -1 * if the text is not found. */ private int findTextInTextComponent(JTextComponent component, String textToFind,int startPos,boolean isWrappedDocument, boolean isCaseSensitive,boolean isDirectionDown) { int foundIndex; String text = component.getText(); if (isDirectionDown) { if (isCaseSensitive) foundIndex = StrTools.search(text,startPos,textToFind); else foundIndex = StrTools.searchIgnoreCase(text,startPos, textToFind); } else { int newStartPos = startPos - 1; if (newStartPos <= 0) newStartPos = startPos; if (isCaseSensitive) { foundIndex = StrTools.searchBackwards(text,newStartPos, textToFind); } else { foundIndex = StrTools.searchBackwardsIgnoreCase(text, newStartPos,textToFind); } } if (foundIndex == -1 && isWrappedDocument && isDirectionDown) { if (isCaseSensitive) foundIndex = StrTools.search(text,0,textToFind); else foundIndex = StrTools.searchIgnoreCase(text,0,textToFind); } else if (foundIndex == -1 && isWrappedDocument) { //We know that the searching is upward because we already checked //if it was downward and disproved that. if (isCaseSensitive) foundIndex = StrTools.searchBackwards(text,textToFind); else foundIndex = StrTools.searchBackwardsIgnoreCase(text, textToFind); } return foundIndex; } } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Private class CustomUndoableEditListener"> private class CustomUndoableEditListener implements UndoableEditListener { @Override public void undoableEditHappened(UndoableEditEvent event) { undoManageTeam.getCurrentManager().addEdit(event.getEdit()); } }//END CLASS Undoable Edit Listener //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Private classes UndoAction and RedoAction"> private class UndoAction extends AbstractAction { @Override public void actionPerformed(ActionEvent event) { try { UndoManager currentManager = undoManageTeam.getCurrentManager(); if (currentManager.canUndo()) currentManager.undo(); } catch (CannotUndoException exceptionInfo) { //Ignore the exception. } } } private class RedoAction extends AbstractAction { @Override public void actionPerformed(ActionEvent event) { try { UndoManager currentManager = undoManageTeam.getCurrentManager(); if (currentManager.canRedo()) currentManager.redo(); } catch (CannotRedoException exceptionInfo) { //Ignore the exception. } } } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="The mux method (called on startup of application)"> /** * @param args the command line arguments */ public static void main(String args[]) { //<editor-fold defaultstate="collapsed" desc="Set the application's look and feel."> try { // Set the system look and feel. // (Windows theme for windows, Mac theme for Macs...) UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { // Ignore this exception. Default Java look & feel // will be loaded. } catch (ClassNotFoundException e) { // Ignore this exception. Default Java look & feel // will be loaded. } catch (InstantiationException e) { // Ignore this exception. Default Java look & feel // will be loaded. } catch (IllegalAccessException e) { // Ignore this exception. Default Java look & feel // will be loaded. } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Create and display the GUI."> java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new MainGui().setVisible(true); } }); //</editor-fold> } //</editor-fold> // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JFrame aboutFrame; private javax.swing.JButton changeFontButton; private javax.swing.JFrame changeFontFrame; private javax.swing.JMenuItem changeFontItem; private javax.swing.JMenuItem closeAllTabsItem; private javax.swing.JMenuItem closeTabItem; private javax.swing.JMenuItem copyItem; private javax.swing.JButton countOccurrencesButton; private javax.swing.JButton countOccurrencesButton2; private javax.swing.JMenuItem cutItem; private javax.swing.JMenu editMenu; private javax.swing.JFileChooser fileChooser; private javax.swing.JMenu fileMenu; private javax.swing.JFrame findReplaceFrame; private javax.swing.JMenuItem findReplaceItem; private javax.swing.JButton findTextButton; private javax.swing.JButton findTextButton2; private javax.swing.JFrame findTextFrame; private javax.swing.JMenuItem findTextItem; private javax.swing.JTextField fontField; private javax.swing.JButton gotoMintWebsiteOfficialButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuItem jMenuItem15; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem24; private javax.swing.JMenuItem jMenuItem26; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JMenuItem jMenuItem8; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JTabbedPane mainTabbedPane; private javax.swing.JCheckBox matchCaseCheckBox; private javax.swing.JCheckBox matchCaseCheckBox2; private javax.swing.JMenu mintMenu; private javax.swing.JMenuItem newFileItem; private javax.swing.JMenuItem newTabItem; private javax.swing.JMenuItem openFileItem; private javax.swing.JMenuItem pasteItem; private javax.swing.JTextField query; private javax.swing.JTextField query2; private javax.swing.JMenuItem quitItem; private javax.swing.JButton replaceAllButton; private javax.swing.JButton replaceButton; private javax.swing.JTextField replaceTextField; private javax.swing.JLabel replaceWithLabel; private javax.swing.JMenuItem runRuby; private javax.swing.JMenuItem runTabAsMint; private javax.swing.JMenuItem saveFileAsItem; private javax.swing.JMenuItem saveFileItem; private javax.swing.JRadioButton searchDownRadioButton; private javax.swing.JRadioButton searchDownRadioButton2; private javax.swing.JLabel searchForLabel; private javax.swing.JLabel searchForLabel2; private javax.swing.JRadioButton searchUpRadioButton; private javax.swing.JRadioButton searchUpRadioButton2; private javax.swing.JMenuItem selectAllItem; private javax.swing.JPopupMenu.Separator separator1; private javax.swing.JPopupMenu.Separator separator2; private javax.swing.JPopupMenu.Separator separator3; private javax.swing.JPopupMenu.Separator separator4; private javax.swing.JMenuItem switchFirstTabItem; private javax.swing.JMenuItem switchLastTabItem; private javax.swing.JMenu tabMenu; private javax.swing.JMenuBar topMenuBar; private javax.swing.JCheckBox wrapDocumentAroundCheckBox; private javax.swing.JCheckBox wrapDocumentAroundCheckBox2; private javax.swing.JMenuItem zoomInItem; private javax.swing.JMenuItem zoomOutItem; // End of variables declaration//GEN-END:variables }