public static void main(String[] args) { Logger.getRootLogger() .addAppender( new ConsoleAppender( new org.apache.log4j.PatternLayout("%d - %-5p - %-20c (%C [%L]) - %m%n"))); GlobalOptions.setSelectedServer("de43"); GlobalOptions.setSelectedProfile(new DummyProfile()); DataHolder.getSingleton().loadData(false); try { // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception e) { } List<Village> selection = new LinkedList<Village>(); for (int i = 0; i < 100; i++) { selection.add(DataHolder.getSingleton().getRandomVillage()); } DSWorkbenchSelectionFrame.getSingleton().resetView(); DSWorkbenchSelectionFrame.getSingleton().addVillages(selection); DSWorkbenchSelectionFrame.getSingleton().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DSWorkbenchSelectionFrame.getSingleton().setVisible(true); }
/** @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ // <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(SOSGenerator.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SOSGenerator.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SOSGenerator.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SOSGenerator.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } // </editor-fold> Logger.getRootLogger() .addAppender( new ConsoleAppender( new org.apache.log4j.PatternLayout("%d - %-5p - %-20c (%C [%L]) - %m%n"))); GlobalOptions.setSelectedServer("de43"); ProfileManager.getSingleton().loadProfiles(); GlobalOptions.setSelectedProfile(ProfileManager.getSingleton().getProfiles("de43")[0]); DataHolder.getSingleton().loadData(false); GlobalOptions.loadUserData(); /* * Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { public void run() { new SOSGenerator().setVisible(true); } }); }
/** Creates new form DSWorkbenchSelectionFrame */ DSWorkbenchSelectionFrame() { initComponents(); centerPanel = new GenericTestPanel(true); jSelectionPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jSelectionTreePanel); buildMenu(); capabilityInfoPanel1.addActionListener(this); treeData = new LinkedList<Village>(); jSelectionTree.setCellRenderer(new NodeCellRenderer()); KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false); jSelectionTree.registerKeyboardAction( DSWorkbenchSelectionFrame.this, "Copy", copy, JComponent.WHEN_FOCUSED); jSelectionTree.registerKeyboardAction( DSWorkbenchSelectionFrame.this, "BBCopy", bbCopy, JComponent.WHEN_FOCUSED); jSelectionTree.registerKeyboardAction( DSWorkbenchSelectionFrame.this, "Delete", delete, JComponent.WHEN_FOCUSED); jSelectionTree.registerKeyboardAction( DSWorkbenchSelectionFrame.this, "Paste", paste, JComponent.WHEN_FOCUSED); jSelectionTree.registerKeyboardAction( DSWorkbenchSelectionFrame.this, "Cut", cut, JComponent.WHEN_FOCUSED); jSelectionTree .getActionMap() .put( "find", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { // ignore find } }); jSelectionTree.getSelectionModel().addTreeSelectionListener(DSWorkbenchSelectionFrame.this); buildTree(); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker() .enableHelpKey( getRootPane(), "pages.selection_tool", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> }
public void restoreProperties() { getModel().clear(); UserProfile profile = GlobalOptions.getSelectedProfile(); villageSelectionPanel.setExpertSelection( Boolean.parseBoolean(profile.getProperty("ret.source.expert"))); villageSelectionPanel.setup(); }
private static String replaceHeadFootVariables( String pBlock, String pPlanName, List<Attack> pAttacks) { String result = pBlock; // set creator Tribe user = GlobalOptions.getSelectedProfile().getTribe(); if (user != null) { result = result.replaceAll(CREATOR, Matcher.quoteReplacement(user.getName())); } else { result = result.replaceAll(CREATOR, "-"); } // set planname if (pPlanName != null) { result = result.replaceAll(PLANNAME, EscapeChars.forHTML(pPlanName)); } else { result = result.replaceAll(PLANNAME, "-"); } // set attack count NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0); nf.setMinimumFractionDigits(0); result = result.replaceAll(ATTACK_COUNT, nf.format(pAttacks.size())); // set attack count String server = GlobalOptions.getSelectedServer(); if (server != null) { result = result.replaceAll(SERVER, server); } else { result = result.replaceAll(SERVER, "-"); } // replace version result = result.replaceAll(VERSION, Double.toString(Constants.VERSION) + Constants.VERSION_ADDITION); // replace creation date SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy 'um' HH:mm:ss 'Uhr'"); result = result.replaceAll(CREATION_DATE, f.format(new Date(System.currentTimeMillis()))); return result; }
public void addVillages(List<Village> pVillages) { boolean showBarbarian = true; try { showBarbarian = Boolean.parseBoolean(GlobalOptions.getProperty("show.barbarian")); } catch (Exception e) { showBarbarian = true; } treeData.clear(); System.out.println(pVillages.size()); for (Village v : pVillages.toArray(new Village[] {})) { if ((v != null && v.getTribe() == Barbarians.getSingleton()) && !showBarbarian) { // dont select barbarians if they are not visible } else { if (v != null && !treeData.contains(v)) { treeData.add(v); } } } Collections.sort(treeData, Village.ALLY_TRIBE_VILLAGE_COMPARATOR); buildTree(); }
private void exportAsHTML() { List<Village> selection = getSelectedElements(); if (selection.isEmpty()) { showInfo("Keine Dörfer ausgewählt"); return; } // do HTML export String dir = GlobalOptions.getProperty("screen.dir"); if (dir == null) { dir = "."; } JFileChooser chooser = null; try { // handle vista problem chooser = new JFileChooser(dir); } catch (Exception e) { JOptionPaneHelper.showErrorBox( this, "Konnte Dateiauswahldialog nicht öffnen.\nMöglicherweise verwendest du Windows Vista. Ist dies der Fall, beende DS Workbench, klicke mit der rechten Maustaste auf DSWorkbench.exe,\n" + "wähle 'Eigenschaften' und deaktiviere dort unter 'Kompatibilität' den Windows XP Kompatibilitätsmodus.", "Fehler"); return; } chooser.setDialogTitle("Datei auswählen"); chooser.setFileFilter( new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File f) { if ((f != null) && (f.isDirectory() || f.getName().endsWith(".html"))) { return true; } return false; } @Override public String getDescription() { return "*.html"; } }); // open dialog chooser.setSelectedFile(new File(dir + "/Dorfliste.html")); int ret = chooser.showSaveDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { try { // check extension File f = chooser.getSelectedFile(); String file = f.getCanonicalPath(); if (!file.endsWith(".html")) { file += ".html"; } // check overwrite File target = new File(file); if (target.exists()) { if (JOptionPaneHelper.showQuestionConfirmBox( this, "Bestehende Datei überschreiben?", "Überschreiben", "Nein", "Ja") == JOptionPane.NO_OPTION) { // do not overwrite return; } } // do export SelectionHTMLExporter.doExport(target, selection); GlobalOptions.addProperty("screen.dir", target.getParent()); showSuccess("Auswahl erfolgreich gespeichert"); if (JOptionPaneHelper.showQuestionConfirmBox( this, "Willst du die erstellte Datei jetzt im Browser betrachten?", "Information", "Nein", "Ja") == JOptionPane.YES_OPTION) { BrowserCommandSender.openPage(target.toURI().toURL().toString()); } } catch (Exception inner) { logger.error("Failed to write selection to HTML", inner); showError("Fehler beim Speichern"); } } }
public static void loadCustomTemplate() { try { HEADER = ""; BLOCK = ""; FOOTER = ""; String header = GlobalOptions.getProperty("attack.template.header"); String block = GlobalOptions.getProperty("attack.template.block"); String footer = GlobalOptions.getProperty("attack.template.footer"); if (header == null) { header = "ThisFileDoesNotExist"; } if (block == null) { block = "ThisFileDoesNotExist"; } if (footer == null) { footer = "ThisFileDoesNotExist"; } File fHeader = new File(header); File fBlock = new File(block); File fFooter = new File(footer); BufferedReader r = null; if (!fHeader.exists()) { r = new BufferedReader( new InputStreamReader( AttackPlanHTMLExporter.class.getResourceAsStream( "/de/tor/tribes/tmpl/attack_header.tmpl"))); } else { r = new BufferedReader(new InputStreamReader(new FileInputStream(header))); } String line = ""; while ((line = r.readLine()) != null) { HEADER += line + "\n"; } r.close(); if (!fBlock.exists()) { r = new BufferedReader( new InputStreamReader( AttackPlanHTMLExporter.class.getResourceAsStream( "/de/tor/tribes/tmpl/attack_block.tmpl"))); } else { r = new BufferedReader(new InputStreamReader(new FileInputStream(block))); } line = ""; while ((line = r.readLine()) != null) { BLOCK += line + "\n"; } r.close(); if (!fFooter.exists()) { r = new BufferedReader( new InputStreamReader( AttackPlanHTMLExporter.class.getResourceAsStream( "/de/tor/tribes/tmpl/attack_footer.tmpl"))); } else { r = new BufferedReader(new InputStreamReader(new FileInputStream(footer))); } line = ""; while ((line = r.readLine()) != null) { FOOTER += line + "\n"; } r.close(); } catch (Exception e) { logger.error("Failed to read custom templates. Switch to default template.", e); loadDefaultTemplate(); } }
public static void doExport(File pHtmlFile, String pPlanName, List<Attack> pAttacks) { if (TEMPLATE_ERROR) { logger.warn("Skip writing HTML file due to TEMPLATE_ERROR flag"); return; } SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); StringBuffer result = new StringBuffer(); // append header result.append(replaceHeadFootVariables(HEADER, pPlanName, pAttacks)); int cnt = 0; for (Attack a : pAttacks) { String b = BLOCK; // <editor-fold defaultstate="collapsed" desc="Replace DIV-IDs"> if (cnt % 2 == 0) { b = b.replaceAll(DIV_CLASS, "odd_div"); } else { b = b.replaceAll(DIV_CLASS, "even_div"); } b = b.replaceAll(ID, Integer.toString(cnt)); // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Replace Unit Icons"> UnitHolder unit = a.getUnit(); b = b.replaceAll( UNIT, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/" + unit.getPlainName() + ".png\">"); switch (a.getType()) { case Attack.CLEAN_TYPE: { b = b.replaceAll( TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/att.png\">"); break; } case Attack.SNOB_TYPE: { b = b.replaceAll( TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/snob.png\">"); break; } case Attack.FAKE_TYPE: { b = b.replaceAll( TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/fake.png\">"); break; } case Attack.FAKE_DEFF_TYPE: { b = b.replaceAll( TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/def_fake.png\">"); break; } case Attack.SUPPORT_TYPE: { b = b.replaceAll( TYPE, "<img src=\"http://www.dsworkbench.de/DSWorkbench/export/ally.png\">"); break; } default: { b = b.replaceAll(TYPE, "-"); break; } } // </editor-fold> String baseURL = ServerManager.getServerURL(GlobalOptions.getSelectedServer()) + "/"; // <editor-fold defaultstate="collapsed" desc=" replace source tribe and ally"> Tribe sourceTribe = a.getSource().getTribe(); String sourceTribeName = ""; String sourceTribeLink = ""; String sourceAllyName = ""; String sourceAllyTag = ""; String sourceAllyLink = ""; String sourceVillageName = ""; String sourceVillageCoord = ""; String sourceVillageLink = ""; if (sourceTribe == null) { // tribe is null, so it is a barbarian village sourceTribeName = "Barbaren"; sourceAllyName = "Barbaren"; } else { sourceTribeLink = baseURL; sourceTribeLink += "guest.php?screen=info_player&id=" + sourceTribe.getId(); sourceTribeName = sourceTribe.getName(); // replace source tribe Ally sourceAlly = sourceTribe.getAlly(); if (sourceAlly == null) { // tribe has no ally sourceAllyName = "Kein Stamm"; } else { // ally valid sourceAllyName = sourceAlly.getName(); sourceAllyTag = sourceAlly.getTag(); sourceAllyLink = baseURL; sourceAllyLink += "guest.php?screen=info_ally&id=" + sourceAlly.getId(); } } // replace source village sourceVillageLink = baseURL; sourceVillageLink += "guest.php?screen=info_village&id=" + a.getSource().getId(); sourceVillageName = a.getSource().getFullName(); sourceVillageCoord = a.getSource().getCoordAsString(); // replace values b = b.replaceAll(SOURCE_PLAYER_NAME, Matcher.quoteReplacement(sourceTribeName)); b = b.replaceAll(SOURCE_PLAYER_LINK, sourceTribeLink); b = b.replaceAll(SOURCE_ALLY_NAME, Matcher.quoteReplacement(sourceAllyName)); b = b.replaceAll(SOURCE_ALLY_TAG, Matcher.quoteReplacement(sourceAllyTag)); b = b.replaceAll(SOURCE_ALLY_LINK, sourceAllyLink); b = b.replaceAll(SOURCE_VILLAGE_NAME, Matcher.quoteReplacement(sourceVillageName)); b = b.replaceAll(SOURCE_VILLAGE_COORD, sourceVillageCoord); b = b.replaceAll(SOURCE_VILLAGE_LINK, sourceVillageLink); // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" replace target tribe and ally"> Tribe targetTribe = a.getTarget().getTribe(); String targetTribeName = ""; String targetTribeLink = ""; String targetAllyName = ""; String targetAllyTag = ""; String targetAllyLink = ""; String targetVillageName = ""; String targetVillageCoord = ""; String targetVillageLink = ""; if (targetTribe == null) { // tribe is null, so it is a barbarian village targetTribeName = "Barbaren"; targetAllyName = "Barbaren"; } else { targetTribeLink = baseURL; targetTribeLink += "guest.php?screen=info_player&id=" + targetTribe.getId(); targetTribeName = targetTribe.getName(); // replace source tribe Ally targetAlly = targetTribe.getAlly(); if (targetAlly == null) { // tribe has no ally targetAllyName = "Kein Stamm"; } else { // ally valid targetAllyName = targetAlly.getName(); targetAllyTag = targetAlly.getTag(); targetAllyLink = baseURL; targetAllyLink += "guest.php?screen=info_ally&id=" + targetAlly.getId(); } } // replace source village targetVillageLink = baseURL; targetVillageLink += "guest.php?screen=info_village&id=" + a.getTarget().getId(); targetVillageName = a.getTarget().getFullName(); targetVillageCoord = a.getTarget().getCoordAsString(); // replace values b = b.replaceAll(TARGET_PLAYER_NAME, Matcher.quoteReplacement(targetTribeName)); b = b.replaceAll(TARGET_PLAYER_LINK, targetTribeLink); b = b.replaceAll(TARGET_ALLY_NAME, Matcher.quoteReplacement(targetAllyName)); b = b.replaceAll(TARGET_ALLY_TAG, Matcher.quoteReplacement(targetAllyTag)); b = b.replaceAll(TARGET_ALLY_LINK, targetAllyLink); b = b.replaceAll(TARGET_VILLAGE_NAME, Matcher.quoteReplacement(targetVillageName)); b = b.replaceAll(TARGET_VILLAGE_COORD, targetVillageCoord); b = b.replaceAll(TARGET_VILLAGE_LINK, targetVillageLink); // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Replace times and place URL"> // replace arrive time String arrive = f.format(a.getArriveTime()); b = b.replaceAll(ARRIVE_TIME, arrive); // replace send time long send = a.getArriveTime().getTime() - ((long) DSCalculator.calculateMoveTimeInSeconds( a.getSource(), a.getTarget(), a.getUnit().getSpeed()) * 1000); b = b.replaceAll(SEND_TIME, f.format(new Date(send))); // replace place link String placeURL = baseURL + "game.php?village="; int uvID = GlobalOptions.getSelectedProfile().getUVId(); if (uvID >= 0) { placeURL = baseURL + "game.php?t=" + uvID + "&village="; } placeURL += a.getSource().getId() + "&screen=place&mode=command&target=" + a.getTarget().getId(); placeURL += "&type=0"; StandardAttack stdAttack = StandardAttackManager.getSingleton().getElementByIcon(a.getType()); for (UnitHolder u : DataHolder.getSingleton().getUnits()) { int amount = 0; if (stdAttack != null) { amount = stdAttack.getAmountForUnit(u, a.getSource()); } placeURL += "&" + u.getPlainName() + "=" + amount; } b = b.replaceAll(PLACE, placeURL); // </editor-fold> result.append(b); cnt++; } // append footer result.append(replaceHeadFootVariables(FOOTER, pPlanName, pAttacks)); try { FileWriter w = new FileWriter(pHtmlFile); w.write(result.toString()); w.flush(); w.close(); } catch (Exception e) { logger.error("Failed writing HTML file", e); } }
public void storeProperties() { UserProfile profile = GlobalOptions.getSelectedProfile(); profile.addProperty("ret.source.expert", villageSelectionPanel.isExpertSelection()); }