Skip to content

Commit

Permalink
Merge pull request #17 from SeanCarrick/wip
Browse files Browse the repository at this point in the history
Printing Completed
  • Loading branch information
SeanCarrick authored Oct 8, 2019
2 parents 93fdf36 + 528d510 commit 654ab27
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 43 deletions.
4 changes: 4 additions & 0 deletions isrcp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Written during exit: 2019-10-08
#Tue Oct 08 11:14:59 CDT 2019
Command_Line_Argument_Parser=2019-10-08
project.home=/home/sean/.isrcp/projects
32 changes: 22 additions & 10 deletions src/com/is2300/rcp/StartPrinting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
*/
package com.is2300.rcp;

import com.is2300.cmdlineparser.CmdLineParser;
import com.is2300.rcp.desktop.RcpFrame;
import com.is2300.rcp.enums.SysExits;
import com.is2300.rcp.printer.FileFilterFactory;
import com.is2300.rcp.printer.PrintSetup;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* ***Integrity Solutions*** *Recursive Code Printer Utility* is designed from
Expand Down Expand Up @@ -147,9 +142,16 @@ public class StartPrinting {

PROPS = new Properties();

File appPath = new File(System.getProperty("user.home") +
try (FileReader reader = new FileReader(System.getProperty("user.home")
+ System.getProperty("file.separator") + "isrcp.conf")) {
PROPS.load(reader);
} catch (IOException ex) {
PROPS.setProperty("project.home", System.getProperty("user.home") +
System.getProperty("file.separator") + ".isrcp" +
System.getProperty("file.separator") + "projects");
}

File appPath = new File(PROPS.getProperty("project.home"));

if ( !appPath.exists() ) {
appPath.mkdirs();
Expand Down Expand Up @@ -378,6 +380,16 @@ public static void showConditions() {
public static void exit(SysExits status) {
System.out.println("Thank you for using Integrity Solutions' Recursive "
+ "Code Printer utility...\n");

try {
PROPS.store(new FileOutputStream(new File(System.getProperty("user.home")
+ System.getProperty("file.separator") + "isrcp.conf")),
"Written during exit: " + LocalDate.now().toString());
} catch (IOException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
}

System.exit(status.toInt());
}

Expand Down
5 changes: 4 additions & 1 deletion src/com/is2300/rcp/desktop/RcpFrame.form
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtSrcFolder">
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="CanPrint"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnBrowseFolders">
<Properties>
Expand Down Expand Up @@ -279,7 +282,7 @@
<Component class="javax.swing.JTextField" name="txtProjectName">
<Events>
<EventHandler event="focusGained" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="ProjectGotFocus"/>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="ProjectLostFocus"/>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="ProjectLostFocus,CanPrint"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnBrowseProjects">
Expand Down
97 changes: 74 additions & 23 deletions src/com/is2300/rcp/desktop/RcpFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,18 @@

import com.is2300.rcp.StartPrinting;
import com.is2300.rcp.enums.SysExits;
import com.is2300.rcp.filters.FileFilterEx;
import com.is2300.rcp.printer.FileFilterFactory;
import com.is2300.rcp.printer.FormattedPrinter;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import static java.util.Locale.filter;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.Sides;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
Expand All @@ -65,6 +54,10 @@ public class RcpFrame extends javax.swing.JFrame {
public RcpFrame() {
initComponents();

this.setTitle("Integrity Solutions: Recursive Code Printer v. "
+ StartPrinting.MAJOR + "." + StartPrinting.MINOR + "."
+ StartPrinting.BUILD);

Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
int left = (scrSize.width - this.getWidth() ) / 2;
int top = (scrSize.height - this.getHeight() ) / 2;
Expand All @@ -79,7 +72,8 @@ public RcpFrame() {
}

this.txtSrcFolder.setText(System.getProperty("user.home"));
// this.txtProjectName.setText("[Type or Select Project Name]");
this.txtProjectName.setText("[Type or Select Project Name]");
this.CanPrint(null);
}

/**
Expand Down Expand Up @@ -121,6 +115,12 @@ private void initComponents() {
jLabel1.setLabelFor(txtSrcFolder);
jLabel1.setText("Top-Level Source Code Folder:");

txtSrcFolder.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
CanPrint(evt);
}
});

btnBrowseFolders.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/is2300/rcp/desktop/Find.png"))); // NOI18N
btnBrowseFolders.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Expand Down Expand Up @@ -186,6 +186,7 @@ public void focusGained(java.awt.event.FocusEvent evt) {
}
public void focusLost(java.awt.event.FocusEvent evt) {
ProjectLostFocus(evt);
CanPrint(evt);
}
});

Expand Down Expand Up @@ -344,8 +345,33 @@ private void getInstalledPrinters() {
}

private void storeProjectName() {
StartPrinting.PROPS.setProperty(txtProjectName.getText(),
LocalDate.now().toString());
String projFileName = this.txtProjectName.getText().replace(" ", "_");

File project = new File(StartPrinting.PROPS.getProperty("project.home")
+ System.getProperty("file.separator") + projFileName);

if ( !project.exists() ) {
try {
project.createNewFile();
} catch (IOException ex) {
String msg = ex.getMessage();
JOptionPane.showMessageDialog(this, msg, "Input/Ouput Exception",
JOptionPane.ERROR_MESSAGE);
}
}

try (BufferedWriter out = new BufferedWriter(new FileWriter(project))) {
StringBuilder sb = new StringBuilder();
sb.append(LocalDate.now().toString()).append("\n");
sb.append(txtSrcFolder.getText()).append("\n");
sb.append(cboLanguage.getSelectedItem().toString());

out.write(sb.toString());
} catch ( IOException ex ) {
String msg = ex.getMessage();
JOptionPane.showMessageDialog(this, msg, "Input/Ouput Exception",
JOptionPane.ERROR_MESSAGE);
}
}

private void enableProgressControls() {
Expand Down Expand Up @@ -394,20 +420,33 @@ private boolean print(String pathToFiles, FileFilter filter) {
for ( File f : file.listFiles(filter) ) {
if ( f.isDirectory() ) {
this.txtCurrentFolder.setText(f.getAbsolutePath());
/*print(f.getAbsolutePath(), filter);*/
print(f.getAbsolutePath(), filter);
System.out.println("Current Folder: " + f.getAbsolutePath());
this.pbFolder.setValue(this.pbFolder.getValue() + 1);
} else {
FormattedPrinter printer = new FormattedPrinter(f.getAbsolutePath());

/*printer.actionPerformed(null);*/
printer.actionPerformed(null);
System.out.println("Current File: " + f.getName());
}
}

return printed;
}

private boolean isReady() {
boolean ready = false;

if ( !this.txtProjectName.getText().isBlank()
&& !this.txtSrcFolder.getText().isBlank()
&& !this.cboLanguage.getSelectedItem().equals(
"-- SELECT PROGRAMMING LANGUAGE --") ) {
ready = true;
}

return ready;
}

private void CancelAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelAction
this.setVisible(false);

Expand All @@ -430,7 +469,10 @@ private void findFolderClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_
}//GEN-LAST:event_findFolderClick

private void languageSelectionChanged(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_languageSelectionChanged
// TODO add your handling code here:
if ( !cboLanguage.getSelectedItem().equals(
"-- SELECT PROGRAMMING LANGUAGE --") ) {
CanPrint(null);
}
}//GEN-LAST:event_languageSelectionChanged

private void printerSelectionChanged(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_printerSelectionChanged
Expand All @@ -449,7 +491,7 @@ private void ProjectGotFocus(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_P
private void ProjectLostFocus(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ProjectLostFocus
txtProjectName.select(0, 0);

storeProjectName();
CanPrint(evt);
}//GEN-LAST:event_ProjectLostFocus

private void ProjectClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ProjectClick
Expand All @@ -459,9 +501,10 @@ private void ProjectClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Pro
if ( project.selected == true ) {
this.txtProjectName.setText(project.projectName);
this.txtSrcFolder.setText(project.getProjectPath(
project.projectName));
project.projectName.replace(" ", "_")));
this.lblLastPrint.setText("Last Printed On: "
+ StartPrinting.PROPS.getProperty(project.projectName));
+ StartPrinting.PROPS.getProperty(
project.projectName.replace(" ", "_")));

int count = cboLanguage.getItemCount();
for ( int x = 0; x < count; x++ ) {
Expand All @@ -473,11 +516,15 @@ private void ProjectClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Pro
}
}
}

CanPrint(null);
}//GEN-LAST:event_ProjectClick

private void DoPrintJob(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DoPrintJob
this.startTime = System.currentTimeMillis();

storeProjectName();

enableProgressControls();

countWalk(new File(this.txtSrcFolder.getText()));
Expand Down Expand Up @@ -509,6 +556,10 @@ private void DoPrintJob(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DoPri
JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_DoPrintJob

private void CanPrint(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_CanPrint
this.btnPrint.setEnabled(this.isReady());
}//GEN-LAST:event_CanPrint

/**
* @param args the command line arguments
*/
Expand Down
7 changes: 3 additions & 4 deletions src/com/is2300/rcp/desktop/SelectProjectDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ public SelectProjectDialog(java.awt.Frame parent, boolean modal) {

private void loadProjects() {
lstProjects.add("[Type or Select Project Name]");
File projectsDir = new File(System.getProperty("user.home") +
System.getProperty("file.separator") + ".isrcp" +
System.getProperty("file.separator") + "projects");
File projectsDir = new File(StartPrinting.PROPS.getProperty(
"project.home"));

if ( projectsDir.listFiles().length > 0) {
for ( File project : projectsDir.listFiles() ) {
lstProjects.add(project.getName());
lstProjects.add(project.getName().replace("_", " "));

try (BufferedReader in = new BufferedReader(
new FileReader(project))) {
Expand Down
12 changes: 7 additions & 5 deletions src/com/is2300/rcp/printer/FormattedPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
import static java.awt.print.Printable.NO_SUCH_PAGE;
import java.awt.print.PrinterException;
Expand All @@ -34,14 +35,10 @@
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import javax.print.DocFlavor;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.Sides;

/**
Expand Down Expand Up @@ -125,6 +122,10 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
}

Graphics2D g2d = (Graphics2D)graphics;
g2d.setFont(font);
// Paper paper = pageFormat.getPaper();
// paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());
// pageFormat.setPaper(paper);
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

int y = 0;
Expand All @@ -148,6 +149,7 @@ public void actionPerformed(ActionEvent e) {
attributes.add(new Copies(1));
// attributes.add(MediaSize.NA.LETTER);
attributes.add(Sides.DUPLEX);
// attributes.add(new MediaPrintableArea(0f, 0f, w/72f, h/72f, MediaPrintableArea.INCH));
//
// PrintService[] services = PrintServiceLookup.lookupPrintServices(docFmt, attributes);
// DocPrintJob job = null;
Expand Down

0 comments on commit 654ab27

Please sign in to comment.