private void updateTemplateFromEditor(PrintfTemplate template) { ArrayList params = new ArrayList(); String format = null; int text_length = editorPane.getDocument().getLength(); try { format = editorPane.getDocument().getText(0, text_length); } catch (BadLocationException ex1) { } Element section_el = editorPane.getDocument().getDefaultRootElement(); // Get number of paragraphs. int num_para = section_el.getElementCount(); for (int p_count = 0; p_count < num_para; p_count++) { Element para_el = section_el.getElement(p_count); // Enumerate the content elements int num_cont = para_el.getElementCount(); for (int c_count = 0; c_count < num_cont; c_count++) { Element content_el = para_el.getElement(c_count); AttributeSet attr = content_el.getAttributes(); // Get the name of the style applied to this content element; may be null String sn = (String) attr.getAttribute(StyleConstants.NameAttribute); // Check if style name match if (sn != null && sn.startsWith("Parameter")) { // we extract the label. JLabel l = (JLabel) StyleConstants.getComponent(attr); if (l != null) { params.add(l.getName()); } } } } template.setFormat(format); template.setTokens(params); }
/* * return an arraylist with elements: * 0: placeName * 1: lives * 2: name * 3: description * 4: strength */ public ArrayList<String> getHero() { ArrayList<String> hero = new ArrayList<String>(); // extract place int index = game.indexOf("\n"); hero.add(game.substring(7, index)); game = game.substring(index + 1); // extract lives index = game.indexOf("\n"); String info = game.substring(7, index); game = game.substring(index + 1); hero.add(info); // extract name & description index = game.indexOf("\n"); info = game.substring(0, index); game = game.substring(index + 1); index = info.indexOf(":"); hero.add(info.substring(0, index)); hero.add(info.substring(index + 2)); // extract strength index = game.indexOf("\n"); info = game.substring(10, index); game = game.substring(index + 1); hero.add(info); // remove next 2 lines of file game = game.substring(game.indexOf("\n") + 1); game = game.substring(game.indexOf("\n") + 1); // extract weapons // extract treasures return hero; }
// Used in compiling to mark out "dirty" areas of the code; ie, comments and string literals. // These dirty areas don't get their syntax highlighted or any special treatment. // @returns: pairs of integers that represent dirty boundaries. private ArrayList<Integer> getDirty(String code) { ArrayList<Integer> dirtyBounds = new ArrayList<>(); // Handles string literals int j = -1; while (true) { j = code.indexOf("\"", j + 1); if (j < 0) break; // Ignore escaped characters if (!code.substring(j - 1, j).equals("\\")) dirtyBounds.add(j); } // End of line comments j = -1; while (true) { j = code.indexOf("//", j + 1); if (j < 0) break; dirtyBounds.add(j); // If there's no newline, then the comment lasts for the length of the code dirtyBounds.add( code.indexOf("\n", j + 1) == -1 ? code.length() : code.indexOf("\n", j + 1)); } // Block comments (and javadoc comments) j = -1; while (true) { j = code.indexOf("/*", j + 1); if (j < 0) break; dirtyBounds.add(j); dirtyBounds.add(code.indexOf("*/", j + 1)); } return dirtyBounds; }
public ArrayList<String> getNewFoe(int race, int name) { ArrayList<String> foeDes = new ArrayList<>(); int index = 0; switch (race) { case 1: index = characters.indexOf("Gnome"); break; case 2: index = characters.indexOf("Halfling"); break; case 3: index = characters.indexOf("Goblin"); break; case 4: index = characters.indexOf("Human"); break; case 5: index = characters.indexOf("Dwarf"); break; case 6: index = characters.indexOf("Elf"); break; case 7: index = characters.indexOf("Orc"); break; case 8: index = characters.indexOf("Troll"); break; default: System.out.println("Couldn't generate characters"); System.exit(1); break; } String temp = characters.substring(index); // need to remove an extra line if female because of file format if (name > 10) { index = temp.indexOf("\n"); temp = temp.substring(index + 1); } for (; name > 0; name--) { index = temp.indexOf("\n"); temp = temp.substring(index + 1); } index = temp.indexOf(" "); foeDes.add(temp.substring(0, index)); foeDes.add(temp.substring(index + 1, temp.indexOf("\n"))); return foeDes; }
// returns 0: diary 1: diary start time public ArrayList<String> getDiary() { ArrayList<String> info = new ArrayList<>(); int index = game.indexOf("Time:"); info.add(game.substring(0, index)); game = game.substring(index); index = game.indexOf("\n"); info.add(game.substring(6, index)); game = game.substring(index + 1); return info; }
public ArrayList<String> getNewWep(int race, boolean raceWep, int wepNum) { ArrayList<String> wepDes = new ArrayList<>(); String temp = weapons; int index; for (; wepNum > 0; wepNum--) { index = temp.indexOf("\n"); temp = temp.substring(index + 1); } index = temp.indexOf(":"); wepDes.add(temp.substring(0, index)); wepDes.add(temp.substring(index + 2, temp.indexOf("\n"))); return wepDes; }
public ArrayList<String> getNewTres(int race, boolean raceTres, int tresNum) { ArrayList<String> tresDes = new ArrayList<>(); String temp = treasures; int index; for (; tresNum > 0; tresNum--) { index = temp.indexOf("\n"); temp = temp.substring(index + 1); } index = temp.indexOf(":"); tresDes.add(temp.substring(0, index)); tresDes.add(temp.substring(index + 2, temp.indexOf("\n"))); return tresDes; }
public boolean hasMorePaths() { if (game.indexOf("Path") == 0) { path = new ArrayList<>(); // extract name & description int index = game.indexOf("\n"); String info = game.substring(5, index); game = game.substring(index + 1); index = info.indexOf(":"); path.add(info.substring(0, index)); path.add(info.substring(index + 2)); return true; } return false; }
public void bringToFront(Figure figure) { if (children.remove(figure)) { children.add(figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
/** * Returns all editors. * * @return editors */ EditorArea[] editors() { final ArrayList<EditorArea> edits = new ArrayList<EditorArea>(); for (final Component c : tabs.getComponents()) { if (c instanceof EditorArea) edits.add((EditorArea) c); } return edits.toArray(new EditorArea[edits.size()]); }
/** * Method to ignore all incoming messages from a user * * @param i the user to ignore * @param quite if true will not show confirmation * @return true on succes, false on failure */ private boolean ignore(String i, boolean quiet) { if (username.equals(i) || i.equals("server") || admins.contains(i)) { if (!quiet) { error("can't ignore that person"); } return false; } if (!users.contains(i)) { if (!quiet) { error("user does not exists"); } return false; } if (ignores.contains(i)) { if (!quiet) { error("already ignoring user"); } return false; } ignores.add(i); updateList(); if (!quiet) { serverMessage("ignoring " + i); } return true; }
public boolean hasMoreWeps() { if (game.indexOf("Weapon") == 0) { wep = new ArrayList<>(); // extract name & description int index = game.indexOf("\n"); String info = game.substring(7, index); game = game.substring(index + 1); index = info.indexOf(":"); wep.add(info.substring(0, index)); wep.add(info.substring(index + 2, info.indexOf("Force:") - 1)); // extract force wep.add(info.substring(info.lastIndexOf(":") + 2).trim()); return true; } return false; }
public void sendToBack(Figure figure) { if (children.remove(figure)) { children.add(0, figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
public boolean hasMoreTres() { if (game.indexOf("Treasure") == 0) { tres = new ArrayList<>(); // extract name & description int index = game.indexOf("\n"); String info = game.substring(9, index); game = game.substring(index + 1); index = info.indexOf(":"); tres.add(info.substring(0, index)); tres.add(info.substring(index + 2, info.indexOf("Value:") - 1)); // extract value tres.add(info.substring(info.lastIndexOf(":") + 2).trim()); return true; } return false; }
/** Loads the icons for the tile patterns list. */ private void loadIcons() { tilePatternIcons.clear(); for (TilePattern tilePattern : tileset.getTilePatterns()) { tilePatternIcons.add(new TilePatternIcon(tilePattern, tileset)); } }
/** * adds a new user to the interal list of users * * @param un the name of the user to be added */ public void userAdd(String un) { if (!users.contains(un)) { users.add(un); updateList(); if (!un.equals(username) && showUserStatus) serverMessage(un + " has joined " + server.channel); } }
public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { JFileChooser chooser = getFileChooser(); FileSystemView fsv = chooser.getFileSystemView(); JList list = (JList) evt.getSource(); int fsm = chooser.getFileSelectionMode(); boolean useSetDirectory = usesSingleFilePane && (fsm == JFileChooser.FILES_ONLY); if (chooser.isMultiSelectionEnabled()) { File[] files = null; Object[] objects = list.getSelectedValues(); if (objects != null) { if (objects.length == 1 && ((File) objects[0]).isDirectory() && chooser.isTraversable(((File) objects[0])) && (useSetDirectory || !fsv.isFileSystem(((File) objects[0])))) { setDirectorySelected(true); setDirectory(((File) objects[0])); } else { ArrayList<File> fList = new ArrayList<File>(objects.length); for (Object object : objects) { File f = (File) object; boolean isDir = f.isDirectory(); if ((chooser.isFileSelectionEnabled() && !isDir) || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && isDir)) { fList.add(f); } } if (fList.size() > 0) { files = fList.toArray(new File[fList.size()]); } setDirectorySelected(false); } } chooser.setSelectedFiles(files); } else { File file = (File) list.getSelectedValue(); if (file != null && file.isDirectory() && chooser.isTraversable(file) && (useSetDirectory || !fsv.isFileSystem(file))) { setDirectorySelected(true); setDirectory(file); if (usesSingleFilePane) { chooser.setSelectedFile(null); } } else { setDirectorySelected(false); if (file != null) { chooser.setSelectedFile(file); } } } } }
/** * changes the name of a user, updating list of admins, afks, ignoes, and master user list * * @param on old username * @param nn new username */ public void rename(String on, String nn) { if (admins.contains(on)) { admins.remove(admins.indexOf(on)); admins.add(nn); } if (afks.contains(on)) { afks.remove(afks.indexOf(on)); afks.add(nn); } if (ignores.contains(on)) { ignores.remove(ignores.indexOf(on)); ignores.add(nn); } users.remove(on); users.add(nn); updateList(); serverMessage(on + " renamed to " + nn); }
public boolean hasMorePlaces() { if (game.indexOf("Place") == 0) { // the hero's place has a semicolon after it. if we reach the hero's place there are no more // places if (game.indexOf(":") == 5) { return false; } place = new ArrayList<>(); // extract name & description int index = game.indexOf("\n"); String info = game.substring(6, index); game = game.substring(index + 1); index = info.indexOf(":"); place.add(info.substring(0, index)); place.add(info.substring(index + 2)); return true; } return false; }
private ArrayList<Path> holeLaufwerkeWindows() { ArrayList<Path> laufwerksRoot = new ArrayList<>(); Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories(); for (Path path : rootDirectories) { laufwerksRoot.add(path.getRoot()); } return laufwerksRoot; }
/** The only richer format supported is the file list flavor */ protected Object getRicherData(DataFlavor flavor) { if (DataFlavor.javaFileListFlavor.equals(flavor)) { ArrayList<Object> files = new ArrayList<Object>(); for (Object file : this.fileData) { files.add(file); } return files; } return null; }
private ArrayList<Path> holeLaufwerkeUnix() { ArrayList<Path> laufwerksRoot = new ArrayList<>(); for (FileStore store : FileSystems.getDefault().getFileStores()) { if (store.name().contains("/dev/sd")) { laufwerksRoot.add( Paths.get(store.toString().substring(0, store.toString().indexOf(' ')))); } } return laufwerksRoot; }
/** * constructor * * @param values list of values, String[] */ public MPopButton(String[] values) { this(); for (int i = 0; i < values.length; i++) { JMenuItem item = popup.add(values[i]); item.addActionListener(popActionListener); popup.add(item); m_aListValues.add(values[i]); } setDefaultText(); } // MPopButton()
/** Implementation note: Sorting can not be done for orphaned children. */ public java.util.List<Figure> sort(Collection<Figure> c) { ensureSorted(); ArrayList<Figure> sorted = new ArrayList<Figure>(c.size()); for (Figure f : children) { if (c.contains(f)) { sorted.add(f); } } return sorted; }
public void doActionOnButton3() { // Sector sector = Sector.fromDegrees( 44d, 46d, -123.3d, -123.2d ); ArrayList<LatLon> latlons = new ArrayList<LatLon>(); latlons.add(LatLon.fromDegrees(45.50d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.51d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.52d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.53d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.54d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.55d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.56d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.57d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.58d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.59d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.60d, -123.3d)); ElevationModel model = this.wwd.getModel().getGlobe().getElevationModel(); StringBuffer sb = new StringBuffer(); for (LatLon ll : latlons) { double e = model.getElevation(ll.getLatitude(), ll.getLongitude()); sb.append("\n").append(e); } Logging.logger().info(sb.toString()); }
public boolean hasMoreFoes() { if (game.indexOf("Foe") == 0) { foe = new ArrayList<>(); // extract name & description int index = game.indexOf("\n"); String info = game.substring(4, index); game = game.substring(index + 1); index = info.indexOf(":"); foe.add(info.substring(0, index)); foe.add(info.substring(index + 2)); // extract strength index = game.indexOf("\n"); info = game.substring(10, index); game = game.substring(index + 1); foe.add(info); // remove next 2 lines of file game = game.substring(game.indexOf("\n") + 1); game = game.substring(game.indexOf("\n") + 1); return true; } return false; }
/** * Gets the list of selected records. * * @return the list of selected records. */ public Variability[] getSelectedRecords() { ArrayList list = new ArrayList(); int check_column = getCheckColumn(); for (int i = 0; i < model.getRowCount(); i++) { if (((Boolean) getValueAt(i, check_column)).booleanValue()) { Variability record = (Variability) record_list.elementAt(index.get(i)); list.add(record); } } Variability[] records = new Variability[list.size()]; return (Variability[]) list.toArray(records); }
WordListModel(ASDGrammar grammar) { Set entrySet = grammar.lexicon().entrySet(); ArrayList words = new ArrayList(entrySet.size()); for (Iterator it = entrySet.iterator(); it.hasNext(); ) { Map.Entry e = (Map.Entry) it.next(); String word = (String) e.getKey(); words.add(word); } Object[] wordArray = words.toArray(); if (words.size() > 1) // Arrays.sort(wordArray); Arrays.sort(wordArray, new WordComparator()); for (int j = 0; j < wordArray.length; j++) { this.addElement((String) wordArray[j]); } }
public void doActionOnButton4() { ArrayList<LatLon> locations = new ArrayList<LatLon>(); locations.add(LatLon.fromDegrees(45.50d, -123.3d)); locations.add(LatLon.fromDegrees(45.52d, -123.3d)); locations.add(LatLon.fromDegrees(45.54d, -123.3d)); locations.add(LatLon.fromDegrees(45.56d, -123.3d)); locations.add(LatLon.fromDegrees(45.58d, -123.3d)); locations.add(LatLon.fromDegrees(45.60d, -123.3d)); locations.add(LatLon.fromDegrees(40.50d, -120.1d)); locations.add(LatLon.fromDegrees(40.52d, -120.2d)); locations.add(LatLon.fromDegrees(40.54d, -120.3d)); locations.add(LatLon.fromDegrees(40.56d, -120.4d)); locations.add(LatLon.fromDegrees(40.58d, -120.5d)); locations.add(LatLon.fromDegrees(40.60d, -120.6d)); // Now, let's find WMSBasicElevationModel WMSBasicElevationModel wmsbem = null; ElevationModel model = this.wwd.getModel().getGlobe().getElevationModel(); if (model instanceof CompoundElevationModel) { CompoundElevationModel cbem = (CompoundElevationModel) model; for (ElevationModel em : cbem.getElevationModels()) { // you can have additional checks if you know specific model name, etc. if (em instanceof WMSBasicElevationModel) { wmsbem = (WMSBasicElevationModel) em; break; } } } else if (model instanceof WMSBasicElevationModel) { wmsbem = (WMSBasicElevationModel) model; } if (null != wmsbem) { ElevationsRetriever retriever = new ElevationsRetriever(wmsbem, locations, 10000, 30000, new NotifyWhenReady()); retriever.start(); } else { String message = Logging.getMessage( "ElevationModel.ExceptionRequestingElevations", "No instance of WMSBasicElevationModel was found"); Logging.logger().severe(message); } }
public ArrayList getSelectedMessages() { ArrayList list = new ArrayList(); for (int i = 0; i < table.getRowCount(); i++) { if (((Boolean) table.getValueAt(i, 0)) == true) { list.add(msgID[i]); } } return list; }