diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/.classpath b/ diy-layout-creator --username bancika@gmail.com/DIYLC/.classpath
deleted file mode 100644
index aedd5a59..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/.classpath
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/.project b/ diy-layout-creator --username bancika@gmail.com/DIYLC/.project
deleted file mode 100644
index 02c8729f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- DIYLC
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/DIYLCStarter.launch b/ diy-layout-creator --username bancika@gmail.com/DIYLC/DIYLCStarter.launch
deleted file mode 100644
index e6e7b0f9..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/DIYLCStarter.launch
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/build.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/build.xml
deleted file mode 100644
index ae556a0f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/build.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Compile with JDK ${java.runtime.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml
deleted file mode 100644
index 47113384..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-
\ No newline at end of file
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar
deleted file mode 100644
index 439eb6b9..00000000
Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar and /dev/null differ
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar
deleted file mode 100644
index 6686875d..00000000
Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar and /dev/null differ
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/DIYLCStarter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/DIYLCStarter.java
deleted file mode 100644
index 850c355f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/DIYLCStarter.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.diylc;
-
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.Properties;
-
-import javax.swing.UIManager;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.diylc.presenter.Presenter;
-import org.diylc.swing.gui.MainFrame;
-import org.diylc.swing.gui.TemplateDialog;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.diyfever.gui.miscutils.PropertyInjector;
-
-/**
- * Main class that runs DIYLC.
- *
- * @author Branislav Stojkovic
- *
- * @see Presenter
- * @see MainFrame
- */
-public class DIYLCStarter {
-
- private static final Logger LOG = Logger.getLogger(Presenter.class);
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- URL url = DIYLCStarter.class.getResource("log4j.properties");
- Properties properties = new Properties();
- try {
- properties.load(url.openStream());
- PropertyConfigurator.configure(properties);
- } catch (Exception e) {
- LOG.error("Could not initialize log4j configuration", e);
- }
-
- LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by " + System.getProperty("java.vm.vendor"));
-
- LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
-
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception e) {
- LOG.error("Could not set Look&Feel", e);
- }
-
- MainFrame mainFrame = new MainFrame();
- mainFrame.setLocationRelativeTo(null);
- mainFrame.setVisible(true);
-
- boolean showTemplates = ConfigurationManager.getInstance().readBoolean(
- TemplateDialog.SHOW_TEMPLATES_KEY, true);
- if (showTemplates) {
- TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter());
- if (!templateDialog.getFiles().isEmpty()) {
- templateDialog.setVisible(true);
- }
- }
-
- url = DIYLCStarter.class.getResource("/config.properties");
- properties = new Properties();
- try {
- LOG.info("Injecting default properties.");
- properties.load(new FileInputStream("config.properties"));
- PropertyInjector.injectProperties(properties);
- } catch (Exception e) {
- LOG.error("Could not read config.properties file", e);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentType.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentType.java
deleted file mode 100644
index f10717cb..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/ComponentType.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.diylc.common;
-
-import javax.swing.Icon;
-
-import org.diylc.core.CreationMethod;
-import org.diylc.core.IDIYComponent;
-
-/**
- * Entity class used to describe a component type.
- *
- * @author Branislav Stojkovic
- *
- * @see IDIYComponent
- */
-public class ComponentType {
-
- private String name;
- private String description;
- private CreationMethod creationMethod;
- private String category;
- private String namePrefix;
- private String author;
- private Icon icon;
- private Class extends IDIYComponent>> instanceClass;
- private double zOrder;
- private boolean stretchable;
-
- public ComponentType(String name, String description, CreationMethod creationMethod,
- String category, String namePrefix, String author, Icon icon,
- Class extends IDIYComponent>> instanceClass, double zOrder, boolean stretchable) {
- super();
- this.name = name;
- this.description = description;
- this.creationMethod = creationMethod;
- this.category = category;
- this.namePrefix = namePrefix;
- this.author = author;
- this.icon = icon;
- this.instanceClass = instanceClass;
- this.zOrder = zOrder;
- this.stretchable = stretchable;
- }
-
- public String getName() {
- return name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public CreationMethod getCreationMethod() {
- return creationMethod;
- }
-
- public String getCategory() {
- return category;
- }
-
- public String getNamePrefix() {
- return namePrefix;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public Icon getIcon() {
- return icon;
- }
-
- public Class extends IDIYComponent>> getInstanceClass() {
- return instanceClass;
- }
-
- public double getZOrder() {
- return zOrder;
- }
-
- public boolean isStretchable() {
- return stretchable;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugIn.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugIn.java
deleted file mode 100644
index 3764fc44..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugIn.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.diylc.common;
-
-import com.diyfever.gui.simplemq.IMessageListener;
-
-/**
- * Interface for plug-ins.
- *
- * @author Branislav Stojkovic
- */
-public interface IPlugIn extends IMessageListener {
-
- /**
- * Method that connects the plug-in with {@link IPlugInPort}. Called by the
- * application when plug-in is installed.
- *
- * @param plugInPort
- */
- void connect(IPlugInPort plugInPort);
-}
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
deleted file mode 100644
index a87d9d74..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java
+++ /dev/null
@@ -1,375 +0,0 @@
-package org.diylc.common;
-
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.geom.Point2D;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.Project;
-import org.diylc.core.Theme;
-import org.diylc.swing.plugins.edit.ComponentTransferable;
-
-import com.diyfever.gui.simplemq.IMessageListener;
-import com.diyfever.gui.simplemq.MessageDispatcher;
-import com.diyfever.gui.update.VersionNumber;
-
-/**
- * Interface for communication between plug-ins and the application. Plug-ins
- * may acquire information or make changes through this interface. Application
- * events are dispatched to plug-ins through {@link MessageDispatcher}
- *
- * @author Branislav Stojkovic
- *
- * @see IPlugIn
- * @see MessageDispatcher
- * @see IMessageListener
- * @see EventType
- */
-public interface IPlugInPort {
-
- public static final String ANTI_ALIASING_KEY = "antiAliasing";
- public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
- public static final String EXPORT_GRID_KEY = "exportGrid";
- public static final String STICKY_POINTS_KEY = "stickyPoints";
- public static final String METRIC_KEY = "metric";
- public static final String SNAP_TO_GRID_KEY = "snapToGrid";
- public static final String AUTO_PADS_KEY = "autoCreatePads";
- public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
- public static final String AUTO_EDIT_KEY = "autoEdit";
- public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
- 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
- * well as zoom level. Each dimension is calculated as the product of the
- * actual size and the number of pixels per unit. If useZoom is
- * set to true, the result is scaled by zoom factor.
- *
- * @param useZoom
- *
- * @return canvas dimensions
- */
- Dimension getCanvasDimensions(boolean useZoom);
-
- /**
- * Returns an instance of {@link Cursor} that should be used at the
- * specified location.
- *
- * Note: point coordinates are scaled for zoom factor.
- *
- * @param point
- * @return cursor
- */
- Cursor getCursorAt(Point point);
-
- /**
- * Returns an instance of currently loaded project.
- *
- * @return
- */
- Project getCurrentProject();
-
- /**
- * Loads specified {@link Project}.
- *
- * @param project
- * @param freshStart
- */
- void loadProject(Project project, boolean freshStart);
-
- /**
- * Creates a new project.
- */
- void createNewProject();
-
- /**
- * Loads a project from the specified file.
- *
- * @param fileName
- */
- void loadProjectFromFile(String fileName);
-
- /**
- * Saves the current project into the specified file.
- *
- * @param fileName
- * @param isBackup
- */
- void saveProjectToFile(String fileName, boolean isBackup);
-
- /**
- * @return the current file name.
- */
- String getCurrentFileName();
-
- /**
- * @return true if the current project is modified.
- */
- boolean isProjectModified();
-
- /**
- * Shows a user dialog if there are changes to confirm that it's safe to
- * proceed.
- *
- * @return true, if file actions (new, open, close) can be taken
- */
- boolean allowFileAction();
-
- /**
- * Returns all available {@link ComponentType}s classified by category.
- * Result is a {@link Map} between category name to a {@link List} of all
- * {@link ComponentType}s that share that category name.
- *
- * @return
- */
- Map> getComponentTypes();
-
- /**
- * Draws project on the provided {@link Graphics2D}. If the provided filter
- * is not null, it will be used to filter the components that are shown.
- *
- * @param g2d
- * @param drawOptions
- * specific drawing options
- * @param filter
- */
- void draw(Graphics2D g2d, Set drawOptions, IComponentFiler filter);
-
- Double[] getAvailableZoomLevels();
-
- /**
- * Returns current zoom level where zoomLevel = 1.0d means
- * 100%.
- *
- * @return current zoom level
- */
- double getZoomLevel();
-
- /**
- * Changes current zoom level where zoomLevel = 1.0d means 100%
- *
- * @param zoomLevel
- * new zoom leve
- */
- void setZoomLevel(double zoomLevel);
-
- /**
- * Notifies the presenter that mouse is clicked.
- *
- * Note: point coordinates are display based, i.e. scaled for zoom factor.
- *
- * @param point
- * @param ctrlDown
- * @param shiftDown
- * @param altDown
- * @param clickCount
- */
- void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown,
- int clickCount);
-
- /**
- * Notifies the presenter that mouse is moved.
- *
- * Note: point coordinates are display based, i.e. scaled for zoom factor.
- *
- * @param point
- * @param ctrlDown
- * @param shiftDown
- * @param altDown
- */
- void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
-
- /**
- * Returns the current {@link ComponentTransferable}.
- *
- * @return
- */
- List> getSelectedComponents();
-
- /**
- * Updates the selection with the specified list of component. Also, updates
- * control point map with all components that are stuck to the newly
- * selected components.
- *
- * @param newSelection
- */
- void updateSelection(List> newSelection);
-
- /**
- * Selects all components in the project.
- */
- void selectAll();
-
- /**
- * Notification that drag has been started from the specified point.
- *
- * Note: point coordinates are scaled for zoom factor.
- *
- * @param point
- * @param ctrlDown
- * @param shiftDown
- * @param altDown
- */
- void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
-
- /**
- * Checks if it's possible to drop over the specified point.
- *
- * Note: point coordinates are scaled for zoom factor.
- *
- * @param point
- * @return
- */
- boolean dragOver(Point point);
-
- /**
- * Notification that drag has been ended in the specified point.
- *
- * Note: point coordinates are scaled for zoom factor.
- *
- * @param point
- */
- void dragEnded(Point point);
-
- /**
- * Returns current version number.
- *
- * @return
- */
- VersionNumber getCurrentVersionNumber();
-
- /**
- * Adds a list of components to the project.
- *
- * @param components
- */
- void pasteComponents(List> components);
-
- /**
- * Deletes all the selected components from the project.
- */
- void deleteSelectedComponents();
-
- /**
- * Sets default value for the specified property name for currently selected
- * component types.
- *
- * @param propertyName
- * display name for property
- * @param value
- * new default value, must not be null
- */
- void setSelectionDefaultPropertyValue(String propertyName, Object value);
-
- /**
- * Sets default value for the specified property name for projects.
- *
- * @param propertyName
- * display name for property
- * @param value
- * new default value, must not be null
- */
- void setProjectDefaultPropertyValue(String propertyName, Object value);
-
- /**
- * @return a list of properties that are mutual for all the selected
- * components. Resulting list may be empty if selected components do
- * not have mutual properties or can be null if the selection is
- * empty.
- */
- List getMutualSelectionProperties();
-
- void editSelection();
-
- /**
- * @return a list of editable properties of the current project.
- */
- List getProjectProperties();
-
- /**
- * Applies specified properties to the current project.
- *
- * @param properties
- */
- void applyPropertiesToProject(List properties);
-
- /**
- * Sets the new component slot. Specified component type will be used to
- * instantiate new component.
- */
- void setNewComponentTypeSlot(ComponentType componentType);
-
- /**
- * Changes default size notation, true for metric, false for imperial.
- *
- * @param isMetric
- */
- void setMetric(boolean isMetric);
-
- /**
- * Groups all selected components.
- */
- void groupSelectedComponents();
-
- /**
- * Ungroups all selected components.
- */
- void ungroupSelectedComponents();
-
- /**
- * Locks or unlocks the specified layer. All components within +- 0.5 range
- * will be affected by the change as well.
- *
- * @param layerZOrder
- * @param locked
- */
- void setLayerLocked(int layerZOrder, boolean locked);
-
- /**
- * @return selection size expressed in either inches or centimeters, based
- * on the user preference.
- */
- Point2D calculateSelectionDimension();
-
- /**
- * Sends each of the selected components one step back.
- */
- void sendSelectionToBack();
-
- /**
- * Brings each of the selected components one step to front.
- */
- void bringSelectionToFront();
-
- /**
- * Causes the display to refresh.
- */
- void refresh();
-
- /**
- * @return currently selected theme.
- */
- Theme getSelectedTheme();
-
- /**
- * Changes the current theme.
- *
- * @param theme
- */
- void setSelectedTheme(Theme theme);
-
- /**
- * Renumbers all the selected components.
- *
- * @param xAxisFirst
- */
- void renumberSelectedComponents(boolean xAxisFirst);
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractComponent.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractComponent.java
deleted file mode 100644
index 251dd1cd..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractComponent.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.diylc.components;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Shape;
-
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.annotations.EditableProperty;
-
-/**
- * Abstract implementation of {@link IDIYComponent} that contains component name
- * and toString.
- *
- * @author Branislav Stojkovic
- *
- * @param
- */
-public abstract class AbstractComponent implements IDIYComponent {
-
- private static final long serialVersionUID = 1L;
-
- protected String name = "";
-
- public static Color SELECTION_COLOR = Color.red;
- public static Color LABEL_COLOR = Color.black;
- public static Color LABEL_COLOR_SELECTED = Color.red;
- public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
-
- @EditableProperty(defaultable = false)
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public boolean canControlPointOverlap(int index) {
- return false;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- /**
- * Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is
- * even.
- *
- * @param x
- * @return
- */
- protected int getClosestOdd(double x) {
- return ((int) x / 2) * 2 + 1;
- }
-
- /**
- * @param clip
- * @return true if none of the control points lie in the clip rectangle.
- */
- protected boolean checkPointsClipped(Shape clip) {
- for (int i = 0; i < getControlPointCount(); i++) {
- if (clip.contains(getControlPoint(i))) {
- return false;
- }
- }
- return true;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java
deleted file mode 100644
index c58a5cfc..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java
+++ /dev/null
@@ -1,336 +0,0 @@
-package org.diylc.components;
-
-import java.awt.AlphaComposite;
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Rectangle2D;
-
-import org.diylc.common.Display;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.ObjectCache;
-import org.diylc.core.ComponentState;
-import org.diylc.core.IDrawingObserver;
-import org.diylc.core.Project;
-import org.diylc.core.Theme;
-import org.diylc.core.VisibilityPolicy;
-import org.diylc.core.annotations.EditableProperty;
-import org.diylc.core.measures.Size;
-import org.diylc.core.measures.SizeUnit;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-/**
- * Base class for all leaded components such as resistors or capacitors. Has two
- * control points and draws leads between them. Also, it positions and draws the
- * shape of the component as specified by a child class.
- *
- * @author Branislav Stojkovic
- */
-public abstract class AbstractLeadedComponent extends AbstractTransparentComponent {
-
- private static final long serialVersionUID = 1L;
-
- public static Color LEAD_COLOR = Color.decode("#236B8E");
- public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
- public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
-
- protected Size length;
- protected Size width;
- protected Point[] points = new Point[] {
- new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
- new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0) };
- protected Color bodyColor = Color.white;
- protected Color borderColor = Color.black;
- protected Color labelColor = LABEL_COLOR;
- protected Display display = Display.VALUE;
-
- protected AbstractLeadedComponent() {
- super();
- try {
- this.length = getDefaultLength().clone();
- this.width = getDefaultWidth().clone();
- } catch (CloneNotSupportedException e) {
- // This should never happen because Size supports cloning.
- } catch (NullPointerException e) {
- // This will happen if components do not have any shape.
- }
- }
-
- @Override
- public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
- Project project, IDrawingObserver drawingObserver) {
- double distance = points[0].distance(points[1]);
- Shape shape = getBodyShape();
- // If there's no body, just draw the line connecting the ending points.
- if (shape == null) {
- drawLead(g2d, componentState);
- } else if (supportsStandingMode()
- && length.convertToPixels() > points[0].distance(points[1])) {
- // When ending points are too close draw the component in standing
- // mode.
- int width = getClosestOdd(this.width.convertToPixels());
- Shape body = new Ellipse2D.Double(points[0].x - width / 2, points[0].y - width / 2,
- width, width);
- Composite oldComposite = g2d.getComposite();
- if (alpha < MAX_ALPHA) {
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
- / MAX_ALPHA));
- }
- g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
- g2d.fill(body);
- g2d.setComposite(oldComposite);
- Color finalBorderColor;
- if (outlineMode) {
- Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
- IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
- finalBorderColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
- .getOutlineColor();
- } else {
- finalBorderColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
- : borderColor;
- }
-
- g2d.setColor(finalBorderColor);
- g2d.draw(body);
- if (!outlineMode) {
- drawLead(g2d, componentState);
- }
- } else {
- // Normal mode with component body in the center and two lead parts.
- Rectangle shapeRect = shape.getBounds();
- Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
- // Transform graphics to draw the body in the right place and at the
- // right angle.
- AffineTransform oldTransform = g2d.getTransform();
- g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2, (points[0].y
- + points[1].y - shapeRect.height) / 2);
- g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
- // Draw body.
- Composite oldComposite = g2d.getComposite();
- if (alpha < MAX_ALPHA) {
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
- / MAX_ALPHA));
- }
- if (bodyColor != null) {
- if (bodyColor != null) {
- g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
- g2d.fill(shape);
- }
- }
- decorateComponentBody(g2d, outlineMode);
- g2d.setComposite(oldComposite);
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
- Color finalBorderColor;
- if (outlineMode) {
- Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
- IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
- finalBorderColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
- .getOutlineColor();
- } else {
- finalBorderColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
- : borderColor;
- }
- g2d.setColor(finalBorderColor);
- g2d.draw(shape);
- // Draw label.
- g2d.setFont(LABEL_FONT);
- Color finalLabelColor;
- if (outlineMode) {
- Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
- IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
- finalLabelColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
- .getOutlineColor();
- } else {
- finalLabelColor = componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
- : labelColor;
- }
- g2d.setColor(finalLabelColor);
- FontMetrics fontMetrics = g2d.getFontMetrics();
- String label = display == Display.NAME ? getName() : getValue().toString();
- // Adjust label angle if needed to make sure that it's readable.
- if ((theta >= Math.PI / 2 && theta <= Math.PI)
- || (theta < -Math.PI / 2 && theta > -Math.PI)) {
- g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2);
- }
- Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
- g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
- calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
-
- // Go back to the original transformation to draw leads.
- if (!outlineMode) {
- g2d.setTransform(oldTransform);
- int leadThickness = getClosestOdd(getLeadThickness());
- double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
- Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
- : getLeadColor(componentState);
- g2d.setColor(leadColor);
- int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
- int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
- g2d.drawLine(points[0].x, points[0].y, endX, endY);
- endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
- endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
- g2d.drawLine(points[1].x, points[1].y, endX, endY);
- if (shouldShadeLeads()) {
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
- leadColor = getLeadColor(componentState);
- g2d.setColor(leadColor);
- g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
- * leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
- g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
- - Math.PI)
- * leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
- * leadLength));
- }
- }
- }
- }
-
- private void drawLead(Graphics2D g2d, ComponentState componentState) {
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
- Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
- : getLeadColor(componentState);
- g2d.setColor(leadColor);
- g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
- if (shouldShadeLeads()) {
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness() - 2));
- leadColor = getLeadColor(componentState);
- g2d.setColor(leadColor);
- g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
- }
- }
-
- protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
- // Do nothing.
- }
-
- protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect,
- FontMetrics fontMetrics) {
- return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent();
- }
-
- protected boolean shouldShadeLeads() {
- return true;
- }
-
- protected boolean supportsStandingMode() {
- return false;
- }
-
- /**
- * @return default component length.
- */
- protected abstract Size getDefaultLength();
-
- /**
- * Returns default component width.
- *
- * @return
- */
- protected abstract Size getDefaultWidth();
-
- /**
- * @return shape that represents component body. Shape should not be
- * transformed and should be referenced to (0, 0).
- */
- protected abstract Shape getBodyShape();
-
- /**
- * @return default lead thickness. Override this method to change it.
- */
- protected int getLeadThickness() {
- return (int) LEAD_THICKNESS.convertToPixels();
- }
-
- /**
- * @return default lead color. Override this method to change it.
- */
- protected Color getLeadColor(ComponentState componentState) {
- return componentState == ComponentState.SELECTED
- || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
- }
-
- @Override
- public int getControlPointCount() {
- return points.length;
- }
-
- @Override
- public Point getControlPoint(int index) {
- return (Point) points[index];
- }
-
- @Override
- public boolean isControlPointSticky(int index) {
- return true;
- }
-
- @Override
- public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
- return VisibilityPolicy.ALWAYS;
- }
-
- @Override
- public void setControlPoint(Point point, int index) {
- points[index].setLocation(point);
- }
-
- @EditableProperty(name = "Color")
- public Color getBodyColor() {
- return bodyColor;
- }
-
- public void setBodyColor(Color bodyColor) {
- this.bodyColor = bodyColor;
- }
-
- @EditableProperty(name = "Border")
- public Color getBorderColor() {
- return borderColor;
- }
-
- public void setBorderColor(Color borderColor) {
- this.borderColor = borderColor;
- }
-
- @EditableProperty(name = "Length", defaultable = true)
- public Size getLength() {
- return length;
- }
-
- public void setLength(Size length) {
- this.length = length;
- }
-
- @EditableProperty(name = "Width", defaultable = true)
- public Size getWidth() {
- return width;
- }
-
- public void setWidth(Size width) {
- this.width = width;
- }
-
- @EditableProperty
- public Display getDisplay() {
- return display;
- }
-
- public void setDisplay(Display display) {
- this.display = display;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/IView.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/IView.java
deleted file mode 100644
index fe11e4b5..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/IView.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.diylc.core;
-
-import java.util.List;
-import java.util.Set;
-
-import org.diylc.common.PropertyWrapper;
-
-
-/**
- * Base interface for the main GUI component.
- *
- * @author Branislav Stojkovic
- */
-public interface IView {
-
- public static final int ERROR_MESSAGE = 0;
- public static final int INFORMATION_MESSAGE = 1;
- public static final int WARNING_MESSAGE = 2;
- public static final int QUESTION_MESSAGE = 3;
- public static final int PLAIN_MESSAGE = -1;
- public static final int DEFAULT_OPTION = -1;
- public static final int YES_NO_OPTION = 0;
- public static final int YES_NO_CANCEL_OPTION = 1;
- public static final int OK_CANCEL_OPTION = 2;
- public static final int YES_OPTION = 0;
- public static final int NO_OPTION = 1;
- public static final int CANCEL_OPTION = 2;
- public static final int OK_OPTION = 0;
-
- public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
- public static final String RADIO_BUTTON_GROUP_KEY = "org.diylc.radioButtonGroup";
-
- void showMessage(String message, String title, int messageType);
-
- int showConfirmDialog(String message, String title, int optionType, int messageType);
-
- boolean editProperties(List properties, Set defaultedProperties);
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java
deleted file mode 100644
index a4c3bd9f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/Project.java
+++ /dev/null
@@ -1,225 +0,0 @@
-package org.diylc.core;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.diylc.core.annotations.EditableProperty;
-import org.diylc.core.annotations.PositiveMeasureValidator;
-import org.diylc.core.measures.Size;
-import org.diylc.core.measures.SizeUnit;
-
-import com.diyfever.gui.update.VersionNumber;
-
-/**
- * Entity class that defines a project. Contains project properties and a
- * collection of components.This class is serialized to file. Some filed getters
- * are tagged with {@link EditableProperty} to enable for user to edit them.
- *
- * @author Branislav Stojkovic
- */
-public class Project implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static String DEFAULT_TITLE = "New Project";
- public static Size DEFAULT_WIDTH = new Size(29d, SizeUnit.cm);
- public static Size DEFAULT_HEIGHT = new Size(21d, SizeUnit.cm);
- public static Size DEFAULT_GRID_SPACING = new Size(0.1d, SizeUnit.in);
-
- private VersionNumber fileVersion;
-
- private String title;
- private String author;
- private String description;
- private Size width;
- private Size height;
- private Size gridSpacing;
- private List> components;
- private Set>> groups;
- private Set lockedLayers;
-
- public Project() {
- components = new ArrayList>();
- groups = new HashSet>>();
- lockedLayers = new HashSet();
- title = DEFAULT_TITLE;
- author = System.getProperty("user.name");
- width = DEFAULT_WIDTH;
- height = DEFAULT_HEIGHT;
- gridSpacing = DEFAULT_GRID_SPACING;
- }
-
- @EditableProperty(defaultable = false)
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- @EditableProperty
- public String getAuthor() {
- return author;
- }
-
- public void setAuthor(String author) {
- this.author = author;
- }
-
- @EditableProperty(defaultable = false)
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- @EditableProperty
- public Size getWidth() {
- return width;
- }
-
- public void setWidth(Size width) {
- this.width = width;
- }
-
- @EditableProperty
- public Size getHeight() {
- return height;
- }
-
- public void setHeight(Size height) {
- this.height = height;
- }
-
- @EditableProperty(name = "Grid spacing", validatorClass = SpacingValidator.class)
- public Size getGridSpacing() {
- return gridSpacing;
- }
-
- public void setGridSpacing(Size gridSpacing) {
- this.gridSpacing = gridSpacing;
- }
-
- /**
- * List of components sorted by z-order ascending.
- *
- * @return
- */
- public List> getComponents() {
- return components;
- }
-
- /**
- * Set of grouped components.
- *
- * @return
- */
- public Set>> getGroups() {
- return groups;
- }
-
- public Set getLockedLayers() {
- return lockedLayers;
- }
-
- public VersionNumber getFileVersion() {
- return fileVersion;
- }
-
- public void setFileVersion(VersionNumber fileVersion) {
- this.fileVersion = fileVersion;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((author == null) ? 0 : author.hashCode());
- result = prime * result + ((components == null) ? 0 : components.hashCode());
- result = prime * result + ((description == null) ? 0 : description.hashCode());
- result = prime * result + ((height == null) ? 0 : height.hashCode());
- result = prime * result + ((title == null) ? 0 : title.hashCode());
- result = prime * result + ((width == null) ? 0 : width.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Project other = (Project) obj;
- if (author == null) {
- if (other.author != null)
- return false;
- } else if (!author.equals(other.author))
- return false;
- if (components == null) {
- if (other.components != null)
- return false;
- } else if (!components.equals(other.components))
- return false;
- if (description == null) {
- if (other.description != null)
- return false;
- } else if (!description.equals(other.description))
- return false;
- if (height == null) {
- if (other.height != null)
- return false;
- } else if (!height.equals(other.height))
- return false;
- if (title == null) {
- if (other.title != null)
- return false;
- } else if (!title.equals(other.title))
- return false;
- if (width == null) {
- if (other.width != null)
- return false;
- } else if (!width.equals(other.width))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return title;
- }
-
- public static class SpacingValidator extends PositiveMeasureValidator {
-
- @Override
- public void validate(Object value) throws ValidationException {
- super.validate(value);
- Size size = (Size) value;
- if (size.compareTo(new Size(1d, SizeUnit.mm)) < 0) {
- throw new ValidationException("must be greater than 1mm");
- }
- if (size.compareTo(new Size(1d, SizeUnit.in)) > 0) {
- throw new ValidationException("must be less than 1in");
- }
- }
- }
-
- // @Override
- // public Project clone() throws CloneNotSupportedException {
- // List clonedComponents = new
- // ArrayList();
- // for (IDIYComponent component : components) {
- // clonedComponents.add(component.clone());
- // }
- // Project project = new Project(title, author, description,
- // width.clone(), height.clone(), clonedComponents);
- // return project;
- // }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/annotations/ComponentDescriptor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/annotations/ComponentDescriptor.java
deleted file mode 100644
index c9bbaa21..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/annotations/ComponentDescriptor.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.diylc.core.annotations;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import org.diylc.core.CreationMethod;
-import org.diylc.core.IDIYComponent;
-
-/**
- * Annotation for {@link IDIYComponent} implementation. Describes component
- * properties.
- *
- * @author Branislav Stojkovic
- */
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ComponentDescriptor {
-
- /**
- * @return component type name.
- */
- String name();
-
- /**
- * @return component type description.
- */
- String description();
-
- /**
- * @return method that should be used to create a component. If
- * CreationMethod.POINT_BY_POINT is used, user will
- * have to select ending points before the component is created.
- */
- CreationMethod creationMethod() default CreationMethod.SINGLE_CLICK;
-
- /**
- * @return component category, e.g. "Passive", "Semiconductors", etc.
- */
- String category();
-
- /**
- * @return component author name.
- */
- String author();
-
- /**
- * @return prefix that will be used to generate component instance names,
- * e.g. "R" for resistors or "Q" for transistors.
- */
- String instanceNamePrefix();
-
- /**
- * @return Z-order of the component.
- */
- double zOrder();
-
- /**
- * @return when false, moving one control point will cause all the others to
- * move together with it.
- */
- boolean stretchable() default true;
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/AbstractMeasure.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/AbstractMeasure.java
deleted file mode 100644
index 0245fba9..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/AbstractMeasure.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.diylc.core.measures;
-
-import java.io.Serializable;
-import java.text.DecimalFormat;
-import java.text.Format;
-
-public class AbstractMeasure> implements Serializable, Cloneable {
-
- private static final long serialVersionUID = 1L;
-
- protected static final Format format = new DecimalFormat("0.####");
-
- protected Double value;
- protected T unit;
-
- public AbstractMeasure() {
- }
-
- public AbstractMeasure(Double value, T unit) {
- super();
- this.value = value;
- this.unit = unit;
- }
-
- public Double getValue() {
- return value;
- }
-
- public void setValue(Double value) {
- this.value = value;
- }
-
- public T getUnit() {
- return unit;
- }
-
- public void setUnit(T multiplier) {
- this.unit = multiplier;
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((unit == null) ? 0 : unit.hashCode());
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- AbstractMeasure> other = (AbstractMeasure>) obj;
- if (unit == null) {
- if (other.unit != null)
- return false;
- } else if (!unit.equals(other.unit))
- return false;
- if (value == null) {
- if (other.value != null)
- return false;
- } else if (!value.equals(other.value))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return format.format(value) + " " + unit;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Resistance.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Resistance.java
deleted file mode 100644
index 63236e70..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/Resistance.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.diylc.core.measures;
-
-import java.awt.Color;
-
-import org.diylc.common.ResistorColorCode;
-
-public class Resistance extends AbstractMeasure {
-
- private static final long serialVersionUID = 1L;
-
- private static final Color[] COLOR_DIGITS = new Color[] { Color.black, Color.decode("#8B4513"),
- Color.red, Color.orange, Color.yellow, Color.decode("#76EE00"), Color.blue,
- Color.decode("#91219E"), Color.lightGray, Color.white };
- private static final Color[] COLOR_MULTIPLIER = new Color[] { Color.lightGray.brighter(),
- Color.decode("#FFB90F"), Color.black, Color.decode("#8B4513"), Color.red, Color.orange,
- Color.yellow, Color.decode("#76EE00"), Color.blue };
-
- public Resistance() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- public Resistance(Double value, ResistanceUnit multiplier) {
- super(value, multiplier);
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public Resistance clone() throws CloneNotSupportedException {
- return new Resistance(value, unit);
- }
-
- public Color[] getColorCode(ResistorColorCode resistorColorCode) {
- Color[] bands;
- double base = getValue() * getUnit().getFactor();
- int multiplier = 0;
- while (base > (resistorColorCode == ResistorColorCode._4_BAND ? 99 : 999)) {
- multiplier += 1;
- base /= 10;
- }
- while (base < (resistorColorCode == ResistorColorCode._4_BAND ? 10 : 100)) {
- multiplier -= 1;
- base *= 10;
- }
- if (multiplier > 6 || multiplier < -2) {
- // Out of range.
- return new Color[] {};
- }
- switch (resistorColorCode) {
- case _4_BAND:
- bands = new Color[3];
- bands[0] = COLOR_DIGITS[(int) (base / 10)];
- bands[1] = COLOR_DIGITS[(int) (base % 10)];
- bands[2] = COLOR_MULTIPLIER[multiplier + 2];
- break;
- case _5_BAND:
- bands = new Color[4];
- bands[0] = COLOR_DIGITS[(int) (base / 100)];
- bands[1] = COLOR_DIGITS[(int) (base / 10 % 10)];
- bands[2] = COLOR_DIGITS[(int) (base % 10)];
- bands[3] = COLOR_MULTIPLIER[multiplier + 2];
- break;
- default:
- bands = new Color[] {};
- }
- return bands;
- }
-
- public static Resistance parseResistance(String value) {
- for (ResistanceUnit unit : ResistanceUnit.values()) {
- if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
- value = value.substring(0, value.length() - unit.toString().length() - 1).trim();
- return new Resistance(Double.parseDouble(value), unit);
- }
- }
- throw new IllegalArgumentException("Could not parse resistance: " + value);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/ResistanceUnit.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/ResistanceUnit.java
deleted file mode 100644
index 9d7a917f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/core/measures/ResistanceUnit.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.diylc.core.measures;
-
-public enum ResistanceUnit implements Unit {
-
- R(1, "\u03a9"), K(1e3, "K"), M(1e6, "M");
-
- double factor;
- String display;
-
- private ResistanceUnit(double factor, String display) {
- this.factor = factor;
- this.display = display;
- }
-
- @Override
- public double getFactor() {
- return factor;
- }
-
- @Override
- public String toString() {
- return display;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java
deleted file mode 100644
index baef6933..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.diylc.images;
-
-import java.awt.Image;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-
-import javax.imageio.ImageIO;
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-
-/**
- * Loads image resources as Icons.
- *
- * @author Branislav Stojkovic
- */
-public enum IconLoader {
-
- Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue(
- "disk_blue.png"), SaveAs("save_as.png"), Exit("exit.png"), DocumentPlainYellow(
- "document_plain_yellow.png"), PhotoScenery("photo_scenery.png"), LightBulbOn(
- "lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd("notebook_add.png"), FormGreen(
- "form_green.png"), Gears("gears.png"), About("about.png"), WindowColors(
- "window_colors.png"), WindowGear("window_gear.png"), NavigateCheck("navigate_check.png"), Undo(
- "undo.png"), Error("error.png"), Warning("warning.png"), ZoomSmall("zoom_small.png"), MoveSmall(
- "move_small.png"), Print("print.png"), PDF("pdf.png"), Excel("excel.png"), CSV(
- "csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste(
- "paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
- "id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
- "wrench.png"), Group("group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq(
- "faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
- "donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
- "icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent(
- "edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens(
- "pens.png"), Sort("sort.png");
-
- protected String name;
-
- private IconLoader(String name) {
- this.name = name;
- }
-
- public Icon getIcon() {
- java.net.URL imgURL = getClass().getResource(name);
- if (imgURL != null) {
- return new ImageIcon(imgURL, name);
- } else {
- System.err.println("Couldn't find file: " + name);
- return null;
- }
- }
-
- public Image getImage() {
- BufferedImage img = null;
- try {
- img = ImageIO.read(getClass().getResourceAsStream(name));
- } catch (IOException e) {
- System.err.println("Couldn't find file: " + name);
- }
- return img;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java
deleted file mode 100644
index 3eb9bee2..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java
+++ /dev/null
@@ -1,225 +0,0 @@
-package org.diylc.presenter;
-
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.Icon;
-import javax.swing.ImageIcon;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.ComponentType;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.CreationMethod;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.IPropertyValidator;
-import org.diylc.core.annotations.ComponentDescriptor;
-import org.diylc.core.annotations.EditableProperty;
-
-import com.rits.cloning.Cloner;
-
-/**
- * Utility class with component processing methods.
- *
- * @author Branislav Stojkovic
- */
-public class ComponentProcessor {
-
- private static final Logger LOG = Logger.getLogger(ComponentProcessor.class);
-
- private static ComponentProcessor instance;
-
- private Map> propertyCache;
- private Map propertyValidatorCache;
- private Map componentTypeMap;
-
- private Cloner cloner;
-
- public static ComponentProcessor getInstance() {
- if (instance == null) {
- instance = new ComponentProcessor();
- }
- return instance;
- }
-
- private ComponentProcessor() {
- super();
- this.cloner = new Cloner();
- this.propertyCache = new HashMap>();
- this.componentTypeMap = new HashMap();
- this.propertyValidatorCache = new HashMap();
- }
-
- public ComponentType extractComponentTypeFrom(Class extends IDIYComponent>> clazz) {
- if (componentTypeMap.containsKey(clazz.getName())) {
- return componentTypeMap.get(clazz.getName());
- }
- String name;
- String description;
- CreationMethod creationMethod;
- String category;
- String namePrefix;
- String author;
- Icon icon;
- double zOrder;
- boolean stretchable;
- if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
- ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
- name = annotation.name();
- description = annotation.description();
- creationMethod = annotation.creationMethod();
- category = annotation.category();
- namePrefix = annotation.instanceNamePrefix();
- author = annotation.author();
- zOrder = annotation.zOrder();
- stretchable = annotation.stretchable();
- } else {
- name = clazz.getSimpleName();
- description = "";
- creationMethod = CreationMethod.SINGLE_CLICK;
- category = "Uncategorized";
- namePrefix = "Unknown";
- author = "Unknown";
- zOrder = IDIYComponent.COMPONENT;
- stretchable = true;
- }
- icon = null;
- // Draw component icon.
- try {
- IDIYComponent> componentInstance = (IDIYComponent>) clazz.newInstance();
- Image image = new BufferedImage(Presenter.ICON_SIZE, Presenter.ICON_SIZE,
- java.awt.image.BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2d = (Graphics2D) image.getGraphics();
- g2d
- .setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- componentInstance.drawIcon(g2d, Presenter.ICON_SIZE, Presenter.ICON_SIZE);
- icon = new ImageIcon(image);
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- ComponentType componentType = new ComponentType(name, description, creationMethod,
- category, namePrefix, author, icon, clazz, zOrder, stretchable);
- componentTypeMap.put(clazz.getName(), componentType);
- return componentType;
- }
-
- /**
- * Extracts all editable properties from the component class.
- *
- * @param clazz
- * @return
- */
- public List extractProperties(Class> clazz) {
- if (propertyCache.containsKey(clazz.getName())) {
- return cloner.deepClone(propertyCache.get(clazz.getName()));
- }
- List properties = new ArrayList();
- for (Method method : clazz.getMethods()) {
- if (method.getName().startsWith("get")) {
- try {
- if (method.isAnnotationPresent(EditableProperty.class)
- && !method.isAnnotationPresent(Deprecated.class)) {
- EditableProperty annotation = method.getAnnotation(EditableProperty.class);
- String name;
- if (annotation.name().equals("")) {
- name = method.getName().substring(3);
- } else {
- name = annotation.name();
- }
- IPropertyValidator validator = getPropertyValidator(annotation
- .validatorClass());
- Method setter = clazz.getMethod("set" + method.getName().substring(3),
- method.getReturnType());
- PropertyWrapper property = new PropertyWrapper(name,
- method.getReturnType(), method.getName(), setter.getName(),
- annotation.defaultable(), validator);
- properties.add(property);
- }
- } catch (NoSuchMethodException e) {
- LOG.debug("No matching setter found for \"" + method.getName()
- + "\". Skipping...");
- }
- }
- }
-
- propertyCache.put(clazz.getName(), properties);
- return cloner.deepClone(properties);
- }
-
- /**
- * Returns properties that have the same value for all the selected
- * components.
- *
- * @param selectedComponents
- * @return
- */
- public List getMutualSelectionProperties(
- List> selectedComponents) throws Exception {
- if (selectedComponents.isEmpty()) {
- return null;
- }
- List properties = new ArrayList();
- IDIYComponent> firstComponent = selectedComponents.get(0);
- properties.addAll(extractProperties(firstComponent.getClass()));
- // Initialize values
- for (PropertyWrapper property : properties) {
- property.readFrom(firstComponent);
- }
- for (int i = 1; i < selectedComponents.size(); i++) {
- IDIYComponent> component = selectedComponents.get(i);
- List newProperties = extractProperties(component.getClass());
- for (PropertyWrapper property : newProperties) {
- property.readFrom(component);
- }
- properties.retainAll(newProperties);
- // Try to find matching properties in old and new lists and see if
- // their values match.
- for (PropertyWrapper oldProperty : properties) {
- if (newProperties.contains(oldProperty)) {
- PropertyWrapper newProperty = newProperties.get(newProperties
- .indexOf(oldProperty));
- if ((newProperty.getValue() != null && newProperty.getValue() == null)
- || !newProperty.getValue().equals(oldProperty.getValue())) {
- // Values don't match, so the property is not unique valued.
- oldProperty.setUnique(false);
- }
- }
- }
- // for (PropertyWrapper property : properties) {
- // try {
- // property.readUniqueFrom(component);
- // } catch (Exception e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // }
- }
- Collections.sort(properties, ComparatorFactory.getInstance().getPropertyNameComparator());
- return properties;
- }
-
- private IPropertyValidator getPropertyValidator(Class extends IPropertyValidator> clazz) {
- if (propertyValidatorCache.containsKey(clazz.getName())) {
- return propertyValidatorCache.get(clazz.getName());
- }
- IPropertyValidator validator;
- try {
- validator = clazz.newInstance();
- } catch (Exception e) {
- LOG.error("Could not instantiate validator for " + clazz.getName(), e);
- return null;
- }
- propertyValidatorCache.put(clazz.getName(), validator);
- return validator;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java
deleted file mode 100644
index 778208de..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/DrawingManager.java
+++ /dev/null
@@ -1,396 +0,0 @@
-package org.diylc.presenter;
-
-import java.awt.AlphaComposite;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.geom.Area;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.DrawOption;
-import org.diylc.common.EventType;
-import org.diylc.common.GridType;
-import org.diylc.common.IComponentFiler;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.ObjectCache;
-import org.diylc.core.ComponentState;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.Project;
-import org.diylc.core.Theme;
-import org.diylc.core.VisibilityPolicy;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.diyfever.gui.simplemq.MessageDispatcher;
-
-/**
- * Utility that deals with painting {@link Project} on the {@link Graphics2D}
- * and keeps areas taken by each drawn component.
- *
- * @author Branislav Stojkovic
- */
-public class DrawingManager {
-
- private static final Logger LOG = Logger.getLogger(DrawingManager.class);
-
- public static int CONTROL_POINT_SIZE = 7;
-
- public static final String ZOOM_KEY = "zoom";
-
- public static String DEBUG_COMPONENT_AREAS = "org.diylc.debugComponentAreas";
-
- public static Color CONTROL_POINT_COLOR = Color.blue;
- public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
-
- private Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
- IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
-
- // Keeps Area object of each drawn component.
- private Map, Area> componentAreaMap;
- // Maps components to the last state they are drawn in. Also, used to
- // determine which components are invalidated when they are not in the map.
- private Map, ComponentState> lastDrawnStateMap;
-
- private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
- private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
- private List> failedComponents = new ArrayList>();
-
- private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
- // 1d);
-
- private MessageDispatcher messageDispatcher;
-
- private boolean debugComponentAreas;
-
- public DrawingManager(MessageDispatcher messageDispatcher) {
- super();
- this.messageDispatcher = messageDispatcher;
- componentAreaMap = new HashMap, Area>();
- lastDrawnStateMap = new HashMap, ComponentState>();
- String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
- debugComponentAreas = debugComponentAreasStr != null
- && debugComponentAreasStr.equalsIgnoreCase("true");
- }
-
- /**
- * Paints the project onto the canvas and returns the list of components
- * that failed to draw.
- *
- * @param g2d
- * @param project
- * @param drawOptions
- * @param filter
- * @param selectionRect
- * @param selectedComponents
- * @param lockedComponents
- * @param groupedComponents
- * @param controlPointSlot
- * @param componentSlot
- * @param dragInProgress
- * @return
- */
- public List> drawProject(Graphics2D g2d, Project project,
- Set drawOptions, IComponentFiler filter, Rectangle selectionRect,
- List> selectedComponents, Set> lockedComponents,
- Set> groupedComponents, List controlPointSlot,
- IDIYComponent> componentSlot, boolean dragInProgress) {
- failedComponents.clear();
- if (project == null) {
- return failedComponents;
- }
- G2DWrapper g2dWrapper = new G2DWrapper(g2d);
-
- if (drawOptions.contains(DrawOption.ANTIALIASING)) {
- g2d
- .setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- } else {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
- g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
- }
- if (ConfigurationManager.getInstance()
- .readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
- RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
- g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- } else {
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
- RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
- RenderingHints.VALUE_COLOR_RENDER_SPEED);
- g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
- g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- }
-
- double zoom = 1d;
- if (drawOptions.contains(DrawOption.ZOOM)) {
- zoom = zoomLevel;
- } else {
- zoom = 1 / Constants.PIXEL_SIZE;
- }
-
- // AffineTransform initialTx = g2d.getTransform();
- Dimension d = getCanvasDimensions(project, zoom, true);
-
- g2dWrapper.setColor(theme.getBgColor());
- g2dWrapper.fillRect(0, 0, d.width, d.height);
- g2d.clip(new Rectangle(new Point(0, 0), d));
-
- GridType gridType = GridType.LINES;
- if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
- double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
- if (gridType == GridType.CROSSHAIR) {
- g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
- 10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2 },
- (float) zoomStep / 4));
- } else if (gridType == GridType.DOT) {
- g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
- 10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
- }
-
- g2dWrapper.setColor(theme.getGridColor());
- for (double i = zoomStep; i < d.width; i += zoomStep) {
- g2dWrapper.drawLine((int) i, 0, (int) i, d.height - 1);
- }
- for (double j = zoomStep; j < d.height; j += zoomStep) {
- g2dWrapper.drawLine(0, (int) j, d.width - 1, (int) j);
- }
- }
-
- if (Math.abs(1.0 - zoom) > 1e-4) {
- g2dWrapper.scale(zoom, zoom);
- }
-
- // Composite mainComposite = g2d.getComposite();
- // Composite alphaComposite =
- // AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
-
- // g2dWrapper.resetTx();
-
- // componentAreaMap.clear();
- for (IDIYComponent> component : project.getComponents()) {
- // Do not draw the component if it's filtered out.
- if (filter != null && !filter.testComponent(component)) {
- continue;
- }
- ComponentState state = ComponentState.NORMAL;
- if (drawOptions.contains(DrawOption.SELECTION)
- && selectedComponents.contains(component)) {
- if (dragInProgress) {
- state = ComponentState.DRAGGING;
- } else {
- state = ComponentState.SELECTED;
- }
- }
- // Do not track the area if component is not invalidated and was
- // drawn in the same state.
- boolean trackArea = lastDrawnStateMap.get(component) != state;
- g2dWrapper.startedDrawingComponent();
- if (!trackArea) {
- g2dWrapper.stopTracking();
- }
- // Draw locked components in a new composite.
- if (lockedComponents.contains(component)) {
- g2d.setComposite(lockedComposite);
- }
- // Draw the component through the g2dWrapper.
- try {
- component.draw(g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE),
- project, g2dWrapper);
- } catch (Exception e) {
- LOG.error("Error drawing " + component.getName(), e);
- failedComponents.add(component);
- }
- Area area = g2dWrapper.finishedDrawingComponent();
- if (trackArea && area != null && !area.isEmpty()) {
- componentAreaMap.put(component, area);
- lastDrawnStateMap.put(component, state);
- }
- }
-
- // Draw control points.
- if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
- // Draw unselected points first to make sure they are below.
- if (dragInProgress || drawOptions.contains(DrawOption.OUTLINE_MODE)) {
- for (IDIYComponent> component : project.getComponents()) {
- for (int i = 0; i < component.getControlPointCount(); i++) {
- VisibilityPolicy visibilityPolicy = component
- .getControlPointVisibilityPolicy(i);
- if ((groupedComponents.contains(component)
- && (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
- .contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
- .contains(component)
- && !selectedComponents.contains(component) && component
- .getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
- g2dWrapper.setColor(CONTROL_POINT_COLOR);
- Point controlPoint = component.getControlPoint(i);
- int pointSize = CONTROL_POINT_SIZE - 2;
- g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
- - pointSize / 2, pointSize, pointSize);
- }
- }
- }
- }
- // Then draw the selected ones.
- for (IDIYComponent> component : selectedComponents) {
- for (int i = 0; i < component.getControlPointCount(); i++) {
- if (!groupedComponents.contains(component)
- && (component.getControlPointVisibilityPolicy(i) == VisibilityPolicy.WHEN_SELECTED || component
- .getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS)) {
-
- Point controlPoint = component.getControlPoint(i);
- int pointSize = CONTROL_POINT_SIZE;
-
- g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
- g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
- - pointSize / 2, pointSize, pointSize);
- g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
- g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1,
- controlPoint.y - CONTROL_POINT_SIZE / 2 + 1,
- CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
- }
- }
- }
- }
-
- // Draw component slot in a separate composite.
- if (componentSlot != null) {
- g2dWrapper.startedDrawingComponent();
- g2dWrapper.setComposite(slotComposite);
- try {
- componentSlot.draw(g2dWrapper, ComponentState.NORMAL, drawOptions
- .contains(DrawOption.OUTLINE_MODE), project, g2dWrapper);
- } catch (Exception e) {
- LOG.error("Error drawing " + componentSlot.getName(), e);
- failedComponents.add(componentSlot);
- }
- g2dWrapper.finishedDrawingComponent();
- }
-
- // Draw control points of the component in the slot.
- if (controlPointSlot != null) {
- for (Point point : controlPointSlot) {
- if (point != null) {
- g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
- g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y
- - CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
- g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
- g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y
- - CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2,
- CONTROL_POINT_SIZE - 2);
- }
- }
- }
-
- // Go back to the original transformation and zoom in to draw the
- // selection rectangle and other similar elements.
- // g2d.setTransform(initialTx);
- // if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 -
- // zoomLevel) > 1e-4)) {
- // g2d.scale(zoomLevel, zoomLevel);
- // }
-
- // At the end draw selection rectangle if needed.
- if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) {
- g2d.setColor(Color.white);
- g2d.draw(selectionRect);
- g2d.setColor(Color.black);
- g2d.setStroke(Constants.DASHED_STROKE);
- g2d.draw(selectionRect);
- }
-
- // Draw component area for test
- if (debugComponentAreas) {
- g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
- g2d.setColor(Color.red);
- for (Area area : componentAreaMap.values()) {
- g2d.draw(area);
- }
- }
-
- return failedComponents;
- }
-
- public double getZoomLevel() {
- return zoomLevel;
- }
-
- public void setZoomLevel(double zoomLevel) {
- this.zoomLevel = zoomLevel;
- fireZoomChanged();
- // ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel);
- }
-
- public void invalidateComponent(IDIYComponent> component) {
- componentAreaMap.remove(component);
- lastDrawnStateMap.remove(component);
- }
-
- public Area getComponentArea(IDIYComponent> component) {
- return componentAreaMap.get(component);
- }
-
- public void clearComponentAreaMap() {
- componentAreaMap.clear();
- }
-
- public List> findComponentsAt(Point point, Project project) {
- List> components = new ArrayList>();
- for (int i = 0; i < project.getComponents().size(); i++) {
- Area area = componentAreaMap.get(project.getComponents().get(i));
- if (area != null && area.contains(point)) {
- components.add(project.getComponents().get(i));
- }
- }
- return components;
- }
-
- public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) {
- double width = project.getWidth().convertToPixels();
- double height = project.getHeight().convertToPixels();
- if (useZoom) {
- width *= zoomLevel;
- height *= zoomLevel;
- } else {
- width /= Constants.PIXEL_SIZE;
- height /= Constants.PIXEL_SIZE;
- }
- return new Dimension((int) width, (int) height);
- }
-
- public void fireZoomChanged() {
- messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- public Theme getTheme() {
- return theme;
- }
-
- public void setTheme(Theme theme) {
- this.theme = theme;
- ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/G2DWrapper.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/G2DWrapper.java
deleted file mode 100644
index 10e638f0..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/G2DWrapper.java
+++ /dev/null
@@ -1,673 +0,0 @@
-package org.diylc.presenter;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Composite;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Polygon;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Arc2D;
-import java.awt.geom.Area;
-import java.awt.geom.CubicCurve2D;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.Line2D;
-import java.awt.geom.PathIterator;
-import java.awt.geom.Point2D;
-import java.awt.geom.QuadCurve2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.RoundRectangle2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
-import java.awt.image.ImageObserver;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
-import java.text.AttributedCharacterIterator;
-import java.util.Map;
-
-import org.diylc.core.IDrawingObserver;
-
-/**
- * {@link Graphics2D} wrapper that keeps track of all drawing actions and
- * creates an {@link Area} that corresponds to drawn objects. Before each
- * component is drawn, {@link #startedDrawingComponent()} should be called.
- * After the component is drawn, area may be retrieved using
- * {@link #finishedDrawingComponent()}. Graphics configuration (color, font,
- * etc) is reset between each two components.
- *
- * @author Branislav Stojkovic
- */
-class G2DWrapper extends Graphics2D implements IDrawingObserver {
-
- public static int LINE_SENSITIVITY_MARGIN = 2;
- public static int CURVE_SENSITIVITY = 6;
-
- private boolean drawingComponent = false;
- private boolean trackingAllowed = true;
-
- private Graphics2D canvasGraphics;
- private Stroke originalStroke;
- private Color originalColor;
- private Composite originalComposite;
- private AffineTransform originalTx;
- private Font originalFont;
- private AffineTransform currentTx;
- private Area currentArea;
- private Shape lastShape;
-
- /**
- * Creates a wrapper around specified {@link Graphics2D} object.
- *
- * @param canvasGraphics
- */
- public G2DWrapper(Graphics2D canvasGraphics) {
- super();
- this.canvasGraphics = canvasGraphics;
- currentArea = new Area();
- currentTx = new AffineTransform();
- }
-
- /**
- * Clears out the current area and caches canvas settings.
- */
- public void startedDrawingComponent() {
- drawingComponent = true;
- currentArea = new Area();
- originalStroke = canvasGraphics.getStroke();
- originalColor = canvasGraphics.getColor();
- originalTx = canvasGraphics.getTransform();
- originalComposite = canvasGraphics.getComposite();
- originalFont = canvasGraphics.getFont();
- currentTx = new AffineTransform();
- lastShape = null;
- startTracking();
- }
-
- /**
- * Reverts {@link Graphics2D} settings and returns area drawn by component
- * in the meantime.
- *
- * @return
- */
- public Area finishedDrawingComponent() {
- drawingComponent = false;
- canvasGraphics.setStroke(originalStroke);
- canvasGraphics.setColor(originalColor);
- canvasGraphics.setTransform(originalTx);
- canvasGraphics.setComposite(originalComposite);
- canvasGraphics.setFont(originalFont);
- return currentArea;
- }
-
- @Override
- public void startTracking() {
- this.trackingAllowed = true;
- }
-
- @Override
- public void stopTracking() {
- this.trackingAllowed = false;
- }
-
- /**
- * Appends shape interior to the current component area.
- *
- * @param s
- */
- private void appendShape(Shape s) {
- if (!drawingComponent || !trackingAllowed) {
- return;
- }
- Rectangle2D bounds = s.getBounds2D();
- // Only cache the shape if it's not 1D.
- if (bounds.getWidth() > 1 && bounds.getHeight() > 1) {
- Area area = new Area(s);
- area.transform(currentTx);
- currentArea.add(area);
- lastShape = s;
- }
- }
-
- /**
- * Appends shape outline to the current component area.
- *
- * @param s
- */
- private void appendShapeOutline(Shape s) {
- // Do not add shape outline if the same shape has been filled recently.
- if (!drawingComponent || !trackingAllowed || s.equals(lastShape)) {
- return;
- }
- lastShape = s;
- PathIterator pathIterator = s.getPathIterator(null);
- double thickness;
- if (getStroke() instanceof BasicStroke) {
- thickness = ((BasicStroke) getStroke()).getLineWidth() + 2 * LINE_SENSITIVITY_MARGIN;
- } else {
- thickness = 2 * LINE_SENSITIVITY_MARGIN;
- }
- Point2D prevPoint = null;
- while (!pathIterator.isDone()) {
- double[] coord = new double[6];
- int type = pathIterator.currentSegment(coord);
- switch (type) {
- case PathIterator.SEG_MOVETO:
- prevPoint = new Point2D.Double(coord[0], coord[1]);
- break;
- case PathIterator.SEG_LINETO:
- // Represent straight line with a rectangle.
- Point2D nextPoint = new Point2D.Double(coord[0], coord[1]);
- Double theta = Math.atan2(nextPoint.getY() - prevPoint.getY(), nextPoint.getX()
- - prevPoint.getX());
- double width = Math.sqrt(Math.pow(nextPoint.getX() - prevPoint.getX(), 2)
- + Math.pow(nextPoint.getY() - prevPoint.getY(), 2));
- double midX = (prevPoint.getX() + nextPoint.getX()) / 2;
- double midY = (prevPoint.getY() + nextPoint.getY()) / 2;
- Rectangle2D rect = new Rectangle2D.Double(midX - width / 2, midY - thickness / 2,
- width, thickness);
- Area area = new Area(rect);
- area.transform(AffineTransform.getRotateInstance(theta, midX, midY));
-// area.transform(currentTx);
- appendShape(area);
- // Set the prev point to line end
- prevPoint = nextPoint;
- break;
- case PathIterator.SEG_CUBICTO:
- CubicCurve2D cubicCurve = new CubicCurve2D.Double(prevPoint.getX(), prevPoint
- .getY(), coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
- addCubicCurveArea(cubicCurve);
- prevPoint = new Point2D.Double(coord[4], coord[5]);
- break;
- case PathIterator.SEG_QUADTO:
- QuadCurve2D quadCurve = new QuadCurve2D.Double(prevPoint.getX(), prevPoint.getY(),
- coord[0], coord[1], coord[2], coord[3]);
- addQuadCurveArea(quadCurve);
- prevPoint = new Point2D.Double(coord[3], coord[3]);
- break;
- }
- pathIterator.next();
- }
- }
-
- /**
- * Adds a cubic curve to the component area. It uses subdivision to
- * approximate the curve with a series of straight lines.
- *
- * @param curve
- */
- private void addCubicCurveArea(CubicCurve2D curve) {
- // When end points are close enough, approximate the curve with a
- // straight line.
- if (curve.getFlatness() < CURVE_SENSITIVITY) {
- appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
- } else {
- CubicCurve2D leftSubcurve = new CubicCurve2D.Double();
- CubicCurve2D rightSubcurve = new CubicCurve2D.Double();
- curve.subdivide(leftSubcurve, rightSubcurve);
- addCubicCurveArea(leftSubcurve);
- addCubicCurveArea(rightSubcurve);
- }
- }
-
- /**
- * Adds a quad curve to the component area. It uses subdivision to
- * approximate the curve with a series of straight lines.
- *
- * @param curve
- */
- private void addQuadCurveArea(QuadCurve2D curve) {
- // When end points are close enough, approximate the curve with a
- // straight line.
- if (curve.getFlatness() < CURVE_SENSITIVITY) {
- appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
- } else {
- QuadCurve2D leftSubcurve = new QuadCurve2D.Double();
- QuadCurve2D rightSubcurve = new QuadCurve2D.Double();
- curve.subdivide(leftSubcurve, rightSubcurve);
- addQuadCurveArea(leftSubcurve);
- addQuadCurveArea(rightSubcurve);
- }
- }
-
- @Override
- public void addRenderingHints(Map, ?> hints) {
- canvasGraphics.addRenderingHints(hints);
- }
-
- @Override
- public void clip(Shape s) {
- canvasGraphics.clip(s);
- }
-
- @Override
- public void draw(Shape s) {
- canvasGraphics.draw(s);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(s);
- }
- }
-
- @Override
- public void drawGlyphVector(GlyphVector g, float x, float y) {
- canvasGraphics.drawGlyphVector(g, x, y);
- }
-
- @Override
- public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
- // FIXME: process map
- return canvasGraphics.drawImage(img, xform, obs);
- }
-
- @Override
- public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
- canvasGraphics.drawImage(img, op, x, y);
- // FIXME: process map
- }
-
- @Override
- public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
- canvasGraphics.drawRenderableImage(img, xform);
- // FIXME: process map
- }
-
- @Override
- public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
- canvasGraphics.drawRenderedImage(img, xform);
- // FIXME: process map
- }
-
- @Override
- public void drawString(String str, int x, int y) {
- canvasGraphics.drawString(str, x, y);
- if (drawingComponent && trackingAllowed) {
- FontMetrics fontMetrics = canvasGraphics.getFontMetrics();
- Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
- appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(),
- rect.getHeight()));
- }
- }
-
- @Override
- public void drawString(String str, float x, float y) {
- canvasGraphics.drawString(str, x, y);
- if (drawingComponent && trackingAllowed) {
- FontMetrics fontMetrics = canvasGraphics.getFontMetrics();
- Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
- appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(),
- rect.getHeight()));
- }
- }
-
- @Override
- public void drawString(AttributedCharacterIterator iterator, int x, int y) {
- canvasGraphics.drawString(iterator, x, y);
- // FIXME: process map
- }
-
- @Override
- public void drawString(AttributedCharacterIterator iterator, float x, float y) {
- canvasGraphics.drawString(iterator, x, y);
- // FIXME: process map
- }
-
- @Override
- public void fill(Shape s) {
- canvasGraphics.fill(s);
- appendShape(s);
- }
-
- @Override
- public Color getBackground() {
- return canvasGraphics.getBackground();
- }
-
- @Override
- public Composite getComposite() {
- return canvasGraphics.getComposite();
- }
-
- @Override
- public GraphicsConfiguration getDeviceConfiguration() {
- return canvasGraphics.getDeviceConfiguration();
- }
-
- @Override
- public FontRenderContext getFontRenderContext() {
- return canvasGraphics.getFontRenderContext();
- }
-
- @Override
- public Paint getPaint() {
- return canvasGraphics.getPaint();
- }
-
- @Override
- public Object getRenderingHint(Key hintKey) {
- return canvasGraphics.getRenderingHint(hintKey);
- }
-
- @Override
- public RenderingHints getRenderingHints() {
- return canvasGraphics.getRenderingHints();
- }
-
- @Override
- public Stroke getStroke() {
- return canvasGraphics.getStroke();
- }
-
- @Override
- public AffineTransform getTransform() {
- return canvasGraphics.getTransform();
- }
-
- @Override
- public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
- return canvasGraphics.hit(rect, s, onStroke);
- }
-
- @Override
- public void rotate(double theta) {
- canvasGraphics.rotate(theta);
- currentTx.rotate(theta);
- }
-
- @Override
- public void rotate(double theta, double x, double y) {
- canvasGraphics.rotate(theta, x, y);
- currentTx.rotate(theta, x, y);
- }
-
- @Override
- public void scale(double sx, double sy) {
- canvasGraphics.scale(sx, sy);
- currentTx.scale(sx, sy);
- }
-
- @Override
- public void setBackground(Color color) {
- canvasGraphics.setBackground(color);
- // FIXME: fix map
- }
-
- @Override
- public void setComposite(Composite comp) {
- canvasGraphics.setComposite(comp);
- // FIXME: check this.
- }
-
- @Override
- public void setPaint(Paint paint) {
- canvasGraphics.setPaint(paint);
- // FIXME: check this
- }
-
- @Override
- public void setRenderingHint(Key hintKey, Object hintValue) {
- canvasGraphics.setRenderingHint(hintKey, hintValue);
- // FIXME: check this
- }
-
- @Override
- public void setRenderingHints(Map, ?> hints) {
- canvasGraphics.setRenderingHints(hints);
- // FIXME: check this
- }
-
- @Override
- public void setStroke(Stroke s) {
- canvasGraphics.setStroke(s);
- }
-
- @Override
- public void setTransform(AffineTransform Tx) {
- canvasGraphics.setTransform(Tx);
- currentTx = Tx;
- }
-
- @Override
- public void shear(double shx, double shy) {
- canvasGraphics.shear(shx, shy);
- currentTx.shear(shx, shy);
- }
-
- @Override
- public void transform(AffineTransform Tx) {
- canvasGraphics.transform(Tx);
- currentTx.concatenate(Tx);
- }
-
- @Override
- public void translate(int x, int y) {
- canvasGraphics.translate(x, y);
- currentTx.translate(x, y);
- }
-
- @Override
- public void translate(double tx, double ty) {
- canvasGraphics.translate(tx, ty);
- currentTx.translate(tx, ty);
- }
-
- @Override
- public void clearRect(int x, int y, int width, int height) {
- canvasGraphics.clearRect(x, y, width, height);
- }
-
- @Override
- public void clipRect(int x, int y, int width, int height) {
- canvasGraphics.clipRect(x, y, width, height);
- }
-
- @Override
- public void copyArea(int x, int y, int width, int height, int dx, int dy) {
- canvasGraphics.copyArea(x, y, width, height, dx, dy);
- }
-
- @Override
- public Graphics create() {
- return canvasGraphics.create();
- }
-
- @Override
- public void dispose() {
- canvasGraphics.dispose();
- }
-
- @Override
- public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- canvasGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
- }
-
- @Override
- public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
- boolean result = canvasGraphics.drawImage(img, x, y, observer);
- appendShape(new Rectangle2D.Double(x, y, img.getWidth(observer), img.getHeight(observer)));
- return result;
- }
-
- @Override
- public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
- // FIXME: map
- return canvasGraphics.drawImage(img, x, y, bgcolor, observer);
- }
-
- @Override
- public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
- // FIXME: map
- return canvasGraphics.drawImage(img, x, y, width, height, observer);
- }
-
- @Override
- public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor,
- ImageObserver observer) {
- // FIXME: map
- return canvasGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
- }
-
- @Override
- public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
- int sx2, int sy2, ImageObserver observer) {
- // FIXME: map
- return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
- }
-
- @Override
- public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
- int sx2, int sy2, Color bgcolor, ImageObserver observer) {
- // FIXME: map
- return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
- }
-
- @Override
- public void drawLine(int x1, int y1, int x2, int y2) {
- canvasGraphics.drawLine(x1, y1, x2, y2);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(new Line2D.Double(x1, y1, x2, y2));
- }
- }
-
- @Override
- public void drawOval(int x, int y, int width, int height) {
- canvasGraphics.drawOval(x, y, width, height);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(new Ellipse2D.Double(x, y, width, height));
- }
- }
-
- @Override
- public void drawPolygon(int[] points, int[] points2, int points3) {
- canvasGraphics.drawPolygon(points, points2, points3);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(new Polygon(points, points2, points3));
- }
- }
-
- @Override
- public void drawPolyline(int[] points, int[] points2, int points3) {
- canvasGraphics.drawPolyline(points, points2, points3);
- }
-
- @Override
- public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
- }
- }
-
- @Override
- public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
- if (drawingComponent && trackingAllowed) {
- appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE));
- }
- }
-
- @Override
- public void fillOval(int x, int y, int width, int height) {
- canvasGraphics.fillOval(x, y, width, height);
- if (drawingComponent && trackingAllowed) {
- appendShape(new Ellipse2D.Double(x, y, width, height));
- }
- }
-
- @Override
- public void fillPolygon(int[] points, int[] points2, int points3) {
- canvasGraphics.fillPolygon(points, points2, points3);
- if (drawingComponent && trackingAllowed) {
- appendShape(new Polygon(points, points2, points3));
- }
- }
-
- @Override
- public void drawRect(int x, int y, int width, int height) {
- canvasGraphics.drawRect(x, y, width, height);
- if (drawingComponent && trackingAllowed) {
- appendShapeOutline(new Rectangle(x, y, width, height));
- }
- }
-
- @Override
- public void fillRect(int x, int y, int width, int height) {
- canvasGraphics.fillRect(x, y, width, height);
- if (drawingComponent && trackingAllowed) {
- appendShape(new Rectangle(x, y, width, height));
- }
- }
-
- @Override
- public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
- if (drawingComponent && trackingAllowed) {
- appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
- }
- }
-
- @Override
- public Shape getClip() {
- return canvasGraphics.getClip();
- }
-
- @Override
- public Rectangle getClipBounds() {
- return canvasGraphics.getClipBounds();
- }
-
- @Override
- public Color getColor() {
- return canvasGraphics.getColor();
- }
-
- @Override
- public Font getFont() {
- return canvasGraphics.getFont();
- }
-
- @Override
- public FontMetrics getFontMetrics(Font f) {
- return canvasGraphics.getFontMetrics(f);
- }
-
- @Override
- public void setClip(Shape clip) {
- canvasGraphics.setClip(clip);
- }
-
- @Override
- public void setClip(int x, int y, int width, int height) {
- canvasGraphics.setClip(x, y, width, height);
- }
-
- @Override
- public void setColor(Color c) {
- canvasGraphics.setColor(c);
- }
-
- @Override
- public void setFont(Font font) {
- canvasGraphics.setFont(font);
- }
-
- @Override
- public void setPaintMode() {
- canvasGraphics.setPaintMode();
- }
-
- @Override
- public void setXORMode(Color c1) {
- canvasGraphics.setXORMode(c1);
- }
-}
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
deleted file mode 100644
index e2176333..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/InstantiationManager.java
+++ /dev/null
@@ -1,219 +0,0 @@
-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;
-import org.diylc.core.measures.Size;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.rits.cloning.Cloner;
-
-/**
- * Manages component instantiation.
- *
- * @author Branislav Stojkovic
- */
-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;
- private IDIYComponent> componentSlot;
- private Point firstControlPoint;
- private Point potentialControlPoint;
-
- public InstantiationManager() {
- cloner = new Cloner();
- }
-
- public ComponentType getComponentTypeSlot() {
- return componentTypeSlot;
- }
-
- public IDIYComponent> getComponentSlot() {
- return componentSlot;
- }
-
- public Point getFirstControlPoint() {
- return firstControlPoint;
- }
-
- public Point getPotentialControlPoint() {
- return potentialControlPoint;
- }
-
- public void setComponentTypeSlot(ComponentType componentTypeSlot, Project currentProject)
- throws Exception {
- this.componentTypeSlot = componentTypeSlot;
- if (componentTypeSlot == null) {
- this.componentSlot = null;
- } else {
- switch (componentTypeSlot.getCreationMethod()) {
- case POINT_BY_POINT:
- this.componentSlot = null;
- break;
- case SINGLE_CLICK:
- this.componentSlot = instantiateComponent(componentTypeSlot, new Point(0, 0),
- currentProject);
- break;
- }
- }
- this.firstControlPoint = null;
- this.potentialControlPoint = null;
- }
-
- public void instatiatePointByPoint(Point scaledPoint, Project currentProject) throws Exception {
- firstControlPoint = scaledPoint;
- componentSlot = instantiateComponent(componentTypeSlot, firstControlPoint, currentProject);
-
- // Set the other control point to the same location, we'll
- // move it later when mouse moves.
- componentSlot.setControlPoint(firstControlPoint, 0);
- componentSlot.setControlPoint(firstControlPoint, 1);
- }
-
- /**
- * Updates component in the slot with the new second control point.
- *
- * @param scaledPoint
- * @return true, if any change is made
- */
- public boolean updatePointByPoint(Point scaledPoint) {
- boolean changeMade = !scaledPoint.equals(potentialControlPoint);
- potentialControlPoint = scaledPoint;
- if (componentSlot != null) {
- componentSlot.setControlPoint(scaledPoint, 1);
- }
- return changeMade;
- }
-
- public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
- if (potentialControlPoint == null) {
- potentialControlPoint = new Point(0, 0);
- }
- int dx = scaledPoint.x - potentialControlPoint.x;
- int dy = scaledPoint.y - potentialControlPoint.y;
- if (snapToGrid) {
- dx = CalcUtils.roundToGrid(dx, gridSpacing);
- dy = CalcUtils.roundToGrid(dy, gridSpacing);
- }
- // Only repaint if there's an actual change.
- if (dx == 0 && dy == 0) {
- return false;
- }
- potentialControlPoint.translate(dx, dy);
- if (componentSlot == null) {
- LOG.error("Component slot should not be null!");
- } else {
- Point p = new Point();
- for (int i = 0; i < componentSlot.getControlPointCount(); i++) {
- p.setLocation(componentSlot.getControlPoint(i));
- p.translate(dx, dy);
- componentSlot.setControlPoint(p, i);
- }
- }
- return true;
- }
-
- @SuppressWarnings("unchecked")
- public IDIYComponent> instantiateComponent(ComponentType componentType, Point point,
- Project currentProject) throws Exception {
- LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
-
- // Instantiate the component.
- IDIYComponent> component = componentType.getInstanceClass().newInstance();
-
- component.setName(createUniqueName(componentType, currentProject));
-
- // Translate them to the desired location.
- if (point != null) {
- for (int j = 0; j < component.getControlPointCount(); j++) {
- Point controlPoint = new Point(component.getControlPoint(j));
- controlPoint.translate(point.x, point.y);
- // snapPointToGrid(controlPoint);
- component.setControlPoint(controlPoint, j);
- }
- }
-
- 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;
- while (exists) {
- i++;
- String name = componentType.getNamePrefix() + i;
- exists = false;
- for (IDIYComponent> c : currentProject.getComponents()) {
- if (c.getName().equals(name)) {
- exists = true;
- break;
- }
- }
- }
- return componentType.getNamePrefix() + i;
- }
-
- /**
- * Finds any properties that have default values and injects default values.
- * Typically it should be used for {@link IDIYComponent} and {@link Project}
- * objects.
- *
- * @param object
- * @throws IllegalArgumentException
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- * @throws NoSuchMethodException
- * @throws SecurityException
- */
- public void fillWithDefaultProperties(Object object) throws IllegalArgumentException,
- IllegalAccessException, InvocationTargetException, SecurityException,
- NoSuchMethodException {
- // Extract properties.
- List properties = ComponentProcessor.getInstance().extractProperties(
- object.getClass());
- // Override with default values if available.
- for (PropertyWrapper property : properties) {
- Object defaultValue = ConfigurationManager.getInstance().readObject(
- Presenter.DEFAULTS_KEY_PREFIX + object.getClass().getName() + ":"
- + property.getName(), null);
- if (defaultValue != null) {
- property.setValue(cloner.deepClone(defaultValue));
- property.writeTo(object);
- }
- }
- }
-
-}
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
deleted file mode 100644
index df3ecbd1..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java
+++ /dev/null
@@ -1,1391 +0,0 @@
-package org.diylc.presenter;
-
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.geom.Area;
-import java.awt.geom.Point2D;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.JOptionPane;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.ComponentType;
-import org.diylc.common.DrawOption;
-import org.diylc.common.EventType;
-import org.diylc.common.IComponentFiler;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.components.connectivity.SolderPad;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.IView;
-import org.diylc.core.Project;
-import org.diylc.core.Theme;
-import org.diylc.core.measures.SizeUnit;
-import org.diylc.swing.plugins.edit.ComponentTransferable;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.diyfever.gui.miscutils.JarScanner;
-import com.diyfever.gui.miscutils.Utils;
-import com.diyfever.gui.simplemq.MessageDispatcher;
-import com.diyfever.gui.update.VersionNumber;
-import com.rits.cloning.Cloner;
-
-/**
- * The main presenter class, contains core app logic and drawing routines.
- *
- * @author Branislav Stojkovic
- */
-public class Presenter implements IPlugInPort {
-
- private static final Logger LOG = Logger.getLogger(Presenter.class);
-
- 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();
-
- public static final int ICON_SIZE = 32;
-
- private Project currentProject;
- private Map> componentTypes;
- // Maps component class names to ComponentType objects.
- private List plugIns;
-
- private List> selectedComponents;
- // Maps components that have at least one dragged point to set of indices
- // that designate which of their control points are being dragged.
- private Map, Set> controlPointMap;
- private Set> lockedComponents;
-
- // Utilities
- private Cloner cloner;
- private DrawingManager drawingManager;
- private ProjectFileManager projectFileManager;
- private InstantiationManager instantiationManager;
-
- private Rectangle selectionRect;
-
- private final IView view;
-
- private MessageDispatcher messageDispatcher;
-
- // Layers
- // private Set lockedLayers;
- // private Set visibleLayers;
-
- // D&D
- private boolean dragInProgress = false;
- // Previous mouse location, not scaled for zoom factor.
- private Point previousDragPoint = null;
- private Project preDragProject = null;
-
- public Presenter(IView view) {
- super();
- this.view = view;
- plugIns = new ArrayList();
- messageDispatcher = new MessageDispatcher(true);
- selectedComponents = new ArrayList>();
- lockedComponents = new HashSet>();
- currentProject = new Project();
- cloner = new Cloner();
- drawingManager = new DrawingManager(messageDispatcher);
- projectFileManager = new ProjectFileManager(messageDispatcher);
- instantiationManager = new InstantiationManager();
-
- // lockedLayers = EnumSet.noneOf(ComponentLayer.class);
- // visibleLayers = EnumSet.allOf(ComponentLayer.class);
- }
-
- public void installPlugin(IPlugIn plugIn) {
- LOG.info(String.format("installPlugin(%s)", plugIn.getClass().getSimpleName()));
- plugIns.add(plugIn);
- plugIn.connect(this);
- messageDispatcher.registerListener(plugIn);
- }
-
- public void dispose() {
- for (IPlugIn plugIn : plugIns) {
- messageDispatcher.unregisterListener(plugIn);
- }
- }
-
- // IPlugInPort
-
- @Override
- public Double[] getAvailableZoomLevels() {
- return new Double[] { 0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d, 1.5d, 2d };
- }
-
- @Override
- public double getZoomLevel() {
- return drawingManager.getZoomLevel();
- }
-
- @Override
- public void setZoomLevel(double zoomLevel) {
- LOG.info(String.format("setZoomLevel(%s)", zoomLevel));
- if (drawingManager.getZoomLevel() == zoomLevel) {
- return;
- }
- drawingManager.setZoomLevel(zoomLevel);
- }
-
- @Override
- public Cursor getCursorAt(Point point) {
- // Only change the cursor if we're not making a new component.
- if (instantiationManager.getComponentTypeSlot() == null) {
- // Scale point to remove zoom factor.
- Point2D scaledPoint = scalePoint(point);
- if (controlPointMap != null && !controlPointMap.isEmpty()) {
- return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
- }
- for (IDIYComponent> component : currentProject.getComponents()) {
- if (!isComponentLocked(component)) {
- Area area = drawingManager.getComponentArea(component);
- if (area != null && area.contains(scaledPoint)) {
- return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
- }
- }
- }
- }
- return Cursor.getDefaultCursor();
- }
-
- @Override
- public Dimension getCanvasDimensions(boolean useZoom) {
- return drawingManager.getCanvasDimensions(currentProject, drawingManager.getZoomLevel(),
- useZoom);
- }
-
- @Override
- public Project getCurrentProject() {
- return currentProject;
- }
-
- @Override
- public void loadProject(Project project, boolean freshStart) {
- LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
- this.currentProject = project;
- drawingManager.clearComponentAreaMap();
- updateSelection(EMPTY_SELECTION);
- messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject
- .getLockedLayers());
- }
-
- @Override
- public void createNewProject() {
- LOG.info("createNewFile()");
- try {
- Project project = new Project();
- instantiationManager.fillWithDefaultProperties(project);
- loadProject(project, true);
- projectFileManager.startNewFile();
- } catch (Exception e) {
- LOG.error("Could not create new file", e);
- view.showMessage("Could not create a new file. Check the log for details.", "Error",
- IView.ERROR_MESSAGE);
- }
- }
-
- @Override
- public void loadProjectFromFile(String fileName) {
- LOG.info(String.format("loadProjectFromFile(%s)", fileName));
- try {
- List warnings = new ArrayList();
- Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName,
- warnings);
- loadProject(project, true);
- projectFileManager.fireFileStatusChanged();
- if (!warnings.isEmpty()) {
- StringBuilder builder = new StringBuilder(
- "File was opened, but there were some issues with it:
");
- for (String warning : warnings) {
- builder.append(warning);
- builder.append("
");
- }
- builder.append("> getComponentTypes() {
- if (componentTypes == null) {
- LOG.info("Loading component types.");
- componentTypes = new HashMap>();
- List> componentTypeClasses = JarScanner.getInstance().scanFolder("library/",
- IDIYComponent.class);
- for (Class> clazz : componentTypeClasses) {
- if (!Modifier.isAbstract(clazz.getModifiers())) {
- ComponentType componentType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom((Class extends IDIYComponent>>) clazz);
- List nestedList;
- if (componentTypes.containsKey(componentType.getCategory())) {
- nestedList = componentTypes.get(componentType.getCategory());
- } else {
- nestedList = new ArrayList();
- componentTypes.put(componentType.getCategory(), nestedList);
- }
- nestedList.add(componentType);
- }
- }
- }
- return componentTypes;
- }
-
- @Override
- public void draw(Graphics2D g2d, Set drawOptions, IComponentFiler filter) {
- if (currentProject == null) {
- return;
- }
- Set> groupedComponents = new HashSet>();
- for (IDIYComponent> component : currentProject.getComponents()) {
- // Only try to draw control points of ungrouped components.
- if (findAllGroupedComponents(component).size() > 1) {
- groupedComponents.add(component);
- }
- }
- // Don't draw the component in the slot if both control points
- // match.
- IDIYComponent> componentSlotToDraw;
- if (instantiationManager.getFirstControlPoint() != null
- && instantiationManager.getPotentialControlPoint() != null
- && instantiationManager.getFirstControlPoint().equals(
- instantiationManager.getPotentialControlPoint())) {
- componentSlotToDraw = null;
- } else {
- componentSlotToDraw = instantiationManager.getComponentSlot();
- }
- List> failedComponents = drawingManager.drawProject(g2d, currentProject,
- drawOptions, filter, selectionRect, selectedComponents, getLockedComponents(),
- groupedComponents, Arrays.asList(instantiationManager.getFirstControlPoint(),
- instantiationManager.getPotentialControlPoint()), componentSlotToDraw,
- dragInProgress);
- List failedComponentNames = new ArrayList();
- for (IDIYComponent> component : failedComponents) {
- failedComponentNames.add(component.getName());
- }
- Collections.sort(failedComponentNames);
- if (!failedComponentNames.isEmpty()) {
- messageDispatcher.dispatchMessage(EventType.STATUS_MESSAGE_CHANGED,
- "Failed to draw components: "
- + Utils.toCommaString(failedComponentNames) + "");
- } else {
- messageDispatcher.dispatchMessage(EventType.STATUS_MESSAGE_CHANGED, "");
- }
- }
-
- /**
- * Finds all components whose areas include the specified {@link Point}.
- * Point is not scaled by the zoom factor. Components that belong to
- * locked layers are ignored.
- *
- * @return
- */
- private List> findComponentsAt(Point point) {
- List> components = drawingManager.findComponentsAt(point, currentProject);
- Iterator> iterator = components.iterator();
- while (iterator.hasNext()) {
- if (isComponentLocked(iterator.next())) {
- iterator.remove();
- }
- }
- return components;
- }
-
- @Override
- public void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown,
- int clickCount) {
- LOG.debug(String
- .format("mouseClicked(%s, %s, %s, %s)", point, ctrlDown, shiftDown, altDown));
- Point scaledPoint = scalePoint(point);
- if (clickCount >= 2) {
- editSelection();
- } else {
- if (instantiationManager.getComponentTypeSlot() != null) {
- // Keep the reference to component type for later.
- ComponentType componentTypeSlot = instantiationManager.getComponentTypeSlot();
- Project oldProject = cloner.deepClone(currentProject);
- switch (componentTypeSlot.getCreationMethod()) {
- case SINGLE_CLICK:
- try {
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.SNAP_TO_GRID_KEY, true)) {
- CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
- }
- IDIYComponent> component = instantiationManager.instantiateComponent(
- componentTypeSlot, scaledPoint, currentProject);
- addComponent(component, componentTypeSlot, true);
- // Select the new component
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- List> newSelection = new ArrayList>();
- newSelection.add(component);
- updateSelection(newSelection);
- } catch (Exception e) {
- LOG.error("Error instatiating component of type: "
- + componentTypeSlot.getInstanceClass().getName(), e);
- }
-
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY,
- false)) {
- editSelection();
- }
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
- setNewComponentTypeSlot(componentTypeSlot);
- } else {
- setNewComponentTypeSlot(null);
- }
- break;
- case POINT_BY_POINT:
- // First click is just to set the controlPointSlot and
- // componentSlot.
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.SNAP_TO_GRID_KEY, true)) {
- CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
- }
- if (instantiationManager.getComponentSlot() == null) {
- try {
- instantiationManager
- .instatiatePointByPoint(scaledPoint, currentProject);
- } catch (Exception e) {
- view.showMessage("Could not create component. Check log for details.",
- "Error", IView.ERROR_MESSAGE);
- LOG.error("Could not create component", e);
- }
- messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED,
- componentTypeSlot, instantiationManager.getFirstControlPoint());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- } else {
- // On the second click, add the component to the
- // project.
- IDIYComponent> componentSlot = instantiationManager.getComponentSlot();
- componentSlot.setControlPoint(scaledPoint, 1);
- addComponent(componentSlot, componentTypeSlot, true);
- // Select the new component if it's not locked.
- List> newSelection = new ArrayList>();
- if (!isComponentLocked(componentSlot)) {
- newSelection.add(componentSlot);
- }
- updateSelection(newSelection);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
-
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.AUTO_EDIT_KEY, false)) {
- editSelection();
- }
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
- setNewComponentTypeSlot(componentTypeSlot);
- } else {
- setNewComponentTypeSlot(null);
- }
- }
- break;
- default:
- LOG.error("Unknown creation method: " + componentTypeSlot.getCreationMethod());
- }
- // Notify the listeners.
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject,
- cloner.deepClone(currentProject), "Add " + componentTypeSlot.getName());
- projectFileManager.notifyFileChange();
- }
- } else {
- List> newSelection = new ArrayList>(
- selectedComponents);
- List> components = findComponentsAt(scaledPoint);
- // If there's nothing under mouse cursor deselect all.
- if (components.isEmpty()) {
- if (!ctrlDown) {
- newSelection.clear();
- }
- } else {
- IDIYComponent> component = components.get(components.size() - 1);
- // If ctrl is pressed just toggle the component under mouse
- // cursor.
- if (ctrlDown) {
- if (newSelection.contains(component)) {
- newSelection.removeAll(findAllGroupedComponents(component));
- } else {
- newSelection.addAll(findAllGroupedComponents(component));
- }
- } else {
- // Otherwise just select that one component.
- newSelection.clear();
- newSelection.addAll(findAllGroupedComponents(component));
- }
- }
- updateSelection(newSelection);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- }
- }
-
- @Override
- public void editSelection() {
- List properties = getMutualSelectionProperties();
- if (properties != null && !properties.isEmpty()) {
- Set defaultedProperties = new HashSet();
- boolean edited = view.editProperties(properties, defaultedProperties);
- if (edited) {
- try {
- applyPropertiesToSelection(properties);
- } catch (Exception e1) {
- view.showMessage(
- "Error occured while editing selection. Check the log for details.",
- "Error", JOptionPane.ERROR_MESSAGE);
- LOG.error("Error applying properties", e1);
- }
- // Save default values.
- for (PropertyWrapper property : defaultedProperties) {
- if (property.getValue() != null) {
- setSelectionDefaultPropertyValue(property.getName(), property.getValue());
- }
- }
- }
- }
- }
-
- @Override
- public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
- Map, Set> components = new HashMap, Set>();
- Point scaledPoint = scalePoint(point);
- if (instantiationManager.getComponentTypeSlot() != null) {
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true)) {
- CalcUtils.snapPointToGrid(scaledPoint, currentProject.getGridSpacing());
- }
- boolean refresh = false;
- switch (instantiationManager.getComponentTypeSlot().getCreationMethod()) {
- case POINT_BY_POINT:
- refresh = instantiationManager.updatePointByPoint(scaledPoint);
- break;
- case SINGLE_CLICK:
- refresh = instantiationManager.updateSingleClick(scaledPoint, ConfigurationManager
- .getInstance().readBoolean(IPlugInPort.SNAP_TO_GRID_KEY, true),
- currentProject.getGridSpacing());
- break;
- }
- if (refresh) {
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- } else {
- // Go backwards so we take the highest z-order components first.
- for (int i = currentProject.getComponents().size() - 1; i >= 0; i--) {
- IDIYComponent> component = currentProject.getComponents().get(i);
- ComponentType componentType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass());
- for (int pointIndex = 0; pointIndex < component.getControlPointCount(); pointIndex++) {
- Point controlPoint = component.getControlPoint(pointIndex);
- // Only consider selected components that are not grouped.
- if (selectedComponents.contains(component) && componentType.isStretchable()
- && findAllGroupedComponents(component).size() == 1) {
- try {
- if (scaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) {
- Set indices = new HashSet();
- if (componentType.isStretchable()) {
- indices.add(pointIndex);
- } else {
- for (int j = 0; j < component.getControlPointCount(); j++) {
- indices.add(j);
- }
- }
- components.put(component, indices);
- break;
- }
- } catch (Exception e) {
- LOG.warn("Error reading control point for component of type: "
- + component.getClass().getName());
- }
- }
- }
- }
- }
-
- messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, scaledPoint);
-
- if (!components.equals(controlPointMap)) {
- controlPointMap = components;
- messageDispatcher.dispatchMessage(EventType.AVAILABLE_CTRL_POINTS_CHANGED,
- new HashMap, Set>(components));
- }
- }
-
- @Override
- public List> getSelectedComponents() {
- return selectedComponents;
- }
-
- @Override
- public void selectAll() {
- LOG.info("selectAll()");
- updateSelection(new ArrayList>(currentProject.getComponents()));
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- @Override
- public VersionNumber getCurrentVersionNumber() {
- return CURRENT_VERSION;
- }
-
- @Override
- public void dragStarted(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
- LOG.debug(String.format("dragStarted(%s)", point));
- if (instantiationManager.getComponentTypeSlot() != null) {
- LOG.debug("Cannot start drag because a new component is being created.");
- mouseClicked(point, ctrlDown, shiftDown, altDown, 1);
- return;
- }
- dragInProgress = true;
- preDragProject = cloner.deepClone(currentProject);
- Point scaledPoint = scalePoint(point);
- previousDragPoint = scaledPoint;
- List> components = findComponentsAt(scaledPoint);
- if (!controlPointMap.isEmpty()) {
- // If we're dragging control points reset selection.
- updateSelection(new ArrayList>(controlPointMap.keySet()));
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- } else if (components.isEmpty()) {
- // If there are no components are under the cursor, reset selection.
- updateSelection(EMPTY_SELECTION);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- } else {
- // Take the last component, i.e. the top order component.
- IDIYComponent> component = components.get(components.size() - 1);
- // If the component under the cursor is not already selected, make
- // it into the only selected component.
- if (!selectedComponents.contains(component)) {
- updateSelection(new ArrayList>(findAllGroupedComponents(component)));
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- // If there aren't any control points, try to add all the selected
- // components with all their control points. That will allow the
- // user to drag the whole components.
- for (IDIYComponent> c : selectedComponents) {
- Set pointIndices = new HashSet();
- if (c.getControlPointCount() > 0) {
- for (int i = 0; i < c.getControlPointCount(); i++) {
- pointIndices.add(i);
- }
- controlPointMap.put(c, pointIndices);
- }
- }
- // Expand control points to include all stuck components.
- boolean sticky = ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.STICKY_POINTS_KEY, true);
- if (ctrlDown) {
- sticky = !sticky;
- }
- if (sticky) {
- includeStuckComponents(controlPointMap);
- }
- }
- }
-
- /**
- * Finds any components that are stuck to one of the components already in
- * the map.
- *
- * @param controlPointMap
- */
- private void includeStuckComponents(Map, Set> controlPointMap) {
- int oldSize = controlPointMap.size();
- LOG.trace("Expanding selected component map");
- for (IDIYComponent> component : currentProject.getComponents()) {
- ComponentType componentType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass());
-
- // Check if there's a control point in the current selection
- // that matches with one of its control points.
- for (int i = 0; i < component.getControlPointCount(); i++) {
- // Do not process a control point if it's already in the map and
- // if it's locked.
- if ((!controlPointMap.containsKey(component) || !controlPointMap.get(component)
- .contains(i))
- && !isComponentLocked(component)) {
- if (component.isControlPointSticky(i)) {
- boolean componentMatches = false;
- for (Map.Entry, Set> entry : controlPointMap
- .entrySet()) {
- if (componentMatches) {
- break;
- }
- for (Integer j : entry.getValue()) {
- Point firstPoint = component.getControlPoint(i);
- if (entry.getKey().isControlPointSticky(j)) {
- Point secondPoint = entry.getKey().getControlPoint(j);
- // If they are close enough we can consider
- // them matched.
- if (firstPoint.distance(secondPoint) < DrawingManager.CONTROL_POINT_SIZE) {
- componentMatches = true;
- break;
- }
- }
- }
- }
- if (componentMatches) {
- LOG.trace("Including component: " + component);
- Set indices = new HashSet();
- // For stretchable components just add the
- // matching component. Otherwise, add all control
- // points.
- if (componentType.isStretchable()) {
- indices.add(i);
- } else {
- for (int k = 0; k < component.getControlPointCount(); k++) {
- indices.add(k);
- }
- }
- if (controlPointMap.containsKey(component)) {
- controlPointMap.get(component).addAll(indices);
- } else {
- controlPointMap.put(component, indices);
- }
- }
- }
- }
- }
- }
- int newSize = controlPointMap.size();
- // As long as we're adding new components, do another iteration.
- if (newSize > oldSize) {
- LOG.trace("Component count changed, trying one more time.");
- includeStuckComponents(controlPointMap);
- } else {
- LOG.trace("Component count didn't change, done with expanding.");
- }
- }
-
- @Override
- public boolean dragOver(Point point) {
- if (point == null) {
- return false;
- }
- Point scaledPoint = scalePoint(point);
- if (!controlPointMap.isEmpty()) {
- // We're dragging control point(s).
- int dx = (scaledPoint.x - previousDragPoint.x);
- int dy = (scaledPoint.y - previousDragPoint.y);
- // After we make the transfer and snap to grid, calculate actual dx
- // and dy. We'll use them to translate the previous drag point.
- int actualDx = 0;
- int actualDy = 0;
-
- // For each component, do a simulation of the move to see if any of
- // them will overlap or go out of bounds.
- int width = (int) currentProject.getWidth().convertToPixels();
- int height = (int) currentProject.getHeight().convertToPixels();
- boolean isFirst = true;
- for (Map.Entry, Set> entry : controlPointMap.entrySet()) {
- IDIYComponent> component = entry.getKey();
- Point[] controlPoints = new Point[component.getControlPointCount()];
- for (int index = 0; index < component.getControlPointCount(); index++) {
- controlPoints[index] = new Point(component.getControlPoint(index));
- // When the first point is moved, calculate how much it
- // actually moved after snapping.
- if (entry.getValue().contains(index)) {
- if (isFirst) {
- isFirst = false;
- Point testPoint = new Point(controlPoints[index]);
- testPoint.translate(dx, dy);
- if (ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.SNAP_TO_GRID_KEY, true)) {
- CalcUtils.snapPointToGrid(testPoint, currentProject
- .getGridSpacing());
- }
- actualDx = testPoint.x - component.getControlPoint(index).x;
- actualDy = testPoint.y - component.getControlPoint(index).y;
- if (actualDx == 0 && actualDy == 0) {
- // Nothing to move.
- return true;
- }
- }
- controlPoints[index].translate(actualDx, actualDy);
- if (controlPoints[index].x < 0 || controlPoints[index].y < 0
- || controlPoints[index].x > width
- || controlPoints[index].y > height) {
- // At least one control point went out of bounds.
- return true;
- }
- }
- // For control points that may overlap, just write null,
- // we'll ignore them later.
- if (component.canControlPointOverlap(index)) {
- controlPoints[index] = null;
- }
- }
-
- for (int i = 0; i < controlPoints.length - 1; i++) {
- for (int j = i + 1; j < controlPoints.length; j++) {
- if (controlPoints[i] != null && controlPoints[j] != null
- && controlPoints[i].equals(controlPoints[j])) {
- // Control points collision detected, cannot make
- // this move.
- return true;
- }
- }
- }
- }
-
- // Update all points.
- for (Map.Entry, Set> entry : controlPointMap.entrySet()) {
- IDIYComponent> c = entry.getKey();
- drawingManager.invalidateComponent(c);
- for (Integer index : entry.getValue()) {
- Point p = new Point(c.getControlPoint(index));
- p.translate(actualDx, actualDy);
- c.setControlPoint(p, index);
- }
- }
- previousDragPoint.translate(actualDx, actualDy);
- } else if (selectedComponents.isEmpty()
- && instantiationManager.getComponentTypeSlot() == null) {
- // If there's no selection, the only thing to do is update the
- // selection rectangle and refresh.
- Rectangle oldSelectionRect = selectionRect == null ? null
- : new Rectangle(selectionRect);
- this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
- if (selectionRect.equals(oldSelectionRect)) {
- return true;
- }
- // messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
- // selectionRect);
- }
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- return true;
- }
-
- @Override
- public void dragEnded(Point point) {
- LOG.debug(String.format("dragEnded(%s)", point));
- if (!dragInProgress) {
- return;
- }
- Point scaledPoint = scalePoint(point);
- if (selectedComponents.isEmpty()) {
- // If there's no selection finalize selectionRect and see which
- // components intersect with it.
- if (scaledPoint != null) {
- this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
- }
- List> newSelection = new ArrayList>();
- for (IDIYComponent> component : currentProject.getComponents()) {
- if (!isComponentLocked(component)) {
- Area area = drawingManager.getComponentArea(component);
- if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) {
- newSelection.addAll(findAllGroupedComponents(component));
- }
- }
- }
- selectionRect = null;
- updateSelection(newSelection);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- } else {
- updateSelection(selectedComponents);
- }
- // There is selection, so we need to finalize the drag&drop
- // operation.
-
- if (!preDragProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, preDragProject, cloner
- .deepClone(currentProject), "Drag");
- projectFileManager.notifyFileChange();
- }
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- dragInProgress = false;
- }
-
- @Override
- public void pasteComponents(List> components) {
- LOG.info(String.format("addComponents(%s)", components));
- Project oldProject = cloner.deepClone(currentProject);
- for (IDIYComponent> component : components) {
- for (int i = 0; i < component.getControlPointCount(); i++) {
- Point point = new Point(component.getControlPoint(i));
- point.translate((int) currentProject.getGridSpacing().convertToPixels(),
- (int) currentProject.getGridSpacing().convertToPixels());
- component.setControlPoint(point, i);
- }
- component.setName(instantiationManager.createUniqueName(ComponentProcessor
- .getInstance().extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass()),
- currentProject));
- addComponent(component, ComponentProcessor.getInstance().extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass()), false);
- }
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Add");
- projectFileManager.notifyFileChange();
- updateSelection(new ArrayList>(components));
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- @Override
- public void deleteSelectedComponents() {
- LOG.info("deleteSelectedComponents()");
- if (selectedComponents.isEmpty()) {
- LOG.debug("Nothing to delete");
- return;
- }
- Project oldProject = cloner.deepClone(currentProject);
- // Remove selected components from any groups.
- ungroupComponents(selectedComponents);
- // Remove from area map.
- for (IDIYComponent> component : selectedComponents) {
- drawingManager.invalidateComponent(component);
- }
- currentProject.getComponents().removeAll(selectedComponents);
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Delete");
- projectFileManager.notifyFileChange();
- updateSelection(EMPTY_SELECTION);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- @Override
- public void setSelectionDefaultPropertyValue(String propertyName, Object value) {
- LOG.info(String.format("setSelectionDefaultPropertyValue(%s, %s)", propertyName, value));
- for (IDIYComponent> component : selectedComponents) {
- String className = component.getClass().getName();
- LOG.debug("Default property value set for " + className + ":" + propertyName);
- ConfigurationManager.getInstance().writeValue(
- DEFAULTS_KEY_PREFIX + className + ":" + propertyName, value);
- }
- }
-
- @Override
- public void setProjectDefaultPropertyValue(String propertyName, Object value) {
- LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s)", propertyName, value));
- LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName);
- ConfigurationManager.getInstance().writeValue(
- DEFAULTS_KEY_PREFIX + Project.class.getName() + ":" + propertyName, value);
- }
-
- @Override
- public void setMetric(boolean isMetric) {
- ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric);
- }
-
- @Override
- public void groupSelectedComponents() {
- LOG.info("groupSelectedComponents()");
- Project oldProject = cloner.deepClone(currentProject);
- // First remove the selected components from other groups.
- ungroupComponents(selectedComponents);
- // Then group them together.
- currentProject.getGroups().add(new HashSet>(selectedComponents));
- // Notify the listeners.
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Group");
- projectFileManager.notifyFileChange();
- }
- }
-
- @Override
- public void ungroupSelectedComponents() {
- LOG.info("ungroupSelectedComponents()");
- Project oldProject = cloner.deepClone(currentProject);
- ungroupComponents(selectedComponents);
- // Notify the listeners.
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Ungroup");
- projectFileManager.notifyFileChange();
- }
- }
-
- @Override
- public void setLayerLocked(int layerZOrder, boolean locked) {
- LOG.info(String.format("setLayerLocked(%s, %s)", layerZOrder, locked));
- if (locked) {
- currentProject.getLockedLayers().add(layerZOrder);
- } else {
- currentProject.getLockedLayers().remove(layerZOrder);
- }
- updateSelection(EMPTY_SELECTION);
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject
- .getLockedLayers());
- }
-
- @Override
- public void sendSelectionToBack() {
- LOG.info("sendSelectionToBack()");
- Project oldProject = cloner.deepClone(currentProject);
- for (IDIYComponent> component : selectedComponents) {
- ComponentType componentType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass());
- int index = currentProject.getComponents().indexOf(component);
- if (index < 0) {
- LOG.warn("Component not found in the project: " + component.getName());
- } else if (index > 0) {
- IDIYComponent> componentBefore = currentProject.getComponents().get(index - 1);
- ComponentType componentBeforeType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) componentBefore.getClass());
- Collections.swap(currentProject.getComponents(), index, index - 1);
- }
- }
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Send to Back");
- projectFileManager.notifyFileChange();
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- }
-
- @Override
- public void bringSelectionToFront() {
- LOG.info("bringSelectionToFront()");
- Project oldProject = cloner.deepClone(currentProject);
- for (IDIYComponent> component : selectedComponents) {
- ComponentType componentType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass());
- int index = currentProject.getComponents().indexOf(component);
- if (index < 0) {
- LOG.warn("Component not found in the project: " + component.getName());
- } else if (index < currentProject.getComponents().size() - 1) {
- IDIYComponent> componentAfter = currentProject.getComponents().get(index + 1);
- ComponentType componentAfterType = ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) componentAfter.getClass());
- Collections.swap(currentProject.getComponents(), index, index + 1);
- }
- }
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Bring to Front");
- projectFileManager.notifyFileChange();
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- }
-
- @Override
- public void refresh() {
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- @Override
- public Theme getSelectedTheme() {
- return drawingManager.getTheme();
- }
-
- @Override
- public void setSelectedTheme(Theme theme) {
- drawingManager.setTheme(theme);
- }
-
- @Override
- public void renumberSelectedComponents(final boolean xAxisFirst) {
- if (getSelectedComponents().isEmpty()) {
- return;
- }
- Project oldProject = cloner.deepClone(currentProject);
- List> components = new ArrayList>(getSelectedComponents());
- // Sort components by their location.
- Collections.sort(components, new Comparator>() {
-
- @Override
- public int compare(IDIYComponent> o1, IDIYComponent> o2) {
- Area area1 = drawingManager.getComponentArea(o1);
- Area area2 = drawingManager.getComponentArea(o2);
- if (area1 != null && area2 != null) {
- Point point1 = area1.getBounds().getLocation();
- Point point2 = area2.getBounds().getLocation();
- if (xAxisFirst) {
- if (point1.y < point2.y) {
- return -1;
- } else if (point1.y > point2.y) {
- return 1;
- } else {
- if (point1.x < point1.x) {
- return -1;
- } else if (point1.x > point1.x) {
- return 1;
- }
- }
- } else {
- if (point1.x < point2.x) {
- return -1;
- } else if (point1.x > point2.x) {
- return 1;
- } else {
- if (point1.y < point1.y) {
- return -1;
- } else if (point1.y > point1.y) {
- return 1;
- }
- }
- }
- }
- return 0;
- }
- });
- // Clear names.
- for (IDIYComponent> component : components) {
- component.setName("");
- }
- // Assign new ones.
- for (IDIYComponent> component : components) {
- component.setName(instantiationManager.createUniqueName(ComponentProcessor
- .getInstance().extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass()),
- currentProject));
- }
-
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Renumber selection");
- projectFileManager.notifyFileChange();
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
-
- public void updateSelection(List> newSelection) {
- this.selectedComponents = newSelection;
- Map, Set> controlPointMap = new HashMap, Set>();
- for (IDIYComponent> component : selectedComponents) {
- Set indices = new HashSet();
- for (int i = 0; i < component.getControlPointCount(); i++) {
- indices.add(i);
- }
- controlPointMap.put(component, indices);
- }
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
- includeStuckComponents(controlPointMap);
- }
- messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents,
- controlPointMap.keySet());
- }
-
- /**
- * Removes all the groups that contain at least one of the specified
- * components.
- *
- * @param components
- */
- private void ungroupComponents(Collection> components) {
- Iterator>> groupIterator = currentProject.getGroups().iterator();
- while (groupIterator.hasNext()) {
- Set> group = groupIterator.next();
- group.removeAll(components);
- if (group.isEmpty()) {
- groupIterator.remove();
- }
- }
- }
-
- /**
- * Finds all components that are grouped with the specified component. This
- * should be called any time components are added or removed from the
- * selection.
- *
- * @param component
- * @return set of all components that belong to the same group with the
- * specified component. At the minimum, set contains that single
- * component.
- */
- private Set> findAllGroupedComponents(IDIYComponent> component) {
- Set> components = new HashSet>();
- components.add(component);
- for (Set> group : currentProject.getGroups()) {
- if (group.contains(component)) {
- components.addAll(group);
- break;
- }
- }
- return components;
- }
-
- @Override
- public Point2D calculateSelectionDimension() {
- if (selectedComponents.isEmpty()) {
- return null;
- }
- boolean metric = ConfigurationManager.getInstance().readBoolean(METRIC_KEY, true);
- Area area = new Area();
- for (IDIYComponent> component : selectedComponents) {
- Area componentArea = drawingManager.getComponentArea(component);
- if (componentArea != null) {
- area.add(componentArea);
- } else {
- LOG.warn("No area found for: " + component.getName());
- }
- }
- double width = area.getBounds2D().getWidth();
- double height = area.getBounds2D().getHeight();
- width /= Constants.PIXELS_PER_INCH;
- height /= Constants.PIXELS_PER_INCH;
- if (metric) {
- width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
- height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
- }
- Point2D dimension = new Point2D.Double(width, height);
- return dimension;
- }
-
- /**
- * Adds a component to the project taking z-order into account.
- *
- * @param component
- * @param componentType
- */
- private void addComponent(IDIYComponent> component, ComponentType componentType,
- boolean canCreatePads) {
- int index = 0;
- while (index < currentProject.getComponents().size()
- && componentType.getZOrder() >= ComponentProcessor.getInstance()
- .extractComponentTypeFrom(
- (Class extends IDIYComponent>>) currentProject.getComponents()
- .get(index).getClass()).getZOrder()) {
- index++;
- }
- if (index < currentProject.getComponents().size()) {
- currentProject.getComponents().add(index, component);
- } else {
- currentProject.getComponents().add(component);
- }
- if (canCreatePads
- && ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)
- && !(component instanceof SolderPad)) {
- ComponentType padType = ComponentProcessor.getInstance().extractComponentTypeFrom(
- SolderPad.class);
- for (int i = 0; i < component.getControlPointCount(); i++) {
- if (component.isControlPointSticky(i)) {
- try {
- IDIYComponent> pad = instantiationManager.instantiateComponent(padType,
- component.getControlPoint(i), currentProject);
- pad.setControlPoint(component.getControlPoint(i), 0);
- addComponent(pad, padType, false);
- } catch (Exception e) {
- LOG.warn("Could not auto-create solder pad", e);
- }
- // SolderPad pad = new SolderPad();
- // pad.setControlPoint(component.getControlPoint(i), 0);
- // addComponent(pad,
- // ComponentProcessor.getInstance().extractComponentTypeFrom(
- // SolderPad.class), false);
- }
- }
- }
- }
-
- @Override
- public List getMutualSelectionProperties() {
- try {
- return ComponentProcessor.getInstance()
- .getMutualSelectionProperties(selectedComponents);
- } catch (Exception e) {
- LOG.error("Could not get mutual selection properties", e);
- return null;
- }
- }
-
- private void applyPropertiesToSelection(List properties) {
- LOG.debug(String.format("applyPropertiesToSelection(%s)", properties));
- Project oldProject = cloner.deepClone(currentProject);
- try {
- for (IDIYComponent> component : selectedComponents) {
- drawingManager.invalidateComponent(component);
- for (PropertyWrapper property : properties) {
- if (property.isChanged()) {
- property.writeTo(component);
- }
- }
- }
- } catch (Exception e) {
- LOG.error("Could not apply selection properties", e);
- view.showMessage(
- "Could not apply changes to the selection. Check the log for details.",
- "Error", IView.ERROR_MESSAGE);
- } finally {
- // Notify the listeners.
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Edit Selection");
- projectFileManager.notifyFileChange();
- }
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- }
- }
-
- @Override
- public List getProjectProperties() {
- List properties = ComponentProcessor.getInstance().extractProperties(
- Project.class);
- try {
- for (PropertyWrapper property : properties) {
- property.readFrom(currentProject);
- }
- } catch (Exception e) {
- LOG.error("Could not get project properties", e);
- return null;
- }
- Collections.sort(properties, ComparatorFactory.getInstance().getPropertyNameComparator());
- return properties;
- }
-
- @Override
- public void applyPropertiesToProject(List properties) {
- LOG.debug(String.format("applyPropertiesToProject(%s)", properties));
- Project oldProject = cloner.deepClone(currentProject);
- try {
- for (PropertyWrapper property : properties) {
- property.writeTo(currentProject);
- }
- } catch (Exception e) {
- LOG.error("Could not apply project properties", e);
- view.showMessage("Could not apply changes to the project. Check the log for details.",
- "Error", IView.ERROR_MESSAGE);
- } finally {
- // Notify the listeners.
- if (!oldProject.equals(currentProject)) {
- messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
- .deepClone(currentProject), "Edit Project");
- projectFileManager.notifyFileChange();
- }
- drawingManager.fireZoomChanged();
- }
- }
-
- @Override
- public void setNewComponentTypeSlot(ComponentType componentType) {
- LOG.info(String.format("setNewComponentSlot(%s)", componentType == null ? null
- : componentType.getName()));
- try {
- instantiationManager.setComponentTypeSlot(componentType, currentProject);
- if (componentType != null) {
- updateSelection(EMPTY_SELECTION);
- }
- messageDispatcher.dispatchMessage(EventType.REPAINT);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
- // selectedComponents);
- // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
- // calculateSelectionDimension());
- messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager
- .getComponentTypeSlot(), instantiationManager.getFirstControlPoint());
- } catch (Exception e) {
- LOG.error("Could not set component type slot", e);
- view.showMessage("Could not set component type slot. Check log for details.", "Error",
- IView.ERROR_MESSAGE);
- }
- }
-
- private Set> getLockedComponents() {
- lockedComponents.clear();
- for (IDIYComponent> component : currentProject.getComponents()) {
- if (isComponentLocked(component)) {
- lockedComponents.add(component);
- }
- }
- return lockedComponents;
- }
-
- private boolean isComponentLocked(IDIYComponent> component) {
- ComponentType componentType = ComponentProcessor.getInstance().extractComponentTypeFrom(
- (Class extends IDIYComponent>>) component.getClass());
- return currentProject.getLockedLayers().contains(
- (int) Math.round(componentType.getZOrder()));
- }
-
- /**
- * Scales point from display base to actual base.
- *
- * @param point
- * @return
- */
- private Point scalePoint(Point point) {
- return point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
- (int) (point.y / drawingManager.getZoomLevel()));
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ProjectFileManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ProjectFileManager.java
deleted file mode 100644
index bf55eb83..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ProjectFileManager.java
+++ /dev/null
@@ -1,456 +0,0 @@
-package org.diylc.presenter;
-
-import java.awt.Color;
-import java.awt.Point;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.EventType;
-import org.diylc.common.Orientation;
-import org.diylc.components.boards.AbstractBoard;
-import org.diylc.components.boards.BlankBoard;
-import org.diylc.components.boards.PerfBoard;
-import org.diylc.components.boards.VeroBoard;
-import org.diylc.components.connectivity.CopperTrace;
-import org.diylc.components.connectivity.HookupWire;
-import org.diylc.components.connectivity.Jumper;
-import org.diylc.components.connectivity.SolderPad;
-import org.diylc.components.misc.Label;
-import org.diylc.components.passive.RadialElectrolytic;
-import org.diylc.components.passive.RadialFilmCapacitor;
-import org.diylc.components.passive.Resistor;
-import org.diylc.components.semiconductors.DIL_IC;
-import org.diylc.components.semiconductors.DiodePlastic;
-import org.diylc.components.semiconductors.LED;
-import org.diylc.components.semiconductors.TransistorTO92;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.Project;
-import org.diylc.core.measures.Capacitance;
-import org.diylc.core.measures.Resistance;
-import org.diylc.core.measures.Size;
-import org.diylc.core.measures.SizeUnit;
-import org.diylc.utils.Constants;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import com.diyfever.gui.simplemq.MessageDispatcher;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
-public class ProjectFileManager {
-
- private static final Logger LOG = Logger.getLogger(ProjectFileManager.class);
-
- // private static final int V1_PIXELS_PER_INCH = 200;
- private static final Size V1_GRID_SPACING = new Size(0.1d, SizeUnit.in);
- private static final Map V1_COLOR_MAP = new HashMap();
- static {
- V1_COLOR_MAP.put("red", Color.red);
- V1_COLOR_MAP.put("blue", Color.blue);
- V1_COLOR_MAP.put("white", Color.white);
- V1_COLOR_MAP.put("green", Color.green.darker());
- V1_COLOR_MAP.put("black", Color.black);
- V1_COLOR_MAP.put("yellow", Color.yellow);
- }
-
- private XStream xStream;
- // Legacy deserializer for 3.0.1 through 3.0.7, loads Points referenced in
- // pixels.
- private XStream xStreamOld;
-
- private String currentFileName = null;
- private boolean modified = false;
-
- private MessageDispatcher messageDispatcher;
-
- public ProjectFileManager(MessageDispatcher messageDispatcher) {
- super();
- this.xStream = new XStream(new DomDriver());
- xStream.autodetectAnnotations(true);
- xStream.registerConverter(new PointConverter());
- this.xStreamOld = new XStream(new DomDriver());
- xStreamOld.autodetectAnnotations(true);
- this.messageDispatcher = messageDispatcher;
- }
-
- public void startNewFile() {
- currentFileName = null;
- modified = false;
- fireFileStatusChanged();
- }
-
- public void serializeProjectToFile(Project project, String fileName, boolean isBackup)
- throws IOException {
- if (!isBackup) {
- LOG.info(String.format("saveProjectToFile(%s)", fileName));
- }
- FileOutputStream fos;
- fos = new FileOutputStream(fileName);
- xStream.toXML(project, fos);
- fos.close();
- if (!isBackup) {
- this.currentFileName = fileName;
- this.modified = false;
- fireFileStatusChanged();
- }
- }
-
- public Project deserializeProjectFromFile(String fileName, List warnings)
- throws SAXException, IOException, ParserConfigurationException {
- LOG.info(String.format("loadProjectFromFile(%s)", fileName));
- Project project;
- File file = new File(fileName);
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(file);
- doc.getDocumentElement().normalize();
- if (doc.getDocumentElement().getNodeName().equalsIgnoreCase(Project.class.getName())) {
- project = parseV3File(fileName);
- } else {
- if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase("layout")) {
- throw new IllegalArgumentException(
- "Could not open DIY file. Root node is not named 'Layout'.");
- }
- String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
- if (formatVersion == null || formatVersion.trim().isEmpty()) {
- LOG.debug("Detected v1 file.");
- project = parseV1File(doc.getDocumentElement(), warnings);
- } else if (formatVersion.equals("2.0")) {
- LOG.debug("Detected v2 file.");
- project = parseV2File(doc.getDocumentElement());
- } else {
- throw new IllegalArgumentException("Unknown file format version: " + formatVersion);
- }
- }
- Collections.sort(warnings);
- this.currentFileName = fileName;
- this.modified = false;
- return project;
- }
-
- public void notifyFileChange() {
- this.modified = true;
- fireFileStatusChanged();
- }
-
- public String getCurrentFileName() {
- return currentFileName;
- }
-
- public boolean isModified() {
- return modified;
- }
-
- public void fireFileStatusChanged() {
- messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(),
- isModified());
- }
-
- private Project parseV1File(Element root, List warnings) {
- Project project = new Project();
- project.setTitle(root.getAttribute("Project"));
- project.setAuthor(root.getAttribute("Credits"));
- project.setGridSpacing(V1_GRID_SPACING);
- String type = root.getAttribute("Type");
-
- // Create the board.
- int width = Integer.parseInt(root.getAttribute("Width")) + 1;
- int height = Integer.parseInt(root.getAttribute("Height")) + 1;
- int boardWidth = (int) (width * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
- int boardHeight = (int) (height * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue());
- int projectWidth = (int) project.getWidth().convertToPixels();
- int projectHeight = (int) project.getHeight().convertToPixels();
- int x = (projectWidth - boardWidth) / 2;
- int y = (projectHeight - boardHeight) / 2;
- AbstractBoard board;
- if (type.equalsIgnoreCase("pcb")) {
- board = new BlankBoard();
- board.setBoardColor(Color.white);
- board.setBorderColor(Color.black);
- } else if (type.equalsIgnoreCase("perfboard")) {
- board = new PerfBoard();
- } else if (type.equalsIgnoreCase("stripboard")) {
- board = new VeroBoard();
- } else {
- throw new IllegalArgumentException("Unrecognized board type: " + type);
- }
- board.setName("Main board");
- Point referencePoint = new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils
- .roundToGrid(y, V1_GRID_SPACING));
- board.setControlPoint(referencePoint, 0);
- board.setControlPoint(new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING),
- CalcUtils.roundToGrid(y + boardHeight, V1_GRID_SPACING)), 1);
- project.getComponents().add(board);
-
- NodeList childNodes = root.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- Node node = childNodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- String nodeName = node.getNodeName();
- String nameAttr = node.getAttributes().getNamedItem("Name").getNodeValue();
- Node valueNode = node.getAttributes().getNamedItem("Value");
- String valueAttr = valueNode == null ? null : valueNode.getNodeValue();
- int x1Attr = Integer.parseInt(node.getAttributes().getNamedItem("X1")
- .getNodeValue());
- int y1Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y1")
- .getNodeValue());
- Point point1 = convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr);
- Point point2 = null;
- Integer x2Attr = null;
- Integer y2Attr = null;
- Color color = null;
- if (node.getAttributes().getNamedItem("Color") != null) {
- String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
- color = V1_COLOR_MAP.get(colorAttr.toLowerCase());
- }
- if (node.getAttributes().getNamedItem("X2") != null
- && node.getAttributes().getNamedItem("Y2") != null) {
- x2Attr = Integer.parseInt(node.getAttributes().getNamedItem("X2")
- .getNodeValue());
- y2Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y2")
- .getNodeValue());
- point2 = convertV1CoordinatesToV3Point(referencePoint, x2Attr, y2Attr);
- }
- IDIYComponent> component = null;
- if (nodeName.equalsIgnoreCase("text")) {
- LOG.debug("Recognized " + nodeName);
- Label label = new Label();
- label.setName(nameAttr);
- if (color != null) {
- label.setColor(color);
- }
- label.setText(valueAttr);
- label.setCenter(false);
- label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
- y1Attr), 0);
- component = label;
- } else if (nodeName.equalsIgnoreCase("pad")) {
- LOG.debug("Recognized " + nodeName);
- SolderPad pad = new SolderPad();
- pad.setName(nameAttr);
- if (color != null) {
- pad.setColor(color);
- }
- pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
- y1Attr), 0);
- component = pad;
- } else if (nodeName.equalsIgnoreCase("trace")) {
- LOG.debug("Recognized " + nodeName);
- CopperTrace trace = new CopperTrace();
- trace.setName(nameAttr);
- if (color != null) {
- trace.setLeadColor(color);
- }
- trace.setControlPoint(point1, 0);
- trace.setControlPoint(point2, 1);
- component = trace;
- } else if (nodeName.equalsIgnoreCase("jumper")) {
- LOG.debug("Recognized " + nodeName);
- Jumper jumper = new Jumper();
- jumper.setName(nameAttr);
- jumper.setControlPoint(point1, 0);
- jumper.setControlPoint(point2, 1);
- component = jumper;
- } else if (nodeName.equalsIgnoreCase("wire")) {
- LOG.debug("Recognized " + nodeName);
- HookupWire wire = new HookupWire();
- Point midPoint = new Point((point1.x + point2.x) / 2, (point1.y + point2.y) / 2);
- wire.setName(nameAttr);
- wire.setControlPoint(point1, 0);
- wire.setControlPoint(midPoint, 1);
- wire.setControlPoint(midPoint, 2);
- wire.setControlPoint(point2, 3);
- component = wire;
- } else if (nodeName.equalsIgnoreCase("resistor")) {
- LOG.debug("Recognized " + nodeName);
- Resistor resistor = new Resistor();
- resistor.setName(nameAttr);
- try {
- resistor.setValue(Resistance.parseResistance(valueAttr));
- } catch (Exception e) {
- LOG.debug("Could not set value of " + nameAttr);
- }
- resistor.setLength(new Size(6d, SizeUnit.mm));
- resistor.setWidth(new Size(2d, SizeUnit.mm));
- resistor.setControlPoint(point1, 0);
- resistor.setControlPoint(point2, 1);
- component = resistor;
- } else if (nodeName.equalsIgnoreCase("capacitor")) {
- LOG.debug("Recognized " + nodeName);
- RadialFilmCapacitor capacitor = new RadialFilmCapacitor();
- capacitor.setName(nameAttr);
- try {
- capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
- } catch (Exception e) {
- LOG.debug("Could not set value of " + nameAttr);
- }
- capacitor.setLength(new Size(6d, SizeUnit.mm));
- capacitor.setWidth(new Size(2d, SizeUnit.mm));
- capacitor.setControlPoint(point1, 0);
- capacitor.setControlPoint(point2, 1);
- component = capacitor;
- } else if (nodeName.equalsIgnoreCase("electrolyte")) {
- LOG.debug("Recognized " + nodeName);
- RadialElectrolytic capacitor = new RadialElectrolytic();
- capacitor.setName(nameAttr);
- try {
- capacitor.setValue(Capacitance.parseCapacitance(valueAttr));
- } catch (Exception e) {
- LOG.debug("Could not set value of " + nameAttr);
- }
- String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
- if (sizeAttr.equalsIgnoreCase("small")) {
- capacitor.setLength(new Size(3.5d, SizeUnit.mm));
- } else if (sizeAttr.equalsIgnoreCase("medium")) {
- capacitor.setLength(new Size(5d, SizeUnit.mm));
- } else if (sizeAttr.equalsIgnoreCase("large")) {
- capacitor.setLength(new Size(7d, SizeUnit.mm));
- } else {
- capacitor.setLength(new Size(4d, SizeUnit.mm));
- }
- capacitor.setControlPoint(point1, 0);
- capacitor.setControlPoint(point2, 1);
- component = capacitor;
- } else if (nodeName.equalsIgnoreCase("diode")) {
- LOG.debug("Recognized " + nodeName);
- DiodePlastic capacitor = new DiodePlastic();
- capacitor.setName(nameAttr);
- try {
- capacitor.setValue(valueAttr);
- } catch (Exception e) {
- LOG.debug("Could not set value of " + nameAttr);
- }
- capacitor.setLength(new Size(6d, SizeUnit.mm));
- capacitor.setWidth(new Size(2d, SizeUnit.mm));
- capacitor.setControlPoint(point1, 0);
- capacitor.setControlPoint(point2, 1);
- component = capacitor;
- } else if (nodeName.equalsIgnoreCase("led")) {
- LOG.debug("Recognized " + nodeName);
- LED led = new LED();
- led.setName(nameAttr);
- led.setValue(valueAttr);
- led.setBodyColor(Color.red);
- led.setBorderColor(Color.red.darker());
- led.setLength(new Size(3d, SizeUnit.mm));
- led.setControlPoint(point1, 0);
- led.setControlPoint(point2, 1);
- component = led;
- } else if (nodeName.equalsIgnoreCase("transistor")) {
- LOG.debug("Recognized " + nodeName);
- TransistorTO92 transistor = new TransistorTO92();
- transistor.setName(nameAttr);
- try {
- transistor.setValue(valueAttr);
- } catch (Exception e) {
- LOG.debug("Could not set value of " + nameAttr);
- }
- transistor.setControlPoint(point1, 0);
- if (point1.y > point2.y) {
- transistor.setOrientation(Orientation._180);
- } else if (point1.y < point2.y) {
- transistor.setOrientation(Orientation.DEFAULT);
- } else if (point1.x < point2.x) {
- transistor.setOrientation(Orientation._270);
- } else if (point1.x > point2.x) {
- transistor.setOrientation(Orientation._90);
- }
- // capacitor.setControlPoint(point2, 1);
- component = transistor;
- } else if (nodeName.equalsIgnoreCase("ic")) {
- LOG.debug("Recognized " + nodeName);
- DIL_IC ic = new DIL_IC();
- if (x1Attr + 3 == x2Attr) {
- if (y1Attr < y2Attr) {
- ic
- .setPinCount(DIL_IC.PinCount.valueOf("_" + 2
- * (y2Attr - y1Attr + 1)));
- } else {
- ic.setOrientation(Orientation._180);
- ic
- .setPinCount(DIL_IC.PinCount.valueOf("_" + 2
- * (y1Attr - y2Attr + 1)));
- }
- }
- ic.setName(nameAttr);
- // Translate control points.
- for (int j = 0; j < ic.getControlPointCount(); j++) {
- Point p = new Point(ic.getControlPoint(j));
- p.translate(point1.x, point1.y);
- ic.setControlPoint(p, j);
- }
- ic.setValue(valueAttr);
- component = ic;
- } else {
- String message = "Could not recognize component type " + nodeName;
- LOG.debug(message);
- if (!warnings.contains(message)) {
- warnings.add(message);
- }
- }
- if (component != null) {
- project.getComponents().add(component);
- }
- }
- }
- Collections.sort(project.getComponents(), ComparatorFactory.getInstance()
- .getComponentZOrderComparator());
- return project;
- }
-
- private Point convertV1CoordinatesToV3Point(Point reference, int x, int y) {
- Point point = new Point(reference);
- point.translate((int) (x * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()),
- (int) (y * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()));
- return point;
- }
-
- private Project parseV2File(Element root) {
- Project project = new Project();
- String projectName = root.getAttribute("projectName");
- String credits = root.getAttribute("credits");
- String width = root.getAttribute("width");
- String height = root.getAttribute("height");
- NodeList childNodes = root.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- Node node = childNodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- if (node.getNodeName().equalsIgnoreCase("component")) {
- LOG.debug(node.getAttributes().getNamedItem("name").getNodeValue());
- } else {
- LOG.debug("Unrecognized node name found: " + node.getNodeName());
- }
- }
- }
- return project;
- }
-
- private Project parseV3File(String fileName) throws IOException {
- Project project;
- FileInputStream fis = new FileInputStream(fileName);
- try {
- project = (Project) xStream.fromXML(fis);
- } catch (Exception e) {
- LOG.warn("Could not open with the new xStream, trying the old one");
- fis.close();
- fis = new FileInputStream(fileName);
- project = (Project) xStreamOld.fromXML(fis);
- }
- fis.close();
- return project;
- }
-}
\ No newline at end of file
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java
deleted file mode 100644
index 4fd80d3a..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ActionFactory.java
+++ /dev/null
@@ -1,870 +0,0 @@
-package org.diylc.swing;
-
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.ClipboardOwner;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.awt.print.PrinterException;
-import java.io.File;
-import java.util.List;
-
-import javax.swing.AbstractAction;
-import javax.swing.KeyStroke;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.ITask;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.IView;
-import org.diylc.core.Theme;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.gui.DialogFactory;
-import org.diylc.swing.gui.editor.PropertyEditorDialog;
-import org.diylc.swing.plugins.edit.ComponentTransferable;
-import org.diylc.swing.plugins.file.BomDialog;
-import org.diylc.swing.plugins.file.BomEntry;
-import org.diylc.swing.plugins.file.BomMaker;
-import org.diylc.swing.plugins.file.FileFilterEnum;
-
-import com.diyfever.gui.ButtonDialog;
-import com.diyfever.gui.IDrawingProvider;
-import com.diyfever.gui.export.DrawingExporter;
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.rits.cloning.Cloner;
-
-public class ActionFactory {
-
- private static final Logger LOG = Logger.getLogger(ActionFactory.class);
-
- private static ActionFactory instance;
- private static Cloner cloner = new Cloner();
-
- public static ActionFactory getInstance() {
- if (instance == null) {
- instance = new ActionFactory();
- }
- return instance;
- }
-
- private ActionFactory() {
- }
-
- // File menu actions.
-
- public NewAction createNewAction(IPlugInPort plugInPort) {
- return new NewAction(plugInPort);
- }
-
- public OpenAction createOpenAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- return new OpenAction(plugInPort, swingUI);
- }
-
- public SaveAction createSaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- return new SaveAction(plugInPort, swingUI);
- }
-
- public SaveAsAction createSaveAsAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- return new SaveAsAction(plugInPort, swingUI);
- }
-
- public CreateBomAction createBomAction(IPlugInPort plugInPort) {
- return new CreateBomAction(plugInPort);
- }
-
- public ExportPDFAction createExportPDFAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
- return new ExportPDFAction(drawingProvider, swingUI);
- }
-
- public ExportPNGAction createExportPNGAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
- return new ExportPNGAction(drawingProvider, swingUI);
- }
-
- public PrintAction createPrintAction(IDrawingProvider drawingProvider) {
- return new PrintAction(drawingProvider);
- }
-
- public ExitAction createExitAction(IPlugInPort plugInPort) {
- return new ExitAction(plugInPort);
- }
-
- // Edit menu actions.
-
- public CutAction createCutAction(IPlugInPort plugInPort, Clipboard clipboard,
- ClipboardOwner clipboardOwner) {
- return new CutAction(plugInPort, clipboard, clipboardOwner);
- }
-
- public CopyAction createCopyAction(IPlugInPort plugInPort, Clipboard clipboard,
- ClipboardOwner clipboardOwner) {
- return new CopyAction(plugInPort, clipboard, clipboardOwner);
- }
-
- public PasteAction createPasteAction(IPlugInPort plugInPort, Clipboard clipboard) {
- return new PasteAction(plugInPort, clipboard);
- }
-
- public SelectAllAction createSelectAllAction(IPlugInPort plugInPort) {
- return new SelectAllAction(plugInPort);
- }
-
- public GroupAction createGroupAction(IPlugInPort plugInPort) {
- return new GroupAction(plugInPort);
- }
-
- public UngroupAction createUngroupAction(IPlugInPort plugInPort) {
- return new UngroupAction(plugInPort);
- }
-
- public EditProjectAction createEditProjectAction(IPlugInPort plugInPort) {
- return new EditProjectAction(plugInPort);
- }
-
- public EditSelectionAction createEditSelectionAction(IPlugInPort plugInPort) {
- return new EditSelectionAction(plugInPort);
- }
-
- public DeleteSelectionAction createDeleteSelectionAction(IPlugInPort plugInPort) {
- return new DeleteSelectionAction(plugInPort);
- }
-
- public SendToBackAction createSendToBackAction(IPlugInPort plugInPort) {
- return new SendToBackAction(plugInPort);
- }
-
- public BringToFrontAction createBringToFrontAction(IPlugInPort plugInPort) {
- return new BringToFrontAction(plugInPort);
- }
-
- // Config actions.
-
- public ConfigAction createConfigAction(IPlugInPort plugInPort, String title, String configKey,
- boolean defaultValue) {
- return new ConfigAction(plugInPort, title, configKey, defaultValue);
- }
-
- public ThemeAction createThemeAction(IPlugInPort plugInPort, Theme theme) {
- return new ThemeAction(plugInPort, theme);
- }
-
- public RenumberAction createRenumberAction(IPlugInPort plugInPort, boolean xAxisFirst) {
- return new RenumberAction(plugInPort, xAxisFirst);
- }
-
- // File menu actions.
-
- public static class NewAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public NewAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "New");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("NewAction triggered");
- if (!plugInPort.allowFileAction()) {
- return;
- }
- plugInPort.createNewProject();
- List properties = plugInPort.getProjectProperties();
- PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
- properties, "Edit Project");
- editor.setVisible(true);
- if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
- plugInPort.applyPropertiesToProject(properties);
- }
- // Save default values.
- for (PropertyWrapper property : editor.getDefaultedProperties()) {
- if (property.getValue() != null) {
- plugInPort.setProjectDefaultPropertyValue(property.getName(), property
- .getValue());
- }
- }
- }
- }
-
- public static class OpenAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private ISwingUI swingUI;
-
- public OpenAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- super();
- this.plugInPort = plugInPort;
- this.swingUI = swingUI;
- putValue(AbstractAction.NAME, "Open");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.FolderOut.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("OpenAction triggered");
- if (!plugInPort.allowFileAction()) {
- return;
- }
- final File file = DialogFactory.getInstance().showOpenDialog(
- FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
- null);
- if (file != null) {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Opening from " + file.getAbsolutePath());
- plugInPort.loadProjectFromFile(file.getAbsolutePath());
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not open file. " + e.getMessage(), "Error",
- ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- }
- }
-
- public static class SaveAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private ISwingUI swingUI;
-
- public SaveAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- super();
- this.plugInPort = plugInPort;
- this.swingUI = swingUI;
- putValue(AbstractAction.NAME, "Save");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("SaveAction triggered");
- if (plugInPort.getCurrentFileName() == null) {
- final File file = DialogFactory.getInstance().showSaveDialog(
- FileFilterEnum.DIY.getFilter(), null,
- FileFilterEnum.DIY.getExtensions()[0], null);
- if (file != null) {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Saving to " + file.getAbsolutePath());
- plugInPort.saveProjectToFile(file.getAbsolutePath(), false);
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not save to file. " + e.getMessage(),
- "Error", ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- } else {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Saving to " + plugInPort.getCurrentFileName());
- plugInPort.saveProjectToFile(plugInPort.getCurrentFileName(), false);
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
- ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- }
- }
-
- public static class SaveAsAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private ISwingUI swingUI;
-
- public SaveAsAction(IPlugInPort plugInPort, ISwingUI swingUI) {
- super();
- this.plugInPort = plugInPort;
- this.swingUI = swingUI;
- putValue(AbstractAction.NAME, "Save As");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
- ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("SaveAsAction triggered");
- final File file = DialogFactory.getInstance().showSaveDialog(
- FileFilterEnum.DIY.getFilter(), null, FileFilterEnum.DIY.getExtensions()[0],
- null);
- if (file != null) {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Saving to " + file.getAbsolutePath());
- plugInPort.saveProjectToFile(file.getAbsolutePath(), false);
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not save to file. " + e.getMessage(), "Error",
- ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- }
- }
-
- public static class CreateBomAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public CreateBomAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Create B.O.M.");
- putValue(AbstractAction.SMALL_ICON, IconLoader.BOM.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("CreateBomAction triggered");
- List bom = BomMaker.getInstance().createBom(
- plugInPort.getCurrentProject().getComponents());
- BomDialog dialog = DialogFactory.getInstance().createBomDialog(bom);
- dialog.setVisible(true);
- }
- }
-
- public static class ExportPDFAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IDrawingProvider drawingProvider;
- private ISwingUI swingUI;
-
- public ExportPDFAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
- super();
- this.drawingProvider = drawingProvider;
- this.swingUI = swingUI;
- putValue(AbstractAction.NAME, "Export to PDF");
- putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("ExportPDFAction triggered");
- final File file = DialogFactory.getInstance().showSaveDialog(
- FileFilterEnum.PDF.getFilter(), null, FileFilterEnum.PDF.getExtensions()[0],
- null);
- if (file != null) {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Exporting to " + file.getAbsolutePath());
- DrawingExporter.getInstance().exportPDF(
- ExportPDFAction.this.drawingProvider, file);
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not export to PDF. " + e.getMessage(), "Error",
- ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- }
- }
-
- public static class ExportPNGAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IDrawingProvider drawingProvider;
- private ISwingUI swingUI;
-
- public ExportPNGAction(IDrawingProvider drawingProvider, ISwingUI swingUI) {
- super();
- this.drawingProvider = drawingProvider;
- this.swingUI = swingUI;
- putValue(AbstractAction.NAME, "Export to PNG");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Image.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("ExportPNGAction triggered");
- final File file = DialogFactory.getInstance().showSaveDialog(
- FileFilterEnum.PNG.getFilter(), null, FileFilterEnum.PNG.getExtensions()[0],
- null);
- if (file != null) {
- swingUI.executeBackgroundTask(new ITask() {
-
- @Override
- public Void doInBackground() throws Exception {
- LOG.debug("Exporting to " + file.getAbsolutePath());
- DrawingExporter.getInstance().exportPNG(
- ExportPNGAction.this.drawingProvider, file);
- return null;
- }
-
- @Override
- public void complete(Void result) {
- }
-
- @Override
- public void failed(Exception e) {
- swingUI.showMessage("Could not export to PNG. " + e.getMessage(), "Error",
- ISwingUI.ERROR_MESSAGE);
- }
- });
- }
- }
- }
-
- public static class PrintAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IDrawingProvider drawingProvider;
-
- public PrintAction(IDrawingProvider drawingProvider) {
- super();
- this.drawingProvider = drawingProvider;
- putValue(AbstractAction.NAME, "Print...");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("ExportPNGAction triggered");
- try {
- DrawingExporter.getInstance().print(this.drawingProvider);
- } catch (PrinterException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
-
- public static class ExitAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public ExitAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Exit");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Exit.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if (plugInPort.allowFileAction()) {
- System.exit(0);
- }
- }
- }
-
- // Edit menu actions.
-
- public static class CutAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private Clipboard clipboard;
- private ClipboardOwner clipboardOwner;
-
- public CutAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
- super();
- this.plugInPort = plugInPort;
- this.clipboard = clipboard;
- this.clipboardOwner = clipboardOwner;
- putValue(AbstractAction.NAME, "Cut");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Cut triggered");
- clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
- .getSelectedComponents())), clipboardOwner);
- plugInPort.deleteSelectedComponents();
- }
- }
-
- public static class CopyAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private Clipboard clipboard;
- private ClipboardOwner clipboardOwner;
-
- public CopyAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
- super();
- this.plugInPort = plugInPort;
- this.clipboard = clipboard;
- this.clipboardOwner = clipboardOwner;
- putValue(AbstractAction.NAME, "Copy");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Copy triggered");
- clipboard.setContents(new ComponentTransferable(cloner.deepClone(plugInPort
- .getSelectedComponents())), clipboardOwner);
- }
- }
-
- public static class PasteAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private Clipboard clipboard;
-
- public PasteAction(IPlugInPort plugInPort, Clipboard clipboard) {
- super();
- this.plugInPort = plugInPort;
- this.clipboard = clipboard;
- putValue(AbstractAction.NAME, "Paste");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon());
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Paste triggered");
- try {
- List> components = (List>) clipboard
- .getData(ComponentTransferable.listFlavor);
- plugInPort.pasteComponents(cloner.deepClone(components));
- } catch (Exception ex) {
- LOG.error("Coule not paste.", ex);
- }
- }
- }
-
- public static class SelectAllAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public SelectAllAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Select All");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Select All triggered");
- plugInPort.selectAll();
- }
- }
-
- public static class GroupAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public GroupAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Group Selection");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Group.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Group Selection triggered");
- plugInPort.groupSelectedComponents();
- }
- }
-
- public static class UngroupAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public UngroupAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Ungroup Selection");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Ungroup.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Ungroup Selection triggered");
- plugInPort.ungroupSelectedComponents();
- }
- }
-
- public static class EditProjectAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public EditProjectAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Edit Project");
- putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentEdit.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Edit Project triggered");
- List properties = plugInPort.getProjectProperties();
- PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
- properties, "Edit Project");
- editor.setVisible(true);
- if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
- plugInPort.applyPropertiesToProject(properties);
- }
- // Save default values.
- for (PropertyWrapper property : editor.getDefaultedProperties()) {
- if (property.getValue() != null) {
- plugInPort.setProjectDefaultPropertyValue(property.getName(), property
- .getValue());
- }
- }
- }
- }
-
- public static class EditSelectionAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public EditSelectionAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Edit Selection");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
- ActionEvent.CTRL_MASK));
- putValue(AbstractAction.SMALL_ICON, IconLoader.EditComponent.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Edit Selection triggered");
- List properties = plugInPort.getMutualSelectionProperties();
- if (properties == null || properties.isEmpty()) {
- LOG.info("Nothing to edit");
- return;
- }
- plugInPort.editSelection();
- }
- }
-
- public static class DeleteSelectionAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public DeleteSelectionAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Delete Selection");
- putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
- putValue(AbstractAction.SMALL_ICON, IconLoader.Delete.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Delete Selection triggered");
- plugInPort.deleteSelectedComponents();
- }
- }
-
- public static class SendToBackAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public SendToBackAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Send Backward");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Back.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Send to Back triggered");
- plugInPort.sendSelectionToBack();
- }
- }
-
- public static class BringToFrontAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- public BringToFrontAction(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- putValue(AbstractAction.NAME, "Bring Forward");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Front.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info("Bring to Front triggered");
- plugInPort.bringSelectionToFront();
- }
- }
-
- public static class ConfigAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private String configKey;
-
- public ConfigAction(IPlugInPort plugInPort, String title, String configKey,
- boolean defaultValue) {
- super();
- this.plugInPort = plugInPort;
- this.configKey = configKey;
- putValue(AbstractAction.NAME, title);
- putValue(IView.CHECK_BOX_MENU_ITEM, true);
- putValue(AbstractAction.SELECTED_KEY, ConfigurationManager.getInstance().readBoolean(
- configKey, defaultValue));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info(getValue(AbstractAction.NAME) + " triggered");
- ConfigurationManager.getInstance().writeValue(configKey,
- getValue(AbstractAction.SELECTED_KEY));
- plugInPort.refresh();
- }
- }
-
- public static class ThemeAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private Theme theme;
-
- public ThemeAction(IPlugInPort plugInPort, Theme theme) {
- super();
- this.plugInPort = plugInPort;
- this.theme = theme;
- putValue(AbstractAction.NAME, theme.getName());
- putValue(IView.RADIO_BUTTON_GROUP_KEY, "theme");
- putValue(AbstractAction.SELECTED_KEY, plugInPort.getSelectedTheme().getName().equals(
- theme.getName()));
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info(getValue(AbstractAction.NAME) + " triggered");
- plugInPort.setSelectedTheme(theme);
- }
- }
-
- public static class RenumberAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
- private boolean xAxisFirst;
-
- public RenumberAction(IPlugInPort plugInPort, boolean xAxisFirst) {
- super();
- this.plugInPort = plugInPort;
- this.xAxisFirst = xAxisFirst;
- putValue(AbstractAction.NAME, xAxisFirst ? "X Axis First" : "Y Axis First");
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.info(getValue(AbstractAction.NAME) + " triggered");
- plugInPort.renumberSelectedComponents(xAxisFirst);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ISwingUI.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ISwingUI.java
deleted file mode 100644
index b316113f..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/ISwingUI.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.diylc.swing;
-
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JComponent;
-import javax.swing.SwingConstants;
-import javax.swing.JPopupMenu.Separator;
-
-import org.diylc.common.BadPositionException;
-import org.diylc.common.ITask;
-import org.diylc.core.IView;
-
-/**
- * Interface for plugin access to the swing front end.
- *
- * @author Branislav Stojkovic
- */
-public interface ISwingUI extends IView {
-
- /**
- * Injects a custom GUI panels provided by the plug-in and desired position
- * in the window. Application will layout plug-in panels accordingly.
- * Valid positions are:
- *
- * - {@link SwingConstants#TOP}
- * - {@link SwingConstants#BOTTOM}
- * - {@link SwingConstants#LEFT}
- * - {@link SwingConstants#RIGHT}
- *
- *
- * Center position is reserved for the main canvas panel and cannot be used.
- *
- * @param component
- * @param position
- * @throws BadPositionException
- * in case invalid position is specified
- */
- void injectGUIComponent(JComponent component, int position) throws BadPositionException;
-
- /**
- * Injects a custom menu action into application's main menu. If
- * action is set to null {@link Separator} will be added. If
- * the specified menu does not exist it will be automatically created.
- *
- * @param action
- * {@link Action} to inser
- * @param menuName
- * name of the menu to insert into
- */
- void injectMenuAction(Action action, String menuName);
-
- /**
- * Injects a custom submenu into application's main menu. If
- * action is set to null {@link Separator} will be added. If
- * the specified menu does not exist it will be automatically created.
- *
- * @param name
- * @param icon
- * @param parentMenuName
- */
- void injectSubmenu(String name, Icon icon, String parentMenuName);
-
- void executeBackgroundTask(ITask task);
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/CustomGlassPane.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/CustomGlassPane.java
deleted file mode 100644
index 9852bdcd..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/CustomGlassPane.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.diylc.swing.gui;
-
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionAdapter;
-
-import javax.swing.Icon;
-import javax.swing.JComponent;
-
-public class CustomGlassPane extends JComponent {
-
- private static final long serialVersionUID = 1L;
- private Icon icon;
-
- public CustomGlassPane() {
- super();
- addMouseMotionListener(new MouseMotionAdapter() {
-
- @Override
- public void mouseMoved(MouseEvent e) {
- if (icon != null) {
- repaint();
- }
- }
- });
- }
-
- public void setCursorIcon(Icon icon) {
- this.icon = icon;
- }
-
- @Override
- public void paint(Graphics g) {
- Point cursor = getMousePosition();
- if ((icon != null) && (cursor != null)) {
- Graphics2D g2d = (Graphics2D) g;
- icon.paintIcon(this, g2d, cursor.x + 10, cursor.y + 10);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/DialogFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/DialogFactory.java
deleted file mode 100644
index d5a3b031..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/DialogFactory.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package org.diylc.swing.gui;
-
-import java.io.File;
-import java.util.List;
-
-import javax.swing.Icon;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.filechooser.FileFilter;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.swing.gui.components.OverwritePromptFileChooser;
-import org.diylc.swing.gui.editor.PropertyEditorDialog;
-import org.diylc.swing.plugins.file.BomDialog;
-import org.diylc.swing.plugins.file.BomEntry;
-import org.diylc.swing.plugins.online.view.LoginDialog;
-import org.diylc.swing.plugins.online.view.NewUserDialog;
-import org.diylc.swing.plugins.online.view.UploadDialog;
-
-import com.diyfever.gui.AboutDialog;
-import com.diyfever.gui.IFileChooserAccessory;
-import com.diyfever.gui.ProgressDialog;
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-public class DialogFactory {
-
- private static DialogFactory instance;
-
- private static final String PATH_KEY = "lastPath";
-
- public static DialogFactory getInstance() {
- if (instance == null) {
- instance = new DialogFactory();
- }
- return instance;
- }
-
- private JFrame mainFrame;
- private File lastDirectory;
-
- private DialogFactory() {
- }
-
- /**
- * Sets the frame to be used as dialog parent. This should be called prior
- * to any other methods in this class.
- *
- * @param mainFrame
- */
- public void initialize(JFrame mainFrame) {
- this.mainFrame = mainFrame;
- String lastDirectoryPath = (String) ConfigurationManager.getInstance()
- .readString(PATH_KEY, null);
- if (lastDirectoryPath != null) {
- lastDirectory = new File(lastDirectoryPath);
- }
- }
-
- public PropertyEditorDialog createPropertyEditorDialog(List properties,
- String title) {
- PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties, title);
- return editor;
- }
-
- public BomDialog createBomDialog(List bom) {
- BomDialog dialog = new BomDialog(mainFrame, bom);
- return dialog;
- }
-
- public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
- IFileChooserAccessory accessory) {
- JFileChooser openFileChooser = new JFileChooser();
- initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
-
- int result = openFileChooser.showOpenDialog(mainFrame);
-
- return processFileChooserResult(result, openFileChooser, defaultExtension);
- }
-
- public File showSaveDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
- IFileChooserAccessory accessory) {
- JFileChooser saveFileChooser = new OverwritePromptFileChooser();
- initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory);
-
- int result = saveFileChooser.showSaveDialog(mainFrame);
-
- return processFileChooserResult(result, saveFileChooser, defaultExtension);
- }
-
- private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter,
- File initialFile, String defaultExtension, IFileChooserAccessory accessory) {
- if (accessory != null) {
- accessory.install(fileChooser);
- }
- for (FileFilter filter : fileChooser.getChoosableFileFilters()) {
- fileChooser.removeChoosableFileFilter(filter);
- }
- if (fileChooser instanceof OverwritePromptFileChooser) {
- ((OverwritePromptFileChooser) fileChooser).setFileFilter(fileFilter, defaultExtension);
- } else {
- fileChooser.setFileFilter(fileFilter);
- }
- if (lastDirectory != null) {
- fileChooser.setCurrentDirectory(lastDirectory);
- }
- fileChooser.setSelectedFile(initialFile);
- }
-
- private File processFileChooserResult(int result, JFileChooser fileChooser,
- String defaultExtension) {
- fileChooser.setAccessory(null);
- if (result == JFileChooser.APPROVE_OPTION) {
- lastDirectory = fileChooser.getCurrentDirectory();
- ConfigurationManager.getInstance().writeValue(PATH_KEY,
- lastDirectory.getAbsolutePath());
- if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
- return fileChooser.getSelectedFile();
- } else {
- return new File(fileChooser.getSelectedFile().getAbsoluteFile() + "."
- + defaultExtension);
- }
- } else {
- return null;
- }
- }
-
- public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author,
- String url, String mail, String htmlContent) {
- AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail,
- htmlContent);
- return dialog;
- }
-
- public NewUserDialog createNewUserDialog() {
- NewUserDialog dialog = new NewUserDialog(mainFrame);
- return dialog;
- }
-
- public LoginDialog createLoginDialog() {
- LoginDialog dialog = new LoginDialog(mainFrame);
- return dialog;
- }
-
- public UploadDialog createUploadDialog() {
- UploadDialog dialog = new UploadDialog(mainFrame);
- return dialog;
- }
-
- public ProgressDialog createProgressDialog(String title, String[] buttonCaptions,
- String description, boolean useProgress) {
- ProgressDialog dialog = new ProgressDialog(mainFrame, title, buttonCaptions, description,
- useProgress);
- return dialog;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/MainFrame.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/MainFrame.java
deleted file mode 100644
index 5bf68978..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/MainFrame.java
+++ /dev/null
@@ -1,370 +0,0 @@
-package org.diylc.swing.gui;
-
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.Cursor;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.Action;
-import javax.swing.BoxLayout;
-import javax.swing.ButtonGroup;
-import javax.swing.Icon;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.SwingConstants;
-import javax.swing.SwingWorker;
-import javax.swing.Timer;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.BadPositionException;
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.ITask;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.IView;
-import org.diylc.images.IconLoader;
-import org.diylc.presenter.Presenter;
-import org.diylc.swing.ISwingUI;
-import org.diylc.swing.gui.editor.PropertyEditorDialog;
-import org.diylc.swing.plugins.autosave.AutoSavePlugin;
-import org.diylc.swing.plugins.canvas.CanvasPlugin;
-import org.diylc.swing.plugins.config.ConfigPlugin;
-import org.diylc.swing.plugins.edit.EditMenuPlugin;
-import org.diylc.swing.plugins.file.FileMenuPlugin;
-import org.diylc.swing.plugins.help.HelpMenuPlugin;
-import org.diylc.swing.plugins.layers.LayersMenuPlugin;
-import org.diylc.swing.plugins.statusbar.StatusBar;
-import org.diylc.swing.plugins.toolbox.ToolBox;
-
-import com.diyfever.gui.ButtonDialog;
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-public class MainFrame extends JFrame implements ISwingUI {
-
- private static final Logger LOG = Logger.getLogger(MainFrame.class);
-
- private static final long serialVersionUID = 1L;
-
- private JPanel centerPanel;
- private JPanel leftPanel;
- private JPanel rightPanel;
- private JPanel topPanel;
- private JPanel bottomPanel;
-
- private Presenter presenter;
-
- private JMenuBar mainMenuBar;
- private Map menuMap;
- private Map buttonGroupMap;
-
- private CanvasPlugin canvasPlugin;
-
- public MainFrame() {
- super("DIYLC 3");
- setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- setPreferredSize(new Dimension(800, 600));
- createBasePanels();
- menuMap = new HashMap();
- buttonGroupMap = new HashMap();
- setIconImages(Arrays.asList(IconLoader.IconSmall.getImage(), IconLoader.IconMedium
- .getImage(), IconLoader.IconLarge.getImage()));
- DialogFactory.getInstance().initialize(this);
-
- this.presenter = new Presenter(this);
-
- presenter.installPlugin(new ToolBox(this));
- presenter.installPlugin(new FileMenuPlugin(this));
- presenter.installPlugin(new EditMenuPlugin(this));
- presenter.installPlugin(new ConfigPlugin(this));
- presenter.installPlugin(new LayersMenuPlugin(this));
- // presenter.installPlugin(new OnlineManager());
- presenter.installPlugin(new HelpMenuPlugin(this));
-
- presenter.installPlugin(new StatusBar(this));
- canvasPlugin = new CanvasPlugin(this);
- presenter.installPlugin(canvasPlugin);
- presenter.installPlugin(new FramePlugin());
-
- try {
- File testFile = new File("test.tmp");
- Writer out = new OutputStreamWriter(new FileOutputStream(testFile));
- out.write("This is a test");
- out.close();
- testFile.delete();
- presenter.installPlugin(new AutoSavePlugin(this));
- } catch (Exception e) {
- showMessage(
- "The current user does not have permissions to access folder "
- + new File(".").getAbsolutePath()
- + ".\nAuto-save feature will not be available, contact your system administrator.",
- "Warning", IView.WARNING_MESSAGE);
- }
-
- presenter.createNewProject();
-
- addWindowListener(new WindowAdapter() {
-
- @Override
- public void windowClosed(WindowEvent e) {
- if (presenter.allowFileAction()) {
- ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY,
- false);
- dispose();
- presenter.dispose();
- System.exit(0);
- }
- }
-
- @Override
- public void windowClosing(WindowEvent e) {
- if (presenter.allowFileAction()) {
- ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY,
- false);
- dispose();
- presenter.dispose();
- System.exit(0);
- }
- }
- });
-
- // setGlassPane(new CustomGlassPane());
- // getGlassPane().setVisible(true);
- }
-
- public Presenter getPresenter() {
- return presenter;
- }
-
- @Override
- public void setVisible(boolean b) {
- super.setVisible(b);
- // TODO: hack to prevent painting issues in the scroll bar rulers. Find
- // a better fix if possible.
- Timer timer = new Timer(500, new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- canvasPlugin.refresh();
- }
-
- });
- timer.setRepeats(false);
- timer.start();
- // if (b) {
- // SwingUtilities.invokeLater(new Runnable() {
- // @Override
- // public void run() {
- //
- // }
- // });
- // }
- }
-
- private void createBasePanels() {
- Container c = new Container();
- c.setLayout(new BorderLayout());
-
- centerPanel = new JPanel(new BorderLayout());
- c.add(centerPanel, BorderLayout.CENTER);
-
- topPanel = new JPanel();
- topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
- c.add(topPanel, BorderLayout.NORTH);
-
- leftPanel = new JPanel();
- leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.X_AXIS));
- c.add(leftPanel, BorderLayout.WEST);
-
- bottomPanel = new JPanel();
- bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
- c.add(bottomPanel, BorderLayout.SOUTH);
-
- rightPanel = new JPanel();
- rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.X_AXIS));
- c.add(rightPanel, BorderLayout.EAST);
-
- setContentPane(c);
- }
-
- private JMenuBar getMainMenuBar() {
- if (mainMenuBar == null) {
- mainMenuBar = new JMenuBar();
- setJMenuBar(mainMenuBar);
- }
- return mainMenuBar;
- }
-
- // IView
-
- @Override
- public void showMessage(String message, String title, int messageType) {
- JOptionPane.showMessageDialog(this, message, title, messageType);
- }
-
- @Override
- public int showConfirmDialog(String message, String title, int optionType, int messageType) {
- return JOptionPane.showConfirmDialog(this, message, title, optionType, messageType);
- }
-
- @Override
- public boolean editProperties(List properties,
- Set defaultedProperties) {
- PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
- properties, "Edit Selection");
- editor.setVisible(true);
- defaultedProperties.addAll(editor.getDefaultedProperties());
- return ButtonDialog.OK.equals(editor.getSelectedButtonCaption());
- }
-
- private JMenu findOrCreateMenu(String menuName) {
- JMenu menu;
- if (menuMap.containsKey(menuName)) {
- menu = menuMap.get(menuName);
- } else {
- menu = new JMenu(menuName);
- menuMap.put(menuName, menu);
- getMainMenuBar().add(menu);
- }
- return menu;
- }
-
- @Override
- public void injectGUIComponent(JComponent component, int position) throws BadPositionException {
- LOG.info(String.format("injectGUIComponent(%s, %s)", component.getClass().getName(),
- position));
- switch (position) {
- case SwingConstants.TOP:
- topPanel.add(component);
- break;
- case SwingConstants.LEFT:
- leftPanel.add(component);
- break;
- case SwingConstants.BOTTOM:
- bottomPanel.add(component);
- break;
- case SwingConstants.RIGHT:
- rightPanel.add(component);
- break;
- case SwingConstants.CENTER:
- centerPanel.add(component, BorderLayout.CENTER);
- break;
- default:
- throw new BadPositionException();
- }
- pack();
- }
-
- @Override
- public void injectMenuAction(Action action, String menuName) {
- LOG.info(String.format("injectMenuAction(%s, %s)", action == null ? "Separator" : action
- .getValue(Action.NAME), menuName));
- JMenu menu = findOrCreateMenu(menuName);
- if (action == null) {
- menu.addSeparator();
- } else {
- Boolean isCheckBox = (Boolean) action.getValue(IView.CHECK_BOX_MENU_ITEM);
- String groupName = (String) action.getValue(IView.RADIO_BUTTON_GROUP_KEY);
- if (isCheckBox != null && isCheckBox) {
- menu.add(new JCheckBoxMenuItem(action));
- } else if (groupName != null) {
- ButtonGroup group;
- if (buttonGroupMap.containsKey(groupName)) {
- group = buttonGroupMap.get(groupName);
- } else {
- group = new ButtonGroup();
- buttonGroupMap.put(groupName, group);
- }
- JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
- group.add(item);
- menu.add(item);
- } else {
- menu.add(action);
- }
- }
- }
-
- @Override
- public void injectSubmenu(String name, Icon icon, String parentMenuName) {
- LOG.info(String.format("injectSubmenu(%s, icon, %s)", name, parentMenuName));
- JMenu menu = findOrCreateMenu(parentMenuName);
- JMenu submenu = new JMenu(name);
- submenu.setIcon(icon);
- menu.add(submenu);
- menuMap.put(name, submenu);
- }
-
- @Override
- public void executeBackgroundTask(final ITask task) {
- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- SwingWorker worker = new SwingWorker() {
-
- @Override
- protected T doInBackground() throws Exception {
- return task.doInBackground();
- }
-
- @Override
- protected void done() {
- try {
- T result = get();
- task.complete(result);
- } catch (Exception e) {
- LOG.error("Task failed", e);
- task.failed(e);
- }
- setCursor(Cursor.getDefaultCursor());
- }
- };
- worker.execute();
- }
-
- class FramePlugin implements IPlugIn {
-
- private IPlugInPort plugInPort;
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.of(EventType.FILE_STATUS_CHANGED);
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- if (eventType == EventType.FILE_STATUS_CHANGED) {
- String fileName = (String) params[0];
- if (fileName == null) {
- fileName = "Untitled";
- }
- String modified = (Boolean) params[1] ? " (modified)" : "";
- setTitle(String.format("DIYLC %s beta - %s %s", plugInPort
- .getCurrentVersionNumber(), fileName, modified));
- }
- }
- }
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/TemplateDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/TemplateDialog.java
deleted file mode 100644
index 385a4184..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/TemplateDialog.java
+++ /dev/null
@@ -1,285 +0,0 @@
-package org.diylc.swing.gui;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.BorderFactory;
-import javax.swing.DefaultListCellRenderer;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.DrawOption;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.IView;
-import org.diylc.presenter.Presenter;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-public class TemplateDialog extends JDialog {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = Logger.getLogger(TemplateDialog.class);
-
- private static final Dimension panelSize = new Dimension(400, 300);
- public static final String SHOW_TEMPLATES_KEY = "showTemplatesAtStartup";
-
- private IPlugInPort plugInPort;
-
- private JList fileList;
- private JPanel canvasPanel;
- private Presenter presenter;
- private List files;
- private JCheckBox showTemplatesBox;
- private JPanel mainPanel;
- private JButton loadButton;
- private JPanel infoPanel;
-
- public TemplateDialog(JFrame owner, IPlugInPort plugInPort) {
- super(owner, "Templates");
- setModal(true);
- setResizable(false);
- this.plugInPort = plugInPort;
- this.presenter = new Presenter(new IView() {
-
- @Override
- public int showConfirmDialog(String message, String title, int optionType,
- int messageType) {
- return JOptionPane.showConfirmDialog(TemplateDialog.this, message, title,
- optionType, messageType);
- }
-
- @Override
- public void showMessage(String message, String title, int messageType) {
- JOptionPane.showMessageDialog(TemplateDialog.this, message, title, messageType);
- }
-
- @Override
- public boolean editProperties(List properties, Set defaultedProperties) {
- return false;
- }
- });
- // this.presenter.installPlugin(new IPlugIn() {
- //
- // @Override
- // public void connect(IPlugInPort plugInPort) {
- // }
- //
- // @Override
- // public EnumSet getSubscribedEventTypes() {
- // return EnumSet.of(EventType.REPAINT);
- // }
- //
- // @Override
- // public void processMessage(EventType eventType, Object... params) {
- // if (eventType == EventType.REPAINT) {
- // getCanvasPanel().repaint();
- // }
- // }
- // });
- setContentPane(getMainPanel());
- pack();
- setLocationRelativeTo(owner);
- }
-
- public JPanel getMainPanel() {
- if (mainPanel == null) {
- mainPanel = new JPanel(new GridBagLayout());
- mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
-
- GridBagConstraints c = new GridBagConstraints();
- c.gridx = 0;
- c.gridy = 0;
- c.weightx = 0;
- c.weighty = 1;
- c.weightx = 1;
- c.gridwidth = 2;
- c.fill = GridBagConstraints.BOTH;
- c.insets = new Insets(0, 0, 4, 0);
- mainPanel.add(getInfoPanel(), c);
-
- c.gridy = 1;
- c.weightx = 0;
- c.gridwidth = 1;
- c.insets = new Insets(0, 0, 0, 0);
- JScrollPane scrollPane = new JScrollPane(getFileList());
- mainPanel.add(scrollPane, c);
-
- c.gridx = 1;
- c.weightx = 1;
-
- JPanel panel = new JPanel(new BorderLayout());
- panel.setBorder(scrollPane.getBorder());
- panel.add(getCanvasPanel(), BorderLayout.CENTER);
- mainPanel.add(panel, c);
-
- c.gridx = 0;
- c.gridy = 2;
- c.weightx = 0;
- c.weighty = 0;
- c.anchor = GridBagConstraints.LAST_LINE_START;
- c.fill = GridBagConstraints.NONE;
- mainPanel.add(getShowTemplatesBox(), c);
-
- c.gridx = 1;
- c.anchor = GridBagConstraints.LAST_LINE_END;
- c.insets = new Insets(4, 0, 0, 0);
- mainPanel.add(getLoadButton(), c);
- }
- return mainPanel;
- }
-
- public JButton getLoadButton() {
- if (loadButton == null) {
- loadButton = new JButton("Load Template");
- loadButton.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- plugInPort.loadProject(presenter.getCurrentProject(), true);
- dispose();
- }
- });
- }
- return loadButton;
- }
-
- public JPanel getInfoPanel() {
- if (infoPanel == null) {
- infoPanel = new JPanel();
- infoPanel.setBackground(Color.decode("#FFFFCC"));
- infoPanel.setBorder(new JTextField().getBorder());
- JLabel infoLabel = new JLabel(
- "Templates are semi-product layouts that are used as a starting point for your projects.
"
- + "Pick a templete in the left list and click \"Load Template\" to load it or close this dialog to continue.
"
- + "You can create your own templates by placing a DIY file into diylc/templates directory.");
- infoLabel.setOpaque(false);
- infoPanel.add(infoLabel);
- }
- return infoPanel;
- }
-
- public JList getFileList() {
- if (fileList == null) {
- fileList = new JList(getFiles().toArray());
- fileList.setPreferredSize(new Dimension(128, -1));
- fileList.setCellRenderer(new DefaultListCellRenderer() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Component getListCellRendererComponent(JList list, Object value, int index,
- boolean isSelected, boolean cellHasFocus) {
- JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index,
- isSelected, cellHasFocus);
- if (value instanceof File) {
- label.setText(((File) value).getName());
- }
- return label;
- }
-
- });
- fileList.addListSelectionListener(new ListSelectionListener() {
-
- @Override
- public void valueChanged(ListSelectionEvent e) {
- File file = (File) fileList.getSelectedValue();
- if (file != null) {
- presenter.loadProjectFromFile(file.getAbsolutePath());
- Dimension dim = presenter.getCanvasDimensions(true);
- double xFactor = panelSize.getWidth() / dim.getWidth();
- double yFactor = panelSize.getHeight() / dim.getHeight();
- presenter.setZoomLevel(Math.min(xFactor, yFactor));
- getCanvasPanel().repaint();
- }
- }
- });
- fileList.setSelectedIndex(0);
- }
- return fileList;
- }
-
- public JCheckBox getShowTemplatesBox() {
- if (showTemplatesBox == null) {
- showTemplatesBox = new JCheckBox("Show this dialog at startup");
- showTemplatesBox.setSelected(true);
- showTemplatesBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- ConfigurationManager.getInstance().writeValue(SHOW_TEMPLATES_KEY,
- showTemplatesBox.isSelected());
- }
- });
- }
- return showTemplatesBox;
- }
-
- public List getFiles() {
- if (files == null) {
- files = new ArrayList();
- File dir = new File("templates");
- if (dir.exists()) {
- for (File f : dir.listFiles()) {
- if (f.isFile() && f.getName().toLowerCase().endsWith(".diy")) {
- files.add(f);
- }
- }
- }
- LOG.debug("Found " + files.size() + " templates");
- }
- return files;
- }
-
- public JPanel getCanvasPanel() {
- if (canvasPanel == null) {
- canvasPanel = new JPanel() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- // Graphics2D g2d = (Graphics2D) g;
- // AffineTransform transform = g2d.getTransform();
- presenter.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM,
- DrawOption.ANTIALIASING), null);
- // g2d.setTransform(transform);
- // Rectangle rect = canvasPanel.getBounds();
- // BorderFactory.createEtchedBorder().paintBorder(canvasPanel,
- // g, 0, 0,
- // (int) rect.getWidth(), (int) rect.getHeight());
- }
- };
- canvasPanel.setBackground(Color.white);
- canvasPanel.setPreferredSize(panelSize);
- }
- return canvasPanel;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/components/OverwritePromptFileChooser.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/components/OverwritePromptFileChooser.java
deleted file mode 100644
index 514d47eb..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/components/OverwritePromptFileChooser.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.diylc.swing.gui.components;
-
-import java.io.File;
-
-import javax.swing.JFileChooser;
-import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
-
-public class OverwritePromptFileChooser extends JFileChooser {
-
- private static final long serialVersionUID = 1L;
- private String defaultExtension;
-
- public void approveSelection() {
- File lSelectedFile;
- if (getSelectedFile().getAbsolutePath().contains(".")) {
- lSelectedFile = getSelectedFile();
- } else {
- lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "." + defaultExtension);
- }
-
- if (lSelectedFile != null && lSelectedFile.exists()) {
- int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile.getAbsolutePath()
- + " already exists.\nDo you " + "want to replace it?", "Warning",
- JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
-
- if (lResponse != JOptionPane.YES_OPTION) {
- return;
- }
- }
- super.approveSelection();
- }
-
- public void setFileFilter(FileFilter filter, String defaultExtension) {
- this.defaultExtension = defaultExtension;
- super.setFileFilter(filter);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/BooleanEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/BooleanEditor.java
deleted file mode 100644
index c8842b26..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/BooleanEditor.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JCheckBox;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-public class BooleanEditor extends JCheckBox {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- public BooleanEditor(final PropertyWrapper property) {
- super();
- setSelected((Boolean) property.getValue());
- addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- property.setChanged(true);
- setBackground(oldBg);
- property.setValue(isSelected());
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ByteEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ByteEditor.java
deleted file mode 100644
index 05d72207..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ByteEditor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-
-import javax.swing.JSlider;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-public class ByteEditor extends JSlider {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- public ByteEditor(final PropertyWrapper property) {
- super();
- setMinimum(0);
- setMaximum(127);
- setValue((Byte) property.getValue());
- addChangeListener(new ChangeListener() {
-
- @Override
- public void stateChanged(ChangeEvent e) {
- property.setChanged(true);
- setBackground(oldBg);
- property.setValue(new Integer(getValue()).byteValue());
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ColorEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ColorEditor.java
deleted file mode 100644
index 24e16ef2..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ColorEditor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-import java.awt.Cursor;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-
-import javax.swing.BorderFactory;
-import javax.swing.JColorChooser;
-import javax.swing.JLabel;
-import javax.swing.SwingConstants;
-
-import org.diylc.common.PropertyWrapper;
-
-public class ColorEditor extends JLabel {
-
- private static final long serialVersionUID = 1L;
-
- private static final String title = "Click to edit";
-
- public ColorEditor(final PropertyWrapper property) {
- super(property.isUnique() ? title : ("(multi value) " + title));
- setOpaque(true);
- setHorizontalAlignment(SwingConstants.CENTER);
- setBorder(BorderFactory.createEtchedBorder());
- setBackground((Color) property.getValue());
- setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
- addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseClicked(MouseEvent e) {
- Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color",
- getBackground());
- if (newColor != null) {
- property.setChanged(true);
- property.setValue(newColor);
- setBackground(newColor);
- }
- }
- });
- }
-
- @Override
- public void setBackground(Color bg) {
- if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
- setForeground(Color.white);
- } else {
- setForeground(Color.black);
- }
- super.setBackground(bg);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/EnumEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/EnumEditor.java
deleted file mode 100644
index d53bf2c6..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/EnumEditor.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JComboBox;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-public class EnumEditor extends JComboBox {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- private final PropertyWrapper property;
-
- public EnumEditor(final PropertyWrapper property) {
- this.property = property;
- Object[] values = property.getType().getEnumConstants();
- setModel(new DefaultComboBoxModel(values));
- setSelectedItem(property.getValue());
- addItemListener(new ItemListener() {
-
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- property.setChanged(true);
- setBackground(oldBg);
- EnumEditor.this.property.setValue(e.getItem());
- }
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FieldEditorFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FieldEditorFactory.java
deleted file mode 100644
index 1eca8238..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FieldEditorFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Font;
-
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.measures.AbstractMeasure;
-
-public class FieldEditorFactory {
-
- private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class);
-
- public static Component createFieldEditor(PropertyWrapper property) {
- if (property.getType().equals(String.class)) {
- StringEditor editor = new StringEditor(property);
- return editor;
- }
- if (property.getType().equals(Color.class)) {
- ColorEditor editor = new ColorEditor(property);
- return editor;
- }
- if (AbstractMeasure.class.isAssignableFrom(property.getType())) {
- MeasureEditor editor = new MeasureEditor(property);
- return editor;
- }
- if (ImageIcon.class.isAssignableFrom(property.getType())) {
- ImageEditor editor = new ImageEditor(property);
- return editor;
- }
- if (property.getType().isEnum()) {
- EnumEditor editor = new EnumEditor(property);
- return editor;
- }
- if (Byte.class.isAssignableFrom(property.getType())
- || byte.class.isAssignableFrom(property.getType())) {
- ByteEditor editor = new ByteEditor(property);
- return editor;
- }
- if (Boolean.class.isAssignableFrom(property.getType())
- || boolean.class.isAssignableFrom(property.getType())) {
- BooleanEditor editor = new BooleanEditor(property);
- return editor;
- }
- if (Font.class.isAssignableFrom(property.getType())) {
- FontEditor editor = new FontEditor(property);
- return editor;
- }
- if (Integer.class.isAssignableFrom(property.getType())
- || int.class.isAssignableFrom(property.getType())) {
- IntEditor editor = new IntEditor(property);
- return editor;
- }
- LOG.error("Unrecognized parameter type: " + property.getType().getName());
- return new JLabel("Unrecognized");
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FontEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FontEditor.java
deleted file mode 100644
index 64471349..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/FontEditor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.FontChooserComboBox;
-
-public class FontEditor extends FontChooserComboBox {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- private final PropertyWrapper property;
-
- public FontEditor(final PropertyWrapper property) {
- this.property = property;
- setSelectedItem(((Font) property.getValue()).getName());
- addItemListener(new ItemListener() {
-
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- property.setChanged(true);
- setBackground(oldBg);
- Font oldFont = (Font) FontEditor.this.property.getValue();
- Font newFont = new Font(getSelectedItem().toString(), oldFont.getStyle(),
- oldFont.getSize());
- FontEditor.this.property.setValue(newFont);
- }
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ImageEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ImageEditor.java
deleted file mode 100644
index 11bdb574..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/ImageEditor.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.event.ActionListener;
-import java.io.File;
-
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.swing.gui.DialogFactory;
-import org.diylc.swing.plugins.file.FileFilterEnum;
-
-public class ImageEditor extends JButton {
-
- private static final long serialVersionUID = 1L;
-
- private static final String title = "Click to load image file";
-
- public ImageEditor(final PropertyWrapper property) {
- super(property.isUnique() ? title : ("(multi value) " + title));
- addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(java.awt.event.ActionEvent e) {
- File file = DialogFactory.getInstance().showOpenDialog(
- FileFilterEnum.IMAGES.getFilter(), null,
- FileFilterEnum.IMAGES.getExtensions()[0], null);
- if (file != null) {
- property.setChanged(true);
- ImageIcon image = new ImageIcon(file.getAbsolutePath());
- property.setValue(image);
- }
- }
- });
- }
-
- // @Override
- // public void setBackground(Color bg) {
- // if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
- // setForeground(Color.white);
- // } else {
- // setForeground(Color.black);
- // }
- // super.setBackground(bg);
- // }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/IntEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/IntEditor.java
deleted file mode 100644
index 919c7949..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/IntEditor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.DoubleTextField;
-
-public class IntEditor extends DoubleTextField {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- public IntEditor(final PropertyWrapper property) {
- setLayout(new BorderLayout());
- setValue((double) (Integer) property.getValue());
- addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY, new PropertyChangeListener() {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- property.setChanged(true);
- setBackground(oldBg);
- property.setValue(((Double) evt.getNewValue()).intValue());
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/MeasureEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/MeasureEditor.java
deleted file mode 100644
index c16d6bc2..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/MeasureEditor.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import javax.swing.JComboBox;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.measures.AbstractMeasure;
-import org.diylc.core.measures.Unit;
-import org.diylc.utils.Constants;
-
-import com.diyfever.gui.DoubleTextField;
-
-public class MeasureEditor extends Container {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg;
- private DoubleTextField valueField;
- private JComboBox unitBox;
-
- @SuppressWarnings("unchecked")
- public MeasureEditor(final PropertyWrapper property) {
- setLayout(new BorderLayout());
- AbstractMeasure measure = ((AbstractMeasure) property.getValue());
- valueField = new DoubleTextField(measure.getValue());
- oldBg = valueField.getBackground();
- valueField.addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY,
- new PropertyChangeListener() {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- try {
- AbstractMeasure> newMeasure = (AbstractMeasure>) ((AbstractMeasure) property
- .getValue()).clone();
- newMeasure.setValue((Double) evt.getNewValue());
- property.setValue(newMeasure);
- property.setChanged(true);
- valueField.setBackground(oldBg);
- unitBox.setBackground(oldBg);
- } catch (CloneNotSupportedException ex) {
- }
- }
- });
- add(valueField, BorderLayout.CENTER);
- try {
- Method method = measure.getUnit().getClass().getMethod("values");
- unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit()));
- unitBox.setSelectedItem(measure.getUnit());
- unitBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- AbstractMeasure> newMeasure = (AbstractMeasure>) ((AbstractMeasure) property
- .getValue()).clone();
- newMeasure.setUnit((Enum extends Unit>) unitBox.getSelectedItem());
- property.setValue(newMeasure);
- property.setChanged(true);
- valueField.setBackground(oldBg);
- unitBox.setBackground(oldBg);
- } catch (CloneNotSupportedException ex) {
- }
- }
- });
- add(unitBox, BorderLayout.EAST);
-
- if (!property.isUnique()) {
- valueField.setBackground(Constants.MULTI_VALUE_COLOR);
- unitBox.setBackground(Constants.MULTI_VALUE_COLOR);
- }
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/PropertyEditorDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/PropertyEditorDialog.java
deleted file mode 100644
index b8242a71..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/PropertyEditorDialog.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.BorderFactory;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.ValidationException;
-
-import com.diyfever.gui.ButtonDialog;
-
-public class PropertyEditorDialog extends ButtonDialog {
-
- private static final Logger LOG = Logger.getLogger(PropertyEditorDialog.class);
-
- private static final long serialVersionUID = 1L;
-
- private static final String DEFAULT_BOX_TOOLTIP = "If this box is checked application will use the current value as a
default when creating new components of the same type";
-
- private List properties;
- private Set defaultedProperties;
-
- public PropertyEditorDialog(JFrame owner, List properties, String title) {
- super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
-
- LOG.debug("Creating property editor for: " + properties);
-
- this.properties = properties;
- this.defaultedProperties = new HashSet();
-
- setMinimumSize(new Dimension(240, 40));
-
- layoutGui();
- setLocationRelativeTo(owner);
- //
- // setModal(true);
- //
- // JPanel holderPanel = new JPanel();
- // holderPanel.setLayout(new BorderLayout());
- // holderPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
- //
- // holderPanel.add(createEditorFields(), BorderLayout.CENTER);
- // holderPanel.add(createButtonPanel(), BorderLayout.SOUTH);
- //
- // setContentPane(holderPanel);
- //
- //
- // pack();
- // setLocationRelativeTo(owner);
- }
-
- @Override
- protected boolean validateInput(String button) {
- if (button.equals(ButtonDialog.OK)) {
- for (PropertyWrapper property : properties) {
- try {
- property.getValidator().validate(property.getValue());
- } catch (ValidationException ve) {
- JOptionPane.showMessageDialog(PropertyEditorDialog.this, "Input error for \""
- + property.getName() + "\": " + ve.getMessage(), "Error",
- JOptionPane.ERROR_MESSAGE);
- return false;
- }
- }
- }
- return true;
- }
-
- private JPanel createEditorFields() {
- JPanel editorPanel = new JPanel(new GridBagLayout());
- editorPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
-
- GridBagConstraints gbc = new GridBagConstraints();
-
- gbc.gridy = 0;
- gbc.insets = new Insets(2, 2, 2, 2);
- gbc.anchor = GridBagConstraints.LINE_START;
-
- for (PropertyWrapper property : properties) {
- gbc.gridx = 0;
- gbc.fill = GridBagConstraints.NONE;
- gbc.weightx = 0;
-
- editorPanel.add(new JLabel(property.getName() + ": "), gbc);
-
- gbc.gridx = 1;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1;
-
- Component editor = FieldEditorFactory.createFieldEditor(property);
- editor.addKeyListener(new KeyAdapter() {
-
- @Override
- public void keyPressed(KeyEvent e) {
- if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- getButton(OK).doClick();
- } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
- getButton(CANCEL).doClick();
- }
- }
- });
- editorPanel.add(editor, gbc);
-
- if (property.isDefaultable()) {
- gbc.gridx = 2;
- gbc.fill = GridBagConstraints.NONE;
- gbc.weightx = 0;
-
- editorPanel.add(createDefaultCheckBox(property), gbc);
- }
-
- gbc.gridy++;
- }
-
- return editorPanel;
- }
-
- private JCheckBox createDefaultCheckBox(final PropertyWrapper property) {
- final JCheckBox checkBox = new JCheckBox();
- checkBox.setToolTipText(DEFAULT_BOX_TOOLTIP);
- checkBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- if (checkBox.isSelected()) {
- defaultedProperties.add(property);
- } else {
- defaultedProperties.remove(property);
- }
- }
- });
- return checkBox;
- }
-
- public Set getDefaultedProperties() {
- return defaultedProperties;
- }
-
- public static boolean showFor(JFrame owner, List properties, String title) {
- PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
- editor.setVisible(true);
- if (OK.equals(editor.getSelectedButtonCaption())) {
- return true;
- }
- return false;
- }
-
- @Override
- protected JComponent getMainComponent() {
- return createEditorFields();
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/StringEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/StringEditor.java
deleted file mode 100644
index 3dbf9e16..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/gui/editor/StringEditor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.diylc.swing.gui.editor;
-
-import java.awt.Color;
-
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import org.diylc.common.PropertyWrapper;
-import org.diylc.utils.Constants;
-
-public class StringEditor extends JTextField {
-
- private static final long serialVersionUID = 1L;
-
- private Color oldBg = getBackground();
-
- private final PropertyWrapper property;
-
- public StringEditor(PropertyWrapper property) {
- super(property.getValue() == null ? "" : (String) property.getValue());
- this.property = property;
- getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- textChanged();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- textChanged();
- }
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- textChanged();
- }
- });
- if (!property.isUnique()) {
- setBackground(Constants.MULTI_VALUE_COLOR);
- }
- }
-
- private void textChanged() {
- property.setChanged(true);
- setBackground(oldBg);
- property.setValue(getText());
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/autosave/AutoSavePlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/autosave/AutoSavePlugin.java
deleted file mode 100644
index d622272d..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/autosave/AutoSavePlugin.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.diylc.swing.plugins.autosave;
-
-import java.io.File;
-import java.util.EnumSet;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.swing.SwingUtilities;
-
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.IView;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-public class AutoSavePlugin implements IPlugIn {
-
- private static final String AUTO_SAVE_FILE_NAME = "autoSave.diy";
-
- private ExecutorService executor;
-
- private IPlugInPort plugInPort;
- private IView view;
-
- public AutoSavePlugin(IView view) {
- this.view = view;
- executor = Executors.newSingleThreadExecutor();
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- SwingUtilities.invokeLater(new Runnable() {
-
- @Override
- public void run() {
- boolean wasAbnormal = ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.ABNORMAL_EXIT_KEY, false);
- if (wasAbnormal && new File(AUTO_SAVE_FILE_NAME).exists()) {
- int decision = view
- .showConfirmDialog(
- "It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?",
- "Auto-Save", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE);
- if (decision == IView.YES_OPTION) {
- AutoSavePlugin.this.plugInPort.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
- }
- }
- // Set abnormal flag to true, GUI side of the app must flip to
- // false when app closes regularly.
- ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY, true);
- }
- });
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.of(EventType.PROJECT_MODIFIED);
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- if (eventType == EventType.PROJECT_MODIFIED) {
- executor.execute(new Runnable() {
-
- @Override
- public void run() {
- plugInPort.saveProjectToFile(AUTO_SAVE_FILE_NAME, true);
- }
- });
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasGestureListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasGestureListener.java
deleted file mode 100644
index f8273c2a..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasGestureListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.dnd.DragGestureEvent;
-import java.awt.dnd.DragGestureListener;
-
-import org.diylc.common.IPlugInPort;
-
-/**
- * {@link DragGestureListener} for {@link CanvasPanel}.
- *
- * @author Branislav Stojkovic
- */
-class CanvasGestureListener implements DragGestureListener {
-
- private IPlugInPort presenter;
-
- public CanvasGestureListener(IPlugInPort presenter) {
- super();
- this.presenter = presenter;
- }
-
- @Override
- public void dragGestureRecognized(DragGestureEvent dge) {
- presenter.dragStarted(dge.getDragOrigin(), dge.getTriggerEvent().isControlDown(), dge
- .getTriggerEvent().isShiftDown(), dge.getTriggerEvent().isAltDown());
- dge.startDrag(presenter.getCursorAt(dge.getDragOrigin()), new EmptyTransferable(),
- new CanvasSourceListener(presenter));
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPanel.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPanel.java
deleted file mode 100644
index 83e8b9d9..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPanel.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
-import java.awt.Image;
-import java.awt.Insets;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.dnd.Autoscroll;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragSource;
-import java.awt.dnd.DropTarget;
-import java.awt.event.ActionEvent;
-import java.awt.event.ComponentAdapter;
-import java.awt.event.ComponentEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.image.VolatileImage;
-import java.util.EnumSet;
-import java.util.Set;
-
-import javax.swing.AbstractAction;
-import javax.swing.JComponent;
-import javax.swing.KeyStroke;
-
-import org.diylc.common.DrawOption;
-import org.diylc.common.IPlugInPort;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-/**
- * GUI class used to draw onto.
- *
- * @author Branislav Stojkovic
- */
-class CanvasPanel extends JComponent implements Autoscroll {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort plugInPort;
-
- private Image bufferImage;
- private GraphicsConfiguration screenGraphicsConfiguration;
-
- private static boolean USE_HARDWARE_ACCELLERATION = false;
-
-// static final EnumSet DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
-// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
-// static final EnumSet DRAW_OPTIONS_ANTI_ALIASING = EnumSet.of(DrawOption.GRID,
-// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
-// DrawOption.CONTROL_POINTS);
-
- public CanvasPanel(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- setFocusable(true);
- initializeListeners();
- initializeDnD();
- GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
- screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
-
- initializeActions();
- }
-
- public void invalidateCache() {
- bufferImage = null;
- }
-
- private void initializeDnD() {
- // Initialize drag source recognizer.
- DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
- DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
- new CanvasGestureListener(plugInPort));
- // Initialize drop target.
- new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE,
- new CanvasTargetListener(plugInPort), true);
- }
-
- private void initializeActions() {
- getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
- getActionMap().put("clearSlot", new AbstractAction() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void actionPerformed(ActionEvent e) {
- CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null);
- }
- });
- }
-
- protected void createBufferImage() {
- if (USE_HARDWARE_ACCELLERATION) {
- bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(),
- getHeight());
- ((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
- } else {
- bufferImage = createImage(getWidth(), getHeight());
- }
- }
-
- @Override
- public void paint(Graphics g) {
- if (plugInPort == null) {
- return;
- }
- if (bufferImage == null) {
- createBufferImage();
- }
- Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
- g2d.setClip(getVisibleRect());
- Set drawOptions = EnumSet.of(DrawOption.GRID, DrawOption.SELECTION,
- DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
- drawOptions.add(DrawOption.ANTIALIASING);
- }
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
- drawOptions.add(DrawOption.OUTLINE_MODE);
- }
- plugInPort.draw(g2d, drawOptions, null);
- if (USE_HARDWARE_ACCELLERATION) {
- VolatileImage volatileImage = (VolatileImage) bufferImage;
- do {
- try {
- if (volatileImage.contentsLost()) {
- createBufferImage();
- }
- // int validation =
- // volatileImage.validate(screenGraphicsConfiguration);
- // if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
- // createBufferImage();
- // }
- g.drawImage(bufferImage, 0, 0, this);
- } catch (NullPointerException e) {
- createBufferImage();
- }
- } while (volatileImage == null || volatileImage.contentsLost());
- } else {
- g.drawImage(bufferImage, 0, 0, this);
- // bufferImage.flush();
- }
- }
-
- @Override
- public void update(Graphics g) {
- paint(g);
- }
-
- private void initializeListeners() {
- addComponentListener(new ComponentAdapter() {
-
- @Override
- public void componentResized(ComponentEvent e) {
- invalidateCache();
- invalidate();
- }
- });
- // addKeyListener(new KeyAdapter() {
- //
- // @Override
- // public void keyPressed(KeyEvent e) {
- // if (e.getKeyCode() == KeyEvent.VK_DELETE) {
- // plugInPort.deleteSelectedComponents();
- // }
- // // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
- // // e.isShiftDown(), e
- // // .isAltDown());
- // }
- // });
- addMouseMotionListener(new MouseAdapter() {
-
- @Override
- public void mouseMoved(MouseEvent e) {
- setCursor(plugInPort.getCursorAt(e.getPoint()));
- plugInPort.mouseMoved(e.getPoint(), e.isControlDown(), e.isShiftDown(), e
- .isAltDown());
- }
- });
- addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseClicked(MouseEvent e) {
- if (e.getButton() == MouseEvent.BUTTON1) {
- plugInPort.mouseClicked(e.getPoint(), e.isControlDown(), e.isShiftDown(), e
- .isAltDown(), e.getClickCount());
- }
- }
- });
- }
-
- // Autoscroll
-
- @Override
- public void autoscroll(Point cursorLocn) {
- scrollRectToVisible(new Rectangle(cursorLocn.x - 15, cursorLocn.y - 15, 30, 30));
- }
-
- @Override
- public Insets getAutoscrollInsets() {
- Rectangle rect = getVisibleRect();
- return new Insets(rect.y - 15, rect.x - 15, rect.y + rect.height + 15, rect.x + rect.width
- + 15);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java
deleted file mode 100644
index 6a7f32d5..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java
+++ /dev/null
@@ -1,319 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Dimension;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.ClipboardOwner;
-import java.awt.datatransfer.Transferable;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-import java.util.EnumSet;
-
-import javax.swing.JPopupMenu;
-import javax.swing.SwingConstants;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.BadPositionException;
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.measures.Size;
-import org.diylc.core.measures.SizeUnit;
-import org.diylc.presenter.Presenter;
-import org.diylc.swing.ActionFactory;
-import org.diylc.swing.ISwingUI;
-import org.diylc.swing.plugins.edit.ComponentTransferable;
-import org.diylc.swing.plugins.file.ProjectDrawingProvider;
-
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.diyfever.gui.miscutils.IConfigListener;
-import com.diyfever.gui.ruler.IRulerListener;
-import com.diyfever.gui.ruler.RulerScrollPane;
-
-public class CanvasPlugin implements IPlugIn, ClipboardOwner {
-
- private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
-
- private RulerScrollPane scrollPane;
- private CanvasPanel canvasPanel;
- private JPopupMenu popupMenu;
-
- private ActionFactory.CutAction cutAction;
- private ActionFactory.CopyAction copyAction;
- private ActionFactory.PasteAction pasteAction;
- private ActionFactory.EditSelectionAction editSelectionAction;
- private ActionFactory.DeleteSelectionAction deleteSelectionAction;
- private ActionFactory.GroupAction groupAction;
- private ActionFactory.UngroupAction ungroupAction;
- private ActionFactory.SendToBackAction sendToBackAction;
- private ActionFactory.BringToFrontAction bringToFrontAction;
-
- private IPlugInPort plugInPort;
- private ISwingUI swingUI;
-
- private Clipboard clipboard;
-
- private double zoomLevel = 1;
-
- public CanvasPlugin(ISwingUI swingUI) {
- this.swingUI = swingUI;
- clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- try {
- swingUI.injectGUIComponent(getScrollPane(), SwingConstants.CENTER);
- } catch (BadPositionException e) {
- LOG.error("Could not install canvas plugin", e);
- }
- }
-
- public CanvasPanel getCanvasPanel() {
- if (canvasPanel == null) {
- canvasPanel = new CanvasPanel(plugInPort);
- canvasPanel.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseReleased(MouseEvent e) {
- if (e.isPopupTrigger()) {
- // Enable actions.
- boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
- getCutAction().setEnabled(enabled);
- getCopyAction().setEnabled(enabled);
- try {
- getPasteAction()
- .setEnabled(
- clipboard
- .isDataFlavorAvailable(ComponentTransferable.listFlavor));
- } catch (Exception ex) {
- getPasteAction().setEnabled(false);
- }
- getEditSelectionAction().setEnabled(enabled);
- getDeleteSelectionAction().setEnabled(enabled);
- getGroupAction().setEnabled(enabled);
- getUngroupAction().setEnabled(enabled);
- getSendToBackAction().setEnabled(enabled);
- getBringToFrontAction().setEnabled(enabled);
-
- getPopupMenu().show(canvasPanel, e.getX(), e.getY());
- }
- }
- });
- }
- return canvasPanel;
- }
-
- private RulerScrollPane getScrollPane() {
- if (scrollPane == null) {
- scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
- plugInPort, true, false), new Size(1d, SizeUnit.cm).convertToPixels(),
- new Size(1d, SizeUnit.in).convertToPixels());
- boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
- true);
- boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.WHEEL_ZOOM_KEY, false);
- ConfigurationManager.getInstance().addConfigListener(IPlugInPort.WHEEL_ZOOM_KEY,
- new IConfigListener() {
-
- @Override
- public void valueChanged(String key, Object value) {
- scrollPane.setWheelScrollingEnabled(!(Boolean) value);
- }
- });
- scrollPane.setMetric(metric);
- scrollPane.setWheelScrollingEnabled(!wheelZoom);
- scrollPane.addUnitListener(new IRulerListener() {
-
- @Override
- public void unitsChanged(boolean isMetric) {
- plugInPort.setMetric(isMetric);
- }
- });
- scrollPane.addMouseWheelListener(new MouseWheelListener() {
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(
- IPlugInPort.WHEEL_ZOOM_KEY, false);
- if (!wheelZoom) {
- return;
- }
- double d = plugInPort.getZoomLevel();
- Double[] availableZoomLevels = plugInPort.getAvailableZoomLevels();
- if (e.getWheelRotation() > 0) {
- int i = availableZoomLevels.length - 1;
- while (i > 0 && availableZoomLevels[i] >= d) {
- i--;
- }
- plugInPort.setZoomLevel(availableZoomLevels[i]);
- } else {
- int i = 0;
- while (i < availableZoomLevels.length - 1 && availableZoomLevels[i] <= d) {
- i++;
- }
- plugInPort.setZoomLevel(availableZoomLevels[i]);
- }
- }
- });
- }
- return scrollPane;
- }
-
- public JPopupMenu getPopupMenu() {
- if (popupMenu == null) {
- popupMenu = new JPopupMenu();
- popupMenu.add(getCutAction());
- popupMenu.add(getCopyAction());
- popupMenu.add(getPasteAction());
- popupMenu.addSeparator();
- popupMenu.add(getEditSelectionAction());
- popupMenu.add(getDeleteSelectionAction());
- popupMenu.add(getGroupAction());
- popupMenu.add(getUngroupAction());
- popupMenu.add(getSendToBackAction());
- popupMenu.add(getBringToFrontAction());
- popupMenu.addSeparator();
- popupMenu.add(ActionFactory.getInstance().createEditProjectAction(plugInPort));
- }
- return popupMenu;
- }
-
- public ActionFactory.CutAction getCutAction() {
- if (cutAction == null) {
- cutAction = ActionFactory.getInstance().createCutAction(plugInPort, clipboard, this);
- }
- return cutAction;
- }
-
- public ActionFactory.CopyAction getCopyAction() {
- if (copyAction == null) {
- copyAction = ActionFactory.getInstance().createCopyAction(plugInPort, clipboard, this);
- }
- return copyAction;
- }
-
- public ActionFactory.PasteAction getPasteAction() {
- if (pasteAction == null) {
- pasteAction = ActionFactory.getInstance().createPasteAction(plugInPort, clipboard);
- }
- return pasteAction;
- }
-
- public ActionFactory.EditSelectionAction getEditSelectionAction() {
- if (editSelectionAction == null) {
- editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
- }
- return editSelectionAction;
- }
-
- public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
- if (deleteSelectionAction == null) {
- deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(
- plugInPort);
- }
- return deleteSelectionAction;
- }
-
- public ActionFactory.GroupAction getGroupAction() {
- if (groupAction == null) {
- groupAction = ActionFactory.getInstance().createGroupAction(plugInPort);
- }
- return groupAction;
- }
-
- public ActionFactory.UngroupAction getUngroupAction() {
- if (ungroupAction == null) {
- ungroupAction = ActionFactory.getInstance().createUngroupAction(plugInPort);
- }
- return ungroupAction;
- }
-
- public ActionFactory.SendToBackAction getSendToBackAction() {
- if (sendToBackAction == null) {
- sendToBackAction = ActionFactory.getInstance().createSendToBackAction(plugInPort);
- }
- return sendToBackAction;
- }
-
- public ActionFactory.BringToFrontAction getBringToFrontAction() {
- if (bringToFrontAction == null) {
- bringToFrontAction = ActionFactory.getInstance().createBringToFrontAction(plugInPort);
- }
- return bringToFrontAction;
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT);
- }
-
- @Override
- public void processMessage(final EventType eventType, Object... params) {
- // SwingUtilities.invokeLater(new Runnable() {
- //
- // @Override
- // public void run() {
- // LOG.debug("event: " + eventType);
- switch (eventType) {
- case PROJECT_LOADED:
- refreshSize();
- if ((Boolean) params[1]) {
- // Scroll to the center.
- Rectangle visibleRect = canvasPanel.getVisibleRect();
- visibleRect.setLocation((canvasPanel.getWidth() - visibleRect.width) / 2,
- (canvasPanel.getHeight() - visibleRect.height) / 2);
- canvasPanel.scrollRectToVisible(visibleRect);
- canvasPanel.revalidate();
- }
- break;
- case ZOOM_CHANGED:
- Rectangle visibleRect = canvasPanel.getVisibleRect();
- refreshSize();
- // Try to set the visible area to be centered with the previous
- // one.
- double zoomFactor = (Double) params[0] / zoomLevel;
- visibleRect.setBounds((int) (visibleRect.x * zoomFactor),
- (int) (visibleRect.y * zoomFactor), visibleRect.width, visibleRect.height);
- canvasPanel.scrollRectToVisible(visibleRect);
- canvasPanel.revalidate();
-
- zoomLevel = (Double) params[0];
- break;
- case REPAINT:
- canvasPanel.repaint();
- break;
- }
- // }
- // });
- }
-
- private void refreshSize() {
- Dimension d = plugInPort.getCanvasDimensions(true);
- canvasPanel.setSize(d);
- canvasPanel.setPreferredSize(d);
- getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
- }
-
- /**
- * Causes ruler scroll pane to refresh by sending a fake mouse moved message
- * to the canvasPanel.
- */
- public void refresh() {
- MouseEvent event = new MouseEvent(canvasPanel, MouseEvent.MOUSE_MOVED, System
- .currentTimeMillis(), 0, 1, 1,// canvasPanel.getWidth() / 2,
- // canvasPanel.getHeight() / 2,
- 0, false);
- canvasPanel.dispatchEvent(event);
- }
-
- @Override
- public void lostOwnership(Clipboard clipboard, Transferable contents) {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasSourceListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasSourceListener.java
deleted file mode 100644
index 61a98185..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasSourceListener.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Point;
-import java.awt.dnd.DragSourceDragEvent;
-import java.awt.dnd.DragSourceDropEvent;
-import java.awt.dnd.DragSourceEvent;
-import java.awt.dnd.DragSourceListener;
-
-import org.diylc.common.IPlugInPort;
-
-
-/**
- * {@link DragSourceListener} for {@link CanvasPanel}.
- *
- * @author Branislav Stojkovic
- */
-class CanvasSourceListener implements DragSourceListener {
-
- private IPlugInPort presenter;
-
- public CanvasSourceListener(IPlugInPort presenter) {
- super();
- this.presenter = presenter;
- }
-
- @Override
- public void dragDropEnd(DragSourceDropEvent dsde) {
- presenter.dragEnded(null);
- }
-
- @Override
- public void dragEnter(DragSourceDragEvent dsde) {
- }
-
- @Override
- public void dragExit(DragSourceEvent dse) {
- }
-
- @Override
- public void dragOver(DragSourceDragEvent dsde) {
- Point p = dsde.getDragSourceContext().getComponent().getMousePosition();
- if (p != null) {
- dsde.getDragSourceContext().getComponent().firePropertyChange("dragPoint", p.x, p.y);
- }
- }
-
- @Override
- public void dropActionChanged(DragSourceDragEvent dsde) {
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasTargetListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasTargetListener.java
deleted file mode 100644
index a96f6273..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/CanvasTargetListener.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Point;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-
-import org.diylc.common.IPlugInPort;
-
-
-/**
- * {@link DropTargetListener} for {@link CanvasPanel}.
- *
- * @author Branislav Stojkovic
- */
-class CanvasTargetListener implements DropTargetListener {
-
- private IPlugInPort presenter;
-
- // Cached values
- private Point currentPoint = null;
- private boolean lastAccept;
-
- public CanvasTargetListener(IPlugInPort presenter) {
- super();
- this.presenter = presenter;
- }
-
- @Override
- public void dragEnter(DropTargetDragEvent dtde) {
- }
-
- @Override
- public void dragExit(DropTargetEvent dte) {
- }
-
- @Override
- public void dragOver(DropTargetDragEvent dtde) {
- // If dragOver was previously called for this location use cached value.
- if (dtde.getLocation().equals(currentPoint)) {
- if (lastAccept) {
- dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
- } else {
- dtde.rejectDrag();
- }
- return;
- }
- try {
- // Transferable t = dtde.getTransferable();
- // if
- // (t.isDataFlavorSupported(SelectionTransferable.selectionFlavor))
- // {
- // if (currentPoint != null) {
- // List selection = (List) t
- // .getTransferData(SelectionTransferable.selectionFlavor);
- // Point startPoint = (Point) t
- // .getTransferData(PointTransferable.pointFlavor);
- // presenter.selectionMoved(dtde.getLocation().x
- // - currentPoint.x, dtde.getLocation().y
- // - currentPoint.y);
- // }
- // } else if
- // (t.isDataFlavorSupported(PointTransferable.pointFlavor)) {
- // Point startPoint = (Point) t
- // .getTransferData(PointTransferable.pointFlavor);
- // Point endPoint = dtde.getLocation();
- // presenter.setSelectionRect(Utils.createRectangle(startPoint,
- // endPoint));
- // }
- currentPoint = dtde.getLocation();
- if (presenter.dragOver(currentPoint)) {
- dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
- lastAccept = true;
- } else {
- dtde.rejectDrag();
- lastAccept = false;
- }
- } catch (Exception e) {
- e.printStackTrace();
- dtde.rejectDrag();
- lastAccept = false;
- }
- }
-
- @Override
- public void drop(DropTargetDropEvent dtde) {
- presenter.dragEnded(dtde.getLocation());
- }
-
- @Override
- public void dropActionChanged(DropTargetDragEvent dtde) {
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/EmptyTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/EmptyTransferable.java
deleted file mode 100644
index ccddb7b1..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/EmptyTransferable.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-
-public class EmptyTransferable implements Transferable {
-
- @Override
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- throw new UnsupportedFlavorException(flavor);
- }
-
- @Override
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] {};
- }
-
- @Override
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return false;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/PointTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/PointTransferable.java
deleted file mode 100644
index 7c854f82..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/PointTransferable.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Point;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-
-public class PointTransferable implements Transferable {
-
- public static final DataFlavor pointFlavor = new DataFlavor(Point.class, "Java Point");
-
- private Point startPoint;
-
- public PointTransferable(Point startPoint) {
- super();
- this.startPoint = startPoint;
- }
-
- @Override
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- if (flavor.equals(pointFlavor)) {
- return startPoint;
- }
- throw new UnsupportedFlavorException(flavor);
- }
-
- @Override
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] { pointFlavor };
- }
-
- @Override
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return flavor.equals(pointFlavor);
- }
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/SelectionTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/SelectionTransferable.java
deleted file mode 100644
index 5901d2fc..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/canvas/SelectionTransferable.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.diylc.swing.plugins.canvas;
-
-import java.awt.Point;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-import java.util.List;
-
-import org.diylc.core.IDIYComponent;
-
-
-public class SelectionTransferable implements Transferable {
-
- public static final DataFlavor selectionFlavor = new DataFlavor(List.class,
- "Component Selection");
-
- private Point startPoint;
- private List> selection;
-
- public SelectionTransferable(List> selection, Point startPoint) {
- super();
- this.selection = selection;
- this.startPoint = startPoint;
- }
-
- @Override
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- if (flavor.equals(selectionFlavor)) {
- return selection;
- }
- if (flavor.equals(PointTransferable.pointFlavor)) {
- return startPoint;
- }
- throw new UnsupportedFlavorException(flavor);
- }
-
- @Override
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] { selectionFlavor, PointTransferable.pointFlavor };
- }
-
- @Override
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return flavor.equals(selectionFlavor) || flavor.equals(selectionFlavor);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/config/ConfigPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/config/ConfigPlugin.java
deleted file mode 100644
index d12360df..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/config/ConfigPlugin.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.diylc.swing.plugins.config;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.EnumSet;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.Theme;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.ActionFactory;
-import org.diylc.swing.ISwingUI;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
-/**
- * Controls configuration menu.
- *
- * @author Branislav Stojkovic
- */
-public class ConfigPlugin implements IPlugIn {
-
- private static final Logger LOG = Logger.getLogger(ConfigPlugin.class);
-
- private static final String CONFIG_MENU = "Config";
- private static final String THEME_MENU = "Theme";
-
- private ISwingUI swingUI;
-
- public ConfigPlugin(ISwingUI swingUI) {
- super();
- this.swingUI = swingUI;
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Anti-Aliasing", IPlugInPort.ANTI_ALIASING_KEY, true), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Auto-Create Pads", IPlugInPort.AUTO_PADS_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Auto-Edit Mode", IPlugInPort.AUTO_EDIT_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Continuous Creation", IPlugInPort.CONTINUOUS_CREATION_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Export Grid", IPlugInPort.EXPORT_GRID_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Hi-Quality Rendering", IPlugInPort.HI_QUALITY_RENDER_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Mouse Wheel Zoom", IPlugInPort.WHEEL_ZOOM_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Outline Mode", IPlugInPort.OUTLINE_KEY, false), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Snap to Grid", IPlugInPort.SNAP_TO_GRID_KEY, true), CONFIG_MENU);
- swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
- "Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU);
-
- File themeDir = new File("themes");
- if (themeDir.exists()) {
- XStream xStream = new XStream(new DomDriver());
- swingUI.injectSubmenu(THEME_MENU, IconLoader.Pens.getIcon(), CONFIG_MENU);
- for (File file : themeDir.listFiles()) {
- if (file.getName().toLowerCase().endsWith(".xml")) {
- try {
- InputStream in = new FileInputStream(file);
- Theme theme = (Theme) xStream.fromXML(in);
- LOG.debug("Found theme: " + theme.getName());
- swingUI.injectMenuAction(ActionFactory.getInstance().createThemeAction(
- plugInPort, theme), THEME_MENU);
- } catch (Exception e) {
- LOG.error("Could not load theme file " + file.getName(), e);
- }
- }
- }
- }
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.noneOf(EventType.class);
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/ComponentTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/ComponentTransferable.java
deleted file mode 100644
index e5506739..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/ComponentTransferable.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.diylc.swing.plugins.edit;
-
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.diylc.core.IDIYComponent;
-
-/**
- * Represents component selection as a {@link List} of {@link IDIYComponent}
- * objects. Implements {@link Transferable}, so it is suitable for clipboard
- * usage.
- *
- * @author Branislav Stojkovic
- */
-public class ComponentTransferable extends ArrayList> implements Transferable {
-
- private static final long serialVersionUID = 1L;
-
- public static final DataFlavor listFlavor = new DataFlavor(ComponentTransferable.class, "application/diylc");
-
- public ComponentTransferable() {
- super();
- }
-
- public ComponentTransferable(Collection> selectedComponents) {
- super(selectedComponents);
- }
-
- @Override
- public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- if (flavor.equals(listFlavor)) {
- return this;
- }
- throw new UnsupportedFlavorException(flavor);
- }
-
- @Override
- public DataFlavor[] getTransferDataFlavors() {
- return new DataFlavor[] { listFlavor };
- }
-
- @Override
- public boolean isDataFlavorSupported(DataFlavor flavor) {
- return flavor.equals(listFlavor);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java
deleted file mode 100644
index 9be4addb..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/edit/EditMenuPlugin.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.diylc.swing.plugins.edit;
-
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.ClipboardOwner;
-import java.awt.datatransfer.FlavorEvent;
-import java.awt.datatransfer.FlavorListener;
-import java.awt.datatransfer.Transferable;
-import java.util.EnumSet;
-
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.Project;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.ActionFactory;
-import org.diylc.swing.ISwingUI;
-
-import com.diyfever.gui.undo.IUndoListener;
-import com.diyfever.gui.undo.UndoHandler;
-
-public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
-
- private static final String EDIT_TITLE = "Edit";
- private static final String RENUMBER_TITLE = "Renumber Selection";
-
- private IPlugInPort plugInPort;
- private ISwingUI swingUI;
-
- private Clipboard clipboard;
-
- private ActionFactory.CutAction cutAction;
- private ActionFactory.CopyAction copyAction;
- private ActionFactory.PasteAction pasteAction;
- private ActionFactory.EditSelectionAction editSelectionAction;
- private ActionFactory.DeleteSelectionAction deleteSelectionAction;
- private ActionFactory.GroupAction groupAction;
- private ActionFactory.UngroupAction ungroupAction;
- private ActionFactory.SendToBackAction sendToBackAction;
- private ActionFactory.BringToFrontAction bringToFrontAction;
- private ActionFactory.RenumberAction renumberXAxisAction;
- private ActionFactory.RenumberAction renumberYAxisAction;
-
- private UndoHandler undoHandler;
-
- public EditMenuPlugin(ISwingUI swingUI) {
- this.swingUI = swingUI;
- // SecurityManager securityManager = System.getSecurityManager();
- // if (securityManager != null) {
- // try {
- // securityManager.checkSystemClipboardAccess();
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // }
- clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- undoHandler = new UndoHandler(new IUndoListener() {
-
- @Override
- public void actionPerformed(Project currentState) {
- plugInPort.loadProject(currentState, false);
- }
- });
- clipboard.addFlavorListener(new FlavorListener() {
-
- @Override
- public void flavorsChanged(FlavorEvent e) {
- refreshActions();
- }
- });
- }
-
- public ActionFactory.CutAction getCutAction() {
- if (cutAction == null) {
- cutAction = ActionFactory.getInstance().createCutAction(plugInPort, clipboard, this);
- }
- return cutAction;
- }
-
- public ActionFactory.CopyAction getCopyAction() {
- if (copyAction == null) {
- copyAction = ActionFactory.getInstance().createCopyAction(plugInPort, clipboard, this);
- }
- return copyAction;
- }
-
- public ActionFactory.PasteAction getPasteAction() {
- if (pasteAction == null) {
- pasteAction = ActionFactory.getInstance().createPasteAction(plugInPort, clipboard);
- }
- return pasteAction;
- }
-
- public ActionFactory.EditSelectionAction getEditSelectionAction() {
- if (editSelectionAction == null) {
- editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
- }
- return editSelectionAction;
- }
-
- public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
- if (deleteSelectionAction == null) {
- deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(
- plugInPort);
- }
- return deleteSelectionAction;
- }
-
- public ActionFactory.GroupAction getGroupAction() {
- if (groupAction == null) {
- groupAction = ActionFactory.getInstance().createGroupAction(plugInPort);
- }
- return groupAction;
- }
-
- public ActionFactory.UngroupAction getUngroupAction() {
- if (ungroupAction == null) {
- ungroupAction = ActionFactory.getInstance().createUngroupAction(plugInPort);
- }
- return ungroupAction;
- }
-
- public ActionFactory.SendToBackAction getSendToBackAction() {
- if (sendToBackAction == null) {
- sendToBackAction = ActionFactory.getInstance().createSendToBackAction(plugInPort);
- }
- return sendToBackAction;
- }
-
- public ActionFactory.BringToFrontAction getBringToFrontAction() {
- if (bringToFrontAction == null) {
- bringToFrontAction = ActionFactory.getInstance().createBringToFrontAction(plugInPort);
- }
- return bringToFrontAction;
- }
-
- public ActionFactory.RenumberAction getRenumberXAxisAction() {
- if (renumberXAxisAction == null) {
- renumberXAxisAction = ActionFactory.getInstance()
- .createRenumberAction(plugInPort, true);
- }
- return renumberXAxisAction;
- }
-
- public ActionFactory.RenumberAction getRenumberYAxisAction() {
- if (renumberYAxisAction == null) {
- renumberYAxisAction = ActionFactory.getInstance().createRenumberAction(plugInPort,
- false);
- }
- return renumberYAxisAction;
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
-
- ActionFactory actionFactory = ActionFactory.getInstance();
-
- swingUI.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE);
- swingUI.injectMenuAction(undoHandler.getRedoAction(), EDIT_TITLE);
- swingUI.injectMenuAction(null, EDIT_TITLE);
- swingUI.injectMenuAction(getCutAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getCopyAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getPasteAction(), EDIT_TITLE);
- swingUI.injectMenuAction(null, EDIT_TITLE);
- swingUI.injectMenuAction(actionFactory.createSelectAllAction(plugInPort), EDIT_TITLE);
- swingUI.injectMenuAction(getEditSelectionAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getDeleteSelectionAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getGroupAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getUngroupAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getSendToBackAction(), EDIT_TITLE);
- swingUI.injectMenuAction(getBringToFrontAction(), EDIT_TITLE);
- swingUI.injectMenuAction(null, EDIT_TITLE);
- swingUI.injectSubmenu(RENUMBER_TITLE, IconLoader.Sort.getIcon(), EDIT_TITLE);
- swingUI.injectMenuAction(getRenumberXAxisAction(), RENUMBER_TITLE);
- swingUI.injectMenuAction(getRenumberYAxisAction(), RENUMBER_TITLE);
- swingUI.injectMenuAction(null, EDIT_TITLE);
- swingUI.injectMenuAction(actionFactory.createEditProjectAction(plugInPort), EDIT_TITLE);
-
- refreshActions();
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED);
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- switch (eventType) {
- case SELECTION_CHANGED:
- refreshActions();
- break;
- case PROJECT_MODIFIED:
- undoHandler.stateChanged((Project) params[0], (Project) params[1], (String) params[2]);
- break;
- }
- }
-
- private void refreshActions() {
- boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
- getCutAction().setEnabled(enabled);
- getCopyAction().setEnabled(enabled);
- try {
- getPasteAction().setEnabled(
- clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
- } catch (Exception e) {
- getPasteAction().setEnabled(false);
- }
- getEditSelectionAction().setEnabled(enabled);
- getDeleteSelectionAction().setEnabled(enabled);
- getGroupAction().setEnabled(enabled);
- getUngroupAction().setEnabled(enabled);
- getSendToBackAction().setEnabled(enabled);
- getBringToFrontAction().setEnabled(enabled);
- }
-
- // ClipboardOwner
-
- @Override
- public void lostOwnership(Clipboard clipboard, Transferable contents) {
- refreshActions();
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomDialog.java
deleted file mode 100644
index b3b51d4c..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomDialog.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-
-import org.diylc.images.IconLoader;
-import org.diylc.swing.gui.DialogFactory;
-
-import com.diyfever.gui.export.TableExporter;
-import com.diyfever.gui.objecttable.ObjectListTable;
-
-public class BomDialog extends JDialog {
-
- private static final long serialVersionUID = 1L;
-
- private ObjectListTable table;
- private JPanel toolbar;
-
- public BomDialog(JFrame parent, List bom) {
- super(parent, "Bill of Materials");
- setContentPane(createMainPanel());
- getTable().setData(bom);
- pack();
- setLocationRelativeTo(parent);
- }
-
- @Override
- public void setVisible(boolean b) {
- super.setVisible(b);
- if (b) {
- getTable().autoFit(Arrays.asList(3));
- }
- }
-
- private JPanel createMainPanel() {
- JPanel mainPanel = new JPanel();
- mainPanel.setLayout(new BorderLayout());
- mainPanel.add(getToolbar(), BorderLayout.NORTH);
- mainPanel.add(new JScrollPane(getTable()), BorderLayout.CENTER);
- return mainPanel;
- }
-
- private ObjectListTable getTable() {
- if (table == null) {
- try {
- table = new ObjectListTable(BomEntry.class, new String[] { "getName",
- "getValue", "getQuantity", "getNotes/setNotes" }, null);
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
- }
- return table;
- }
-
- private JPanel getToolbar() {
- if (toolbar == null) {
- toolbar = new JPanel();
- toolbar.add(new JButton(new SaveToExcelAction()));
- toolbar.add(new JButton(new SaveToCSVAction()));
- toolbar.add(new JButton(new SaveToPNGAction()));
- toolbar.add(new JButton(new SaveToHTMLAction()));
- }
- return toolbar;
- }
-
- class SaveToExcelAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public SaveToExcelAction() {
- super();
- putValue(Action.NAME, "Save to Excel");
- putValue(Action.SMALL_ICON, IconLoader.Excel.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- File file = DialogFactory.getInstance().showSaveDialog(
- FileFilterEnum.EXCEL.getFilter(), null,
- FileFilterEnum.EXCEL.getExtensions()[0], null);
- if (file != null) {
- try {
- TableExporter.getInstance().exportToExcel(getTable(), file);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
-
- class SaveToCSVAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public SaveToCSVAction() {
- super();
- putValue(Action.NAME, "Save to CSV");
- putValue(Action.SMALL_ICON, IconLoader.CSV.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.CSV.getFilter(),
- null, FileFilterEnum.CSV.getExtensions()[0], null);
- if (file != null) {
- try {
- TableExporter.getInstance().exportToCSV(getTable(), file);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
-
- class SaveToHTMLAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public SaveToHTMLAction() {
- super();
- putValue(Action.NAME, "Save to HTML");
- putValue(Action.SMALL_ICON, IconLoader.HTML.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.HTML.getFilter(),
- null, FileFilterEnum.HTML.getExtensions()[0], null);
- if (file != null) {
- try {
- TableExporter.getInstance().exportToHTML(getTable(), file);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
-
- class SaveToPNGAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public SaveToPNGAction() {
- super();
- putValue(Action.NAME, "Save to PNG");
- putValue(Action.SMALL_ICON, IconLoader.Image.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(),
- null, FileFilterEnum.PNG.getExtensions()[0], null);
- if (file != null) {
- try {
- TableExporter.getInstance().exportToPNG(getTable(), file);
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomEntry.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomEntry.java
deleted file mode 100644
index 550a21d0..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomEntry.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-public class BomEntry {
-
- private String name;
- private String value;
- private Integer quantity;
- private String notes;
-
- public BomEntry(String name, String value, int quantity) {
- super();
- this.name = name;
- this.value = value;
- this.quantity = quantity;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public Integer getQuantity() {
- return quantity;
- }
-
- public void setQuantity(Integer quantity) {
- this.quantity = quantity;
- }
-
- public String getNotes() {
- return notes;
- }
-
- public void setNotes(String notes) {
- this.notes = notes;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((notes == null) ? 0 : notes.hashCode());
- result = prime * result + quantity;
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- BomEntry other = (BomEntry) obj;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (notes == null) {
- if (other.notes != null)
- return false;
- } else if (!notes.equals(other.notes))
- return false;
- if (quantity != other.quantity)
- return false;
- if (value == null) {
- if (other.value != null)
- return false;
- } else if (!value.equals(other.value))
- return false;
- return true;
- }
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomMaker.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomMaker.java
deleted file mode 100644
index 1c3d7d73..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/BomMaker.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.diylc.core.IDIYComponent;
-
-public class BomMaker {
-
- private static BomMaker instance;
-
- public static BomMaker getInstance() {
- if (instance == null) {
- instance = new BomMaker();
- }
- return instance;
- }
-
- private BomMaker() {
- }
-
- public List createBom(List> components) {
- Map entryMap = new HashMap();
- for (IDIYComponent> component : components) {
- String name = component.getName();
- String value = component.getValue() == null ? null : component.getValue().toString();
- if ((name != null) && (value != null)) {
- String key = name + "|" + value;
- if (entryMap.containsKey(key)) {
- BomEntry entry = entryMap.get(key);
- entry.setQuantity(entry.getQuantity() + 1);
- } else {
- entryMap.put(key, new BomEntry(name, value, 1));
- }
- }
- }
- List bom = new ArrayList(entryMap.values());
- Collections.sort(bom, new Comparator() {
-
- @Override
- public int compare(BomEntry o1, BomEntry o2) {
- int compare = o1.getName().compareToIgnoreCase(o2.getName());
- if (compare != 0) {
- return compare;
- }
- return o1.getValue().compareToIgnoreCase(o2.getValue());
- }
- });
- return bom;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileFilterEnum.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileFilterEnum.java
deleted file mode 100644
index 508ad906..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileFilterEnum.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.io.File;
-
-import javax.swing.filechooser.FileFilter;
-
-public enum FileFilterEnum {
-
- PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY(
- "DIY Project Files (*.diy)", "diy"), EXCEL("Excel Workbooks (*.xls)", "xls"), CSV(
- "Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html"), IMAGES(
- "Image Files (*.png, *.jpg, *.gif)", "png", "jpg", "gif");
-
- FileFilter filter;
- String[] extensions;
-
- private FileFilterEnum(final String description, final String... extensions) {
- this.extensions = extensions;
- filter = new FileFilter() {
-
- @Override
- public boolean accept(File f) {
- if (f.isDirectory()) {
- return true;
- }
- String fileExt = f.getName();
- fileExt = fileExt.substring(fileExt.lastIndexOf('.') + 1).toLowerCase();
- for (String ext : extensions) {
- if (ext.equals(fileExt)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
- };
- }
-
- public FileFilter getFilter() {
- return filter;
- }
-
- public String[] getExtensions() {
- return extensions;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileMenuPlugin.java
deleted file mode 100644
index aacd1d81..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/FileMenuPlugin.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.util.EnumSet;
-
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.ActionFactory;
-import org.diylc.swing.ISwingUI;
-
-/**
- * Entry point class for File management utilities.
- *
- * @author Branislav Stojkovic
- */
-public class FileMenuPlugin implements IPlugIn {
-
- private static final String FILE_TITLE = "File";
- private static final String TRACE_MASK_TITLE = "Trace Mask";
-
- private ProjectDrawingProvider drawingProvider;
- private TraceMaskDrawingProvider traceMaskDrawingProvider;
-
- private ISwingUI swingUI;
-
- public FileMenuPlugin(ISwingUI swingUI) {
- super();
- this.swingUI = swingUI;
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.drawingProvider = new ProjectDrawingProvider(plugInPort, false, true);
- this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
-
- ActionFactory actionFactory = ActionFactory.getInstance();
- swingUI.injectMenuAction(actionFactory.createNewAction(plugInPort), FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createOpenAction(plugInPort, swingUI), FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createSaveAction(plugInPort, swingUI), FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createSaveAsAction(plugInPort, swingUI), FILE_TITLE);
- swingUI.injectMenuAction(null, FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createExportPDFAction(drawingProvider, swingUI),
- FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createExportPNGAction(drawingProvider, swingUI),
- FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createPrintAction(drawingProvider), FILE_TITLE);
- swingUI.injectSubmenu(TRACE_MASK_TITLE, IconLoader.TraceMask.getIcon(), FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createExportPDFAction(traceMaskDrawingProvider,
- swingUI), TRACE_MASK_TITLE);
- swingUI.injectMenuAction(actionFactory.createExportPNGAction(traceMaskDrawingProvider,
- swingUI), TRACE_MASK_TITLE);
- swingUI.injectMenuAction(actionFactory.createPrintAction(traceMaskDrawingProvider),
- TRACE_MASK_TITLE);
- swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), FILE_TITLE);
- swingUI.injectMenuAction(null, FILE_TITLE);
- swingUI.injectMenuAction(actionFactory.createExitAction(plugInPort), FILE_TITLE);
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return null;
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- // Do nothing.
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectDrawingProvider.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectDrawingProvider.java
deleted file mode 100644
index 6290a124..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectDrawingProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.util.EnumSet;
-
-import org.diylc.common.DrawOption;
-import org.diylc.common.IPlugInPort;
-
-import com.diyfever.gui.IDrawingProvider;
-import com.diyfever.gui.miscutils.ConfigurationManager;
-
-/**
- * {@link IDrawingProvider} implementation that uses {@link IPlugInPort} to draw
- * a project onto the canvas.
- *
- * @author Branislav Stojkovic
- */
-public class ProjectDrawingProvider implements IDrawingProvider {
-
- private IPlugInPort plugInPort;
- private boolean useZoom;
- private boolean showGridWhenNeeded;
-
- public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom,
- boolean showGridWhenNeeded) {
- super();
- this.plugInPort = plugInPort;
- this.useZoom = useZoom;
- this.showGridWhenNeeded = showGridWhenNeeded;
- }
-
- @Override
- public void draw(Graphics g) {
- EnumSet drawOptions = EnumSet.of(DrawOption.ANTIALIASING);
- if (useZoom) {
- drawOptions.add(DrawOption.ZOOM);
- }
- if (showGridWhenNeeded
- && ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXPORT_GRID_KEY,
- false)) {
- drawOptions.add(DrawOption.GRID);
- }
- if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
- drawOptions.add(DrawOption.OUTLINE_MODE);
- }
- plugInPort.draw((Graphics2D) g, drawOptions, null);
- }
-
- @Override
- public Dimension getSize() {
- return plugInPort.getCanvasDimensions(useZoom);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectPreview.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectPreview.java
deleted file mode 100644
index d5476264..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/ProjectPreview.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.swing.JComponent;
-import javax.swing.JFileChooser;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.diylc.common.DrawOption;
-import org.diylc.common.IPlugInPort;
-import org.diylc.common.PropertyWrapper;
-import org.diylc.core.IView;
-import org.diylc.core.Project;
-import org.diylc.presenter.Presenter;
-
-import com.diyfever.gui.IFileChooserAccessory;
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
-/**
- * {@link JComponent} that shows preview of the selected project in
- * {@link JFileChooser}. It's hooked onto {@link JFileChooser} as
- * {@link PropertyChangeListener} and refreshes when file is selected.
- *
- * @author Branislav Stojkovic
- */
-public class ProjectPreview extends JPanel implements PropertyChangeListener, IFileChooserAccessory {
-
- private static final long serialVersionUID = 1L;
-
- private IPlugInPort presenter;
- private XStream xStream;
- private Project emptyProject;
- private RenderComponent renderComponent;
- private JLabel nameLabel;
-
- public ProjectPreview() {
- super();
-
- setPreferredSize(new Dimension(140, 128));
- presenter = new Presenter(new IView() {
-
- @Override
- public int showConfirmDialog(String message, String title, int optionType,
- int messageType) {
- return 0;
- }
-
- @Override
- public void showMessage(String message, String title, int messageType) {
- }
-
- @Override
- public boolean editProperties(List properties, Set defaultedProperties) {
- return false;
- }
- });
- xStream = new XStream(new DomDriver());
-
- emptyProject = new Project();
- emptyProject.setTitle("");
-
- renderComponent = new RenderComponent();
- nameLabel = new JLabel();
-
- // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
- add(renderComponent);
- add(nameLabel);
- }
-
- // PropertyChangeListener
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- boolean update = false;
- String prop = evt.getPropertyName();
-
- Project selectedProject = emptyProject;
- if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
- update = true;
- } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
- File selectedFile = (File) evt.getNewValue();
- try {
- FileInputStream in = new FileInputStream(selectedFile);
- selectedProject = (Project) xStream.fromXML(in);
- in.close();
- } catch (Exception e) {
- }
- update = true;
- }
-
- nameLabel.setText(selectedProject.getTitle());
- presenter.loadProject(selectedProject, true);
-
- if (update) {
- if (renderComponent.isShowing()) {
- renderComponent.repaint();
- }
- }
- }
-
- class RenderComponent extends JComponent {
-
- private static final long serialVersionUID = 1L;
-
- public RenderComponent() {
- setPreferredSize(new Dimension(128, 96));
- // setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
- }
-
- @Override
- public void paint(Graphics g) {
- super.paint(g);
-
- Graphics2D g2d = (Graphics2D) g;
- Dimension d = presenter.getCanvasDimensions(false);
- // System.out.println(d);
- Rectangle rect = getBounds();
- // System.out.println(rect);
-
- double projectRatio = d.getWidth() / d.getHeight();
- double actualRatio = rect.getWidth() / rect.getHeight();
- double zoomRatio;
- if (projectRatio > actualRatio) {
- zoomRatio = rect.getWidth() / d.getWidth();
- } else {
- zoomRatio = rect.getHeight() / d.getHeight();
- }
- // d.setSize(d.getWidth() * zoomRatio, d.getHeight() * zoomRatio);
- // int x = (int) (rect.getWidth() - d.getWidth() * zoomRatio) / 2;
- // int y = (int) (rect.getHeight() - d.getHeight() * zoomRatio) / 2;
-
- // System.out.println(x + "," + y);
-
- // g2d.translate(x, y);
- g2d.scale(zoomRatio, zoomRatio);
- presenter.draw(g2d, EnumSet.noneOf(DrawOption.class), null);
-
- g2d.setColor(Color.black);
- g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio));
- }
- }
-
- // IFileChooserAccessory
-
- @Override
- public void install(JFileChooser fileChooser) {
- fileChooser.setAccessory(this);
- fileChooser.addPropertyChangeListener(this);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/TraceMaskDrawingProvider.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/TraceMaskDrawingProvider.java
deleted file mode 100644
index 06cb6aae..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/file/TraceMaskDrawingProvider.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.diylc.swing.plugins.file;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.util.EnumSet;
-
-import org.diylc.common.DrawOption;
-import org.diylc.common.IComponentFiler;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.IDIYComponent;
-import org.diylc.presenter.ComponentZOrderFiler;
-
-import com.diyfever.gui.IDrawingProvider;
-
-/**
- * {@link IDrawingProvider} implementation that uses {@link IPlugInPort} to draw
- * a project onto the canvas.
- *
- * @author Branislav Stojkovic
- */
-public class TraceMaskDrawingProvider implements IDrawingProvider {
-
- private IPlugInPort plugInPort;
- private IComponentFiler filter;
-
- public TraceMaskDrawingProvider(IPlugInPort plugInPort) {
- super();
- this.plugInPort = plugInPort;
- this.filter = new ComponentZOrderFiler(IDIYComponent.TRACE);
- }
-
- @Override
- public void draw(Graphics g) {
- plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ANTIALIASING),
- this.filter);
- }
-
- @Override
- public Dimension getSize() {
- return plugInPort.getCanvasDimensions(false);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/help/HelpMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/help/HelpMenuPlugin.java
deleted file mode 100644
index 3fb764c9..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/help/HelpMenuPlugin.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package org.diylc.swing.plugins.help;
-
-import java.awt.event.ActionEvent;
-import java.util.EnumSet;
-
-import javax.swing.AbstractAction;
-import javax.swing.Icon;
-import javax.swing.JOptionPane;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.ISwingUI;
-import org.diylc.swing.gui.DialogFactory;
-
-import com.diyfever.gui.AboutDialog;
-import com.diyfever.gui.LinkLabel;
-import com.diyfever.gui.miscutils.Utils;
-
-/**
- * Entry point class for help-related utilities.
- *
- * @author Branislav Stojkovic
- */
-public class HelpMenuPlugin implements IPlugIn {
-
- private static final String HELP_TITLE = "Help";
-
- public static String MANUAL_URL = "http://code.google.com/p/diy-layout-creator/wiki/Manual";
- public static String FAQ_URL = "http://code.google.com/p/diy-layout-creator/wiki/FAQ";
- public static String COMPONENT_URL = "http://code.google.com/p/diy-layout-creator/wiki/ComponentAPI";
- public static String PLUGIN_URL = "http://code.google.com/p/diy-layout-creator/wiki/PluginAPI";
- public static String BUG_URL = "http://code.google.com/p/diy-layout-creator/issues/entry";
- public static String DONATE_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=25161";
-
- private IPlugInPort plugInPort;
- private AboutDialog aboutDialog;
-
- public HelpMenuPlugin(ISwingUI swingUI) {
- swingUI.injectMenuAction(new NavigateURLAction("User Manual", IconLoader.Manual.getIcon(),
- MANUAL_URL), HELP_TITLE);
- swingUI.injectMenuAction(new NavigateURLAction("FAQ", IconLoader.Faq.getIcon(), FAQ_URL),
- HELP_TITLE);
- swingUI.injectMenuAction(new NavigateURLAction("Component API", IconLoader.Component
- .getIcon(), COMPONENT_URL), HELP_TITLE);
- swingUI.injectMenuAction(new NavigateURLAction("Plugin API", IconLoader.Plugin.getIcon(),
- PLUGIN_URL), HELP_TITLE);
- swingUI.injectMenuAction(new NavigateURLAction("Submit a Bug", IconLoader.Bug.getIcon(),
- BUG_URL), HELP_TITLE);
- swingUI.injectMenuAction(null, HELP_TITLE);
- swingUI.injectMenuAction(new NavigateURLAction("Donate", IconLoader.Donate.getIcon(),
- DONATE_URL), HELP_TITLE);
- swingUI.injectMenuAction(new AboutAction(), HELP_TITLE);
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return null;
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- }
-
- private AboutDialog getAboutDialog() {
- if (aboutDialog == null) {
- aboutDialog = DialogFactory.getInstance().createAboutDialog("DIY Layout Creator",
- IconLoader.IconLarge.getIcon(),
- plugInPort.getCurrentVersionNumber().toString(), "Branislav Stojkovic",
- "diylc.org", "bancika@gmail.com", "");
- }
- return aboutDialog;
- }
-
- class AboutAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public AboutAction() {
- super();
- putValue(AbstractAction.NAME, "About");
- putValue(AbstractAction.SMALL_ICON, IconLoader.About.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- getAboutDialog().setVisible(true);
- }
- }
-
- class NavigateURLAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- private String url;
-
- public NavigateURLAction(String name, Icon icon, String url) {
- super();
- this.url = url;
- putValue(AbstractAction.NAME, name);
- putValue(AbstractAction.SMALL_ICON, icon);
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Utils.openURL(url);
- } catch (Exception e1) {
- Logger.getLogger(LinkLabel.class).error("Could not launch default browser", e1);
- }
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/layers/LayersMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/layers/LayersMenuPlugin.java
deleted file mode 100644
index bf9b314a..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/layers/LayersMenuPlugin.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.diylc.swing.plugins.layers;
-
-import java.awt.event.ActionEvent;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.IDIYComponent;
-import org.diylc.core.IView;
-import org.diylc.swing.ISwingUI;
-
-public class LayersMenuPlugin implements IPlugIn {
-
- private static final String LOCK_LAYERS_TITLE = "Lock Layers";
-
- private IPlugInPort plugInPort;
- private Map lockActionMap;
-
- public LayersMenuPlugin(ISwingUI swingUI) {
- lockActionMap = new HashMap();
- for (Layer layer : Layer.values()) {
- final int zOrder = layer.getZOrder();
- AbstractAction action = new AbstractAction(layer.getTitle()) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LayersMenuPlugin.this.plugInPort.setLayerLocked(zOrder,
- (Boolean) getValue(Action.SELECTED_KEY));
- }
- };
- action.putValue(IView.CHECK_BOX_MENU_ITEM, true);
- lockActionMap.put(layer, action);
- swingUI.injectMenuAction(action, LOCK_LAYERS_TITLE);
- }
- }
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return EnumSet.of(EventType.LAYER_STATE_CHANGED);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public void processMessage(EventType eventType, Object... params) {
- if (eventType == EventType.LAYER_STATE_CHANGED) {
- Set lockedLayers = (Set) params[0];
- for (Layer layer : Layer.values()) {
- lockActionMap.get(layer).putValue(Action.SELECTED_KEY,
- lockedLayers.contains(layer.getZOrder()));
- }
- }
- }
-
- static enum Layer {
- CHASSIS("Chassis", IDIYComponent.CHASSIS), BOARD("Board", IDIYComponent.BOARD), TRACE(
- "Trace", IDIYComponent.TRACE), COMPONENT("Component", IDIYComponent.COMPONENT), TEXT(
- "Text", IDIYComponent.TEXT);
-
- String title;
- int zOrder;
-
- private Layer(String title, int order) {
- this.title = title;
- zOrder = order;
- }
-
- public String getTitle() {
- return title;
- }
-
- public int getZOrder() {
- return zOrder;
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/OnlineManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/OnlineManager.java
deleted file mode 100644
index cd988389..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/OnlineManager.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package org.diylc.swing.plugins.online;
-
-import java.awt.event.ActionEvent;
-import java.util.EnumSet;
-
-import javax.swing.AbstractAction;
-import javax.swing.SwingWorker;
-
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.images.IconLoader;
-import org.diylc.swing.gui.DialogFactory;
-import org.diylc.swing.plugins.online.presenter.LibraryPresenter;
-import org.diylc.swing.plugins.online.view.LoginDialog;
-import org.diylc.swing.plugins.online.view.NewUserDialog;
-import org.diylc.swing.plugins.online.view.UploadDialog;
-
-import com.diyfever.gui.ProgressDialog;
-
-public class OnlineManager implements IPlugIn {
-
- private static final String ONLINE_TITLE = "Online";
-
- private IPlugInPort plugInPort;
- private LibraryPresenter libraryPresenter;
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
- this.libraryPresenter = new LibraryPresenter();
-
- initialize();
-
-// plugInPort.injectMenuAction(new LibraryAction(), ONLINE_TITLE);
-// plugInPort.injectMenuAction(null, ONLINE_TITLE);
-// plugInPort.injectMenuAction(new LoginAction(), ONLINE_TITLE);
-// plugInPort.injectMenuAction(new CreateAccountAction(), ONLINE_TITLE);
-// plugInPort.injectMenuAction(null, ONLINE_TITLE);
-// plugInPort.injectMenuAction(new UploadAction(), ONLINE_TITLE);
-// plugInPort.injectMenuAction(new ManageProjectsAction(), ONLINE_TITLE);
- }
-
- private void initialize() {
- SwingWorker worker = new SwingWorker() {
-
- @Override
- protected Void doInBackground() throws Exception {
- libraryPresenter.connectDb();
- return null;
- }
-
- @Override
- protected void done() {
- if (libraryPresenter.isLoggedIn()) {
-
- }
- }
- };
- worker.execute();
- }
-
- @Override
- public EnumSet getSubscribedEventTypes() {
- return null;
- }
-
- @Override
- public void processMessage(EventType eventType, Object... params) {
- }
-
- class LibraryAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public LibraryAction() {
- super();
- putValue(AbstractAction.NAME, "Browse Library");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Chest.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- }
-
- class LoginAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public LoginAction() {
- super();
- putValue(AbstractAction.NAME, "Log in");
- putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- LoginDialog dialog = DialogFactory.getInstance().createLoginDialog();
- dialog.setVisible(true);
- }
- }
-
- class CreateAccountAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public CreateAccountAction() {
- super();
- putValue(AbstractAction.NAME, "Create New Account");
- putValue(AbstractAction.SMALL_ICON, IconLoader.IdCardAdd.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog();
- dialog.setVisible(true);
- }
- }
-
- class UploadAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public UploadAction() {
- super();
- putValue(AbstractAction.NAME, "Upload Project");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Upload.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- UploadDialog dialog = DialogFactory.getInstance().createUploadDialog();
- dialog.setVisible(true);
- }
- }
-
- class ManageProjectsAction extends AbstractAction {
-
- private static final long serialVersionUID = 1L;
-
- public ManageProjectsAction() {
- super();
- putValue(AbstractAction.NAME, "Manage Projects");
- putValue(AbstractAction.SMALL_ICON, IconLoader.Wrench.getIcon());
- }
-
- @Override
- public void actionPerformed(ActionEvent e) {
- ProgressDialog dialog = DialogFactory.getInstance().createProgressDialog("Test",
- new String[] {}, "Some text", false);
- dialog.setVisible(true);
- }
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/Test.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/Test.java
deleted file mode 100644
index aee1e52b..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/Test.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.diylc.swing.plugins.online;
-
-import org.apache.log4j.BasicConfigurator;
-import org.diylc.swing.plugins.online.presenter.LibraryPresenter;
-
-
-public class Test {
-
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- BasicConfigurator.configure();
- LibraryPresenter pres = new LibraryPresenter();
- // pres.createUser("bancika", "pwd", "bancika@gmail.com");
- System.out.println(pres.fetchCategories());
- pres.login("bancika", "pwd");
- int id = pres.fetchMyProjectRows().get(0).getId();
- // InputStream stream = pres.downloadProjectContent(id);
- // byte[] buf = new byte[100];
- // int len = stream.read(buf);
- System.out.println(pres.downloadProjectContent(id));
- // System.out.println(pres.hashPassword("bancikabancikabancikabancikabancika"));
- pres.dispose();
- }
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/model/ProjectEntity.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/model/ProjectEntity.java
deleted file mode 100644
index 228307fa..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/model/ProjectEntity.java
+++ /dev/null
@@ -1,136 +0,0 @@
-package org.diylc.swing.plugins.online.model;
-
-import java.awt.event.ActionEvent;
-import java.io.Serializable;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.JOptionPane;
-
-public class ProjectEntity implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private int id;
- private String name;
- private String description;
- private String owner;
- private String category;
-
- public ProjectEntity() {
- super();
- }
-
- public ProjectEntity(int id, String name, String description, String owner, String category) {
- super();
- this.id = id;
- this.name = name;
- this.description = description;
- this.owner = owner;
- this.category = category;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.owner = owner;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public Action getDownload() {
-
- Action a = new AbstractAction() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(null, name);
- }
- };
- a.putValue(AbstractAction.NAME, "Download");
- return a;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((category == null) ? 0 : category.hashCode());
- result = prime * result + ((description == null) ? 0 : description.hashCode());
- result = prime * result + id;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((owner == null) ? 0 : owner.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ProjectEntity other = (ProjectEntity) obj;
- if (category == null) {
- if (other.category != null)
- return false;
- } else if (!category.equals(other.category))
- return false;
- if (description == null) {
- if (other.description != null)
- return false;
- } else if (!description.equals(other.description))
- return false;
- if (id != other.id)
- return false;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (owner == null) {
- if (other.owner != null)
- return false;
- } else if (!owner.equals(other.owner))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return name;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/AlreadyExistsException.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/AlreadyExistsException.java
deleted file mode 100644
index 412fabea..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/AlreadyExistsException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-public class AlreadyExistsException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java
deleted file mode 100644
index e6acd8a4..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.diylc.swing.plugins.online.model.ProjectEntity;
-
-
-public class LibraryPresenter {
-
- private final static Logger LOG = Logger.getLogger(LibraryPresenter.class);
-
- private static final String DB_HOST = "diy-fever.com";
- private static final String DB_PORT = "3306";
- private static final String DB_USER = "diylc-app";
- private static final String DB_PASS = "zuf7RuS8";
-
- private static final String CATEGORY_SQL = "SELECT * FROM diylc.category WHERE 1=1";
- private static final String USER_SQL = "SELECT * FROM diylc.user WHERE name = \"%s\"";
- private static final String CREATE_USER_SQL = "INSERT INTO diylc.user (name, password, email) VALUES (\"%s\", \"%s\", \"%s\")";
- private static final String MY_PROJECTS_SQL = "SELECT project_id, name, category_id, description FROM diylc.project WHERE owner_user_id = %s";
- private static final String PROJECT_SQL = "SELECT content FROM diylc.project WHERE project_id = %s";
- private static final String UPLOAD_PROJECT_SQL = "INSERT INTO diylc.project (name, description, content, category_id, owner_user_id) VALUES (\"%s\", \"%s\", \"%s\", %s, %s)";
- private static final String UPDATE_PROJECT_SQL = "UPDATE diylc.project SET name = \"%s\", description = \"%s\", content = \"%s\", category_id = %s WHERE project_id = %s";
-
- private MySqlDBManager dbManager;
- private MessageDigest messageDigest;
- private Integer currentUserId;
-
- public LibraryPresenter() {
- dbManager = new MySqlDBManager(DB_HOST, DB_PORT, DB_USER, DB_PASS);
- try {
- messageDigest = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- LOG.error("Could not initialize MD5, algorithm not found.");
- }
- }
-
- public boolean connectDb() {
- try {
- dbManager.connectDB();
- return true;
- } catch (Exception e) {
- LOG.error("Could not connect to the database: " + e.getMessage());
- return false;
- }
- }
-
- public void createUser(String userName, String password, String email) throws SQLException,
- NotConnectedException, AlreadyExistsException {
- LOG.info("Creating user: " + userName);
- if (dbManager.isConnected()) {
- ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
- if (resultSet.next()) {
- throw new AlreadyExistsException();
- }
- dbManager.updateDB(String.format(CREATE_USER_SQL, userName, hashPassword(password),
- email));
- resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
- if (resultSet.next()) {
- LOG.info("Logged in as \"" + userName + "\"");
- currentUserId = resultSet.getInt("user_id");
- }
- } else {
- LOG.error("Not connected");
- throw new NotConnectedException();
- }
- }
-
- public boolean login(String userName, String password) throws SQLException,
- NotConnectedException {
- LOG.info("Logging in as: " + userName);
- if (dbManager.isConnected()) {
- ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
- if (resultSet.next()) {
- String dbPassword = resultSet.getString("password");
- String hashPassword = hashPassword(password);
- if (dbPassword.equals(hashPassword)) {
- LOG.info("Logged in as \"" + userName + "\"");
- currentUserId = resultSet.getInt("user_id");
- } else {
- LOG.info("User name and password do not match.");
- }
- }
- return false;
- } else {
- LOG.error("Not connected");
- throw new NotConnectedException();
- }
- }
-
- public Map fetchCategories() throws SQLException, NotConnectedException {
- LOG.info("Fetching categories");
- if (dbManager.isConnected()) {
- Map categories = new HashMap();
- ResultSet resultSet = dbManager.getResultSet(CATEGORY_SQL);
- while (resultSet.next()) {
- categories.put(resultSet.getInt("category_id"), resultSet.getString("name"));
- }
- return categories;
- } else {
- LOG.error("Not connected");
- throw new NotConnectedException();
- }
- }
-
- public List fetchMyProjectRows() throws NotLoggedInException,
- NotConnectedException, SQLException {
- if (dbManager.isConnected()) {
- if (isLoggedIn()) {
- Map categories = fetchCategories();
- List projects = new ArrayList();
- ResultSet resultSet = dbManager.getResultSet(String.format(MY_PROJECTS_SQL,
- currentUserId));
- while (resultSet.next()) {
- projects.add(new ProjectEntity(resultSet.getInt("project_id"), resultSet
- .getString("name"), resultSet.getString("description"), "", categories
- .get(resultSet.getInt("category_id"))));
- }
- return projects;
- } else {
- LOG.error("Not logged in");
- throw new NotLoggedInException();
- }
- } else {
- LOG.error("Not connected");
- throw new NotConnectedException();
- }
- }
-
- public String downloadProjectContent(int projectId) throws NotConnectedException,
- NotExistsException, SQLException {
- if (dbManager.isConnected()) {
- ResultSet resultSet = dbManager.getResultSet(String.format(PROJECT_SQL, projectId));
- if (resultSet.next()) {
- return resultSet.getString("content");
- }
- throw new NotExistsException("Project with id = " + projectId + " does not exist.");
- } else {
- LOG.error("Not connected");
- throw new NotConnectedException();
- }
- }
-
- public List fetchProjectRows(String searchCriteria) {
- return null;
- }
-
- public boolean isLoggedIn() {
- return currentUserId != null;
- }
-
- public String hashPassword(String password) {
- messageDigest.reset();
- byte[] bytes = messageDigest.digest(password.getBytes());
- String md5 = "";
- for (byte b : bytes) {
- String str = Integer.toHexString(b);
- if (str.length() == 1) {
- str = "0" + str;
- }
- md5 += str.substring(str.length() - 2);
- }
- return md5;
- }
-
- public void dispose() {
- dbManager.closeConnection();
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/MySqlDBManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/MySqlDBManager.java
deleted file mode 100644
index 186ba407..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/MySqlDBManager.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.apache.log4j.Logger;
-
-public class MySqlDBManager {
-
- private final static Logger LOG = Logger.getLogger(MySqlDBManager.class);
-
- protected Connection connection;
- protected Statement statement;
- protected ResultSet resultSet;
- protected String url;
- protected String user;
- protected String pass;
- protected boolean connected;
-
- public MySqlDBManager(String url, String user, String pass) {
- this.url = url;
- this.user = user;
- this.pass = pass;
- this.connected = false;
- }
-
- public MySqlDBManager(String host, String port, String userName, String password) {
- this(String.format("jdbc:mysql://%s%s", host, port.trim().equals("") ? "" : (":" + port)),
- userName, password);
- }
-
- public void connectDB() throws Exception {
- if (!connected) {
- Driver driver = (Driver) Class.forName("com.mysql.jdbc.Driver").newInstance();
- DriverManager.registerDriver(driver);
- String finalUrl = String.format("%s?user=%s&password=%s", url, user, pass);
- LOG.info("Trying to connect to: " + url);
- connection = DriverManager.getConnection(finalUrl);
- statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- connected = true;
- }
- }
-
- public boolean isConnected() {
- return connected;
- }
-
- public void closeConnection() {
- LOG.info("Closing connection.");
- try {
- if (resultSet != null) {
- resultSet.close();
- }
- if (statement != null) {
- statement.close();
- }
- if (connection != null) {
- connection.close();
- }
- connected = false;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- public ResultSet getResultSet(String query) throws SQLException {
- LOG.info("Executing query: " + query);
- resultSet = statement.executeQuery(query);
- return resultSet;
- }
-
- public Connection getConnection() {
- return connection;
- }
-
- public int updateDB(String query) throws SQLException {
- LOG.info("Executing query: " + query);
- statement.execute(query);
- return statement.getUpdateCount();
- }
-}
\ No newline at end of file
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java
deleted file mode 100644
index 4752625e..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-public class NotConnectedException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java
deleted file mode 100644
index 169dcc37..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-public class NotExistsException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- public NotExistsException(String message) {
- super(message);
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java
deleted file mode 100644
index aba9b870..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.diylc.swing.plugins.online.presenter;
-
-public class NotLoggedInException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LibraryFrame.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LibraryFrame.java
deleted file mode 100644
index 89f2b839..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LibraryFrame.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.diylc.swing.plugins.online.view;
-
-import javax.swing.JFrame;
-
-public class LibraryFrame extends JFrame {
-
- private static final long serialVersionUID = 1L;
-
- public LibraryFrame() {
- super("Online Library");
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LoginDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LoginDialog.java
deleted file mode 100644
index 12c56f1a..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/LoginDialog.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package org.diylc.swing.plugins.online.view;
-
-import java.awt.Dimension;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JPasswordField;
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import com.diyfever.gui.ButtonDialog;
-
-public class LoginDialog extends ButtonDialog {
-
- private static final long serialVersionUID = 1L;
-
- private JPanel mainPanel;
-
- private JTextField userNameField;
- private JPasswordField passwordField;
-
- private String userName;
- private String password;
-
- public LoginDialog(JFrame owner) {
- super(owner, "Login", new String[] { OK, CANCEL });
- setMinimumSize(new Dimension(240, 32));
- layoutGui();
- refreshState();
- }
-
- public String getUserName() {
- return userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- @Override
- protected JComponent getMainComponent() {
- if (mainPanel == null) {
- mainPanel = new JPanel(new GridBagLayout());
- mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
-
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.anchor = GridBagConstraints.LINE_START;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(2, 2, 2, 2);
-
- gbc.gridx = 0;
-
- gbc.gridy = 0;
- mainPanel.add(new JLabel("User Name:"), gbc);
-
- gbc.gridy = 1;
- mainPanel.add(new JLabel("Password:"), gbc);
-
- gbc.gridx = 1;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1;
-
- gbc.gridy = 0;
- mainPanel.add(getUserNameField(), gbc);
-
- gbc.gridy = 1;
- mainPanel.add(getPasswordField(), gbc);
- }
- return mainPanel;
- }
-
- private void refreshState() {
- this.userName = getUserNameField().getText();
- this.password = new String(getPasswordField().getPassword());
-
- JButton okButton = getButton(OK);
- okButton.setEnabled((this.userName.length() > 0) && (this.password.length() > 0));
- }
-
- private JTextField getUserNameField() {
- if (userNameField == null) {
- userNameField = new JTextField();
- userNameField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return userNameField;
- }
-
- private JPasswordField getPasswordField() {
- if (passwordField == null) {
- passwordField = new JPasswordField();
- passwordField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return passwordField;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/NewUserDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/NewUserDialog.java
deleted file mode 100644
index 1f914071..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/NewUserDialog.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package org.diylc.swing.plugins.online.view;
-
-import java.awt.Dimension;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JPasswordField;
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-
-import com.diyfever.gui.ButtonDialog;
-
-public class NewUserDialog extends ButtonDialog {
-
- private static final long serialVersionUID = 1L;
-
- private JPanel mainPanel;
-
- private JTextField userNameField;
- private JPasswordField passwordField;
- private JPasswordField confirmPasswordField;
- private JTextField emailField;
-
- private String userName;
- private String password;
- private String email;
-
- public NewUserDialog(JFrame owner) {
- super(owner, "New Account", new String[] { OK, CANCEL });
- setMinimumSize(new Dimension(240, 32));
- layoutGui();
- refreshState();
- userNameField.setText(System.getProperty("user.name"));
- }
-
- public String getUserName() {
- return userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getEmail() {
- return email;
- }
-
- @Override
- protected JComponent getMainComponent() {
- if (mainPanel == null) {
- mainPanel = new JPanel(new GridBagLayout());
- mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
-
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.anchor = GridBagConstraints.LINE_START;
- gbc.fill = GridBagConstraints.NONE;
- gbc.insets = new Insets(2, 2, 2, 2);
-
- gbc.gridx = 0;
-
- gbc.gridy = 0;
- mainPanel.add(new JLabel("User Name:"), gbc);
-
- gbc.gridy = 1;
- mainPanel.add(new JLabel("Password:"), gbc);
-
- gbc.gridy = 2;
- mainPanel.add(new JLabel("Confirm Password:"), gbc);
-
- gbc.gridy = 3;
- mainPanel.add(new JLabel("eMail:"), gbc);
-
- gbc.gridx = 1;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1;
-
- gbc.gridy = 0;
- mainPanel.add(getUserNameField(), gbc);
-
- gbc.gridy = 1;
- mainPanel.add(getPasswordField(), gbc);
-
- gbc.gridy = 2;
- mainPanel.add(getConfirmPasswordField(), gbc);
-
- gbc.gridy = 3;
- mainPanel.add(getEmailField(), gbc);
- }
- return mainPanel;
- }
-
- private void refreshState() {
- this.userName = getUserNameField().getText();
- String password = new String(getPasswordField().getPassword());
- String confirmPassword = new String(getConfirmPasswordField().getPassword());
- if (password.equals(confirmPassword)) {
- this.password = password;
- } else {
- this.password = null;
- }
- this.email = getEmailField().getText();
- JButton okButton = getButton(OK);
- okButton.setEnabled((this.userName.length() > 0) && (this.password != null)
- && (this.password.length() > 0));
- }
-
- private JTextField getUserNameField() {
- if (userNameField == null) {
- userNameField = new JTextField();
- userNameField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return userNameField;
- }
-
- private JPasswordField getPasswordField() {
- if (passwordField == null) {
- passwordField = new JPasswordField();
- passwordField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return passwordField;
- }
-
- private JPasswordField getConfirmPasswordField() {
- if (confirmPasswordField == null) {
- confirmPasswordField = new JPasswordField();
- confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return confirmPasswordField;
- }
-
- private JTextField getEmailField() {
- if (emailField == null) {
- emailField = new JTextField();
- emailField.getDocument().addDocumentListener(new DocumentListener() {
-
- @Override
- public void removeUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void insertUpdate(DocumentEvent e) {
- refreshState();
- }
-
- @Override
- public void changedUpdate(DocumentEvent e) {
- refreshState();
- }
- });
- }
- return emailField;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/UploadDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/UploadDialog.java
deleted file mode 100644
index 5c1249c2..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/online/view/UploadDialog.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.diylc.swing.plugins.online.view;
-
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
-
-import javax.swing.BorderFactory;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.UIManager;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import com.diyfever.gui.ButtonDialog;
-
-public class UploadDialog extends ButtonDialog {
-
- private static final long serialVersionUID = 1L;
-
- private static final String BULLET = " • ";
- private static final String TERMS_HTML = "Terms of Service
"
- + BULLET
- + "Online Library is provided free of charge for DIY Layout Creator users.
"
- + BULLET
- + "Only finished and verified projects may be uploaded to the library. Online Library is not a repository for unfinished projects and temprary work.
"
- + BULLET
- + "Projects uploaded to the library may be reviewed, modified or deleted by the administrator without notice.
"
- + BULLET
- + "Once uploaded, project becomes avaialble to all other users. Anyone may use the project, modify it and upload modified version. When modifying an existing projects credit for the original author must be left.
"
- + BULLET
- + "You can not use Online Library to advertise products or services.
"
- + BULLET
- + "Users that do not follow these terms may be banned from the server, with or without notice.
"
- + BULLET + "Administrator is not responsible for library contents.
" + "";
-
- private JPanel mainPanel;
- private JLabel termsLabel;
- private JCheckBox agreeBox;
-
- public UploadDialog(JFrame owner) {
- super(owner, "Upload", new String[] { OK, CANCEL });
- layoutGui();
- refreshState();
- }
-
- @Override
- protected JComponent getMainComponent() {
- if (mainPanel == null) {
- mainPanel = new JPanel(new GridBagLayout());
- mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
-
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.anchor = GridBagConstraints.LINE_START;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.weightx = 1;
- gbc.weighty = 1;
- gbc.insets = new Insets(2, 2, 2, 2);
-
- gbc.gridx = 0;
- gbc.gridy = 0;
- mainPanel.add(getTermsLabel(), gbc);
-
- gbc.gridy = 1;
- gbc.anchor = GridBagConstraints.CENTER;
- gbc.fill = GridBagConstraints.NONE;
- gbc.weightx = 0;
- gbc.weighty = 0;
- mainPanel.add(getAgreeBox(), gbc);
- }
- return mainPanel;
- }
-
- private void refreshState() {
- getButton(OK).setEnabled(getAgreeBox().isSelected());
- }
-
- private JCheckBox getAgreeBox() {
- if (agreeBox == null) {
- agreeBox = new JCheckBox("I agree to these terms");
- agreeBox.addChangeListener(new ChangeListener() {
-
- @Override
- public void stateChanged(ChangeEvent e) {
- refreshState();
- }
- });
- }
- return agreeBox;
- }
-
- private JLabel getTermsLabel() {
- if (termsLabel == null) {
- termsLabel = new JLabel();
- termsLabel.setOpaque(true);
- termsLabel.setBackground(UIManager.getColor("ToolTip.background"));
- termsLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
- .createEtchedBorder(), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
- termsLabel.setText(TERMS_HTML);
- }
- return termsLabel;
- }
-}
diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java
deleted file mode 100644
index c2ac05e4..00000000
--- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/swing/plugins/statusbar/StatusBar.java
+++ /dev/null
@@ -1,301 +0,0 @@
-package org.diylc.swing.plugins.statusbar;
-
-import java.awt.BorderLayout;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Point;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Point2D;
-import java.text.DecimalFormat;
-import java.text.Format;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.BorderFactory;
-import javax.swing.JComboBox;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.SwingUtilities;
-
-import org.apache.log4j.Logger;
-import org.diylc.common.BadPositionException;
-import org.diylc.common.ComponentType;
-import org.diylc.common.EventType;
-import org.diylc.common.IPlugIn;
-import org.diylc.common.IPlugInPort;
-import org.diylc.core.IDIYComponent;
-import org.diylc.images.IconLoader;
-import org.diylc.presenter.Presenter;
-import org.diylc.swing.ISwingUI;
-
-import com.diyfever.gui.MemoryBar;
-import com.diyfever.gui.miscutils.ConfigurationManager;
-import com.diyfever.gui.miscutils.PercentageListCellRenderer;
-import com.diyfever.gui.miscutils.Utils;
-import com.diyfever.gui.update.UpdateLabel;
-
-public class StatusBar extends JPanel implements IPlugIn {
-
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = Logger.getLogger(StatusBar.class);
-
- public static String UPDATE_URL = "http://www.diy-fever.com/update.xml";
- private static final Format sizeFormat = new DecimalFormat("0.##");
-
- private JComboBox zoomBox;
- private UpdateLabel updateLabel;
- private MemoryBar memoryPanel;
- private JLabel statusLabel;
- private JLabel sizeLabel;
-
- private IPlugInPort plugInPort;
-
- // State variables
- private ComponentType componentSlot;
- private Point controlPointSlot;
- private List componentNamesUnderCursor;
- private List selectedComponentNames;
- private List stuckComponentNames;
- private String statusMessage;
-
- public StatusBar(ISwingUI swingUI) {
- super();
-
- setLayout(new GridBagLayout());
-
- try {
- swingUI.injectGUIComponent(this, SwingUtilities.BOTTOM);
- } catch (BadPositionException e) {
- LOG.error("Could not install status bar", e);
- }
- }
-
- private JComboBox getZoomBox() {
- if (zoomBox == null) {
- zoomBox = new JComboBox(plugInPort.getAvailableZoomLevels());
- zoomBox.setSelectedItem(plugInPort.getZoomLevel());
- zoomBox.setFocusable(false);
- zoomBox.setRenderer(new PercentageListCellRenderer());
- zoomBox.addActionListener(new ActionListener() {
-
- @Override
- public void actionPerformed(ActionEvent e) {
- plugInPort.setZoomLevel((Double) zoomBox.getSelectedItem());
- }
- });
- }
- return zoomBox;
- }
-
- private UpdateLabel getUpdateLabel() {
- if (updateLabel == null) {
- updateLabel = new UpdateLabel(plugInPort.getCurrentVersionNumber(), UPDATE_URL);
- // updateLabel.setBorder(BorderFactory.createCompoundBorder(
- // BorderFactory.createEtchedBorder(), BorderFactory
- // .createEmptyBorder(2, 4, 2, 4)));
- updateLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
- }
- return updateLabel;
- }
-
- private MemoryBar getMemoryPanel() {
- if (memoryPanel == null) {
- memoryPanel = new MemoryBar(false);
- }
- return memoryPanel;
- }
-
- private JLabel getStatusLabel() {
- if (statusLabel == null) {
- statusLabel = new JLabel();
- statusLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
- }
- return statusLabel;
- }
-
- public JLabel getSizeLabel() {
- if (sizeLabel == null) {
- sizeLabel = new JLabel(IconLoader.Size.getIcon());
- sizeLabel.setFocusable(true);
- sizeLabel.setToolTipText("Click to calculate selection size");
- sizeLabel.addMouseListener(new MouseAdapter() {
-
- @Override
- public void mouseClicked(MouseEvent e) {
- Point2D size = plugInPort.calculateSelectionDimension();
- boolean metric = ConfigurationManager.getInstance().readBoolean(
- Presenter.METRIC_KEY, true);
- String text;
- if (size == null) {
- text = "Selection is empty.";
- } else {
- text = "Selection size: " + sizeFormat.format(size.getX()) + " x "
- + sizeFormat.format(size.getY()) + (metric ? " cm" : " in");
- }
- JOptionPane.showMessageDialog(SwingUtilities.getRootPane(StatusBar.this), text,
- "Information", JOptionPane.INFORMATION_MESSAGE);
- }
- });
- }
- return sizeLabel;
- }
-
- private void layoutComponents() {
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.fill = GridBagConstraints.HORIZONTAL;
- gbc.weightx = 1;
- add(getStatusLabel(), gbc);
-
- JPanel zoomPanel = new JPanel(new BorderLayout());
- zoomPanel.add(new JLabel("Zoom: "), BorderLayout.WEST);
- zoomPanel.add(getZoomBox(), BorderLayout.CENTER);
- // zoomPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
- // .createEtchedBorder(), BorderFactory.createEmptyBorder(2, 4, 2,
- // 4)));
- zoomPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
-
- gbc.gridx = 1;
- gbc.fill = GridBagConstraints.BOTH;
- gbc.weightx = 0;
- add(zoomPanel, gbc);
-
- gbc.gridx = 2;
- add(getSizeLabel(), gbc);
-
- gbc.gridx = 3;
- add(getUpdateLabel(), gbc);
-
- gbc.gridx = 4;
- gbc.fill = GridBagConstraints.NONE;
- add(getMemoryPanel(), gbc);
-
- gbc.gridx = 5;
- add(new JPanel(), gbc);
- }
-
- // IPlugIn
-
- @Override
- public void connect(IPlugInPort plugInPort) {
- this.plugInPort = plugInPort;
-
- layoutComponents();
- }
-
- @Override
- public EnumSet