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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. /**
  5. *
  6. * Beschreibung
  7. *
  8. * @version 1.0 vom 14.11.2011
  9. * @author
  10. */
  11. public class frame extends JFrame {
  12. // Anfang Variablen
  13. private Canvas cubeCanvas = new Canvas();
  14. private JButton editA = new JButton();
  15. private JButton editB = new JButton();
  16. private JButton editC = new JButton();
  17. private JButton editD = new JButton();
  18. private JButton editE = new JButton();
  19. private JButton editF = new JButton();
  20. private JButton editG = new JButton();
  21. private JButton editH = new JButton();
  22. private DefaultListModel frameListModel = new DefaultListModel();
  23. private JList frameList = new JList(frameListModel);
  24. private JButton frameUp = new JButton();
  25. private JButton frameDown = new JButton();
  26. private JButton frameAdd = new JButton();
  27. private JButton frameRemove = new JButton();
  28. private DefaultListModel animationListModel = new DefaultListModel();
  29. private JList jList2 = new JList(animationListModel);
  30. private JButton animUp = new JButton();
  31. private JButton animDown = new JButton();
  32. private JButton animAdd = new JButton();
  33. private JButton animRemove = new JButton();
  34. private JTextField animPath = new JTextField();
  35. private JButton load = new JButton();
  36. private JButton save = new JButton();
  37. private String[] jComboBox1Daten = {"Select serial port..."};
  38. private JComboBox jComboBox1 = new JComboBox(jComboBox1Daten);
  39. private JButton upload = new JButton();
  40. private JButton download = new JButton();
  41. private JLabel jLabel4 = new JLabel();
  42. private JTextField frameRemaining = new JTextField();
  43. private cubeWorker worker = new cubeWorker();
  44. // Ende Variablen
  45. private int saveExitDialog() {
  46. String[] Optionen = {"Yes", "No"};
  47. int Auswahl = JOptionPane.showOptionDialog(this, "Save?", "Yes/No", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Optionen, Optionen[0]);
  48. if (Auswahl == JOptionPane.YES_OPTION) {
  49. worker.saveState(animPath.getText());
  50. return 1;
  51. } else {
  52. return 0;
  53. }
  54. }
  55. public frame(String title) {
  56. // Frame-Initialisierung
  57. super(title);
  58. frameListModel.add(0, "Frame 1");
  59. frameListModel.add(1, "Frame 2");
  60. frameListModel.add(2, "Frame 3");
  61. animationListModel.add(0, "Animation 1");
  62. animationListModel.add(1, "Animation 2");
  63. animationListModel.add(2, "Animation 3");
  64. addWindowListener(new WindowAdapter() {
  65. public void windowClosing(WindowEvent evt) {
  66. if (worker.changedStateSinceSave()) {
  67. saveExitDialog();
  68. }
  69. System.exit(0);
  70. }
  71. });
  72. int frameWidth = 662;
  73. int frameHeight = 416;
  74. setSize(frameWidth, frameHeight);
  75. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  76. int x = (d.width - getSize().width) / 2;
  77. int y = (d.height - getSize().height) / 2 ;
  78. setLocation(x, y);
  79. Container cp = getContentPane();
  80. cp.setLayout(null);
  81. // Anfang Komponenten
  82. cubeCanvas.setBounds(8, 8, 250, 250);
  83. cubeCanvas.setBackground(Color.GRAY);
  84. cp.add(cubeCanvas);
  85. editA.setBounds(264, 8, 107, 25);
  86. editA.setText("Layer A");
  87. cp.add(editA);
  88. editA.addActionListener(new ActionListener() {
  89. public void actionPerformed(ActionEvent evt) {
  90. editAActionPerformed(evt);
  91. }
  92. });
  93. editB.setBounds(264, 40, 107, 25);
  94. editB.setText("Layer B");
  95. cp.add(editB);
  96. editB.addActionListener(new ActionListener() {
  97. public void actionPerformed(ActionEvent evt) {
  98. editBActionPerformed(evt);
  99. }
  100. });
  101. editC.setBounds(264, 72, 107, 25);
  102. editC.setText("Layer C");
  103. cp.add(editC);
  104. editC.addActionListener(new ActionListener() {
  105. public void actionPerformed(ActionEvent evt) {
  106. editCActionPerformed(evt);
  107. }
  108. });
  109. editD.setBounds(264, 104, 107, 25);
  110. editD.setText("Layer D");
  111. cp.add(editD);
  112. editD.addActionListener(new ActionListener() {
  113. public void actionPerformed(ActionEvent evt) {
  114. editDActionPerformed(evt);
  115. }
  116. });
  117. editE.setBounds(264, 136, 107, 25);
  118. editE.setText("Layer E");
  119. cp.add(editE);
  120. editE.addActionListener(new ActionListener() {
  121. public void actionPerformed(ActionEvent evt) {
  122. editEActionPerformed(evt);
  123. }
  124. });
  125. editF.setBounds(264, 168, 107, 25);
  126. editF.setText("Layer F");
  127. cp.add(editF);
  128. editF.addActionListener(new ActionListener() {
  129. public void actionPerformed(ActionEvent evt) {
  130. editFActionPerformed(evt);
  131. }
  132. });
  133. editG.setBounds(264, 200, 107, 25);
  134. editG.setText("Layer G");
  135. cp.add(editG);
  136. editG.addActionListener(new ActionListener() {
  137. public void actionPerformed(ActionEvent evt) {
  138. editGActionPerformed(evt);
  139. }
  140. });
  141. editH.setBounds(264, 232, 107, 25);
  142. editH.setText("Layer H");
  143. cp.add(editH);
  144. editH.addActionListener(new ActionListener() {
  145. public void actionPerformed(ActionEvent evt) {
  146. editHActionPerformed(evt);
  147. }
  148. });
  149. frameList.setBounds(384, 8, 145, 249);
  150. cp.add(frameList);
  151. frameUp.setBounds(544, 8, 107, 33);
  152. frameUp.setText("Move up");
  153. cp.add(frameUp);
  154. frameUp.addActionListener(new ActionListener() {
  155. public void actionPerformed(ActionEvent evt) {
  156. frameUpActionPerformed(evt);
  157. }
  158. });
  159. frameDown.setBounds(544, 152, 107, 33);
  160. frameDown.setText("Move down");
  161. cp.add(frameDown);
  162. frameDown.addActionListener(new ActionListener() {
  163. public void actionPerformed(ActionEvent evt) {
  164. frameDownActionPerformed(evt);
  165. }
  166. });
  167. frameAdd.setBounds(544, 56, 107, 33);
  168. frameAdd.setText("Add");
  169. cp.add(frameAdd);
  170. frameAdd.addActionListener(new ActionListener() {
  171. public void actionPerformed(ActionEvent evt) {
  172. frameAddActionPerformed(evt);
  173. }
  174. });
  175. frameRemove.setBounds(544, 104, 107, 33);
  176. frameRemove.setText("Remove");
  177. cp.add(frameRemove);
  178. frameRemove.addActionListener(new ActionListener() {
  179. public void actionPerformed(ActionEvent evt) {
  180. frameRemoveActionPerformed(evt);
  181. }
  182. });
  183. jList2.setBounds(8, 264, 209, 121);
  184. cp.add(jList2);
  185. animUp.setBounds(224, 264, 99, 25);
  186. animUp.setText("Move up");
  187. cp.add(animUp);
  188. animUp.addActionListener(new ActionListener() {
  189. public void actionPerformed(ActionEvent evt) {
  190. animUpActionPerformed(evt);
  191. }
  192. });
  193. animDown.setBounds(224, 360, 99, 25);
  194. animDown.setText("Move down");
  195. cp.add(animDown);
  196. animDown.addActionListener(new ActionListener() {
  197. public void actionPerformed(ActionEvent evt) {
  198. animDownActionPerformed(evt);
  199. }
  200. });
  201. animAdd.setBounds(224, 296, 99, 25);
  202. animAdd.setText("Add");
  203. cp.add(animAdd);
  204. animAdd.addActionListener(new ActionListener() {
  205. public void actionPerformed(ActionEvent evt) {
  206. animAddActionPerformed(evt);
  207. }
  208. });
  209. animRemove.setBounds(224, 328, 99, 25);
  210. animRemove.setText("Remove");
  211. cp.add(animRemove);
  212. animRemove.addActionListener(new ActionListener() {
  213. public void actionPerformed(ActionEvent evt) {
  214. animRemoveActionPerformed(evt);
  215. }
  216. });
  217. animPath.setBounds(344, 264, 305, 24);
  218. animPath.setEditable(false);
  219. animPath.setText("Load/Save an animation file...");
  220. cp.add(animPath);
  221. load.setBounds(344, 296, 147, 25);
  222. load.setText("Load");
  223. cp.add(load);
  224. load.addActionListener(new ActionListener() {
  225. public void actionPerformed(ActionEvent evt) {
  226. loadActionPerformed(evt);
  227. }
  228. });
  229. save.setBounds(504, 296, 147, 25);
  230. save.setText("Save");
  231. cp.add(save);
  232. save.addActionListener(new ActionListener() {
  233. public void actionPerformed(ActionEvent evt) {
  234. saveActionPerformed(evt);
  235. }
  236. });
  237. jComboBox1.setBounds(344, 328, 305, 24);
  238. cp.add(jComboBox1);
  239. upload.setBounds(344, 360, 147, 25);
  240. upload.setText("Upload");
  241. cp.add(upload);
  242. upload.addActionListener(new ActionListener() {
  243. public void actionPerformed(ActionEvent evt) {
  244. uploadActionPerformed(evt);
  245. }
  246. });
  247. download.setBounds(504, 360, 147, 25);
  248. download.setText("Download");
  249. cp.add(download);
  250. download.addActionListener(new ActionListener() {
  251. public void actionPerformed(ActionEvent evt) {
  252. downloadActionPerformed(evt);
  253. }
  254. });
  255. jLabel4.setBounds(536, 208, 111, 16);
  256. jLabel4.setText("Frames remaining:");
  257. jLabel4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
  258. cp.add(jLabel4);
  259. frameRemaining.setBounds(536, 232, 113, 24);
  260. frameRemaining.setEditable(false);
  261. frameRemaining.setText("2048");
  262. cp.add(frameRemaining);
  263. // Ende Komponenten
  264. setResizable(false);
  265. setVisible(true);
  266. }
  267. // Anfang Ereignisprozeduren
  268. public void editAActionPerformed(ActionEvent evt) {
  269. }
  270. public void editBActionPerformed(ActionEvent evt) {
  271. }
  272. public void editCActionPerformed(ActionEvent evt) {
  273. }
  274. public void editDActionPerformed(ActionEvent evt) {
  275. }
  276. public void editEActionPerformed(ActionEvent evt) {
  277. }
  278. public void editFActionPerformed(ActionEvent evt) {
  279. }
  280. public void editGActionPerformed(ActionEvent evt) {
  281. }
  282. public void editHActionPerformed(ActionEvent evt) {
  283. }
  284. public void frameUpActionPerformed(ActionEvent evt) {
  285. int i = frameList.getSelectedIndex();
  286. if ((i > 0) && (frameListModel.getSize() >= 2)) {
  287. Object tmp = frameListModel.get(i);
  288. frameListModel.set(i, frameListModel.get(i - 1));
  289. frameListModel.set(i - 1, tmp);
  290. frameList.setSelectedIndex(i - 1);
  291. }
  292. }
  293. public void frameDownActionPerformed(ActionEvent evt) {
  294. int i = frameList.getSelectedIndex();
  295. if ((i >= 0) && (frameListModel.getSize() >= 2) && (i < (frameListModel.getSize() - 1))) {
  296. Object tmp = frameListModel.get(i);
  297. frameListModel.set(i, frameListModel.get(i + 1));
  298. frameListModel.set(i + 1, tmp);
  299. frameList.setSelectedIndex(i + 1);
  300. }
  301. }
  302. public void frameAddActionPerformed(ActionEvent evt) {
  303. }
  304. public void frameRemoveActionPerformed(ActionEvent evt) {
  305. }
  306. public void animUpActionPerformed(ActionEvent evt) {
  307. int i = jList2.getSelectedIndex();
  308. if ((i > 0) && (animationListModel.getSize() >= 2)) {
  309. Object tmp = animationListModel.get(i);
  310. animationListModel.set(i, animationListModel.get(i - 1));
  311. animationListModel.set(i - 1, tmp);
  312. jList2.setSelectedIndex(i - 1);
  313. }
  314. }
  315. public void animDownActionPerformed(ActionEvent evt) {
  316. int i = jList2.getSelectedIndex();
  317. if ((i >= 0) && (animationListModel.getSize() >= 2) && (i < (animationListModel.getSize() - 1))) {
  318. Object tmp = animationListModel.get(i);
  319. animationListModel.set(i, animationListModel.get(i + 1));
  320. animationListModel.set(i + 1, tmp);
  321. jList2.setSelectedIndex(i + 1);
  322. }
  323. }
  324. public void animAddActionPerformed(ActionEvent evt) {
  325. }
  326. public void animRemoveActionPerformed(ActionEvent evt) {
  327. }
  328. public void loadActionPerformed(ActionEvent evt) {
  329. }
  330. public void saveActionPerformed(ActionEvent evt) {
  331. }
  332. public void uploadActionPerformed(ActionEvent evt) {
  333. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  334. JOptionPane.showMessageDialog(this, "No serial port selected...");
  335. } else {
  336. worker.uploadState((String)jComboBox1.getSelectedItem());
  337. }
  338. }
  339. public void downloadActionPerformed(ActionEvent evt) {
  340. if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
  341. JOptionPane.showMessageDialog(this, "No serial port selected...");
  342. } else {
  343. worker.downloadState((String)jComboBox1.getSelectedItem());
  344. }
  345. }
  346. // Ende Ereignisprozeduren
  347. public static void main(String[] args) {
  348. new frame("Cube Control");
  349. }
  350. }