private void updateParentUserObject(DefaultMutableTreeNode parent) { String label = ((CheckBoxNode) parent.getUserObject()).label; int selectedCount = 0; int indeterminateCount = 0; Enumeration children = parent.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); CheckBoxNode check = (CheckBoxNode) node.getUserObject(); if (check.status == Status.INDETERMINATE) { indeterminateCount++; break; } if (check.status == Status.SELECTED) { selectedCount++; } } onCheckboxStatusChanged(parent); if (indeterminateCount > 0) { parent.setUserObject(new CheckBoxNode(label)); } else if (selectedCount == 0) { parent.setUserObject(new CheckBoxNode(label, Status.DESELECTED)); } else if (selectedCount == parent.getChildCount()) { parent.setUserObject(new CheckBoxNode(label, Status.SELECTED)); } else { parent.setUserObject(new CheckBoxNode(label)); } }
/** * Query the maximum image size allowed. * * @return the maximum image size allowed. */ public Dimension getMaximumSize() { final Dimension retval = new Dimension(); final Hashtable depthMap = getDepthMap(); int item = 0; synchronized (getActiveVector()) { final Enumeration keys = getDepthMap().keys(); while (keys.hasMoreElements()) { final Bookmark bookmark = (Bookmark) keys.nextElement(); final Rectangle bounds = getTextBounds(item++, bookmark, depthMap.get(bookmark)); final int width = bounds.x + bounds.width; if (width > retval.width) { retval.width = width; } retval.height = bounds.y + bounds.height; } } retval.width += (2 * getFontMetrics(getFont()).getMaxAdvance()); retval.height += (2 * getFontHeight()); return retval; }
private void checkNodeValidity(@NotNull DefaultMutableTreeNode node) { Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { checkNodeValidity((DefaultMutableTreeNode) enumeration.nextElement()); } if (node instanceof Node && node != getModelRoot()) ((Node) node).update(this); }
private void MenuPopup (MouseEvent ev, CGNode node) { if (!node.IsConcept()) return; String menuname = (String)menumap.get (node.GetType(true)); if (menuname == null) return; Hashtable templates = (Hashtable)menus.get (menuname); if (templates == null) return; if( popup != null ) remove( popup ); popup = new PopupMenu( menuname ); Enumeration e = templates.keys(); while (e.hasMoreElements()) { String key = (String)e.nextElement(); MenuItem mi = new MenuItem( key ); mi.setActionCommand( key ); mi.addActionListener( this ); popup.add( mi ); } curnode = node; this.add( popup ); popup.show( this, ev.getX(), ev.getY() ); }
public DefaultMutableTreeNode findNode(DefaultMutableTreeNode parent, String match) { if (parent == null) return null; // Commented by Balan on 15/03/03 // String treename = (String)parent.getUserObject (); // Comment Ends // Added by Balan on 15/03/03 String treename = "" + ((Hashtable) parent.getUserObject()).get("TREE-NAME"); // Add Ends if (treename != null) { if (treename.equals(match)) return parent; } if (frame.model.isLeaf(parent)) return null; Enumeration en = parent.children(); if ((en == null) || (!en.hasMoreElements())) return null; for (; en.hasMoreElements(); ) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) en.nextElement(); DefaultMutableTreeNode returnNode = findNode(child, match); if (returnNode != null) return returnNode; } return null; }
/** Description of the Method */ public void removeAllElements() { for (Enumeration<BPM_Element> e = listModel.elements(); e.hasMoreElements(); ) { BPM_Element elm = e.nextElement(); elm.stopMonitor(); } listModel.removeAllElements(); }
/** * Called to create a map the parent of each bookmark. * * @param parent top level bookmark. * @param parentMap map to add children to. * @param pagenoVector vector of page numbers. * @param depth object indicating bookmark depth. */ protected void mapChildren( final Bookmark parent, final Hashtable parentMap, final Vector pagenoVector, final Number depth) { getDepthMap().put(parent, depth); final int pageno = parent.getPageno(); if (pageno >= 0) { while (pageno >= pagenoVector.size()) { pagenoVector.addElement(null); } pagenoVector.setElementAt(parent, pageno); } final Enumeration e = parent.elements(); if (e.hasMoreElements()) { final Number childDepth = new Integer(depth.intValue() + 1); do { final Bookmark child = (Bookmark) e.nextElement(); parentMap.put(child, parent); mapChildren(child, parentMap, pagenoVector, childDepth); } while (e.hasMoreElements()); } }
/** * notify listeners of a popup selection * * @param popStr popup selection string */ void popNotify(String popStr) { Enumeration en = popListeners.elements(); for (; en.hasMoreElements(); ) { PopListener listener = (PopListener) en.nextElement(); listener.popHappened(popStr); } } // popNotify()
// {{{ traverseNodes() method public static boolean traverseNodes( DefaultMutableTreeNode node, HyperSearchTreeNodeCallback callbackInterface) { if (!callbackInterface.processNode(node)) return false; for (Enumeration e = node.children(); e.hasMoreElements(); ) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) e.nextElement(); if (!traverseNodes(childNode, callbackInterface)) return false; } return true; } // }}}
@Override public void actionPerformed(ActionEvent evt) { TreePath path = resultTree.getSelectionPath(); DefaultMutableTreeNode operNode = (DefaultMutableTreeNode) path.getLastPathComponent(); for (Enumeration e = operNode.children(); e.hasMoreElements(); ) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); resultTree.collapsePath(new TreePath(node.getPath())); } resultTree.scrollPathToVisible(new TreePath(operNode.getPath())); }
/* * Applet is no longer displayed */ public void stop() { // Tell all pages to stop talking to the server Enumeration e = pages.elements(); while (e.hasMoreElements()) { SOAPMonitorPage pg = (SOAPMonitorPage) e.nextElement(); if (pg != null) { pg.stop(); } } }
public void save(PrintStream stream) { saved = true; stream.println("<?xml version=\"1.0\"?>"); stream.println("<scale>"); stream.println(" <name>" + nameTF.getText() + "</name>"); for (Enumeration en = sp.notes.elements(); en.hasMoreElements(); ) { ScalePanel.Notik cur = (ScalePanel.Notik) en.nextElement(); stream.println(" <note>" + cur.n + "</note>"); } stream.println("</scale>"); }
/** * Returns the bPM attribute of the BPMsTable object * * @param name The Parameter * @return The bPM value */ public BPM_Element getBPM(String name) { BPM_Element bpmElm = null; Enumeration<BPM_Element> bpm_enum = listModel.elements(); while (bpm_enum.hasMoreElements()) { BPM_Element bpmElm1 = bpm_enum.nextElement(); if (bpmElm1.getName().equals(name)) { bpmElm = bpmElm1; } } return bpmElm; }
// Get what the user selects as the answer public String getSelection() { String selectedChoice = null; Enumeration<AbstractButton> buttons = bg.getElements(); while (buttons.hasMoreElements()) { JRadioButton temp = (JRadioButton) buttons.nextElement(); if (temp.isSelected()) { selectedChoice = temp.getText(); } } return (selectedChoice); }
private static void sortNode(ParentNode node, final Comparator<ElementNode> sortComparator) { ArrayList<MemberNode> arrayList = new ArrayList<MemberNode>(); Enumeration<MemberNode> children = node.children(); while (children.hasMoreElements()) { arrayList.add(children.nextElement()); } Collections.sort(arrayList, sortComparator); replaceChildren(node, arrayList); }
protected void doSort() { Pair<ElementNode, List<ElementNode>> pair = storeSelection(); Enumeration<ParentNode> children = getRootNodeChildren(); while (children.hasMoreElements()) { ParentNode classNode = children.nextElement(); sortNode(classNode, myComparator); myTreeModel.nodeStructureChanged(classNode); } restoreSelection(pair); }
private void updateAllChildrenUserObject(DefaultMutableTreeNode root, Status status) { Enumeration breadth = root.breadthFirstEnumeration(); while (breadth.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) breadth.nextElement(); if (root == node) { continue; } CheckBoxNode check = (CheckBoxNode) node.getUserObject(); node.setUserObject(new CheckBoxNode(check.label, status)); onCheckboxStatusChanged(node); } }
private void createClusterManagerElement() { ConfigElementFactory factory = new ConfigElementFactory(mBroker.getRepository().getAllLatest()); ConfigElement cluster_manager = factory.create("Sample Cluster", "cluster_manager"); for (Enumeration e = mNodesListModel.elements(); e.hasMoreElements(); ) { cluster_manager.addProperty("cluster_node", (String) e.nextElement()); } cluster_manager.addProperty("plugin_path", "${VJ_BASE_DIR}/lib/gadgeteer/plugins/"); cluster_manager.addProperty("plugin", "RemoteInputManager"); cluster_manager.addProperty("plugin", "ApplicationDataManager"); mBroker.add(mContext, cluster_manager); }
private void save() { try { Document doc = XmlUtil.getDocument(); Element root = doc.createElement("profiles"); doc.appendChild(root); Enumeration<String> keys = table.keys(); while (keys.hasMoreElements()) { table.get(keys.nextElement()).appendTo(root); } FileUtil.setText(new File(filename), FileUtil.utf8, XmlUtil.toString(doc)); } catch (Exception ignore) { } }
/** * List results by date * * @param reslist result list * @param ldisp */ private void listByDateRun(ResultList reslist, boolean ldisp) { StringTokenizer tokenizer = new StringTokenizer((String) reslist.get("list"), "\n"); Vector vdata = new Vector(); while (tokenizer.hasMoreTokens()) { String data = convertToPretty(tokenizer.nextToken()); if (datasets.contains(data) || ldisp) vdata.add(data); } datasets.removeAllElements(); Enumeration en = vdata.elements(); while (en.hasMoreElements()) datasets.addElement(en.nextElement()); }
/** * Called to recursively paint the check box for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintCheckbox(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle checkboxBounds = getCheckboxBounds(item, bookmark, getDepthMap().get(bookmark)); final int yCheckboxMidPoint = checkboxBounds.y + (checkboxBounds.height / 2); final int xCheckboxMidPoint = checkboxBounds.x + (checkboxBounds.width / 2); final Enumeration e = bookmark.elements(); if (e.hasMoreElements()) { // clear any lines crossing through the checkbox. g.clearRect( checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw box around checkbox g.drawRect(checkboxBounds.x, checkboxBounds.y, checkboxBounds.width, checkboxBounds.height); // draw dash inside checkbox g.drawLine( checkboxBounds.x + 2, yCheckboxMidPoint, (checkboxBounds.x + checkboxBounds.width) - 2, yCheckboxMidPoint); boolean drawPlus = true; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } drawPlus = false; nextItem = paintCheckbox(nextItem, g, child); } while (e.hasMoreElements()); if (drawPlus) { g.drawLine( xCheckboxMidPoint, checkboxBounds.y + 2, xCheckboxMidPoint, (checkboxBounds.y + checkboxBounds.height) - 2); } } } return nextItem; }
// find all available serial ports for the settings->ports menu. public String[] ListSerialPorts() { @SuppressWarnings("unchecked") Enumeration<CommPortIdentifier> ports = (Enumeration<CommPortIdentifier>) CommPortIdentifier.getPortIdentifiers(); ArrayList<String> portList = new ArrayList<String>(); while (ports.hasMoreElements()) { CommPortIdentifier port = (CommPortIdentifier) ports.nextElement(); if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) { portList.add(port.getName()); } } portsDetected = (String[]) portList.toArray(new String[0]); return portsDetected; }
/** check for flow mappings; does not allow flow mapping through CoordinateSystem */ private String findFlow( ShadowTupleType shadow, DisplayImpl display, DisplayTupleType[] tuples, int[] flowToComponent) { ShadowRealType[] components = shadow.getRealComponents(); for (int i = 0; i < components.length; i++) { int num_flow_per_real = 0; Enumeration maps = components[i].getSelectedMapVector().elements(); while (maps.hasMoreElements()) { ScalarMap map = (ScalarMap) maps.nextElement(); DisplayRealType dreal = map.getDisplayScalar(); DisplayTupleType tuple = dreal.getTuple(); if (Display.DisplayFlow1Tuple.equals(tuple) || Display.DisplayFlow2Tuple.equals(tuple)) { if (tuples[0] != null) { if (!tuples[0].equals(tuple)) { return multipleFlowTuples; } } else { tuples[0] = tuple; } num_flow_per_real++; if (num_flow_per_real > 1) { return multipleFlowMapping; } int index = dreal.getTupleIndex(); flowToComponent[index] = i; directMap[index] = map; } else if (Display.DisplayFlow1SphericalTuple.equals(tuple) || Display.DisplayFlow2SphericalTuple.equals(tuple)) { if (tuples[0] != null) { if (!tuples[0].equals(tuple)) { return multipleFlowTuples; } } else { tuples[0] = tuple; coord = tuple.getCoordinateSystem(); } num_flow_per_real++; if (num_flow_per_real > 1) { return multipleFlowMapping; } int index = dreal.getTupleIndex(); flowToComponent[index] = i; directMap[index] = map; } } // while (maps.hasMoreElements()) } return null; }
// Take a tree of files starting in a directory in a zip file // and copy them to a disk directory, recreating the tree. private int unpackZipFile( File inZipFile, String directory, String parent, boolean suppressFirstPathElement) { int count = 0; if (!inZipFile.exists()) return count; parent = parent.trim(); if (!parent.endsWith(File.separator)) parent += File.separator; if (!directory.endsWith(File.separator)) directory += File.separator; File outFile = null; try { ZipFile zipFile = new ZipFile(inZipFile); Enumeration zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { ZipEntry entry = (ZipEntry) zipEntries.nextElement(); String name = entry.getName().replace('/', File.separatorChar); if (name.startsWith(directory)) { if (suppressFirstPathElement) name = name.substring(directory.length()); outFile = new File(parent + name); // Create the directory, just in case if (name.indexOf(File.separatorChar) >= 0) { String p = name.substring(0, name.lastIndexOf(File.separatorChar) + 1); File dirFile = new File(parent + p); dirFile.mkdirs(); } if (!entry.isDirectory()) { System.out.println("Installing " + outFile); // Copy the file BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile)); BufferedInputStream in = new BufferedInputStream(zipFile.getInputStream(entry)); int size = 1024; int n = 0; byte[] b = new byte[size]; while ((n = in.read(b, 0, size)) != -1) out.write(b, 0, n); in.close(); out.flush(); out.close(); // Count the file count++; } } } zipFile.close(); } catch (Exception e) { System.err.println("...an error occured while installing " + outFile); e.printStackTrace(); System.err.println("Error copying " + outFile.getName() + "\n" + e.getMessage()); return -count; } System.out.println(count + " files were installed."); return count; }
private static void collectUsages( @NotNull DefaultMutableTreeNode node, @NotNull Set<Usage> usages) { if (node instanceof UsageNode) { UsageNode usageNode = (UsageNode) node; final Usage usage = usageNode.getUsage(); usages.add(usage); } Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) enumeration.nextElement(); collectUsages(child, usages); } }
/** * Called to recursively paint text and lines for the specified item. * * @param item row number * @param g graphics object to paint. * @param bookmark to check selected value. * @return the next row number to paint. */ public int paintItem(final int item, final Graphics g, final Bookmark bookmark) { int nextItem = item + 1; if (bookmark != null) { final Rectangle textBounds = getTextBounds(item, bookmark, getDepthMap().get(bookmark)); final int yTextMidPoint = textBounds.y + (textBounds.height / 2); final Enumeration e = bookmark.elements(); final String displayName = bookmark.getDisplayName(); if (displayName != null) { g.drawString(displayName, textBounds.x, textBounds.y + textBounds.height); } if (e.hasMoreElements()) { // draw line from checkbox to text g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint); final int xLineToChildren = textBounds.x - (getFontWidth() / 2); int southLine = yTextMidPoint; do { final Bookmark child = (Bookmark) e.nextElement(); final Bookmark next = getBookmark(nextItem); if (child != next) { break; } southLine = (((2 * nextItem) + 1) * getFontHeight()) / 2; g.drawLine(xLineToChildren, southLine, textBounds.x - 2, southLine); nextItem = paintItem(nextItem, g, child); } while (e.hasMoreElements()); if (southLine > yTextMidPoint) { g.drawLine(xLineToChildren, yTextMidPoint, xLineToChildren, southLine); } } else if (displayName != null) { g.drawLine(textBounds.x - getFontWidth(), yTextMidPoint, textBounds.x - 2, yTextMidPoint); } } return nextItem; }
/** Refilter the list of messages */ public void applyFilter() { // Re-filter using new criteria filter_data = null; if ((filter_include != null) || (filter_exclude != null) || filter_active || filter_complete) { filter_data = new Vector(); Enumeration e = data.elements(); SOAPMonitorData soap; while (e.hasMoreElements()) { soap = (SOAPMonitorData) e.nextElement(); if (filterMatch(soap)) { filter_data.addElement(soap); } } } fireTableDataChanged(); }
/** Draw vertices on top of the edge structure */ public void drawNodes(Graphics2D gg) { Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // Run through the traversal and draw each vertex // using an Ellipse2D // The draw point has been determined previously in // calcNodeCoords() while (nodeList.hasMoreElements()) { TreeVertex vertex = (TreeVertex) nodeList.nextElement(); // Don't draw virtual nodes if (vertex.isVirtual()) continue; // If tree is incomplete and we're on the top layer, skip it if (argument.isMultiRoots() && vertex.getLayer() == 0) continue; Point corner = vertex.getDrawPoint(); Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM); vertex.setShape(node, this); // Fill the interior of the node with vertex's fillPaint gg.setPaint(vertex.fillPaint); gg.fill(node); // Draw the outline with vertex's outlinePaint; bold if selected gg.setPaint(vertex.outlinePaint); if (vertex.isSelected()) { gg.setStroke(selectStroke); } else { gg.setStroke(solidStroke); } gg.draw(node); // Draw the short label on top of the vertex gg.setPaint(vertex.textPaint); String shortLabelString = new String(vertex.getShortLabel()); if (shortLabelString.length() == 1) { gg.setFont(labelFont1); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4); } else if (shortLabelString.length() == 2) { gg.setFont(labelFont2); gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4); } } }
protected void loadAirspacesFromPath(String path, Collection<Airspace> airspaces) { File file = ExampleUtil.saveResourceToTempFile(path, ".zip"); if (file == null) return; try { ZipFile zipFile = new ZipFile(file); ZipEntry entry = null; for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); entry = e.nextElement()) { if (entry == null) continue; String name = WWIO.getFilename(entry.getName()); if (!(name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml"))) continue; String[] tokens = name.split("-"); try { Class c = Class.forName(tokens[0]); Airspace airspace = (Airspace) c.newInstance(); BufferedReader input = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry))); String s = input.readLine(); airspace.restoreState(s); airspaces.add(airspace); if (tokens.length >= 2) { airspace.setValue(AVKey.DISPLAY_NAME, tokens[1]); } } catch (Exception ex) { ex.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } }
/** Draws the edge structure of the tree */ public void drawEdges(Graphics2D gg) { gg.setPaint(Color.black); Enumeration nodeList = argument.getBreadthFirstTraversal().elements(); // For each vertex... while (nodeList.hasMoreElements()) { // Get its edge list... TreeVertex vertex = (TreeVertex) nodeList.nextElement(); Enumeration edges = vertex.getEdgeList().elements(); // For each edge in the list... while (edges.hasMoreElements()) { TreeEdge edge = (TreeEdge) edges.nextElement(); // If we have several vertices on layer 0, only draw // edges for layers below that if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) { // If the edge has been selected with the mouse, // use a thick line if (edge.isSelected()) { gg.setStroke(selectStroke); } gg.draw(edge.getShape(this)); // If we used a thick line, reset the stroke to normal // line for next edge. if (edge.isSelected()) { gg.setStroke(solidStroke); } TreeVertex edgeSource = edge.getDestVertex(); } } } }