📄 gui.java.svn-base
字号:
/** * This method initializes saveCompare * * @return javax.swing.JButton */ private JButton getSaveCompare() { if (saveCompare == null) { saveCompare = new JButton(); saveCompare.setText("Save compare"); saveCompare.setToolTipText("Save the compare file (the right one)"); saveCompare.addActionListener(this); } return saveCompare; } /** * This method initializes remove * * @return javax.swing.JButton */ private JButton getRemove() { if (remove == null) { remove = new JButton(); remove.setText("Remove"); remove.setToolTipText("Remove the currently selected langauge String"); remove.addActionListener(this); } return remove; } /** * This method initializes about * * @return javax.swing.JButton */ private JButton getAbout() { if (about == null) { about = new JButton(); about.setText("About"); about.setToolTipText("Display info about this application"); about.addActionListener(this); } return about; } public void actionPerformed(ActionEvent act){ int answer = -1; if (act.getSource() == this.openBase) { JFileChooser chooser = new JFileChooser(LGFile.sBasePath); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) ; { jlft.setBase(null); clearColum(BASE_SECTION); File file = chooser.getSelectedFile(); try { LGFile lLGFile = LGFile.load(file.getCanonicalPath()); Hashtable<String,LGString> lDuplicates = lLGFile.checkForDuplicates(); if(lDuplicates.size() > 0){ String lDupString = ""; Enumeration<String> lDupKeys = lDuplicates.keys(); while(lDupKeys.hasMoreElements()){ lDupString+=lDuplicates.get(lDupKeys.nextElement()).getKey()+"\n"; } JOptionPane.showMessageDialog(this, "Duplicate found in base file!\n"+lDupString+"\n Please remve these from the base file before continuing! ", "Error", JOptionPane.ERROR_MESSAGE); } else { jlft.setBase(lLGFile); } } catch (Exception e) { if(JimmLangFileTool.DEBUG){ System.out.println("Error loading file"); } } jlft.compare(); this.fillInValues(); } } if (act.getSource() == this.openCompare) { if (jlft.getBase() != null) { JFileChooser chooser = new JFileChooser(LGFile.sBasePath); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION); { jlft.setCompare(null); clearColum(COMPARE_SECTION); File file = chooser.getSelectedFile(); try { jlft.setCompare(LGFile.load(file.getCanonicalPath())); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error loading the file", "Error", JOptionPane.ERROR_MESSAGE); } jlft.compare(); this.fillInValues(); } } else { JOptionPane.showMessageDialog(this, "You have to open a base file before you can open a compare file", "Error", JOptionPane.ERROR_MESSAGE); } } if (act.getSource() == this.saveCompare) { JFileChooser chooser = new JFileChooser(LGFile.sBasePath); 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(); this.fillInValues(); } } if (act.getSource() == this.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: if(JimmLangFileTool.DEBUG){ System.out.println("YES"); } ((LGString) compareTable.getValueAt(compareTable.getSelectedRow(), compareTable.getSelectedColumn())).setTranslated(LGString.REMOVED); fillInValues(); break; default: // do nothing } } } if (act.getSource() == this.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: if(JimmLangFileTool.DEBUG){ System.out.println("YES"); System.out.println("Delete it"); } LGFileSubset lRemoveSubset = ((LGFileSubset) compareTable.getValueAt(compareTable.getSelectedRow(), compareTable.getSelectedColumn())); lRemoveSubset.setRemoved(true); for(int i=0;i<lRemoveSubset.size();i++){ lRemoveSubset.get(i).setTranslated(LGString.REMOVED); } fillInValues(); break; default: // do nothing } } if (act.getSource() == this.about) JOptionPane.showMessageDialog(this, "Jimm Lang File Tool - Tool for editing Jimm language Files\n\n Version " + JimmLangFileTool.VERSION + "\n\n(c) Jimm project 2005-2008\n\nwww.jimm.org\n\n", "About Jimm Lang File Tool", JOptionPane.PLAIN_MESSAGE); } public class JlftTableRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; LGString lgs; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof LGString) { lgs = (LGString) value; switch (lgs.isTranslated()) { case LGString.TRANSLATED: cell.setBackground(Color.white); break; case LGString.NEWLY_TRANSLATED: cell.setBackground(Color.orange); break; case LGString.NOT_IN_BASE_FILE: cell.setBackground(Color.red); break; case LGString.NOT_TRANSLATED: cell.setBackground(Color.yellow); break; default: cell.setBackground(Color.white); } } else { cell.setFocusable(false); cell.setBackground(Color.lightGray); } return cell; } } public class JlftTableModel extends DefaultTableModel { private static final long serialVersionUID = 1L; LGString lgs; public boolean isCellEditable(int row, int colum) { if(!(super.getValueAt(row,colum) instanceof LGString) || (colum < 2) || ((LGString)super.getValueAt(row,colum)).isTranslated() == LGString.NOT_IN_BASE_FILE) return false; else return true; } public Object getValueAt(int row, int colum) { if(super.getValueAt(row,colum) instanceof LGString) { lgs = (LGString)super.getValueAt(row,colum); if(colum %2 == 0) lgs.setReturnKey(true); else lgs.setReturnKey(false); return lgs; } else return super.getValueAt(row,colum); } public void setValueAt(Object value,int row, int colum) { if (value instanceof String && !(((String)value).startsWith("MOD_") || ((String)value).startsWith("TAR_") || ((String)value).startsWith("GENERAL")) && getValueAt(row, colum) instanceof LGString) { lgs = (LGString) getValueAt(row, colum); if (!((String) value).equals(lgs.getValue())) { lgs.setTranslated(LGString.NEWLY_TRANSLATED); lgs.setValue((String)value); super.setValueAt(lgs.getClone(), row, colum); } } else super.setValueAt(value, row, colum); } } /** * This method initializes legendPanel * * @return javax.swing.JPanel */ private JPanel getLegendPanel() { if (legendPanel == null) { GridLayout gridLayout = new GridLayout(); gridLayout.setRows(2); gridLayout.setHgap(3); gridLayout.setVgap(3); gridLayout.setColumns(2); legendPanel = new JPanel(); legendPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(3,3,3,3)); legendPanel.setLayout(gridLayout); legendPanel.add(getWhite(), null); legendPanel.add(getRed(), null); legendPanel.add(getOrange(), null); legendPanel.add(getYellow(), null); } return legendPanel; } /** * This method initializes white * * @return javax.swing.JLabel */ private JLabel getWhite() { if (white == null) { white = new JLabel(); white.setText("Key was found in base and compare file"); white.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); white.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.PLAIN, 10)); white.setOpaque(true); white.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,3,0,3)); white.setBackground(new Color(255,255,255)); } return white; } /** * This method initializes yellow * * @return javax.swing.JLabel */ private JLabel getYellow() { if (yellow == null) { yellow = new JLabel(); yellow.setText("Key was not found in compare file"); yellow.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); yellow.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.PLAIN, 10)); yellow.setOpaque(true); yellow.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,3,0,3)); yellow.setBackground(java.awt.Color.yellow); } return yellow; } /** * This method initializes orange * * @return javax.swing.JLabel */ private JLabel getOrange() { if (orange == null) { orange = new JLabel(); orange.setText("Text for this key was changed but not saved yet"); orange.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); orange.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.PLAIN, 10)); orange.setOpaque(true); orange.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,3,0,3)); orange.setBackground(java.awt.Color.orange); } return orange; } /** * This method initializes red * * @return javax.swing.JLabel */ private JLabel getRed() { if (red == null) { red = new JLabel(); red.setText("Key was found in compare but not in base"); red.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT); red.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.PLAIN, 10)); red.setOpaque(true); red.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,3,0,3)); red.setBackground(java.awt.Color.red); } return red; } /** * This method initializes removeGroup * * @return javax.swing.JButton */ private JButton getRemoveGroup() { if (removeGroup == null) { removeGroup = new JButton(); removeGroup.setText("Remove group"); removeGroup.setToolTipText("Remove a whole group of Strings at once"); removeGroup.addActionListener(this); } return removeGroup; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -