20 package net.sf.gridarta.gui.utils.tabbedpanel;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.util.IdentityHashMap;
27 import java.util.prefs.Preferences;
28 import javax.swing.JMenu;
29 import javax.swing.JPopupMenu;
35 import net.
sf.japi.swing.action.ActionBuilder;
36 import net.
sf.japi.swing.action.ActionBuilderFactory;
37 import net.
sf.japi.swing.action.ToggleAction;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
53 private static final String
TAB_PREFIX =
"MainWindow.tab";
64 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
83 private final Map<Component, Tab>
openTabs =
new IdentityHashMap<>();
92 public void tabChanged(@Nullable
final Tab prevTab, @Nullable
final Tab tab) {
93 if (prevTab != null) {
117 public void sizeChanged(@NotNull
final Component component,
final int size) {
118 final Tab tab = openTabs.get(component);
125 public void size2Changed(@NotNull
final Location location,
final int size2) {
126 PREFERENCES.putInt(TAB_PREFIX + location.getName() +
".position", size2);
130 public int getSize2(
final Location location) {
131 return PREFERENCES.getInt(TAB_PREFIX + location.
getName() +
".position", -1);
135 borderPanel =
new BorderPanel(centerComponent, borderPanelListener);
136 setLayout(
new BorderLayout());
137 add(borderPanel, BorderLayout.CENTER);
147 tabAdded(tab, buttonList, tab.isOpen());
161 return buttonLists.
getActiveTab(location, alternativeLocation);
170 if (tab.getLocation() == location) {
174 final boolean open = tab.isOpen();
190 if (tab.isAlternativeLocation() == splitMode) {
194 final boolean open = tab.isOpen();
197 buttonList.
selectButton(tab.getButton(), tab.isAlternativeLocation());
209 if (buttonList.getButtonCount() == 1) {
210 add(buttonList.getButtons(), tab.getLocation().getBorderLocation());
215 buttonList.selectButton(tab.getButton(), tab.isAlternativeLocation());
225 if (buttonList.getButtonCount() == 0) {
226 remove(buttonList.getButtons());
239 final JPopupMenu popupMenu = tab.getPopupMenu();
240 final ToggleAction splitModeAction = (ToggleAction) ACTION_BUILDER.createToggle(
false,
"tabSplitMode", moveToActions);
241 splitModeAction.setSelected(tab.isAlternativeLocation());
242 popupMenu.insert(splitModeAction.createCheckBoxMenuItem(), 0);
243 tab.setSplitModeAction(splitModeAction);
246 final JMenu moveToMenu = tab.getMoveToMenu();
248 final Location location = tab.getLocation();
250 if (thisLocation != location) {
251 moveToMenu.add(ACTION_BUILDER.createAction(
true,
"tabButtonMoveTo" + thisLocation.getName(), moveToActions));
261 openTabs.put(tab.getComponent(), tab);
262 borderPanel.
setComponent(tab.getLocation(), tab.getComponent(), tab.isAlternativeLocation(), tab.getSize());
Defines ActionMethods to move tab locations.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
void addTab(@NotNull final Tab tab)
Adds a tab.
abstract String getName()
Returns a name for building resource keys.
void setTabSplitMode(@NotNull final Tab tab, final boolean splitMode)
Toggles split mode for the given tab.
final ButtonListsListener buttonListsListener
The ButtonListsListener attached to buttonLists.
Graphical User Interface of Gridarta.
A tab in a TabbedPanel component.
final BorderPanel borderPanel
The BorderPanel.
void setComponent(@NotNull final Location location, @NotNull final Component component, final boolean alternativeLocation, final int size)
Sets the optional Component for a location.
void tabAdded(@NotNull final Tab tab, @NotNull final DoubleButtonList buttonList, final boolean open)
Called whenever a Tab has been added to a ButtonList.
final ButtonLists buttonLists
The list of buttons for each Location.
Base package of all Gridarta classes.
Location getLocation()
Returns the tab's location.
void fillContextMenu(@NotNull final Tab tab, final boolean initialize)
Fills in context popup menu entries for a tab in a given location.
Component getComponent()
Returns the Component that is shown when this tab is active.
void close(@NotNull final Tab tab)
Closes a Tab.
void setSize(final int size)
Sets the tab's size.
static final long serialVersionUID
The serial version UID.
Interface used as preferences location.
A Component that always displays another component and optionally a number of tabs around it...
Tab getActiveTab(@NotNull final Location location, final boolean alternativeLocation)
Returns the active Tab on a given Location of the main view.
void open(@NotNull final Tab tab)
Opens a Tab.
void moveTab(@NotNull final Tab tab, @NotNull final Location location)
Moves the tab to the given location.
final Map< Component, Tab > openTabs
The Tabs currently shown in borderPanel.
static final String TAB_PREFIX
The key used to store the preferred height of a tab.
A Component that permanently displays another Component and optionally displays more components on th...
Interface for listeners interested in BorderPanel related events.
static final Preferences PREFERENCES
The Preferences.
boolean isAlternativeLocation()
Returns whether the button is shown in the alternative location.
void closeInt(final Tab tab)
Closes a Tab but does not update the tab's open status.
void tabRemoved(@NotNull final DoubleButtonList buttonList)
Called whenever a Tab has been added from a ButtonList.
TabbedPanel(@NotNull final Component centerComponent)
Creates a new instance.
void unsetComponent(@NotNull final Location location, final boolean alternativeLocation)
Unsets the optional Component for a location.