Beispiel #1
0
  /** Create the dialog. */
  public TaEditor(X10flash flash, Vector<TaEntry> v) {
    _flash = flash;
    setModalityType(ModalityType.APPLICATION_MODAL);
    setTitle("TA Editor");
    setBounds(100, 100, 715, 450);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(
        new FormLayout(
            new ColumnSpec[] {
              FormFactory.RELATED_GAP_COLSPEC,
              ColumnSpec.decode("max(63dlu;min)"),
              FormFactory.RELATED_GAP_COLSPEC,
              ColumnSpec.decode("default:grow"),
              FormFactory.RELATED_GAP_COLSPEC,
              FormFactory.DEFAULT_COLSPEC,
            },
            new RowSpec[] {
              FormFactory.RELATED_GAP_ROWSPEC,
              FormFactory.DEFAULT_ROWSPEC,
              FormFactory.RELATED_GAP_ROWSPEC,
              RowSpec.decode("default:grow"),
              FormFactory.RELATED_GAP_ROWSPEC,
              FormFactory.DEFAULT_ROWSPEC,
              FormFactory.RELATED_GAP_ROWSPEC,
              RowSpec.decode("default:grow"),
            }));
    {
      JScrollPane scrollPane = new JScrollPane();
      contentPanel.add(scrollPane, "2, 2, 1, 7, fill, fill");
      {
        tablePartition =
            new JTable() {
              /** */
              private static final long serialVersionUID = 1L;

              public boolean isCellEditable(int rowIndex, int vColIndex) {
                return false;
              }
            };
        tablePartition.addKeyListener(
            new KeyAdapter() {
              @Override
              public void keyReleased(KeyEvent arg0) {
                reloadUnit();
              }
            });
        tablePartition.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mouseReleased(MouseEvent arg0) {
                String result =
                    (String) modelPartition.getValueAt(tablePartition.getSelectedRow(), 0);
                try {
                  if (ta != null) ta.setData(hex.getByteContent());
                  ta = (TaEntry) content.get(result);
                  hex.setByteContent(ta.getDataString().getBytes());
                } catch (Exception e) {
                }
              }
            });
        JMenuItem mntmResize = new JMenuItem("Resize Unit");
        mntmResize.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                TAUnitResizeGUI resize = new TAUnitResizeGUI();
                String newsize = resize.getUnitSize();
                if (newsize.length() > 0) {
                  ta.resize(Integer.parseInt(newsize));
                  hex.setByteContent(ta.getDataString().getBytes());
                }
              }
            });
        popupMenu.add(mntmResize);
        JMenuItem mntmLoad = new JMenuItem("Load from file");
        mntmLoad.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                TaSelectGUI tasel =
                    new TaSelectGUI(
                        ".bin",
                        _flash.getPhoneProperty("MSN")
                            + "_"
                            + (String)
                                modelPartition.getValueAt(tablePartition.getSelectedRow(), 0));
                String result = tasel.getTa();
                if (result.length() > 0) {
                  String path = OS.getWorkDir() + "/custom/ta/" + result;
                  try {
                    byte[] array = BytesUtil.getBytesFromFile(new File(path));
                    ta.setData(array);
                    hex.setByteContent(array);
                  } catch (Exception e) {
                    MyLogger.getLogger().error(e.getMessage());
                  }
                }
              }
            });
        popupMenu.add(mntmLoad);
        JMenuItem mntmWriteFile = new JMenuItem("Write to file");
        mntmWriteFile.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                String rootpath = OS.getWorkDir() + "/custom/ta/";
                String path =
                    _flash.getPhoneProperty("MSN")
                        + "_"
                        + (String) modelPartition.getValueAt(tablePartition.getSelectedRow(), 0)
                        + "-"
                        + org.logger.TextAreaAppender.timestamp
                        + ".bin";
                File f = new File(rootpath + path);
                try {
                  FileOutputStream fos = new FileOutputStream(f);
                  fos.write(hex.getByteContent());
                  fos.flush();
                  fos.close();
                  JOptionPane.showMessageDialog(null, "Unit saved to \n" + path);
                } catch (Exception e) {
                }
              }
            });
        popupMenu.add(mntmWriteFile);
        JMenuItem mntmWrite = new JMenuItem("Write to phone");
        mntmWrite.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                reloadUnit();
                try {
                  _flash.sendTAUnit(ta);
                } catch (Exception e) {
                  MyLogger.getLogger().error(e.getMessage());
                }
              }
            });
        popupMenu.add(mntmWrite);
        MouseListener popupListener = new PopupListener();
        tablePartition.addMouseListener(popupListener);
        tablePartition.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        scrollPane.setViewportView(tablePartition);
      }
    }
    {
      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
      getContentPane().add(buttonPane, BorderLayout.SOUTH);
      {
        JButton cancelButton = new JButton("Close");
        cancelButton.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                dispose();
              }
            });
        cancelButton.setActionCommand("Cancel");
        buttonPane.add(cancelButton);
      }
    }
    contentPanel.add(hex, "4, 2, 1, 7");
    hex.setColorBorderBackGround(Color.LIGHT_GRAY);
    {
      JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);
      {
        JMenu mnFile = new JMenu("File");
        menuBar.add(mnFile);
        {
          JMenuItem mntmLoad_1 = new JMenuItem("Load");
          mntmLoad_1.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                  TaSelectGUI tasel = new TaSelectGUI(".ta", _flash.getPhoneProperty("MSN"));
                  String result = tasel.getTa();
                  if (result.length() > 0) {
                    String tafile = OS.getWorkDir() + "/custom/ta/" + result;
                    try {
                      TaFile ta = new TaFile(new FileInputStream(new File(tafile)));
                      Vector<TaEntry> entries = ta.entries();
                      fill(entries);
                    } catch (Exception e1) {
                    }
                  }
                }
              });
          mnFile.add(mntmLoad_1);
        }
        {
          JMenuItem mntmSave = new JMenuItem("Save");
          mntmSave.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                  try {
                    String rootpath = OS.getWorkDir() + "/custom/ta/";
                    String path =
                        _flash.getPhoneProperty("MSN")
                            + "-"
                            + org.logger.TextAreaAppender.timestamp
                            + ".ta";
                    TextFile tazone = new TextFile(rootpath + path, "ISO8859-1");
                    tazone.open(false);
                    Iterator i = content.values().iterator();
                    while (i.hasNext()) {
                      tazone.writeln(i.next().toString());
                    }
                    tazone.close();
                    JOptionPane.showMessageDialog(null, "TA saved to \n" + path);
                  } catch (Exception e) {
                    MyLogger.getLogger().error(e.getMessage());
                  }
                }
              });
          mnFile.add(mntmSave);
        }
      }
    }
    fill(v);
  }
Beispiel #2
0
 private void reloadUnit() {
   String result = (String) modelPartition.getValueAt(tablePartition.getSelectedRow(), 0);
   if (ta != null) ta.setData(hex.getByteContent());
   ta = (TaEntry) content.get(result);
   hex.setByteContent(ta.getDataString().getBytes());
 }