mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added recently used tab
This commit is contained in:
+1
@@ -45,6 +45,7 @@ public interface IPlugInPort {
|
|||||||
public static final String WHEEL_ZOOM_KEY = "wheelZoom";
|
public static final String WHEEL_ZOOM_KEY = "wheelZoom";
|
||||||
public static final String OUTLINE_KEY = "outline";
|
public static final String OUTLINE_KEY = "outline";
|
||||||
public static final String THEME_KEY = "theme";
|
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
|
* Returns size of the canvas that takes project dimensions into account as
|
||||||
|
|||||||
+24
-1
@@ -2,10 +2,12 @@ package org.diylc.presenter;
|
|||||||
|
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.common.ComponentType;
|
import org.diylc.common.ComponentType;
|
||||||
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
@@ -23,6 +25,8 @@ public class InstantiationManager {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(InstantiationManager.class);
|
private static final Logger LOG = Logger.getLogger(InstantiationManager.class);
|
||||||
|
|
||||||
|
private static final int MAX_RECENT_COMPONENTS = 16;
|
||||||
|
|
||||||
private Cloner cloner;
|
private Cloner cloner;
|
||||||
|
|
||||||
private ComponentType componentTypeSlot;
|
private ComponentType componentTypeSlot;
|
||||||
@@ -123,6 +127,7 @@ public class InstantiationManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public IDIYComponent<?> instantiateComponent(ComponentType componentType, Point point,
|
public IDIYComponent<?> instantiateComponent(ComponentType componentType, Point point,
|
||||||
Project currentProject) throws Exception {
|
Project currentProject) throws Exception {
|
||||||
LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
|
LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
|
||||||
@@ -144,6 +149,23 @@ public class InstantiationManager {
|
|||||||
|
|
||||||
fillWithDefaultProperties(component);
|
fillWithDefaultProperties(component);
|
||||||
|
|
||||||
|
// Write to recent components
|
||||||
|
List<String> recentComponentTypes = (List<String>) ConfigurationManager.getInstance()
|
||||||
|
.readObject(IPlugInPort.RECENT_COMPONENTS_KEY, new ArrayList<ComponentType>());
|
||||||
|
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;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +199,8 @@ public class InstantiationManager {
|
|||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public void fillWithDefaultProperties(Object object) throws IllegalArgumentException,
|
public void fillWithDefaultProperties(Object object) throws IllegalArgumentException,
|
||||||
IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
|
IllegalAccessException, InvocationTargetException, SecurityException,
|
||||||
|
NoSuchMethodException {
|
||||||
// Extract properties.
|
// Extract properties.
|
||||||
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||||
object.getClass());
|
object.getClass());
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
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 String DEFAULTS_KEY_PREFIX = "default.";
|
||||||
|
|
||||||
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
|
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
|
||||||
|
|||||||
+56
-3
@@ -1,6 +1,7 @@
|
|||||||
package org.diylc.swing.plugins.toolbox;
|
package org.diylc.swing.plugins.toolbox;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -15,11 +16,17 @@ import javax.swing.JTabbedPane;
|
|||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.common.ComponentType;
|
import org.diylc.common.ComponentType;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.presenter.ComparatorFactory;
|
import org.diylc.presenter.ComparatorFactory;
|
||||||
|
import org.diylc.presenter.ComponentProcessor;
|
||||||
import org.diylc.presenter.Presenter;
|
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.
|
* Tabbed pane that shows all available components categorized into tabs.
|
||||||
*
|
*
|
||||||
@@ -27,14 +34,18 @@ import org.diylc.presenter.Presenter;
|
|||||||
*/
|
*/
|
||||||
class ComponentTabbedPane extends JTabbedPane {
|
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;
|
public static int SCROLL_STEP = Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 2;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
private final IPlugInPort plugInPort;
|
private final IPlugInPort plugInPort;
|
||||||
|
|
||||||
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
||||||
super();
|
super();
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
|
addTab("Recently Used", createRecentComponentsPanel());
|
||||||
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);
|
||||||
@@ -94,8 +105,10 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private JScrollPane createComponentScrollBar(List<ComponentType> componentTypes) {
|
// private JScrollPane createComponentScrollBar(List<ComponentType>
|
||||||
// JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes));
|
// componentTypes) {
|
||||||
|
// JScrollPane scrollPane = new
|
||||||
|
// JScrollPane(createComponentPanel(componentTypes));
|
||||||
// scrollPane.setOpaque(false);
|
// scrollPane.setOpaque(false);
|
||||||
// scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
// scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
// scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
// scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||||
@@ -111,6 +124,46 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
JButton button = new ComponentButton(plugInPort, componentType);
|
JButton button = new ComponentButton(plugInPort, componentType);
|
||||||
toolbar.add(button);
|
toolbar.add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
return toolbar;
|
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<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) {
|
||||||
|
refreshRecentComponentsToolbar(toolbar, (List<String>) value);
|
||||||
|
toolbar.invalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
panel.add(toolbar, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshRecentComponentsToolbar(Container toolbar,
|
||||||
|
List<String> recentComponentClassList) {
|
||||||
|
toolbar.removeAll();
|
||||||
|
for (String componentClassName : recentComponentClassList) {
|
||||||
|
ComponentType componentType;
|
||||||
|
try {
|
||||||
|
componentType = ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||||
|
(Class<? extends IDIYComponent<?>>) 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -362,6 +362,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Renumber selected components by X or Y axis</description>
|
<description>Renumber selected components by X or Y axis</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Recently used components in the toolbar for easy navigation</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
||||||
</com.diyfever.gui.update.Version>
|
</com.diyfever.gui.update.Version>
|
||||||
|
|||||||
Reference in New Issue
Block a user