[Ctrl+C]と同様の処理を行うコンテキストメニューを作成したい

◆ご質問◆
コンテキストポップアップメニューのメニューに「コピー」を追加し、
追加したメニューの「コピー」を選択した際に「Crtl+C」と同様の機能を実装することは可能でしょうか?

◆回答◆
FocusManagerが管理する標準のコマンド(コピーコマンド)を取得し、
MenuPaneを生成して、そのMenuActionに取得したコピーコマンドを割り当てることで実現可能です。

詳細はサンプルをご参照ください。

{curl  5.0,6.0 applet}
{curl-file-attributes character-encoding = “shift-jis”}

{define-class public MyTextFieldUI {inherits StandardTextFieldUI}
  {constructor public {default control:#TextField=null, …}
    {construct-super control = control, …}
  }

  {method private {make-menu-pane-for-text-field view:View}:MenuPane
    let fm:FocusManager = {non-null view.focus-manager}
    {return
        {MenuPane
            {on e:GrabRelease do
                {if self.input-method-enabled? then
                    let local?:bool = {set? self.input-method-enabled?}
                    {try
                        set self.input-method-enabled? = false
                     finally
                        {if local? then
                            set self.input-method-enabled? = true
                         else
                            {unset self.input-method-enabled?}
                        }
                    }
                }
            },
            {MenuAction
                label = {host-localize “Cut”},
                bound-command = {fm.get-command “cut”}
            },
            {MenuAction
                label = {host-localize “Copy”},
                bound-command = {fm.get-command “copy”}
            },
            {MenuAction
                label = {host-localize “Paste”},
                bound-command = {fm.get-command “paste”}
            },
            {MenuAction
                label = {host-localize “Delete”},
                bound-command = {fm.get-command “delete”}
            }
        }
    }
  }

  {method open public {on-context-menu-event e:ContextMenuEvent}:void
    {if not e.consumed? then
        {if-non-null v = {self.get-view} then
            {if-non-null
                menu-pane = {self.make-menu-pane-for-text-field v}
             then
                {e.consume}
                {menu-pane.popup self, e.x, e.y}
            }
        }
    }
  }
}

{do
    {the-standard-look-and-feel.register-ui
        TextField,
        MyTextFieldUI
    }
}

{TextField width = 100pt}