mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 01:02:08 +10:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e2f42eaaa |
+2
-1
@@ -9,9 +9,10 @@
|
||||
<classpathentry kind="lib" path="lib/iText-2.1.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/cloning-1.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/objenesis-1.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
|
||||
<classpathentry kind="lib" path="lib/HttpProxy.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/>
|
||||
<classpathentry kind="lib" path="library/main.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;Library&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;DIYLC&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.DIYLCStarter"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="DIYLC"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx512m"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms64m -Xmx256m"/>
|
||||
</launchConfiguration>
|
||||
|
||||
+3
-65
@@ -1,76 +1,14 @@
|
||||
<map>
|
||||
<entry>
|
||||
<string>default.org.diylc.components.passive.TrimmerPotentiometer:Type</string>
|
||||
<org.diylc.components.passive.TrimmerPotentiometer_-TrimmerType>FLAT_LARGE</org.diylc.components.passive.TrimmerPotentiometer_-TrimmerType>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>lastPath</string>
|
||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>abnormalExit</string>
|
||||
<boolean>false</boolean>
|
||||
<string>zoom</string>
|
||||
<double>1.0</double>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>stickyPoints</string>
|
||||
<string>metric</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>theme</string>
|
||||
<org.diylc.core.Theme>
|
||||
<name>Light</name>
|
||||
<bgColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bgColor>
|
||||
<gridColor>
|
||||
<red>240</red>
|
||||
<green>240</green>
|
||||
<blue>240</blue>
|
||||
<alpha>240</alpha>
|
||||
</gridColor>
|
||||
</org.diylc.core.Theme>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>antiAliasing</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>snapToGrid</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>hiQualityRender</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>exportGrid</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>autoEdit</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>wheelZoom</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>default.org.diylc.components.misc.Label:Font Bold</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>autoCreatePads</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>continuousCreation</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>showTemplatesAtStartup</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
</map>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,11 +8,9 @@ import javax.swing.UIManager;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.diylc.gui.MainFrame;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -40,8 +38,6 @@ public class DIYLCStarter {
|
||||
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 {
|
||||
@@ -53,16 +49,7 @@ public class DIYLCStarter {
|
||||
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 {
|
||||
@@ -72,5 +59,6 @@ public class DIYLCStarter {
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not read config.properties file", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+17
-8
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.edit;
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
@@ -10,24 +10,33 @@ 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.
|
||||
* 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<IDIYComponent<?>> implements Transferable {
|
||||
public class ComponentSelection extends ArrayList<IDIYComponent<?>> implements Transferable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final DataFlavor listFlavor = new DataFlavor(ComponentTransferable.class, "application/diylc");
|
||||
public static final DataFlavor listFlavor = new DataFlavor(List.class, "Java List");
|
||||
|
||||
public static final ComponentSelection EMPTY_SELECTION = new ComponentSelection();
|
||||
|
||||
public static ComponentSelection of(IDIYComponent<?> component) {
|
||||
ComponentSelection selection = new ComponentSelection();
|
||||
selection.add(component);
|
||||
return selection;
|
||||
}
|
||||
|
||||
public ComponentTransferable() {
|
||||
public ComponentSelection() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ComponentTransferable(Collection<IDIYComponent<?>> selectedComponents) {
|
||||
public ComponentSelection(Collection<IDIYComponent<?>> selectedComponents) {
|
||||
super(selectedComponents);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ public enum EventType {
|
||||
* object containing selection size (x = width, y = height). Size is
|
||||
* expressed in the default measure (cm for metric, inches for imperial).
|
||||
*/
|
||||
SELECTION_SIZE_CHANGED,
|
||||
/**
|
||||
* Called when display needs to be repainted. No parameters are passed.
|
||||
*/
|
||||
REPAINT,
|
||||
/**
|
||||
* Called when new component slot has been changed. The only parameter is
|
||||
@@ -72,12 +76,6 @@ public enum EventType {
|
||||
* current cursor location (not taking zoom into account).
|
||||
*/
|
||||
MOUSE_MOVED,
|
||||
/**
|
||||
* Called when a layer status is changed. The first parameter is a set of indices of locked layers. All layers not included are considered unlocked.
|
||||
*/
|
||||
LAYER_STATE_CHANGED,
|
||||
/**
|
||||
* Called to update the status message. New status message is passed as a first parameter.
|
||||
*/
|
||||
STATUS_MESSAGE_CHANGED;
|
||||
LAYER_STATE_CHANGED;
|
||||
;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ 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 javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JPopupMenu.Separator;
|
||||
|
||||
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;
|
||||
@@ -31,18 +34,8 @@ import com.diyfever.gui.update.VersionNumber;
|
||||
* @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 CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
|
||||
|
||||
/**
|
||||
* Returns size of the canvas that takes project dimensions into account as
|
||||
@@ -98,9 +91,8 @@ public interface IPlugInPort {
|
||||
* Saves the current project into the specified file.
|
||||
*
|
||||
* @param fileName
|
||||
* @param isBackup
|
||||
*/
|
||||
void saveProjectToFile(String fileName, boolean isBackup);
|
||||
void saveProjectToFile(String fileName);
|
||||
|
||||
/**
|
||||
* @return the current file name.
|
||||
@@ -140,6 +132,49 @@ public interface IPlugInPort {
|
||||
*/
|
||||
void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter);
|
||||
|
||||
/**
|
||||
* Injects a custom GUI panels provided by the plug-in and desired position
|
||||
* in the window. Application will layout plug-in panels accordingly. <br>
|
||||
* Valid positions are:
|
||||
* <ul>
|
||||
* <li> {@link SwingConstants#TOP}</li>
|
||||
* <li> {@link SwingConstants#BOTTOM}</li>
|
||||
* <li> {@link SwingConstants#LEFT}</li>
|
||||
* <li> {@link SwingConstants#RIGHT}</li>
|
||||
* </ul>
|
||||
*
|
||||
* 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
|
||||
* <code>action</code> 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
|
||||
* <code>action</code> 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);
|
||||
|
||||
Double[] getAvailableZoomLevels();
|
||||
|
||||
/**
|
||||
@@ -167,9 +202,8 @@ public interface IPlugInPort {
|
||||
* @param ctrlDown
|
||||
* @param shiftDown
|
||||
* @param altDown
|
||||
* @param clickCount
|
||||
*/
|
||||
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown, int clickCount);
|
||||
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
|
||||
|
||||
/**
|
||||
* Notifies the presenter that mouse is moved.
|
||||
@@ -184,11 +218,11 @@ public interface IPlugInPort {
|
||||
void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
|
||||
|
||||
/**
|
||||
* Returns the current {@link ComponentTransferable}.
|
||||
* Returns the current {@link ComponentSelection}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<IDIYComponent<?>> getSelectedComponents();
|
||||
ComponentSelection getSelectedComponents();
|
||||
|
||||
/**
|
||||
* Selects all components in the project.
|
||||
@@ -274,9 +308,15 @@ public interface IPlugInPort {
|
||||
*/
|
||||
List<PropertyWrapper> getMutualSelectionProperties();
|
||||
|
||||
|
||||
void editSelection();
|
||||
|
||||
/**
|
||||
* Applies specified properties to all the selected components. If some of
|
||||
* the properties are not applicable to some of the selected components an
|
||||
* exception will be thrown.
|
||||
*
|
||||
* @param properties
|
||||
*/
|
||||
void applyPropertiesToSelection(List<PropertyWrapper> properties);
|
||||
|
||||
/**
|
||||
* @return a list of editable properties of the current project.
|
||||
*/
|
||||
@@ -311,46 +351,6 @@ public interface IPlugInPort {
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package org.diylc.common;
|
||||
|
||||
/**
|
||||
* Abstract layer between the app and platform worker thread implementation.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface ITask<T> {
|
||||
|
||||
/**
|
||||
* Runs in background thread.
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
T doInBackground() throws Exception;
|
||||
|
||||
/**
|
||||
* Called if background thread fails.
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
void failed(Exception e);
|
||||
|
||||
/**
|
||||
* Called if background thread is executed correctly, the result is passed
|
||||
* as a parameter.
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void complete(T result);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum LabelPosition {
|
||||
|
||||
ABOVE, BELOW;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class ObjectCache {
|
||||
if (basicStrokeMap.containsKey(width)) {
|
||||
return basicStrokeMap.get(width);
|
||||
}
|
||||
Stroke stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
Stroke stroke = new BasicStroke(width);
|
||||
basicStrokeMap.put(width, stroke);
|
||||
return stroke;
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum OrientationHV {
|
||||
|
||||
VERTICAL, HORIZONTAL;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package org.diylc.common;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.diylc.core.IPropertyValidator;
|
||||
|
||||
/**
|
||||
* Entity class for editable properties extracted from component objects.
|
||||
* Represents a single editable property together with it's current value.
|
||||
@@ -19,21 +17,19 @@ public class PropertyWrapper implements Cloneable {
|
||||
private Method setter;
|
||||
private Method getter;
|
||||
private boolean defaultable;
|
||||
private IPropertyValidator validator;
|
||||
|
||||
public PropertyWrapper(String name, Class<?> type, Method getter, Method setter,
|
||||
boolean defaultable, IPropertyValidator validator) {
|
||||
boolean defaultable) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
this.defaultable = defaultable;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
public void readFrom(Object object) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException {
|
||||
this.value = getter.invoke(object);
|
||||
}
|
||||
|
||||
@@ -46,8 +42,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
// }
|
||||
// }
|
||||
|
||||
public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
public void writeTo(Object object) throws IllegalArgumentException,
|
||||
IllegalAccessException, InvocationTargetException {
|
||||
setter.invoke(object, value);
|
||||
}
|
||||
|
||||
@@ -71,8 +67,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
return defaultable;
|
||||
}
|
||||
|
||||
public IPropertyValidator getValidator() {
|
||||
return validator;
|
||||
public void setDefaultable(boolean defaultable) {
|
||||
this.defaultable = defaultable;
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum ResistorColorCode {
|
||||
|
||||
NONE, _4_BAND, _5_BAND;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (name().startsWith("_")) {
|
||||
return name().substring(1).replace("_", " ").toLowerCase();
|
||||
}
|
||||
return name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
@@ -20,11 +19,11 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
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);
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 12);
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
@Override
|
||||
@@ -37,11 +36,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
@@ -54,20 +48,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
* @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;
|
||||
protected int getClosestOdd(int x) {
|
||||
return (x / 2) * 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,12 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
public static Color GUIDELINE_COLOR = Color.blue;
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
protected Point[] controlPoints = new Point[] {
|
||||
new Point(0, 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE
|
||||
.convertToPixels())),
|
||||
new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels()) };
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0),
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0),
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, DEFAULT_SIZE.convertToPixels()),
|
||||
new Point(DEFAULT_SIZE.convertToPixels(), DEFAULT_SIZE.convertToPixels()) };
|
||||
|
||||
protected Color color = getDefaultColor();
|
||||
protected PointCount pointCount = PointCount.FOUR;
|
||||
|
||||
/**
|
||||
* Draws the specified curve onto graphics.
|
||||
@@ -40,7 +37,6 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
* @param curve
|
||||
* @param g2d
|
||||
* @param componentState
|
||||
* @param theme
|
||||
*/
|
||||
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d,
|
||||
ComponentState componentState);
|
||||
@@ -65,9 +61,6 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
||||
// Do not track guidelines.
|
||||
drawingObserver.stopTracking();
|
||||
@@ -100,133 +93,29 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Point Count")
|
||||
public PointCount getPointCount() {
|
||||
if (pointCount == null) {
|
||||
pointCount = PointCount.FOUR;
|
||||
}
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
public void setPointCount(PointCount pointCount) {
|
||||
this.pointCount = pointCount;
|
||||
// Reset control points.
|
||||
for (int i = 0; i < getControlPointCount(); i++) {
|
||||
setControlPoint(getControlPoint(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
return 2;
|
||||
case THREE:
|
||||
return 3;
|
||||
case FOUR:
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return index == 0 || index == getControlPointCount() - 1;
|
||||
return index == 0 || index == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
// Only shape control points may overlap.
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
return false;
|
||||
case THREE:
|
||||
return index == 1;
|
||||
case FOUR:
|
||||
return index == 1 || index == 2;
|
||||
}
|
||||
return false;
|
||||
return index == 0 || index == 3 ? VisibilityPolicy.ALWAYS : VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
if (index == 0) {
|
||||
return controlPoints[0];
|
||||
}
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[3];
|
||||
}
|
||||
case THREE:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[1];
|
||||
case 2:
|
||||
return controlPoints[3];
|
||||
}
|
||||
case FOUR:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[1];
|
||||
case 2:
|
||||
return controlPoints[2];
|
||||
case 3:
|
||||
return controlPoints[3];
|
||||
}
|
||||
}
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
if (index == 0) {
|
||||
controlPoints[0].setLocation(point);
|
||||
} else {
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
switch (index) {
|
||||
case 1:
|
||||
Point center = new Point((point.x + controlPoints[0].x) / 2,
|
||||
(point.y + controlPoints[0].y) / 2);
|
||||
controlPoints[1].setLocation(center);
|
||||
controlPoints[2].setLocation(center);
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case THREE:
|
||||
switch (index) {
|
||||
case 1:
|
||||
controlPoints[1].setLocation(point);
|
||||
controlPoints[2].setLocation(point);
|
||||
break;
|
||||
case 2:
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case FOUR:
|
||||
switch (index) {
|
||||
case 1:
|
||||
controlPoints[1].setLocation(point);
|
||||
break;
|
||||
case 2:
|
||||
controlPoints[2].setLocation(point);
|
||||
break;
|
||||
case 3:
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
controlPoints[index].setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -238,12 +127,4 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
enum PointCount {
|
||||
TWO, THREE, FOUR;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ 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;
|
||||
@@ -37,21 +35,21 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
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 Size height;
|
||||
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;
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) };
|
||||
protected Color bodyColor = getDefaultBodyColor();
|
||||
protected Color borderColor = getDefaultBorderColor();
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
|
||||
protected AbstractLeadedComponent() {
|
||||
super();
|
||||
try {
|
||||
this.length = getDefaultLength().clone();
|
||||
this.width = getDefaultWidth().clone();
|
||||
this.height = getDefaultHeight().clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// This should never happen because Size supports cloning.
|
||||
} catch (NullPointerException e) {
|
||||
@@ -64,140 +62,99 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
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);
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(body);
|
||||
Color finalBorderColor = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(body);
|
||||
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(bodyColor);
|
||||
g2d.fill(shape);
|
||||
}
|
||||
}
|
||||
decorateComponentBody(g2d);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
Color finalBorderColor = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
Color finalLabelFont = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: labelColor;
|
||||
g2d.setColor(finalLabelFont);
|
||||
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.
|
||||
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.setStroke(ObjectCache.getInstance().fetchBasicStroke(
|
||||
getLeadThickness().convertToPixels()));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
|
||||
getLeadThickness().convertToPixels() - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Rectangle shapeRect = shape.getBounds();
|
||||
double leadLenght = (distance - shapeRect.width) / 2;
|
||||
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.
|
||||
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));
|
||||
}
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(shape);
|
||||
decorateComponentBody(g2d);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw leads.
|
||||
int leadThickness = getClosestOdd(getLeadThickness().convertToPixels());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width - distance) / 2 + leadLenght) - leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width + distance) / 2 - leadLenght) + leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width - distance) / 2 + leadLenght) - leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width + distance) / 2 - leadLenght) + leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
}
|
||||
// Do not track the label because that area was already covered.
|
||||
drawingObserver.stopTracking();
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : labelColor);
|
||||
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,
|
||||
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||
}
|
||||
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
// 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.
|
||||
* @return default component width.
|
||||
*/
|
||||
protected abstract Size getDefaultLength();
|
||||
protected abstract Size getDefaultWidth();
|
||||
|
||||
/**
|
||||
* Returns default component width.
|
||||
* Returns default component height.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Size getDefaultWidth();
|
||||
protected abstract Size getDefaultHeight();
|
||||
|
||||
/**
|
||||
* @return shape that represents component body. Shape should not be
|
||||
@@ -205,11 +162,21 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
*/
|
||||
protected abstract Shape getBodyShape();
|
||||
|
||||
/**
|
||||
* @return default component body color.
|
||||
*/
|
||||
protected abstract Color getDefaultBodyColor();
|
||||
|
||||
/**
|
||||
* @return default component border color.
|
||||
*/
|
||||
protected abstract Color getDefaultBorderColor();
|
||||
|
||||
/**
|
||||
* @return default lead thickness. Override this method to change it.
|
||||
*/
|
||||
protected int getLeadThickness() {
|
||||
return (int) LEAD_THICKNESS.convertToPixels();
|
||||
protected Size getLeadThickness() {
|
||||
return LEAD_THICKNESS;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,16 +230,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
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)
|
||||
@EditableProperty(defaultable = true)
|
||||
public Size getWidth() {
|
||||
return width;
|
||||
}
|
||||
@@ -281,6 +239,15 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = true)
|
||||
public Size getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(Size height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
return display;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.LabelPosition;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COLOR = Color.blue;
|
||||
public static Color LEAD_COLOR = Color.black;
|
||||
|
||||
protected LabelPosition labelPosition = LabelPosition.ABOVE;
|
||||
|
||||
public AbstractSchematicLeadedSymbol() {
|
||||
super();
|
||||
// We don't want to fill the body, so use null.
|
||||
this.bodyColor = null;
|
||||
this.borderColor = COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBodyColor() {
|
||||
return super.getBodyColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldShadeLeads() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeadThickness() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect,
|
||||
FontMetrics fontMetrics) {
|
||||
if (labelPosition == LabelPosition.ABOVE) {
|
||||
return -1;
|
||||
} else {
|
||||
return (int) (shapeRect.getHeight() + textRect.getHeight() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label position")
|
||||
public LabelPosition getLabelPosition() {
|
||||
return labelPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getBorderColor() {
|
||||
return super.getBorderColor();
|
||||
}
|
||||
|
||||
public void setLabelPosition(LabelPosition labelPosition) {
|
||||
this.labelPosition = labelPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
public abstract class AbstractSinglePointComponent extends AbstractComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Point point = new Point(0, 0);
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.diylc.core;
|
||||
|
||||
/**
|
||||
* Validator that allows all values.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class AllowAllValidator implements IPropertyValidator {
|
||||
|
||||
@Override
|
||||
public void validate(Object value) throws ValidationException {
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,15 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
*/
|
||||
public interface IDIYComponent<T> extends Serializable {
|
||||
|
||||
public static final int CHASSIS = 1;
|
||||
public static final int BOARD = 2;
|
||||
public static final int TRACE = 3;
|
||||
public static final int COMPONENT = 4;
|
||||
public static final int TEXT = 5;
|
||||
public static final int BELOW_CHASSIS = 1;
|
||||
public static final int CHASSIS = 2;
|
||||
public static final int ABOVE_CHASSIS = 3;
|
||||
public static final int BELOW_BOARD = 4;
|
||||
public static final int BOARD = 5;
|
||||
public static final int ABOVE_BOARD = 6;
|
||||
public static final int BELOW_COMPONENT = 7;
|
||||
public static final int COMPONENT = 8;
|
||||
public static final int ABOVE_COMPONENT = 9;
|
||||
|
||||
/**
|
||||
* @return component instance name.
|
||||
@@ -80,22 +84,9 @@ public interface IDIYComponent<T> extends Serializable {
|
||||
* @param index
|
||||
*/
|
||||
void setControlPoint(Point point, int index);
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return true, if the specified control point may stick to control points
|
||||
* of other components.
|
||||
*/
|
||||
|
||||
boolean isControlPointSticky(int index);
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @return true, if the specified control point may overlap with other
|
||||
* control points <b>of the same component</b>. The other control
|
||||
* point must be able to overlap too.
|
||||
*/
|
||||
boolean canControlPointOverlap(int index);
|
||||
|
||||
|
||||
VisibilityPolicy getControlPointVisibilityPolicy(int index);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.diylc.core;
|
||||
|
||||
/**
|
||||
* Interface for validating property value changes.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public interface IPropertyValidator {
|
||||
|
||||
/**
|
||||
* @param value
|
||||
* @throws ValidationException
|
||||
* if validation fails. Message will contain the reason.
|
||||
*/
|
||||
void validate(Object value) throws ValidationException;
|
||||
}
|
||||
@@ -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<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties);
|
||||
}
|
||||
@@ -7,12 +7,9 @@ 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
|
||||
@@ -29,8 +26,6 @@ public class Project implements Serializable {
|
||||
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;
|
||||
@@ -97,7 +92,7 @@ public class Project implements Serializable {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Grid spacing", validatorClass = SpacingValidator.class)
|
||||
@EditableProperty(name = "Grid spacing")
|
||||
public Size getGridSpacing() {
|
||||
return gridSpacing;
|
||||
}
|
||||
@@ -123,18 +118,10 @@ public class Project implements Serializable {
|
||||
public Set<Set<IDIYComponent<?>>> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
public Set<Integer> getLockedLayers() {
|
||||
return lockedLayers;
|
||||
}
|
||||
|
||||
public VersionNumber getFileVersion() {
|
||||
return fileVersion;
|
||||
}
|
||||
|
||||
public void setFileVersion(VersionNumber fileVersion) {
|
||||
this.fileVersion = fileVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -190,27 +177,12 @@ public class Project implements Serializable {
|
||||
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<IDIYComponent> clonedComponents = new
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.diylc.core;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Theme implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private Color bgColor;
|
||||
private Color gridColor;
|
||||
|
||||
public Theme(String name, Color bgColor, Color gridColor) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.bgColor = bgColor;
|
||||
this.gridColor = gridColor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Color getBgColor() {
|
||||
return bgColor;
|
||||
}
|
||||
|
||||
public Color getGridColor() {
|
||||
return gridColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
|
||||
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.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;
|
||||
Theme other = (Theme) obj;
|
||||
if (bgColor == null) {
|
||||
if (other.bgColor != null)
|
||||
return false;
|
||||
} else if (!bgColor.equals(other.bgColor))
|
||||
return false;
|
||||
if (gridColor == null) {
|
||||
if (other.gridColor != null)
|
||||
return false;
|
||||
} else if (!gridColor.equals(other.gridColor))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
package org.diylc.core;
|
||||
|
||||
public class ValidationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,6 @@ package org.diylc.core.annotations;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.diylc.core.AllowAllValidator;
|
||||
import org.diylc.core.IPropertyValidator;
|
||||
|
||||
/**
|
||||
* Used to annotate editable component property. Editable property XYZ must have
|
||||
* both getter and setter named <code>getXYZ</code> and <code>setXYZ</code>
|
||||
@@ -33,10 +30,4 @@ public @interface EditableProperty {
|
||||
* @return
|
||||
*/
|
||||
boolean defaultable() default true;
|
||||
|
||||
/**
|
||||
* Class of validator to use to
|
||||
* @return
|
||||
*/
|
||||
Class<? extends IPropertyValidator> validatorClass() default AllowAllValidator.class;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
import org.diylc.core.IPropertyValidator;
|
||||
import org.diylc.core.ValidationException;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
|
||||
public class PositiveMeasureValidator implements IPropertyValidator {
|
||||
|
||||
@Override
|
||||
public void validate(Object value) throws ValidationException {
|
||||
if (value instanceof AbstractMeasure) {
|
||||
AbstractMeasure measure = (AbstractMeasure) value;
|
||||
if (measure.getValue() <= 0) {
|
||||
throw new ValidationException("must be greater than zero.");
|
||||
}
|
||||
} else {
|
||||
throw new ValidationException("wrong data type, measure expected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
|
||||
|
||||
public enum CapacitanceUnit implements Unit {
|
||||
|
||||
pF(1, "pF"), nF(1e3, "nF"), uF(1e6, "uF"), mF(1e9, "mF"), F(1e12, "F");
|
||||
pF(1, "pF"), nF(1e3, "nF"), uF(1e6, "\u03bcF"), mF(1e9, "mF"), F(1e12, "F");
|
||||
|
||||
double factor;
|
||||
String display;
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
package org.diylc.core.measures;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.diylc.common.ResistorColorCode;
|
||||
|
||||
public class Resistance extends AbstractMeasure<ResistanceUnit> {
|
||||
|
||||
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
|
||||
@@ -30,42 +19,6 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
|
||||
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())) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size> {
|
||||
public class Size extends AbstractMeasure<SizeUnit> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -16,13 +16,13 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public double convertToPixels() {
|
||||
public int convertToPixels() {
|
||||
// double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
||||
// int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH);
|
||||
// double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids;
|
||||
// return (int) Math.round(Constants.PIXELS_PER_INCH / Constants.GRIDS_PER_INCH
|
||||
// * (grids + remainder));
|
||||
return getValue() * getUnit().getFactor() / SizeUnit.in.getFactor() * Constants.PIXELS_PER_INCH;
|
||||
return (int) (getValue() * getUnit().getFactor() / SizeUnit.in.getFactor() * Constants.PIXELS_PER_INCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,9 +39,4 @@ public class Size extends AbstractMeasure<SizeUnit> implements Comparable<Size>
|
||||
}
|
||||
throw new IllegalArgumentException("Could not parse size: " + value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Size o) {
|
||||
return new Double(value * unit.getFactor()).compareTo(o.getValue() * o.getUnit().getFactor());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui;
|
||||
package org.diylc.gui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui;
|
||||
package org.diylc.gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -9,13 +9,13 @@ 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 org.diylc.gui.components.OverwritePromptFileChooser;
|
||||
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||
import org.diylc.plugins.file.BomDialog;
|
||||
import org.diylc.plugins.file.BomEntry;
|
||||
import org.diylc.plugins.online.view.LoginDialog;
|
||||
import org.diylc.plugins.online.view.NewUserDialog;
|
||||
import org.diylc.plugins.online.view.UploadDialog;
|
||||
|
||||
import com.diyfever.gui.AboutDialog;
|
||||
import com.diyfever.gui.IFileChooserAccessory;
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.diylc.gui;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
|
||||
/**
|
||||
* Base interface for the main GUI component.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public interface IView {
|
||||
|
||||
/**
|
||||
* Adds a component to the view.
|
||||
*
|
||||
* @param component
|
||||
* component to insert
|
||||
* @param position
|
||||
* target position
|
||||
* @throws BadPositionException
|
||||
*
|
||||
* @see IPlugInPort#injectGUIComponent
|
||||
*/
|
||||
void addComponent(JComponent component, int position) throws BadPositionException;
|
||||
|
||||
/**
|
||||
* Adds a menu action.
|
||||
*
|
||||
* @param action
|
||||
* action to insert
|
||||
* @param menuName
|
||||
* target menu name
|
||||
*
|
||||
* @see IPlugInPort#injectMenuAction
|
||||
*/
|
||||
void addMenuAction(Action action, String menuName);
|
||||
|
||||
/**
|
||||
* Adds a submenu to an existing menu.
|
||||
*
|
||||
* @param name
|
||||
* @param icon
|
||||
* @param parentMenuName
|
||||
*/
|
||||
void addSubmenu(String name, Icon icon, String parentMenuName);
|
||||
|
||||
void showMessage(String message, String title, int messageType);
|
||||
|
||||
int showConfirmDialog(String message, String title, int optionType, int messageType);
|
||||
}
|
||||
+38
-122
@@ -1,8 +1,7 @@
|
||||
package org.diylc.swing.gui;
|
||||
package org.diylc.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;
|
||||
@@ -11,13 +10,10 @@ import java.awt.event.WindowEvent;
|
||||
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;
|
||||
@@ -26,39 +22,24 @@ 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.plugins.canvas.CanvasPlugin;
|
||||
import org.diylc.plugins.clipboard.EditMenuPlugin;
|
||||
import org.diylc.plugins.file.FileMenuPlugin;
|
||||
import org.diylc.plugins.help.HelpMenuPlugin;
|
||||
import org.diylc.plugins.layers.LayersMenuPlugin;
|
||||
import org.diylc.plugins.statusbar.StatusBar;
|
||||
import org.diylc.plugins.toolbox.ToolBox;
|
||||
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);
|
||||
public class MainFrame extends JFrame implements IView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -72,7 +53,6 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
|
||||
private JMenuBar mainMenuBar;
|
||||
private Map<String, JMenu> menuMap;
|
||||
private Map<String, ButtonGroup> buttonGroupMap;
|
||||
|
||||
private CanvasPlugin canvasPlugin;
|
||||
|
||||
@@ -82,26 +62,23 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
createBasePanels();
|
||||
menuMap = new HashMap<String, JMenu>();
|
||||
buttonGroupMap = new HashMap<String, ButtonGroup>();
|
||||
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 ToolBox());
|
||||
presenter.installPlugin(new FileMenuPlugin());
|
||||
presenter.installPlugin(new EditMenuPlugin());
|
||||
presenter.installPlugin(new LayersMenuPlugin());
|
||||
// presenter.installPlugin(new OnlineManager());
|
||||
presenter.installPlugin(new HelpMenuPlugin(this));
|
||||
presenter.installPlugin(new HelpMenuPlugin());
|
||||
|
||||
presenter.installPlugin(new StatusBar(this));
|
||||
canvasPlugin = new CanvasPlugin(this);
|
||||
presenter.installPlugin(new StatusBar());
|
||||
canvasPlugin = new CanvasPlugin();
|
||||
presenter.installPlugin(canvasPlugin);
|
||||
presenter.installPlugin(new FramePlugin());
|
||||
presenter.installPlugin(new AutoSavePlugin(this));
|
||||
|
||||
presenter.createNewProject();
|
||||
|
||||
@@ -110,8 +87,6 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (presenter.allowFileAction()) {
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY,
|
||||
false);
|
||||
dispose();
|
||||
presenter.dispose();
|
||||
System.exit(0);
|
||||
@@ -121,8 +96,6 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
if (presenter.allowFileAction()) {
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.ABNORMAL_EXIT_KEY,
|
||||
false);
|
||||
dispose();
|
||||
presenter.dispose();
|
||||
System.exit(0);
|
||||
@@ -134,10 +107,6 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
// getGlassPane().setVisible(true);
|
||||
}
|
||||
|
||||
public Presenter getPresenter() {
|
||||
return presenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
super.setVisible(b);
|
||||
@@ -200,41 +169,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
// 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<PropertyWrapper> properties,
|
||||
Set<PropertyWrapper> 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));
|
||||
public void addComponent(JComponent component, int position) throws BadPositionException {
|
||||
switch (position) {
|
||||
case SwingConstants.TOP:
|
||||
topPanel.add(component);
|
||||
@@ -258,28 +193,14 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectMenuAction(Action action, String menuName) {
|
||||
LOG.info(String.format("injectMenuAction(%s, %s)", action == null ? "Separator" : action
|
||||
.getValue(Action.NAME), menuName));
|
||||
public void addMenuAction(Action action, String 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);
|
||||
Boolean isCheckBox = (Boolean) action.getValue(IPlugInPort.CHECK_BOX_MENU_ITEM);
|
||||
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);
|
||||
}
|
||||
@@ -287,8 +208,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
LOG.info(String.format("injectSubmenu(%s, icon, %s)", name, parentMenuName));
|
||||
public void addSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
JMenu menu = findOrCreateMenu(parentMenuName);
|
||||
JMenu submenu = new JMenu(name);
|
||||
submenu.setIcon(icon);
|
||||
@@ -297,28 +217,25 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Object> void executeBackgroundTask(final ITask<T> task) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
SwingWorker<T, Void> worker = new SwingWorker<T, Void>() {
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
JOptionPane.showMessageDialog(this, message, title, messageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T doInBackground() throws Exception {
|
||||
return task.doInBackground();
|
||||
}
|
||||
@Override
|
||||
public int showConfirmDialog(String message, String title, int optionType, int messageType) {
|
||||
return JOptionPane.showConfirmDialog(this, message, title, optionType, messageType);
|
||||
}
|
||||
|
||||
@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();
|
||||
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;
|
||||
}
|
||||
|
||||
class FramePlugin implements IPlugIn {
|
||||
@@ -343,10 +260,9 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
fileName = "Untitled";
|
||||
}
|
||||
String modified = (Boolean) params[1] ? " (modified)" : "";
|
||||
setTitle(String.format("DIYLC %s beta - %s %s", plugInPort
|
||||
setTitle(String.format("DIYLC %s alpha - %s %s", plugInPort
|
||||
.getCurrentVersionNumber(), fileName, modified));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.components;
|
||||
package org.diylc.gui.components;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
+3
-23
@@ -1,10 +1,8 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.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;
|
||||
@@ -28,32 +26,14 @@ public class FieldEditorFactory {
|
||||
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;
|
||||
ByteEditor byteEditor = new ByteEditor(property);
|
||||
return byteEditor;
|
||||
}
|
||||
LOG.error("Unrecognized parameter type: " + property.getType().getName());
|
||||
return new JLabel("Unrecognized");
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.diylc.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 FontEditor extends JLabel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FontEditor(final PropertyWrapper property) {
|
||||
super("Click to edit");
|
||||
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) {
|
||||
// JFo
|
||||
Color newColor = JColorChooser.showDialog(FontEditor.this, "Choose Color",
|
||||
getBackground());
|
||||
if (newColor != null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
+1
-20
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
@@ -18,12 +18,10 @@ 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;
|
||||
|
||||
@@ -67,23 +65,6 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
// 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));
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
@@ -30,8 +30,7 @@ public enum IconLoader {
|
||||
"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");
|
||||
"edit_component.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 537 B |
Binary file not shown.
|
Before Width: | Height: | Size: 535 B |
Binary file not shown.
|
Before Width: | Height: | Size: 922 B |
Binary file not shown.
|
Before Width: | Height: | Size: 550 B |
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.dnd.DragGestureEvent;
|
||||
import java.awt.dnd.DragGestureListener;
|
||||
+78
-32
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -16,11 +16,13 @@ import java.awt.dnd.DropTarget;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
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.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JComponent;
|
||||
@@ -28,8 +30,11 @@ import javax.swing.KeyStroke;
|
||||
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.gui.DialogFactory;
|
||||
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||
|
||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
import com.diyfever.gui.ButtonDialog;
|
||||
|
||||
/**
|
||||
* GUI class used to draw onto.
|
||||
@@ -45,11 +50,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
private Image bufferImage;
|
||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||
|
||||
private static boolean USE_HARDWARE_ACCELLERATION = false;
|
||||
private static boolean USE_HARDWARE_ACCELLERATION = true;
|
||||
|
||||
static final EnumSet<DrawOption> DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
|
||||
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING = EnumSet.of(DrawOption.GRID,
|
||||
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
||||
DrawOption.CONTROL_POINTS);
|
||||
|
||||
@@ -73,8 +76,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
|
||||
new CanvasGestureListener(plugInPort));
|
||||
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);
|
||||
@@ -102,6 +104,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
} else {
|
||||
bufferImage = createImage(getWidth(), getHeight());
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
plugInPort.draw(g2d, DRAW_OPTIONS, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,12 +115,10 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
}
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
} else {
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
plugInPort.draw(g2d, DRAW_OPTIONS, null);
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
g2d.setClip(getVisibleRect());
|
||||
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
|
||||
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING : DRAW_OPTIONS,
|
||||
null);
|
||||
if (USE_HARDWARE_ACCELLERATION) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
@@ -124,11 +126,10 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
if (volatileImage.contentsLost()) {
|
||||
createBufferImage();
|
||||
}
|
||||
// int validation =
|
||||
// volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
// int validation = volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, 0, 0, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
@@ -136,7 +137,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, 0, 0, this);
|
||||
// bufferImage.flush();
|
||||
bufferImage.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,18 +155,18 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
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());
|
||||
// }
|
||||
// });
|
||||
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
|
||||
@@ -180,8 +181,53 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.isControlDown(), e.isShiftDown(), e
|
||||
.isAltDown(), e.getClickCount());
|
||||
if (e.getClickCount() == 2) {
|
||||
List<PropertyWrapper> properties = plugInPort
|
||||
.getMutualSelectionProperties();
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
// 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());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||
.createPropertyEditorDialog(properties, "Edit Selection");
|
||||
editor.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||
try {
|
||||
plugInPort.applyPropertiesToSelection(properties);
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
// Save default values.
|
||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||
if (property.getValue() != null) {
|
||||
plugInPort.setSelectionDefaultPropertyValue(property.getName(),
|
||||
property.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.isControlDown(), e.isShiftDown(), e
|
||||
.isAltDown());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,150 @@
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.util.EnumSet;
|
||||
|
||||
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.plugins.file.ProjectDrawingProvider;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
import com.diyfever.gui.ruler.IRulerListener;
|
||||
import com.diyfever.gui.ruler.RulerScrollPane;
|
||||
|
||||
public class CanvasPlugin implements IPlugIn {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||
|
||||
private RulerScrollPane scrollPane;
|
||||
private CanvasPanel canvasPanel;
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
public CanvasPlugin() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
try {
|
||||
plugInPort.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);
|
||||
}
|
||||
return canvasPanel;
|
||||
}
|
||||
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
|
||||
plugInPort, true), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
|
||||
SizeUnit.in).convertToPixels());
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
|
||||
true);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.setWheelScrollingEnabled(false);
|
||||
scrollPane.addUnitListener(new IRulerListener() {
|
||||
|
||||
@Override
|
||||
public void unitsChanged(boolean isMetric) {
|
||||
plugInPort.setMetric(isMetric);
|
||||
}
|
||||
});
|
||||
scrollPane.addMouseWheelListener(new MouseWheelListener() {
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> 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();
|
||||
}
|
||||
// canvasPanel.validate();
|
||||
// canvasPanel.repaint();
|
||||
break;
|
||||
case ZOOM_CHANGED:
|
||||
refreshSize();
|
||||
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 ruller 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);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.dnd.DragSourceDragEvent;
|
||||
@@ -25,7 +25,7 @@ class CanvasSourceListener implements DragSourceListener {
|
||||
|
||||
@Override
|
||||
public void dragDropEnd(DragSourceDropEvent dsde) {
|
||||
presenter.dragEnded(null);
|
||||
// presenter.dragEnded(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
package org.diylc.plugins.canvas;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
@@ -0,0 +1,316 @@
|
||||
package org.diylc.plugins.clipboard;
|
||||
|
||||
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.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.ComponentSelection;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.gui.DialogFactory;
|
||||
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||
import org.diylc.images.IconLoader;
|
||||
|
||||
import com.diyfever.gui.ButtonDialog;
|
||||
import com.diyfever.gui.undo.IUndoListener;
|
||||
import com.diyfever.gui.undo.UndoHandler;
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EditMenuPlugin.class);
|
||||
|
||||
private static final String EDIT_TITLE = "Edit";
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
private Clipboard clipboard;
|
||||
private Cloner cloner;
|
||||
|
||||
// private CutAction cutAction;
|
||||
private CopyAction copyAction;
|
||||
private PasteAction pasteAction;
|
||||
|
||||
private UndoHandler<Project> undoHandler;
|
||||
|
||||
public EditMenuPlugin() {
|
||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
cloner = new Cloner();
|
||||
undoHandler = new UndoHandler<Project>(new IUndoListener<Project>() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(Project currentState) {
|
||||
plugInPort.loadProject(currentState, false);
|
||||
}
|
||||
});
|
||||
clipboard.addFlavorListener(new FlavorListener() {
|
||||
|
||||
@Override
|
||||
public void flavorsChanged(FlavorEvent e) {
|
||||
refreshActions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
plugInPort.injectMenuAction(undoHandler.getUndoAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(undoHandler.getRedoAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||
// cutAction = new CutAction();
|
||||
// plugInPort.injectMenuAction(cutAction, EDIT_TITLE);
|
||||
copyAction = new CopyAction();
|
||||
plugInPort.injectMenuAction(copyAction, EDIT_TITLE);
|
||||
pasteAction = new PasteAction();
|
||||
plugInPort.injectMenuAction(pasteAction, EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(new EditSelectionAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(new EditProjectAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(null, EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(new GroupAction(), EDIT_TITLE);
|
||||
plugInPort.injectMenuAction(new UngroupAction(), EDIT_TITLE);
|
||||
|
||||
refreshActions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> 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();
|
||||
// cutAction.setEnabled(enabled);
|
||||
copyAction.setEnabled(enabled);
|
||||
try {
|
||||
pasteAction.setEnabled(clipboard.isDataFlavorAvailable(ComponentSelection.listFlavor));
|
||||
} catch (Exception e) {
|
||||
pasteAction.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
class CutAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CutAction() {
|
||||
super();
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
class CopyAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CopyAction() {
|
||||
super();
|
||||
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(cloner.deepClone(plugInPort.getSelectedComponents()),
|
||||
EditMenuPlugin.this);
|
||||
}
|
||||
}
|
||||
|
||||
class PasteAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PasteAction() {
|
||||
super();
|
||||
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<IDIYComponent<?>> components = (List<IDIYComponent<?>>) clipboard
|
||||
.getData(ComponentSelection.listFlavor);
|
||||
plugInPort.pasteComponents(cloner.deepClone(components));
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Coule not paste.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SelectAllAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SelectAllAction() {
|
||||
super();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class GroupAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public GroupAction() {
|
||||
super();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class UngroupAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UngroupAction() {
|
||||
super();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
class EditProjectAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public EditProjectAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Edit Project");
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E,
|
||||
ActionEvent.CTRL_MASK));
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentEdit.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("Edit Project triggered");
|
||||
List<PropertyWrapper> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EditSelectionAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public EditSelectionAction() {
|
||||
super();
|
||||
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<PropertyWrapper> properties = plugInPort.getMutualSelectionProperties();
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
LOG.info("Nothing to edit");
|
||||
return;
|
||||
}
|
||||
PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog(
|
||||
properties, "Edit Selection");
|
||||
editor.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||
plugInPort.applyPropertiesToSelection(properties);
|
||||
}
|
||||
// Save default values.
|
||||
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||
if (property.getValue() != null) {
|
||||
plugInPort.setSelectionDefaultPropertyValue(property.getName(), property
|
||||
.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ClipboardOwner
|
||||
|
||||
@Override
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||
refreshActions();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -15,8 +15,8 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import org.diylc.gui.DialogFactory;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.swing.gui.DialogFactory;
|
||||
|
||||
import com.diyfever.gui.export.TableExporter;
|
||||
import com.diyfever.gui.objecttable.ObjectListTable;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
public class BomEntry {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
+3
-4
@@ -1,15 +1,14 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
public enum FileFilterEnum {
|
||||
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");
|
||||
"Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html");
|
||||
|
||||
FileFilter filter;
|
||||
String[] extensions;
|
||||
@@ -0,0 +1,289 @@
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.gui.DialogFactory;
|
||||
import org.diylc.gui.editor.PropertyEditorDialog;
|
||||
import org.diylc.images.IconLoader;
|
||||
|
||||
import com.diyfever.gui.ButtonDialog;
|
||||
import com.diyfever.gui.IDrawingProvider;
|
||||
import com.diyfever.gui.export.DrawingExporter;
|
||||
import com.lowagie.text.DocumentException;
|
||||
|
||||
/**
|
||||
* 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 IPlugInPort plugInPort;
|
||||
private ProjectDrawingProvider drawingProvider;
|
||||
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false);
|
||||
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
|
||||
|
||||
plugInPort.injectMenuAction(new NewAction(), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new OpenAction(), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new SaveAction(), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new SaveAsAction(), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(null, FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new ExportPDFAction(drawingProvider), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new ExportPNGAction(drawingProvider), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new PrintAction(drawingProvider), FILE_TITLE);
|
||||
plugInPort.injectSubmenu(TRACE_MASK_TITLE, IconLoader.TraceMask.getIcon(), FILE_TITLE);
|
||||
plugInPort
|
||||
.injectMenuAction(new ExportPDFAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
||||
plugInPort
|
||||
.injectMenuAction(new ExportPNGAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
||||
plugInPort.injectMenuAction(new PrintAction(traceMaskDrawingProvider), TRACE_MASK_TITLE);
|
||||
plugInPort.injectMenuAction(new CreateBomAction(), FILE_TITLE);
|
||||
plugInPort.injectMenuAction(null, FILE_TITLE);
|
||||
plugInPort.injectMenuAction(new ExitAction(), FILE_TITLE);
|
||||
}
|
||||
|
||||
class NewAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NewAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "New");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (!plugInPort.allowFileAction()) {
|
||||
return;
|
||||
}
|
||||
plugInPort.createNewProject();
|
||||
List<PropertyWrapper> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OpenAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public OpenAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Open");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.FolderOut.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (!plugInPort.allowFileAction()) {
|
||||
return;
|
||||
}
|
||||
File file = DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(),
|
||||
null, FileFilterEnum.DIY.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
plugInPort.loadProjectFromFile(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SaveAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SaveAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Save");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (plugInPort.getCurrentFileName() == null) {
|
||||
File file = DialogFactory.getInstance().showSaveDialog(
|
||||
FileFilterEnum.DIY.getFilter(), null,
|
||||
FileFilterEnum.DIY.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||
}
|
||||
} else {
|
||||
plugInPort.saveProjectToFile(plugInPort.getCurrentFileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SaveAsAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SaveAsAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Save As");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
||||
null, FileFilterEnum.DIY.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
plugInPort.saveProjectToFile(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CreateBomAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CreateBomAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Create B.O.M.");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.BOM.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<BomEntry> bom = BomMaker.getInstance().createBom(
|
||||
plugInPort.getCurrentProject().getComponents());
|
||||
BomDialog dialog = DialogFactory.getInstance().createBomDialog(bom);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class ExportPDFAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IDrawingProvider drawingProvider;
|
||||
|
||||
public ExportPDFAction(IDrawingProvider drawingProvider) {
|
||||
super();
|
||||
this.drawingProvider = drawingProvider;
|
||||
putValue(AbstractAction.NAME, "Export to PDF");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.PDF.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(),
|
||||
null, FileFilterEnum.PDF.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
try {
|
||||
DrawingExporter.getInstance().exportPDF(this.drawingProvider, file);
|
||||
} catch (FileNotFoundException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (DocumentException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExportPNGAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IDrawingProvider drawingProvider;
|
||||
|
||||
public ExportPNGAction(IDrawingProvider drawingProvider) {
|
||||
super();
|
||||
this.drawingProvider = drawingProvider;
|
||||
putValue(AbstractAction.NAME, "Export to PNG");
|
||||
putValue(AbstractAction.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) {
|
||||
DrawingExporter.getInstance().exportPNG(this.drawingProvider, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.SMALL_ICON, IconLoader.Print.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
DrawingExporter.getInstance().print(this.drawingProvider);
|
||||
} catch (PrinterException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExitAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ExitAction() {
|
||||
super();
|
||||
putValue(AbstractAction.NAME, "Exit");
|
||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Exit.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (plugInPort.allowFileAction()) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... params) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
+2
-11
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
@@ -9,7 +9,6 @@ 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
|
||||
@@ -21,14 +20,11 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private boolean useZoom;
|
||||
private boolean showGridWhenNeeded;
|
||||
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom,
|
||||
boolean showGridWhenNeeded) {
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.useZoom = useZoom;
|
||||
this.showGridWhenNeeded = showGridWhenNeeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,11 +33,6 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
if (useZoom) {
|
||||
options.add(DrawOption.ZOOM);
|
||||
}
|
||||
if (showGridWhenNeeded
|
||||
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXPORT_GRID_KEY,
|
||||
false)) {
|
||||
options.add(DrawOption.GRID);
|
||||
}
|
||||
plugInPort.draw((Graphics2D) g, options, null);
|
||||
}
|
||||
|
||||
+18
-10
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@@ -10,19 +10,19 @@ 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.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.diylc.common.BadPositionException;
|
||||
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.gui.IView;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
import com.diyfever.gui.IFileChooserAccessory;
|
||||
@@ -52,6 +52,19 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
setPreferredSize(new Dimension(140, 128));
|
||||
presenter = new Presenter(new IView() {
|
||||
|
||||
@Override
|
||||
public void addComponent(JComponent component, int position)
|
||||
throws BadPositionException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMenuAction(Action action, String menuName) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubmenu(String name, Icon icon, String parentMenuName) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showConfirmDialog(String message, String title, int optionType,
|
||||
int messageType) {
|
||||
@@ -61,11 +74,6 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
xStream = new XStream(new DomDriver());
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.file;
|
||||
package org.diylc.plugins.file;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
@@ -27,7 +27,7 @@ public class TraceMaskDrawingProvider implements IDrawingProvider {
|
||||
public TraceMaskDrawingProvider(IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.filter = new ComponentZOrderFiler(IDIYComponent.TRACE);
|
||||
this.filter = new ComponentZOrderFiler(IDIYComponent.ABOVE_BOARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
+18
-28
@@ -1,22 +1,18 @@
|
||||
package org.diylc.swing.plugins.help;
|
||||
package org.diylc.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.gui.DialogFactory;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -38,26 +34,24 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
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;
|
||||
|
||||
plugInPort.injectMenuAction(new NavigateURLAction("User Manual", IconLoader.Manual
|
||||
.getIcon(), MANUAL_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(
|
||||
new NavigateURLAction("FAQ", IconLoader.Faq.getIcon(), FAQ_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(new NavigateURLAction("Component API", IconLoader.Component
|
||||
.getIcon(), COMPONENT_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(new NavigateURLAction("Plugin API",
|
||||
IconLoader.Plugin.getIcon(), PLUGIN_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(new NavigateURLAction("Submit a Bug", IconLoader.Bug.getIcon(),
|
||||
BUG_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(null, HELP_TITLE);
|
||||
plugInPort.injectMenuAction(new NavigateURLAction("Donate", IconLoader.Donate.getIcon(),
|
||||
DONATE_URL), HELP_TITLE);
|
||||
plugInPort.injectMenuAction(new AboutAction(), HELP_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,11 +104,7 @@ public class HelpMenuPlugin implements IPlugIn {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
Utils.openURL(url);
|
||||
} catch (Exception e1) {
|
||||
Logger.getLogger(LinkLabel.class).error("Could not launch default browser", e1);
|
||||
}
|
||||
Utils.openURL(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-14
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.layers;
|
||||
package org.diylc.plugins.layers;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.EnumSet;
|
||||
@@ -13,8 +13,6 @@ 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 {
|
||||
|
||||
@@ -23,7 +21,13 @@ public class LayersMenuPlugin implements IPlugIn {
|
||||
private IPlugInPort plugInPort;
|
||||
private Map<Layer, Action> lockActionMap;
|
||||
|
||||
public LayersMenuPlugin(ISwingUI swingUI) {
|
||||
public LayersMenuPlugin() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
|
||||
lockActionMap = new HashMap<Layer, Action>();
|
||||
for (Layer layer : Layer.values()) {
|
||||
final int zOrder = layer.getZOrder();
|
||||
@@ -37,17 +41,12 @@ public class LayersMenuPlugin implements IPlugIn {
|
||||
(Boolean) getValue(Action.SELECTED_KEY));
|
||||
}
|
||||
};
|
||||
action.putValue(IView.CHECK_BOX_MENU_ITEM, true);
|
||||
action.putValue(IPlugInPort.CHECK_BOX_MENU_ITEM, true);
|
||||
lockActionMap.put(layer, action);
|
||||
swingUI.injectMenuAction(action, LOCK_LAYERS_TITLE);
|
||||
plugInPort.injectMenuAction(action, LOCK_LAYERS_TITLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.LAYER_STATE_CHANGED);
|
||||
@@ -66,9 +65,12 @@ public class LayersMenuPlugin implements IPlugIn {
|
||||
}
|
||||
|
||||
static enum Layer {
|
||||
CHASSIS("Chassis", IDIYComponent.CHASSIS), BOARD("Board", IDIYComponent.BOARD), TRACE(
|
||||
"Trace", IDIYComponent.TRACE), COMPONENT("Component", IDIYComponent.COMPONENT), TEXT(
|
||||
"Text", IDIYComponent.TEXT);
|
||||
BELOW_CHASSIS("Below Chassis", IDIYComponent.BELOW_CHASSIS), CHASSIS("Chassis",
|
||||
IDIYComponent.CHASSIS), ABOVE_CHASSIS("Above Chassis", IDIYComponent.ABOVE_CHASSIS), BELOW_BOARD(
|
||||
"Below Board", IDIYComponent.BELOW_BOARD), BOARD("Board", IDIYComponent.BOARD), ABOVE_BOARD(
|
||||
"Above Board", IDIYComponent.ABOVE_BOARD), BELOW_COMPONENT("Below Component",
|
||||
IDIYComponent.BELOW_COMPONENT), COMPONENT("Component", IDIYComponent.COMPONENT), ABOVE_COMPONENT(
|
||||
"Above Component", IDIYComponent.ABOVE_COMPONENT);
|
||||
|
||||
String title;
|
||||
int zOrder;
|
||||
+13
-13
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online;
|
||||
package org.diylc.plugins.online;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.EnumSet;
|
||||
@@ -9,12 +9,12 @@ import javax.swing.SwingWorker;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.gui.DialogFactory;
|
||||
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 org.diylc.plugins.online.presenter.LibraryPresenter;
|
||||
import org.diylc.plugins.online.view.LoginDialog;
|
||||
import org.diylc.plugins.online.view.NewUserDialog;
|
||||
import org.diylc.plugins.online.view.UploadDialog;
|
||||
|
||||
import com.diyfever.gui.ProgressDialog;
|
||||
|
||||
@@ -32,13 +32,13 @@ public class OnlineManager implements IPlugIn {
|
||||
|
||||
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);
|
||||
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() {
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package org.diylc.swing.plugins.online;
|
||||
package org.diylc.plugins.online;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.diylc.swing.plugins.online.presenter.LibraryPresenter;
|
||||
import org.diylc.plugins.online.presenter.LibraryPresenter;
|
||||
|
||||
|
||||
public class Test {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.model;
|
||||
package org.diylc.plugins.online.model;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.Serializable;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
public class AlreadyExistsException extends Exception {
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.swing.plugins.online.model.ProjectEntity;
|
||||
import org.diylc.plugins.online.model.ProjectEntity;
|
||||
|
||||
|
||||
public class LibraryPresenter {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
public class NotConnectedException extends Exception {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
public class NotExistsException extends Exception {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.presenter;
|
||||
package org.diylc.plugins.online.presenter;
|
||||
|
||||
public class NotLoggedInException extends Exception {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.view;
|
||||
package org.diylc.plugins.online.view;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.view;
|
||||
package org.diylc.plugins.online.view;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.view;
|
||||
package org.diylc.plugins.online.view;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.online.view;
|
||||
package org.diylc.plugins.online.view;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
+42
-52
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.statusbar;
|
||||
package org.diylc.plugins.statusbar;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
@@ -6,8 +6,6 @@ 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;
|
||||
@@ -22,20 +20,18 @@ 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 javax.swing.UIManager;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.ComponentSelection;
|
||||
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;
|
||||
@@ -47,10 +43,8 @@ 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 static final Format sizeFormat = new DecimalFormat("0.00");
|
||||
|
||||
private JComboBox zoomBox;
|
||||
private UpdateLabel updateLabel;
|
||||
@@ -66,18 +60,12 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
private List<String> componentNamesUnderCursor;
|
||||
private List<String> selectedComponentNames;
|
||||
private List<String> stuckComponentNames;
|
||||
private String statusMessage;
|
||||
|
||||
public StatusBar(ISwingUI swingUI) {
|
||||
public StatusBar() {
|
||||
super();
|
||||
|
||||
// setLayout(new FlowLayout(FlowLayout.TRAILING));
|
||||
setLayout(new GridBagLayout());
|
||||
|
||||
try {
|
||||
swingUI.injectGUIComponent(this, SwingUtilities.BOTTOM);
|
||||
} catch (BadPositionException e) {
|
||||
LOG.error("Could not install status bar", e);
|
||||
}
|
||||
}
|
||||
|
||||
private JComboBox getZoomBox() {
|
||||
@@ -125,27 +113,11 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
sizeLabel = new JLabel("N/A");
|
||||
sizeLabel.setToolTipText("Selection Size");
|
||||
sizeLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(
|
||||
0, 1, 0, 1, UIManager.getColor("Separator.shadow")), BorderFactory
|
||||
.createEmptyBorder(0, 4, 0, 4)));
|
||||
}
|
||||
return sizeLabel;
|
||||
}
|
||||
@@ -169,10 +141,10 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
gbc.gridx = 1;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.weightx = 0;
|
||||
add(zoomPanel, gbc);
|
||||
add(getSizeLabel(), gbc);
|
||||
|
||||
gbc.gridx = 2;
|
||||
add(getSizeLabel(), gbc);
|
||||
add(zoomPanel, gbc);
|
||||
|
||||
gbc.gridx = 3;
|
||||
add(getUpdateLabel(), gbc);
|
||||
@@ -192,13 +164,20 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
this.plugInPort = plugInPort;
|
||||
|
||||
layoutComponents();
|
||||
|
||||
try {
|
||||
plugInPort.injectGUIComponent(this, SwingUtilities.BOTTOM);
|
||||
} catch (BadPositionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED,
|
||||
EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_CHANGED,
|
||||
EventType.STATUS_MESSAGE_CHANGED);
|
||||
EventType.AVAILABLE_CTRL_POINTS_CHANGED, EventType.SELECTION_SIZE_CHANGED,
|
||||
EventType.SELECTION_CHANGED);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -218,7 +197,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
}
|
||||
break;
|
||||
case SELECTION_CHANGED:
|
||||
List<IDIYComponent<?>> selection = (List<IDIYComponent<?>>) params[0];
|
||||
ComponentSelection selection = (ComponentSelection) params[0];
|
||||
Collection<IDIYComponent<?>> stuckComponents = (Collection<IDIYComponent<?>>) params[1];
|
||||
Collection<String> componentNames = new HashSet<String>();
|
||||
for (IDIYComponent<?> component : selection) {
|
||||
@@ -235,6 +214,18 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
Collections.sort(this.stuckComponentNames);
|
||||
refreshStatusText();
|
||||
break;
|
||||
case SELECTION_SIZE_CHANGED:
|
||||
Point2D size = (Point2D) params[0];
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
|
||||
true);
|
||||
if (size == null) {
|
||||
getSizeLabel().setText("N/A");
|
||||
} else {
|
||||
getSizeLabel().setText(
|
||||
sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY())
|
||||
+ (metric ? " cm" : " in"));
|
||||
}
|
||||
break;
|
||||
case SLOT_CHANGED:
|
||||
componentSlot = (ComponentType) params[0];
|
||||
controlPointSlot = (Point) params[1];
|
||||
@@ -249,13 +240,11 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
Collections.sort(componentNamesUnderCursor);
|
||||
refreshStatusText();
|
||||
break;
|
||||
case STATUS_MESSAGE_CHANGED:
|
||||
statusMessage = (String) params[0];
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshStatusText() {
|
||||
String statusText = this.statusMessage;
|
||||
String statusText = "";
|
||||
if (componentSlot == null) {
|
||||
if (componentNamesUnderCursor != null && !componentNamesUnderCursor.isEmpty()) {
|
||||
String formattedNames = Utils.toCommaString(componentNamesUnderCursor);
|
||||
@@ -269,6 +258,8 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
builder.append(")");
|
||||
}
|
||||
statusText = "<html>Selection: " + builder.toString() + "</html>";
|
||||
} else {
|
||||
statusText = "";
|
||||
}
|
||||
} else {
|
||||
switch (componentSlot.getCreationMethod()) {
|
||||
@@ -279,13 +270,12 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
} else {
|
||||
count = "second";
|
||||
}
|
||||
statusText = "<html>Click on the canvas to set the " + count
|
||||
+ " control point of a new <font color='blue'>" + componentSlot.getName()
|
||||
+ "</font> or press <b>Esc</b> to cancel</html>";
|
||||
statusText = "Click on the canvas to set the " + count + " control point of a new "
|
||||
+ componentSlot.getName() + " or press Esc to cancel";
|
||||
break;
|
||||
case SINGLE_CLICK:
|
||||
statusText = "<html>Click on the canvas to create a new <font color='blue'>"
|
||||
+ componentSlot.getName() + "</font> or press <b>Esc</b> to cancel</html>";
|
||||
statusText = "Click on the canvas to create a new " + componentSlot.getName()
|
||||
+ " or press Esc to cancel";
|
||||
break;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.toolbox;
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
@@ -0,0 +1,113 @@
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.presenter.ComparatorFactory;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
/**
|
||||
* Tabbed pane that shows all available components categorized into tabs.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
class ComponentTabbedPane extends JTabbedPane {
|
||||
|
||||
public static int SCROLL_STEP = Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 2;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final IPlugInPort plugInPort;
|
||||
|
||||
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
|
||||
List<String> categories = new ArrayList<String>(componentTypes.keySet());
|
||||
Collections.sort(categories);
|
||||
for (String category : categories) {
|
||||
JPanel panel = createTab((componentTypes.get(category)));
|
||||
addTab(category, panel);
|
||||
}
|
||||
setPreferredSize(new Dimension(-1, Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 38));
|
||||
}
|
||||
|
||||
private JPanel createTab(List<ComponentType> componentTypes) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
final JScrollPane scrollPane = createComponentScrollBar(componentTypes);
|
||||
panel.setOpaque(false);
|
||||
JButton leftButton = new JButton("<");
|
||||
leftButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Rectangle rect = scrollPane.getVisibleRect();
|
||||
if (rect.x > SCROLL_STEP) {
|
||||
rect.translate(-SCROLL_STEP, 0);
|
||||
} else {
|
||||
rect.translate(-rect.x, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
leftButton.setMargin(new Insets(0, 2, 0, 2));
|
||||
JButton rightButton = new JButton(">");
|
||||
rightButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Rectangle rect = scrollPane.getVisibleRect();
|
||||
if (rect.x + rect.width < scrollPane.getViewport().getSize().width - SCROLL_STEP) {
|
||||
rect.translate(SCROLL_STEP, 0);
|
||||
} else {
|
||||
rect.translate(scrollPane.getViewport().getSize().width - rect.x - rect.width,
|
||||
0);
|
||||
}
|
||||
}
|
||||
});
|
||||
rightButton.setMargin(new Insets(0, 2, 0, 2));
|
||||
panel.add(leftButton, BorderLayout.WEST);
|
||||
panel.add(scrollPane);
|
||||
panel.add(rightButton, BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JScrollPane createComponentScrollBar(List<ComponentType> componentTypes) {
|
||||
JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes));
|
||||
scrollPane.setOpaque(false);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
private Component createComponentPanel(List<ComponentType> componentTypes) {
|
||||
Container toolbar = new Container();
|
||||
Collections.sort(componentTypes, ComparatorFactory.getInstance()
|
||||
.getComponentTypeComparator());
|
||||
toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
|
||||
for (ComponentType componentType : componentTypes) {
|
||||
JButton button = new ComponentButton(plugInPort, componentType);
|
||||
toolbar.add(button);
|
||||
}
|
||||
return toolbar;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
|
||||
|
||||
public class ToolBox implements IPlugIn {
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
try {
|
||||
plugInPort.injectGUIComponent(new ComponentTabbedPane(plugInPort), SwingConstants.TOP);
|
||||
} catch (BadPositionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... params) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.toolbox;
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.diylc.swing.plugins.toolbox;
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.dnd.DragSourceDragEvent;
|
||||
import java.awt.dnd.DragSourceDropEvent;
|
||||
@@ -13,8 +13,8 @@ public class CalcUtils {
|
||||
* @return
|
||||
*/
|
||||
public static int roundToGrid(int x, Size gridSpacing) {
|
||||
double grid = gridSpacing.convertToPixels();
|
||||
return (int) (Math.round(1f * x / grid) * grid);
|
||||
int grid = gridSpacing.convertToPixels();
|
||||
return (Math.round(1f * x / grid) * grid);
|
||||
}
|
||||
|
||||
public static void snapPointToGrid(Point point, Size gridSpacing) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -13,7 +14,6 @@ public class ComparatorFactory {
|
||||
private Comparator<IDIYComponent<?>> componentNameComparator;
|
||||
private Comparator<ComponentType> componentTypeComparator;
|
||||
private Comparator<PropertyWrapper> propertyNameComparator;
|
||||
private Comparator<IDIYComponent<?>> componentZOrderComparator;
|
||||
|
||||
public static ComparatorFactory getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -53,6 +53,20 @@ public class ComparatorFactory {
|
||||
return componentTypeComparator;
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent<?>> getComponentZOrderComparator(
|
||||
final List<IDIYComponent<?>> components) {
|
||||
Comparator<IDIYComponent<?>> componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
int index1 = components.indexOf(o1);
|
||||
int index2 = components.indexOf(o2);
|
||||
return new Integer(index1).compareTo(index2);
|
||||
}
|
||||
};
|
||||
return componentZOrderComparator;
|
||||
}
|
||||
|
||||
public Comparator<PropertyWrapper> getPropertyNameComparator() {
|
||||
if (propertyNameComparator == null) {
|
||||
propertyNameComparator = new Comparator<PropertyWrapper>() {
|
||||
@@ -66,23 +80,4 @@ public class ComparatorFactory {
|
||||
}
|
||||
return propertyNameComparator;
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent<?>> getComponentZOrderComparator() {
|
||||
if (componentZOrderComparator == null) {
|
||||
componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
ComponentType type1 = ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) o1.getClass());
|
||||
ComponentType type2 = ComponentProcessor.getInstance()
|
||||
.extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) o2.getClass());
|
||||
return new Double(type1.getZOrder()).compareTo(type2.getZOrder());
|
||||
}
|
||||
};
|
||||
}
|
||||
return componentZOrderComparator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ 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;
|
||||
|
||||
@@ -36,9 +35,7 @@ public class ComponentProcessor {
|
||||
|
||||
private static ComponentProcessor instance;
|
||||
|
||||
private Map<String, List<PropertyWrapper>> propertyCache;
|
||||
private Map<String, IPropertyValidator> propertyValidatorCache;
|
||||
private Map<String, ComponentType> componentTypeMap;
|
||||
private Map<Class<?>, List<PropertyWrapper>> propertyCache;
|
||||
|
||||
private Cloner cloner;
|
||||
|
||||
@@ -52,15 +49,10 @@ public class ComponentProcessor {
|
||||
private ComponentProcessor() {
|
||||
super();
|
||||
this.cloner = new Cloner();
|
||||
this.propertyCache = new HashMap<String, List<PropertyWrapper>>();
|
||||
this.componentTypeMap = new HashMap<String, ComponentType>();
|
||||
this.propertyValidatorCache = new HashMap<String, IPropertyValidator>();
|
||||
this.propertyCache = new HashMap<Class<?>, List<PropertyWrapper>>();
|
||||
}
|
||||
|
||||
public ComponentType extractComponentTypeFrom(Class<? extends IDIYComponent<?>> clazz) {
|
||||
if (componentTypeMap.containsKey(clazz.getName())) {
|
||||
return componentTypeMap.get(clazz.getName());
|
||||
}
|
||||
public ComponentType createComponentTypeFrom(Class<? extends IDIYComponent<?>> clazz) {
|
||||
String name;
|
||||
String description;
|
||||
CreationMethod creationMethod;
|
||||
@@ -109,7 +101,6 @@ public class ComponentProcessor {
|
||||
}
|
||||
ComponentType componentType = new ComponentType(name, description, creationMethod,
|
||||
category, namePrefix, author, icon, clazz, zOrder, stretchable);
|
||||
componentTypeMap.put(clazz.getName(), componentType);
|
||||
return componentType;
|
||||
}
|
||||
|
||||
@@ -120,8 +111,8 @@ public class ComponentProcessor {
|
||||
* @return
|
||||
*/
|
||||
public List<PropertyWrapper> extractProperties(Class<?> clazz) {
|
||||
if (propertyCache.containsKey(clazz.getName())) {
|
||||
return cloner.deepClone(propertyCache.get(clazz.getName()));
|
||||
if (propertyCache.containsKey(clazz)) {
|
||||
return cloner.deepClone(propertyCache.get(clazz));
|
||||
}
|
||||
List<PropertyWrapper> properties = new ArrayList<PropertyWrapper>();
|
||||
for (Method method : clazz.getMethods()) {
|
||||
@@ -136,13 +127,10 @@ public class ComponentProcessor {
|
||||
} 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, setter, annotation.defaultable(),
|
||||
validator);
|
||||
method.getReturnType(), method, setter, annotation.defaultable());
|
||||
properties.add(property);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
@@ -152,7 +140,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
propertyCache.put(clazz.getName(), properties);
|
||||
propertyCache.put(clazz, properties);
|
||||
return cloner.deepClone(properties);
|
||||
}
|
||||
|
||||
@@ -193,19 +181,4 @@ public class ComponentProcessor {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ComponentZOrderFiler implements IComponentFiler {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean testComponent(IDIYComponent<?> component) {
|
||||
ComponentType componentType = ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
ComponentType componentType = ComponentProcessor.getInstance().createComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
return Math.round(componentType.getZOrder()) == zOrder;
|
||||
}
|
||||
|
||||
@@ -11,22 +11,21 @@ import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Area;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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.ComponentSelection;
|
||||
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;
|
||||
|
||||
@@ -41,20 +40,16 @@ import com.diyfever.gui.simplemq.MessageDispatcher;
|
||||
*/
|
||||
public class DrawingManager {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DrawingManager.class);
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
public static final String THEME_KEY = "theme";
|
||||
public static String DEBUG_COMPONENT_AREAS = "org.diylc.debugComponentAreas";
|
||||
public static boolean DEBUG_COMPONENT_AREAS = false;
|
||||
|
||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||
public static Color CONTROL_POINT_COLOR = Color.black;
|
||||
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
|
||||
|
||||
private Theme theme = new Theme("Light", Constants.CANVAS_COLOR, GRID_COLOR);
|
||||
|
||||
// Keeps Area object of each drawn component.
|
||||
private Map<IDIYComponent<?>, Area> componentAreaMap;
|
||||
// Maps components to the last state they are drawn in. Also, used to
|
||||
@@ -63,88 +58,33 @@ public class DrawingManager {
|
||||
|
||||
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>();
|
||||
|
||||
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
|
||||
// 1d);
|
||||
|
||||
private MessageDispatcher<EventType> messageDispatcher;
|
||||
|
||||
private boolean debugComponentAreas;
|
||||
|
||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||
super();
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
|
||||
debugComponentAreas = debugComponentAreasStr != null
|
||||
&& debugComponentAreasStr.equalsIgnoreCase("true");
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null);
|
||||
if (theme != null) {
|
||||
this.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project,
|
||||
Set<DrawOption> drawOptions, IComponentFiler filter, Rectangle selectionRect,
|
||||
List<IDIYComponent<?>> selectedComponents, Set<IDIYComponent<?>> lockedComponents,
|
||||
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
|
||||
IDIYComponent<?> componentSlot, boolean dragInProgress) {
|
||||
failedComponents.clear();
|
||||
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
|
||||
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
|
||||
Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents,
|
||||
List<Point> controlPointSlot, IDIYComponent<?> componentSlot, boolean dragInProgress) {
|
||||
if (project == null) {
|
||||
return failedComponents;
|
||||
return;
|
||||
}
|
||||
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
|
||||
|
||||
if (drawOptions.contains(DrawOption.ANTIALIASING)) {
|
||||
if (drawOptions.contains(DrawOption.ANTIALIASING)
|
||||
&& ConfigurationManager.getInstance().readBoolean(ANTIALIASING_KEY, true)) {
|
||||
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;
|
||||
@@ -157,11 +97,12 @@ public class DrawingManager {
|
||||
// AffineTransform initialTx = g2d.getTransform();
|
||||
Dimension d = getCanvasDimensions(project, zoom, true);
|
||||
|
||||
g2dWrapper.setColor(theme.getBgColor());
|
||||
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
g2d.clip(new Rectangle(new Point(0, 0), d));
|
||||
g2d.setClip(new Rectangle(new Point(0, 0), d));
|
||||
|
||||
GridType gridType = GridType.LINES;
|
||||
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
||||
ANTIALIASING_KEY, GridType.LINES);
|
||||
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
|
||||
double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
|
||||
if (gridType == GridType.CROSSHAIR) {
|
||||
@@ -173,7 +114,7 @@ public class DrawingManager {
|
||||
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
|
||||
}
|
||||
|
||||
g2dWrapper.setColor(theme.getGridColor());
|
||||
g2dWrapper.setColor(GRID_COLOR);
|
||||
for (double i = zoomStep; i < d.width; i += zoomStep) {
|
||||
g2dWrapper.drawLine((int) i, 0, (int) i, d.height - 1);
|
||||
}
|
||||
@@ -219,14 +160,9 @@ public class DrawingManager {
|
||||
g2d.setComposite(lockedComposite);
|
||||
}
|
||||
// Draw the component through the g2dWrapper.
|
||||
try {
|
||||
component.draw(g2dWrapper, state, project, g2dWrapper);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error drawing " + component.getName(), e);
|
||||
failedComponents.add(component);
|
||||
}
|
||||
component.draw(g2dWrapper, state, project, g2dWrapper);
|
||||
Area area = g2dWrapper.finishedDrawingComponent();
|
||||
if (trackArea && area != null && !area.isEmpty()) {
|
||||
if (trackArea) {
|
||||
componentAreaMap.put(component, area);
|
||||
lastDrawnStateMap.put(component, state);
|
||||
}
|
||||
@@ -235,24 +171,22 @@ public class DrawingManager {
|
||||
// Draw control points.
|
||||
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
||||
// Draw unselected points first to make sure they are below.
|
||||
if (dragInProgress) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,12 +216,7 @@ public class DrawingManager {
|
||||
if (componentSlot != null) {
|
||||
g2dWrapper.startedDrawingComponent();
|
||||
g2dWrapper.setComposite(slotComposite);
|
||||
try {
|
||||
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error drawing " + componentSlot.getName(), e);
|
||||
failedComponents.add(componentSlot);
|
||||
}
|
||||
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
|
||||
g2dWrapper.finishedDrawingComponent();
|
||||
}
|
||||
|
||||
@@ -324,15 +253,13 @@ public class DrawingManager {
|
||||
}
|
||||
|
||||
// Draw component area for test
|
||||
if (debugComponentAreas) {
|
||||
if (DEBUG_COMPONENT_AREAS) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(Color.red);
|
||||
for (Area area : componentAreaMap.values()) {
|
||||
g2d.draw(area);
|
||||
}
|
||||
}
|
||||
|
||||
return failedComponents;
|
||||
}
|
||||
|
||||
public double getZoomLevel() {
|
||||
@@ -354,24 +281,22 @@ public class DrawingManager {
|
||||
return componentAreaMap.get(component);
|
||||
}
|
||||
|
||||
public void clearComponentAreaMap() {
|
||||
componentAreaMap.clear();
|
||||
}
|
||||
|
||||
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
|
||||
List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
|
||||
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));
|
||||
for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) {
|
||||
if (entry.getValue().contains(point)) {
|
||||
components.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
// Sort by z-order.
|
||||
Collections.sort(components, ComparatorFactory.getInstance().getComponentZOrderComparator(
|
||||
project.getComponents()));
|
||||
return components;
|
||||
}
|
||||
|
||||
public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) {
|
||||
double width = project.getWidth().convertToPixels();
|
||||
double height = project.getHeight().convertToPixels();
|
||||
int height = project.getHeight().convertToPixels();
|
||||
if (useZoom) {
|
||||
width *= zoomLevel;
|
||||
height *= zoomLevel;
|
||||
@@ -386,14 +311,4 @@ public class DrawingManager {
|
||||
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(THEME_KEY, theme);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,6 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
|
||||
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;
|
||||
@@ -493,9 +492,8 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
|
||||
|
||||
@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;
|
||||
// FIXME: map
|
||||
return canvasGraphics.drawImage(img, x, y, observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ public class InstantiationManager {
|
||||
private Point potentialControlPoint;
|
||||
|
||||
public InstantiationManager() {
|
||||
cloner = new Cloner();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ComponentType getComponentTypeSlot() {
|
||||
@@ -80,22 +80,14 @@ public class InstantiationManager {
|
||||
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);
|
||||
public void updatePointByPoint(Point scaledPoint) {
|
||||
potentialControlPoint = scaledPoint;
|
||||
if (componentSlot != null) {
|
||||
componentSlot.setControlPoint(scaledPoint, 1);
|
||||
}
|
||||
return changeMade;
|
||||
}
|
||||
|
||||
public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
|
||||
public void updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
|
||||
if (potentialControlPoint == null) {
|
||||
potentialControlPoint = new Point(0, 0);
|
||||
}
|
||||
@@ -107,7 +99,7 @@ public class InstantiationManager {
|
||||
}
|
||||
// Only repaint if there's an actual change.
|
||||
if (dx == 0 && dy == 0) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
potentialControlPoint.translate(dx, dy);
|
||||
if (componentSlot == null) {
|
||||
@@ -120,7 +112,6 @@ public class InstantiationManager {
|
||||
componentSlot.setControlPoint(p, i);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IDIYComponent<?> instantiateComponent(ComponentType componentType, Point point,
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes {@link Point} objects by converting coordinates from pixels to
|
||||
* inches, thus avoiding the resolution to affect point placement.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class PointConverter implements Converter {
|
||||
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
Point point = (Point) object;
|
||||
writer.addAttribute("x", Double.toString(1d * point.x / Constants.PIXELS_PER_INCH));
|
||||
writer.addAttribute("y", Double.toString(1d * point.y / Constants.PIXELS_PER_INCH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
double x = Double.parseDouble(reader.getAttribute("x"));
|
||||
double y = Double.parseDouble(reader.getAttribute("y"));
|
||||
return new Point((int) Math.round(x * Constants.PIXELS_PER_INCH), (int) Math.round(y
|
||||
* Constants.PIXELS_PER_INCH));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return Point.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,10 +6,6 @@ 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;
|
||||
@@ -23,17 +19,11 @@ 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;
|
||||
@@ -55,22 +45,10 @@ public class ProjectFileManager {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ProjectFileManager.class);
|
||||
|
||||
// private static final int V1_PIXELS_PER_INCH = 200;
|
||||
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<String, Color> V1_COLOR_MAP = new HashMap<String, Color>();
|
||||
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 XStream xStream = new XStream(new DomDriver());
|
||||
|
||||
private String currentFileName = null;
|
||||
private boolean modified = false;
|
||||
@@ -79,38 +57,22 @@ public class ProjectFileManager {
|
||||
|
||||
public ProjectFileManager(MessageDispatcher<EventType> 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));
|
||||
}
|
||||
public void serializeProjectToFile(Project project, String fileName) throws IOException {
|
||||
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();
|
||||
}
|
||||
this.currentFileName = fileName;
|
||||
this.modified = false;
|
||||
fireFileStatusChanged();
|
||||
}
|
||||
|
||||
public Project deserializeProjectFromFile(String fileName, List<String> warnings)
|
||||
throws SAXException, IOException, ParserConfigurationException {
|
||||
public Project deserializeProjectFromFile(String fileName) throws SAXException, IOException,
|
||||
ParserConfigurationException {
|
||||
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
||||
Project project;
|
||||
File file = new File(fileName);
|
||||
@@ -128,7 +90,7 @@ public class ProjectFileManager {
|
||||
String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
|
||||
if (formatVersion == null || formatVersion.trim().isEmpty()) {
|
||||
LOG.debug("Detected v1 file.");
|
||||
project = parseV1File(doc.getDocumentElement(), warnings);
|
||||
project = parseV1File(doc.getDocumentElement());
|
||||
} else if (formatVersion.equals("2.0")) {
|
||||
LOG.debug("Detected v2 file.");
|
||||
project = parseV2File(doc.getDocumentElement());
|
||||
@@ -136,7 +98,6 @@ public class ProjectFileManager {
|
||||
throw new IllegalArgumentException("Unknown file format version: " + formatVersion);
|
||||
}
|
||||
}
|
||||
Collections.sort(warnings);
|
||||
this.currentFileName = fileName;
|
||||
this.modified = false;
|
||||
return project;
|
||||
@@ -160,7 +121,7 @@ public class ProjectFileManager {
|
||||
isModified());
|
||||
}
|
||||
|
||||
private Project parseV1File(Element root, List<String> warnings) {
|
||||
private Project parseV1File(Element root) {
|
||||
Project project = new Project();
|
||||
project.setTitle(root.getAttribute("Project"));
|
||||
project.setAuthor(root.getAttribute("Credits"));
|
||||
@@ -172,8 +133,8 @@ public class ProjectFileManager {
|
||||
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 projectWidth = project.getWidth().convertToPixels();
|
||||
int projectHeight = project.getHeight().convertToPixels();
|
||||
int x = (projectWidth - boardWidth) / 2;
|
||||
int y = (projectHeight - boardHeight) / 2;
|
||||
AbstractBoard board;
|
||||
@@ -189,11 +150,11 @@ public class ProjectFileManager {
|
||||
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));
|
||||
Point referencePoint = new Point(roundToGrid(x, V1_GRID_SPACING), 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);
|
||||
board.setControlPoint(new Point(roundToGrid(x + boardWidth, V1_GRID_SPACING), roundToGrid(y
|
||||
+ boardHeight, V1_GRID_SPACING)), 1);
|
||||
project.getComponents().add(board);
|
||||
|
||||
NodeList childNodes = root.getChildNodes();
|
||||
@@ -212,11 +173,6 @@ public class ProjectFileManager {
|
||||
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")
|
||||
@@ -226,35 +182,20 @@ public class ProjectFileManager {
|
||||
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")) {
|
||||
if (nodeName.equalsIgnoreCase("pad")) {
|
||||
LOG.debug("Recognized " + nodeName);
|
||||
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
||||
SolderPad pad = new SolderPad();
|
||||
pad.setName(nameAttr);
|
||||
if (color != null) {
|
||||
pad.setColor(color);
|
||||
}
|
||||
// pad.setColor(Color.getColor(colorAttr));
|
||||
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
|
||||
y1Attr), 0);
|
||||
component = pad;
|
||||
} else if (nodeName.equalsIgnoreCase("trace")) {
|
||||
LOG.debug("Recognized " + nodeName);
|
||||
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
|
||||
CopperTrace trace = new CopperTrace();
|
||||
trace.setName(nameAttr);
|
||||
if (color != null) {
|
||||
trace.setLeadColor(color);
|
||||
}
|
||||
trace.setControlPoint(point1, 0);
|
||||
trace.setControlPoint(point2, 1);
|
||||
component = trace;
|
||||
@@ -265,16 +206,6 @@ public class ProjectFileManager {
|
||||
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();
|
||||
@@ -284,8 +215,8 @@ public class ProjectFileManager {
|
||||
} 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.setWidth(new Size(6d, SizeUnit.mm));
|
||||
resistor.setHeight(new Size(2d, SizeUnit.mm));
|
||||
resistor.setControlPoint(point1, 0);
|
||||
resistor.setControlPoint(point2, 1);
|
||||
component = resistor;
|
||||
@@ -298,79 +229,11 @@ public class ProjectFileManager {
|
||||
} 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.setWidth(new Size(6d, SizeUnit.mm));
|
||||
capacitor.setHeight(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();
|
||||
@@ -387,28 +250,17 @@ public class ProjectFileManager {
|
||||
}
|
||||
}
|
||||
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.setControlPoint(point1, 0);
|
||||
ic.setValue(valueAttr);
|
||||
component = ic;
|
||||
} else {
|
||||
String message = "Could not recognize component type " + nodeName;
|
||||
LOG.debug(message);
|
||||
if (!warnings.contains(message)) {
|
||||
warnings.add(message);
|
||||
}
|
||||
LOG.debug("Could not recognize component type " + nodeName);
|
||||
}
|
||||
if (component != null) {
|
||||
project.getComponents().add(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(project.getComponents(), ComparatorFactory.getInstance()
|
||||
.getComponentZOrderComparator());
|
||||
return project;
|
||||
}
|
||||
|
||||
@@ -442,15 +294,13 @@ public class ProjectFileManager {
|
||||
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);
|
||||
}
|
||||
project = (Project) xStream.fromXML(fis);
|
||||
fis.close();
|
||||
return project;
|
||||
}
|
||||
|
||||
public int roundToGrid(int x, Size gridSpacing) {
|
||||
int grid = gridSpacing.convertToPixels();
|
||||
return (Math.round(1f * x / grid) * grid);
|
||||
}
|
||||
}
|
||||
@@ -1,845 +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);
|
||||
}
|
||||
|
||||
// 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<PropertyWrapper> 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<Void>() {
|
||||
|
||||
@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<Void>() {
|
||||
|
||||
@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<Void>() {
|
||||
|
||||
@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<Void>() {
|
||||
|
||||
@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<BomEntry> 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<Void>() {
|
||||
|
||||
@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<Void>() {
|
||||
|
||||
@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<IDIYComponent<?>> components = (List<IDIYComponent<?>>) 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<PropertyWrapper> 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<PropertyWrapper> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user