/* * PlotCanvas.java * * Created on October 30, 2005, 4:36 PM */ package Current.canvases.Plot; import Current.plot.Plotters.*; import Current.manage.*; import Current.manage.Popup.*; import Current.gui.*; import Current.basic.*; import java.awt.*; import java.awt.event.*; import java.lang.*; import org.pat.graphics.boxed.ListenString; /** * * @author pat */ public class PlotCanvas extends Container implements MouseListener, Runnable{ public class PlotTypeMenu extends Canvas implements MouseListener, HearingPopup { ListenString[] LS; ListenString title; Current.gui.PopupMenu PM; public PlotTypeMenu(int X, int Y) { setBackground(menuBg); setFont(new Font("sanserif", Font.PLAIN, 12)); double x=4, y=4; title=new ListenString("mode", this); title.setColors(Color.white, menuBg); title.showBorder=false; title.setLeft(x); title.setTop(y); y=title.getBottom()+4; LS=new ListenString[names.length]; for (int i=0; i< LS.length; i++) { LS[i]=new ListenString(names[i],this); LS[i].setColors(buttonFg, types[i].getColor()); LS[i].setLeft(x); LS[i].setTop(y); y=LS[i].getBottom(); } setSize(); addMouseListener(this); PM=new Current.gui.PopupMenu(PlotCanvas.this,this,X,Y,this); } private void setSize(){ int x=0,y=0,temp; for (int i=0; ix) x=temp; temp=(int)(LS[i].getBottom()); if (temp>y) y=temp; } setSize(x+5,y+5); } public void onClose(){ } public void paint(Graphics gfx){ Graphics2D g=(Graphics2D) gfx; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); title.render(g); for (int i=0; ihalf_width) { half_width=temp; } setSize(); resetComponent(); } /** find the next enabled plot type */ /*public void inc(){ i=(i+1)%types.length; while (!enabled[i]) i=(i+1)%types.length; }*/ public Dimension getPreferredSize() { Dimension d; int maxx=0,maxy=0; for (int i=0; imaxx) { maxx=d.width; } if (d.height>maxy) { maxy=d.height; } } maxy=maxy+2; maxx=maxx+half_width+1; int temp=(int)(plot.getBottom()+padding); if (temp>maxy) { maxy=temp; } return new Dimension(maxx,maxy); } /** set the canvas size to some minimal but appropriate size. */ public void setSize(){ setSize(getPreferredSize()); } public void paint(Graphics gfx) { super.paint(gfx); Graphics2D g=(Graphics2D) gfx; Dimension D=this.getSize(); g.setColor(getBackground()); g.fillRect(1,1,D.width-2,D.height-2); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, //RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); plotType.str=names[i]; plotType.setColors(buttonFg, types[i].getColor()); plotType.render(g); if (plot_enabled) { plot.render(g); } doc2.render(g); g.setColor(new Color(100,180,255)); g.drawRect(0,0,D.width-1,D.height-1); } public XPlotter getPlotter() { return types[i]; } public void plot() { plot.str="stop"; repaint(); T=new Thread(this); T.setName(""+getClass().getName()+" Thread"); T.start(); } public void donePlot() { plot.str="plot"; repaint(); T=null; } public void run() { try { I=new Interrupter(); Tile tile=types[i].plot(M.getWord(),M.getColor(), I, M); if ((tile!=null)&&(! I.isInterrupted())) { M.plotTile(tile); } else { if (tile==null) System.err.println("PlotCanvas: No tile found."); } } catch (Throwable t) { System.err.println("Some error occurred while plotting"); System.err.flush(); t.printStackTrace(); } donePlot(); } public void interrupt() { if (I!=null) { I.interrupt(); donePlot(); } } public void mouseClicked(MouseEvent e) { if ((plot_enabled) && (plot.contains(e.getX(),e.getY()))) { if (T==null) { plot(); } else { // interupt the plot interrupt(); } } else if (plotType.contains(e.getX(),e.getY())) { if (PTM==null) { PTM=new PlotTypeMenu( (int)(plotType.getLeft()),(int)(plotType.getTop())); } else { PTM.PM.forceClose(); } //inc(); repaint(); } else if(doc2.contains(e.getX(),e.getY())) { //types[i].document(); document(); } } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void document() { M.mcbSend(new HelpDocument("Plotting.html")); //M.setExplain("This is the plot window..."); } /** return true iff we are currently plotting something */ public boolean isPlotting() { return (T!=null); } }