• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package traceviewer.ui.builders
18 
19 import java.awt.event.ActionEvent
20 import javax.swing.JMenu
21 import javax.swing.JMenuBar
22 import javax.swing.JMenuItem
23 
24 class MenuBar private constructor(val base: JMenuBar) {
25     companion object {
invokenull26         operator fun invoke(init: MenuBar.() -> Unit): JMenuBar {
27             val base = JMenuBar()
28             MenuBar(base).init()
29             return base
30         }
31     }
32 
menunull33     fun menu(name: String, init: Menu.() -> Unit) {
34         base.add(Menu(name, init))
35     }
36 }
37 
38 class Menu private constructor(val base: JMenu) {
39     companion object {
invokenull40         operator fun invoke(name: String, init: Menu.() -> Unit): JMenu {
41             val base = JMenu(name)
42             Menu(base).init()
43             return base
44         }
45     }
46 
itemnull47     fun item(name: String, init: MenuItem.() -> Unit) {
48         base.add(MenuItem(name, init))
49     }
50 }
51 
52 class MenuItem private constructor(val base: JMenuItem) {
53     companion object {
invokenull54         operator fun invoke(name: String, init: MenuItem.() -> Unit): JMenuItem {
55             val base = JMenuItem(name)
56             MenuItem(base).init()
57             return base
58         }
59     }
60 
actionnull61     fun action(listener: (ActionEvent) -> Unit) {
62         base.addActionListener(listener)
63     }
64 }