|
| 1 | +/* |
| 2 | + * This file is part of Arduino. |
| 3 | + * |
| 4 | + * Arduino is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + * |
| 18 | + * As a special exception, you may use this file as part of a free software |
| 19 | + * library without restriction. Specifically, if other files instantiate |
| 20 | + * templates or use macros or inline functions from this file, or you compile |
| 21 | + * this file and link it with other files to produce an executable, this |
| 22 | + * file does not by itself cause the resulting executable to be covered by |
| 23 | + * the GNU General Public License. This exception does not however |
| 24 | + * invalidate any other reasons why the executable file might be covered by |
| 25 | + * the GNU General Public License. |
| 26 | + * |
| 27 | + * Copyright 2015 Arduino LLC (http://www.arduino.cc/) |
| 28 | + */ |
| 29 | + |
| 30 | +package cc.arduino.view; |
| 31 | + |
| 32 | +import processing.app.Base; |
| 33 | +import processing.app.Editor; |
| 34 | + |
| 35 | +import java.awt.event.WindowEvent; |
| 36 | + |
| 37 | +import static processing.app.I18n.tr; |
| 38 | + |
| 39 | +public class GoToLineNumber extends javax.swing.JDialog { |
| 40 | + |
| 41 | + private final Editor editor; |
| 42 | + |
| 43 | + public GoToLineNumber(Editor editor) { |
| 44 | + super(editor); |
| 45 | + this.editor = editor; |
| 46 | + initComponents(); |
| 47 | + |
| 48 | + Base.registerWindowCloseKeys(getRootPane(), this::cancelActionPerformed); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * This method is called from within the constructor to initialize the form. |
| 53 | + * WARNING: Do NOT modify this code. The content of this method is always |
| 54 | + * regenerated by the Form Editor. |
| 55 | + */ |
| 56 | + @SuppressWarnings("unchecked") |
| 57 | + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| 58 | + private void initComponents() { |
| 59 | + |
| 60 | + javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); |
| 61 | + lineNumber = new javax.swing.JTextField(); |
| 62 | + javax.swing.JButton cancel = new javax.swing.JButton(); |
| 63 | + javax.swing.JButton ok = new javax.swing.JButton(); |
| 64 | + |
| 65 | + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); |
| 66 | + setTitle(tr("Go to line")); |
| 67 | + setModal(true); |
| 68 | + setResizable(false); |
| 69 | + |
| 70 | + jLabel1.setText(tr("Line number:")); |
| 71 | + |
| 72 | + lineNumber.addActionListener(new java.awt.event.ActionListener() { |
| 73 | + public void actionPerformed(java.awt.event.ActionEvent evt) { |
| 74 | + lineNumberActionPerformed(evt); |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + cancel.setText(tr("Cancel")); |
| 79 | + cancel.addActionListener(new java.awt.event.ActionListener() { |
| 80 | + public void actionPerformed(java.awt.event.ActionEvent evt) { |
| 81 | + cancelActionPerformed(evt); |
| 82 | + } |
| 83 | + }); |
| 84 | + |
| 85 | + ok.setText(tr("OK")); |
| 86 | + ok.addActionListener(new java.awt.event.ActionListener() { |
| 87 | + public void actionPerformed(java.awt.event.ActionEvent evt) { |
| 88 | + okActionPerformed(evt); |
| 89 | + } |
| 90 | + }); |
| 91 | + |
| 92 | + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
| 93 | + getContentPane().setLayout(layout); |
| 94 | + layout.setHorizontalGroup( |
| 95 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 96 | + .addGroup(layout.createSequentialGroup() |
| 97 | + .addContainerGap() |
| 98 | + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 99 | + .addGroup(layout.createSequentialGroup() |
| 100 | + .addComponent(jLabel1) |
| 101 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| 102 | + .addComponent(lineNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)) |
| 103 | + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() |
| 104 | + .addGap(0, 0, Short.MAX_VALUE) |
| 105 | + .addComponent(ok) |
| 106 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| 107 | + .addComponent(cancel))) |
| 108 | + .addContainerGap()) |
| 109 | + ); |
| 110 | + layout.setVerticalGroup( |
| 111 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 112 | + .addGroup(layout.createSequentialGroup() |
| 113 | + .addContainerGap() |
| 114 | + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
| 115 | + .addComponent(jLabel1) |
| 116 | + .addComponent(lineNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) |
| 117 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
| 118 | + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
| 119 | + .addComponent(cancel) |
| 120 | + .addComponent(ok)) |
| 121 | + .addContainerGap()) |
| 122 | + ); |
| 123 | + |
| 124 | + pack(); |
| 125 | + }// </editor-fold>//GEN-END:initComponents |
| 126 | + |
| 127 | + private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed |
| 128 | + try { |
| 129 | + int line = Integer.parseInt(lineNumber.getText()); |
| 130 | + editor.goToLine(line); |
| 131 | + cancelActionPerformed(evt); |
| 132 | + } catch (Exception e) { |
| 133 | + // ignore |
| 134 | + } |
| 135 | + }//GEN-LAST:event_okActionPerformed |
| 136 | + |
| 137 | + private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed |
| 138 | + dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); |
| 139 | + }//GEN-LAST:event_cancelActionPerformed |
| 140 | + |
| 141 | + private void lineNumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lineNumberActionPerformed |
| 142 | + okActionPerformed(evt); |
| 143 | + }//GEN-LAST:event_lineNumberActionPerformed |
| 144 | + |
| 145 | + // Variables declaration - do not modify//GEN-BEGIN:variables |
| 146 | + private javax.swing.JTextField lineNumber; |
| 147 | + // End of variables declaration//GEN-END:variables |
| 148 | +} |
0 commit comments