Simple single-color 8x8x8 LED Cube with AVRs
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

frame.java 21KB

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