cmdGUI.java 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. * Copyright (C) 2015 iZc
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package de.nplusc.izc.tools.UiToolz;
  18. import com.sun.awt.AWTUtilities;
  19. import de.nplusc.izc.tools.baseTools.RingBuffer;
  20. import de.nplusc.izc.tools.baseTools.Tools;
  21. import java.awt.*;
  22. import java.awt.event.KeyEvent;
  23. import java.awt.event.MouseMotionAdapter;
  24. import java.io.*;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.HashMap;
  28. import javax.imageio.ImageIO;
  29. import javax.swing.*;
  30. import org.apache.commons.exec.*;
  31. import org.apache.logging.log4j.LogManager;
  32. import org.apache.logging.log4j.Logger;
  33. /**
  34. *
  35. * @author LH
  36. */
  37. public class cmdGUI extends javax.swing.JFrame
  38. {
  39. private static final Logger l = LogManager.getLogger();
  40. //51,0:tab1
  41. //availSize=840:20
  42. /**
  43. * the definition of the Terminal-font
  44. */
  45. public static final Font term = new Font("Lucida Console",Font.BOLD,15);//Terminal
  46. /**
  47. * the color of the font
  48. */
  49. public static final Color FontColor = new Color(170,220,240,200);//Color(255, 0, 0, 128);
  50. /**
  51. * a constant color for transparent bgs
  52. */
  53. public static final Color TransBgColor = new Color(0, 0, 0, 0);
  54. /**
  55. * where the button is
  56. */
  57. public static final Polygon buttonPos = new Polygon(new int[]{27,73,85,152,155,209,229,168,12,6},new int[]{16,16,1,1,8,7,27,47,47,36},10);
  58. /**
  59. * instance-id
  60. */
  61. public final String id;
  62. /**
  63. * number ofTabs
  64. */
  65. public static final int tabCount = 4;
  66. /**
  67. * position of tabs
  68. */
  69. public static final Rectangle[] tabs = new Rectangle[]
  70. {
  71. new Rectangle(50, 0, 200, 20), //0
  72. new Rectangle(250, 0, 200, 20),//1
  73. new Rectangle(450, 0, 200, 20),//2
  74. new Rectangle(650, 0, 200, 20) //3
  75. };
  76. /**
  77. * Instances of the GUI are stored here
  78. * its part of a hack
  79. */
  80. public static HashMap<String,cmdGUI> gac= new HashMap<>();//Part of a haxx
  81. //public static cmdGUI cgui=null;
  82. //public static boolean sa;
  83. //public static DefaultExecutor ex;
  84. //public static boolean bsfin = false;
  85. //##################################################################################################
  86. private ArrayList<RingBuffer<String>> screenBuf= new ArrayList<>();
  87. // /\ new RingBuffer<>(String.class,5000,"")
  88. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  89. // \/ new RingBuffer<>(String.class,5000,"noCmd")
  90. private ArrayList<RingBuffer<String>> cmdBuf=new ArrayList<>() ;//noCmd Detektor für leere Zeile
  91. private boolean[] sil = new boolean[4];
  92. private boolean[] tp = new boolean[3];
  93. private boolean[] isInCmd = new boolean[4];
  94. private String[] cmdForSend = new String[4];
  95. private String[] cmdInLine = new String[4];
  96. private int tabSelected=0;
  97. private int[] currLin = new int[]{0,0,0,0};
  98. private int[] uptypes=new int[]{0,0,0,0};
  99. private int[] upmax = new int[]{0,0,0,0};
  100. private boolean[] ud = new boolean[]{false,false,false,false};
  101. private boolean[] ud1 = new boolean[]{true,true,true,true};
  102. private JSlider js;
  103. private JLabel[] line;
  104. private JTextField ipline;
  105. private ExtendedJPanel Surface,ButtonArea,tabBar;
  106. private UIFileAccess guifile;//replace with loader and selection
  107. //private static String[] RingBuffer = new String[5000];#
  108. private boolean standalone = true;
  109. //private static int[] RingBufferCfg = new int[2];//null=pointer;1=previousElement
  110. // <editor-fold defaultstate="collapsed" desc="pflichcode">
  111. public String getCmdForSend(int targetTab)
  112. {
  113. return cmdForSend[targetTab];
  114. }
  115. public void setCmdForSend(String cmd,int targetTab)
  116. {
  117. this.cmdForSend[targetTab] = cmd;
  118. }
  119. public void setIsInCmd(boolean isInCmd,int targetTab)
  120. {
  121. this.isInCmd[targetTab] = isInCmd;
  122. }
  123. public boolean isStandalone()
  124. {
  125. return standalone;
  126. }
  127. public void setStandalone(boolean standalone)
  128. {
  129. this.standalone = standalone;
  130. }
  131. // </editor-fold>
  132. //baseOffs=200|120
  133. //size=960*480
  134. @SuppressWarnings("CallToThreadDumpStack")
  135. public cmdGUI(UIFileAccess g)
  136. {
  137. super();//HAX;tst.needd
  138. guifile=g;
  139. try
  140. {
  141. if(guifile.zipBased)
  142. {
  143. setIconImage(ImageIO.read(guifile.loadFileFromZip(guifile.ResourceURLs.get("icon"))));
  144. }
  145. else
  146. {
  147. setIconImage(ImageIO.read(new File(guifile.ResourceURLs.get("icon"))));
  148. }
  149. } catch (IOException e1) {
  150. e1.printStackTrace();
  151. }
  152. for(int i=0;i<tabCount;i++)
  153. {
  154. RingBuffer<String>rb = new RingBuffer<>(String.class,5000,"");
  155. screenBuf.add(rb);
  156. rb = new RingBuffer<>(String.class,5000,"noCmd");
  157. cmdBuf.add(rb);
  158. }
  159. id= this.toString();
  160. System.err.println(id);
  161. l.trace(id);
  162. this.setUndecorated(true);
  163. //initComponents();
  164. buildGUI();
  165. tp[1] = AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT);
  166. //cgui=this;//hack
  167. gac.put(id,this);
  168. if(tp[1])
  169. {
  170. AWTUtilities.setWindowOpaque(this, false);
  171. //AWTUtilities.
  172. }
  173. //Point p = this.getLocation();//
  174. //p.setLocation(); //Setzt Fenster an Zielkkordinaten
  175. this.setLocation(guifile.windowBasePoint);
  176. //ButtonArea.setLocation(630, 432);
  177. //this.revalidate();
  178. //630;432==Button
  179. }
  180. /**
  181. * the Form initializer
  182. */
  183. private void buildGUI()
  184. {
  185. int[] wincfg = guifile.windowSize;
  186. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  187. setMinimumSize(new java.awt.Dimension(wincfg[0], wincfg[1]));
  188. setPreferredSize(new java.awt.Dimension(wincfg[0], wincfg[1]));
  189. Container cp = getContentPane();
  190. cp.setLayout(null);
  191. Surface = new ExtendedJPanel(1,guifile);
  192. Surface.setBounds(0,0,wincfg[0], wincfg[1]);
  193. Surface.setLayout(null);
  194. cp.add(Surface);
  195. /*addToSurface*/
  196. //{
  197. /*
  198. MysteryError.
  199. There was no Constructor-CAll anywhere
  200. a
  201. cmdGUI[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.synth.SynthBorder@106def2,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
  202. ???
  203. Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: Constructor must call super() or this() before return in method FontEngine.<init>()V at offset 0
  204. at cmdGUI.buildGUI(cmdGUI.java:178)
  205. at cmdGUI.<init>(cmdGUI.java:139)
  206. at cmdGUI$9$1.run(cmdGUI.java:1047)
  207. at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
  208. at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
  209. at java.awt.EventQueue.access$000(EventQueue.java:101)
  210. at java.awt.EventQueue$3.run(EventQueue.java:666)
  211. at java.awt.EventQueue$3.run(EventQueue.java:664)
  212. at java.security.AccessController.doPrivileged(Native Method)
  213. at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
  214. at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
  215. at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
  216. at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
  217. at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
  218. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
  219. at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
  220. at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
  221. */
  222. int[]tbc = guifile.tabBarPos;
  223. tabBar = new ExtendedJPanel(3,guifile);
  224. tabBar.setBounds(tbc[0],tbc[1],tbc[2],tbc[3]);
  225. tabBar.initOVL();
  226. updateTabBarMessages(0);
  227. Surface.add(tabBar);
  228. int[] lcf = guifile.lineCfg;
  229. js = new JSlider(0, 5000-lcf[3]);//H@XX
  230. js.setInverted(true);
  231. js.setOrientation(SwingConstants.VERTICAL);
  232. js.setUI(new HoloSliderUi(js));
  233. js.setOpaque(false);
  234. int[] scfg = guifile.ScrollBar;
  235. js.setBounds(scfg[0],scfg[1],scfg[2],scfg[3]);
  236. Surface.add(js);
  237. ButtonArea = new ExtendedJPanel(2,guifile);//ExtebdeedJPanel(2);
  238. //ButtonArea.setLocation(630, 432);
  239. int[] bacfg = guifile.buttonPanel;
  240. ButtonArea.setBounds(bacfg[0],bacfg[1],bacfg[2],bacfg[3]);
  241. // ButtonArea.setBounds(630,432,233,48);
  242. Surface.add(ButtonArea);
  243. int[] ipc = guifile.ipLineArea;
  244. ipline = new JTextField();
  245. ipline.setBounds(ipc[0],ipc[1],ipc[2],ipc[3]);
  246. ipline.setBorder(null);
  247. ipline.setOpaque(false);
  248. ipline.setFont(term);
  249. ipline.setForeground(FontColor);
  250. ipline.setBackground(TransBgColor);
  251. Surface.add(ipline);
  252. int lmx = guifile.lineCount;
  253. line = new JLabel[lmx];
  254. // <editor-fold defaultstate="collapsed" desc="Altlast">
  255. /*
  256. * Disabled old variant
  257. * JLabel line2 = new JLabel();
  258. * JLabel line3 = new JLabel();
  259. * JLabel line4 = new JLabel();
  260. * JLabel line5 = new JLabel();
  261. * JLabel line6 = new JLabel();
  262. * JLabel line7 = new JLabel();
  263. * JLabel line8 = new JLabel();
  264. * JLabel line9 = new JLabel();
  265. * JLabel line10 = new JLabel();
  266. * JLabel line11 = new JLabel();
  267. * JLabel line12 = new JLabel();
  268. * JLabel line13 = new JLabel();
  269. * JLabel line14 = new JLabel();
  270. * JLabel line15 = new JLabel();
  271. */
  272. //</editor-fold>
  273. //for( int i=0,i<tabCount,i++)
  274. //{
  275. for (int i=0;i<lmx;i++)
  276. {
  277. JLabel linel = line[i];
  278. linel = new JLabel();
  279. linel.setFont(term);
  280. //line1.setOpaque(true);//Fliegenklatsche
  281. linel.setForeground(FontColor);
  282. //linel.setText("test.lm("+i+")");
  283. if(i==13)
  284. {
  285. //linel.setText("llll.lm("+i+")");
  286. }
  287. linel.setBounds(lcf[0], lcf[1]+i*lcf[3], lcf[2], lcf[3]);
  288. // if(k==0)//KEin I hier!!!!!!!!!
  289. // {
  290. Surface.add(linel);
  291. //Surface.remove()
  292. //}
  293. line[i]=linel;
  294. }
  295. //}
  296. //}
  297. // MouseMotionAdapter MMA = ;
  298. ButtonArea.addMouseMotionListener(new MouseMotionAdapter() {
  299. @Override
  300. public void mouseMoved(java.awt.event.MouseEvent evt) {
  301. ButtonAreaHover(evt,false);
  302. }
  303. });
  304. ipline.addKeyListener(new java.awt.event.KeyAdapter()
  305. {
  306. @Override
  307. public void keyPressed(java.awt.event.KeyEvent evt)
  308. {
  309. keyPressAtIpLine(evt);
  310. }
  311. });
  312. ButtonArea.addMouseListener(new java.awt.event.MouseAdapter() {
  313. @Override
  314. public void mouseClicked(java.awt.event.MouseEvent evt) {
  315. ButtonAreaClicked(evt);
  316. }
  317. @Override
  318. public void mouseEntered(java.awt.event.MouseEvent evt) {
  319. ButtonAreaHover(evt,true);
  320. }
  321. @Override
  322. public void mouseExited(java.awt.event.MouseEvent evt)
  323. {
  324. ButtonAreaHover(evt,true);
  325. }
  326. });
  327. js.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
  328. @Override
  329. public void mouseDragged(java.awt.event.MouseEvent evt) {
  330. refreshLines(evt,tabSelected);
  331. }
  332. });
  333. tabBar.addMouseListener(new java.awt.event.MouseAdapter() {
  334. @Override
  335. public void mouseClicked(java.awt.event.MouseEvent evt) {
  336. TabBarClicked(evt);
  337. }/*
  338. @Override
  339. public void mouseEntered(java.awt.event.MouseEvent evt) {
  340. ButtonAreaHover(evt,true);
  341. }
  342. @Override
  343. public void mouseExited(java.awt.event.MouseEvent evt)
  344. {
  345. ButtonAreaHover(evt,true);
  346. }*/
  347. });
  348. //js.
  349. //54,412:Po:Sizs
  350. //860*17
  351. Surface.repaint();
  352. cp.repaint();
  353. cp.revalidate();
  354. }
  355. /**
  356. * Handeles the Glow
  357. * @param evt mouse pos
  358. * @param forceX1t override
  359. */
  360. private void ButtonAreaHover(java.awt.event.MouseEvent evt,boolean forceX1t)
  361. {
  362. if(buttonPos.contains(evt.getPoint())&&!forceX1t)
  363. {
  364. ButtonArea.cmdButtonGlow(true);
  365. }
  366. else
  367. {
  368. ButtonArea.cmdButtonGlow(false);
  369. }
  370. ButtonArea.repaint(/*null*/);//niemals nullen
  371. }
  372. /**
  373. * @see ButtonAreaClicked(evt,entered)
  374. * @param evt
  375. */
  376. private void ButtonAreaClicked(java.awt.event.MouseEvent evt)
  377. {
  378. ButtonAreaClicked(evt,false);
  379. }
  380. /**
  381. * the Tab-Bar event handler
  382. * @param evt ClickEvent
  383. */
  384. private void TabBarClicked(java.awt.event.MouseEvent evt)
  385. {
  386. cmdInLine[tabSelected] = ipline.getText();
  387. for (int i = 0; i < tabs.length; i++)
  388. {
  389. Rectangle r = tabs[i];
  390. if(r.contains(evt.getPoint()))
  391. {
  392. tabSelected=i;
  393. }
  394. }
  395. refreshLines(evt, tabSelected);
  396. refreshCmd();
  397. updateTabBarMessages(tabSelected);
  398. Surface.repaint();
  399. }
  400. /**
  401. * Handles the addit features of IpLine;
  402. * @param evt keypress
  403. */
  404. public void keyPressAtIpLine(java.awt.event.KeyEvent evt)
  405. {
  406. int kc = evt.getKeyCode();
  407. if(kc==KeyEvent.VK_ENTER)
  408. {
  409. //Tools.dlg(true,"Enter","...");
  410. ButtonAreaClicked(new java.awt.event.MouseEvent(Surface, kc, kc, 0, kc, kc, 0, true),true);
  411. //^No NPX here^\\
  412. }
  413. if(kc==KeyEvent.VK_UP)
  414. {
  415. if(!ud[tabSelected]&&!ud1[tabSelected])
  416. {
  417. uptypes[tabSelected]++;
  418. }
  419. ud1[tabSelected]=false;
  420. ud[tabSelected]=true;
  421. int get = upmax[tabSelected]-(uptypes[tabSelected]+1);
  422. //System.err.println("uptypes|"+uptypes);
  423. if(get>=0&&!(uptypes[tabSelected]>upmax[tabSelected]))
  424. {
  425. String ldcmd = cmdBuf.get(tabSelected).getContentAt(get);
  426. l.trace("get|"+get);
  427. if(!ldcmd.equals("noCmd"))
  428. {
  429. uptypes[tabSelected]++;
  430. ipline.setText(ldcmd);
  431. }
  432. }
  433. }
  434. if(kc==KeyEvent.VK_DOWN)
  435. {
  436. /*
  437. if(uptypes>0)
  438. {
  439. uptypes--;
  440. }
  441. if(uptypes>=0)
  442. {
  443. int get = upmax-(uptypes+1);
  444. if(!(get<0))
  445. {
  446. get=0;
  447. }
  448. String ldcmd = cmdBuf.getContentAt(get);
  449. ipline.setText(ldcmd);
  450. }
  451. else
  452. {
  453. ipline.setText(ipline.getText());
  454. }*/
  455. if(ud[tabSelected])
  456. {
  457. uptypes[tabSelected]--;
  458. }
  459. ud[tabSelected]=false;
  460. uptypes[tabSelected]--;
  461. if(uptypes[tabSelected]<0)
  462. {
  463. uptypes[tabSelected]++;
  464. }
  465. int get = upmax[tabSelected]-(uptypes[tabSelected]+1);
  466. l.trace("uptypes|"+Arrays.toString(uptypes));
  467. if(get>=0&&!(uptypes[tabSelected]>upmax[tabSelected]))
  468. {
  469. String ldcmd = cmdBuf.get(tabSelected).getContentAt(get);
  470. l.trace("get|"+get);
  471. if(!ldcmd.equals("noCmd"))
  472. {
  473. //uptypes++;
  474. ipline.setText(ldcmd);
  475. }
  476. }
  477. }
  478. }
  479. /**
  480. * Handles Button
  481. * @param evt where clicked
  482. * @param entered if enter key pressed
  483. */
  484. @SuppressWarnings("CallToThreadDumpStack")
  485. private void ButtonAreaClicked(java.awt.event.MouseEvent evt,boolean entered)//für Enter-Eingabe
  486. {
  487. if(buttonPos.contains(evt.getPoint())||entered)
  488. {
  489. cmdBuf.get(tabSelected).addItem(ipline.getText());
  490. if(upmax[tabSelected]<5000)
  491. {
  492. upmax[tabSelected]++;
  493. }
  494. uptypes[tabSelected]=0;
  495. l.trace("tabForTrg|"+tabSelected+"|"+isInCmd[tabSelected]);
  496. if(!isInCmd[tabSelected])
  497. {
  498. runCmd();
  499. }
  500. else
  501. {
  502. l.trace("toCmdatTab|"+tabSelected+"|"+isInCmd[tabSelected]);
  503. String t = ipline.getText();
  504. if(t == null)
  505. {
  506. t = "";
  507. }
  508. if(t.equals(""))
  509. {
  510. t=" ";
  511. }
  512. ipline.setText("");
  513. cmdForSend[tabSelected]=t;
  514. if(t.equals("exit")&&standalone)
  515. {
  516. try
  517. {
  518. Thread.sleep(200);
  519. cmdForSend[tabSelected]=" ";//HAKK
  520. }
  521. catch (InterruptedException exc)
  522. {
  523. exc.printStackTrace();
  524. }
  525. }
  526. }
  527. }
  528. }
  529. /**
  530. * reloads the command of previous tab
  531. */
  532. private void refreshCmd()//ynchroniszeUpTypes()
  533. {
  534. ipline.setText(cmdInLine[tabSelected]);
  535. }
  536. /**
  537. * This method is not called from within the constructor to
  538. * initialize the form.
  539. * WARNING: Do NOT modify this code. The content of this method is
  540. * always regenerated by the Form Editor.
  541. */
  542. public void updateTabBarMessages(int targetTab)
  543. {
  544. /* tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_T, 50, 0);
  545. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_A, 70, 0);
  546. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_B, 90, 0);
  547. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_A, 130, 0);
  548. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_T, 250, 0);
  549. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_A, 270, 0);
  550. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_B, 290, 0);
  551. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_B, 330, 0);
  552. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_T, 450, 0);
  553. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_A, 470, 0);
  554. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_B, 490, 0);
  555. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_C, 530, 0);
  556. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_T, 650, 0);
  557. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_A, 670, 0);
  558. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_B, 690, 0);
  559. tabBar.setLetter(FontEngine.FONT_LAUNCHPAD, FontEngine.LETTER_D, 630, 0);
  560. */
  561. //marker for active Tab
  562. tabBar.initOVL();
  563. tabBar.setLetter(FontEngine.FONT_DECEPTICON_GRAFFITTI,FontEngine.LETTER_N,
  564. (targetTab*200)+150,0);
  565. tabBar.repaint();
  566. }
  567. @SuppressWarnings("unchecked")
  568. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  569. private void initComponents() {
  570. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  571. setMinimumSize(new java.awt.Dimension(960, 480));
  572. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  573. getContentPane().setLayout(layout);
  574. layout.setHorizontalGroup(
  575. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  576. .addGap(0, 964, Short.MAX_VALUE)
  577. );
  578. layout.setVerticalGroup(
  579. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  580. .addGap(0, 516, Short.MAX_VALUE)
  581. );
  582. pack();
  583. }// </editor-fold>//GEN-END:initComponents
  584. /**
  585. * runs the cmd which is in the ipLine
  586. */
  587. public void runCmd()
  588. {
  589. final String cmd = ipline.getText();
  590. addLine(cmd,tabSelected);
  591. ipline.setText("");
  592. l.trace("cmdLoaded|"+cmd+"|"+tabSelected);
  593. if(cmd.equals("quit"))
  594. {
  595. System.exit(0);
  596. }
  597. //runCode here;
  598. Thread t = new Thread(new Runnable()
  599. {
  600. //@SuppressWarnings("SleepWhileInLoop")//Hx
  601. @SuppressWarnings("CallToThreadDumpStack")
  602. @Override
  603. public void run()
  604. {
  605. l.trace("cmdLoaded2|"+cmd+"|"+tabSelected);
  606. runCmd(cmd);
  607. }
  608. });
  609. t.start();
  610. }
  611. /**
  612. * Runs a cmd and sets inCmd mode.
  613. *
  614. * @param args the command line arguments
  615. */
  616. @SuppressWarnings("CallToThreadDumpStack")
  617. public void runCmd(String cmd)//synchronized gint nen fetten Bug
  618. {
  619. final HashMap<Integer,Object> t = new HashMap<>();
  620. int belongingTab = tabSelected;
  621. t.put(0,belongingTab);
  622. Tools.DebugHelperPrint("cmd|"+belongingTab, true, "Toolkit.enableFinerDebug");
  623. cmdGUI cG = this;
  624. String[] cmdp = cmd.split(" ");
  625. // BufferedInputStream log = new BufferedInputStream
  626. // (
  627. // new ByteArrayInputStream(new byte[]{0})
  628. // );//das einzelne Byte ist n(ö|ä)tig um ne NPX zu verhindern
  629. ExecuteStreamHandler s;
  630. final DefaultExecuteResultHandler devnull = new DefaultExecuteResultHandler();
  631. /* {
  632. @Override
  633. public void onProcessComplete(int exitValue)
  634. {
  635. System.err.println("fin");
  636. cmdGUI.sil=false;
  637. cmdGUI.cgui.setIsInCmd(false);
  638. }
  639. @Override
  640. public void onProcessFailed(ExecuteException e)
  641. {
  642. System.err.println("Urrgs");
  643. cmdGUI.sil=false;
  644. cmdGUI.cgui.setIsInCmd(false);
  645. }
  646. };*/
  647. String[] fexg = cmd.split("\\.");
  648. Tools.DebugHelperPrint(cmd, true, "Toolkit.enableFinerDebug");
  649. Tools.DebugHelperPrint("cmd2|"+belongingTab, true, "Toolkit.enableFinerDebug");
  650. if(fexg[fexg.length-1].equalsIgnoreCase("bat")||cmd.equals("dir"))
  651. {
  652. cmd = "cmd.exe /c "+cmd;
  653. Tools.DebugHelperPrint("cmdtrigger", true, "Toolkit.enableFinerDebug");
  654. }
  655. CommandLine cl = CommandLine.parse(cmdp[0]);
  656. for (int i = 1; i < cmdp.length; i++)
  657. {
  658. cl.addArgument(cmdp[i]);
  659. }
  660. Executor e = new DefaultExecutor();
  661. //ex=(DefaultExecutor)e;
  662. try
  663. {
  664. setIsInCmd(true,(int)t.get(0));
  665. final PipedInputStream in = new PipedInputStream();
  666. PipedOutputStream out = new PipedOutputStream();
  667. final PipedOutputStream txOut = new PipedOutputStream();
  668. PipedInputStream txIn = new PipedInputStream();
  669. Tools.DebugHelperPrint("cmd3|"+belongingTab, true, "Toolkit.enableFinerDebug");
  670. txIn.connect(txOut);
  671. out.connect(in);
  672. // txOut.write((byte)0);//??//
  673. //System.err.pri
  674. s = new PumpStreamHandler(out,out,txIn);
  675. //final OutputStream txOut = ((DefaultExecutor)e).stdin;
  676. // i.
  677. //s.setProcessOutputStream(log);
  678. Tools.DebugHelperPrint("???", true, "Toolkit.enableFinerDebug");
  679. e.setStreamHandler(s);
  680. //^HAck da sonst zwodeitich//VOID
  681. Tools.DebugHelperPrint("Wennhier was ist...", true, "Toolkit.enableFinerDebug");
  682. //log.
  683. //cG.
  684. sil[(int)t.get(0)]=true;
  685. Tools.DebugHelperPrint("cmd4|"+belongingTab, true, "Toolkit.enableFinerDebug");
  686. /*new Thread(new Runnable()
  687. {
  688. @Override
  689. @SuppressWarnings("SleepWhileInLoop")
  690. public void run()
  691. {
  692. // while(!devnull.hasResult())
  693. // {
  694. try
  695. {
  696. ex.p.waitFor();
  697. Thread.sleep(50);
  698. //System.err.println("AA");
  699. }
  700. catch (InterruptedException ex)
  701. {
  702. ex.printStackTrace();
  703. }
  704. //}
  705. System.err.println("fin");
  706. cmdGUI.sil=false;
  707. cmdGUI.cgui.setIsInCmd(false);
  708. System.err.println("Wr");
  709. System.setProperty("fin", "true");
  710. }
  711. }).start();*/
  712. new Thread(new Runnable()
  713. {
  714. cmdGUI cG =cmdGUI.gac.get(id);
  715. //BufferedOutputStream txOut=(BufferedOutputStream)((DefaultExecutor)ex).getStdin();
  716. @Override
  717. @SuppressWarnings({"SleepWhileInLoop", "SleepWhileInLoop"})
  718. public void run()
  719. {
  720. while(sil[(int)t.get(0)])
  721. {
  722. // try
  723. // {
  724. //txOut.write("x\b".getBytes());
  725. //txOut.flush();
  726. String chk = cG.getCmdForSend((int)t.get(0));
  727. // System.err.println(chk);
  728. Tools.DebugHelperPrint(chk, true, "Toolkit.enableFinerDebug");
  729. if(chk==null)
  730. {
  731. chk="";
  732. }
  733. //if((!System.getProperty("fin", "lm").equals("lm")))
  734. //{
  735. // System.clearProperty("fin");
  736. // chk="\r";
  737. //}
  738. if(!chk.equals(""))
  739. {
  740. try
  741. {
  742. chk+="\n";
  743. //o=txOut
  744. txOut.write(chk.getBytes());
  745. txOut.flush();
  746. //System.err.println(">>"+chk);
  747. Tools.DebugHelperPrint(">>"+chk, true, "Toolkit.enableFinerDebug");
  748. //in.mark(1);
  749. //in.reset();Funzen nicht;
  750. }
  751. catch (IOException ex)
  752. {
  753. ex.printStackTrace();
  754. }
  755. cG.setCmdForSend(null,(int)t.get(0));//Nicht vergessen.sonst Bugschleuder
  756. chk=null;
  757. }
  758. Tools.wait(50);
  759. // }
  760. //catch (IOException ex)
  761. // {
  762. // System.err.println("Kakk");
  763. // ex.printStackTrace();
  764. // }
  765. }
  766. }
  767. }).start();
  768. new Thread(new Runnable()
  769. {
  770. cmdGUI cG =cmdGUI.gac.get(id);
  771. @Override
  772. public void run()
  773. {
  774. try
  775. {
  776. BufferedReader br = new BufferedReader(new InputStreamReader(in));
  777. //String s2 = br.readLine();
  778. //if(in.)
  779. while(sil[(int)t.get(0)])
  780. {
  781. while (in.available()>0)//||(cmdGUI.sil))
  782. {
  783. byte rb = (byte) in.read();
  784. String ln = ""+(char)rb;
  785. //in.
  786. rb = (byte) in.read();
  787. Tools.DebugHelperPrint((char)rb+"|"+0, true, "Toolkit.enableFinerDebug");
  788. int i=0;
  789. while(((char)rb!='\n')&&((char)rb!='>'))
  790. {
  791. ln +=(char)rb;
  792. // System.err.println((char)rb+"|"+i+1);
  793. Tools.DebugHelperPrint((char)rb+"|"+i+1, true, "Toolkit.enableFinerDebug");
  794. rb = (byte) in.read();//DONOTFORGET!!!!!
  795. // System.err.println((char)rb+"|"+i+2);
  796. Tools.DebugHelperPrint((char)rb+"|"+i+2, true, "Toolkit.enableFinerDebug");
  797. i++;
  798. }
  799. if((char)rb=='>')
  800. {
  801. ln+=">";
  802. }
  803. cG.addLine(ln,(int)t.get(0));
  804. Tools.DebugHelperPrint("trg2|"+(int)t.get(0), true, "Toolkit.enableFinerDebug");
  805. Tools.DebugHelperPrint(ln, true, "Toolkit.enableFinerDebug");
  806. //s2 = br.readLine();
  807. Tools.DebugHelperPrint("Fotze", true, "Toolkit.enableFinerDebug");
  808. }
  809. Tools.wait(50);
  810. }
  811. Tools.DebugHelperPrint("Hira?",true, "Toolkit.enableFinerDebug");
  812. }
  813. catch (IOException ex)
  814. {
  815. ex.printStackTrace();
  816. }
  817. cG.setIsInCmd(false,(int)t.get(0));
  818. }
  819. }).start();
  820. Tools.DebugHelperPrint("X XX|"+(int)t.get(0), true, "Toolkit.enableFinerDebug");
  821. try{
  822. e.execute(cl/*,devnull*/);//HACKALERT
  823. }
  824. catch (org.apache.commons.exec.ExecuteException exc)
  825. {
  826. //Do nothing. Cmd steigt ja bei Error auch nicht aus
  827. //exc.printStackTrace();
  828. }
  829. Tools.DebugHelperPrint("fin", true, "Toolkit.enableFinerDebug");
  830. sil[(int)t.get(0)]=false;
  831. cG.setIsInCmd(false,(int)t.get(0));
  832. if(standalone)
  833. {
  834. if(gac.size()<=1)
  835. {
  836. System.exit(0);
  837. }
  838. else
  839. {
  840. gac.get(id).setVisible(false);
  841. gac.remove(id);
  842. }
  843. }
  844. }
  845. catch (ExecuteException exc)
  846. {
  847. exc.printStackTrace();
  848. }
  849. catch (IOException exc)
  850. {
  851. exc.printStackTrace();
  852. }
  853. Tools.DebugHelperPrint("FIN", true, "Toolkit.enableFinerDebug");
  854. //sil=false;
  855. }
  856. /**
  857. * runs a cmd in a specific tab
  858. * @param cmd the command to run
  859. * @param targetTab the tab in which it should run
  860. * @throws Error when the parameter is out od range (<0 or >4)
  861. * and exits the current console
  862. */
  863. public void runCmd(String cmd,int targetTab)
  864. {
  865. if(targetTab<0||targetTab>4)
  866. {
  867. Tools.DebugHelperPrint("xyxyx", true, "Toolkit.enableCoreDebug");
  868. gac.put(id,null);
  869. this.setVisible(false);
  870. this.dispose();
  871. throw new Error("The tabCount has to be >=0 and <=4");
  872. }
  873. tabSelected = targetTab;
  874. runCmd(cmd);
  875. updateTabBarMessages(targetTab);
  876. }
  877. /**
  878. * updates the shown lines
  879. * @param evt currently igged
  880. */
  881. public void refreshLines(java.awt.event.MouseEvent evt,int targetTab)
  882. {
  883. Tools.DebugHelperPrint("refreshAt|"+targetTab, true, "Toolkit.enableFinerDebug");
  884. Tools.DebugHelperPrint(js.getValue()+"", true, "Toolkit.enableFinerDebug");
  885. int os = js.getValue();
  886. RingBuffer<String> lb = screenBuf.get(targetTab);
  887. for(int i=0;i<line.length;i++)
  888. {
  889. JLabel linew = line[i];
  890. String tx = lb.getContentAt(os+i);
  891. linew.setText(tx);
  892. }
  893. //Surface.revalidate();
  894. //Surface.repaint();
  895. }
  896. /**
  897. * Adds a line to the Screen
  898. * @param cmd the line to add
  899. */
  900. public void addLine(String cmd,int targetTab)
  901. {
  902. Tools.DebugHelperPrint(cmd+"|"+targetTab, true, "Toolkit.enableFinerDebug");
  903. RingBuffer<String> lb = screenBuf.get(targetTab);
  904. lb.addItem(cmd);//CMD here
  905. if(currLin[targetTab]<5000)
  906. {
  907. currLin[targetTab]++;
  908. }
  909. int setLin;
  910. setLin=currLin[targetTab]-line.length;
  911. if(currLin[targetTab]<0)
  912. {
  913. setLin=0;
  914. }
  915. js.setValue(setLin);
  916. refreshLines(null,targetTab);
  917. /*
  918. if(linPos==line.length-1)
  919. {
  920. int ip = 1;
  921. for (int i = 1; i < line.length-1; i++)
  922. {
  923. line[i].setText(line[i+1].getText());
  924. ip=i;
  925. }
  926. line[ip].setText(cmd);
  927. }
  928. else
  929. {
  930. line[linPos].setText(cmd);
  931. linPos++;
  932. }*/
  933. }
  934. // public static void main(final String args[])
  935. // {
  936. // main2(args);
  937. // }
  938. /**
  939. * Main procedure for intenal use only
  940. * @param args The command lie args of this proggy
  941. */
  942. @SuppressWarnings({"CallToThreadDumpStack", "SleepWhileInLoop"})
  943. public static void main2(final String args[])//musste MethodenSig ändern wg final
  944. {
  945. //if(true)
  946. //{
  947. /*
  948. try
  949. {
  950. // File f = new File();
  951. System.err.println();
  952. }
  953. catch (URISyntaxException ex)
  954. {
  955. ex.printStackTrace();
  956. }
  957. return;*/
  958. //}
  959. new Thread(new Runnable()
  960. {
  961. @Override
  962. public void run()
  963. {
  964. final HashMap<Integer, Object> t = new HashMap<>();
  965. t.put(0, false);
  966. //final HashMap<Integer,Boolean> t = new HashMap<>();
  967. String cmd = "cmd";
  968. // boolean sa=false;
  969. if (args.length > 0)
  970. {
  971. Tools.DebugHelperPrint("1", true, "Toolkit.enableFinerDebug");
  972. if ((args[0].equals("--cmd")) || (args[0].equals("--standalone")))
  973. {
  974. Tools.DebugHelperPrint("12", true, "Toolkit.enableFinerDebug");
  975. //sa=false;
  976. if (args.length > 1)
  977. {
  978. Tools.DebugHelperPrint("123", true, "Toolkit.enableFinerDebug");
  979. t.put(3,true);
  980. cmd = args[1];
  981. }
  982. else
  983. {
  984. Tools.DebugHelperPrint("123e", true, "Toolkit.enableFinerDebug");
  985. t.put(3,true);
  986. cmd = "cmd";
  987. }
  988. }
  989. else
  990. {
  991. Tools.DebugHelperPrint("12e", true, "Toolkit.enableFinerDebug");
  992. t.put(3,false);
  993. }
  994. }
  995. else
  996. {
  997. Tools.DebugHelperPrint("1e", true, "Toolkit.enableFinerDebug");
  998. t.put(3,true);
  999. }
  1000. t.put(2, cmd);
  1001. /*
  1002. * Set the Nimbus look and feel
  1003. */
  1004. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  1005. /*
  1006. * If Nimbus (introduced in Java SE 6) is not available, stay
  1007. * with the
  1008. * default look and feel.
  1009. * For details see
  1010. * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  1011. */
  1012. try
  1013. {
  1014. Icon icon = new ImageIcon("C:/users/LH/Desktop/jp/GUI-File-CMD-IP-SLDR.png");
  1015. UIDefaults defaults = UIManager.getDefaults();
  1016. defaults.put("Slider.verticalThumbIcon", icon);
  1017. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
  1018. {
  1019. if ("Nimbus".equals(info.getName()))
  1020. {
  1021. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  1022. break;
  1023. }
  1024. }/*
  1025. * SynthLookAndFeel laf = new SynthLookAndFeel();
  1026. * laf.load(new File("SynthSlider.xml").toURI().toURL());
  1027. * javax.swing.UIManager.setLookAndFeel(laf);
  1028. */
  1029. }
  1030. catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException exc)
  1031. {/*
  1032. * IOException|java.net.MalformedURLException|
  1033. */
  1034. //java.util.logging.Logger.getLogger(cmdGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  1035. }
  1036. // Icon icon = new ImageIcon("C:/users/LH/Desktop/jp/GUI-File-CMD-IP-SLDR.png");
  1037. // UIDefaults defaults = UIManager.getLookAndFeelDefaults();
  1038. // defaults.put("Slider.verticalThumbIcon", icon);
  1039. // Slider.
  1040. //C:/users/LH/Desktop/jp/GUI-File-CMD-IP-SLDR.png
  1041. //</editor-fold>
  1042. /*
  1043. * Create and display the form
  1044. */
  1045. java.awt.EventQueue.invokeLater(new Runnable()
  1046. {
  1047. @Override
  1048. public void run()
  1049. {
  1050. cmdGUI g = new cmdGUI(new UIFileAccess(/**/de.nplusc.izc.tools.UIToolz.rsrc.UIFile.class));
  1051. //
  1052. /*Ü*//*new File("C:\\Users\\LH\\Desktop\\jp\\uiexamole\\ui.zip")));*/
  1053. g.setVisible(true);
  1054. if (((boolean) t.get(3)))
  1055. {
  1056. Tools.DebugHelperPrint("sacall2", true, "Toolkit.enableFinerDebug");
  1057. g.setStandalone(true);
  1058. }//V:HAXX
  1059. t.put(1, g);/*
  1060. * bsfin=true;
  1061. */
  1062. t.put(0, true);/*
  1063. * new Thread(new Runnable()
  1064. * {
  1065. * @Override
  1066. * public void run()
  1067. * {
  1068. *
  1069. *
  1070. * }
  1071. *
  1072. * }).start();
  1073. */
  1074. }
  1075. });//Dieser Häck funzt nur in main()!!!!!//VOID
  1076. while (!((boolean) t.get(0)))//Hack
  1077. {
  1078. try
  1079. {
  1080. Thread.sleep(50);
  1081. }
  1082. catch (InterruptedException exc)
  1083. {
  1084. exc.printStackTrace();
  1085. }
  1086. }
  1087. try //BUG-ALERT:HACK_USED
  1088. { //REQUIRED da sonst Deadlock...
  1089. //vermutlich ne Race-Condition...
  1090. //ergibt nämlich nen fetten Hänger...
  1091. Thread.sleep(500);
  1092. }
  1093. catch (InterruptedException exc)
  1094. {
  1095. exc.printStackTrace();
  1096. }
  1097. if (((boolean)t.get(3)))
  1098. {
  1099. Tools.DebugHelperPrint("sacall2", true, "Toolkit.enableFinerDebug");
  1100. // cmdGUI.cgui.runCmd(cmd);
  1101. ((cmdGUI) t.get(1)).runCmd((String)t.get(2));
  1102. }
  1103. }
  1104. }).start();
  1105. }
  1106. // Variables declaration - do not modify//GEN-BEGIN:variables
  1107. // End of variables declaration//GEN-END:variables
  1108. }