View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  package org.devaki.nextobjects.ui.menus;
21  import javax.swing.JPopupMenu;
22  import java.awt.event.ActionEvent;
23  import java.awt.event.ActionListener;
24  import org.devaki.nextobjects.constants.CstImages;
25  import org.devaki.nextobjects.ui.components.CustomMenuItem;
26  import org.devaki.nextobjects.util.NOClipboard;
27  import java.awt.event.KeyEvent;
28  import javax.swing.JTextPane;
29  /***
30   * This class provide a popup menu for the SQL panel
31   */
32  public class EditorPopupMenu extends JPopupMenu
33  {
34      /***
35       * Copy menu item
36       */
37      private static CustomMenuItem jMenuItemCopy =
38          new CustomMenuItem(
39              "Copy",
40              CstImages.ICN_COPY,
41              KeyEvent.VK_C,
42              false);
43      /***
44       * Select all menu item
45       */
46      private CustomMenuItem jMenuItemSelectAll =
47          new CustomMenuItem("Select All", null, KeyEvent.VK_A, false);
48      /***
49       *  Reference to the SQL editor
50       */
51      private static JTextPane textpane;
52      /***
53       * Create a new 'EditorPopupMenu' object
54       * @param theTextPane reference to the sql editor
55       */
56      public EditorPopupMenu()
57      {
58          // Action Listeners
59          EditorPopupMenu
60              .jMenuItemCopy
61              .addActionListener(new ActionListener()
62          {
63              public void actionPerformed(ActionEvent e)
64              {
65                  // JTextPane.get
66                  NOClipboard.copy(textpane.getSelectedText());
67              }
68          });
69          this.jMenuItemSelectAll.addActionListener(new ActionListener()
70          {
71              public void actionPerformed(ActionEvent e)
72              {
73                  textpane.selectAll();
74              }
75          });
76          jMenuItemCopy.setEnabled(true);
77          jMenuItemSelectAll.setEnabled(true);
78          this.add(this.jMenuItemSelectAll);
79          this.addSeparator();
80          add(jMenuItemCopy);
81      }
82      /***
83       * @param pane
84       */
85      public void setTextpane(JTextPane pane)
86      {
87          textpane = pane;
88      }
89  }