Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class PropertiesParserState {
private StickingPolygonGenerator stickingPolygonGenerator = SimpleStickingPolygonGenerator.INSTANCE;
private double totalTextBlockHeight;
private final Map<Class<? extends Facet>, Object> facetResponse = new HashMap<Class<? extends Facet>, Object>();
private String page;

public PropertiesParserState(Settings settings, DrawHandler drawer) {
this.settings = settings;
Expand All @@ -46,6 +47,7 @@ public void resetValues(Dimension gridElementSize, double totalTextBlockHeight,
this.totalTextBlockHeight = totalTextBlockHeight;
facetResponse.clear();
drawer.setEnableDrawing(enableDrawing);
page = "";
}

public Alignment getAlignment() {
Expand Down Expand Up @@ -152,4 +154,12 @@ public void setDrawer(DrawHandler drawer) {
this.drawer = drawer;
}

public void setPage(String page) {
this.page = page;
}

public String getPage() {
return page;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.baselet.element.facet.common.LayerFacet;
import com.baselet.element.facet.common.LineTypeFacet;
import com.baselet.element.facet.common.LineWidthFacet;
import com.baselet.element.facet.common.PageFacet;
import com.baselet.element.facet.common.SeparatorLineFacet;
import com.baselet.element.facet.common.TextPrintFacet;
import com.baselet.element.facet.common.TransparencyFacet;
Expand All @@ -39,7 +40,7 @@
*/
public abstract class Settings {
// the following lists are default facet configurations. they are declared here as a simple overview and for easy reuse
protected static final List<Facet> BASE = listOf(BackgroundColorFacet.INSTANCE, TransparencyFacet.INSTANCE, ForegroundColorFacet.INSTANCE, LayerFacet.INSTANCE, LineWidthFacet.INSTANCE, GroupFacet.INSTANCE, CommentFacet.INSTANCE);
protected static final List<Facet> BASE = listOf(BackgroundColorFacet.INSTANCE, TransparencyFacet.INSTANCE, ForegroundColorFacet.INSTANCE, LayerFacet.INSTANCE, LineWidthFacet.INSTANCE, GroupFacet.INSTANCE, CommentFacet.INSTANCE, PageFacet.INSTANCE);
protected static final List<Facet> BASE_WITH_LINETYPE = listOf(BASE, LineTypeFacet.INSTANCE, CustomDrawingFacet.INSTANCE, AdvancedDrawingsFacet.INSTANCE);
protected static final List<Facet> BASE_EXTENDED = listOf(BASE_WITH_LINETYPE, TextPrintFacet.INSTANCE, FontSizeFacet.INSTANCE);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.baselet.element.facet.common;

import com.baselet.diagram.draw.helper.StyleException;
import com.baselet.element.facet.FirstRunKeyValueFacet;
import com.baselet.element.facet.PropertiesParserState;

public class PageFacet extends FirstRunKeyValueFacet {

public static final PageFacet INSTANCE = new PageFacet();

private PageFacet() {
}

public static final String KEY = "page";
public static final String DEFAULT_VALUE = "";

@Override
public KeyValue getKeyValue() {
return new KeyValue(KEY, false, DEFAULT_VALUE.toString(), "Page frame to print");
}

@Override
public void handleValue(String value, PropertiesParserState state) {
if (value.matches("\\S+")) {
state.setPage(value);
}
else {
throw new StyleException("page identifier must be text w/o whitespaces");
}

}

}
28 changes: 28 additions & 0 deletions umlet-swing/src/main/java/com/baselet/diagram/DrawPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ public List<GridElement> getGridElements() {
return gridElements;
}

public List<GridElement> getPages() {
List<GridElement> pages = new ArrayList<GridElement>();

// Search for pages
for (GridElement e : getGridElements()) {
if (null != e.getSetting("page")) {
pages.add(e);
}
}

return pages;
}

public List<GridElement> getPageElements(GridElement page) {

List<GridElement> pageElements = new ArrayList<GridElement>();
pageElements.add(page);

// Identify the elements per page
Rectangle pageArea = page.getRectangle();
for (GridElement e : getGridElements()) {
if (e.isInRange(pageArea)) {
pageElements.add(e);
}
}
return pageElements;
}

public List<Relation> getOldRelations() {
return getHelper(Relation.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@

public class OutputHandler {

private OutputHandler() {} // private constructor to avoid instantiation
private OutputHandler() {
} // private constructor to avoid instantiation

public static void createAndOutputToFile(String extension, File file, DiagramHandler handler) throws Exception {
OutputStream ostream = new FileOutputStream(file);
createToStream(extension, ostream, handler);
ostream.close();
createToStreamForPages(extension, file, handler);
}

public static void createToStream(String extension, OutputStream ostream, DiagramHandler handler) throws Exception {
Expand All @@ -63,7 +65,8 @@ public static void createToStream(String extension, OutputStream ostream, Diagra

// if some GridElements are selected, only export them
Collection<GridElement> elementsToDraw = handler.getDrawPanel().getSelector().getSelectedElements();
// if nothing is selected, draw everything

// if no page frame is defined, draw everything
if (elementsToDraw.isEmpty()) {
elementsToDraw = handler.getDrawPanel().getGridElements();
}
Expand All @@ -73,6 +76,29 @@ public static void createToStream(String extension, OutputStream ostream, Diagra
handler.setGridAndZoom(oldZoom, false); // Zoom back to the oldGridsize after execution
}

private static void createToStreamForPages(String extension, File file, DiagramHandler handler) throws Exception {

// Skip export of pages if something is selected
if (!handler.getDrawPanel().getSelector().getSelectedElements().isEmpty()) {
return;
}

int oldZoom = handler.getGridSize();
handler.setGridAndZoom(Constants.DEFAULTGRIDSIZE, false); // Zoom to the defaultGridsize before execution

// File without extension
String filenameWholeExport = file.getAbsolutePath().replaceFirst("[.][^.]+$", "");

for (GridElement page : handler.getDrawPanel().getPages()) {
OutputStream ostream = new FileOutputStream(new File(filenameWholeExport + "_" + page.getSetting("page") + "." + extension));
Collection<GridElement> elementsToDraw = handler.getDrawPanel().getPageElements(page);
OutputHandler.exportToOutputStream(extension, ostream, elementsToDraw, handler.getFontHandler());
ostream.close();
}

handler.setGridAndZoom(oldZoom, false); // Zoom back to the oldGridsize after execution
}

private static void exportToOutputStream(String extension, OutputStream ostream, Collection<GridElement> entities, FontHandler diagramFont) throws IOException {
for (GridElement ge : entities) {
ge.getDeprecatedAddons().doBeforeExport();
Expand Down