⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fjreport.java

📁 定要上载质量高而定要上载质量高而定要上载质量高而定要上载质量高而定要上定要上载质量高而定要上载质量高而载质量高而
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		border0.setOrientation(Line.HORIZONTAL_ORIENTATION);
		border1.setOrientation(Line.VERTICAL_ORIENTATION);
		border2.setOrientation(Line.HORIZONTAL_ORIENTATION);
		border3.setOrientation(Line.VERTICAL_ORIENTATION);
		
		int x = (int) pageFormat.getImageableX();
		int y = (int) pageFormat.getImageableY();
		int w = (int) pageFormat.getImageableWidth();
		int h = (int) pageFormat.getImageableHeight();
		
		x = x + Line.lineInterval - x % Line.lineInterval;
		y = y + Line.lineInterval - y % Line.lineInterval;
		w = w - Line.lineInterval - w % Line.lineInterval;
		h = h - Line.lineInterval - h % Line.lineInterval;

		border0.setInVisible(true);
		border1.setInVisible(true);
		border2.setInVisible(true);
		border3.setInVisible(true);
		border0.setStartPoint(new Point(x, y));
		border0.setLength(w);
		border1.setStartPoint(new Point(x, y));
		border1.setLength(h);
		border2.setStartPoint(new Point(x, y+h));
		border2.setLength(w);
		border3.setStartPoint(new Point(x+w, y));
		border3.setLength(h);

		currentPage.hLines.add(border0);
		currentPage.vLines.add(border1);
		currentPage.hLines.add(border2);
		currentPage.vLines.add(border3);
	}

	/** 
	 * Get x coordinate of the imageable border.
	 * this corrdinate is slightly different from 
	 * pageformat.getPaper().getImageableX(). Because for
	 * easily snap to grid, the line's position and length is 
	 * automatically set to the round interger that can be 
	 * divided exactly by Line.lineInterval. 
	 * @see net.sf.fjreport.line.Line#lineInterval lineInterval
	 * @return x
	 */
	public int getImageableBorderX(){
		int x = (int) pageFormat.getImageableX();
		return x + Line.lineInterval - x % Line.lineInterval;
	}
	/**
	 * @see FJReport#getImageableBorderX() getImageableBorderX
	 * @return  y
	 */
	public int getImageableBorderY(){
		int y = (int) pageFormat.getImageableY();
		return y + Line.lineInterval - y % Line.lineInterval;
	}
	/**
	 * @see FJReport#getImageableBorderX() getImageableBorderX
	 * @return width
	 */
	public int getImageableBorderWidth(){
		int w = (int) pageFormat.getImageableWidth();
		return w - Line.lineInterval - w % Line.lineInterval;
	}
	/**
	 * @see FJReport#getImageableBorderX() getImageableBorderX
	 * @return height
	 */
	public int getImageableBorderHeight(){
		int h = (int) pageFormat.getImageableHeight();
		return h - Line.lineInterval - h % Line.lineInterval;
	}
	
	/**
	 *  
	 */
	public Zoom getZoom() {
		return zoom;
	}

	/**
	 * zoom
	 * @param zoom
	 */
	public void setZoom(Zoom zoom) {
		this.zoom = zoom;
	}

	/* (non-Javadoc)
	 * @see javax.swing.JComponent#paint(java.awt.Graphics)
	 */
	public void paint(Graphics arg0) {
		// TODO Auto-generated method stub
		super.paint(arg0);
		arg0.drawRect(1, 1, (int)pageFormat.getWidth()-2, (int)pageFormat.getHeight()-2);
		Iterator it;
		Line line;
		Graphics2D g2d = (Graphics2D) arg0;
		
		if (state == CELL_STATE) {
			if (currentPage.cells != null) {
				it = currentPage.cells.iterator();
				while (it.hasNext()) {
					((Cell)it.next()).render(0, 0, g2d);
				}
			}
		} else if (state == EDIT_STATE || state == READONLY_STATE) {
			if (currentPage.cells != null) {
				it = currentPage.cells.iterator();
				Cell cell;
				while (it.hasNext()) {
					cell = (Cell)it.next();
					if (cell.getType() == Cell.TYPE_LABEL)
						cell.render(0, 0, g2d);
				}
			}
		}
		
		it = currentPage.vLines.iterator();
		while (it.hasNext()) {
			((Line)it.next()).render(0, 0, g2d);
		}
		it = currentPage.hLines.iterator();
		while (it.hasNext()) {
			((Line)it.next()).render(0, 0, g2d);
		}
		if (operation != null) operation.render(0, 0, g2d);
		
		g2d.dispose();
	}

	/**
	 * @see FJReport#DRAWLINE_STATE DRAWLINE_STATE
	 * @see FJReport#CELL_STATE CELL_STATE
	 * @see FJReport#EDIT_STATE EDIT_STATE
	 * @see FJReport#READONLY_STATE READONLY_STATE
	 * 
	 * @return state of report
	 */
	public int getState() {
		return state;
	}

	/**
	 * @see FJReport#DRAWLINE_STATE DRAWLINE_STATE
	 * @see FJReport#CELL_STATE CELL_STATE
	 * @see FJReport#EDIT_STATE EDIT_STATE
	 * @see FJReport#READONLY_STATE READONLY_STATE
	 * 
	 * @param state
	 */
	public void setState(int state) {
//		if (this.state == state) return;
		removeAll();
		if (this.state == DRAWLINE_STATE && state != DRAWLINE_STATE) {
			reCalcCells();
			buildMap();
		}
		this.state = state;
		if (state == DRAWLINE_STATE) {
			setOperation(new LineMouseControl(this));
		} else if (state == CELL_STATE) {
			setOperation(new CellMouseControl(this));
		} else if (state == EDIT_STATE) {
			addAllEditor();
//			setOperation(new EditMouseControl(this));
			setOperation(null);
			for (int i = 0; i < pages.size(); i++) {
				List cells = ((FJReportPage)pages.get(i)).cells;
				for (int j = 0; j < cells.size(); j++) {
					((Cell)cells.get(j)).setReadOnly(false);
				}
			}
		} else if (state == READONLY_STATE) {
			addAllEditor();
			for (int i = 0; i < pages.size(); i++) {
				List cells = ((FJReportPage)pages.get(i)).cells;
				for (int j = 0; j < cells.size(); j++) {
					((Cell)cells.get(j)).setReadOnly(true);
				}
			}
		}
		updateUI();
	}
	
	private void addAllEditor() {
		if (currentPage == null || currentPage.cells == null) return;
		removeAll();
		Iterator it = currentPage.cells.iterator();
		while (it.hasNext()) {
			((Cell) it.next()).registerEditor();
		}
	}

	private void setOperation(BaseControl control) {
		if (this.operation != null) {
			if (this.operation instanceof MouseMotionListener) 
				removeMouseMotionListener(this.operation);
			if (this.operation instanceof MouseListener) 
				removeMouseListener(this.operation);
		}
		if (control != null) {
			if (control instanceof MouseMotionListener) 
				addMouseMotionListener(control);
			if (control instanceof MouseListener) 
				addMouseListener(control);
		}
		this.operation = control;
	}

	private void calcCells(){   

	// Performance of this algorithm is about O(vLine.size * hLine.size)
	// In order to keep the previous designed cells, when new cells
	// are calculated out, all new cells will be compared to the previous
	// cells, if the intersect area above 1/2, the two cells are
	// considered to be the same one, then the previous cell properties
	// will be set to the new one.
	// Considering the comparing operations between previous cells and new cells,
	// the performance of this function is about O(vLine.size * hLine.size)^2

		List vLines = currentPage.vLines;
		List hLines = currentPage.hLines;
		Collections.sort(vLines);
		Collections.sort(hLines);
		Line hLine, vLine;
		int x, y, l, x2, y2, l2;
		int i2, j2;
		int k;
		int hSize = hLines.size();
		int vSize = vLines.size();		
		boolean[][][] joins = new boolean[hSize][vSize][4]; // 4 orientation,  east, south, west, north
		boolean[] join;
		for (int i = 0; i < hSize; i++) {
			hLine = (Line) hLines.get(i);
			x = hLine.getX();
			y = hLine.getY();
			l = hLine.getLength();
			for (int j = 0; j < vSize; j++){
				vLine = (Line) vLines.get(j);
				x2 = vLine.getX();
				y2 = vLine.getY();
				l2 = vLine.getLength();
				join = joins[i][j];
				if (y < y2 - 5 || y > y2 + l2 + 5 || x2 < x - 5 || x2 > x + l + 5) { //no join
					join[0] = false;  //then 4 orientation no join
					join[1] = false;
					join[2] = false;
					join[3] = false;
					continue;
				}
				joins[i][j][0] = (x + l > x2 + 5);  // east
				joins[i][j][1] = (y2 + l2 > y + 5);  //south 
				joins[i][j][2] = (x < x2 - 5); //west
				joins[i][j][3] = (y2 < y - 5); //north
			}
		}
		for (int i = 0; i < hSize - 1; i++) {
			for (int j = 0; j < vSize - 1; j++){
				if (joins[i][j][0] && joins[i][j][1]) {  //east join && north join
					for (j2 = j + 1; j2 < vSize; j2++) //then look for next sounth join along the hLine
						if (joins[i][j2][1]) break;
					if (j2 < vSize) {  // found next south join
						for (i2 = i + 1; i2 < hSize; i2++)//then look for next west join along the hLine
							if (joins[i2][j2][2]) break;
						if (i2 < hSize) {  // found next west join
							if (joins[i2][j][3] && joins[i2][j][0]) {
								for (k = j2 - 1; k > j; k--) 
									if (joins[i2][k][3]) break;
								if (k == j) {
									for (k = i2 - 1; k > i; k--)
										if (joins[k][j][0]) break;
									if (k == i) {  //found
//										if (i != 0 || j != 0 || i2 != hSize - 1 || j2 != vSize - 1)  //abandon the border cell
											addCell(i, j, i2, j2);
									}
								}
							}								
						}
					}
					j = j2-1;		//skip the useless joins
				}
			}
		}
		updateUI();
	}

	private void addCell(int i, int j, int i2, int j2) {
		int x1 = ((Line)currentPage.vLines.get(j)).getX() + ((Line)currentPage.vLines.get(j)).getLineWidth()/2+1;
		int y1 = ((Line)currentPage.hLines.get(i)).getY() + ((Line)currentPage.hLines.get(i)).getLineWidth()/2+1;
		int x2 = ((Line)currentPage.vLines.get(j2)).getX() - ((Line)currentPage.vLines.get(j2)).getLineWidth()/2;
		int y2 = ((Line)currentPage.hLines.get(i2)).getY() - ((Line)currentPage.hLines.get(i2)).getLineWidth()/2;
		if (x2 - x1 < 4 && y2 - y1 < 4) return; // abandon tiny cell;
		Iterator it = currentPage.cells.iterator();
		Cell c;
		while (it.hasNext()) {
			c = (Cell)it.next();
			if ( c.contains(x1, y1, x2-x1, y2-y1) ) {
				currentPage.cells.remove(c);
				break;
			}
		}
		if (currentPage.oldCells != null) {
			it = currentPage.oldCells.iterator();
			while (it.hasNext()) {
				c = (Cell) it.next();
				if ( c.equil(x1, y1, x2, y2)) {
//				if ( c.equil(i, j, i2, j2) ) {	// if found the same cell in oldcells, then add the oldcell, to keep the modified properties.
					currentPage.cells.add(c);
					c.x = x1;
					c.y = y1;
					c.width = x2 - x1;
					c.height = y2 - y1;
					return;
				}
			}
			currentPage.cells.add(new Cell(this, x1, y1, x2, y2, i, j, i2, j2));
		} else currentPage.cells.add(new Cell(this, x1, y1, x2, y2, i, j, i2, j2));
	}

	/**
	 * Print the report.
	 */
	public void print() {
		PrinterJob job = PrinterJob.getPrinterJob();
		try {
			job.setPrintable(this, job.validatePage(pageFormat));
			if (job.printDialog()) {
				job.setJobName("Flying Frank Report Printing");
				job.print();
			}
		} catch (PrinterException exception) {
			JOptionPane.showMessageDialog(this, exception);
		}
	}

	private void reCalcCells() {
		Iterator it = currentPage.hLines.iterator();
		while (it.hasNext()) {
			((Line)it.next()).cells.clear();
		}
		it = currentPage.vLines.iterator();
		while (it.hasNext()) {
			((Line)it.next()).cells.clear();
		}
		currentPage.oldCells = currentPage.cells;
		currentPage.cells = new ArrayList();
		calcCells();
		currentPage.oldCells = null;
	}


	public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2) {
		return 10;
	}
	public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2) {
		return 200;
	}
	public Dimension getPreferredScrollableViewportSize() {return null;}
	public boolean getScrollableTracksViewportWidth() {return false;}
	public boolean getScrollableTracksViewportHeight() {return false;}

	class LeftAlignAction extends AbstractAction{
		public LeftAlignAction(){
			super("", new ImageIcon(instance.getClass().getResource("resources/left.gif")));
		}
		public void actionPerformed(ActionEvent arg0) {
			if (currentPage == null || currentPage.currentCell == null) return;
			currentPage.currentCell.setAlignment(Cell.ALIGN_LEFT);
			updateUI();
		}
	}
	class RightAlignAction extends AbstractAction{
		public RightAlignAction(){
			super("", new ImageIcon(instance.getClass().getResource("resources/right.gif")));
		}
		public void actionPerformed(ActionEvent arg0) {
			if (currentPage == null || currentPage.currentCell == null) return;
			currentPage.currentCell.setAlignment(Cell.ALIGN_RIGHT);
			updateUI();
		}
	}
	class CenterAlignAction extends AbstractAction{
		public CenterAlignAction(){
			super("", new ImageIcon(instance.getClass().getResource("resources/center.gif")));
		}
		public void actionPerformed(ActionEvent arg0) {
			if (currentPage == null || currentPage.currentCell == null) return;
			currentPage.currentCell.setAlignment(Cell.ALIGN_CENTER);
			updateUI();
		}
	}
	class BoldFontAction extends AbstractAction{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -