Пример #1
0
 /**
  * This method initializes defaultTableModel
  *
  * @return javax.swing.table.DefaultTableModel
  */
 private DefaultTableModel getDefaultTableModel(boolean refresh) {
   if (jlftTableModel == null || refresh) {
     jlftTableModel = new JlftTableModel();
     Vector columIdent = new Vector();
     columIdent.add("Base key " + jlft.getBase().getName());
     columIdent.add("Base value " + jlft.getBase().getName());
     columIdent.add("Compare key " + jlft.getCompare().getName());
     columIdent.add("Compare value " + jlft.getCompare().getName());
     jlftTableModel.setColumnIdentifiers(columIdent);
     jlftTableModel.setColumnCount(4);
     jlftTableModel.setRowCount(getSizeForTable());
   }
   return jlftTableModel;
 }
Пример #2
0
 private int getSizeForTable() {
   LGFile base = jlft.getBase();
   LGFile compare = jlft.getCompare();
   return (base.getEntrysize() > compare.getEntrysize())
       ? base.getEntrysize()
       : compare.getEntrysize();
 }
Пример #3
0
  private void fillInValues() {
    int j = 0;
    int k = 0;
    int l = 0;
    int m = 0;

    // Delete all old stuff
    compareTable.removeAll();
    compareTable.setModel(getDefaultTableModel(true));
    setTableProps();

    // Set base values
    LGFile base = jlft.getBase();
    for (int i = 0; i < base.size(); i++) {
      LGFileSubset subset = (LGFileSubset) base.get(i);
      compareTable.setValueAt(subset, i + k + l, 0);
      for (j = 0; j < subset.size(); j++) {
        if (((LGString) subset.get(j)).getTranslated() != LGString.REMOVED) {
          compareTable.setValueAt(subset.get(j), i + k + j + 1 + l, 0);
          compareTable.setValueAt(subset.get(j), i + k + j + 1 + l, 1);
        } else {
          l--;
        }
      }
      k += j;
    }

    k = 0;
    l = 0;

    // Set compare values
    LGFile compare = jlft.getCompare();
    for (int i = 0; i < compare.size(); i++) {
      if (!((LGFileSubset) compare.get(i)).isRemoved()) {
        LGFileSubset subset = (LGFileSubset) compare.get(i);
        compareTable.setValueAt(subset, i + k + l + m, 2);
        for (j = 0; j < subset.size(); j++) {
          if (((LGString) subset.get(j)).getTranslated() != LGString.REMOVED) {
            compareTable.setValueAt(subset.get(j), i + k + j + 1 + l + m, 2);
            compareTable.setValueAt(subset.get(j), i + k + j + 1 + l + m, 3);
          } else {
            l--;
          }
        }
        k += j;
      } else {
        m--;
      }
    }
  }
Пример #4
0
  public void actionPerformed(ActionEvent act) {
    int answer = -1;
    if (act.getSource() == openBase) {
      JFileChooser chooser = new JFileChooser("src/lng");
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
          jlft.setBase(LGFile.load(file.getCanonicalPath()));
        } catch (Exception e) {
          System.out.println("Error loading file");
        }
        jlft.compare();
        fillInValues();
      }
    }
    if (act.getSource() == openCompare) {
      JFileChooser chooser = new JFileChooser("src/lng/");
      int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
          jlft.setCompare(LGFile.load(file.getCanonicalPath()));
        } catch (Exception e) {
          e.printStackTrace();
          JOptionPane.showMessageDialog(
              this, "Error loading the file", "Error", JOptionPane.ERROR_MESSAGE);
        }
        jlft.compare();
        fillInValues();
      }
    }
    if (act.getSource() == saveCompare) {
      JFileChooser chooser = new JFileChooser("src/lng/");
      int returnVal = chooser.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
          jlft.getCompare().save(file.getCanonicalPath());
        } catch (Exception e) {
          JOptionPane.showMessageDialog(
              this, "Error saving the file", "Error", JOptionPane.ERROR_MESSAGE);
        }
        jlft.compare();
        fillInValues();
      }
    }
    if (act.getSource() == remove)
      if ((compareTable.getSelectedColumn() == -1) || (compareTable.getSelectedRow() == -1))
        JOptionPane.showMessageDialog(
            this, "You have to select an item first", "Select first", JOptionPane.ERROR_MESSAGE);
      else if (((compareTable.getValueAt(
              compareTable.getSelectedRow(), compareTable.getSelectedColumn())
          instanceof LGString))) {
        if ((((LGString)
                    compareTable.getValueAt(
                        compareTable.getSelectedRow(), compareTable.getSelectedColumn()))
                .isTranslated()
            != LGString.NOT_IN_BASE_FILE))
          JOptionPane.showMessageDialog(
              this,
              "You can only delete items which are not in the base file(red).",
              "Cannot delete item",
              JOptionPane.ERROR_MESSAGE);
        else {
          answer =
              JOptionPane.showConfirmDialog(
                  this,
                  "Delete \""
                      + ((LGString)
                              compareTable.getValueAt(
                                  compareTable.getSelectedRow(), compareTable.getSelectedColumn()))
                          .getKey()
                      + "\"?",
                  "Delete?",
                  JOptionPane.YES_NO_OPTION);
          switch (answer) {
            case JOptionPane.YES_OPTION:
              System.out.println("YES");
              ((LGString)
                      compareTable.getValueAt(
                          compareTable.getSelectedRow(), compareTable.getSelectedColumn()))
                  .setTranslated(LGString.REMOVED);
              fillInValues();
              break;
            default: // do nothing
          }
        }
      }

    if (act.getSource() == removeGroup)
      if (compareTable.getSelectedColumn() > 1)
        if ((compareTable.getSelectedColumn() == -1) || (compareTable.getSelectedRow() == -1))
          JOptionPane.showMessageDialog(
              this,
              "You have to select a group item first",
              "Select first",
              JOptionPane.ERROR_MESSAGE);
        else if ((compareTable.getValueAt(
                compareTable.getSelectedRow(), compareTable.getSelectedColumn())
            instanceof LGFileSubset)) {
          answer =
              JOptionPane.showConfirmDialog(
                  this,
                  "Delete \""
                      + ((LGFileSubset)
                              compareTable.getValueAt(
                                  compareTable.getSelectedRow(), compareTable.getSelectedColumn()))
                          .getId()
                      + "\"?",
                  "Delete?",
                  JOptionPane.YES_NO_OPTION);
          switch (answer) {
            case JOptionPane.YES_OPTION:
              System.out.println("YES");
              System.out.println("Delete it");
              ((LGFileSubset)
                      compareTable.getValueAt(
                          compareTable.getSelectedRow(), compareTable.getSelectedColumn()))
                  .setRemoved(true);
              fillInValues();
              break;
            default: // do nothing
          }
        }

    if (act.getSource() == about) {
      JOptionPane.showMessageDialog(
          this,
          "Jimm Lang File Tool - Tool for editing Jimm language Files\n\n (C) Jimm project 2005\n\nwww.jimm.org\n\n",
          "About Jimm Lang File Tool",
          JOptionPane.PLAIN_MESSAGE);
    }
    if (act.getSource() == optimize) {
      jlft.getBase().optimize();
      jlft.getCompare().optimize();
      jlft.compare();
      fillInValues();
    }
  }