Gridarta Editor
MenuItemCreator.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
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
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * 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.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.filter;
21 
22 import javax.swing.JMenuItem;
27 import net.sf.japi.swing.action.ActionBuilder;
28 import net.sf.japi.swing.action.ActionBuilderFactory;
29 import net.sf.japi.swing.action.ToggleAction;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
39 public class MenuItemCreator {
40 
44  @NotNull
45  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
46 
50  @Nullable
51  private JMenuItem menuItem;
52 
56  @NotNull
58 
59  @Override
60  public void visit(@NotNull final NamedFilterConfig filterConfig) {
61  menuItem = new FilterMenuEntry(filterConfig);
62  }
63 
64  @Override
65  public void visit(@NotNull final NamedGameObjectMatcherFilterConfig filterConfig) {
66  final ToggleAction action = (ToggleAction) ACTION_BUILDER.createToggle(false, "enabled", filterConfig);
67  menuItem = action.createCheckBoxMenuItem();
68  action.setSelected(filterConfig.isEnabled());
69  }
70 
71  };
72 
77  public MenuItemCreator(@NotNull final FilterConfig<?, ?> config) {
78  config.accept(filterVisitor);
79  assert menuItem != null;
80  }
81 
86  @NotNull
87  @SuppressWarnings("NullableProblems")
88  public JMenuItem getMenuItem() {
89  assert menuItem != null;
90  return menuItem;
91  }
92 
93 }
final FilterConfigVisitor filterVisitor
The FilterConfigVisitor for creating the menu item.
Base package of all Gridarta classes.
Creates menu items for net.sf.gridarta.model.filter.Filter instances.
Interface for visitors of filter configs.
JMenuItem getMenuItem()
Returns the menu item.
MenuItemCreator(@NotNull final FilterConfig<?, ?> config)
Creates a new instance.
Filter configuration of NamedGameObjectMatcherFilter instances.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
Interface for filter configurations.