123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083 |
- /*
- * Frame.java
- *
- *
- * Copyright 2011 Thomas Buck <xythobuz@me.com>
- * Copyright 2011 Max Nuding <max.nuding@gmail.com>
- * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
- *
- * This file is part of LED-Cube.
- *
- * LED-Cube is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * LED-Cube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
- */
- import com.sun.j3d.utils.universe.*;
- import javax.media.j3d.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- import java.io.File;
-
- public class Frame extends JFrame implements ListSelectionListener {
-
- private static final long serialVersionUID = 23421337L;
- // Anfang Variablen
- private GraphicsConfiguration gConfig = SimpleUniverse
- .getPreferredConfiguration();
- private Canvas3D cubeCanvas = new Canvas3D(gConfig);
- public Led3D ledView = new Led3D(cubeCanvas);
-
- // Anfang Attribute
- private JButton editA = new JButton();
- private JButton editB = new JButton();
- private JButton editC = new JButton();
- private JButton editD = new JButton();
- private JButton editE = new JButton();
- private JButton editF = new JButton();
- private JButton editG = new JButton();
- private JButton editH = new JButton();
- private DefaultListModel frameListModel = new DefaultListModel();
- public JList frameList = new JList();
- private JScrollPane frameListScrollPane = new JScrollPane(frameList);
- private JButton frameUp = new JButton();
- private JButton frameDown = new JButton();
- private JButton frameAdd = new JButton();
- private JButton frameRemove = new JButton();
- private JButton frameRename = new JButton();
- private JList animList = new JList();
- private DefaultListModel animModel = new DefaultListModel();
- private JScrollPane animScrollPane = new JScrollPane(animList);
- private JButton animUp = new JButton();
- private JButton animDown = new JButton();
- private JButton animAdd = new JButton();
- private JButton animRemove = new JButton();
- private JButton animRename = new JButton();
- private JTextField animPath = new JTextField();
- private JButton load = new JButton();
- private JButton save = new JButton();
- private JButton saveAs = new JButton();
- public JComboBox jComboBox1 = new JComboBox();
- private JButton upload = new JButton();
- private JButton download = new JButton();
- private JLabel jLabel4 = new JLabel();
- private JTextField frameRemaining = new JTextField();
- private JLabel frameLengthLabel = new JLabel();
- private JTextField frameLengthText = new JTextField();
- private JButton frameDuration = new JButton();
- private JButton fullScreenButton = new JButton();
- private JButton playAnimation = new JButton();
- private JButton exitButton;
- private JButton playAnimationFullscreen = new JButton();
- // Ende Attribute
-
- public cubeWorker worker = new cubeWorker(this);
- private boolean fileSelected = false;
-
- // Ende Variablen
-
- private int saveExitDialog() {
- String[] Optionen = { "Yes", "No" };
- int Auswahl = JOptionPane.showOptionDialog(this,
- "Do you want to save your changes?", "Save?",
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
- Optionen, Optionen[0]);
- if (Auswahl == JOptionPane.YES_OPTION) {
- return 1;
- } else {
- return 0;
- }
- }
-
- public String askString(String title, String text) {
- return JOptionPane.showInputDialog(null, text, title,
- JOptionPane.QUESTION_MESSAGE);
- }
-
- public void errorMessage(String s) {
- String[] Optionen = { "OK" };
- JOptionPane.showOptionDialog(this, s, "Error!", JOptionPane.YES_OPTION,
- JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
- }
-
- public void errorMessage(String title, String msg) {
- String[] Optionen = { "OK" };
- JOptionPane.showOptionDialog(this, msg, title, JOptionPane.YES_OPTION,
- JOptionPane.ERROR_MESSAGE, null, Optionen, Optionen[0]);
- }
-
- public void valueChanged(ListSelectionEvent evt) {
- if ((!evt.getValueIsAdjusting())
- && ((evt.getSource() == animList) || (evt.getSource() == frameList))) {
- // If animList or framsList is the source, we act...
-
- if ((evt.getSource() == animList)
- && (animList.getSelectedIndex() != -1)) {
- // animList selection changed, update frameList
- frameListModel.clear();
- for (int i = 0; i < worker.numOfFrames(animList
- .getSelectedIndex()); i++) {
- // Offending statement:
- // worker.numOfFrames(animList.getSelectedIndex())
- frameListModel.addElement(worker.getFrameName(
- animList.getSelectedIndex(), i));
- }
- frameList.setModel(frameListModel);
- }
-
- // If both selections are valid, update Frame duration and set 3D
- // data
- if ((animList.getSelectedIndex() != -1)
- && (frameList.getSelectedIndex() != -1)) {
- ledView.setData(worker.getFrame(animList.getSelectedIndex(),
- frameList.getSelectedIndex()));
- frameLengthText.setText(Integer.toString(worker.getFrameTime(
- animList.getSelectedIndex(),
- frameList.getSelectedIndex())));
- } else {
- // clear Frame duration
- frameLengthText.setText("");
- }
- }
- }
-
- private void save() {
- if (fileSelected == false) {
- JFileChooser fc = new JFileChooser();
- int ret = fc.showSaveDialog(this);
- if (ret == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- fileSelected = true;
- animPath.setText(file.getPath());
- worker.saveState(animPath.getText());
- }
- } else {
- worker.saveState(animPath.getText());
- }
- }
-
- public Frame(String title) {
- // Frame-Initialisierung
- super(title);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- String[] sPorts = worker.getSerialPorts();
- for (int i = 0; i < sPorts.length; i++) {
- jComboBox1.addItem(sPorts[i]);
- }
-
- for (int i = 0; i < worker.numOfAnimations(); i++) {
- animModel.addElement(worker.getAnimationName(i));
- }
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent evt) {
- if (worker.changedStateSinceSave()) {
- if (saveExitDialog() == 1) {
- save();
- } else {
- return;
- }
- }
- System.exit(0);
- }
- });
- int frameWidth = 661;
- int frameHeight = 440;
- setSize(frameWidth, frameHeight);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- int x = (d.width - getSize().width) / 2;
- int y = (d.height - getSize().height) / 2;
- setLocation(x, y);
- Container cp = getContentPane();
- cp.setLayout(null);
- // Anfang Komponenten
-
- // ----- 3D-----
- // -------------
- cubeCanvas.setBounds(8, 8, 250, 250);
- cp.add(cubeCanvas);
-
- // -------------
-
- editA.setBounds(264, 8, 107, 25);
- editA.setText("Layer A");
- editA.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editA);
- editA.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editA_ActionPerformed(evt);
- }
- });
-
- editB.setBounds(264, 40, 107, 25);
- editB.setText("Layer B");
- editB.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editB);
- editB.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editB_ActionPerformed(evt);
- }
- });
-
- editC.setBounds(264, 72, 107, 25);
- editC.setText("Layer C");
- editC.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editC);
- editC.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editC_ActionPerformed(evt);
- }
- });
-
- editD.setBounds(264, 104, 107, 25);
- editD.setText("Layer D");
- editD.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editD);
- editD.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editD_ActionPerformed(evt);
- }
- });
-
- editE.setBounds(264, 136, 107, 25);
- editE.setText("Layer E");
- editE.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editE);
- editE.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editE_ActionPerformed(evt);
- }
- });
-
- editF.setBounds(264, 168, 107, 25);
- editF.setText("Layer F");
- editF.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editF);
- editF.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editF_ActionPerformed(evt);
- }
- });
-
- editG.setBounds(264, 200, 107, 25);
- editG.setText("Layer G");
- editG.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editG);
- editG.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editG_ActionPerformed(evt);
- }
- });
-
- editH.setBounds(264, 232, 107, 25);
- editH.setText("Layer H");
- editH.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(editH);
- editH.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- editH_ActionPerformed(evt);
- }
- });
-
- frameListScrollPane.setBounds(384, 8, 145, 249);
- frameList.setModel(frameListModel);
- cp.add(frameListScrollPane);
-
- frameUp.setBounds(544, 8, 107, 28);
- frameUp.setText("Move up");
- frameUp.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameUp);
- frameUp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- frameUp_ActionPerformed(evt);
- }
- });
-
- frameAdd.setBounds(544, 39, 107, 28);
- frameAdd.setText("Add");
- frameAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameAdd);
- frameAdd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- frameAdd_ActionPerformed(evt);
- }
- });
-
- frameRemove.setBounds(544, 70, 107, 28);
- frameRemove.setText("Remove");
- frameRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameRemove);
- frameRemove.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- frameRemove_ActionPerformed(evt);
- }
- });
-
- frameRename.setBounds(544, 101, 107, 28);
- frameRename.setText("Rename");
- frameRename.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameRename);
- frameRename.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- int a = animList.getSelectedIndex();
- if (a < 0) {
- errorMessage("Select an animation!");
- return;
- }
- int f = frameList.getSelectedIndex();
- if (f < 0) {
- errorMessage("Select a Frame!");
- return;
- }
- worker.setFrameName(
- askString("Rename",
- "Rename " + frameList.getSelectedValue() + "?"),
- a, f);
- frameListModel.set(f, worker.getFrameName(a, f));
- frameList.setModel(frameListModel);
- }
- });
-
- frameDown.setBounds(544, 132, 107, 28);
- frameDown.setText("Move down");
- frameDown.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameDown);
- frameDown.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- frameDown_ActionPerformed(evt);
- }
- });
-
- frameLengthLabel.setBounds(536, 160, 113, 24);
- frameLengthLabel.setText("Time (1/24 sec)");
- frameLengthLabel.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameLengthLabel);
-
- frameLengthText.setBounds(536, 184, 50, 24);
- frameLengthText.setText("");
- frameLengthText.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameLengthText);
-
- fullScreenButton.setText("Fullscreen");
- fullScreenButton.setBounds(504, 390, 147, 25);
- fullScreenButton.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(fullScreenButton);
- fullScreenButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- enterFullscreen(evt);
- }
- });
-
- exitButton = new JButton("Exit Fullscreen");
- exitButton.setBounds(Toolkit.getDefaultToolkit().getScreenSize().width-150, Toolkit.getDefaultToolkit().getScreenSize().height-80, 150, 25);
- cp.add(exitButton);
- exitButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- exitFullscreen();
- }
- });
-
-
- playAnimation.setText("Play");
- playAnimation.setBounds(344, 390, 147, 25);
- playAnimation.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(playAnimation);
- playAnimation.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt){
- playAnimation(evt);
- }
- });
-
- playAnimationFullscreen.setText("Play");
- playAnimationFullscreen.setBounds(Toolkit.getDefaultToolkit().getScreenSize().width-310, Toolkit.getDefaultToolkit().getScreenSize().height-80, 150, 25);
- playAnimationFullscreen.setFont(new Font("Dialog", Font.PLAIN, 13));
- playAnimationFullscreen.setVisible(false);
- cp.add(playAnimationFullscreen);
- playAnimationFullscreen.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt){
- playAnimation(evt);
- }
- });
-
-
- frameDuration.setBounds(590, 184, 60, 24);
- frameDuration.setText("OK");
- frameDuration.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameDuration);
- frameDuration.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- if (frameLengthText.getText().equals("0")) {
- errorMessage("0 is not a valid value!");
- frameLengthText.setText("1");
- } else if (Integer.parseInt(frameLengthText.getText()) > 256) {
- errorMessage("Value too high. Max: 256");
- frameLengthText.setText("256");
- return;
- } else {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation!");
- return;
- }
- if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame!");
- return;
- }
- worker.setFrameTime(
- (byte) (Integer.parseInt(frameLengthText.getText()) - 1),
- animList.getSelectedIndex(),
- frameList.getSelectedIndex());
- }
- }
- });
-
-
- animScrollPane.setBounds(8, 264, 209, 121);
- animList.setModel(animModel);
- cp.add(animScrollPane);
-
- animUp.setBounds(224, 264, 99, 25);
- animUp.setText("Move up");
- animUp.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animUp);
- animUp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- animUp_ActionPerformed(evt);
- }
- });
-
- animDown.setBounds(224, 368, 99, 25);
- animDown.setText("Move down");
- animDown.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animDown);
- animDown.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- animDown_ActionPerformed(evt);
- }
- });
-
- animRename.setBounds(224, 342, 99, 25);
- animRename.setText("Rename");
- animRename.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animRename);
- animRename.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- int a = animList.getSelectedIndex();
- if (a < 0) {
- errorMessage("Select an animation!");
- return;
- }
- worker.setAnimationName(
- askString("Rename",
- "Rename " + animList.getSelectedValue() + "?"),
- a);
- animModel.set(a, worker.getAnimationName(a));
- animList.setModel(animModel);
- }
- });
-
- animAdd.setBounds(224, 290, 99, 25);
- animAdd.setText("Add");
- animAdd.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animAdd);
- animAdd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- animAdd_ActionPerformed(evt);
- }
- });
-
- animRemove.setBounds(224, 316, 99, 25);
- animRemove.setText("Remove");
- animRemove.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animRemove);
- animRemove.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- animRemove_ActionPerformed(evt);
- }
- });
-
- animPath.setBounds(344, 264, 305, 24);
- animPath.setEditable(false);
- animPath.setText("Load/Save an animation file...");
- animPath.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(animPath);
- load.setBounds(344, 296, 100, 25);
- load.setText("Load");
- load.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(load);
- load.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- load_ActionPerformed(evt);
- }
- });
-
- save.setBounds(454, 296, 100, 25);
- save.setText("Save");
- save.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(save);
- save.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- save_ActionPerformed(evt);
- }
- });
-
- saveAs.setBounds(564, 296, 90, 25);
- saveAs.setText("Save As");
- saveAs.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(saveAs);
- saveAs.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- saveAs_ActionPerformed(evt);
- }
- });
-
- jComboBox1.setBounds(344, 328, 305, 24);
- jComboBox1.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(jComboBox1);
- upload.setBounds(344, 360, 147, 25);
- upload.setText("Upload");
- upload.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(upload);
- upload.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- upload_ActionPerformed(evt);
- }
- });
-
- download.setBounds(504, 360, 147, 25);
- download.setText("Download");
- download.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(download);
- download.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- download_ActionPerformed(evt);
- }
- });
-
- jLabel4.setBounds(536, 208, 112, 20);
- jLabel4.setText("Remaining:");
- jLabel4.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(jLabel4);
- frameRemaining.setBounds(536, 232, 113, 24);
- frameRemaining.setEditable(false);
- frameRemaining.setText(String.valueOf(worker.framesRemaining()));
- frameRemaining.setFont(new Font("Dialog", Font.PLAIN, 13));
- cp.add(frameRemaining);
- animList.setFont(new Font("Dialog", Font.PLAIN, 13));
- frameList.setFont(new Font("Dialog", Font.PLAIN, 13));
- // Ende Komponenten
- animList.addListSelectionListener(this);
- frameList.addListSelectionListener(this);
- setResizable(false);
- setVisible(true);
- }
-
- // Anfang Methoden
-
- // Anfang Ereignisprozeduren
-
- public void playAnimation(ActionEvent evt){
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- for(int i = 0; i < frameList.getModel().getSize(); i++){
- frameList.setSelectedIndex(i);
- short time1 = worker.getFrameTime(animList.getSelectedIndex(), frameList.getSelectedIndex());
- long time = (long) (((time1+1) * 1/24) * 1000);
- try{
- Thread.sleep(time);
- }catch(Exception e){
- System.out.println(e);
- }
- }
- }
-
- }
-
- public void enterFullscreen(ActionEvent evt) {
- ledView.enterFullscreen();
- //FullscreenWindow fw = new FullscreenWindow(worker, cubeCanvas, ledView, this);
- setLocation(0,0);
- setSize(700, 700);
- int w = Toolkit.getDefaultToolkit().getScreenSize().width;
- int h = Toolkit.getDefaultToolkit().getScreenSize().height;
- System.out.println(w);
- System.out.println(h);
- setSize(w-5, h-30);
-
- playAnimationFullscreen.setVisible(true);
- //setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
- //Y U NO WORK????
- cubeCanvas.setBounds(0,0,Toolkit.getDefaultToolkit().getScreenSize().width-5, Toolkit.getDefaultToolkit().getScreenSize().height-80);
-
- }
- public void exitFullscreen(){
- //661, 440
- playAnimationFullscreen.setVisible(false);
- setLocation(0,0);
- setSize(661, 440);
- ledView.leaveFullscreen();
- cubeCanvas.setBounds(8,8, 250,250);
- Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
- int x = (d.width - getSize().width) / 2;
- int y = (d.height - getSize().height) / 2;
- setLocation(x, y);
- }
-
- public void editA_ActionPerformed(ActionEvent evt) {
-
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 0, worker, this);
-
- }
- }
-
- public void editB_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 1, worker, this);
- }
- }
-
- public void editC_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 2, worker, this);
- }
- }
-
- public void editD_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 3, worker, this);
- }
- }
-
- public void editE_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 4, worker, this);
- }
- }
-
- public void editF_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 5, worker, this);
- }
- }
-
- public void editG_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 6, worker, this);
- }
- }
-
- public void editH_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Please select a Frame.");
- } else {
- @SuppressWarnings("unused")
- layerEditFrame layerFrame1 = new layerEditFrame(
- animList.getSelectedIndex(), frameList.getSelectedIndex(),
- 7, worker, this);
- }
- }
-
- public void frameUp_ActionPerformed(ActionEvent evt) {
- int i = frameList.getSelectedIndex();
- if ((i > 0) && (frameListModel.getSize() >= 2)) {
- Object tmp = frameListModel.get(i);
- frameListModel.set(i, frameListModel.get(i - 1));
- frameListModel.set(i - 1, tmp);
- frameList.setSelectedIndex(i - 1);
- worker.moveFrame(worker.UP, animList.getSelectedIndex(),
- frameList.getSelectedIndex());
- }
- }
-
- public void frameDown_ActionPerformed(ActionEvent evt) {
- int i = frameList.getSelectedIndex();
- if ((i >= 0) && (frameListModel.getSize() >= 2)
- && (i < (frameListModel.getSize() - 1))) {
- Object tmp = frameListModel.get(i);
- frameListModel.set(i, frameListModel.get(i + 1));
- frameListModel.set(i + 1, tmp);
- frameList.setSelectedIndex(i + 1);
- worker.moveFrame(worker.DOWN, animList.getSelectedIndex(),
- frameList.getSelectedIndex());
- }
- }
-
- public void frameAdd_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Please select an animation!");
- } else {
- int n = worker.numOfFrames(animList.getSelectedIndex());
- worker.addFrame(animList.getSelectedIndex());
- // Not reaching past this comment if frame list empty
- frameRemaining.setText(Integer.toString(worker.framesRemaining()));
- frameListModel.add(n,
- worker.getFrameName(animList.getSelectedIndex(), n));
- frameList.setModel(frameListModel);
- }
- }
-
- public void frameRemove_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Select an animation.");
- } else if (frameList.getSelectedIndex() == -1) {
- errorMessage("Select a Frame.");
- } else {
- worker.removeFrame(animList.getSelectedIndex(),
- frameList.getSelectedIndex());
- frameRemaining.setText(Integer.toString(worker.framesRemaining()));
- frameListModel.removeElementAt(frameList.getSelectedIndex());
- frameList.setModel(frameListModel);
- }
- }
-
- public void animUp_ActionPerformed(ActionEvent evt) {
- int i = animList.getSelectedIndex();
- if ((i > 0) && (animModel.getSize() >= 2)) {
- Object tmp = animModel.get(i);
- animModel.set(i, animModel.get(i - 1));
- animModel.set(i - 1, tmp);
- animList.setSelectedIndex(i - 1);
- worker.moveAnimation(worker.UP, animList.getSelectedIndex());
- }
- }
-
- public void animDown_ActionPerformed(ActionEvent evt) {
- int i = animList.getSelectedIndex();
- if ((i >= 0) && (animModel.getSize() >= 2)
- && (i < (animModel.getSize() - 1))) {
- Object tmp = animModel.get(i);
- animModel.set(i, animModel.get(i + 1));
- animModel.set(i + 1, tmp);
- animList.setSelectedIndex(i + 1);
- worker.moveAnimation(worker.DOWN, animList.getSelectedIndex());
- }
- }
-
- public void animAdd_ActionPerformed(ActionEvent evt) {
- if (worker.addAnimation() == -1) {
- errorMessage("Could not add animation!");
- } else {
- animModel.clear();
- for (int i = 0; i < worker.numOfAnimations(); i++) {
- animModel.add(i, worker.getAnimationName(i));
- }
- animList.setModel(animModel);
- }
-
- }
-
- public void animRemove_ActionPerformed(ActionEvent evt) {
- if (animList.getSelectedIndex() == -1) {
- errorMessage("Select an animation.");
- } else {
- worker.removeAnimation(animList.getSelectedIndex());
- animModel.removeElementAt(animList.getSelectedIndex());
- animList.setModel(animModel);
- }
- }
-
- public void load_ActionPerformed(ActionEvent evt) {
- JFileChooser fc = new JFileChooser();
- int ret = fc.showOpenDialog(this);
- if (ret == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- if (fileSelected == false) {
- fileSelected = true;
- }
- animPath.setText(file.getPath());
- worker.loadState(animPath.getText());
- animModel.clear();
- for (int i = 0; i < worker.numOfAnimations(); i++) {
- animModel.addElement(worker.getAnimationName(i));
- }
- animList.setModel(animModel);
-
- frameListModel.clear();
- frameList.setModel(frameListModel);
- }
- }
-
- public void save_ActionPerformed(ActionEvent evt) {
- if (fileSelected == false) {
- JFileChooser fc = new JFileChooser();
- int ret = fc.showSaveDialog(this);
- if (ret == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- fileSelected = true;
- animPath.setText(file.getPath());
- worker.saveState(animPath.getText());
- }
- } else {
- worker.saveState(animPath.getText());
- }
- }
-
- public void saveAs_ActionPerformed(ActionEvent evt) {
- JFileChooser fc;
- if (fileSelected == true) {
- fc = new JFileChooser(new File(animPath.getText()).getParentFile());
- } else {
- fc = new JFileChooser();
- }
- int ret = fc.showSaveDialog(this);
- if (ret == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- if (fileSelected == false) {
- fileSelected = true;
- }
- animPath.setText(file.getPath());
- worker.saveState(animPath.getText());
- }
- }
-
- // We get detailed error messages from the SerialHelper...
- public void upload_ActionPerformed(ActionEvent evt) {
- if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
- // errorMessage("No serial port selected...");
- } else {
- if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
- if (worker.uploadState((String) jComboBox1.getSelectedItem()) != 0) {
- // errorMessage("Could not upload data!");
- }
- } else {
- // errorMessage("Cube does not respond...");
- }
- }
- }
-
- public void download_ActionPerformed(ActionEvent evt) {
- if (jComboBox1.getSelectedItem().equals("Select serial port...")) {
- // errorMessage("No serial port selected...");
- } else {
- if (worker.probeCubeConnected((String) jComboBox1.getSelectedItem())) {
- if (worker.downloadState((String) jComboBox1.getSelectedItem()) != 0) {
- // errorMessage("Could not download data!");
- }
- } else {
- // errorMessage("Cube does not respond...");
- }
- }
- }
-
- public Led3D get3D() {
- return ledView;
- }
-
- public static void main(String[] args) {
- Frame f = new Frame("Cube Control");
- Led3D l = f.get3D();
- String lastCommand = null;
- java.util.Scanner sc = new java.util.Scanner(System.in);
- System.out.println("#### Cube Control Debug Console ####");
- System.out.println("## Enter a Command ('h' for help) ##");
- System.out.print("$> ");
-
- do {
- if (sc.hasNextLine()) {
- String s = sc.nextLine();
-
- // Up arrow key
- if (s.equals("\u001B[A")) {
- if (lastCommand != null) {
- System.out.println("Last command: " + lastCommand);
- s = new String(lastCommand);
- } else {
- System.out.println("No last command!");
- }
- }
-
- if (s.equals("p") || (s.equals("print")))
- l.printTranslationData();
-
- if (s.equals("q") || s.equals("quit"))
- System.exit(0);
-
- if (s.equals("on") || s.equals("1")) {
- short[] d = new short[64];
- for (int i = 0; i < d.length; i++) {
- d[i] = 0xFF;
- }
- l.setData(d);
- System.out.println("All LEDs on now...");
- }
-
- if (s.equals("off") || s.equals("0")) {
- short[] d = new short[64];
- for (int i = 0; i < d.length; i++) {
- d[i] = 0x00;
- }
- l.setData(d);
- System.out.println("All LEDs off now...");
- }
-
- if (s.equals("r") || s.equals("reset")) {
- l.resetView();
- }
-
- if (s.startsWith("port ")) {
- f.jComboBox1.addItem(s.substring(5));
- f.jComboBox1.setSelectedItem(s.substring(5));
- }
-
- if (s.startsWith("send ")) {
- HelperUtility.openPort((String) f.jComboBox1
- .getSelectedItem());
- short[] dat = toShortArray(s.substring(5));
- HelperUtility.writeData(dat, dat.length);
- HelperUtility.closePort();
- }
-
- if (s.startsWith("read ")) {
- int leng = Integer.parseInt(s.substring(5));
- HelperUtility.openPort((String) f.jComboBox1
- .getSelectedItem());
- short[] data = HelperUtility.readData(leng);
- System.out.println(shortToString(data));
- HelperUtility.closePort();
- }
-
- if (s.startsWith("frames ")) {
- int anim = Integer.parseInt(s.substring(7));
- if (anim >= f.worker.numOfAnimations()) {
- System.out.println("Animation does not exist! Max: " + (f.worker.numOfAnimations() - 1));
- } else {
- System.out.println("Animation: " + f.worker.getAnimationName(anim));
- for (int i = 0; i < f.worker.numOfFrames(anim); i++) {
- AFrame frame = f.worker.getAnimationList().get(anim).get(i);
- System.out.println("\tFrame " + frame.getOrder() + " (" + frame.getTime() + "): " + frame.getName());
- }
- }
- }
-
- if (s.equals("a") || s.equals("anims")) {
- for (int i = 0; i < f.worker.numOfAnimations(); i++) {
- Animation anim = f.worker.getAnimationList().get(i);
- System.out.println("\tAnimation " + anim.getOrder() + ": " + anim.getName());
- }
- }
-
- if (s.equals("s") || s.equals("scan")) {
- String[] sPorts = f.worker.getSerialPorts();
- f.jComboBox1.removeAllItems();
- for (int i = 0; i < sPorts.length; i++) {
- f.jComboBox1.addItem(sPorts[i]);
- }
- }
-
- if (s.equals("h") || (s.equals("help"))) {
- System.out.println("Commands:");
- System.out
- .println("\t'port *name*'\t:\tSet serial port to this");
- System.out
- .println("\t'send *datas*'\t:\tSend data to serial port");
- System.out
- .println("\t'read *leng*'\t:\tRead data from serial port");
- System.out
- .println("\t'scan' / 's'\t:\tScan for serial ports");
- System.out
- .println("\t'on' / '1'\t:\tToggle all LEDs on");
- System.out
- .println("\t'off' / '0'\t:\tToggle all LEDs off");
- System.out
- .println("\t'print' / 'p'\t:\tPrint 3D Translation Matrix Data");
- System.out
- .println("\t'reset' / 'r'\t:\tReset rotation of cube");
- System.out
- .println("\t'anims' / 'a'\t:\tPrint animation tree");
- System.out
- .println("\t'frames *anim*\t:\tPrint frame tree");
- System.out
- .println("\t'help' / 'h'\t:\tShow this message");
- System.out
- .println("\t'quit' / 'q'\t:\tExit Cube Control");
- }
-
- lastCommand = new String(s);
- System.out.print("$> ");
- }
- } while (true);
- }
-
- private static short[] toShortArray(String s) {
- char[] d = s.toCharArray();
- System.out.println("Length: " + d.length);
- short[] r = new short[d.length];
- for (int i = 0; i < d.length; i++) {
- r[i] = (short) d[i];
- }
- return r;
- }
-
- private static String shortToString(short[] d) {
- String s = "";
- for (int i = 0; i < d.length; i++) {
- s += String.valueOf((char) d[i]);
- }
- return s;
- }
- }
|