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));
}
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου