agent/src/share/classes/sun/jvm/hotspot/ui/CommandProcessorPanel.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 7088955 Sdiff agent/src/share/classes/sun/jvm/hotspot/ui

agent/src/share/classes/sun/jvm/hotspot/ui/CommandProcessorPanel.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  71         cp.setErr(o);
  72 
  73         editor.getDocument().addDocumentListener(new DocumentListener() {
  74                 public void changedUpdate(DocumentEvent e) {
  75                 }
  76 
  77                 public void insertUpdate(DocumentEvent e) {
  78                     if (updating) return;
  79                     beginUpdate();
  80                     editor.setCaretPosition(editor.getDocument().getLength());
  81                     if (insertContains(e, '\n')) {
  82                         String cmd = getMarkedText();
  83                         // Handle multi-line input
  84                         if ((cmd.length() == 0) || (cmd.charAt(cmd.length() - 1) != '\\')) {
  85                             // Trim "\\n" combinations
  86                             final String ln = trimContinuations(cmd);
  87                             SwingUtilities.invokeLater(new Runnable() {
  88                                     public void run() {
  89                                         beginUpdate();
  90                                         try {
  91                                             commands.executeCommand(ln);
  92                                             commands.printPrompt();
  93                                             Document d = editor.getDocument();
  94                                             try {
  95                                                 d.insertString(d.getLength(), baos.toString(), null);
  96                                             }
  97                                             catch (BadLocationException ble) {
  98                                                 ble.printStackTrace();
  99                                             }
 100                                             baos.reset();
 101                                             editor.setCaretPosition(editor.getDocument().getLength());
 102                                             setMark();
 103                                         } finally {
 104                                             endUpdate();
 105                                         }
 106                                     }
 107                                 });
 108                         }
 109                     } else {
 110                         endUpdate();
 111                     }


 132         JButton button = new JButton("Clear Saved Text");
 133         button.addActionListener(new ActionListener() {
 134                 public void actionPerformed(ActionEvent e) {
 135                     clear();
 136                 }
 137             });
 138         hbox.add(button);
 139         hbox.add(Box.createGlue());
 140         add(hbox, BorderLayout.SOUTH);
 141 
 142         clear();
 143     }
 144 
 145     public void requestFocus() {
 146         editor.requestFocus();
 147     }
 148 
 149     public void clear() {
 150         EditableAtEndDocument d = (EditableAtEndDocument) editor.getDocument();
 151         d.clear();
 152         commands.executeCommand("");
 153         setMark();
 154         editor.requestFocus();
 155     }
 156 
 157     public void setMark() {
 158         ((EditableAtEndDocument) editor.getDocument()).setMark();
 159     }
 160 
 161     public String getMarkedText() {
 162         try {
 163             String s = ((EditableAtEndDocument) editor.getDocument()).getMarkedText();
 164             int i = s.length();
 165             while ((i > 0) && (s.charAt(i - 1) == '\n')) {
 166                 i--;
 167             }
 168             return s.substring(0, i);
 169         }
 170         catch (BadLocationException e) {
 171             e.printStackTrace();
 172             return null;


   1 /*
   2  * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  71         cp.setErr(o);
  72 
  73         editor.getDocument().addDocumentListener(new DocumentListener() {
  74                 public void changedUpdate(DocumentEvent e) {
  75                 }
  76 
  77                 public void insertUpdate(DocumentEvent e) {
  78                     if (updating) return;
  79                     beginUpdate();
  80                     editor.setCaretPosition(editor.getDocument().getLength());
  81                     if (insertContains(e, '\n')) {
  82                         String cmd = getMarkedText();
  83                         // Handle multi-line input
  84                         if ((cmd.length() == 0) || (cmd.charAt(cmd.length() - 1) != '\\')) {
  85                             // Trim "\\n" combinations
  86                             final String ln = trimContinuations(cmd);
  87                             SwingUtilities.invokeLater(new Runnable() {
  88                                     public void run() {
  89                                         beginUpdate();
  90                                         try {
  91                                             commands.executeCommand(ln, true);
  92                                             commands.printPrompt();
  93                                             Document d = editor.getDocument();
  94                                             try {
  95                                                 d.insertString(d.getLength(), baos.toString(), null);
  96                                             }
  97                                             catch (BadLocationException ble) {
  98                                                 ble.printStackTrace();
  99                                             }
 100                                             baos.reset();
 101                                             editor.setCaretPosition(editor.getDocument().getLength());
 102                                             setMark();
 103                                         } finally {
 104                                             endUpdate();
 105                                         }
 106                                     }
 107                                 });
 108                         }
 109                     } else {
 110                         endUpdate();
 111                     }


 132         JButton button = new JButton("Clear Saved Text");
 133         button.addActionListener(new ActionListener() {
 134                 public void actionPerformed(ActionEvent e) {
 135                     clear();
 136                 }
 137             });
 138         hbox.add(button);
 139         hbox.add(Box.createGlue());
 140         add(hbox, BorderLayout.SOUTH);
 141 
 142         clear();
 143     }
 144 
 145     public void requestFocus() {
 146         editor.requestFocus();
 147     }
 148 
 149     public void clear() {
 150         EditableAtEndDocument d = (EditableAtEndDocument) editor.getDocument();
 151         d.clear();
 152         commands.executeCommand("", false);
 153         setMark();
 154         editor.requestFocus();
 155     }
 156 
 157     public void setMark() {
 158         ((EditableAtEndDocument) editor.getDocument()).setMark();
 159     }
 160 
 161     public String getMarkedText() {
 162         try {
 163             String s = ((EditableAtEndDocument) editor.getDocument()).getMarkedText();
 164             int i = s.length();
 165             while ((i > 0) && (s.charAt(i - 1) == '\n')) {
 166                 i--;
 167             }
 168             return s.substring(0, i);
 169         }
 170         catch (BadLocationException e) {
 171             e.printStackTrace();
 172             return null;


agent/src/share/classes/sun/jvm/hotspot/ui/CommandProcessorPanel.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File