mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +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>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Scroll buttons added to the component toolbar that appear when needed</description>
|
<description>Scroll buttons added to the component toolbar that appear when needed</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</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>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Save last selected tab in the component toolbar and restore it in the next session</description>
|
<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).
|
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
*
|
||||||
|
* This file is part of DIYLC.
|
||||||
This file is part of DIYLC.
|
*
|
||||||
|
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
DIYLC is free software: you can redistribute it and/or modify
|
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
it under the terms of the GNU General Public License as published by
|
* License, or (at your option) any later version.
|
||||||
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
|
||||||
DIYLC is distributed in the hope that it will be useful,
|
* Public License for more details.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||||
GNU General Public License for more details.
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
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;
|
package org.diylc.swing.plugins.toolbox;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JRadioButtonMenuItem;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
@@ -52,6 +55,9 @@ import org.diylc.core.Template;
|
|||||||
import org.diylc.lang.LangUtil;
|
import org.diylc.lang.LangUtil;
|
||||||
import org.diylc.presenter.ComparatorFactory;
|
import org.diylc.presenter.ComparatorFactory;
|
||||||
import org.diylc.presenter.ComponentProcessor;
|
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.
|
* 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));
|
toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
|
||||||
for (ComponentType componentType : componentTypes) {
|
for (ComponentType componentType : componentTypes) {
|
||||||
try {
|
try {
|
||||||
Component button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
Component button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||||
|
createVariantPopup(componentType));
|
||||||
toolbar.add(button);
|
toolbar.add(button);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not create recent component button for " + componentType.getName(), e);
|
LOG.error("Could not create recent component button for " + componentType.getName(), e);
|
||||||
@@ -227,9 +234,10 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Component createRecentComponentsPanel() {
|
private Component createRecentComponentsPanel() {
|
||||||
final Container toolbar = getRecentToolbar();
|
final Container toolbar = getRecentToolbar();
|
||||||
refreshRecentComponentsToolbar((List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY,
|
refreshRecentComponentsToolbar((List<String>) ConfigurationManager.getInstance()
|
||||||
new ArrayList<String>()));
|
.readObject(IPlugInPort.RECENT_COMPONENTS_KEY, new ArrayList<String>()));
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, new IConfigListener() {
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY,
|
||||||
|
new IConfigListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(String key, Object value) {
|
public void valueChanged(String key, Object value) {
|
||||||
@@ -276,10 +284,10 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
for (String componentClassName : recentComponentClassList) {
|
for (String componentClassName : recentComponentClassList) {
|
||||||
ComponentType componentType;
|
ComponentType componentType;
|
||||||
try {
|
try {
|
||||||
componentType =
|
componentType = ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
|
||||||
(Class<? extends IDIYComponent<?>>) Class.forName(componentClassName));
|
(Class<? extends IDIYComponent<?>>) Class.forName(componentClassName));
|
||||||
Component button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
Component button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||||
|
createVariantPopup(componentType));
|
||||||
toolbar.add(button);
|
toolbar.add(button);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not create recent component button for " + componentClassName, 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());
|
button = ComponentButtonFactory.createBuildingBlockButton(plugInPort, fav.getName());
|
||||||
} else {
|
} else {
|
||||||
ComponentType componentType = this.typesByClass.get(fav.getName());
|
ComponentType componentType = this.typesByClass.get(fav.getName());
|
||||||
button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
button = ComponentButtonFactory.create(plugInPort, componentType,
|
||||||
|
createVariantPopup(componentType));
|
||||||
}
|
}
|
||||||
toolbar.add(button);
|
toolbar.add(button);
|
||||||
}
|
}
|
||||||
@@ -316,9 +325,103 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
variantPopup.add("Loading...");
|
variantPopup.add("Loading...");
|
||||||
variantPopup.addPopupMenuListener(new PopupMenuListener() {
|
variantPopup.addPopupMenuListener(new PopupMenuListener() {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||||
variantPopup.removeAll();
|
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);
|
List<Template> variants = plugInPort.getVariantsFor(componentType);
|
||||||
if (variants == null || variants.isEmpty()) {
|
if (variants == null || variants.isEmpty()) {
|
||||||
JMenuItem item = new JMenuItem("<no variants>");
|
JMenuItem item = new JMenuItem("<no variants>");
|
||||||
@@ -326,7 +429,8 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
variantPopup.add(item);
|
variantPopup.add(item);
|
||||||
} else {
|
} else {
|
||||||
for (Template variant : variants) {
|
for (Template variant : variants) {
|
||||||
JMenuItem item = ComponentButtonFactory.createVariantItem(plugInPort, variant, componentType);
|
JMenuItem item =
|
||||||
|
ComponentButtonFactory.createVariantItem(plugInPort, variant, componentType);
|
||||||
variantPopup.add(item);
|
variantPopup.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user