use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintCarRosterAction method printCars.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "CarManager only provides Car Objects")
private void printCars() {
boolean landscape = false;
if (manifestOrientationComboBox.getSelectedItem() != null && manifestOrientationComboBox.getSelectedItem() == Setup.LANDSCAPE) {
landscape = true;
}
int fontSize = (int) fontSizeComboBox.getSelectedItem();
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleCarRoster"), fontSize, .5, .5, .5, .5, isPreview, "", landscape, true, null);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
numberCharPerLine = writer.getCharactersPerLine();
// Loop through the Roster, printing as needed
String location = "";
String number;
String road;
String type;
String length = "";
String weight = "";
String color = "";
String owner = "";
String built = "";
String load = "";
String kernel = "";
String train = "";
String destination = "";
String finalDestination = "";
String returnWhenEmpty = "";
String value = "";
String rfid = "";
String last = "";
String wait = "";
String schedule = "";
String comment = "";
try {
printTitleLine(writer);
String previousLocation = null;
List<RollingStock> cars = panel.carsTableModel.getCarList(sortByComboBox.getSelectedIndex());
for (RollingStock rs : cars) {
Car car = (Car) rs;
if (printCarsWithLocation.isSelected() && car.getLocation() == null) {
// car doesn't have a location skip
continue;
}
location = "";
destination = "";
finalDestination = "";
returnWhenEmpty = "";
if (printCarLocation.isSelected()) {
if (car.getLocation() != null) {
location = car.getLocationName().trim() + " - " + car.getTrackName().trim();
}
location = padAttribute(location, LocationManager.instance().getMaxLocationAndTrackNameLength() + 3);
}
// Page break between locations?
if (previousLocation != null && !car.getLocationName().trim().equals(previousLocation) && printPage.isSelected()) {
writer.pageBreak();
printTitleLine(writer);
} else // Add a line between locations?
if (previousLocation != null && !car.getLocationName().trim().equals(previousLocation) && printSpace.isSelected()) {
writer.write(NEW_LINE);
}
previousLocation = car.getLocationName().trim();
// car number
number = padAttribute(car.getNumber().trim(), Control.max_len_string_print_road_number);
// car road
road = padAttribute(car.getRoadName().trim(), CarRoads.instance().getMaxNameLength());
// car type
type = padAttribute(car.getTypeName().trim(), CarTypes.instance().getMaxFullNameLength());
if (printCarLength.isSelected()) {
length = padAttribute(car.getLength().trim(), Control.max_len_string_length_name);
}
if (printCarWeight.isSelected()) {
weight = padAttribute(car.getWeight().trim(), Control.max_len_string_weight_name);
}
if (printCarColor.isSelected()) {
color = padAttribute(car.getColor().trim(), CarColors.instance().getMaxNameLength());
}
if (printCarLoad.isSelected()) {
load = padAttribute(car.getLoadName().trim(), CarLoads.instance().getMaxNameLength());
}
if (printCarKernel.isSelected()) {
kernel = padAttribute(car.getKernelName().trim(), Control.max_len_string_attibute);
}
if (printCarOwner.isSelected()) {
owner = padAttribute(car.getOwner().trim(), CarOwners.instance().getMaxNameLength());
}
if (printCarBuilt.isSelected()) {
built = padAttribute(car.getBuilt().trim(), Control.max_len_string_built_name);
}
if (printCarLast.isSelected()) {
last = padAttribute(car.getLastDate().split(" ")[0], 10);
}
if (printCarWait.isSelected()) {
wait = padAttribute(Integer.toString(car.getWait()), 4);
}
if (printCarPickup.isSelected()) {
schedule = padAttribute(car.getPickupScheduleName(), 10);
}
if (printCarValue.isSelected()) {
value = padAttribute(car.getValue().trim(), Control.max_len_string_attibute);
}
if (printCarRfid.isSelected()) {
rfid = padAttribute(car.getRfid().trim(), Control.max_len_string_attibute);
}
if (// pad out train to half of its maximum
printCarTrain.isSelected()) {
train = padAttribute(car.getTrainName().trim(), Control.max_len_string_train_name / 2);
}
if (printCarDestination.isSelected()) {
if (car.getDestination() != null) {
destination = car.getDestinationName().trim() + " - " + car.getDestinationTrackName();
}
destination = padAttribute(destination, LocationManager.instance().getMaxLocationAndTrackNameLength() + 3);
}
if (printCarFinalDestination.isSelected()) {
if (car.getFinalDestination() != null) {
finalDestination = car.getFinalDestinationName().trim() + " - " + car.getFinalDestinationTrackName().trim();
}
finalDestination = padAttribute(finalDestination, LocationManager.instance().getMaxLocationAndTrackNameLength() + 3);
}
if (printCarRWE.isSelected()) {
if (car.getReturnWhenEmptyDestination() != null) {
returnWhenEmpty = car.getReturnWhenEmptyDestinationName().trim() + " - " + car.getReturnWhenEmptyDestTrackName().trim();
}
returnWhenEmpty = padAttribute(returnWhenEmpty, LocationManager.instance().getMaxLocationAndTrackNameLength() + 3);
}
if (printCarComment.isSelected()) {
comment = car.getComment().trim();
}
String s = number + road + type + length + weight + color + load + kernel + owner + built + last + wait + schedule + value + rfid + location + train + destination + finalDestination + returnWhenEmpty + comment;
if (s.length() > numberCharPerLine) {
s = s.substring(0, numberCharPerLine);
}
writer.write(s + NEW_LINE);
}
// and force completion of the printing
writer.close();
} catch (IOException we) {
log.error("Error printing car roster");
}
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintEngineRosterAction method actionPerformed.
@Override
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "EngineManager only provides Engine Objects")
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleEngineRoster"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
numberCharPerLine = writer.getCharactersPerLine();
// Loop through the Roster, printing as needed
String number;
String road;
String model;
String type;
String length;
String owner = "";
String consist = "";
String built = "";
String value = "";
String rfid = "";
String location;
List<RollingStock> engines = panel.getSortByList();
try {
// header
String header = padAttribute(Bundle.getMessage("Number"), Control.max_len_string_print_road_number) + padAttribute(Bundle.getMessage("Road"), CarRoads.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Model"), EngineModels.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Type"), EngineTypes.instance().getMaxNameLength()) + padAttribute(Bundle.getMessage("Len"), Control.max_len_string_length_name) + (panel.sortByConsist.isSelected() ? padAttribute(Bundle.getMessage("Consist"), Control.max_len_string_attibute) : padAttribute(Bundle.getMessage("Owner"), ownerMaxLen)) + (panel.sortByValue.isSelected() ? padAttribute(Setup.getValueLabel(), Control.max_len_string_attibute) : "") + (panel.sortByRfid.isSelected() ? padAttribute(Setup.getRfidLabel(), Control.max_len_string_attibute) : "") + ((!panel.sortByValue.isSelected() && !panel.sortByRfid.isSelected()) ? padAttribute(Bundle.getMessage("Built"), Control.max_len_string_built_name) : "") + Bundle.getMessage("Location") + NEW_LINE;
writer.write(header);
for (RollingStock rs : engines) {
Engine engine = (Engine) rs;
// loco number
number = padAttribute(engine.getNumber(), Control.max_len_string_print_road_number);
road = padAttribute(engine.getRoadName(), CarRoads.instance().getMaxNameLength());
model = padAttribute(engine.getModel(), EngineModels.instance().getMaxNameLength());
type = padAttribute(engine.getTypeName(), EngineTypes.instance().getMaxNameLength());
length = padAttribute(engine.getLength(), Control.max_len_string_length_name);
if (panel.sortByConsist.isSelected()) {
consist = padAttribute(engine.getConsistName(), Control.max_len_string_attibute);
} else {
owner = padAttribute(engine.getOwner(), ownerMaxLen);
}
if (panel.sortByValue.isSelected()) {
value = padAttribute(engine.getValue(), Control.max_len_string_attibute);
} else if (panel.sortByRfid.isSelected()) {
rfid = padAttribute(engine.getRfid(), Control.max_len_string_attibute);
} else {
built = padAttribute(engine.getBuilt(), Control.max_len_string_built_name);
}
location = "";
if (!engine.getLocationName().equals(Engine.NONE)) {
location = engine.getLocationName() + " - " + engine.getTrackName();
}
String s = number + road + model + type + length + owner + consist + value + rfid + built + location;
if (s.length() > numberCharPerLine) {
s = s.substring(0, numberCharPerLine);
}
writer.write(s + NEW_LINE);
}
} catch (IOException we) {
log.error("Error printing ConsistRosterEntry: " + e);
}
// and force completion of the printing
writer.close();
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintTrainAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
Train train = trainEditFrame._train;
if (train == null) {
return;
}
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, MessageFormat.format(Bundle.getMessage("TitleTrain"), new Object[] { train.getName() }), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
printTrain(writer, train);
// and force completion of the printing
writer.close();
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintRoutesAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
log.debug("Print all routes");
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, MessageFormat.format(Bundle.getMessage("TitleRoutesTable"), new Object[] {}), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
try {
// prevents exception when using Preview and no routes
writer.write(" ");
List<Route> routes = RouteManager.instance().getRoutesByNameList();
for (int i = 0; i < routes.size(); i++) {
Route route = routes.get(i);
writer.write(route.getName() + NEW_LINE);
printRoute(writer, route);
if (i != routes.size() - 1) {
writer.write(FORM_FEED);
}
}
} catch (IOException e1) {
log.error("Exception in print routes");
}
// and force completion of the printing
writer.close();
}
use of jmri.util.davidflanagan.HardcopyWriter in project JMRI by JMRI.
the class PrintDecoderListAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
try {
writer = new HardcopyWriter(mFrame, "DecoderPro V" + Version.name() + " Decoder Definitions", 10, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
// add the image
ImageIcon icon = new ImageIcon(FileUtil.findURL("resources/decoderpro.gif", FileUtil.Location.INSTALLED));
// we use an ImageIcon because it's guaranteed to have been loaded when ctor is complete
writer.write(icon.getImage(), new JLabel(icon));
// Loop through the decoder index, printing as needed
String lastMfg = "";
String lastFamily = "";
DecoderIndexFile f = DecoderIndexFile.instance();
// take all
List<DecoderFile> l = f.matchingDecoderList(null, null, null, null, null, null);
int i = -1;
log.debug("Roster list size: " + l.size());
for (i = 0; i < l.size(); i++) {
DecoderFile d = l.get(i);
if (!d.getMfg().equals(lastMfg)) {
printMfg(d, writer);
lastMfg = d.getMfg();
lastFamily = "";
}
if (!d.getFamily().equals(lastFamily)) {
printFamily(d, writer);
lastFamily = d.getFamily();
}
if (!d.getFamily().equals(d.getModel())) {
printEntry(d, writer);
}
}
// and force completion of the printing
writer.close();
}
Aggregations