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

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