Τετάρτη 28 Σεπτεμβρίου 2022

UTF-8 decoder try version....

Reading anscii to utf...

                if(b1<=127){}//U+007F

                else if(b1<=2047){}//U+07FF

                else if(b1<=65535){}//U+FFFF

                else if(b1<=1114111){}//U+10FFFF

                else{} //???


https://en.wikipedia.org/wiki/UTF-8












/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */

package asciutfnotepadsolution;


import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.awt.Rectangle;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.nio.charset.Charset;

import java.util.Vector;

import javax.swing.JButton;

import javax.swing.JComboBox;

import javax.swing.JComponent;

import javax.swing.JFileChooser;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JSpinner;

import javax.swing.JSplitPane;

import javax.swing.JTabbedPane;

import javax.swing.JTable;

import javax.swing.JTextArea;

import javax.swing.SpinnerNumberModel;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

import javax.swing.table.DefaultTableColumnModel;

import javax.swing.table.DefaultTableModel;


/**

 *

 * @author jimak

 */

public class AsciUtfNotepadSolution extends JPanel implements ActionListener,ChangeListener{


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        new AsciUtfNotepadSolution();

    }

    static Dimension scr=Toolkit.getDefaultToolkit().getScreenSize();

    public JFrame njfr(JComponent jc){

        JFrame out=new JFrame(jc.getClass().getSimpleName());

        out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        out.setBounds(scr.width/2,0,scr.width/2,scr.height/4);

        out.getContentPane().add(jc);

        out.setVisible(true);

        return out;

    }

    JTabbedPane jtp=new JTabbedPane();

    JPanel jpLeft=new JPanel(new BorderLayout());

    JPanel jpRight=new JPanel(new BorderLayout());

    JSplitPane jspl=new JSplitPane(0,jpLeft,jpRight);

    


    JFrame jfr=null;

    Ints2 ints=new Ints2();

    JLabel jlUnicode=new JLabel("Unicode char : ");

    JPanel jpUnicode=new JPanel(new BorderLayout());

    JLabel jlMaps=new JLabel("possibly written as");

    JPanel jpMaps=new JPanel(new BorderLayout());

    

    JPanel jpUnicodeMaps=new JPanel(new GridLayout(2,1));

    

    JTextArea jtaManual=new JTextArea("ÅÐÉÊÏÕÑÉÊÇ ÈÁÍÁÔÏÕ\nÊÕÑÉÁ ÈÁÍÁÔÏÕ");

    

    

    JFileChooser jfch=new JFileChooser();

    JButton jbTryDecodeFile=new JButton("decode from File");

    JButton jbTryDecodeFromTextArea=new JButton("decodeFrom TextArea");

    JPanel sp=new JPanel(new BorderLayout());

    public AsciUtfNotepadSolution(){

        super(new BorderLayout());

        

        jpRight.add(BorderLayout.CENTER,jtp);

        jspl.setResizeWeight(0.1);

        add(BorderLayout.CENTER,jspl);

        

        jpUnicode.add(BorderLayout.WEST,jlUnicode);

        jpUnicode.add(BorderLayout.CENTER,ints.jspun);

        jpUnicodeMaps.add(jpUnicode);

        jpMaps.add(BorderLayout.WEST,jlMaps);

        jpMaps.add(BorderLayout.CENTER,ints.jspwr);

        jpUnicodeMaps.add(jpMaps);

        

        

        sp.add(BorderLayout.WEST,jbTryDecodeFromTextArea);

        sp.add(BorderLayout.EAST,jbTryDecodeFile);

        jbTryDecodeFromTextArea.setEnabled(false);

        jtaManual.setEnabled(false);

        

        

        jpLeft.add(BorderLayout.WEST,new JScrollPane(jtaManual));

        jpLeft.add(BorderLayout.CENTER,jpUnicodeMaps);

        jpLeft.add(BorderLayout.SOUTH,sp);

        jfr=njfr(this);

        jfr.setTitle(""+Charset.defaultCharset()+"..");

        jfr.setBounds(50,50,scr.width-100,scr.height-100);

        jfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        jbTryDecodeFile.addActionListener(this);

        jbTryDecodeFromTextArea.addActionListener(this);

        ints.jspun.addChangeListener(this);

        ints.jspwr.addChangeListener(this);

    }

    static Vector createColumns(){

        Vector out=new Vector();

        out.add("index");

        out.add("view");

        out.add("unicode");

        out.add("<127");

        out.add("result");

        out.add("repr");

        out.add("reads(b1)");

        out.add("bin_b1");

        out.add("b2");

        out.add("bin_b2");

        out.add("b3");

        out.add("bin_b3");

        out.add("b4");

        out.add("bin_b4");

        return out;

    }

    void newTxtDecodingTaskFinished(Rows rows){

        System.out.println("done creating swing");

        

        rows.jtbl=new Jtl(rows,createColumns());

        rows.jscr=new JScrollPane(rows.jtbl);

        rows.jscr.getVerticalScrollBar().setUnitIncrement(100);

        rows.jp.add(BorderLayout.CENTER,rows.jscr);

        rows.jp.add(BorderLayout.NORTH,rows.jpn);

        String tabname="from JTA";

        if(rows.src!=null){

            tabname=""+rows.src.getName();

        }

        jtp.addTab(tabname, rows.jspl);

        rows.jta.setText(rows.sbuf.toString());

        rows.jta.setCaretPosition(0);


    }

    public static final int []lastCodePoint={127,2047,65535,1114111};

    void newTxtDecodeingTask(Rows rows){

        if(rows.input!=null){

            System.out.println("Decoding bytes vector length="+rows.input.size());

            System.out.println("creating multi vectors for");

            System.out.println("charOut,i,(<-)byteRead-b1, b1Bin, b2, b2Bin, b3, b3Bin, b4, b4Bin");

            

            int i=0,l=rows.input.size();

            

            int b1,b2,b3,b4;//bytes

            int i1,i2,i3,i4;//trancated bytes

            int unicodeFinally=0;

            char unicode=0;

            while(i<l){

                Vector v=new Vector();

                v.add(i+":i");

                v.add("");//view[1]

                v.add("");//unicodefinal[2]

                v.add(0);//<127[3]

                v.add("");//complex resuylt[4]

                v.add("");//repr[5]

                b1=rows.input.get(i);

                v.add(b1);

                v.add(Integer.toBinaryString(b1));

                


                rows.add(v);

                ++i;

            }

            System.out.println("finished heavy job now omputing job(2nd pass)");

            

            i=0;

            int idif=1;

            while(i<l){

                Vector v=(Vector)rows.get(i);

                b1=rows.input.get(i);

                if(b1<=127){

                    v.setElementAt(b1, 3);//result

                    unicodeFinally=b1;

                    idif=1;

                }

                else if(b1<=2047){

                    if(i+1<l){

                        b2=rows.input.get(i+1);

                        v.add(b2);

                        v.add(Integer.toBinaryString(b2));

                        i1=b1&31;

                        i2=b2&63;

                        i1<<=6;

                        i1+=i2;

                        

                        v.setElementAt(i1, 4);//result

                        unicodeFinally=rows.un+(i1-rows.wr);

                        

                        

                        String s1=Integer.toBinaryString(b1);

                        String s2=Integer.toBinaryString(b2);

                        String s="";

                        String st="";

                        try{

                            s+=s1.substring(0,s1.length()-5);

                            s+="(";

                            s+=s1.substring(s1.length()-5,s1.length());

                            s+=")+";

                            s+=s2.substring(0,s2.length()-6);

                            s+="(";

                            s+=s2.substring(s2.length()-6,s2.length());

                            s+=")";


                            v.setElementAt(s, 5);

                        }catch(Exception e){v.setElementAt("errSTr", 3);}

                        

                    }

                    else{v.add("err_2");}

                    idif=2;

                }

                else if(b1<=65535){

                    

                    idif=3;

                }

                else if(b1<=1114111){

                    

                    idif=4;

                }

                else{

                    v.add("err_1");

                    idif=1;

                }

                

                

                

                

                

                unicode=(char)unicodeFinally;

                v.setElementAt(unicodeFinally,2);

                v.setElementAt(unicode,1);

                rows.sbuf.append(unicode);

                i+=idif;                

            }

            

            newTxtDecodingTaskFinished(rows);

            

        }

    }

    void newTxtDecodingTask(String text){

        if(text!=null){

            int l=text.length();

            if(l>0){

                Rows rows=new Rows(null,ints.un(),ints.wr());

                System.out.println("textArea.len()="+l);

                int i=0;

                while(i<l){

                    int ch=(int)text.charAt(i);

                    int i1=ch%256;

                    int i0=ch>>8;

                    rows.input.add(i0);

                    rows.input.add(i1);

                    ++i;

                }

                newTxtDecodeingTask(rows);

            }else{JOptionPane.showMessageDialog(this, "You must have some text in the up left TextArea to decode it");}

        }

    }

    void newTxtDecodingTask(File f){

        if(f!=null){

            System.out.println("Task:"+f);

            jfr.setTitle("Reading :"+f.getName());

            Rows rows=new Rows(f,ints.un(),ints.wr());

            IOException iof=null;

            boolean end=false;

            int ri;

            FileInputStream fin=null;

            try{

                fin=new FileInputStream(f);

                ri=fin.read();

                while(ri>-1){

                    rows.input.add(ri);

                    ri=fin.read();

                }

                end=true;

            }catch(IOException io){iof=io;}

            finally{

                try{fin.close();System.out.println("closed");}catch(Exception e){}

            }

            if(iof!=null){

                if(!end){

                    JOptionPane.showMessageDialog(this, iof);

                }

            }

            else{

                System.out.println("ok...we have read "+rows.input.size()+" bytes");

                System.out.println(f.getName()+" has length = "+f.length());

                jfr.setTitle(rows.input.size()+" bytes read ok from "+f.getName());

                newTxtDecodeingTask(rows);

            }

        }

    }

    void jcUnicodeSetted(int unicodepoint){

        jlUnicode.setText("Unicode char: "+((char)unicodepoint)+" = "+unicodepoint);

    }

    @Override

    public void actionPerformed(ActionEvent e) {

        Object src=e.getSource();

        if(src==jbTryDecodeFile){

            int answer=jfch.showOpenDialog(this);

            if(answer==JFileChooser.APPROVE_OPTION){

                newTxtDecodingTask(jfch.getSelectedFile());

            }

        }

        else if(src==jbTryDecodeFromTextArea){

            newTxtDecodingTask(jtaManual.getText());

        }

    }


    @Override

    public void stateChanged(ChangeEvent e) {

        

    }

    

    

    

    

    

    

    

}


class Rows extends Vector<Vector> implements ChangeListener{

    File src;

    Vector<Integer>input;

    int un,wr;

    StringBuffer sbuf=new StringBuffer();

    


    Ints2 unwr=new Ints2();

    JPanel jpn=new JPanel(new BorderLayout());

    

    Jtl jtbl=null;

    JScrollPane jscr=null;

    JPanel jp=new JPanel(new BorderLayout());

    

    JTextArea jta=new JTextArea();

    JScrollPane jscrjta=new JScrollPane(jta);

    

    JSplitPane jspl=new JSplitPane(1,jp,jscrjta);

    public Rows(File f,int unicodePoint,int writtenAs){

        src=f;

        input=new Vector();

        un=unicodePoint;

        wr=writtenAs;

        

        jspl.setResizeWeight(0.8);

        

        

        unwr.jspun.setValue(un);

        unwr.jspwr.setValue(wr);

        jpn.add(BorderLayout.WEST,unwr);

        

        unwr.jspun.addChangeListener(this);

        unwr.jspwr.addChangeListener(this);

        

    }

    

    void recompute(){

        if(jtbl!=null){

            //if(newPossibleWr>=0){

                System.out.println("recomputing for un="+un+" , wr="+wr);

                DefaultTableModel dtm=(DefaultTableModel)jtbl.getModel();

                int i=0,l=size();

                int unicodeFinally;

                sbuf.delete(0, sbuf.length());

                char unicode;

                while(i<l){

                    Vector v=(Vector)get(i);

                    Object o2=v.get(4);

                    if(o2 instanceof Integer){

                        unicodeFinally=(Integer)o2;

                        unicodeFinally+=un;

                        unicodeFinally-=wr;

                        

                    }

                    else{

                        unicodeFinally=(Integer)v.get(3);

                    }

                    unicode=(char)unicodeFinally;

                    sbuf.append(unicode);

                    v.setElementAt(unicodeFinally, 2);

                    v.setElementAt(unicode, 1);

                    ++i;

                }

                jtbl.repaint();

                jta.setText(sbuf.toString());

            //}

        }

    }


    @Override

    public void stateChanged(ChangeEvent e) {

        un=unwr.un();

        wr=unwr.wr();

        recompute();

    }

    

    

    

}





class Jtl extends JTable{

    

    public Jtl(Vector rowDate,Vector columnData){

        DefaultTableModel ndtm=new DefaultTableModel(rowDate, columnData);

        setModel(ndtm);

        

    }

    public Jtl(Vector rowsWithVectorsOrNot){

        super();

        if(rowsWithVectorsOrNot==null){

            rowsWithVectorsOrNot=new Vector();

        }

        int i=0,l=rowsWithVectorsOrNot.size(), maxCols=0,vCols;

        while(i<l){

            Object ov=rowsWithVectorsOrNot.get(i);

            Vector v=null;

            if(ov!=null && (ov instanceof Vector)){

                v=(Vector)ov;

            }

            else{

                    v=new Vector();

                    rowsWithVectorsOrNot.insertElementAt(v, i);

                    rowsWithVectorsOrNot.remove(i+1);

                    v.add(ov);

            }

            vCols=v.size();

            if(vCols>maxCols){

                maxCols=vCols;

            }

            ++i;

        }

        System.out.println("maxCols found : "+maxCols+"...creating default columns");

        Vector cs=new Vector();

        i=0;

        while(i<maxCols){

            cs.add("c"+i);

            ++i;

        }

        DefaultTableModel ndtm=new DefaultTableModel(rowsWithVectorsOrNot, cs);

        setModel(ndtm);

        

    }

}


class Ints2 extends JPanel{

    JSpinner jspun=new JSpinner(new SpinnerNumberModel(913,0,65555,1));

    JSpinner jspwr=new JSpinner(new SpinnerNumberModel(193,0,65555,1));

    

    Ints2(){

        super(new BorderLayout());

        add(BorderLayout.WEST,jspun);

        add(BorderLayout.EAST,jspwr);

        

    }

    public int un(){

        return (Integer)jspun.getValue();

    }

    public int wr(){

        return (Integer)jspwr.getValue();

    }

}

Κυριακή 25 Σεπτεμβρίου 2022

java Code Generation for JSplitPane complex

Now just alone in a class...compile and run!!!

 .....corrected put nice names on code for
Jspl jspl?? =new Jspl....
instead of bad ...jspl001 in image below

Now just Cntrl+Space on netbeans and ready !











package test;



import java.awt.BorderLayout;

import java.awt.Color;


import java.awt.Component;


import java.awt.Container;

import java.awt.GridLayout;

import java.awt.HeadlessException;

import java.awt.Insets;


import java.awt.event.ActionEvent;


import java.awt.event.ActionListener;


import java.awt.event.MouseEvent;


import java.awt.event.MouseListener;


import java.util.Enumeration;

import java.util.Random;

import java.util.Vector;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;


import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JScrollPane;

import javax.swing.JSpinner;

import javax.swing.JSplitPane;

import javax.swing.JTabbedPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import javax.swing.JToggleButton;

import javax.swing.JTree;

import javax.swing.SpinnerModel;

import javax.swing.SpinnerNumberModel;


import javax.swing.event.ChangeEvent;


import javax.swing.event.ChangeListener;


import javax.swing.event.TreeSelectionEvent;


import javax.swing.event.TreeSelectionListener;

import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.DefaultTreeModel;

import javax.swing.tree.TreeModel;

import javax.swing.tree.TreeNode;


import javax.swing.tree.TreePath;






/**


 *


 * @author jimak


 * @date Sep 25, 2022


 */


public class JJsplitPaneCreator extends Jp implements TreeSelectionListener,ActionListener,ChangeListener,MouseListener{


    public static void main(String[] args) {


        new Jfr(new JJsplitPaneCreator())

.setTitle("Right click on JPanels to their name");


    }


    


    


    Jb jbSwitch=new Jb("switch").qb(Color.red).qtt("Not ready yet.Must reset names after....boring");


    Jr jrVer=new Jr("ver");


    Jr jrOne=new Jr("one");


    Jr jrCont=new Jr("cont");


    Jsp jsp=new Jsp(0.5,0.0,1.0,0.1).qtt("Resize Weight and for code divider location");


    Jsp jspDiv=new Jsp(8,2,14,1).qtt("divider size.On code will see if !=10 but ...it is UI relative...");


        Jt jtdivgen=new Jt("?",false).qtt("By the time you press..!!->use current for default generation.");


    Jb jbNew=new Jb("new split");


    Jb jbClear=new Jb("clear");


    Jb jbCode=new Jb("code").qb(Color.magenta);


    Jt jtCodeColors=new Jt("col?",true).qins0().qtt("colors in code?");


    Jt jtJpNamesAsTooltip=new Jt("n-ttt?",true).qtt("code puts names as tooltiptext in jpanels?");


    Jp jpButs=new Jp(10,1,jbNew,jrVer,jrOne,jsp,jrCont,new Jp(jspDiv,2,jtdivgen,3),jbSwitch,jbClear,jbCode,new Jp(1,2,jtCodeColors,jtJpNamesAsTooltip));


    int panelid=0;


    Integer defDiv=null;


    Jspl createSplitPane(){


        Jp jp0=new Jp().qb(Rand.sti.randColor()).qn("A"+(panelid++));


        jp0.setToolTipText(jp0.getName());


        Dmtn jp0n=new Dmtn(jp0);


        jp0.putClientProperty(Dmtn.class, jp0n);


        Jp jp1=new Jp().qb(Rand.sti.randColor()).qn("B"+(panelid++));


        jp1.setToolTipText(jp1.getName());


        Dmtn jp1n=new Dmtn(jp1);


        jp1.putClientProperty(Dmtn.class, jp1n);


        


        Jspl out=new Jspl((jrVer.isSelected())?(0):(1),jp0,jp1).qrw(jsp.vd());


        out.setContinuousLayout(jrCont.isSelected());


        out.setOneTouchExpandable(jrOne.isSelected());


        if(defDiv!=null){


            out.setDividerSize(defDiv);


        }


        Dmtn outn=new Dmtn(out);


        out.putClientProperty(Dmtn.class, outn);


        outn.add(jp0n);


        outn.add(jp1n);


        


        out.compDivider.addMouseListener(this);


        jp0.addMouseListener(this);


        jp1.addMouseListener(this);


        


        return out;


    }




    Jspl jsplEdit=createSplitPane();


    Dmtn root=(Dmtn)jsplEdit.getClientProperty(Dmtn.class);


    Jtr jtr=new Jtr(root);


    Jp jtrjp=new Jp(jtr.jscr());


    Jtf jtfJpName=new Jtf("");


    


    Jp jpNames=new Jp(jtfJpName,2,new Jl("jp name").qtt("right click on some jp"),3);


    Jp jptr=new Jp(jpButs,3,jtrjp,2,jpNames,4);


    


    


    Jp jpView=new Jp(jsplEdit);


    Jspl jsplMy=new Jspl(1,jptr,jpView).qrw(0.2);


    


    public JJsplitPaneCreator(){


        super();


        jsplEdit.setName("jsplMain");


        


        


        jsplMy.qOneTouchExpandable().qdiv(8);


        cad(new Jp(jsplMy));


        jbClear.addActionListener(e->clear());


        jtr.addTreeSelectionListener(this);


        jrVer.addActionListener(this);


        jrOne.addActionListener(this);


        jrCont.addActionListener(this);


        jbSwitch.addActionListener(this);


        jsp.addChangeListener(this);


        jspDiv.addChangeListener(this);


        jtdivgen.addActionListener(this);


        jbNew.addActionListener(this);


        jbCode.addActionListener(e->getCode());


        jtfJpName.addActionListener(this);


        //clear();


    }


    Dmtn lpcSel=null;


    Jspl jsplSel=null;


    Jp jpSel=null;


    boolean isAdjusting=false;


    @Override


    public void valueChanged(TreeSelectionEvent e) {


        //System.out.println(""+e.getNewLeadSelectionPath());


        TreePath tp=e.getNewLeadSelectionPath();


        jsplSel=null;


        jpSel=null;


        lpcSel=null;


        if(tp!=null){


            lpcSel=(Dmtn)tp.getLastPathComponent();


            Object lpco=lpcSel.getUserObject();


            if(lpco instanceof Jspl){


                jsplSel=(Jspl)lpco;


                setFields(jsplSel);


                jtfJpName.setEnabled(false);


            }


            else if(lpco instanceof Jp){


                jpSel=(Jp)lpco;


                Container par=jpSel.getParent();


                if(par!=null && par instanceof Jspl){


                    setFields((Jspl)par);


                }


                jtfJpName.setText(jpSel.getName());


                jtfJpName.setEnabled(true);


            }


        }


    }


    void setFields(Jspl jspl){


            isAdjusting=true;


            jrVer.setSelected(jspl.getOrientation()==0);


            jrCont.setSelected(jspl.isContinuousLayout());


            jrOne.setSelected(jspl.isOneTouchExpandable());


            jsp.setValue(jspl.getResizeWeight());


            jspDiv.setValue(jspl.getDividerSize());


            isAdjusting=false;


    }


    @Override


    public void stateChanged(ChangeEvent e) {


        if(e.getSource()==jsp  && !isAdjusting){


            if(jsplSel!=null){


                jsplSel.qrw(jsp.vd());


            }


            else if(jpSel!=null){


                ((Jspl)jpSel.getParent()).qrw(jsp.vd());


            }


        }


        else if(e.getSource()==jspDiv  && !isAdjusting){


            if(jsplSel!=null){


                jsplSel.setDividerSize(jspDiv.vi());


            }


            else if(jpSel!=null){


                ((Jspl)jpSel.getParent()).setDividerSize(jspDiv.vi());


            }


        }


    }




    @Override


    public void actionPerformed(ActionEvent e) {


        if(e.getSource()==jrVer && !isAdjusting ){


            if(jsplSel!=null){


                jsplSel.qver(jrVer.isSelected());


            }


            else if(jpSel!=null){


                ((Jspl)jpSel.getParent()).qver(jrVer.isSelected());


            }


            


        }


        else if(e.getSource()==jrOne && !isAdjusting ){


            if(jsplSel!=null){


                jsplSel.setOneTouchExpandable(jrOne.isSelected());


            }


            else if(jpSel!=null){


                ((Jspl)jpSel.getParent()).setOneTouchExpandable(jrOne.isSelected());


            }


            


        }


        else if(e.getSource()==jrCont && !isAdjusting ){


            if(jsplSel!=null){


                jsplSel.setContinuousLayout(jrCont.isSelected());


            }


            else if(jpSel!=null){


                ((Jspl)jpSel.getParent()).setContinuousLayout(jrCont.isSelected());


            }


            


        }


        else if(e.getSource()==jbSwitch && jsplSel!=null){


            Jp jp0=(Jp)jsplSel.getLeftComponent();


            Dmtn jp0n=(Dmtn)jp0.getClientProperty(Dmtn.class);


            Dmtn par=jp0n.dmtnPar();


            par.remove(jp0n);


            par.add(jp0n);


            jsplSel.switchComponents();


            jtr.dtm().nodeStructureChanged(par);


            jtr.expandAll();


        }


        else if(e.getSource()==jtfJpName && jpSel!=null){


            jpSel.setName(jtfJpName.getText());


            jpSel.setToolTipText(jpSel.getName());


            jtfJpName.selectAll();


        }


        else if(e.getSource()==jtdivgen){


            if(jtdivgen.isSelected()){


                defDiv=jspDiv.vi();


            }


            else{


                defDiv=null;


            }


        }


        else if(e.getSource()==jbNew && jpSel!=null && !isAdjusting){


            if(jpSel.getComponentCount()>0){


                System.out.println("cant do this..yet");


            }


            else{




                Jspl nspl=createSplitPane();


                Dmtn nspln=(Dmtn)nspl.getClientProperty(Dmtn.class);


                jpSel.cad(nspl);


                jpSel.validate();


                nspl.setName(createDepthName(nspl));


                /////


                lpcSel.add(nspln);


                jtr.dtm().nodeStructureChanged(lpcSel);


                jtr.expandPath(nspln.ntp());


                jtr.setSelectionPath(nspln.ntp());




                jtr.dtm().nodeStructureChanged(nspln);


                jtr.expandPath(nspln.ntp());


               


            }


        }


    }


    


    String createDepthName(Jspl jsplSome){


        String out="spl_";


        Vect<Container> path=new Vect();


       


        Container it=jsplSome.getParent();


        while(it!=null){


            path.insertElementAt(it, 0);


            if(it==jsplEdit){


                break;


            }


            it=it.getParent();


        }


        System.out.println(""+path);


        


        int i=0;


        Jspl jspl=(Jspl)path.get(i);


        Component comp=path.get(i+1);


        if(jspl.getLeftComponent()==comp){out+="0"; }


        else{out+="1";}


        i+=2;


        while(i<path.size()){


            jspl=(Jspl)path.get(i);


            comp=path.get(i+1);


            if(jspl.getLeftComponent()==comp){out+="0"; }


            else{out+="1";}


            i+=2;


        }


        


        return out;


    }






    @Override


    public void mouseClicked(MouseEvent e) {


    }




    @Override


    public void mousePressed(MouseEvent e) {


        Component comp=(Component)e.getSource();


        Dmtn nn=null;


        if(comp instanceof Jp){


            nn=(Dmtn)((Jp)comp).getClientProperty(Dmtn.class);


            jtr.setSelectionPath(nn.ntp());


            Dmtn par=nn.dmtnPar();


            if(par!=null){


                Jspl jspl=(Jspl)par.getUserObject();


                setFields(jspl);


            }


        }


        else{


            Container par=comp.getParent();


            if(par instanceof Jspl){


                Jspl jspl=(Jspl)par;


                nn=(Dmtn)jspl.getClientProperty(Dmtn.class);


                jtr.setSelectionPath(nn.ntp());




            }


        }




    }




    @Override


    public void mouseReleased(MouseEvent e) {


        Component comp=(Component)e.getSource();


        Dmtn nn=null;


        if(comp instanceof Jp){


            if(e.getButton()==MouseEvent.BUTTON3){


                Jp jpp=(Jp)comp;


                String na=jpp.getName();


                String newna=JOptionPane.showInputDialog(comp, na, na);


                System.out.println(""+newna);


                if(newna!=null){


                    setNewName(jpp,newna);


                }


            }


        }


        else{


            Container par=comp.getParent();


            if(par instanceof Jspl){


                Jspl jspl=(Jspl)par;


                double nrw=jspl.getDividerDoubleLocation();


                //if(nrw>0.01&& nrw<0.91){


                    jspl.setResizeWeight(nrw);


                    isAdjusting=true;


                    jsp.setValue(jspl.getResizeWeight());


                    //jspDiv.setValue(jspl.getDividerSize());


                    isAdjusting=false;


                //}else{System.err.println("line:260-----------------------"+nrw);}


            }


        }


    }




    @Override


    public void mouseEntered(MouseEvent e) {


    }




    @Override


    public void mouseExited(MouseEvent e) {


    }


    


    


    void setNewName(Jp jpp,String na){


        if(jpp!=null&&na!=null){


            jpp.setName(na);


            jpp.setToolTipText(na);


        }


    }


    Jp crjp(String name){


        return new Jp().qb(Rand.sti.randColor()).qn(name);


    }


    void clear(){


        


        Dmtn jp0n=root.dmtn(0);


        Dmtn jp1n=root.dmtn(1);


        jp0n.removeAllChildren();


        jtr.dtm().nodeStructureChanged(jp0n);


        jp1n.removeAllChildren();


        jtr.dtm().nodeStructureChanged(jp1n);


        jtr.expandAll();


        


        ((Jp)jp0n.getUserObject()).removeAll();


        ((Jp)jp1n.getUserObject()).removeAll();


        jsplEdit.validate();


        jsplEdit.repaint();


        panelid=2;


    }


    




    void getCode(){


        boolean jpcolorcode=jtCodeColors.isSelected();


        boolean jpnamtip=jtJpNamesAsTooltip.isSelected();


        Enumeration en=root.depthFirstEnumeration();


        Dmtn it;


        Object ito;




        Jspl jspl;


        String out="";


        while(en.hasMoreElements()){


            it=(Dmtn)en.nextElement();


            ito=it.getUserObject();


            System.out.println(""+it);


            if(ito instanceof Jp){



            }


            else{


                jspl=(Jspl)ito;


                Jp jp0=(Jp)jspl.getLeftComponent();


                String jp0params="";


                //if(jp0.getComponentCount()>0){jp0params+=((Jspl)jp0.getComponent(0)).getName();}


                if(jp0.getComponentCount()>0){jp0params+=((Jspl)jp0.getComponent(0)).getToolTipText();}


                Jp jp1=(Jp)jspl.getRightComponent();


                String jp1params="";


                //if(jp1.getComponentCount()>0){jp1params+=((Jspl)jp1.getComponent(0)).getName();}


                if(jp1.getComponentCount()>0){jp1params+=((Jspl)jp1.getComponent(0)).getToolTipText();}


                out+="\t\tJp jp"+jp0.getName()+" = new Jp("+jp0params+").qn(\""+jp0.getName()+"\")"


                        +((jpnamtip)?(".qtt(\""+jp0.getName()+"\")"):(""))+((jpcolorcode)?(".qb(new Color("+jp0.getBackground().getRGB()+"))"):(""))+";\n";


                out+="\t\tJp jp"+jp1.getName()+" = new Jp("+jp1params+").qn(\""+jp1.getName()+"\")"


                        +((jpnamtip)?(".qtt(\""+jp1.getName()+"\")"):(""))+((jpcolorcode)?(".qb(new Color("+jp1.getBackground().getRGB()+"))"):(""))+";\n";


                


                String jsplname=jspl.getName();


                if(jspl!=jsplEdit){//correction...


                    jsplname="jspl"+jp0.getName()+"_"+jp1.getName();


                    jspl.setToolTipText(jsplname);//to be used after as params in jp


                }


                


                out+="\t\tJspl "+jsplname+" = new Jspl("+jspl.getOrientation()+" , jp"+jp0.getName()+" , jp"+jp1.getName()


                        +").qrw("+jspl.getResizeWeight()+")"


                        + ((jspl.isContinuousLayout())?(".qContinuousLayout()"):(""))+""


                        + ((jspl.isOneTouchExpandable())?(".qOneTouchExpandable()"):(""))+""


                        + ((jspl.getDividerSize()!=10)?(".qdiv("+jspl.getDividerSize()+")"):(""))+""


                        + ";\n";


                


            }


        }


        System.out.println("------------------------");


        System.out.println(out);


        System.out.println("------------------------");


        Jta jta=new Jta(out);


        jta.selectAll();


        jta.copy();


        if(jfrcode==null){


            Jtb jtb=new Jtb();


            jfrcode=new Jfr(jtb).qti("Paste and test it");


        }


        Jtb jtb=(Jtb)jfrcode.getContentPane().getComponent(0);


        Jscr js=jta.jscr();


        jtb.addTab("*"+jtb.getTabCount(),js);


        jtb.setSelectedComponent(js);


        jfrcode.setVisible(true);


        jfrcode.qNormal();


        jfrcode.toFront();


    }


    Jfr jfrcode;




    


    


}

class Jfr extends JFrame{

    public static final Insets zins=new Insets(0,0,0,0);



    public Jfr(Component mainCentered){

        super.setBounds(0,0,777,666);

        super.getContentPane().add(mainCentered,Jp.bl(2));

        super.setTitle(getClass().getName());

        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setVisible(true);

    }

    public Jfr qExitOnClose(){

        super.setDefaultCloseOperation(EXIT_ON_CLOSE);

        return this;

    }

    public Jfr qDisposeOnClose(){

        super.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

        return this;

    }

    public Jfr qNormal(){

        super.setState(Jfr.NORMAL);

        return this;

    }

    public Jfr qIconified(){

        super.setState(Jfr.ICONIFIED);

        return this;

    }

    public Jfr qti(String title){

        super.setTitle(title);

        return this;

    }


    

}

class Jscr extends JScrollPane{


    public Jscr(Component view) {

        super(view);

    }

    

    

}

class Jp extends JPanel{

    public static Object bl(int code04){

        if(code04<1){return BorderLayout.NORTH;}

        else if(code04<2){return BorderLayout.WEST;}

        else if(code04<3){return BorderLayout.CENTER;}

        else if(code04<4){return BorderLayout.EAST;}

        return BorderLayout.SOUTH;

    }

    public Jscr jscr;

    public Jscr jscr(){

        if(jscr==null){

            jscr=new Jscr(this);

            revalidate();

            repaint();

        }

        return jscr;

    }

     @Override

    public String toString() {

        String out=super.toString();

        String name=getName();

        if(name!=null){

            out=name;

        }

        return out;

    }

   public Jp() {

        super(new BorderLayout());

    }

    public Jp(Component centered){

        this(centered,2);

    }

    public Jp(Component ca,int a){

        this();

        super.add(ca,bl(a));

    }

    

    public Jp(Component ca,int a,Component cb,int b){

        this(ca,a);

        super.add(cb,bl(b));

    }

    public Jp(Component ca,int a,Component cb,int b,Component cc,int c){

        this(ca,a,cb,b);

        super.add(cc,bl(c));

    }

    public Jp(Component ca,int a,Component cb,int b,Component cc,int c,Component cd,int d){

        this(ca,a,cb,b,cc,c);

        super.add(cd,bl(d));

    }

    public Jp(Component ca,int a,Component cb,int b,Component cc,int c,Component cd,int d,Component ce,int e){

        this(ca,a,cb,b,cc,c,cd,d);

        super.add(ce,bl(e));

    }

    public Jp(int rows,int cols){

        super(new GridLayout(rows, cols));

    }

    public Jp(int rows,int cols,Component c0){

        this(rows, cols);

        add(c0);

    }

    public Jp(int rows,int cols,Component c0,Component c1){

        this(rows, cols);

        add(c0);add(c1);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2){

        this(rows, cols);

        add(c0);add(c1);add(c2);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5,Component c6){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5,Component c6,Component c7){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);add(c7);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5,Component c6,Component c7,Component c8){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);add(c7);add(c8);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5,Component c6,Component c7,Component c8,Component c9){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);add(c7);add(c8);add(c9);

    }

    public Jp(int rows,int cols,Component c0,Component c1,Component c2,Component c3,Component c4,Component c5,Component c6,Component c7,Component c8,Component c9,Component c10){

        this(rows, cols);

        add(c0);add(c1);add(c2);add(c3);add(c4);add(c5);add(c6);add(c7);add(c8);add(c9);add(c10);

    }

    public void resetGridOnRows(){

        resetGrid(new GridLayout(getComponentCount(),1));

    }

    public void resetGridOnColumns(){

        resetGrid(new GridLayout(1,getComponentCount()));

    }

    public void resetGrid(int newRows,int newCols){

        resetGrid(new GridLayout(newRows, newCols));

    }

    public void resetGrid(GridLayout gl){

        setLayout(gl);

        validate();

        repaint();

    } 

    public void blad(Component c,int pos){

        add(c,bl(pos));

        //validate();

        //repaint();

    }

    public void nad(Component c){ blad(c,0); }

    public void wad(Component c){ blad(c,1); }

    public void cad(Component c){ blad(c,2); }

    public void ead(Component c){ blad(c,3); }

    public void sad(Component c){ blad(c,4); }

    public Jp qb(Color c) {super.setBackground(c); return this; }

    public Jp qf(Color c) {super.setForeground(c); return this; }

    public Jp qe(boolean b) {setEnabled(b); return this; }

    public Jp qn(String name) {super.setName(name); return this;  }

    public Jp qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

}

class Jtb extends JTabbedPane{


    public Jtb() {

    }

    

}

class Jta extends JTextArea{

    public Jscr jscr;

    public Jscr jscr(){

        if(jscr==null){

            jscr=new Jscr(this);

            revalidate();

            repaint();

        }

        return jscr;

    }


    public Jta() {

    }


    public Jta(String text) {

        super(text);

    }

    

    public Jta qb(Color c) {super.setBackground(c); return this; }

    public Jta qf(Color c) {super.setForeground(c); return this; }

    public Jta qe(boolean b) {setEnabled(b); return this; }

    public Jta qn(String name) {super.setName(name); return this;  }

    public Jta qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

}

class Jsp extends JSpinner{

    public Jsp() {

    }


    public Jsp(SpinnerModel model) {

        super(model);

    }

    

    public Jsp(int val,int min,int max,int step){

        this(new SpinnerNumberModel(val,min,max,step));

    }

    public Jsp(double val,double min,double max,double step){

        this(new SpinnerNumberModel(val,min,max,step));

    }

    public Jsp(Number val,Comparable min,Comparable max,Number step){

        this(new SpinnerNumberModel(val,min,max,step));

    }

    public Jsp qbed(Color c) {super.getEditor().getComponent(0).setBackground(c); return this; }

    public Jsp qbup(Color c) {super.getComponent(0).setBackground(c); return this; }

    public Jsp qbdo(Color c) {super.getComponent(1).setBackground(c); return this; }

    public Jsp qfed(Color c) {super.getEditor().getComponent(0).setForeground(c); return this; }

    public Jsp qfup(Color c) {super.getComponent(0).setForeground(c); return this; }

    public Jsp qfdo(Color c) {super.getComponent(1).setForeground(c); return this; }

    public Jsp qbarrows(Color c) {super.getComponent(0).setBackground(c);super.getComponent(1).setBackground(c); return this; }

    

    

    public boolean isModelDouble(){

        return (getModel() instanceof SpinnerNumberModel)

                && (snm().getNumber() instanceof Double)

        ;

    }

    public SpinnerNumberModel snm(){

        return (SpinnerNumberModel)getModel();

    }

    public int vi(){return (int)getValue();}

    //public int minint(){return (int)snm().getMinimum();}

    //public int maxint(){return (int)snm().getMaximum();}

    public int stepint(){return (int)snm().getStepSize();}

    

    public void minint(int i){snm().setMinimum(i);}

    public void maxint(int i){snm().setMaximum(i);}

    public void stepint(int i){snm().setStepSize(i);}

    

    

    public double vd(){return (double)getValue();}

    //public double mindouble(){return (double)snm().getMinimum();}

    //public double maxdouble(){return (double)snm().getMaximum();}

    public double stepdouble(){return (double)snm().getStepSize();}

    

    

    public Number vn(){return (Number)getValue();}

    public Number minNumber(){return (Number)snm().getMinimum();}

    public Number maxNumber(){return (Number)snm().getMaximum();}

    public Number stepNumber(){return (Number)snm().getStepSize();}

    public Jsp qb(Color c) {super.setBackground(c); return this; }

    public Jsp qf(Color c) {super.setForeground(c); return this; }

    public Jsp qe(boolean b) {setEnabled(b); return this; }

    public Jsp qn(String name) {super.setName(name); return this;  }

    public Jsp qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

}

class Jtr extends JTree{

    public Jscr jscr;

    public Jscr jscr(){

        if(jscr==null){

            jscr=new Jscr(this);

            revalidate();

            repaint();

        }

        return jscr;

    }


    public Jtr() {

    }


    public Jtr(TreeNode root) {

        super(root);

    }

    public DefaultTreeModel dtm(){

        return (DefaultTreeModel)getModel();

    }

    

    public void selectAndScroll(TreePath tp){

        setSelectionPath(tp);

        scrollPathToVisible(tp);

    }

    

    

    

    

    

    public Jtr qexpandAll(){

        expandAll();

        return this;

    }

    public void expandAll(){

        TreeModel tm=getModel();

        Object or=tm.getRoot();

        if(or instanceof Dmtn){

            //System.out.println("ok compsi compsa algo not perferct");

            expandAll((Dmtn)or);

        }

        else{

            expandAll(1230);

        }

    }

    

    void expandAll(Dmtn n){

        expandPath(n.ntp());

        int l=n.getChildCount();

        --l;

        while(l>-1){

            expandAll(n.dmtn(l));

            --l;

        }

        

    }

    public void expandAll(int maxDepth){

        //System.out.println("expanding stupid ");

        int l=getRowCount();

        int prevl=-1;

        int actions=0;

        while(prevl!=l){

            prevl=l;

            while(l>0){

                --l;

                expandRow(l);

                ++actions;

            }

            l=getRowCount();

            --maxDepth;

            if(maxDepth<0){

                //System.out.println("Reached max stupid depth");

                break;

            }

        }

        

        System.out.println("Stupid expand actions : "+actions);

    }

    

    

    

    public Jtr qb(Color c) {super.setBackground(c); return this; }

    public Jtr qf(Color c) {super.setForeground(c); return this; }

    public Jtr qe(boolean b) {setEnabled(b); return this; }

    public Jtr qn(String name) {super.setName(name); return this;  }

    public Jtr qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

}

class Jt extends JToggleButton{


    public Jt(String text) {

        super(text);

    }


    public Jt(String text, boolean selected) {

        super(text, selected);

    }

    public Jt qb(Color c) {super.setBackground(c); return this; }

    public Jt qf(Color c) {super.setForeground(c); return this; }

    public Jt qe(boolean b) {setEnabled(b); return this; }

    public Jt qn(String name) {super.setName(name); return this;  }

    public Jt qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    public Jt q(Insets marg) {super.setMargin(marg); return this;}

    public Jt qins0() {super.setMargin(Jfr.zins); return this;}

    

    

    

}

class Jr extends JRadioButton{


    public Jr(String text) {

        super(text);

    }


    public Jr(String text, boolean selected) {

        super(text, selected);

    }

    public Jr qb(Color c) {super.setBackground(c); return this; }

    public Jr qf(Color c) {super.setForeground(c); return this; }

    public Jr qe(boolean b) {setEnabled(b); return this; }

    public Jr qn(String name) {super.setName(name); return this;  }

    public Jr qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

    

}

class Jb extends JButton{


    public Jb(String text) {

        super(text);

    }

    public Jb qb(Color c) {super.setBackground(c); return this; }

    public Jb qf(Color c) {super.setForeground(c); return this; }

    public Jb qe(boolean b) {setEnabled(b); return this; }

    public Jb qn(String name) {super.setName(name); return this;  }

    public Jb qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

    

}

class Jl extends JLabel{


    public Jl(String text) {

        super(text);

    }

    public Jl qb(Color c) {super.setBackground(c); return this; }

    public Jl qf(Color c) {super.setForeground(c); return this; }

    public Jl qe(boolean b) {setEnabled(b); return this; }

    public Jl qn(String name) {super.setName(name); return this;  }

    public Jl qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

    

}

class Jtf extends JTextField{


    public Jtf(String text) {

        super(text);

    }

    public Jtf qb(Color c) {super.setBackground(c); return this; }

    public Jtf qf(Color c) {super.setForeground(c); return this; }

    public Jtf qe(boolean b) {setEnabled(b); return this; }

    public Jtf qn(String name) {super.setName(name); return this;  }

    public Jtf qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    

    

}

class Jspl extends JSplitPane{

    public Component compDivider;


    public Jspl() {

        super(Jspl.HORIZONTAL_SPLIT,null,null);

        compDivider=getComponent(0);

        

    }

    public Jspl(int newOrientation) {

        this();

        super.setOrientation(newOrientation);

    }


    public Jspl(int newOrientation, boolean newContinuousLayout) {

        this(newOrientation);

        super.setContinuousLayout(newContinuousLayout);

    }


    public Jspl(int newOrientation, Component newLeftComponent, Component newRightComponent) {

        this(newOrientation);

        super.setLeftComponent(newLeftComponent);

        super.setRightComponent(newRightComponent);

    }

    

    public Jspl qb(Color c) {super.setBackground(c); return this; }

    public Jspl qf(Color c) {super.setForeground(c); return this; }

    public Jspl qe(boolean b) {setEnabled(b); return this; }

    public Jspl qn(String name) {super.setName(name); return this;  }

    public Jspl qtt(String tooltip) {super.setToolTipText(tooltip); return this;  }

    @Override

    public String toString() {

        String out=super.toString();

        String name=getName();

        if(name!=null){

            out=name;

        }

        return out;

    }

    

    

    public Jspl qor(int some){

        super.setOrientation(Math.abs(some)%2);

        return this;

    }

    public Jspl qhor(){

        super.setOrientation(Jspl.HORIZONTAL_SPLIT);

        return this;

    }

    public Jspl qhor(boolean hor){

        super.setOrientation((hor)?(1):(0));

        return this;

    }

    public Jspl qver(){

        super.setOrientation(Jspl.VERTICAL_SPLIT);

        return this;

    }

    public Jspl qver(boolean vert){

        super.setOrientation((vert)?(0):(1));

        return this;

    }

    public Jspl qle(Component le){

        super.setLeftComponent(le);

        return this;

    }

    public Jspl qri(Component ri){

        super.setRightComponent(ri);

        return this;

    }

    public Jspl qrw(double rw,double loc){

        super.setResizeWeight(rw);

        super.setDividerLocation(loc);

        return this;

    }

    /**

     * 

     * @param d to set rw and div loc

     * @return 

     */

    public Jspl qrw(double d){

        return qrw(d,d);

    }

    public Jspl qContinuousLayout(){

        super.setContinuousLayout(true);

        return this;

    }

    public Jspl qOneTouchExpandable(){

        super.setOneTouchExpandable(true);

        return this;

    }

    public Jspl qdiv(int dividerSize){

        super.setDividerSize(dividerSize);

        return this;

    }

    public Jspl setComps(Component left,Component right){

        setLeftComponent(null);

        setRightComponent(null);

        setLeftComponent(left);

        setRightComponent(right);

        validate();

        repaint();

        return this;

    }

    

    

    public double getDividerDoubleLocation(){

        int h=getHeight();

        if(orientation==1){h=getWidth();}

        if(h<1){h=100;}

        int d=getDividerLocation();

        if(d<1 || d>h){d=h/2;}

        double out=d;

        out/=h;

        return out;

    }

    public void switchComponents(){

        Component lc=getLeftComponent();

        Component rc=getRightComponent();

        setLeftComponent(null);

        setRightComponent(null);

        setLeftComponent(rc);

        setRightComponent(lc);

    }

    

    

}




class Dmtn extends DefaultMutableTreeNode{


    public Dmtn() {

    }


    public Dmtn(Object userObject) {

        super(userObject);

    }

    public Dmtn cr(){

        return new Dmtn();

    }

    public Dmtn cr(Object uo){

        Dmtn out=cr();

        out.setUserObject(uo);

        return out;

    }

    public Dmtn crad(Object uo){

        Dmtn out=cr(uo);

        add(out);

        return out;

    }

    public Dmtn dmtn(int index){

        return (Dmtn)getChildAt(index);

    }

    

    public Dmtn dmtnLast(){

        return dmtn(getChildCount()-1);

    }

    

    

    

    public TreePath ntp(){

        return new TreePath(getPath());

    }

    public Dmtn dmtnPar(){return (Dmtn)parent;}

    

    

}

class Vect<E> extends Vector<E>{

    

}


class Rand extends Random{

    public static Rand sti=new Rand();


    public int randIntInrange(int floorInc,int ceilIncl){

        return floorInc+nextInt(1+ceilIncl-floorInc);

    }

    

    public Color randColor(){

        return randColor(0,255,0,255,0,255);

    }

    public Color randColor(int rfloorInc,int rceilIncl,int gfloorInc,int gceilIncl,int bfloorInc,int bceilIncl){

        return new Color(randIntInrange(rfloorInc, rceilIncl),randIntInrange(gfloorInc, gceilIncl),randIntInrange(bfloorInc, bceilIncl));

    }


}


Τρίτη 3 Μαΐου 2022

Java vs c++ vs python

3.000.000.000 c++ iterations at:6 sec
9.000.000.000 java iterations at :2 sec
0.123.456.789 python iterations at : 9.88  sec

ok i understand python is too slow but how is this possible and
java is faster than c++ (on my ubuntu 20.01) ????????

3.400.000.000 Hz = 3.4GHz


 

 

 

 

 

 

 

 

( This new idea-stream of
teachers proposing python to kids is beyond...
............my understanding !!!!
Maybe its because they forgot their programming learning progress .
----python....go interprette your self !!!!!)

 

#include <iostream>
#include<ctime>
#include <sstream>
using namespace std;
int main(int argc, char** argv){
    cout<<"Hello c++ Universe" <<endl;
     long iterations=300000000l;//3.000.000.000
       if(argc>1){
        stringstream buffer(argv[1]);
        buffer >> iterations;
        }
    long l=iterations;
    time_t startTime=time(NULL);
    while(l>0){
        //std::cout << l << std::endl;
        l-=1;
    }
    time_t endTime=time(NULL);
    double difTime=endTime-startTime;
    cout<<iterations<<" c++ iterations at:"<<difTime<<" sec"<<endl;
    return 0;
}//g++ -o CppDecreaser CppDecreaser.cpp -> ./CppDecreaser 1234


public class JavaDecreaser{
    public static void main(String args[]){
        long iterations=9000000000l ; //~=3.000.000.000 actions per second
        if(args.length>0){
            try{iterations=Long.parseLong(args[0]);}catch(NumberFormatException nfe){}
        }
        long l=iterations;
        long startTime=System.currentTimeMillis();
        while(l>0){
            //System.out.println(l+"");
            l-=1;
        }
        long endTime=System.currentTimeMillis();
        long difTime=endTime-startTime;
        System.out.println(iterations+" java iterations at :"+(difTime/1000)+" sec" );
    }
}//javac JavaDecreaser.java -> java JavaDecreaser 1234


import sys
import time
iterations = 300000000#0
if(len(sys.argv)>1):
    iterations=int(sys.argv[1])
l=iterations
startTime=time.time()
while(l>0):
    #print(l)
    l-=1
endTime=time.time()
difTime=endTime-startTime
print(iterations," python iterations at :",difTime," sec")
#python or python3 PythonDecreaser 1234


Hello c++ Universe
3000000000 c++ iterations at:6 sec
9000000000 java iterations at :2 sec
123456789  python iterations at : 10.401030540466309  sec