mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Toolbar drop down menu now contains options for managing favorites,
keyboard shortcuts and selecting all components of type
This commit is contained in:
@@ -3430,6 +3430,10 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Scroll buttons added to the component toolbar that appear when needed</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Toolbar drop down menu now contains options for managing favorites, keyboard shortcuts and selecting all components of type</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Save last selected tab in the component toolbar and restore it in the next session</description>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,39 +1,42 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.diylc.swing.plugins.toolbox;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
@@ -52,6 +55,9 @@ import org.diylc.core.Template;
|
||||
import org.diylc.lang.LangUtil;
|
||||
import org.diylc.presenter.ComparatorFactory;
|
||||
import org.diylc.presenter.ComponentProcessor;
|
||||
import org.diylc.swing.images.IconLoader;
|
||||
import org.diylc.swing.plugins.tree.TreePanel;
|
||||
import org.diylc.swing.plugins.tree.TreePanel.SelectAllAction;
|
||||
|
||||
/**
|
||||
* Tabbed pane that shows all available components categorized into tabs.
|
||||
@@ -214,7 +220,8 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
|
||||
for (ComponentType componentType : componentTypes) {
|
||||
try {
|
||||
Component button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
||||
Component button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||
createVariantPopup(componentType));
|
||||
toolbar.add(button);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not create recent component button for " + componentType.getName(), e);
|
||||
@@ -227,17 +234,18 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
@SuppressWarnings("unchecked")
|
||||
private Component createRecentComponentsPanel() {
|
||||
final Container toolbar = getRecentToolbar();
|
||||
refreshRecentComponentsToolbar((List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY,
|
||||
new ArrayList<String>()));
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, new IConfigListener() {
|
||||
refreshRecentComponentsToolbar((List<String>) ConfigurationManager.getInstance()
|
||||
.readObject(IPlugInPort.RECENT_COMPONENTS_KEY, new ArrayList<String>()));
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
// Cache the new list, we'll refresh when there's a
|
||||
// chance
|
||||
pendingRecentComponents = (List<String>) value;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
// Cache the new list, we'll refresh when there's a
|
||||
// chance
|
||||
pendingRecentComponents = (List<String>) value;
|
||||
}
|
||||
});
|
||||
|
||||
JPanel panel = new ToolbarScrollPane(toolbar);
|
||||
|
||||
@@ -276,10 +284,10 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
for (String componentClassName : recentComponentClassList) {
|
||||
ComponentType componentType;
|
||||
try {
|
||||
componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) Class.forName(componentClassName));
|
||||
Component button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
||||
componentType = ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) Class.forName(componentClassName));
|
||||
Component button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||
createVariantPopup(componentType));
|
||||
toolbar.add(button);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not create recent component button for " + componentClassName, e);
|
||||
@@ -305,7 +313,8 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
button = ComponentButtonFactory.createBuildingBlockButton(plugInPort, fav.getName());
|
||||
} else {
|
||||
ComponentType componentType = this.typesByClass.get(fav.getName());
|
||||
button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
||||
button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||
createVariantPopup(componentType));
|
||||
}
|
||||
toolbar.add(button);
|
||||
}
|
||||
@@ -316,9 +325,103 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
variantPopup.add("Loading...");
|
||||
variantPopup.addPopupMenuListener(new PopupMenuListener() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
variantPopup.removeAll();
|
||||
|
||||
final String identifier = componentType.getInstanceClass().getCanonicalName();
|
||||
|
||||
JMenu shortcutSubmenu = new JMenu("Assign Shortcut");
|
||||
final JRadioButtonMenuItem noneItem = new JRadioButtonMenuItem ("None");
|
||||
noneItem.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
HashMap<String, String> map = (HashMap<String, String>) ConfigurationManager
|
||||
.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (map == null)
|
||||
map = new HashMap<String, String>();
|
||||
|
||||
Iterator<Entry<String, String>> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> item = it.next();
|
||||
if (item.getValue().equals(identifier))
|
||||
it.remove();
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(TreePanel.COMPONENT_SHORTCUT_KEY, map);
|
||||
}
|
||||
});
|
||||
|
||||
HashMap<String, String> map = (HashMap<String, String>) ConfigurationManager
|
||||
.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
noneItem.setSelected(map == null);
|
||||
shortcutSubmenu.add(noneItem);
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final JRadioButtonMenuItem item = new JRadioButtonMenuItem("F" + i);
|
||||
item.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
HashMap<String, String> map = (HashMap<String, String>) ConfigurationManager
|
||||
.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (map == null)
|
||||
map = new HashMap<String, String>();
|
||||
|
||||
if (map.containsKey(item.getText()))
|
||||
map.remove(item.getText());
|
||||
|
||||
Iterator<Entry<String, String>> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> item = it.next();
|
||||
if (item.getValue().equals(identifier))
|
||||
it.remove();
|
||||
}
|
||||
|
||||
map.put(item.getText(), identifier);
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(TreePanel.COMPONENT_SHORTCUT_KEY, map);
|
||||
}
|
||||
});
|
||||
|
||||
boolean selected;
|
||||
|
||||
if (map == null)
|
||||
selected = false;
|
||||
else
|
||||
selected = map.containsKey(item.getText()) && map.get(item.getText()).equals(identifier);
|
||||
|
||||
item.setSelected(selected);
|
||||
shortcutSubmenu.add(item);
|
||||
}
|
||||
|
||||
final Favorite fav =
|
||||
new Favorite(FavoriteType.Component, componentType.getInstanceClass().getCanonicalName());
|
||||
final boolean isFavorite = favorites != null && favorites.indexOf(fav) >= 0;
|
||||
final JMenuItem favoritesItem =
|
||||
new JMenuItem(isFavorite ? "Remove From Favorites" : "Add To Favorites",
|
||||
isFavorite ? IconLoader.StarBlue.getIcon() : IconLoader.StarGrey.getIcon());
|
||||
favoritesItem.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<Favorite> favorites = new ArrayList<Favorite>(ComponentTabbedPane.this.favorites);
|
||||
if (isFavorite) {
|
||||
favorites.remove(fav);
|
||||
} else {
|
||||
favorites.add(fav);
|
||||
Collections.sort(favorites);
|
||||
}
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.FAVORITES_KEY, favorites);
|
||||
}
|
||||
});
|
||||
variantPopup.add(favoritesItem);
|
||||
|
||||
variantPopup.add(new SelectAllAction(plugInPort, componentType));
|
||||
variantPopup.add(shortcutSubmenu);
|
||||
|
||||
List<Template> variants = plugInPort.getVariantsFor(componentType);
|
||||
if (variants == null || variants.isEmpty()) {
|
||||
JMenuItem item = new JMenuItem("<no variants>");
|
||||
@@ -326,7 +429,8 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
variantPopup.add(item);
|
||||
} else {
|
||||
for (Template variant : variants) {
|
||||
JMenuItem item = ComponentButtonFactory.createVariantItem(plugInPort, variant, componentType);
|
||||
JMenuItem item =
|
||||
ComponentButtonFactory.createVariantItem(plugInPort, variant, componentType);
|
||||
variantPopup.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user