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

📄 figureobject.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		if ((gridY==_gridY) && (gridX==_gridX)) return;

		// gridY and/or gridX is changed => make new layout
		gridY       = _gridY;
		gridX       = _gridX;

		p.removeAll();
		p.setLayout(new GridLayout(gridY,gridX));
		figureElements = new AxesObject[gridY][gridX];

		for (int y=0; y<figureElements.length; y++)
		{
			for (int x=0; x<figureElements[y].length; x++)
			{
				//ErrorLogger.debugLine("FigureObject: subplot : "+y+" "+x);
				//if (figureElements[y][x]!=null)
				figureElements[y][x] = new AxesObject();
				p.add(figureElements[y][x]);
			}	
		}

		p.validate();
	}

    /**
     *
     */
    public void clearFigure()
    {
        p.removeAll();
        p.setLayout(new GridLayout(1,1));

        for (int y=0; y<figureElements.length; y++)
        {
            for (int x=0; x<figureElements[y].length; x++)
            {
                //ErrorLogger.debugLine("FigureObject: subplot : "+y+" "+x);
                //if (figureElements[y][x]!=null)
                figureElements[y][x] = null;
            }   
        }
        p.validate();
        p.repaint();
    }
    
	/**
	 * method for printing the graphics window to an external printer
	 */
	public int print(Graphics g, PageFormat pf, int page)  throws PrinterException
	{
		//ErrorLogger.debugLine("FigureObject: print : page="+page );

		// get printable area
		int yPos = (int)pf.getImageableY();
		int xPos = (int)pf.getImageableX();
		int yMax = (int)pf.getImageableHeight();
		int xMax = (int)pf.getImageableWidth();
		//ErrorLogger.debugLine("FigureObject: xPos="+xPos+" yPos="+yPos);
		//ErrorLogger.debugLine("FigureObject: xMax="+xMax+" yMax="+yMax);

		double rPage = (double)yMax/(double)xMax;
		double rFig = (double)fig.getSize().height/(double)fig.getSize().width;

		if (rPage > rFig)
		{
			yMax = (int)(rFig*xMax);
			yPos += ((int)pf.getImageableHeight()-yMax)/2;
		}
		else
		{
			xMax = (int)(yMax/rFig);
			xPos += ((int)pf.getImageableWidth()-xMax)/2;
		}

		// draw black rectangle around printing area
		g.setColor(Color.black);
		g.drawRect(xPos, yPos, xMax, yMax);

		//this.setBackground(Color.lightGray);    

		// create a new panel and group all elements which need to be printed
		//  -> is is done in order to get the correct size of the elements
		FigurePanel pP = new FigurePanel();
		pP.setLayout(new GridLayout(gridY, gridX));
		for (int y=0; y<figureElements.length; y++)
		{
			for (int x=0; x<figureElements[y].length; x++)
			{
				//ErrorLogger.debugLine("FigureObject: print : "+y+" "+x);
				pP.add(figureElements[y][x]);
			}    
		}

		// needed?
		pP.setSize(xMax,yMax);
		//pP.setBounds(xPos,yPos,xMax,yMax);

		// move origin of graphical context to left top corner
		//  of the visible page layout
		g.translate(xPos, yPos);

		int xTransSum=0;
		int yTransSum=0;
		int xTrans=0;
		int yTrans=0;

		// print axes on the printer-page
		for (int y=0; y<figureElements.length; y++)
		{
			yTrans=0;
			for (int x=0; x<figureElements[y].length; x++)
			{
				//ErrorLogger.debugLine("FigureObject: print-method : "+y+" "+x);
				//ErrorLogger.debugLine("figure:size x="+figureElements[y][x].getSize().width+" y="+figureElements[y][x].getSize().height);

				figureElements[y][x].getComponent().setSize(xMax, yMax);
				xTrans = figureElements[y][x].getSize().width;
				yTrans = Math.max(yTrans, figureElements[y][x].getSize().height);

				figureElements[y][x].setBackBuffer(false);
				figureElements[y][x].paint(g);
				figureElements[y][x].setBackBuffer(true);

				// move origin to next figure element
				g.translate(xTrans, 0);
				xTransSum += xTrans;
			}    

			// move origin back to left side and 
			// move origin down one row
			g.translate(-xTransSum, 0);
			g.translate(0, yTrans);

			// remember moving down
			yTransSum += yTrans;

		}

		// go back to origin "top left"
		g.translate(0, -yTransSum);


		// copy figure elements back to original panel on the screen
		for (int y=0; y<figureElements.length; y++)
		{
			for (int x=0; x<figureElements[y].length; x++)
			{
				//ErrorLogger.debugLine("FigureObject: copy back : "+y+" "+x);
				//if (figureElements[y][x]!=null)
				p.add(figureElements[y][x]);
			}    
		}

		// return one valid page (page-no. 0)
		if (page==0) 
			return PAGE_EXISTS;
		else
			return NO_SUCH_PAGE;
	}

	public void close()
	{
		close(true);
	}

	public void close(boolean notify)
	{
		if (notify)
			gM.removeFigure(figureNo);
		fig.dispose();
	}

	public void windowClosing(WindowEvent e)
	{
		//ErrorLogger.debugLine("FigureObject: windowClosing: "+figureNo);
		this.close();
	}

	public void windowActivated(WindowEvent e){}

	public void windowDeactivated(WindowEvent e){}

	public void windowClosed(WindowEvent e){}

	public void windowIconified(WindowEvent e){}

	public void windowDeiconified(WindowEvent e){}

	public void windowOpened(WindowEvent e){}

	public void setGraphicsManager(GraphicsManager _gM)
	{
		gM = _gM;
	}

	public void actionPerformed(ActionEvent ev)
	{
		String cmd = ev.getActionCommand();
		if (cmd.equals("Close"))
			gM.closeFigure(figureNo);
		else if (cmd.equals("New Figure"))
			gM.createNewFigure();
		else if (cmd.equals("Close All"))
			gM.closeAll();
		else if (cmd.equals("Print..."))
			doPrint();
	}

	private void doPrint()
	{
		PrinterJob job = PrinterJob.getPrinterJob();
		job.setPrintable(this);
		if (job.printDialog())
		{
			try
			{
				job.print();
			}
			catch (PrinterException e)
			{
			}
		}
	}

    public void repaint()
    {
        //super.repaint();
    }
    
    public void propertyChanged(Property p)
    {
        ErrorLogger.debugLine("FigureObject property changed: "+ p.getName());

        
        // xxx
        if (p==DockControlsP)
        {
            if (DockControlsP.isSet())
            {
                
            }
            else
            {
                
            }
        }
        

        // xxx
        if (p==DoubleBufferP)
        {
            if (DoubleBufferP.isSet())
            {
                
            }
            else
            {
                
            }
        }

        // display/remove menu bar
        if (p == MenuBarP)
        {
            if (MenuBarP.is("none"))
                fig.setMenuBar(null);
            else
                fig.setMenuBar(mbar);
        }

        // change name of this figure
        if (p == NameP)
        {
            if (NameP.getString().equals(""))
                fig.setTitle("Figure No."+figureNo);
            else
                fig.setTitle("Figure No."+figureNo+": "+NameP.getString());
        }

        parent.repaint();
    }

}

⌨️ 快捷键说明

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