Java - Miscellaneous Notes
  21 Days:   Wk1 . Wk1Ref . Applts . Swing . Grph . D13-14 . D15-21 . D22-28
  cc12:   Miscl . SQL . EJB . Vocab . (NotesHelp) . J2EE . Web
  misl:   21 Days(src) . Dictionary(foldoc) . Unicode . Tables . Print . html
  misl:   F.Allimant . Swing (J.H.University)


  MISL. NOTES. (miscl)
-----Mar/23/2004 TUE Create a custom Java 1.2-style ClassLoader ("simple") -----Mar/15/2004 MON ===DYNAMIC JAVA TOPICS - Class ClassLoader (mentioned by, Pallavi) . Understanding the Java ClassLoader (Level: Introductory) Java Technology TUTORIALS - Package java.lang.reflect (mentioned by, Subrata) - Java Virtual Machine Specification (mentioned by, ClassLoader.defineClass()) ===Encryption - Cracking Java byte-code encryption - Why Java obfuscation schemes based on byte-code encryption won't work. -----Jul/10/2002 WED ===San Diego State University : CS 535: Object-Oriented Programming & Design - File and StreamTokenizer -----Jul/02/2002 TUE: TEXT AND FONTS ===Internationalization Frequently Asked Questions - Text Processing - format a date / etc. - Text Rendering - Fonts / etc. - more... ===Other links... - Font Overview - Editing the font.properties Files -----Jun/27/2002 THU http://www.onjava...com/pub/a/onjava/excerpt/javanut4_ch04/ // Arrays.equals() compares all elements of two arrays String[] clone = (String[]) strarray.clone(); boolean b1 = Arrays.equals(strarray, clone); // Yes, they're equal -----Jun/21/2002 FRI: PROBABLY USED TO CAPTURE URL STREAM TO A FILE - JEditorPane . protected InputStream getStream(URL page) Fetches a stream for the given URL, which is about to be loaded by the setPage method. -----Jun/03/2002 MON: File IO Sample - FileOutputStream -----May/31/2002 FRI TESTER CLASS: ALWAAAYS... - Always make the tester class that "extends JFrame". (Pallavi) -----May/30/2002 THU - Finding help with Swing/JTree. Google Search: "Interfaces Using Swing" -----May/16/2002 THU GETTING RETURN VALLLUES IN (StringBuffer b) PARAMETER "I was under the impression that objects are passed by reference in Java, but I've run into two cases that seem to contradict one another. Here's my code snippet: ..." public class Test { // This sample method DOES return the modified string. private void changeBuffer(StringBuffer b) { b.append(" World!"); } ... } www.javajunkies.org
  TIPS.
===(B19.pg.277) Easy way to make a non-String into a String: Add it to an empty String. // Example: int newValue = 5; value.setText("" + newValue); ******************************************************************************** B19 - Teach Yourself Java 2 in 21 Days. 2nd ed. Lemay and Cadenhead. © 2001. ********************************************************************************
  GLOSSARY.

  QUESTIONS. (miscl)
-----Jun/25/2002 TUE pre [ ]Q: How can I be sure that javac will compile all needed java code? -----Jun/20/2002 THU [ ]Q: Can a class be static? -----Jun/03/2002 MON [*]Question: Can "protected methods" be called outside of the class? - Only those in the "package" (Anand) -----May/30/2002 THU Q[ ]: What is "Serrrialized"? - "Warning: Serialized objects of this class will not be compatible with future Swing releases. ..." -----May/28/2002 TUE "this" and "super""" public class TableSorter extends TableMap { int indexes[]; Vector sortingColumns = new Vector(); boolean ascending = true; int compares; ... public void sortByColumn(int column, boolean ascending) { this.ascending = ascending; // [ ]Question: "this" sortingColumns.removeAllElements(); sortingColumns.addElement(new Integer(column)); sort(this); super.tableChanged(new TableModelEvent(this)); // [ ]Question: "super" } } -----May/17/2002 FRI [ ]Q: What is "Serrrialized"? "Serialized objects of this class will not be compatible with future Swing releases." -----May/02/2002 THU [ ]Q: Is swing a sssubset that makes things easier? ===Packages that use TableColumn - javax.swing - Provides a set of "lightweight" (all-Java language) components that, to the maximum degree possible, work the same on all platforms. - javax.swing.table - Provides classes and interfaces for dealing with javax.swing.JTable.
  COMPILE ERRORS.
-----May/17/2002 FRI S:\users\djg\_java\TRX.10>javac TableFunctionsAdapter.java TableFunctionsAdapter.java:107: local variable table is accessed from within inner class; needs to be declared final int colClicked = table.columnAtPoint(e.getPoint()); ^ (next error) TableFunctionsAdapter.java:179: cannot resolve symbol symbol : method getContentPane () location: class TableFunctionsAdapter getContentPane().add(scrollPane, BorderLayout.CENTER); ^
  TABLES.
-----Jun/06/2002 THU: SORTING ADDED TO::: "class TableTester extends JFrame" // ************************************************************************ final DefaultTableModel dtm = new DefaultTableModel(data, columnNames); final TableSorter sorter = new TableSorter(dtm); // ADDED THIS // final JTable returnTbl = new JTable(dtm); // REMOVED final JTable returnTbl = new JTable(sorter); // NEW sorter.addMouseListenerToHeaderInTable(returnTbl); // ADDED THIS /************************************************************************** // BEFORE SORT... (data, columnNames) <-> DefaultTableModel dtm <-> JTable returnTbl // WITH SORT... (data, columnNames) <-> DefaultTableModel dtm <-> TableSorter sorter // download: "TableSorter" and "TableMap". <-> JTable returnTbl -> sorter.addMouseListenerToHeaderInTable(returnTbl); **************************************************************************/ -----May/07/2002 TUE INSIGHT FOR ADDINGGG A ROW ==="JTable doesn't contain or cache data". ==="Detecting Data Changes" - "A table and its model automatically detect whenever the user edits the table's data. However, if the data changes for another reason, you must take special steps to notify the table and its model of the data change. Also, if you don't implement a table model, as in SimpleTableDemo, then you must take special steps to find out when the user edits the table's data. - An example of updating a table's data without directly editing it is in the BINGO application. The BINGO application, which is presented in BINGO!, has a table that displays some information about each user who is signed up to play the game. When a new user signs up to play BINGO, the table needs to add a new row for that user. More precisely, the table model needs to get the data for the new user, and then the table model needs to tell the table to display the new data." -----May/02/2002 THU "TableModel and JTTTable" ===Class TableColumn - java.lang.Object | +--javax.swing.table.TableColumn - Constructors... . TableColumn(int modelIndex) - Fields... . protected int modelIndex The index of the column in the model which is to be displayed by this TableColumn. As columns are moved around in the view modelIndex remains constant. [ ]Question: Does addColumn() increase the array of objects for actual "data" objects. Note: jTbl.addColumn(new TableColumn(modelColumn, width, cellRenderer, cellEditor)); [ ]Question: Does addColumn() increase the array of objects for actual "data" objects. Note: public void addColumn(TableColumn aColumn) : Appends aColumn to the end of the array of columns held by this JTable's : column model. If the column name of aColumn is null, sets the column : name of aColumn to the name returned by getModel().getColumnName(). ===Sample downloaded to: ?:\xln54\rnd\javaDemos\SimpleTableDemo\ ===(from Sun docs): public interface TableModel The TableModel is an interface. TableModel specifies the methods the JTable will use to interrogate a tabular data model. The JTable can be set up to display any data model which implements the TableModel interface with a couple of lines of code: TableModel myData = new MyTableModel(); JTable table = new JTable(myData); ===(from Sun docs): public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible JTable is a user-interface component that presents data in a two-dimensional table format. See How to Use Tables in The Java Tutorial for task-oriented documentation and examples of using JTable. The JTable has many facilities that make it possible to customize its rendering and editing but provides defaults for these features so that simple tables can be set up easily. - public Object getValueAt(int row, int column) Returns the cell value at row and column. Note: The column is specified in the table view's display order, and not in the TableModel's column order. ** THIS IS AN IMPORTANT DISTINCTION ** because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering. ===Extra: Get grasp of the topics mentioned in this sentence... "Your model might hold its data in an array, vector, or hashtable, or it might get the data from an outside source such as a database." -----Apr/30/2002 TUE ===Class JTable java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JTable ===Class JFrame java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Window | +--java.awt.Frame | +--javax.swing.JFrame
  PRINTING.
-----Jun/26/2002 WED: UNDERSTANDING PRINTING ===PageFormat class - "describes the size and orientation of a page to be printed". ===Our print() function calls this line of code... componentToBePrinted.paint(g2d); - Component . public void paint(Graphics g) - Paints this component. ===The Graphics class - It is the abstract base class for all graphics contexts that allow an application to draw onto components that are realized on various devices, as well as onto off-screen images. - A Graphics object encapsulates state information needed for the basic rendering operations that Java supports. - This state information includes the following properties: . The Component object on which to draw. . A translation origin for rendering and clipping coordinates. . The current clip. . The current color. . The current font. . The current logical pixel operation function (XOR or Paint). . The current XOR alternation color (see setXORMode(java.awt.Color)). -----Jun/25/2002 TUE: ===May focus less on rtf at this time. ===Looking at HTML - www.microsoft.com/truetype/fontpack/win.htm Microsofts special web fonts that anyone can download. -----Jun/24/2002 MON: (Links to: http:////java.sun.com/j2se/1.4/docs/) === (medium length) 7.2 - PRINTING CONCEPTS - "The Java Printing API is based on a callback printing model in which the printing system, not the application, controls when pages are printed". - Supporting Printing - two tasks needed: Job control, and Imaging. - (short) Job Control - "the application creates a PrinterJob object and uses it to manage the printing process". - (medium) - Imaging - (terms: Page Painter, and (Printable Job, or Pageable Job)) a) [The application provides a page painter that implements the Printable interface]. When the printing system needs a page rendered, it calls the page painter's print() method, which is part of the application. b) "When a page painter's print method is called, it is passed a Graphics context (defn) to use to render the page image. It is also passed a PageFormat object (defn) that specifies the geometric layout of the page, and an integer page index that identifies the ordinal position of the page in the print job". c) The printing system supports both Graphics and Graphics2D rendering. Cast Graphics objects to (Graphics2D) when printing them. (Examples: Java 2DTM Shapes, Text, and Images). These are passed to the print() method. d) "To print documents in which the pages use different page painters and have different formats, you use a pageable job. To create a pageable job, you can use the Book class or your own implementation of the Pageable interface. To implement simple printing operations, you do not need to use a pageable print job; Printable can be used as long as all of the pages share the same page format and painter".
Printing
   Interfaces and Classes
   Printing Concepts
      Supporting Printing
      Page Painters
      Printable Jobs and Pageable Jobs
      Typical Life-Cycle of a PrinterJob
      Dialogs
   Printing with Printables
      Using Graphics2D for Rendering
   Printing with Pageables and Books
      Using a Pageable Job
      Using Multiple Page Painters
===2PROBLEMS(#1): When printing starts the dialog is poped up when a call to print a Component is made. (NONE OF THESE 3 SHOULD BE A PROBLEM). [*]PROBLEM1: The currently dissplayed Component is expected to be printed first. [*]PROBLEM2: How to print a Component /wo dlg poped up at all. [*]PROBLEM3: How to print a Component /wo dlg poped up once for every page. ===SOLUTION(#1.part1): Rewrite PrintUtilities'. [*]: Add "showPrintDialog" to optionally call printDialog()... public void print() { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); // <<< This line does not sets what component is to be printed. if (!showPrintDialog || printJob.printDialog()) try { printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } } ===SOLUTION(#1.part2): Probably to come up with a similar function to PrintUtilities'... public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { Graphics2D g2d = (Graphics2D)g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(componentToBePrinted); componentToBePrinted.paint(g2d); enableDoubleBuffering(componentToBePrinted); return(PAGE_EXISTS); } } // The rewrite to the above is to handle all of the pages. // **** setPrintable() (of Class PrinterJob) ********************************** // - public abstract void setPrintable(Printable painter) // - Calls painter to render the pages. The pages in the document to be printed // by this PrinterJob are rendered by the Printable object, painter. The // PageFormat for each page is the default page format. // - Parameters: // painter - the Printable that renders each page of the document. // **************************************************************************** [ ]FORNOW: Assume each page is same TYPE. [ ]LATER: Add more page flexability, for each page, from ideas on this link... jw-0202-print-p3.html - The PFPage class ... you must create an instance of PFPage for each page... -----Jun/19/2002 WED NOTE!: JEditorPane can be HTML, RTF, PLAIN-TEXT, or probably custom content. LINK: BorderLayout class - ===TReport1 class - .\TRX.10\TReport1a\ is a backup of TReport1 ver 0.1a. It now puts html in a panel. This is in a splitPane. Toolbars are docable on any edge of the html panel. Next step of development is to get this working from a string, then type to be rtf instead of html. Then next get editPanels working from arrays of String objs. ******************************************************************************* -----Jun/18/2002 TUE: INCORPRATING ACTUUUATE REPORTING TOOL - We have more or less decided to incorprate Actuate reporting tool into TReX for our immediate Reporting needs. I have added the actuate API and programming help on to our held web site at 10.1.1.18 the help is avaliable under the developers page. - This should help us get familiar with actuate till be get licensed copies of the tool. (Anand) -----Jun/17/2002 MON: PRINTING SUPPORT FOR TREX 1.0 ===Looks like our first version of Trex will support printing by use of a Third Party Printing Package. Probably either: 1) an Acuate Product or 2) JReport. -----Jun/17/2002 MON: JAVA'S UNDERLYINGGG PRINT SUPPORT ===3rd party packages are probably implemented through a "custom java editor kit". ===StyledEditorKit classes: - Direct Known Subclasses: HTMLEditorKit, and RTFEditorKit. - Use of this class may support an "editor". - Four ways of of using editor kits are... A) HTML B) RTF (rich text format) (Java's built is support is limited). C) PLAIN-TEXT. (what font) (Not sure if we can select font). D) Own custom output type(s) (If desired, probably wait for later version). ===Sample of actual printing function call... //--- Print the vertical lines for (i = 0; i < pageFormat.getWidth (); i += INCH / 2) { line.setLine (i, 0, i, pageFormat.getHeight ()); g2d.draw (line); } ===Support for something similar to XLN54'S PRNLIB maybe considered at some later time. This may or may not involve the use of an editor kit. ******************************************************************************* Trex printing requirements, concerns: _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ _______________________________________________________________________________ ******************************************************************************* -----Jun/13/2002 THU: RND for RTFEditorKKKit ===http://www.mindspring.com/~scdrye/java/faq.html Q: How do I use the RTFEditorKit? A: The easiest way is to create a JEditorPane and call setContentType("text/rtf"). The JEditorPane will look for an EditorKit registered as supporting that type, and will find the RTFEditorKit by default. Q: How can I use the RTFEditorKit without creating a JEditorPane? A: Create an instance of RTFEditorKit directly, and then create an empty Document using the createDefaultDocument() method. The read() and write() methods can then be used to load or save the document to a stream. - INTERESTING: Notice how read and write can be used. ===Safari | Java Swing -> 24.1 Overview of the Editor Kits - Looks VERY GOOD at a glance. Incudes a DIAGRAM on "EditorKit and related classes". ===Class RTFEditorKit (page of Sun's j2se/v1.4.0 doc) ===From: Java Live - Advanced AWT Topics (June 1997) Q: const: RichText component is mentioned on Swing WWW page. Will it be allowed to embed other components in rich text? Will it support full HTML and RTF or only subset of them? A: SPK-Georges: You can embed other components in the RichText component. Both RTF and HTML will be supported in the final version (I can't swear to which version of HTML). In fact, the parser is fairly seperate so it should be pretty easy to modify the component to handle other document formats. ===3rd Party Items - NLP Programmer's Library For Java Programmers 1) Text - by default, files are assumed to be plain text unless they have a recognized file extension. 2) RTF - Rich Text Documents (files with the extension .rtf) 3) PDF - Portable Document Format (files with the extension .pdf) 4) Word - Microsoft (tm) Word document files (files with the extension .doc) 5) HTML - Web documents (files with the extension .htm or .html) - JReport - If we consider buying a 3rd party report package, we SHOULD AT LEAST GLANCE AT THIS. ($2,000) - Google: Computers>Programming>Languages>Java>Databases and Persistence>Clients -----Jun/12/2002 WED: SUGGESTION FOR XLNNN PRINT GOALS - At this point, I believe Xln's printing should be a simplified, first phase, printing support. Then later, when the rest of the system is developed more, our java insight improves, that we design and code a more sufficient printing system. Another advantage to this two stage approach is: Sun could come up with a better printing layer, and/or document java 1.4 printing better. - First phase printing will include "text", "HTML", and some "Rich Text Format". Output will first be sent to a file (or String obj), then printed. -----Jun/11/2002 TUE ===(Printing before April 1999) JavaTM AWT: Printing - Purpose - The goal for the AWT printing API is to give developers an easy mechanism to print the AWT components using native platform facilities. This API is designed for use with the current AWT Graphics model. - The Printing API - The printing API is very simple and consists primarily of one method in class java.awt.Toolkit... ===Quoting Sun's java doc on "Class JEditorPane"... - By default, the following types of content are known: 1) text/plain - Plain text, which is the default the type given isn't recognized. The kit used in this case is an extension of DefaultEditorKit that produces a wrapped plain text view. 2) text/html - HTML text. The kit used in this case is the class javax.swing.text.html.HTMLEditorKit which provides HTML 3.2 support. 3) text/rtf - RTF text. The kit used in this case is the class javax.swing.text.rtf.RTFEditorKit which provides a limited support of the Rich Text Format. ===(J.H.University) JEditorPane - "...is sort of a fancy text area that can display text derived from different file formats. The built-in version supports HTML and RTF (Rich Text Format) only, but you can build "editor kits" to handle special purpose applications...RTF support is pretty primitive." - "Plain Text", "HTML", and "Rich Text Format" - has limited support within "class JEditorPane". - JEditorPane.registerEditorKitForContentType() might be usable for setting up our own print library. Implementing a Custom Editor [ ]Decision: Consider differences between outputing info record by record, as we go and outputing to printer by processing an intermeadiary file. ===Downloads for (possibly) class source files.HTMLEditorKit.java (byu) -----Jun/10/2002 MON - Printing some examples from JavaWorld 1200 Print 1) Example1.java - Half inch grid. Notices measurements were NOT exact. [ ]theory: One print-job calls print(), once for each page. This print() function needs to handle all pages. Page break by return(PAGE_EXISTS); And end print job by return(NO_SUCH_PAGE); 2) Example2.java -----Jun/05/2002 WED: LOOKS LIKE GOOD MATERIAL AND COMPREHENSIVE - "Printing in Java," Jean-Pierre Dubé (JavaWorld) Learn the strengths and weaknesses of the Java printing API. -----Jun/03/2002 MON: GOOD WAY TO PRINTTT COMPONENTS ===Use this link to develop a new printing approach possibility. http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-Printing.html - "Java 1.2 now supports high-quality printing via classes in the java.awt.print package." [*]Deffinition: Java "package" - is a grouping of classes and interfaces. (pg.53) - "Printing Basics - There are two basic steps required to print: 1) settting up the print job, and 2) rendering graphics on the printer." - 1) "Setting Up the Print Job" - This is virtually always done the same way: - a) "get a PrinterJob object", - b) "pass a Printable to its setPrintable method", - c) "call printDialog" to pop up an OS-specific print dialog, - d) and finally, assuming the user hasn't cancelled the printing from the dialog (you check this by testing the return value of printDialog), "call print on the PrinterJob". - Note) The role of the "Printable" is to define a "print" method showing how the actual drawing to the printer will be done. That's described in the next section. - Here's an example: PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); if (printJob.printDialog()) try { printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } - 2) "Rendering Graphics on the Printer" - The Printable that is passed to setPrintable must have a "print" method that describes how to send drawing to the printer. - a) Decide what to do for different pages of your print job, since Java repeatedly calls print with higher and higher page indexes until print returns NO_SUCH_PAGE. - Note) In the case of printing Swing components, you only have one page. So you return PAGE_EXISTS for index 0, NO_SUCH_PAGE otherwise. - b) Start drawing. In general, you can do any sort of drawing you want. - Note) In the case of printing Swing components, your drawing should just be a high-resolution version of what the component looks like on the screen. 1) So you cast the Graphics object to Graphics2D, 2) scale the resolution to the printer, 3) and call the component's paint method with this scaled Graphics2D. Note) It's this reliance on the Graphics2D's coordinate transformations that prevents this capability from being available in the Java 1.1 version of Swing. - For more info, and the source page for these notes: (click) -----May/24/2002 FRI - Printing basics and more: Printing Swing Components in Java 1.2 - "Java 1.2 now supports high-quality printing via classes in the java.awt.print package. ... There are two basic steps required to print: settting up the print job, and rendering graphics on the printer." ===PRINTING GOAL ===LOOKING FOR STARTING POINT [Y]: Package java.awt.print - Provides classes and interfaces for a general printing API. [y]: Class PrinterJob (java.awt.print) java.lang.Object | +--java.awt.print.PrinterJob "The PrinterJob class is the principal class that controls printing. An application calls methods in this class to set up a job, optionally to invoke a print dialog with the user, and then to print the pages of the job." - - - - - - - - - - [n]: Java 2DTM API Specification - is a set of classes for advanced 2D graphics and imaging. [n]: Package java.io - Provides for system input and output through data streams, serialization and the file system. [n]: Class PrintStream (java.io) java.lang.Object | +--java.io.OutputStream | +--java.io.FilterOutputStream | +--java.io.PrintStream - Direct Known Subclasses: LogStream - Methods in java.awt with parameters of type PrintStream - (Example 3/3): Container.list(PrintStream out, int indent) Prints a listing of this container to the specified output stream. [N]: Uses of Class java.io.OutputStream "OuputStream is the Java API for writing IDL types to CDR marshal streams." - IDL - Interface Definition Language. APIs written in the Java(TM) programming language that provide standards-based interoperability and connectivity with CORBA (Common Object Request Broker Architecture).
  TOOLBAR.
-----Jun/07/2002 FRI
Home