/** {@inheritDoc} */ protected String paramString() { String curDate; if ((selectedComponents & DISPLAY_DATE) == DISPLAY_DATE) { curDate = DateFormat.getDateInstance(DateFormat.FULL, locale).format(getDate()); } else if ((selectedComponents & DISPLAY_TIME) == DISPLAY_TIME) { curDate = DateFormat.getTimeInstance(DateFormat.FULL, locale).format(getDate()); } else { curDate = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, locale) .format(getDate()); } return super.paramString() + ",selectedDate=" + curDate; }
/** * The constructor for this class has a bunch of arguments: The frame argument is required for all * printing in Java. The jobname appears left justified at the top of each printed page. The font * size is specified in points, as on-screen font sizes are. The margins are specified in inches * (or fractions of inches). */ public HardcopyWriter( Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin) throws HardcopyWriter.PrintCanceledException { // Get the PrintJob object with which we'll do all the printing. // The call is synchronized on the static printprops object, which // means that only one print dialog can be popped up at a time. // If the user clicks Cancel in the print dialog, throw an exception. Toolkit toolkit = frame.getToolkit(); // get Toolkit from Frame synchronized (printprops) { job = toolkit.getPrintJob(frame, jobname, printprops); } if (job == null) throw new PrintCanceledException("User cancelled print request"); pagesize = job.getPageDimension(); // query the page size pagedpi = job.getPageResolution(); // query the page resolution // Bug Workaround: // On windows, getPageDimension() and getPageResolution don't work, so // we've got to fake them. if (System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7)) { // Use screen dpi, which is what the PrintJob tries to emulate, anyway pagedpi = toolkit.getScreenResolution(); System.out.println(pagedpi); // Assume a 8.5" x 11" page size. A4 paper users have to change this. pagesize = new Dimension((int) (8.5 * pagedpi), 11 * pagedpi); System.out.println(pagesize); // We also have to adjust the fontsize. It is specified in points, // (1 point = 1/72 of an inch) but Windows measures it in pixels. fontsize = fontsize * pagedpi / 72; System.out.println(fontsize); System.out.flush(); } // Compute coordinates of the upper-left corner of the page. // I.e. the coordinates of (leftmargin, topmargin). Also compute // the width and height inside of the margins. x0 = (int) (leftmargin * pagedpi); y0 = (int) (topmargin * pagedpi); width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi); height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi); // Get body font and font size font = new Font("Monospaced", Font.PLAIN, fontsize); metrics = toolkit.getFontMetrics(font); lineheight = metrics.getHeight(); lineascent = metrics.getAscent(); charwidth = metrics.charWidth('0'); // Assumes a monospaced font! // Now compute columns and lines will fit inside the margins chars_per_line = width / charwidth; lines_per_page = height / lineheight; // Get header font information // And compute baseline of page header: 1/8" above the top margin headerfont = new Font("SansSerif", Font.ITALIC, fontsize); headermetrics = toolkit.getFontMetrics(headerfont); headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent(); // Compute the date/time string to display in the page header DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); df.setTimeZone(TimeZone.getDefault()); time = df.format(new Date()); this.jobname = jobname; // save name this.fontsize = fontsize; // save font size }
/** * This class is used in the model of the ACLTree. The MessageNode contains an ACLMessage, a * direction and a date/timestamp * * @author Chris van Aart - Acklin B.V., the Netherlands * @created April 26, 2002 */ public class ACLMessageNode extends DefaultMutableTreeNode { /** * Constructor for the MessageNode object * * @param str Description of Parameter */ ACLMessageNode(String str) { super(str); } /** * Gets the Message attribute of the MessageNode object * * @return The Message value */ public ACLMessage getMessage() { return theMessage; } /** * Gets the Performative attribute of the MessageNode object * * @return The Performative value */ public String getPerformative() { return theMessage.getPerformative(theMessage.getPerformative()); } /** * Gets the SendTo attribute of the MessageNode object * * @return The SendTo value */ public String getSendTo() { if (theMessage.getAllReceiver().hasNext()) { AID sender = (AID) theMessage.getAllReceiver().next(); return sender.getName(); } return "<unknown>"; } /** * Gets the Ontology attribute of the MessageNode object * * @return The Ontology value */ public String getOntology() { String ontology = theMessage.getOntology(); if (ontology != null) { return ontology; } return "<unknown>"; } /** * Gets the Direction attribute of the MessageNode object * * @return The Direction value */ public String getDirection() { return direction; } public String getTime() { return time; } public Date getTheDate() { return theDate; } /** * Sets the Message attribute of the MessageNode object * * @param msg The new Message value */ public void setMessage(ACLMessage msg) { theMessage = (ACLMessage) msg.clone(); } /** * Sets the Direction attribute of the MessageNode object * * @param theDirection The new Direction value */ public void setDirection(String theDirection) { direction = theDirection; } public void setTime(String theTime) { time = theTime; try { this.theDate = dateFormat.parse(time); } catch (Exception ex) { jade.util.Logger.getMyLogger(this.getClass().getName()) .log(jade.util.Logger.WARNING, ex.getMessage()); } } public void setTheDate(Date theTheDate) { theDate = theTheDate; } public String receivedFrom() { if (theMessage.getSender() != null) { AID sender = theMessage.getSender(); return sender.getName(); } return "<unknown>"; } private static DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); private Date theDate = new Date(); private ACLMessage theMessage; private String direction; private String time; }