-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...et-builder-api/src/main/java/org/modelcatalogue/builder/spreadsheet/api/ImageCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.modelcatalogue.builder.spreadsheet.api; | ||
|
||
import java.io.InputStream; | ||
|
||
public interface ImageCreator { | ||
|
||
void from(String fileOrUrl); | ||
void from(InputStream stream); | ||
void from(byte[] imageData); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...et-builder-api/src/main/java/org/modelcatalogue/builder/spreadsheet/api/ImageKeyword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.modelcatalogue.builder.spreadsheet.api; | ||
|
||
public enum ImageKeyword { | ||
IMAGE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...der-poi/src/main/groovy/org/modelcatalogue/builder/spreadsheet/poi/PoiImageCreator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.modelcatalogue.builder.spreadsheet.poi | ||
|
||
import org.apache.poi.ss.usermodel.ClientAnchor | ||
import org.apache.poi.ss.usermodel.CreationHelper | ||
import org.apache.poi.ss.usermodel.Drawing | ||
import org.apache.poi.ss.usermodel.Picture | ||
import org.modelcatalogue.builder.spreadsheet.api.ImageCreator | ||
|
||
class PoiImageCreator implements ImageCreator { | ||
|
||
private final PoiCell cell | ||
private final int type | ||
|
||
PoiImageCreator(PoiCell poiCell, int type) { | ||
this.cell = poiCell | ||
this.type = type | ||
} | ||
|
||
@Override | ||
void from(String fileOrUrl) { | ||
if (fileOrUrl.startsWith('https://') || fileOrUrl.startsWith('http://')) { | ||
from new URL(fileOrUrl).newInputStream() | ||
return | ||
} | ||
from new FileInputStream(new File(fileOrUrl)) | ||
} | ||
|
||
@Override | ||
void from(InputStream stream) { | ||
addPicture(cell.row.sheet.sheet.workbook.addPicture(stream, type)) | ||
} | ||
|
||
@Override | ||
void from(byte[] imageData) { | ||
addPicture(cell.row.sheet.sheet.workbook.addPicture(imageData, type)) | ||
} | ||
|
||
void addPicture(int pictureIdx) { | ||
Drawing drawing = cell.row.sheet.sheet.createDrawingPatriarch(); | ||
|
||
CreationHelper helper = cell.row.sheet.sheet.workbook.getCreationHelper(); | ||
ClientAnchor anchor = helper.createClientAnchor(); | ||
anchor.setCol1(cell.cell.columnIndex) | ||
anchor.setRow1(cell.cell.rowIndex) | ||
|
||
Picture pict = drawing.createPicture(anchor, pictureIdx); | ||
pict.resize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters