mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
allow extra space around the layout
introduced ability to render just the visible part of the layout for better performance
This commit is contained in:
@@ -56,5 +56,9 @@ public enum DrawOption {
|
||||
/**
|
||||
* Draw components in outline mode.
|
||||
*/
|
||||
OUTLINE_MODE;
|
||||
OUTLINE_MODE,
|
||||
/**
|
||||
* Include extra space around the layout.
|
||||
*/
|
||||
EXTRA_SPACE;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
public static final String SHOW_RULERS_KEY = "showRulers";
|
||||
public static final String SHOW_GRID_KEY = "showGrid";
|
||||
public static final String HIGHLIGHT_CONTINUITY_AREA = "highlightContinuityArea";
|
||||
public static final String HARDWARE_ACCELERATION = "hardwareAcceleration";
|
||||
public static final String HARDWARE_ACCELERATION = "hardwareAcceleration";
|
||||
public static final String EXTRA_SPACE_KEY = "extraSpace";
|
||||
|
||||
public static final int DND_TOGGLE_STICKY = 0x1;
|
||||
public static final int DND_TOGGLE_SNAP = 0x40000000;
|
||||
@@ -91,11 +92,12 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
* Each dimension is calculated as the product of the actual size and the number of pixels per
|
||||
* unit. If <code>useZoom</code> is set to true, the result is scaled by zoom factor.
|
||||
*
|
||||
* @param useZoom
|
||||
* @param useZoom
|
||||
* @param includeExtraSpace
|
||||
*
|
||||
* @return canvas dimensions
|
||||
*/
|
||||
Dimension getCanvasDimensions(boolean useZoom);
|
||||
Dimension getCanvasDimensions(boolean useZoom, boolean includeExtraSpace);
|
||||
|
||||
/**
|
||||
* Returns an instance of {@link Cursor} that should be used at the specified location.
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CalcUtils {
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static int roundToGrid(int x, Size gridSpacing) {
|
||||
public static int roundToGrid(double x, Size gridSpacing) {
|
||||
double grid = gridSpacing.convertToPixels();
|
||||
return (int) (Math.round(1f * x / grid) * grid);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -65,6 +67,7 @@ public class DrawingManager {
|
||||
private static final Logger LOG = Logger.getLogger(DrawingManager.class);
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
public static double EXTRA_SPACE = 0.2;
|
||||
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
|
||||
@@ -141,7 +144,7 @@ public class DrawingManager {
|
||||
} else {
|
||||
zoom = 1 / Constants.PIXEL_SIZE;
|
||||
}
|
||||
|
||||
|
||||
if (externalZoom != null)
|
||||
zoom *= externalZoom;
|
||||
|
||||
@@ -171,7 +174,7 @@ public class DrawingManager {
|
||||
}
|
||||
|
||||
// AffineTransform initialTx = g2d.getTransform();
|
||||
Dimension d = getCanvasDimensions(project, zoom, true);
|
||||
Dimension d = getCanvasDimensions(project, zoom, drawOptions.contains(DrawOption.EXTRA_SPACE));
|
||||
|
||||
g2dWrapper.setColor(theme.getBgColor());
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
@@ -185,8 +188,8 @@ public class DrawingManager {
|
||||
g2d.setStroke(new BasicStroke(gridThickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] {
|
||||
(float) zoomStep / 2, (float) zoomStep / 2}, (float) zoomStep / 4));
|
||||
} else if (gridType == GridType.DOT) {
|
||||
g2d.setStroke(new BasicStroke(gridThickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] {1f,
|
||||
(float) zoomStep - 1}, 0f));
|
||||
g2d.setStroke(new BasicStroke(gridThickness, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] {
|
||||
1f, (float) zoomStep - 1}, 0f));
|
||||
} else {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchZoomableStroke(gridThickness));
|
||||
}
|
||||
@@ -199,11 +202,26 @@ public class DrawingManager {
|
||||
g2dWrapper.draw(new Line2D.Double(0, j, d.width - 1, j));
|
||||
}
|
||||
}
|
||||
|
||||
// manage extra space
|
||||
double extraSpace = 0;
|
||||
if (drawOptions.contains(DrawOption.EXTRA_SPACE)) {
|
||||
Dimension dInner = getCanvasDimensions(project, zoom, false);
|
||||
extraSpace = getExtraSpace(project) * zoom;
|
||||
float borderThickness = (float) (3f * (zoom > 1 ? 1 : zoom));
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchStroke(borderThickness, new float[] {borderThickness * 4, borderThickness * 4, }, 0, BasicStroke.CAP_BUTT));
|
||||
g2dWrapper.setColor(theme.getOutlineColor());
|
||||
g2d.draw(new Rectangle2D.Double(extraSpace, extraSpace, dInner.getWidth(), dInner.getHeight()));
|
||||
|
||||
// translate to the new (0, 0)
|
||||
g2d.transform(AffineTransform.getTranslateInstance(extraSpace, extraSpace));
|
||||
}
|
||||
|
||||
// apply zoom
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2dWrapper.scale(zoom, zoom);
|
||||
}
|
||||
|
||||
|
||||
// Composite mainComposite = g2d.getComposite();
|
||||
// Composite alphaComposite =
|
||||
// AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
|
||||
@@ -363,9 +381,9 @@ public class DrawingManager {
|
||||
g2d.draw(a);
|
||||
}
|
||||
}
|
||||
|
||||
if (continuityArea != null && (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false)))
|
||||
{
|
||||
|
||||
if (continuityArea != null
|
||||
&& (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
||||
g2d.setColor(Color.green);
|
||||
@@ -399,7 +417,7 @@ public class DrawingManager {
|
||||
componentAreaMap.clear();
|
||||
lastDrawnStateMap.clear();
|
||||
}
|
||||
|
||||
|
||||
public void clearContinuityArea() {
|
||||
this.continuityArea = null;
|
||||
}
|
||||
@@ -415,16 +433,26 @@ public class DrawingManager {
|
||||
return components;
|
||||
}
|
||||
|
||||
public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) {
|
||||
public double getExtraSpace(Project project) {
|
||||
double width = project.getWidth().convertToPixels();
|
||||
double height = project.getHeight().convertToPixels();
|
||||
if (useZoom) {
|
||||
width *= zoomLevel;
|
||||
height *= zoomLevel;
|
||||
} else {
|
||||
width /= Constants.PIXEL_SIZE;
|
||||
height /= Constants.PIXEL_SIZE;
|
||||
double targetExtraSpace = EXTRA_SPACE * Math.max(width, height);
|
||||
return CalcUtils.roundToGrid(targetExtraSpace, project.getGridSpacing());
|
||||
}
|
||||
|
||||
public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean includeExtraSpace) {
|
||||
double width = project.getWidth().convertToPixels();
|
||||
double height = project.getHeight().convertToPixels();
|
||||
|
||||
if (includeExtraSpace) {
|
||||
double extraSpace = getExtraSpace(project);
|
||||
width += 2 * extraSpace;
|
||||
height += 2 * extraSpace;
|
||||
}
|
||||
|
||||
width *= zoomLevel;
|
||||
height *= zoomLevel;
|
||||
|
||||
return new Dimension((int) width, (int) height);
|
||||
}
|
||||
|
||||
@@ -481,8 +509,8 @@ public class DrawingManager {
|
||||
List<Area> areas = new ArrayList<Area>();
|
||||
for (int i = 0; i < preliminaryAreas.size(); i++) {
|
||||
Area a = preliminaryAreas.get(i);
|
||||
// if (checkBreakout.get(i))
|
||||
areas.addAll(tryBreakout(a));
|
||||
// if (checkBreakout.get(i))
|
||||
areas.addAll(tryBreakout(a));
|
||||
// else
|
||||
// areas.add(a);
|
||||
}
|
||||
|
||||
@@ -250,8 +250,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getCanvasDimensions(boolean useZoom) {
|
||||
return drawingManager.getCanvasDimensions(currentProject, drawingManager.getZoomLevel(), useZoom);
|
||||
public Dimension getCanvasDimensions(boolean useZoom, boolean includeExtraSpace) {
|
||||
return drawingManager.getCanvasDimensions(currentProject, useZoom ? drawingManager.getZoomLevel() : 1/ Constants.PIXEL_SIZE, includeExtraSpace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1182,8 +1182,10 @@ public class Presenter implements IPlugInPort {
|
||||
int actualDy = 0;
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will overlap or go out of bounds.
|
||||
int width = (int) currentProject.getWidth().convertToPixels();
|
||||
int height = (int) currentProject.getHeight().convertToPixels();
|
||||
|
||||
boolean useExtraSpace = ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true);
|
||||
Dimension d = drawingManager.getCanvasDimensions(currentProject, 1d, useExtraSpace);
|
||||
double extraSpace = useExtraSpace ? drawingManager.getExtraSpace(currentProject) : 0;
|
||||
|
||||
if (controlPointMap.size() == 1) {
|
||||
Map.Entry<IDIYComponent<?>, Set<Integer>> entry = controlPointMap.entrySet().iterator().next();
|
||||
@@ -1220,8 +1222,9 @@ public class Presenter implements IPlugInPort {
|
||||
// actually moved after snapping.
|
||||
if (entry.getValue().contains(index)) {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0 || controlPoints[index].x > width
|
||||
|| controlPoints[index].y > height) {
|
||||
controlPoints[index].translate((int)extraSpace, (int)extraSpace);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0 || controlPoints[index].x > d.width
|
||||
|| controlPoints[index].y > d.height) {
|
||||
// At least one control point went out of bounds.
|
||||
return null;
|
||||
}
|
||||
@@ -2424,8 +2427,14 @@ public class Presenter implements IPlugInPort {
|
||||
* @return
|
||||
*/
|
||||
private Point scalePoint(Point point) {
|
||||
return point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
Point p = point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
(int) (point.y / drawingManager.getZoomLevel()));
|
||||
|
||||
if (p != null && ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
p.translate((int)(-extraSpace), (int)(-extraSpace));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Binary file not shown.
@@ -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;javaProject name=&quot;diylc-core&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-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;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-swing"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:splash.png -Xms256m -Xmx512m -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Dorg.diylc.WriteStaticVariants=true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:splash.png -Xms256m -Xmx512m -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Dorg.diylc.WriteStaticVariants=true -Ddorg.diylc.debugComponentAreas=true"/>
|
||||
</launchConfiguration>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -235,7 +235,7 @@ public class TemplateDialog extends JDialog {
|
||||
File file = (File) fileList.getSelectedValue();
|
||||
if (file != null) {
|
||||
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
Dimension dim = presenter.getCanvasDimensions(true);
|
||||
Dimension dim = presenter.getCanvasDimensions(true, true);
|
||||
double xFactor = panelSize.getWidth() / dim.getWidth();
|
||||
double yFactor = panelSize.getHeight() / dim.getHeight();
|
||||
presenter.setZoomLevel(Math.min(xFactor, yFactor));
|
||||
|
||||
@@ -67,7 +67,9 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||
|
||||
public static boolean RENDER_VISIBLE_RECT_ONLY = true;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
@@ -208,12 +210,23 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
}
|
||||
|
||||
protected void createBufferImage() {
|
||||
protected void createBufferImage() {
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
Rectangle visibleRect = getVisibleRect();
|
||||
imageWidth = visibleRect.width;
|
||||
imageHeight = visibleRect.height;
|
||||
} else {
|
||||
imageWidth = getWidth();
|
||||
imageHeight = getHeight();
|
||||
}
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(), getHeight());
|
||||
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
|
||||
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||
} else {
|
||||
bufferImage = createImage(getWidth(), getHeight());
|
||||
bufferImage = createImage(imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,8 +238,21 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
g2d.setClip(getVisibleRect());
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
|
||||
Rectangle visibleRect = getVisibleRect();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
x = visibleRect.x;
|
||||
y = visibleRect.y;
|
||||
g2d.translate(-x, -y);
|
||||
} else {
|
||||
g2d.setClip(visibleRect);
|
||||
}
|
||||
|
||||
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ANTIALIASING);
|
||||
@@ -236,8 +262,13 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
|
||||
drawOptions.add(DrawOption.GRID);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
|
||||
drawOptions.add(DrawOption.EXTRA_SPACE);
|
||||
}
|
||||
plugInPort.draw(g2d, drawOptions, null, null);
|
||||
|
||||
plugInPort.draw(g2d, drawOptions, null, null);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
@@ -250,13 +281,13 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, 0, 0, this);
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
}
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, 0, 0, this);
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
// bufferImage.flush();
|
||||
}
|
||||
g2d.dispose();
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -106,7 +108,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private Clipboard clipboard;
|
||||
|
||||
private double zoomLevel = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI) {
|
||||
@@ -125,6 +127,27 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
getScrollPane().setRulerVisible(ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||
|
||||
// revalidate canvas on scrolling when we render visible rect only
|
||||
if (CanvasPanel.RENDER_VISIBLE_RECT_ONLY) {
|
||||
getScrollPane().getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
||||
|
||||
@Override
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
getCanvasPanel().invalidateCache();
|
||||
getCanvasPanel().revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
getScrollPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
|
||||
|
||||
@Override
|
||||
public void adjustmentValueChanged(AdjustmentEvent e) {
|
||||
getCanvasPanel().invalidateCache();
|
||||
getCanvasPanel().revalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.SHOW_RULERS_KEY, new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -133,30 +156,44 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
getScrollPane().setRulerVisible((Boolean) value);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION, new IConfigListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
canvasPanel.setUseHardwareAcceleration((Boolean) value);
|
||||
scrollPane.setUseHardwareAcceleration((Boolean) value);
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.EXTRA_SPACE_KEY, new IConfigListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(String key, Object value) {
|
||||
refreshSize();
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CanvasPanel getCanvasPanel() {
|
||||
if (canvasPanel == null) {
|
||||
canvasPanel = new CanvasPanel(plugInPort);
|
||||
canvasPanel.addMouseListener(new MouseAdapter() {
|
||||
|
||||
|
||||
private MouseEvent pressedEvent;
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (scrollPane.isMouseScrollMode() || e.getButton() == MouseEvent.BUTTON2)
|
||||
return;
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown(),
|
||||
e.getClickCount());
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||
e.isShiftDown(), e.isAltDown(), e.getClickCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,7 +211,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugInPort.getNewComponentTypeSlot() == null && (e.isPopupTrigger() || (pressedEvent != null && pressedEvent.isPopupTrigger()))) {
|
||||
if (plugInPort.getNewComponentTypeSlot() == null
|
||||
&& (e.isPopupTrigger() || (pressedEvent != null && pressedEvent.isPopupTrigger()))) {
|
||||
// Enable actions.
|
||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||
getCutAction().setEnabled(enabled);
|
||||
@@ -214,7 +252,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown())) {
|
||||
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||
e.isShiftDown(), e.isAltDown())) {
|
||||
e.consume();
|
||||
}
|
||||
}
|
||||
@@ -227,7 +266,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
if (scrollPane.isMouseScrollMode())
|
||||
return;
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown());
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
|
||||
e.isAltDown());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -237,11 +277,12 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
scrollPane =
|
||||
new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(plugInPort, true, false), new Size(1d,
|
||||
new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(plugInPort, true, false, true), new Size(1d,
|
||||
SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in).convertToPixels());
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
|
||||
|
||||
boolean useHardwareAcceleration = ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
|
||||
boolean useHardwareAcceleration =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
scrollPane.setUseHardwareAcceleration(useHardwareAcceleration);
|
||||
|
||||
scrollPane.setMetric(metric);
|
||||
@@ -655,7 +696,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
|
||||
private void refreshSize() {
|
||||
Dimension d = plugInPort.getCanvasDimensions(true);
|
||||
Dimension d =
|
||||
plugInPort.getCanvasDimensions(true,
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||
canvasPanel.setSize(d);
|
||||
canvasPanel.setPreferredSize(d);
|
||||
getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
|
||||
|
||||
@@ -216,7 +216,7 @@ public class UploadDialog extends ButtonDialog {
|
||||
}
|
||||
|
||||
private Dimension getThumbnailSize() {
|
||||
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false);
|
||||
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false, false);
|
||||
if (d.height > d.width)
|
||||
return new Dimension(192 * d.width / d.height, 192);
|
||||
else
|
||||
@@ -304,7 +304,7 @@ public class UploadDialog extends ButtonDialog {
|
||||
|
||||
private void paintThumbnail(Graphics g, Rectangle rect) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false);
|
||||
Dimension d = UploadDialog.this.plugInPort.getCanvasDimensions(false, false);
|
||||
|
||||
g2d.setColor(Color.white);
|
||||
g2d.fill(rect);
|
||||
|
||||
@@ -75,6 +75,9 @@ public class ConfigPlugin implements IPlugIn {
|
||||
swingUI.injectMenuAction(
|
||||
ActionFactory.getInstance().createConfigAction(plugInPort, "Export Grid", IPlugInPort.EXPORT_GRID_KEY, false),
|
||||
CONFIG_MENU);
|
||||
swingUI.injectMenuAction(
|
||||
ActionFactory.getInstance().createConfigAction(plugInPort, "Extra Working Area", IPlugInPort.EXTRA_SPACE_KEY, true),
|
||||
CONFIG_MENU);
|
||||
swingUI.injectMenuAction(
|
||||
ActionFactory.getInstance().createConfigAction(plugInPort, "Hardware Acceleration", IPlugInPort.HARDWARE_ACCELERATION, false),
|
||||
CONFIG_MENU);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false, true);
|
||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false, true, false);
|
||||
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
|
||||
|
||||
ActionFactory actionFactory = ActionFactory.getInstance();
|
||||
|
||||
@@ -41,18 +41,20 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private boolean useZoom;
|
||||
private boolean showGridWhenNeeded;
|
||||
private boolean showGridWhenNeeded;
|
||||
private boolean includeExtraSpace;
|
||||
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom, boolean showGridWhenNeeded) {
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom, boolean showGridWhenNeeded, boolean includeExtraSpace) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.useZoom = useZoom;
|
||||
this.showGridWhenNeeded = showGridWhenNeeded;
|
||||
this.showGridWhenNeeded = showGridWhenNeeded;
|
||||
this.includeExtraSpace = includeExtraSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return plugInPort.getCanvasDimensions(useZoom);
|
||||
return plugInPort.getCanvasDimensions(useZoom, includeExtraSpace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,6 +68,9 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
|
||||
drawOptions.add(DrawOption.OUTLINE_MODE);
|
||||
}
|
||||
if (includeExtraSpace) {
|
||||
drawOptions.add(DrawOption.EXTRA_SPACE);
|
||||
}
|
||||
plugInPort.draw((Graphics2D) g, drawOptions, null, zoomFactor);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
super.paint(g);
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Dimension d = presenter.getCanvasDimensions(false);
|
||||
Dimension d = presenter.getCanvasDimensions(false, false);
|
||||
// System.out.println(d);
|
||||
Rectangle rect = getBounds();
|
||||
// System.out.println(rect);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TraceMaskDrawingProvider implements IDrawingProvider {
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return plugInPort.getCanvasDimensions(false);
|
||||
return plugInPort.getCanvasDimensions(false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2393,7 +2393,15 @@
|
||||
</versionNumber>
|
||||
<releaseDate>2019-02-03 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added extra work space around the layout that can be used to store additional components and helpers, but does not get exported to a file. Configurable from the menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Vast improvement of rendering performance, especially with large layouts</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Create a backup of config file when there is an issue with loading (for example running two DIYLC versions on the same machine) to avoid data loss</description>
|
||||
|
||||
Reference in New Issue
Block a user