mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
fixed pdf scaling
changed few colors
This commit is contained in:
Binary file not shown.
+11
-9
@@ -40,15 +40,6 @@ public class DIYLCStarter {
|
||||
|
||||
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
|
||||
|
||||
url = DIYLCStarter.class.getResource("/config.properties");
|
||||
properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream("config.properties"));
|
||||
PropertyInjector.injectProperties(properties);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not read config.properties file", e);
|
||||
}
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception e) {
|
||||
@@ -58,5 +49,16 @@ public class DIYLCStarter {
|
||||
MainFrame mainFrame = new MainFrame();
|
||||
mainFrame.setLocationRelativeTo(null);
|
||||
mainFrame.setVisible(true);
|
||||
|
||||
url = DIYLCStarter.class.getResource("/config.properties");
|
||||
properties = new Properties();
|
||||
try {
|
||||
LOG.info("Injecting default properties.");
|
||||
properties.load(new FileInputStream("config.properties"));
|
||||
PropertyInjector.injectProperties(properties);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not read config.properties file", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import java.awt.Graphics;
|
||||
/**
|
||||
* Enumerates all options that can be used when drawing a project.
|
||||
*
|
||||
* @see IPlugInPort#draw(java.awt.Graphics2D, java.util.EnumSet)
|
||||
* @see IPlugInPort#draw(java.awt.Graphics2D, java.util.Set, IComponentFiler)
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
public static Color LEAD_COLOR = Color.decode("#236B8E");
|
||||
public static Color LABEL_COLOR = Color.black;
|
||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||
public static Size LEAD_THICKNESS = new Size(0.8d, SizeUnit.mm);
|
||||
public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
protected Size width;
|
||||
@@ -92,7 +92,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw leads.
|
||||
int leadThickness = getLeadThickness().convertToPixels();
|
||||
int leadThickness = getClosestOdd(getLeadThickness().convertToPixels());
|
||||
g2d.setStroke(new BasicStroke(leadThickness));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
|
||||
+1
-3
@@ -54,7 +54,7 @@ public class CanvasPlugin implements IPlugIn {
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
|
||||
plugInPort), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
|
||||
plugInPort, true), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
|
||||
SizeUnit.in).convertToPixels());
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
|
||||
true);
|
||||
@@ -86,8 +86,6 @@ public class CanvasPlugin implements IPlugIn {
|
||||
}
|
||||
plugInPort.setZoomLevel(availableZoomLevels[i]);
|
||||
}
|
||||
System.out.println(e);
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+19
-3
@@ -1,7 +1,9 @@
|
||||
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;
|
||||
|
||||
@@ -15,6 +17,7 @@ import org.diylc.images.IconLoader;
|
||||
|
||||
import com.diyfever.gui.IDrawingProvider;
|
||||
import com.diyfever.gui.export.DrawingExporter;
|
||||
import com.lowagie.text.DocumentException;
|
||||
|
||||
/**
|
||||
* Entry point class for File management utilities.
|
||||
@@ -33,7 +36,7 @@ public class FileMenuPlugin implements IPlugIn {
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort);
|
||||
this.drawingProvider = new ProjectDrawingProvider(plugInPort, false);
|
||||
this.traceMaskDrawingProvider = new TraceMaskDrawingProvider(plugInPort);
|
||||
|
||||
plugInPort.injectMenuAction(new NewAction(), FILE_TITLE);
|
||||
@@ -179,7 +182,15 @@ public class FileMenuPlugin implements IPlugIn {
|
||||
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(),
|
||||
null, FileFilterEnum.PDF.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
DrawingExporter.getInstance().exportPDF(this.drawingProvider, file);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,7 +233,12 @@ public class FileMenuPlugin implements IPlugIn {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
DrawingExporter.getInstance().print(this.drawingProvider);
|
||||
try {
|
||||
DrawingExporter.getInstance().print(this.drawingProvider);
|
||||
} catch (PrinterException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -19,19 +19,25 @@ import com.diyfever.gui.IDrawingProvider;
|
||||
public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private boolean useZoom;
|
||||
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort) {
|
||||
public ProjectDrawingProvider(IPlugInPort plugInPort, boolean useZoom) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.useZoom = useZoom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null);
|
||||
EnumSet<DrawOption> options = EnumSet.of(DrawOption.ANTIALIASING);
|
||||
if (useZoom) {
|
||||
options.add(DrawOption.ZOOM);
|
||||
}
|
||||
plugInPort.draw((Graphics2D) g, options, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return plugInPort.getCanvasDimensions(true);
|
||||
return plugInPort.getCanvasDimensions(useZoom);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,12 +32,12 @@ public class TraceMaskDrawingProvider implements IDrawingProvider {
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING),
|
||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ANTIALIASING),
|
||||
this.filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
return plugInPort.getCanvasDimensions(true);
|
||||
return plugInPort.getCanvasDimensions(false);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -187,7 +187,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
||||
switch (eventType) {
|
||||
case ZOOM_CHANGED:
|
||||
if (!params[0].equals(getZoomBox().getSelectedItem())) {
|
||||
getZoomBox().setSelectedItem(params[0]);
|
||||
final Double zoom = (Double) params[0];
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
getZoomBox().setSelectedItem(zoom);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case SELECTION_CHANGED:
|
||||
|
||||
+1
-7
@@ -174,13 +174,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public Dimension getCanvasDimensions(boolean useZoom) {
|
||||
double width = currentProject.getWidth().convertToPixels();
|
||||
int height = currentProject.getHeight().convertToPixels();
|
||||
if (useZoom) {
|
||||
width *= zoomLevel;
|
||||
height *= zoomLevel;
|
||||
}
|
||||
return new Dimension((int) width, (int) height);
|
||||
return projectPainter.getCanvasDimensions(currentProject, zoomLevel, useZoom);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+31
-8
@@ -40,6 +40,10 @@ public class ProjectPainter {
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
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;
|
||||
|
||||
// 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
|
||||
@@ -68,8 +72,15 @@ public class ProjectPainter {
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
double zoom = 1d;
|
||||
if (drawOptions.contains(DrawOption.ZOOM)) {
|
||||
zoom = zoomLevel;
|
||||
} else {
|
||||
zoom = 1 / Constants.PIXEL_SIZE;
|
||||
}
|
||||
|
||||
// AffineTransform initialTx = g2d.getTransform();
|
||||
Dimension d = getCanvasDimensions(project, zoomLevel, drawOptions.contains(DrawOption.ZOOM));
|
||||
Dimension d = getCanvasDimensions(project, zoom, true);
|
||||
|
||||
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
@@ -78,7 +89,7 @@ public class ProjectPainter {
|
||||
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
||||
ANTIALIASING_KEY, GridType.LINES);
|
||||
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
|
||||
double zoomStep = project.getGridSpacing().convertToPixels() * zoomLevel;
|
||||
double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
|
||||
if (gridType == GridType.CROSSHAIR) {
|
||||
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
|
||||
10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2 },
|
||||
@@ -88,7 +99,7 @@ public class ProjectPainter {
|
||||
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
|
||||
}
|
||||
|
||||
g2dWrapper.setColor(Constants.GRID_COLOR);
|
||||
g2dWrapper.setColor(GRID_COLOR);
|
||||
for (double i = zoomStep; i < d.width; i += zoomStep) {
|
||||
g2dWrapper.drawLine((int) i, 0, (int) i, d.height - 1);
|
||||
}
|
||||
@@ -97,8 +108,8 @@ public class ProjectPainter {
|
||||
}
|
||||
}
|
||||
|
||||
if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 - zoomLevel) > 1e-4)) {
|
||||
g2dWrapper.scale(zoomLevel, zoomLevel);
|
||||
if (Math.abs(1.0 - zoom) > 1e-4) {
|
||||
g2dWrapper.scale(zoom, zoom);
|
||||
}
|
||||
|
||||
// Composite mainComposite = g2d.getComposite();
|
||||
@@ -142,9 +153,13 @@ public class ProjectPainter {
|
||||
if (controlPointSlot != null) {
|
||||
for (Point point : controlPointSlot) {
|
||||
if (point != null) {
|
||||
g2dWrapper.setColor(Constants.SELECTED_CONTROL_POINT_COLOR);
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y
|
||||
- CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
||||
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y
|
||||
- CONTROL_POINT_SIZE / 2 + 1, CONTROL_POINT_SIZE - 2,
|
||||
CONTROL_POINT_SIZE - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +177,7 @@ public class ProjectPainter {
|
||||
.contains(component)
|
||||
&& !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(Constants.CONTROL_POINT_COLOR);
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
@@ -177,12 +192,17 @@ public class ProjectPainter {
|
||||
if (!groupedComponents.contains(component)
|
||||
&& (component.getControlPointVisibilityPolicy(i) == VisibilityPolicy.WHEN_SELECTED || component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS)) {
|
||||
g2dWrapper.setColor(Constants.SELECTED_CONTROL_POINT_COLOR);
|
||||
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE;
|
||||
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
|
||||
g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1,
|
||||
controlPoint.y - CONTROL_POINT_SIZE / 2 + 1,
|
||||
CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,6 +271,9 @@ public class ProjectPainter {
|
||||
if (useZoom) {
|
||||
width *= zoomLevel;
|
||||
height *= zoomLevel;
|
||||
} else {
|
||||
width /= Constants.PIXEL_SIZE;
|
||||
height /= Constants.PIXEL_SIZE;
|
||||
}
|
||||
return new Dimension((int) width, (int) height);
|
||||
}
|
||||
|
||||
+4
-4
@@ -4,15 +4,15 @@ import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final int PIXELS_PER_INCH = 150;//Toolkit.getDefaultToolkit().getScreenResolution();
|
||||
public static final int PIXELS_PER_INCH = 150;
|
||||
public static final double PIXEL_SIZE = 1d * PIXELS_PER_INCH
|
||||
/ Toolkit.getDefaultToolkit().getScreenResolution();
|
||||
|
||||
public static Color CANVAS_COLOR = Color.white;
|
||||
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.blue;
|
||||
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 12);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user