Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

frame.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.event.*;
  5. import java.io.File;
  6. import com.sun.j3d.utils.universe.*;
  7. import com.sun.j3d.utils.geometry.*;
  8. import javax.media.j3d.*;
  9. import javax.vecmath.*;
  10. /*
  11. * frame.java
  12. *
  13. *
  14. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  15. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  16. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  17. *
  18. * This file is part of LED-Cube.
  19. *
  20. * LED-Cube is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation, either version 3 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * LED-Cube is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  32. */
  33. public class frame extends JFrame implements ListSelectionListener {
  34. // Anfang Variablen
  35. private GraphicsConfiguration gConfig = SimpleUniverse.getPreferredConfiguration();
  36. private Canvas3D cubeCanvas = new Canvas3D(gConfig);
  37. SimpleUniverse universe;
  38. Transform3D transform3d;
  39. TransformGroup transroot;
  40. BranchGroup branchgroup;
  41. // Anfang Attribute
  42. private JButton editA = new JButton();
  43. private JButton editB = new JButton();
  44. private JButton editC = new JButton();
  45. private JButton editD = new JButton();
  46. private JButton editE = new JButton();
  47. private JButton editF = new JButton();
  48. private JButton editG = new JButton();
  49. private JButton editH = new JButton();
  50. private DefaultListModel frameListModel = new DefaultListModel();
  51. private JList frameList = new JList();
  52. private JScrollPane frameListScrollPane = new JScrollPane(frameList);
  53. private JButton frameUp = new JButton();
  54. private JButton frameDown = new JButton();
  55. private JButton frameAdd = new JButton();
  56. private JButton frameRemove = new JButton();
  57. private JButton frameRename = new JButton();
  58. private JButton frame = new JButton();
  59. private JList animList = new JList();
  60. private DefaultListModel animModel = new DefaultListModel();
  61. private JScrollPane animScrollPane = new JScrollPane(animList);
  62. private JButton animUp = new JButton();
  63. private JButton animDown = new JButton();
  64. private JButton animAdd = new JButton();
  65. private JButton animRemove = new JButton();
  66. private JButton animRename = new JButton();
  67. private JTextField animPath = new JTextField();
  68. private JButton load = new JButton();
  69. private JButton save = new JButton();
  70. private JButton saveAs = new JButton();
  71. private JComboBox jComboBox1 = new JComboBox();
  72. private JButton upload = new JButton();
  73. private JButton download = new JButton();
  74. private JLabel jLabel4 = new JLabel();
  75. private JTextField frameRemaining = new JTextField();
  76. private JLabel frmLngthLbl = new JLabel();
  77. private JTextField frmLngthTxt = new JTextField();
  78. // Ende Attribute
  79. private cubeWorker worker = new cubeWorker();
  80. private boolean fileSelected = false;
  81. // Ende Variablen
  82. private int saveExitDialog() {
  83. String[] Optionen = {"Yes", "No"};
  84. int Auswahl = JOptionPane.showOptionDialog(this, "Do you want to save your changes?", "Save?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  85. if (Auswahl == JOptionPane.YES_OPTION) {
  86. return 1;
  87. } else {
  88. return 0;
  89. }
  90. }
  91. private String askString(String title, String text) {
  92. return JOptionPane.showInputDialog(null, text, title, JOptionPane.QUESTION_MESSAGE);
  93. }
  94. private void errorMessage(String s) {
  95. String[] Optionen = {"OK"};
  96. JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
  97. }
  98. public void valueChanged(ListSelectionEvent evt) {
  99. if ((!evt.getValueIsAdjusting()) && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
  100. int anim = animList.getSelectedIndex();
  101. int max;
  102. if (anim == -1){
  103. anim = 0;
  104. }
  105. if(evt.getSource() == frameList){
  106. max = worker.numOfAnimations();
  107. animModel.clear();
  108. } else {
  109. max = worker.numOfFrames(anim);
  110. frameListModel.clear();
  111. }
  112. // if value changed in anim, rebuild frame, else other way round
  113. for (int i = 0; i < max; i++) {
  114. if(evt.getSource() == animList){
  115. frameListModel.addElement(worker.getFrameName(anim, i));
  116. frameList.setModel(frameListModel);
  117. } else {
  118. animModel.addElement(worker.getAnimationName(i));
  119. animList.setModel(animModel);
  120. }
  121. }
  122. }
  123. }
  124. private void save() {
  125. if (fileSelected == false) {
  126. JFileChooser fc = new JFileChooser();
  127. int ret = fc.showSaveDialog(this);
  128. if (ret == JFileChooser.APPROVE_OPTION) {
  129. File file = fc.getSelectedFile();
  130. fileSelected = true;
  131. animPath.setText(file.getPath());
  132. worker.saveState(animPath.getText());
  133. }
  134. } else {
  135. worker.saveState(animPath.getText());
  136. }
  137. }
  138. public frame(String title) {
  139. // Frame-Initialisierung
  140. super(title);
  141. String[] sPorts = worker.getSerialPorts();
  142. for(int i = 0; i < sPorts.length; i++){
  143. jComboBox1.addItem(sPorts[i]);
  144. }
  145. for(int i = 0; i < worker.numOfAnimations(); i++){
  146. animModel.addElement(worker.getAnimationName(i));
  147. }
  148. addWindowListener(new WindowAdapter() {
  149. public void windowClosing(WindowEvent evt) {
  150. if (worker.changedStateSinceSave()) {
  151. if (saveExitDialog() == 1) {
  152. save();
  153. } else {
  154. return;
  155. }
  156. }
  157. System.exit(0);
  158. }
  159. });
  160. int frameWidth = 661;
  161. int frameHeight = 417;
  162. setSize(frameWidth, frameHeight);
  163. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  164. int x = (d.width - getSize().width) / 2;
  165. int y = (d.height - getSize().height) / 2 ;
  166. setLocation(x, y);
  167. Container cp = getContentPane();
  168. cp.setLayout(null);
  169. // Anfang Komponenten
  170. //----- 3D-----
  171. //-------------
  172. cubeCanvas.setBounds(8, 8, 250, 250);
  173. cp.add(cubeCanvas);
  174. ColorCube cube1 = new ColorCube(0.3);
  175. universe = new SimpleUniverse(cubeCanvas);
  176. universe.getViewingPlatform().setNominalViewingTransform();
  177. transform3d = new Transform3D();
  178. transroot = new TransformGroup(transform3d);
  179. transform3d.rotZ (Math.toRadians(30));
  180. transroot.addChild(cube1);
  181. transform3d.setTranslation(new Vector3d(2,2,2));
  182. branchgroup = new BranchGroup();
  183. branchgroup.addChild(transroot);
  184. universe.addBranchGraph(branchgroup);
  185. //-------------
  186. editA.setBounds(264, 8, 107, 25);
  187. editA.setText("Layer A");
  188. editA.setFont(new Font("Dialog", Font.PLAIN, 13));
  189. cp.add(editA);
  190. editA.addActionListener(new ActionListener() {
  191. public void actionPerformed(ActionEvent evt) {
  192. editA_ActionPerformed(evt);
  193. }
  194. });
  195. editB.setBounds(264, 40, 107, 25);
  196. editB.setText("Layer B");
  197. editB.setFont(new Font("Dialog", Font.PLAIN, 13));
  198. cp.add(editB);
  199. editB.addActionListener(new ActionListener() {
  200. public void actionPerformed(ActionEvent evt) {
  201. editB_ActionPerformed(evt);
  202. }
  203. });
  204. editC.setBounds(264, 72, 107, 25);
  205. editC.setText("Layer C");
  206. editC.setFont(new Font("Dialog", Font.PLAIN, 13));
  207. cp.add(editC);
  208. editC.addActionListener(new ActionListener() {
  209. public void actionPerformed(ActionEvent evt) {
  210. editC_ActionPerformed(evt);
  211. }
  212. });
  213. editD.setBounds(264, 104, 107, 25);
  214. editD.setText("Layer D");
  215. editD.setFont(new Font("Dialog", Font.PLAIN, 13));
  216. cp.add(editD);
  217. editD.addActionListener(new ActionListener() {
  218. public void actionPerformed(ActionEvent evt) {
  219. editD_ActionPerformed(evt);
  220. }
  221. });
  222. editE.setBounds(264, 136, 107, 25);
  223. editE.setText("Layer E");
  224. editE.setFont(new Font("Dialog", Font.PLAIN, 13));
  225. cp.add(editE);
  226. editE.addActionListener(new ActionListener() {
  227. public void actionPerformed(ActionEvent evt) {
  228. editE_ActionPerformed(evt);
  229. }
  230. });
  231. editF.setBounds(264, 168, 107, 25);
  232. editF.setText("Layer F");
  233. editF.setFont(new Font("Dialog", Font.PLAIN, 13));
  234. cp.add(editF);
  235. editF.addActionListener(new ActionListener() {
  236. public void actionPerformed(ActionEvent evt) {
  237. editF_ActionPerformed(evt);
  238. }
  239. });
  240. editG.setBounds(264, 200, 107, 25);
  241. editG.setText("Layer G");
  242. editG.setFont(new Font("Dialog", Font.PLAIN, 13));
  243. cp.add(editG);
  244. editG.addActionListener(new ActionListener() {
  245. public void actionPerformed(ActionEvent evt) {
  246. editG_ActionPerformed(evt);
  247. }
  248. });
  249. editH.setBounds(264, 232, 107, 25);
  250. editH.setText("Layer H");
  251. editH.setFont(new Font("Dialog", Font.PLAIN, 13));
  252. cp.add(editH);
  253. editH.addActionListener(new ActionListener() {
  254. public void actionPerformed(ActionEvent evt) {
  255. editH_ActionPerformed(evt);
  256. }
  257. });
  258. frameListScrollPane.setBounds(384, 8, 145, 249);
  259. frameList.setModel(frameListModel);
  260. //frameListModel.addElement();
  261. cp.add(frameListScrollPane);
  262. frameUp.setBounds(544, 8, 107, 28);
  263. frameUp.setText("Move up");
  264. frameUp.setFont(new Font("Dialog", Font.PLAIN, 13));
  265. cp.add(frameUp);
  266. frameUp.addActionListener(new ActionListener() {
  267. public void actionPerformed(ActionEvent evt) {
  268. frameUp_ActionPerformed(evt);
  269. }
  270. });
  271. frameDown.setBounds(544, 122, 107, 28);
  272. frameDown.setText("Move down");
  273. frameDown.setFont(new Font("Dialog", Font.PLAIN, 13));
  274. cp.add(frameDown);
  275. frameDown.addActionListener(new ActionListener() {
  276. public void actionPerformed(ActionEvent evt) {
  277. frameDown_ActionPerformed(evt);
  278. }
  279. });
  280. frameAdd.setBounds(544, 46, 107, 28);
  281. frameRename.setText("Rename");
  282. frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
  283. cp.add(frameRename);
  284. frameRename.addActionListener(new ActionListener() {
  285. public void actionPerformed(ActionEvent evt) {
  286. int a = animList.getSelectedIndex();
  287. if (a < 0) {
  288. errorMessage("Select an animation!");
  289. return;
  290. }
  291. int f = frameList.getSelectedIndex();
  292. if (f < 0) {
  293. errorMessage("Select a frame!");
  294. return;
  295. }
  296. worker.setFrameName(askString("Rename", "Rename " + frameList.getSelectedValue() + "?"), a, f);
  297. frameListModel.set(f, worker.getFrameName(a, f));
  298. frameList.setModel(frameListModel);
  299. }
  300. });
  301. frameAdd.setText("Add");
  302. frameAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
  303. cp.add(frameAdd);
  304. frameAdd.addActionListener(new ActionListener() {
  305. public void actionPerformed(ActionEvent evt) {
  306. frameAdd_ActionPerformed(evt);
  307. }
  308. });
  309. frameRemove.setBounds(544, 84, 107, 28);
  310. frameRemove.setBounds(544, 84, 107, 33);
  311. frameRemove.setText("Remove");
  312. frameRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
  313. cp.add(frameRemove);
  314. frameRemove.addActionListener(new ActionListener() {
  315. public void actionPerformed(ActionEvent evt) {
  316. frameRemove_ActionPerformed(evt);
  317. }
  318. });
  319. frmLngthLbl.setBounds(536, 160, 113, 24);
  320. frmLngthLbl.setText("Length of a frame");
  321. frmLngthLbl.setFont(new Font("Dialog", Font.PLAIN, 13));
  322. cp.add(frmLngthLbl);
  323. frmLngthTxt.setBounds(536, 184, 113, 24);
  324. frmLngthTxt.setText("0");
  325. frmLngthTxt.setFont(new Font("Dialog", Font.PLAIN, 13));
  326. cp.add(frmLngthTxt);
  327. animScrollPane.setBounds(8, 264, 209, 121);
  328. animList.setModel(animModel);
  329. //jList2Model.addElement("");
  330. cp.add(animScrollPane);
  331. animUp.setBounds(224, 264, 99, 25);
  332. animUp.setText("Move up");
  333. animUp.setFont(new Font("Dialog", Font.PLAIN, 13));
  334. cp.add(animUp);
  335. animUp.addActionListener(new ActionListener() {
  336. public void actionPerformed(ActionEvent evt) {
  337. animUp_ActionPerformed(evt);
  338. }
  339. });
  340. animDown.setBounds(224, 342, 99, 25);
  341. animDown.setText("Move down");
  342. animDown.setFont(new Font("Dialog", Font.PLAIN, 13));
  343. cp.add(animDown);
  344. animDown.addActionListener(new ActionListener() {
  345. public void actionPerformed(ActionEvent evt) {
  346. animDown_ActionPerformed(evt);
  347. }
  348. });
  349. animRename.setBounds(224, 368, 99, 25);
  350. animRename.setText("Rename");
  351. animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
  352. cp.add(animRename);
  353. animRename.addActionListener(new ActionListener() {
  354. public void actionPerformed(ActionEvent evt) {
  355. int a = animList.getSelectedIndex();
  356. if (a < 0) {
  357. errorMessage("Select an animation!");
  358. return;
  359. }
  360. worker.setAnimationName(askString("Rename", "Rename " + animList.getSelectedValue() + "?"), a);
  361. animModel.set(a, worker.getAnimationName(a));
  362. animList.setModel(animModel);
  363. }
  364. });
  365. animAdd.setBounds(224, 290, 99, 25);
  366. animAdd.setText("Add");
  367. animAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
  368. cp.add(animAdd);
  369. animAdd.addActionListener(new ActionListener() {
  370. public void actionPerformed(ActionEvent evt) {
  371. animAdd_ActionPerformed(evt);
  372. }
  373. });
  374. animRemove.setBounds(224, 316, 99, 25);
  375. animRemove.setText("Remove");
  376. animRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
  377. cp.add(animRemove);
  378. animRemove.addActionListener(new ActionListener() {
  379. public void actionPerformed(ActionEvent evt) {
  380. animRemove_ActionPerformed(evt);
  381. }
  382. });
  383. animPath.setBounds(344, 264, 305, 24);
  384. animPath.setEditable(false);
  385. animPath.setText("Load/Save an animation file...");
  386. animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
  387. cp.add(animPath);
  388. load.setBounds(344, 296, 100, 25);
  389. load.setText("Load");
  390. load.setFont(new Font("Dialog", Font.PLAIN, 13));
  391. cp.add(load);
  392. load.addActionListener(new ActionListener() {
  393. public void actionPerformed(ActionEvent evt) {
  394. load_ActionPerformed(evt);
  395. }
  396. });
  397. save.setBounds(454, 296, 100, 25);
  398. save.setText("Save");
  399. save.setFont(new Font("Dialog", Font.PLAIN, 13));
  400. cp.add(save);
  401. save.addActionListener(new ActionListener() {
  402. public void actionPerformed(ActionEvent evt) {
  403. save_ActionPerformed(evt);
  404. }
  405. });
  406. saveAs.setBounds(564, 296, 90, 25);
  407. saveAs.setText("Save As");
  408. saveAs.setFont(new Font("Dialog", Font.PLAIN, 13));
  409. cp.add(saveAs);
  410. saveAs.addActionListener(new ActionListener() {
  411. public void actionPerformed(ActionEvent evt) {
  412. saveAs_ActionPerformed(evt);
  413. }
  414. });
  415. jComboBox1.setBounds(344, 328, 305, 24);
  416. jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
  417. cp.add(jComboBox1);
  418. upload.setBounds(344, 360, 147, 25);
  419. upload.setText("Upload");
  420. upload.setFont(new Font("Dialog", Font.PLAIN, 13));
  421. cp.add(upload);
  422. upload.addActionListener(new ActionListener() {
  423. public void actionPerformed(ActionEvent evt) {
  424. upload_ActionPerformed(evt);
  425. }
  426. });
  427. download.setBounds(504, 360, 147, 25);
  428. download.setText("Download");
  429. download.setFont(new Font("Dialog", Font.PLAIN, 13));
  430. cp.add(download);
  431. download.addActionListener(new ActionListener() {
  432. public void actionPerformed(ActionEvent evt) {
  433. download_ActionPerformed(evt);
  434. }
  435. });
  436. jLabel4.setBounds(536, 208, 112, 20);
  437. jLabel4.setText("Remaining:");
  438. jLabel4.setFont(new Font("Dialog", Font.PLAIN, 13));
  439. cp.add(jLabel4);
  440. frameRemaining.setBounds(536, 232, 113, 24);
  441. frameRemaining.setEditable(false);
  442. frameRemaining.setText(String.valueOf(worker.framesRemaining()));
  443. frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
  444. cp.add(frameRemaining);
  445. animList.setFont(new Font("Dialog", Font.PLAIN, 13));
  446. frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
  447. // Ende Komponenten
  448. animList.addListSelectionListener(this);
  449. setResizable(false);
  450. setVisible(true);
  451. }
  452. // Anfang Methoden
  453. // Anfang Ereignisprozeduren
  454. public void editA_ActionPerformed(ActionEvent evt) {
  455. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 0, worker);
  456. }
  457. public void editB_ActionPerformed(ActionEvent evt) {
  458. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 1, worker);
  459. }
  460. public void editC_ActionPerformed(ActionEvent evt) {
  461. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 2, worker);
  462. }
  463. public void editD_ActionPerformed(ActionEvent evt) {
  464. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 3, worker);
  465. }
  466. public void editE_ActionPerformed(ActionEvent evt) {
  467. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 4, worker);
  468. }
  469. public void editF_ActionPerformed(ActionEvent evt) {
  470. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 5, worker);
  471. }
  472. public void editG_ActionPerformed(ActionEvent evt) {
  473. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 6, worker);
  474. }
  475. public void editH_ActionPerformed(ActionEvent evt) {
  476. layerEditFrame layerFrame1 = new layerEditFrame(animList.getSelectedIndex(), frameList.getSelectedIndex(), 7, worker);
  477. }
  478. public void frameUp_ActionPerformed(ActionEvent evt) {
  479. int i = frameList.getSelectedIndex();
  480. if ((i > 0) && (frameListModel.getSize() >= 2)) {
  481. Object tmp = frameListModel.get(i);
  482. frameListModel.set(i, frameListModel.get(i - 1));
  483. frameListModel.set(i - 1, tmp);
  484. frameList.setSelectedIndex(i - 1);
  485. worker.moveFrame(worker.UP, animList.getSelectedIndex(), frameList.getSelectedIndex());
  486. }
  487. }
  488. public void frameDown_ActionPerformed(ActionEvent evt) {
  489. int i = frameList.getSelectedIndex();
  490. if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
  491. Object tmp = frameListModel.get(i);
  492. frameListModel.set(i, frameListModel.get(i + 1));
  493. frameListModel.set(i + 1, tmp);
  494. frameList.setSelectedIndex(i + 1);
  495. worker.moveFrame(worker.DOWN, animList.getSelectedIndex(), frameList.getSelectedIndex());
  496. }
  497. }
  498. public void frameAdd_ActionPerformed(ActionEvent evt) {
  499. if(animList.getSelectedIndex() == -1){
  500. errorMessage("Please select an animation!");
  501. } else {
  502. worker.addFrame(animList.getSelectedIndex());
  503. frameRemaining.setText(Integer.toString(worker.framesRemaining()));
  504. int n = worker.numOfFrames(animList.getSelectedIndex()) - 1;
  505. if (n < 0) {
  506. n = 0;
  507. }
  508. frameListModel.add(n, worker.getFrameName(animList.getSelectedIndex(), n));
  509. frameList.setModel(frameListModel);
  510. }
  511. }
  512. public void frameRemove_ActionPerformed(ActionEvent evt) {
  513. worker.removeFrame(animList.getSelectedIndex(), frameList.getSelectedIndex());
  514. frameRemaining.setText(Integer.toString(worker.framesRemaining()));
  515. frameListModel.removeElementAt(frameList.getSelectedIndex());
  516. frameList.setModel(frameListModel);
  517. }
  518. public void animUp_ActionPerformed(ActionEvent evt) {
  519. int i = animList.getSelectedIndex();
  520. if ((i > 0) && (animModel.getSize() >= 2)) {
  521. Object tmp = animModel.get(i);
  522. animModel.set(i, animModel.get(i - 1));
  523. animModel.set(i - 1, tmp);
  524. animList.setSelectedIndex(i - 1);
  525. worker.moveAnimation(worker.UP, animList.getSelectedIndex());
  526. }
  527. }
  528. public void animDown_ActionPerformed(ActionEvent evt) {
  529. int i = animList.getSelectedIndex();
  530. if ((i >= 0) && (animModel.getSize() >= 2) && (i < (animModel.getSize() - 1))) {
  531. Object tmp = animModel.get(i);
  532. animModel.set(i, animModel.get(i + 1));
  533. animModel.set(i + 1, tmp);
  534. animList.setSelectedIndex(i + 1);
  535. worker.moveAnimation(worker.DOWN, animList.getSelectedIndex());
  536. }
  537. }
  538. public void animAdd_ActionPerformed(ActionEvent evt) {
  539. if(worker.addAnimation() == -1){
  540. errorMessage("Could not add animation!");
  541. } else {
  542. int n = worker.numOfAnimations() - 1;
  543. // would have 0 anims after successfully adding one...
  544. /*if (n < 0) {
  545. n = 0;
  546. }*/
  547. animModel.clear();
  548. for (int i = 0; i < (n + 1); i++) {
  549. animModel.add(i, worker.getAnimationName(i));
  550. }
  551. animList.setModel(animModel);
  552. }
  553. }
  554. public void animRemove_ActionPerformed(ActionEvent evt) {
  555. worker.removeAnimation(animList.getSelectedIndex());
  556. animModel.removeElementAt(animList.getSelectedIndex());
  557. animList.setModel(animModel);
  558. }
  559. public void load_ActionPerformed(ActionEvent evt) {
  560. JFileChooser fc = new JFileChooser();
  561. int ret = fc.showOpenDialog(this);
  562. if (ret == JFileChooser.APPROVE_OPTION) {
  563. File file = fc.getSelectedFile();
  564. if (fileSelected == false) {
  565. fileSelected = true;
  566. }
  567. animPath.setText(file.getPath());
  568. worker.loadState(animPath.getText());
  569. animModel.clear();
  570. for (int i = 0; i < worker.numOfAnimations(); i++) {
  571. animModel.addElement(worker.getAnimationName(i));
  572. }
  573. animList.setModel(animModel);
  574. frameListModel.clear();
  575. frameList.setModel(frameListModel);
  576. }
  577. }
  578. public void save_ActionPerformed(ActionEvent evt) {
  579. if (fileSelected == false) {
  580. JFileChooser fc = new JFileChooser();
  581. int ret = fc.showSaveDialog(this);
  582. if (ret == JFileChooser.APPROVE_OPTION) {
  583. File file = fc.getSelectedFile();
  584. fileSelected = true;
  585. animPath.setText(file.getPath());
  586. worker.saveState(animPath.getText());
  587. }
  588. } else {
  589. worker.saveState(animPath.getText());
  590. }
  591. }
  592. public void saveAs_ActionPerformed(ActionEvent evt) {
  593. JFileChooser fc;
  594. if (fileSelected == true) {
  595. fc = new JFileChooser(new File(animPath.getText()).getParentFile());
  596. } else {
  597. fc = new JFileChooser();
  598. }
  599. int ret = fc.showSaveDialog(this);
  600. if (ret == JFileChooser.APPROVE_OPTION) {
  601. File file = fc.getSelectedFile();
  602. if (fileSelected == false) {
  603. fileSelected = true;
  604. }
  605. animPath.setText(file.getPath());
  606. worker.saveState(animPath.getText());
  607. }
  608. }
  609. public void upload_ActionPerformed(ActionEvent evt) {
  610. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  611. errorMessage("No serial port selected...");
  612. } else {
  613. worker.uploadState((String)jComboBox1.getSelectedItem());
  614. }
  615. }
  616. public void download_ActionPerformed(ActionEvent evt) {
  617. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  618. errorMessage("No serial port selected...");
  619. } else {
  620. worker.downloadState((String)jComboBox1.getSelectedItem());
  621. }
  622. }
  623. // Ende Ereignisprozeduren
  624. public static void main(String[] args) {
  625. new frame("Cube Control");
  626. }
  627. // Ende Methoden
  628. }