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 23KB

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