Skip to content

Commit

Permalink
finalized new pdf viewer component. issue #2409
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed May 29, 2024
1 parent 7db376d commit 19da1e9
Show file tree
Hide file tree
Showing 13 changed files with 983 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ You should also get your employer (if you work as a programmer) or school,

import com.jdimension.jlawyer.client.configuration.DocumentPreviewConfigurationDialog;
import com.jdimension.jlawyer.client.editors.EditorsRegistry;
import com.jdimension.jlawyer.client.editors.documents.viewer.DocumentPreviewSaveCallback;
import com.jdimension.jlawyer.client.utils.FrameUtils;
import com.jdimension.jlawyer.persistence.ArchiveFileBean;
import com.jdimension.jlawyer.persistence.ArchiveFileDocumentsBean;
Expand All @@ -680,22 +681,24 @@ public class DocumentPreviewTooLarge extends javax.swing.JPanel {
private boolean readOnly = false;
private ArchiveFileBean caseDto=null;
private ArchiveFileDocumentsBean docDto=null;
private DocumentPreviewSaveCallback saveCallback=null;

/**
* Creates new form DocumentPreviewTooLarge
* @param caseDto
* @param value
* @param readOnly
* @param pnlPreview
* @param saveCallback
*/
public DocumentPreviewTooLarge(ArchiveFileBean caseDto, ArchiveFileDocumentsBean value, boolean readOnly, JPanel pnlPreview) {
public DocumentPreviewTooLarge(ArchiveFileBean caseDto, ArchiveFileDocumentsBean value, boolean readOnly, JPanel pnlPreview, DocumentPreviewSaveCallback saveCallback) {
initComponents();
this.docDto=value;
this.pnlPreview = pnlPreview;
this.readOnly = readOnly;
this.caseDto=caseDto;
this.lblHint.setText("<html><b>" + this.docDto.getName() + "</b><br/> ist zu gro&szlig; f&uuml;r eine Vorschau.</html>");

this.saveCallback=saveCallback;
}

/**
Expand Down Expand Up @@ -758,7 +761,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}// </editor-fold>//GEN-END:initComponents

private void cmdForcePreviewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdForcePreviewActionPerformed
new Thread(new LoadDocumentPreviewThread(this.caseDto, this.docDto, this.readOnly, this.pnlPreview, true)).start();
new Thread(new LoadDocumentPreviewThread(this.caseDto, this.docDto, this.readOnly, this.pnlPreview, true, this.saveCallback)).start();
}//GEN-LAST:event_cmdForcePreviewActionPerformed

private void cmdPreviewSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdPreviewSettingsActionPerformed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@
package com.jdimension.jlawyer.client.editors.documents;

import com.jdimension.jlawyer.client.editors.documents.viewer.CaseDocumentPreviewProvider;
import com.jdimension.jlawyer.client.editors.documents.viewer.DocumentPreviewSaveCallback;
import com.jdimension.jlawyer.client.editors.documents.viewer.DocumentViewerFactory;
import com.jdimension.jlawyer.client.editors.documents.viewer.GifJpegPngImageWithTextPanel;
import com.jdimension.jlawyer.client.editors.documents.viewer.PreviewPanel;
Expand Down Expand Up @@ -698,13 +699,15 @@ public class LoadDocumentPreviewThread implements Runnable {
private ArchiveFileBean caseDto=null;
ArchiveFileDocumentsBean docDto=null;
private boolean forceAnyDocumentSize=false;
private DocumentPreviewSaveCallback saveCallback=null;

public LoadDocumentPreviewThread(ArchiveFileBean caseDto, ArchiveFileDocumentsBean value, boolean readOnly, JPanel pnlPreview, boolean forceAnyDocumentSize) {
public LoadDocumentPreviewThread(ArchiveFileBean caseDto, ArchiveFileDocumentsBean value, boolean readOnly, JPanel pnlPreview, boolean forceAnyDocumentSize, DocumentPreviewSaveCallback saveCallback) {
this.docDto=value;
this.pnlPreview = pnlPreview;
this.readOnly = readOnly;
this.caseDto=caseDto;
this.forceAnyDocumentSize=forceAnyDocumentSize;
this.saveCallback=saveCallback;
}

public static boolean isRunning() {
Expand Down Expand Up @@ -753,11 +756,10 @@ public void run() {

JComponent preview = null;
if(this.docDto.getSize()>maxPreviewBytes && !this.forceAnyDocumentSize) {
preview=new DocumentPreviewTooLarge(this.caseDto, this.docDto, this.readOnly, this.pnlPreview);
preview=new DocumentPreviewTooLarge(this.caseDto, this.docDto, this.readOnly, this.pnlPreview, this.saveCallback);
} else {
//byte[] data = afs.getDocumentContent(this.docDto.getId());
byte[] data=CachingDocumentLoader.getInstance().getDocument(this.docDto.getId());
preview=DocumentViewerFactory.getDocumentViewer(this.caseDto, this.docDto.getId(), this.docDto.getName(), readOnly, new CaseDocumentPreviewProvider(afs, this.docDto.getId()), data, this.pnlPreview.getWidth(), this.pnlPreview.getHeight());
preview=DocumentViewerFactory.getDocumentViewer(this.caseDto, this.docDto.getId(), this.docDto.getName(), readOnly, new CaseDocumentPreviewProvider(afs, this.docDto.getId()), data, this.pnlPreview.getWidth(), this.pnlPreview.getHeight(), this.saveCallback);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@
import com.jdimension.jlawyer.client.editors.StatusBarProvider;
import com.jdimension.jlawyer.client.editors.ThemeableEditor;
import com.jdimension.jlawyer.client.editors.addresses.CaseForContactEntry;
import com.jdimension.jlawyer.client.editors.documents.viewer.DocumentPreviewSaveCallback;
import com.jdimension.jlawyer.client.editors.documents.viewer.DocumentViewerFactory;
import com.jdimension.jlawyer.client.editors.documents.viewer.ScanPreviewProvider;
import com.jdimension.jlawyer.client.editors.files.BulkSaveDialog;
Expand Down Expand Up @@ -729,7 +730,7 @@
*
* @author jens
*/
public class ScannerPanel extends javax.swing.JPanel implements ThemeableEditor, StatusBarProvider, EventConsumer, SaveToCaseExecutor {
public class ScannerPanel extends javax.swing.JPanel implements ThemeableEditor, StatusBarProvider, EventConsumer, SaveToCaseExecutor, DocumentPreviewSaveCallback {

private static final Logger log = Logger.getLogger(ScannerPanel.class.getName());
private Image backgroundImage = null;
Expand Down Expand Up @@ -817,16 +818,16 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

if (column == 1) {
FileMetadata fm=(FileMetadata)value;
FileMetadata fm = (FileMetadata) value;
label.setIcon(null);
label.setText("");
if(fm.getOcrStatus()==FileMetadata.OCRSTATUS_NOTSUPPORTED) {
if (fm.getOcrStatus() == FileMetadata.OCRSTATUS_NOTSUPPORTED) {
// no icon
} else if(fm.getOcrStatus()==FileMetadata.OCRSTATUS_PROCESSING || fm.getOcrStatus()==FileMetadata.OCRSTATUS_OPEN) {
} else if (fm.getOcrStatus() == FileMetadata.OCRSTATUS_PROCESSING || fm.getOcrStatus() == FileMetadata.OCRSTATUS_OPEN) {
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/baseline_font_download_yellow_48dp.png")));
} else if(fm.getOcrStatus()==FileMetadata.OCRSTATUS_WITHOCR) {
} else if (fm.getOcrStatus() == FileMetadata.OCRSTATUS_WITHOCR) {
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/baseline_font_download_green_48dp.png")));
} else if(fm.getOcrStatus()==FileMetadata.OCRSTATUS_WITHOUTOCR) {
} else if (fm.getOcrStatus() == FileMetadata.OCRSTATUS_WITHOUTOCR) {
label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/material/baseline_font_download_off_red_48dp.png")));
}
} else if (column == 2) {
Expand All @@ -839,7 +840,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
label.setText("");
label.setIcon(null);
String sValue = (String) value;
if(sValue!=null && sValue.length()>0) {
if (sValue != null && sValue.length() > 0) {
label.setText(sValue);
label.setIcon(UserSettings.getInstance().getUserSmallIcon(sValue));
}
Expand Down Expand Up @@ -867,7 +868,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole

ComponentUtils.persistSplitPane(this.splitTop, this.getClass(), "splitTop");
ComponentUtils.persistSplitPane(this.splitContainer, this.getClass(), "splitContainer");

this.jScrollPane1.getVerticalScrollBar().setUnitIncrement(16);

}
Expand Down Expand Up @@ -1148,7 +1149,7 @@ private void selectDirContent() {
this.pnlActionsChild.removeAll();
int[] selRow = this.tblDirContent.getSelectedRows();
if (selRow.length > 0) {

log.info(selRow.length + " documents selected");

ArrayList<String> fileNames = new ArrayList<>();
Expand Down Expand Up @@ -1253,7 +1254,7 @@ private void selectDirContent() {
byte[] data = is.getObservedFile(fFileName);

log.info("rendering preview");
JComponent preview = DocumentViewerFactory.getDocumentViewer(null, fFileName, true, new ScanPreviewProvider(is, fFileName), data, pnlPreview.getWidth(), pnlPreview.getHeight());
JComponent preview = DocumentViewerFactory.getDocumentViewer(null, fFileName, true, new ScanPreviewProvider(is, fFileName), data, pnlPreview.getWidth(), pnlPreview.getHeight(), this);
ThreadUtils.setVisible(pnlPreview, false);
ThreadUtils.remove(pnlPreview, loading);
ThreadUtils.setLayout(pnlPreview, new BorderLayout());
Expand Down Expand Up @@ -1434,9 +1435,9 @@ private void mnuDeactivateLocalFolderActionPerformed(java.awt.event.ActionEvent
public boolean saveToCaseCallback(String caseId, boolean withAttachments, boolean separateAttachments, boolean onlyAttachments) {
int[] selRow = this.tblDirContent.getSelectedRows();
if (selRow.length > 0) {
BulkSaveDialog bulkSaveDlg=new BulkSaveDialog(BulkSaveDialog.TYPE_SCAN, EditorsRegistry.getInstance().getMainWindow(), true);
ScanEntryProcessor processor=new ScanEntryProcessor(this.chkDeleteAfterAction.isSelected());

BulkSaveDialog bulkSaveDlg = new BulkSaveDialog(BulkSaveDialog.TYPE_SCAN, EditorsRegistry.getInstance().getMainWindow(), true);
ScanEntryProcessor processor = new ScanEntryProcessor(this.chkDeleteAfterAction.isSelected());
bulkSaveDlg.setEntryProcessor(processor);

ArrayList<String> fileNames = new ArrayList<>();
Expand All @@ -1447,39 +1448,40 @@ public boolean saveToCaseCallback(String caseId, boolean withAttachments, boolea

CaseFolder rootFolder = null;
CaseFolder targetFolder = null;
ArchiveFileBean targetCase=null;
ArchiveFileBean targetCase = null;
if (caseId == null) {
SearchAndAssignDialog dlg = new SearchAndAssignDialog(EditorsRegistry.getInstance().getMainWindow(), true, "", null);
dlg.setVisible(true);
targetCase = dlg.getCaseSelection();
targetFolder = dlg.getFolderSelection();
rootFolder=dlg.getRootFolder();
rootFolder = dlg.getRootFolder();
dlg.dispose();
} else {
SearchAndAssignDialog dlg = new SearchAndAssignDialog(EditorsRegistry.getInstance().getMainWindow(), true, "", caseId);
dlg.setVisible(true);
dlg.dispose();
targetFolder = dlg.getFolderSelection();
targetCase = dlg.getCaseSelection();
rootFolder=dlg.getRootFolder();
rootFolder = dlg.getRootFolder();
}

// user hit cancel
if (targetCase == null)
if (targetCase == null) {
return false;

}

bulkSaveDlg.setCaseFolder(rootFolder, targetFolder);
bulkSaveDlg.setSelectedCase(targetCase);

for (String fileName : fileNames) {

try {

BulkSaveEntry bulkEntry = new BulkSaveEntry();
bulkEntry.setDocumentDate(new Date());
// do not load document from server - bytes remain empty, processor takes care of it
// bulkEntry.setDocumentBytes(locator.lookupIntegrationServiceRemote().getObservedFile(fileName));

String newName = fileName;
if (newName == null) {
newName = "";
Expand All @@ -1490,16 +1492,16 @@ public boolean saveToCaseCallback(String caseId, boolean withAttachments, boolea
bulkEntry.setDocumentFilenameNew(FileUtils.getNewFileNamePrefix(new Date()) + newName);

bulkSaveDlg.addEntry(bulkEntry);

} catch (Exception ex) {
log.error(ex);
ThreadUtils.showErrorDialog(EditorsRegistry.getInstance().getMainWindow(), "Fehler beim Speichern des Scans: " + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR);
}
}

FrameUtils.centerDialog(bulkSaveDlg, EditorsRegistry.getInstance().getMainWindow());
bulkSaveDlg.setVisible(true);

if (this.chkDeleteAfterAction.isSelected() && !(fileNames.isEmpty())) {
Timer timer = new Timer();
TimerTask scannerTask = new ScannerDocumentsTimerTask(true);
Expand Down Expand Up @@ -1610,19 +1612,20 @@ public boolean splitPdfCallback() {
if (selRow.length == 1) {

String fileName = this.tblDirContent.getValueAt(selRow[0], 2).toString();
if(!fileName.toLowerCase().endsWith(".pdf"))
if (!fileName.toLowerCase().endsWith(".pdf")) {
return false;
}

try {

PDFSplitDialog dlg = new PDFSplitDialog(EditorsRegistry.getInstance().getMainWindow(), true, fileName);
FrameUtils.centerDialog(dlg, EditorsRegistry.getInstance().getMainWindow());
dlg.setVisible(true);
ArrayList<PDFSplitRequest> splitRequests=new ArrayList<>();
if(dlg.getSplitRequest()!=null) {
ArrayList<PDFSplitRequest> splitRequests = new ArrayList<>();
if (dlg.getSplitRequest() != null) {
splitRequests.add(dlg.getSplitRequest());
}

ProgressIndicator pi = new ProgressIndicator(EditorsRegistry.getInstance().getMainWindow(), true);
pi.setShowCancelButton(true);
pi.setMax(3);
Expand All @@ -1638,4 +1641,16 @@ public boolean splitPdfCallback() {
}
return true;
}

@Override
public void savePreview(String documentId, String fileName, byte[] data) {
try {
ClientSettings settings = ClientSettings.getInstance();
JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties());
locator.lookupIntegrationServiceRemote().updateObservedFile(fileName, data);
} catch (Exception ex) {
log.error(ex);
ThreadUtils.showErrorDialog(EditorsRegistry.getInstance().getMainWindow(), "Fehler beim Bearbeiten des Scans: " + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR);
}
}
}
Loading

0 comments on commit 19da1e9

Please sign in to comment.