diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java index feade9ae..a87d9d74 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java @@ -45,6 +45,7 @@ public interface IPlugInPort { public static final String WHEEL_ZOOM_KEY = "wheelZoom"; public static final String OUTLINE_KEY = "outline"; public static final String THEME_KEY = "theme"; + public static final String RECENT_COMPONENTS_KEY = "recentComponents"; /** * Returns size of the canvas that takes project dimensions into account as diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/InstantiationManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/InstantiationManager.java index 260d4a87..e2176333 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/InstantiationManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/InstantiationManager.java @@ -2,10 +2,12 @@ package org.diylc.presenter; import java.awt.Point; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import org.diylc.common.ComponentType; +import org.diylc.common.IPlugInPort; import org.diylc.common.PropertyWrapper; import org.diylc.core.IDIYComponent; import org.diylc.core.Project; @@ -23,6 +25,8 @@ public class InstantiationManager { private static final Logger LOG = Logger.getLogger(InstantiationManager.class); + private static final int MAX_RECENT_COMPONENTS = 16; + private Cloner cloner; private ComponentType componentTypeSlot; @@ -123,6 +127,7 @@ public class InstantiationManager { return true; } + @SuppressWarnings("unchecked") public IDIYComponent instantiateComponent(ComponentType componentType, Point point, Project currentProject) throws Exception { LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName()); @@ -144,9 +149,26 @@ public class InstantiationManager { fillWithDefaultProperties(component); + // Write to recent components + List recentComponentTypes = (List) ConfigurationManager.getInstance() + .readObject(IPlugInPort.RECENT_COMPONENTS_KEY, new ArrayList()); + String className = componentType.getInstanceClass().getName(); + if (recentComponentTypes.size() == 0 || !recentComponentTypes.get(0).equals(className)) { + // Remove if it's already somewhere in the list. + recentComponentTypes.remove(className); + // Add to the end of the list. + recentComponentTypes.add(0, className); + // Trim the list if necessary. + if (recentComponentTypes.size() > MAX_RECENT_COMPONENTS) { + recentComponentTypes.remove(recentComponentTypes.size() - 1); + } + ConfigurationManager.getInstance().writeValue(IPlugInPort.RECENT_COMPONENTS_KEY, + recentComponentTypes); + } + return component; } - + public String createUniqueName(ComponentType componentType, Project currentProject) { int i = 0; boolean exists = true; @@ -173,11 +195,12 @@ public class InstantiationManager { * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException - * @throws NoSuchMethodException - * @throws SecurityException + * @throws NoSuchMethodException + * @throws SecurityException */ public void fillWithDefaultProperties(Object object) throws IllegalArgumentException, - IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException { + IllegalAccessException, InvocationTargetException, SecurityException, + NoSuchMethodException { // Extract properties. List properties = ComponentProcessor.getInstance().extractProperties( object.getClass()); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index 041b2de6..df3ecbd1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -55,7 +55,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); - public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 8); + public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 9); public static final String DEFAULTS_KEY_PREFIX = "default."; public static final List> EMPTY_SELECTION = Collections.emptyList(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentTabbedPane.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentTabbedPane.java index 09fdd827..b1b6f1db 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentTabbedPane.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/toolbox/ComponentTabbedPane.java @@ -1,6 +1,7 @@ package org.diylc.swing.plugins.toolbox; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.util.ArrayList; @@ -15,11 +16,17 @@ import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.apache.log4j.Logger; import org.diylc.common.ComponentType; import org.diylc.common.IPlugInPort; +import org.diylc.core.IDIYComponent; import org.diylc.presenter.ComparatorFactory; +import org.diylc.presenter.ComponentProcessor; import org.diylc.presenter.Presenter; +import com.diyfever.gui.miscutils.ConfigurationManager; +import com.diyfever.gui.miscutils.IConfigListener; + /** * Tabbed pane that shows all available components categorized into tabs. * @@ -27,14 +34,18 @@ import org.diylc.presenter.Presenter; */ class ComponentTabbedPane extends JTabbedPane { + private static final long serialVersionUID = 1L; + + private static final Logger LOG = Logger.getLogger(ComponentTabbedPane.class); + public static int SCROLL_STEP = Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 2; - private static final long serialVersionUID = 1L; private final IPlugInPort plugInPort; public ComponentTabbedPane(IPlugInPort plugInPort) { super(); this.plugInPort = plugInPort; + addTab("Recently Used", createRecentComponentsPanel()); Map> componentTypes = plugInPort.getComponentTypes(); List categories = new ArrayList(componentTypes.keySet()); Collections.sort(categories); @@ -94,13 +105,15 @@ class ComponentTabbedPane extends JTabbedPane { return panel; } -// private JScrollPane createComponentScrollBar(List componentTypes) { -// JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes)); -// scrollPane.setOpaque(false); -// scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); -// scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); -// return scrollPane; -// } + // private JScrollPane createComponentScrollBar(List + // componentTypes) { + // JScrollPane scrollPane = new + // JScrollPane(createComponentPanel(componentTypes)); + // scrollPane.setOpaque(false); + // scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + // scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); + // return scrollPane; + // } private Component createComponentPanel(List componentTypes) { Container toolbar = new Container(); @@ -111,6 +124,46 @@ class ComponentTabbedPane extends JTabbedPane { JButton button = new ComponentButton(plugInPort, componentType); toolbar.add(button); } + return toolbar; } + + private Component createRecentComponentsPanel() { + JPanel panel = new JPanel(new BorderLayout()); + panel.setOpaque(false); + + final Container toolbar = new Container(); + toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); + refreshRecentComponentsToolbar(toolbar, (List) ConfigurationManager.getInstance() + .readObject(IPlugInPort.RECENT_COMPONENTS_KEY, new ArrayList())); + ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, + new IConfigListener() { + + @Override + public void valueChanged(String key, Object value) { + refreshRecentComponentsToolbar(toolbar, (List) value); + toolbar.invalidate(); + } + }); + + panel.add(toolbar, BorderLayout.CENTER); + + return panel; + } + + private void refreshRecentComponentsToolbar(Container toolbar, + List recentComponentClassList) { + toolbar.removeAll(); + for (String componentClassName : recentComponentClassList) { + ComponentType componentType; + try { + componentType = ComponentProcessor.getInstance().extractComponentTypeFrom( + (Class>) Class.forName(componentClassName)); + JButton button = new ComponentButton(plugInPort, componentType); + toolbar.add(button); + } catch (ClassNotFoundException e) { + LOG.error("Could not create recent component button for " + componentClassName, e); + } + } + } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml index b788f728..09602cda 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/update.xml @@ -362,6 +362,10 @@ NEW_FEATURE Renumber selected components by X or Y axis + + NEW_FEATURE + Recently used components in the toolbar for easy navigation + http://code.google.com/p/diy-layout-creator/downloads/list