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 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
|
||||
|
||||
+27
-4
@@ -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<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;
|
||||
}
|
||||
|
||||
|
||||
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<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||
object.getClass());
|
||||
|
||||
+1
-1
@@ -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<IDIYComponent<?>> EMPTY_SELECTION = Collections.emptyList();
|
||||
|
||||
+61
-8
@@ -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<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
|
||||
List<String> categories = new ArrayList<String>(componentTypes.keySet());
|
||||
Collections.sort(categories);
|
||||
@@ -94,13 +105,15 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
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;
|
||||
// }
|
||||
// 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;
|
||||
// }
|
||||
|
||||
private Component createComponentPanel(List<ComponentType> 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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user