mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
toolbar improvements
This commit is contained in:
@@ -3422,6 +3422,18 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Português translation added (thanks Pedro Rizzi!)</description>
|
<description>Português translation added (thanks Pedro Rizzi!)</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Building blocks and Favorites added to the component toolbar</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<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>IMPROVEMENT</changeType>
|
||||||
|
<description>Save last selected tab in the component toolbar and restore it in the next session</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>When editing component properties, group Length and Width properties together</description>
|
<description>When editing component properties, group Length and Width properties together</description>
|
||||||
@@ -3432,7 +3444,7 @@
|
|||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Fixed some issues with exporting and importing building blocks and variants. If you still have issues, your variant/building block files might need to be manually updated to keep working</description>
|
<description>Fixed some issues with exporting/importing building blocks and variants. If you still have issues, your variant/building block files might need to be manually updated to keep working</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.event.ActionEvent;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.Action;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The ActionMapAction class is a convenience class that allows you to use an installed Action as an
|
||||||
|
* Action or ActionListener on a separate component.
|
||||||
|
*
|
||||||
|
* It can be used on components like JButton or JMenuItem that support an Action as a property of
|
||||||
|
* the component. Or it can be added to the same above components as an ActionListener.
|
||||||
|
*
|
||||||
|
* The benefit of this class is that a new ActionEvent will be created such that the source of the
|
||||||
|
* event is the component the Action belongs to, not the component that was "clicked". Otherwise in
|
||||||
|
* many cases a ClassCastException will be thrown when the Action is invoked.
|
||||||
|
*/
|
||||||
|
public class ActionMapAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Action originalAction;
|
||||||
|
private JComponent component;
|
||||||
|
private String actionCommand = "";
|
||||||
|
private int repeatCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the default Action for the given KeyStroke with a custom Action
|
||||||
|
*
|
||||||
|
* @param name the name parameter of the Action
|
||||||
|
* @param componet the component the Action belongs to
|
||||||
|
* @param actionKey the key to identify the Action in the ActionMap
|
||||||
|
* @param repeatCount the number of time to repeat the same action on invocation
|
||||||
|
*/
|
||||||
|
public ActionMapAction(String name, JComponent component, String actionKey, int repeatCount) {
|
||||||
|
super(name);
|
||||||
|
this.repeatCount = repeatCount;
|
||||||
|
|
||||||
|
originalAction = component.getActionMap().get(actionKey);
|
||||||
|
|
||||||
|
if (originalAction == null) {
|
||||||
|
String message = "no Action for action key: " + actionKey;
|
||||||
|
throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.component = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionCommand(String actionCommand) {
|
||||||
|
this.actionCommand = actionCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke the original Action using the original component as the source of the event.
|
||||||
|
*/
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
e = new ActionEvent(component, ActionEvent.ACTION_PERFORMED, actionCommand, e.getWhen(),
|
||||||
|
e.getModifiers());
|
||||||
|
|
||||||
|
for (int i = 0; i < repeatCount; i++)
|
||||||
|
originalAction.actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,12 +37,15 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.appframework.miscutils.Utils;
|
import org.diylc.appframework.miscutils.Utils;
|
||||||
import org.diylc.common.ComponentType;
|
import org.diylc.common.ComponentType;
|
||||||
|
import org.diylc.common.IBlockProcessor.InvalidBlockException;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Template;
|
import org.diylc.core.Template;
|
||||||
@@ -57,6 +60,8 @@ import org.diylc.swingframework.openide.DropDownButtonFactory;
|
|||||||
*/
|
*/
|
||||||
public class ComponentButtonFactory {
|
public class ComponentButtonFactory {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(ComponentButtonFactory.class);
|
||||||
|
|
||||||
public static int MARGIN = 3;
|
public static int MARGIN = 3;
|
||||||
|
|
||||||
public static JButton create(final IPlugInPort plugInPort, final ComponentType componentType, final JPopupMenu menu) {
|
public static JButton create(final IPlugInPort plugInPort, final ComponentType componentType, final JPopupMenu menu) {
|
||||||
@@ -191,4 +196,35 @@ public class ComponentButtonFactory {
|
|||||||
item.add(label);
|
item.add(label);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JButton createBuildingBlockButton(final IPlugInPort plugInPort, final String blockName) {
|
||||||
|
JButton button = new JButton(blockName, IconLoader.Component.getIcon());
|
||||||
|
|
||||||
|
button.setVerticalTextPosition(SwingConstants.BOTTOM);
|
||||||
|
button.setHorizontalTextPosition(SwingConstants.CENTER);
|
||||||
|
|
||||||
|
button.setBorder(BorderFactory.createEmptyBorder(MARGIN + 1, MARGIN + 1, MARGIN, MARGIN));
|
||||||
|
button.setToolTipText("<html><b>" + blockName + "</b><br> building block</html>");
|
||||||
|
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
plugInPort.loadBlock(blockName);
|
||||||
|
} catch (InvalidBlockException e1) {
|
||||||
|
LOG.error("Error loading building block", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
button.addKeyListener(new KeyAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isControlDown() : e.isMetaDown(), e.isShiftDown(), e.isAltDown());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.awt.Component;
|
|||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -43,12 +44,14 @@ import org.apache.log4j.Logger;
|
|||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
import org.diylc.appframework.miscutils.IConfigListener;
|
import org.diylc.appframework.miscutils.IConfigListener;
|
||||||
import org.diylc.common.ComponentType;
|
import org.diylc.common.ComponentType;
|
||||||
|
import org.diylc.common.Favorite;
|
||||||
|
import org.diylc.common.Favorite.FavoriteType;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Template;
|
import org.diylc.core.Template;
|
||||||
|
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.presenter.Presenter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabbed pane that shows all available components categorized into tabs.
|
* Tabbed pane that shows all available components categorized into tabs.
|
||||||
@@ -61,18 +64,29 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(ComponentTabbedPane.class);
|
private static final Logger LOG = Logger.getLogger(ComponentTabbedPane.class);
|
||||||
|
|
||||||
public static int SCROLL_STEP = Presenter.ICON_SIZE + ComponentButtonFactory.MARGIN * 2 + 2;
|
public static String LAST_SELECTED_TAB = "lastSelectedTab";
|
||||||
|
|
||||||
private final IPlugInPort plugInPort;
|
private final IPlugInPort plugInPort;
|
||||||
private Container recentToolbar;
|
private Container recentToolbar;
|
||||||
private Container buildingBlocksToolbar;
|
private Container buildingBlocksToolbar;
|
||||||
|
private Container favoritesToolbar;
|
||||||
|
|
||||||
|
private Map<String, ComponentType> typesByClass;
|
||||||
|
|
||||||
|
private List<Favorite> favorites;
|
||||||
private List<String> pendingRecentComponents = null;
|
private List<String> pendingRecentComponents = null;
|
||||||
|
private List<String> blocks;
|
||||||
|
|
||||||
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
||||||
super();
|
super();
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
addTab("Recently Used", createRecentComponentsPanel());
|
|
||||||
// addTab("Building Blocks", createBuildingBlocksPanel());
|
initialize();
|
||||||
|
|
||||||
|
// layout UI
|
||||||
|
addTab(LangUtil.translate("(Favorites)"), createFavoritesPanel());
|
||||||
|
addTab(LangUtil.translate("(Recently Used)"), createRecentComponentsPanel());
|
||||||
|
addTab(LangUtil.translate("(Building Blocks)"), createBuildingBlocksPanel());
|
||||||
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
|
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
|
||||||
List<String> categories = new ArrayList<String>(componentTypes.keySet());
|
List<String> categories = new ArrayList<String>(componentTypes.keySet());
|
||||||
Collections.sort(categories);
|
Collections.sort(categories);
|
||||||
@@ -80,74 +94,96 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
JPanel panel = createTab((componentTypes.get(category)));
|
JPanel panel = createTab((componentTypes.get(category)));
|
||||||
addTab(category, panel);
|
addTab(category, panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore last selected tab
|
||||||
|
int lastSelectedTab = ConfigurationManager.getInstance().readInt(LAST_SELECTED_TAB, -1);
|
||||||
|
if (lastSelectedTab >= 0)
|
||||||
|
setSelectedIndex(lastSelectedTab);
|
||||||
|
|
||||||
addChangeListener(new ChangeListener() {
|
addChangeListener(new ChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
ConfigurationManager.getInstance().writeValue(LAST_SELECTED_TAB, getSelectedIndex());
|
||||||
ComponentTabbedPane.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
ComponentTabbedPane.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
||||||
// Refresh recent components if needed
|
// Refresh recent components if needed
|
||||||
if (pendingRecentComponents != null) {
|
if (pendingRecentComponents != null) {
|
||||||
refreshRecentComponentsToolbar(getRecentToolbar(), pendingRecentComponents);
|
refreshRecentComponentsToolbar(pendingRecentComponents);
|
||||||
getRecentToolbar().invalidate();
|
getRecentToolbar().invalidate();
|
||||||
pendingRecentComponents = null;
|
pendingRecentComponents = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void initialize() {
|
||||||
|
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
|
||||||
|
this.typesByClass = new HashMap<String, ComponentType>();
|
||||||
|
for (Map.Entry<String, List<ComponentType>> e : componentTypes.entrySet())
|
||||||
|
for (ComponentType c : e.getValue())
|
||||||
|
typesByClass.put(c.getInstanceClass().getCanonicalName(), c);
|
||||||
|
|
||||||
|
// load building blocks
|
||||||
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.BLOCKS_KEY,
|
||||||
|
new IConfigListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void valueChanged(String key, Object value) {
|
||||||
|
Map<String, List<IDIYComponent<?>>> newBlocks =
|
||||||
|
(Map<String, List<IDIYComponent<?>>>) value;
|
||||||
|
if (newBlocks != null) {
|
||||||
|
List<String> blockNames = new ArrayList<String>(newBlocks.keySet());
|
||||||
|
Collections.sort(blockNames);
|
||||||
|
if (!blockNames.equals(ComponentTabbedPane.this.blocks)) {
|
||||||
|
LOG.info("Detected block change");
|
||||||
|
ComponentTabbedPane.this.blocks = blockNames;
|
||||||
|
refreshBuildingBlocksToolbar();
|
||||||
|
} else
|
||||||
|
LOG.info("Detected no block change");
|
||||||
|
} else
|
||||||
|
LOG.info("Detected no block change");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Map<String, List<IDIYComponent<?>>> newBlocks =
|
||||||
|
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance()
|
||||||
|
.readObject(IPlugInPort.BLOCKS_KEY, null);
|
||||||
|
if (newBlocks == null)
|
||||||
|
this.blocks = new ArrayList<String>();
|
||||||
|
else {
|
||||||
|
this.blocks = new ArrayList<String>(newBlocks.keySet());
|
||||||
|
Collections.sort(this.blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.FAVORITES_KEY,
|
||||||
|
new IConfigListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void valueChanged(String key, Object value) {
|
||||||
|
List<Favorite> newFavorites = (List<Favorite>) value;
|
||||||
|
if (newFavorites != null && !newFavorites.equals(ComponentTabbedPane.this.favorites)) {
|
||||||
|
LOG.info("Detected favorites change");
|
||||||
|
ComponentTabbedPane.this.favorites = new ArrayList<Favorite>(newFavorites);
|
||||||
|
refreshFavoritesToolbar();
|
||||||
|
} else
|
||||||
|
LOG.info("Detected no favorites change");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.favorites = new ArrayList<Favorite>((List<Favorite>) ConfigurationManager.getInstance()
|
||||||
|
.readObject(IPlugInPort.FAVORITES_KEY, new ArrayList<Favorite>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createTab(List<ComponentType> componentTypes) {
|
private JPanel createTab(List<ComponentType> componentTypes) {
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
// final JScrollPane scrollPane =
|
|
||||||
// createComponentScrollBar(componentTypes);
|
|
||||||
panel.setOpaque(false);
|
panel.setOpaque(false);
|
||||||
panel.add(createComponentPanel(componentTypes), BorderLayout.CENTER);
|
panel.add(createComponentPanel(componentTypes), BorderLayout.CENTER);
|
||||||
// JButton leftButton = new JButton("<");
|
|
||||||
// leftButton.addActionListener(new ActionListener() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void actionPerformed(ActionEvent e) {
|
|
||||||
// Rectangle rect = scrollPane.getVisibleRect();
|
|
||||||
// if (rect.x > SCROLL_STEP) {
|
|
||||||
// rect.translate(-SCROLL_STEP, 0);
|
|
||||||
// } else {
|
|
||||||
// rect.translate(-rect.x, 0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// leftButton.setMargin(new Insets(0, 2, 0, 2));
|
|
||||||
// JButton rightButton = new JButton(">");
|
|
||||||
// rightButton.addActionListener(new ActionListener() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void actionPerformed(ActionEvent e) {
|
|
||||||
// Rectangle rect = scrollPane.getVisibleRect();
|
|
||||||
// if (rect.x + rect.width < scrollPane.getViewport().getSize().width -
|
|
||||||
// SCROLL_STEP) {
|
|
||||||
// rect.translate(SCROLL_STEP, 0);
|
|
||||||
// } else {
|
|
||||||
// rect.translate(scrollPane.getViewport().getSize().width - rect.x -
|
|
||||||
// rect.width,
|
|
||||||
// 0);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// rightButton.setMargin(new Insets(0, 2, 0, 2));
|
|
||||||
// panel.add(leftButton, BorderLayout.WEST);
|
|
||||||
// panel.add(scrollPane);
|
|
||||||
// panel.add(rightButton, BorderLayout.EAST);
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private JScrollPane createComponentScrollBar(List<ComponentType>
|
|
||||||
// componentTypes) {
|
|
||||||
// JScrollPane scrollPane = new
|
|
||||||
// JScrollPane(createComponentPanel(componentTypes));
|
|
||||||
// scrollPane.setOpaque(false);
|
|
||||||
// scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
|
||||||
// scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
|
||||||
// return scrollPane;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public Container getRecentToolbar() {
|
public Container getRecentToolbar() {
|
||||||
if (recentToolbar == null) {
|
if (recentToolbar == null) {
|
||||||
recentToolbar = new Container();
|
recentToolbar = new Container();
|
||||||
@@ -164,6 +200,14 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
return buildingBlocksToolbar;
|
return buildingBlocksToolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Container getFavoritesToolbar() {
|
||||||
|
if (favoritesToolbar == null) {
|
||||||
|
favoritesToolbar = new Container();
|
||||||
|
favoritesToolbar.setLayout(new BoxLayout(favoritesToolbar, BoxLayout.X_AXIS));
|
||||||
|
}
|
||||||
|
return favoritesToolbar;
|
||||||
|
}
|
||||||
|
|
||||||
private Component createComponentPanel(List<ComponentType> componentTypes) {
|
private Component createComponentPanel(List<ComponentType> componentTypes) {
|
||||||
Container toolbar = new Container();
|
Container toolbar = new Container();
|
||||||
Collections.sort(componentTypes, ComparatorFactory.getInstance().getComponentTypeComparator());
|
Collections.sort(componentTypes, ComparatorFactory.getInstance().getComponentTypeComparator());
|
||||||
@@ -177,18 +221,13 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolbar;
|
return new ToolbarScrollPane(toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Component createRecentComponentsPanel() {
|
private Component createRecentComponentsPanel() {
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
|
||||||
panel.setOpaque(false);
|
|
||||||
|
|
||||||
final Container toolbar = getRecentToolbar();
|
final Container toolbar = getRecentToolbar();
|
||||||
refreshRecentComponentsToolbar(
|
refreshRecentComponentsToolbar((List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY,
|
||||||
toolbar,
|
|
||||||
(List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY,
|
|
||||||
new ArrayList<String>()));
|
new ArrayList<String>()));
|
||||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, new IConfigListener() {
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, new IConfigListener() {
|
||||||
|
|
||||||
@@ -200,40 +239,39 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
panel.add(toolbar, BorderLayout.CENTER);
|
JPanel panel = new ToolbarScrollPane(toolbar);
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Component createBuildingBlocksPanel() {
|
private Component createBuildingBlocksPanel() {
|
||||||
|
final Container toolbar = getBuildingBlocksToolbar();
|
||||||
|
|
||||||
|
JPanel panel = new ToolbarScrollPane(toolbar);
|
||||||
|
|
||||||
|
refreshBuildingBlocksToolbar();
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component createFavoritesPanel() {
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
panel.setOpaque(false);
|
panel.setOpaque(false);
|
||||||
|
|
||||||
final Container toolbar = getBuildingBlocksToolbar();
|
final Container toolbar = getFavoritesToolbar();
|
||||||
// refreshRecentComponentsToolbar(
|
|
||||||
// toolbar,
|
|
||||||
// (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;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
panel.add(toolbar, BorderLayout.CENTER);
|
panel.add(toolbar, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
refreshFavoritesToolbar();
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void refreshRecentComponentsToolbar(Container toolbar, List<String> recentComponentClassList) {
|
private void refreshRecentComponentsToolbar(List<String> recentComponentClassList) {
|
||||||
|
Container toolbar = getRecentToolbar();
|
||||||
toolbar.removeAll();
|
toolbar.removeAll();
|
||||||
for (String componentClassName : recentComponentClassList) {
|
for (String componentClassName : recentComponentClassList) {
|
||||||
ComponentType componentType;
|
ComponentType componentType;
|
||||||
@@ -249,6 +287,30 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshBuildingBlocksToolbar() {
|
||||||
|
Container toolbar = getBuildingBlocksToolbar();
|
||||||
|
toolbar.removeAll();
|
||||||
|
for (String block : this.blocks) {
|
||||||
|
Component button = ComponentButtonFactory.createBuildingBlockButton(plugInPort, block);
|
||||||
|
toolbar.add(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshFavoritesToolbar() {
|
||||||
|
Container toolbar = getFavoritesToolbar();
|
||||||
|
toolbar.removeAll();
|
||||||
|
for (Favorite fav : this.favorites) {
|
||||||
|
Component button;
|
||||||
|
if (fav.getType() == FavoriteType.Block) {
|
||||||
|
button = ComponentButtonFactory.createBuildingBlockButton(plugInPort, fav.getName());
|
||||||
|
} else {
|
||||||
|
ComponentType componentType = this.typesByClass.get(fav.getName());
|
||||||
|
button = ComponentButtonFactory.create(plugInPort, componentType, createVariantPopup(componentType));
|
||||||
|
}
|
||||||
|
toolbar.add(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private JPopupMenu createVariantPopup(final ComponentType componentType) {
|
private JPopupMenu createVariantPopup(final ComponentType componentType) {
|
||||||
final JPopupMenu variantPopup = new JPopupMenu();
|
final JPopupMenu variantPopup = new JPopupMenu();
|
||||||
variantPopup.add("Loading...");
|
variantPopup.add("Loading...");
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.plaf.basic.BasicArrowButton;
|
||||||
|
|
||||||
|
public class ToolbarScrollPane extends JPanel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Component view;
|
||||||
|
private BasicArrowButton west;
|
||||||
|
private BasicArrowButton east;
|
||||||
|
|
||||||
|
public ToolbarScrollPane(Component view) {
|
||||||
|
this.view = view;
|
||||||
|
setOpaque(false);
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(view);
|
||||||
|
scrollPane.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
|
||||||
|
add(scrollPane);
|
||||||
|
|
||||||
|
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
||||||
|
|
||||||
|
west = new BasicArrowButton(BasicArrowButton.WEST);
|
||||||
|
west.setAction(new ActionMapAction("", horizontal, "negativeUnitIncrement", 120));
|
||||||
|
west.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Button.shadow")));
|
||||||
|
add(west, BorderLayout.WEST);
|
||||||
|
|
||||||
|
east = new BasicArrowButton(BasicArrowButton.EAST);
|
||||||
|
east.setAction(new ActionMapAction("", horizontal, "positiveUnitIncrement", 120));
|
||||||
|
east.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Button.shadow")));
|
||||||
|
add(east, BorderLayout.EAST);
|
||||||
|
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
refreshScrollButtonVisibility();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshScrollButtonVisibility() {
|
||||||
|
boolean needsScroll = getWidth() < view.getWidth();
|
||||||
|
west.setVisible(needsScroll);
|
||||||
|
east.setVisible(needsScroll);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user