/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package eric.GUI.window; import eric.FileTools; import eric.GUI.palette.PaletteManager; import eric.GUI.pipe_tools; import eric.GUI.windowComponent; import eric.GUI.themes; import eric.JZirkelCanvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.util.ArrayList; import java.util.Collections; import eric.JEricPanel; import javax.swing.JPopupMenu; import javax.swing.JSeparator; import javax.swing.SwingUtilities; import rene.gui.Global; /** * * @author erichake */ public class tab_main_panel extends windowComponent implements MouseWheelListener { private Color foreColor=new Color(0, 0, 0); private static myJMenuItem paletteitem, leftpanelitem, commentitem; @Override public void paintComponent(Graphics g) { Dimension d=getSize(); g.drawImage(themes.getImage("tabbar.gif"), 0, 0, d.width, d.height, this); } public void init() { // win=StaticTools.getMainWindow(this); int wdth=pipe_tools.getWindowSize().width-themes.getTotalRightPanelWidth()-themes.getTabControlPanelWidth(); setBounds(0, pipe_tools.getWindowSize().height-themes.getMainTabPanelHeight(), wdth, themes.getMainTabPanelHeight()); initBTNS(null); showActiveBtn(); } public tab_main_panel() { me=this; setOpaque(true); setLayout(null); addMouseWheelListener(this); createTabAndCanvas("Figure 1"); // setFocusable(true); } @Override public void mouseWheelMoved(MouseWheelEvent e) { if (BTNS.size()==0) { return; } int notches=e.getWheelRotation(); int askedOffset=offset-notches*30; if ((notches<0)&&(askedOffset>0)) { askedOffset=0; } else { if ((notches>0)&&(Rect_width*BTNS.size()+askedOffset<=getSize().width)) { askedOffset=getSize().width-Rect_width*(BTNS.size()); } } offset=askedOffset; deOverAll(); initBTNS(null); } /***************/ /* STATIC PART */ /***************/ private static int Rect_width=150; private static int offset=0; private static int leftmargin=20; private static tab_main_panel me=null; private static ArrayList BTNS=new ArrayList(); private static JPopupMenu tab_popup=null, ctrl_popup=null; public static tab_main_panel getme() { return me; } public static void removeAllBtns(ContentPane content) { if (content!=null) { for (int i=0; i1) { int i=getActiveBtnPos(); removeBtn(btn); if (i1) { me.remove(btn); BTNS.remove(btn); initBTNS(null); } } public static void addBtnAndSelect(String label) { tab_btn btn=new tab_btn(label); int i=getActiveBtnPos()+1; if (i==BTNS.size()) { me.add(btn); BTNS.add(btn); } else { me.add(btn, i); BTNS.add(i, btn); } initBTNS(null); setActiveBtn(btn); showActiveBtn(); btn.editName(); } public static tab_btn addBtn(String name) { tab_btn btn=new tab_btn(name, name); me.add(btn); BTNS.add(btn); return btn; } public static void createTabAndCanvas(String label, String tooltip) { tab_btn btn=new tab_btn(label, tooltip); me.add(btn); BTNS.add(btn); setActiveBtn(btn); showActiveBtn(); } public static void createTabAndCanvas(String label) { createTabAndCanvas(label, label); } // j is the offset (1 for the next to the right, -1 to the left) public static void setNextActiveBtn(int j) { int i=getActiveBtnPos(); try { setActiveBtn(BTNS.get(i+j)); showActiveBtn(); } catch (Exception e) { } initNAVbtns(); } public static void setCurrentTabName(String name, String tooltip) { getActiveBtn().setTabName(name, tooltip); } public static void setActiveBtn(int k) { setActiveBtn(BTNS.get(k)); } public static void setActiveBtn(final tab_btn btn) { JZirkelCanvas.stopAllScripts(); btn.setActive(true); for (int i=0; i0) { return BTNS.get(BTNS.size()-1); } else { return null; } } public static void currentTabHaveChanged(boolean b) { getActiveBtn().setChanged(b); } public static void allTabsHaveChanged(boolean b) { for (int i=0; ime.getSize().width); if ((btn.getBounds().x+btn.getSize().width>me.getSize().width)) { offset-=btn.getBounds().x+btn.getSize().width-me.getSize().width; } else if (btn.getBounds().x<0) { offset+=-btn.getBounds().x; } initBTNS(null); } public static void setOverBtn(tab_btn btn) { btn.setOver(true); for (int i=0; ime.getSize().width); boolean b2=(btn.getBounds().x