use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintTrainsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleTrainsTable"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
List<Train> trains = trainsTableFrame.getSortByList();
printSummaryTrains(writer, trains);
try {
// new page
writer.write(FORM_FEED);
int numberOfLines = writer.getLinesPerPage();
// now do the details for each train
for (Train train : trains) {
if ((train.isBuildEnabled() || trainsTableFrame.showAllBox.isSelected()) && train.getRoute() != null) {
List<RouteLocation> route = train.getRoute().getLocationsBySequenceList();
// determine if another detailed summary can fit on the same page
if (numberOfLines - writer.getCurrentLineNumber() < route.size() + NUMBER_OF_HEADER_LINES) {
writer.write(FORM_FEED);
} else if (writer.getCurrentLineNumber() > 0) {
writer.write(NEW_LINE);
}
printTrain(writer, train);
}
}
} catch (IOException e1) {
log.error("Exception in print train details");
}
// and force completion of the printing
writer.close();
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintTrainsByCarTypesAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleTrainsByType"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
// Loop through the car types showing which locations and tracks will
// service that car type
String[] carTypes = CarTypes.instance().getNames();
List<Train> trains = trainManager.getTrainsByNameList();
try {
// title line
String s = Bundle.getMessage("Type") + TAB + Bundle.getMessage("Trains") + TAB + TAB + TAB + Bundle.getMessage("Description") + NEW_LINE;
writer.write(s);
// car types
for (String type : carTypes) {
s = type + NEW_LINE;
writer.write(s);
// trains
for (Train train : trains) {
if (train.acceptsTypeName(type)) {
StringBuilder sb = new StringBuilder();
String name = train.getName();
sb.append(TAB + name + " ");
int j = MAX_NAME_LENGTH - name.length();
while (j > 0) {
j--;
sb.append(" ");
}
sb.append(train.getDescription() + NEW_LINE);
writer.write(sb.toString());
}
}
}
// and force completion of the printing
writer.close();
} catch (IOException we) {
log.error("Error printing PrintLocationAction: " + we);
}
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class RosterEntry method printEntryDetails.
/**
* Print the roster information.
* <p>
* Updated to allow for multiline comment and decoder comment fields.
* Separate write statements for text and line feeds to work around
* the HardcopyWriter bug that misplaces borders.
*
* @param w the writer used to print
*/
public void printEntryDetails(Writer w) {
int linesadded = -1;
String title;
// 3 spaces in front of legend labels
String leftMargin = " ";
// pad remaining spaces for legend using fixed width font, forms "%-19s" in line
int labelColumn = 19;
try {
//int indentWidth = indent.length();
HardcopyWriter ww = (HardcopyWriter) w;
int textSpace = ww.getCharactersPerLine() - indentWidth - 1;
title = String.format("%-" + labelColumn + "s", // I18N ID:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldID"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _id, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _id, leftMargin + title, textSpace) + linesadded;
}
title = String.format("%-" + labelColumn + "s", // I18N Filename:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldFilename"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _fileName != null ? _fileName : "<null>", leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _fileName != null ? _fileName : "<null>", leftMargin + title, textSpace) + linesadded;
}
if (!(_roadName.isEmpty())) {
// I18N Road name:
title = String.format("%-" + labelColumn + "s", (Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldRoadName"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _roadName, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _roadName, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_roadNumber.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Road number:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldRoadNumber"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _roadNumber, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _roadNumber, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_mfg.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Manufacturer:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldManufacturer"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _mfg, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _mfg, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_owner.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Owner:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldOwner"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _owner, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _owner, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_model.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Model:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldModel"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _model, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _model, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_dccAddress.isEmpty())) {
w.write(newLine, 0, 1);
title = String.format("%-" + labelColumn + "s", // I18N DCC Address:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldModel"))));
String s = leftMargin + title + _dccAddress;
w.write(s, 0, s.length());
linesadded++;
}
// method and print it
if (!(_comment.isEmpty())) {
//through the picture.
for (int i = 0; i < (blanks - linesadded); i++) {
w.write(newLine, 0, 1);
}
//reset the number of blanks to 0.
if (blanks != 0) {
blanks = 0;
}
title = String.format("%-" + labelColumn + "s", // I18N Comment:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldComment"))));
linesadded = writeWrappedComment(w, _comment, leftMargin + title, textSpace) + linesadded;
}
if (!(_decoderModel.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Decoder Model:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldDecoderModel"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _decoderModel, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _decoderModel, leftMargin + title, textSpace) + linesadded;
}
}
if (!(_decoderFamily.isEmpty())) {
title = String.format("%-" + labelColumn + "s", // I18N Decoder Family:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldDecoderFamily"))));
if ((textSpaceWithIcon != 0) && (linesadded < blanks)) {
linesadded = writeWrappedComment(w, _decoderFamily, leftMargin + title, textSpaceWithIcon) + linesadded;
} else {
linesadded = writeWrappedComment(w, _decoderFamily, leftMargin + title, textSpace) + linesadded;
}
}
//If there is a decoderComment field, need to wrap it
if (!(_decoderComment.isEmpty())) {
//through the picture.
for (int i = 0; i < (blanks - linesadded); i++) {
w.write(newLine, 0, 1);
}
//reset the number of blanks to 0.
if (blanks != 0) {
blanks = 0;
}
title = String.format("%-" + labelColumn + "s", // I18N Decoder Comment:
(Bundle.getMessage("MakeLabel", Bundle.getMessage("FieldDecoderComment"))));
linesadded = writeWrappedComment(w, _decoderComment, leftMargin + title, textSpace) + linesadded;
}
w.write(newLine, 0, 1);
for (int i = -1; i < (blanks - linesadded); i++) {
w.write(newLine, 0, 1);
}
} catch (IOException e) {
log.error("Error printing RosterEntry: " + e);
}
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintCvAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, mFrame.getRosterEntry().getId(), 10, .8, .5, .5, .5, isPreview);
// print the decoder info section, etc
printInfoSection(writer);
String s = "\n\n";
writer.write(s, 0, s.length());
//Initialize some variables to define the CV table size
int cvCount = mModel.getRowCount();
int tableLeft = 1, tableRight = TABLE_COLS * 24 + 1, tableTopRow = 0, tableBottomRow = 0, tableHeight = cvCount / TABLE_COLS;
if (cvCount % TABLE_COLS > 0) {
tableHeight++;
}
/*Start drawing the table of CVs. Set up the table with 4 columns of CV/Value
pairs and Draw the table borders and lines. Each column width is
16 characters, including the starting vertical line, but not the
ending one. Therefore the total table width is 64+1 characters
The colummn headings take 2 lines
4 columns of 20 gives 80 CVs possible. NMRA specs only define about 70 CVs
including all the optional ones plus some Manufacturer ones. 80 should be
enough, although more can be added by increasing the tableHeight value
*/
//Set the top row and draw top line to start the table of CVs
tableTopRow = writer.getCurrentLineNumber();
writer.write(tableTopRow, tableLeft, tableTopRow, tableRight);
//set the bottom of the table
tableBottomRow = tableTopRow + tableHeight + 2;
//Draw vertical lines for columns
for (int i = 1; i < 76; i = i + 24) {
writer.write(tableTopRow, i, tableBottomRow, i);
}
//Draw remaining horozontal lines
writer.write(tableTopRow + 2, tableLeft, tableTopRow + 2, tableRight);
writer.write(tableBottomRow, tableLeft, tableBottomRow, tableRight);
//set font to Bold
writer.setFontStyle(1);
// print a simple heading with I18N
// pad with spaces to column width, 3 x insert Value as var %1
s = String.format("%1$21s%1$24s%1$24s", Bundle.getMessage("Value"));
writer.write(s, 0, s.length());
s = "\n";
writer.write(s, 0, s.length());
// NOI18N
s = " CV Dec Hex CV Dec Hex CV Dec Hex\n";
writer.write(s, 0, s.length());
//set font back to Normal
writer.setFontStyle(0);
/* Create array to hold CV/Value strings to allow reformatting and sorting.
* Same size as the table drawn above (4 columns*tableHeight; heading rows
* not included
*/
String[] cvStrings = new String[TABLE_COLS * tableHeight];
//blank the array
for (int i = 0; i < cvStrings.length; i++) {
cvStrings[i] = "";
}
// get each CV and value
for (int i = 0; i < mModel.getRowCount(); i++) {
CvValue cv = mModel.getCvByRow(i);
int value = cv.getValue();
//convert and pad numbers as needed
String numString = String.format("%12s", cv.number());
String valueString = Integer.toString(value);
String valueStringHex = Integer.toHexString(value).toUpperCase();
if (value < 16) {
valueStringHex = "0" + valueStringHex;
}
for (int j = 1; j < 3; j++) {
if (valueString.length() < 3) {
valueString = " " + valueString;
}
}
//Create composite string of CV and its decimal and hex values
s = " " + numString + " " + valueString + " " + valueStringHex + " ";
//populate printing array - still treated as a single column
cvStrings[i] = s;
}
//sort the array in CV order (just the members with values)
String temp;
boolean swap = false;
do {
swap = false;
for (int i = 0; i < mModel.getRowCount() - 1; i++) {
if (cvSortOrderVal(cvStrings[i + 1].substring(0, 15).trim()) < cvSortOrderVal(cvStrings[i].substring(0, 15).trim())) {
temp = cvStrings[i + 1];
cvStrings[i + 1] = cvStrings[i];
cvStrings[i] = temp;
swap = true;
}
}
} while (swap == true);
//Print the array in three columns
for (int i = 0; i < tableHeight; i++) {
s = cvStrings[i] + cvStrings[i + tableHeight] + cvStrings[i + tableHeight * 2] + "\n";
writer.write(s, 0, s.length());
}
//write an extra character to work around the
//last character truncation bug with HardcopyWriter
s = " \n";
writer.write(s, 0, s.length());
} catch (java.io.IOException ex1) {
log.error("IO exception while printing");
return;
} catch (HardcopyWriter.PrintCanceledException ex2) {
log.debug("Print cancelled");
return;
}
writer.close();
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class CbusEventTablePane method getMenus.
@Override
public List<JMenu> getMenus() {
List<JMenu> menuList = new ArrayList<JMenu>();
ResourceBundle rb = ResourceBundle.getBundle("apps.AppsBundle");
JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
JMenuItem openItem = new JMenuItem(rb.getString("MenuItemOpen"));
fileMenu.add(openItem);
JMenuItem saveItem = new JMenuItem(rb.getString("MenuItemSave"));
fileMenu.add(saveItem);
saveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
eventModel.saveAsTable();
}
});
JMenuItem saveAsItem = new JMenuItem(rb.getString("MenuItemSaveAs"));
fileMenu.add(saveAsItem);
saveAsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
eventModel.saveTable();
}
});
// add print menu items
JMenuItem printItem = new JMenuItem(rb.getString("PrintTable"));
fileMenu.add(printItem);
printItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(getWindowInterface().getFrame(), getTitle(), 10, .8, .5, .5, .5, false);
} catch (HardcopyWriter.PrintCanceledException ex) {
//log.debug("Print cancelled");
return;
}
writer.increaseLineSpacing(20);
eventModel.printTable(writer);
}
});
JMenuItem previewItem = new JMenuItem(rb.getString("PreviewTable"));
fileMenu.add(previewItem);
previewItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(getWindowInterface().getFrame(), getTitle(), 10, .8, .5, .5, .5, true);
} catch (HardcopyWriter.PrintCanceledException ex) {
//log.debug("Print cancelled");
return;
}
writer.increaseLineSpacing(20);
eventModel.printTable(writer);
}
});
menuList.add(fileMenu);
return menuList;
}
Aggregations