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

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