@Override
	public int print(Graphics pg, PageFormat pageFormat,
			int pageIndex) throws PrinterException {

		pg.translate((int)pageFormat.getImageableX(),
				(int)pageFormat.getImageableY());
		int wPage = 0;
		int hPage = 0;
		if (pageFormat.getOrientation() == PageFormat.LANDSCAPE) {
			wPage = (int)pageFormat.getImageableWidth();
			hPage = (int)pageFormat.getImageableHeight();
		}
		else {
			wPage = (int)pageFormat.getImageableWidth();
			wPage += wPage/2;
			hPage = (int)pageFormat.getImageableHeight();
			pg.setClip(0,0,wPage,hPage);
		}

		int y = 20;
		pg.setFont(new java.awt.Font("Tahoma", Font.BOLD, 15));
		pg.setColor(Color.black);

		FontMetrics fm = pg.getFontMetrics();
		y += fm.getAscent();
		Graphics2D pg2 = (Graphics2D) pg;
		FontRenderContext frc = pg2.getFontRenderContext();
		StringBuffer sb = new StringBuffer(WindMill.propertyFile.getProperty("SHIP"));
		sb.append(" alarm data");
		String bigTitle = sb.toString();
		Rectangle2D bounds = pg2.getFont().getStringBounds(bigTitle, frc);
		int tWidth = (int) bounds.getWidth();

		pg.drawString(bigTitle, wPage/3 -tWidth/2, y);
		y += 20; // space between title and table headers

		Font headerFont = new Font("Tahoma", Font.PLAIN, 11);
		pg.setFont(headerFont);
		fm = pg.getFontMetrics();

		TableColumnModel colModel = table.getColumnModel();
		int nColumns = colModel.getColumnCount();
		int x[] = new int[nColumns];
		x[0] = 50;

		int h = fm.getAscent();
		y += h; // add ascent of header font because of baseline
		// positioning (see figure 2.10)

		int nRow, nCol;
		for (nCol=0; nCol<nColumns; nCol++) {
			TableColumn tk = colModel.getColumn(nCol);
			int width = 100;//tk.getWidth();
			if (x[nCol] + width > wPage) {
				nColumns = nCol;
				break;
			}
			if (nCol+1<nColumns)
				x[nCol+1] = x[nCol] + width;
			String title = (String)tk.getIdentifier();
			pg.drawString(title, x[nCol], y);
		}

		pg.setFont(new java.awt.Font("Tahoma", Font.PLAIN, 8));
		fm = pg.getFontMetrics();

		int header = y;
		h = fm.getHeight();
		int rowH = Math.max((int)(h*1.5), 10);
		int rowPerPage = (hPage-header-3*rowH)/rowH; // 2*rowH is one blank line plus footer plus one blank
		int m_maxNumPage = Math.max((int)Math.ceil(table.getRowCount()/
				(double)rowPerPage), 1);
		if (pageIndex >= m_maxNumPage)
			return NO_SUCH_PAGE;

		int iniRow = pageIndex*rowPerPage;
		int endRow = Math.min(table.getRowCount(),
				iniRow+rowPerPage);

		for (nRow=iniRow; nRow<endRow; nRow++) {
			//y += h;
			y+=rowH;
			for (nCol=0; nCol<nColumns; nCol++) {
				int col = table.getColumnModel().getColumn(nCol).getModelIndex();
				Object obj = table.getValueAt(nRow, col);
				String str = obj.toString();
				pg.setColor(Color.black);
				pg.drawString(str, x[nCol], y);
			}
		}
		pg.drawString("Page "+ (pageIndex+1), 300, hPage - rowH);
		//System.gc();
		return PAGE_EXISTS;
	}