List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:TrainNet.java
License:Apache License
public void adjustWeights(Element node) throws JDOMException { //each backward connection's weight to equal current weight + LEARNING_RATE * output of neuron at other end of connection * this neuron's errorGradient int lock = java.lang.Integer .parseInt(node.getParentElement().getParentElement().getAttributeValue("ADJUST_LOCK")); Iterator synapses = node.getChildren().iterator(); //iterate through incoming synapses and adjust weights do {/*from w w w. jav a2 s.co m*/ Element currentSynapse = (Element) synapses.next(); String OrgNodeID = currentSynapse.getAttributeValue("ORG_NEURODE"); //if OrgNode !=input then continue else abort/return if (!"INPUT".equals(OrgNodeID) && lock != 1) { Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap, "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']"); double weight = java.lang.Double.parseDouble(currentSynapse.getAttributeValue("WEIGHT")) + (learningRate * (java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY")) * java.lang.Double.parseDouble(node.getAttributeValue("NNET_V4")))); currentSynapse.setAttribute("WEIGHT", String.valueOf(weight)); } } while (synapses.hasNext()); }
From source file:TrainNet.java
License:Apache License
public void adjustBias(Element node) throws JDOMException { //adjusted bias = current bias + LEARNING_RATE * errorGradient int lock = java.lang.Integer .parseInt(node.getParentElement().getParentElement().getAttributeValue("ADJUST_LOCK")); Element currentSynapse = (Element) node.getChild("SYNAPSE"); String OrgNodeID = currentSynapse.getAttributeValue("ORG_NEURODE"); if (!"INPUT".equals(OrgNodeID) && lock != 1) { double bias = java.lang.Double.parseDouble(node.getAttributeValue("BIAS")) + (learningRate * java.lang.Double.parseDouble(node.getAttributeValue("NNET_V4"))); //original ver node.setAttribute("BIAS", String.valueOf(bias)); }// w w w . j av a 2s . c o m }
From source file:Api.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w. ja v a 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("Content-Type: text/javascript"); PrintWriter out = response.getWriter(); // Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("Config.xml"); try { //Se parcea el archivo xml para crear el documento //que se va a tratar. Document documento = (Document) builder.build(xmlFile); // Se obtiene la raiz del documento. En este caso 'cruisecontrol' Element rootNode = documento.getRootElement(); // // Obtengo el tag "info" como nodo raiz para poder trabajar // // los tags de ste. // Element rootNode_Level2 = rootNode.getChild("info"); // // Obtengo los nodos "property" del tag info y los almaceno en // // una lista. // List<Element> lista = rootNode_Level2.getChildren("property"); // // //Imprimo por consola la lista. // for (int i = 0; i < lista.size(); i++) { // System.out.println(((Element) lista.get(i)).getAttributeValue("value")); // } // out.println("<!DOCTYPE html>"); Map<String, Object> actions = new LinkedHashMap<String, Object>(); for (Element action : rootNode.getChildren()) { ArrayList<Map> methods = new ArrayList<Map>(); for (Element method : action.getChildren()) { Map<String, Object> md = new LinkedHashMap<String, Object>(); if (method.getAttribute("len") != null) { md.put("name", method.getName()); md.put("len", method.getAttributeValue("len")); } else { md.put("name", method.getName()); md.put("params", method.getAttributeValue("params")); } if (method.getAttribute("formHandler") != null && method.getAttribute("formHandler") != null) { md.put("formHandler", true); } methods.add(md); } actions.put(action.getName(), methods); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } finally { out.close(); } }
From source file:Erudite_SW_runCmd.java
License:Apache License
public void getOutputs(Document NNetMap) throws JDOMException { Erudite_gui.output = new double[Erudite_gui.outputNID.length]; int oN = 0;/*from w w w . j a v a 2 s . c o m*/ do { String outNodeID = Erudite_gui.outputNID[oN]; Element outNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap, "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + outNodeID + "']"); Erudite_gui.output[oN] = java.lang.Double.parseDouble(outNode.getAttributeValue("ACTIVITY")); oN++; } while (oN < Erudite_gui.output.length); }
From source file:Erudite_SW_trainCmd.java
License:Apache License
private void getErrorGradient(Element node) throws JDOMException { //if-then-else for output/hidden/input layers, if-then for transfer functions, compute error gradient and update nnet map String layerType = node.getParentElement().getAttributeValue("LAYER_NAME").toString(); int xfer = Integer.parseInt(node.getParentElement().getAttributeValue("TRANSFER_FUNCTION")); String nid = node.getAttributeValue("N_ID").toString(); if (layerType.equals("OUTPUT")) { //if computing output neurode error gradient if (xfer == 1) { //if hyperbolic tangent transfer function for (int i = 0; i < Erudite_gui.outputNID.length; i++) { if (nid.equals(Erudite_gui.outputNID[i])) { double error = Erudite_gui.desiredOutput[i] - Erudite_gui.output[i]; double errorGradient = error * ((1 - Erudite_gui.output[i]) * (1 + Erudite_gui.output[i])); node.setAttribute("NNET_V4", String.valueOf(errorGradient)); }//from w w w .j ava 2 s.c om } } else if (xfer == 2) { //if sigmoid transfer function function for (int i = 0; i < Erudite_gui.outputNID.length; i++) { if (nid.equals(Erudite_gui.outputNID[i])) { double error = Erudite_gui.desiredOutput[i] - Erudite_gui.output[i]; double errorGradient = error * (Erudite_gui.output[i] * (1 - Erudite_gui.output[i])); node.setAttribute("NNET_V4", String.valueOf(errorGradient)); } } } } else if (layerType.equals("HIDDEN") || layerType.equals("INPUT")) { //if computing hidden or input neurode error gradient if (xfer == 1) { double sumWouts = 0.0; double nodeActivity = java.lang.Double.parseDouble(node.getAttributeValue("ACTIVITY")); java.util.List outputs = XPath.newInstance("//SYNAPSE[@ORG_NEURODE = '" + nid + "']") .selectNodes(Erudite_gui.NNetMap); Iterator synapseO = outputs.iterator(); do { Element currentNode = (Element) synapseO.next(); sumWouts += java.lang.Double.parseDouble(currentNode.getAttributeValue("WEIGHT")) * java.lang.Double .parseDouble(currentNode.getParentElement().getAttributeValue("NNET_V4")); } while (synapseO.hasNext()); double errorGradient = sumWouts * ((1 - nodeActivity) * (1 + nodeActivity)); node.setAttribute("NNET_V4", String.valueOf(errorGradient)); } else if (xfer == 2) { double sumWouts = 0.0; double nodeActivity = java.lang.Double.parseDouble(node.getAttributeValue("ACTIVITY")); java.util.List outputs = XPath.newInstance("//SYNAPSE[@ORG_NEURODE = '" + nid + "']") .selectNodes(Erudite_gui.NNetMap); Iterator synapseO = outputs.iterator(); do { Element currentNode = (Element) synapseO.next(); sumWouts += java.lang.Double.parseDouble(currentNode.getAttributeValue("WEIGHT")) * java.lang.Double .parseDouble(currentNode.getParentElement().getAttributeValue("NNET_V4")); } while (synapseO.hasNext()); double errorGradient = sumWouts * (nodeActivity * (1 - nodeActivity)); node.setAttribute("NNET_V4", String.valueOf(errorGradient)); } } }
From source file:EvaluateNeurode.java
License:Apache License
public synchronized double sumInput(Element node) throws JDOMException { List SynIns = node.getChildren("SYNAPSE"); double bias = java.lang.Double.parseDouble(node.getAttributeValue("BIAS")); double sumInputs = 0 + bias; for (Iterator itSI = SynIns.iterator(); itSI.hasNext();) { Element SynapseI = (Element) itSI.next(); double weight = java.lang.Double.parseDouble(SynapseI.getAttributeValue("WEIGHT")); String OrgNodeID = SynapseI.getAttributeValue("ORG_NEURODE"); Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap, "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']"); int activeTF = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); if (activeTF == 1) { double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY")); sumInputs += weight * value; } else if (activeTF == -1) { int TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); while (TFcheck != 1) { TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); }/*www. ja va2 s .c om*/ double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY")); sumInputs += weight * value; } else if (activeTF == 0) { sumInputs += 0; } } return sumInputs; }
From source file:AL_gui.java
License:Apache License
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: try {//from w w w .ja v a 2 s .c o m String nnetName = JOptionPane.showInputDialog(jButton3, "Enter a filename, excluding extention.", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (nnetName == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } Element nnet = new Element("NNETWORK"); nnet.setAttribute(new Attribute("noNamespaceSchemaLocation", "ANNeML.xsd", Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"))); nnet.setAttribute(new Attribute("NNET_NAME", nnetName)); Document doc = new Document(nnet); String subnnets = JOptionPane.showInputDialog(jButton3, "How many SUBNET(s)?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (subnnets == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numSubs = java.lang.Integer.parseInt(subnnets); int i = 0; do { Element subnet = new Element("SUBNET"); String learningRate = JOptionPane.showInputDialog(jButton3, "SUBNET learning rate(eta)?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (learningRate == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } subnet.setAttribute(new Attribute("NNET_V2", learningRate)); subnet.setAttribute(new Attribute("SNET_NAME", nnetName + "-subnet" + String.valueOf(i + 1))); subnet.setAttribute(new Attribute("ADJUST_LOCK", "0")); String input_layers = JOptionPane.showInputDialog(jButton3, "How many <<INPUT>> LAYERS(s) in this subnet?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (input_layers == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numInLayers = java.lang.Integer.parseInt(input_layers); int x = 0; do { Element inLayer = new Element("LAYER"); inLayer.setAttribute(new Attribute("LAYER_NAME", "INPUT")); String transferFunc = JOptionPane.showInputDialog(jButton3, "Which transfer function for this LAYER? 1(hyberbolic tangent) or 2(logarithmic sigmoid)", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (transferFunc == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } inLayer.setAttribute(new Attribute("TRANSFER_FUNCTION", transferFunc)); String inNodes = JOptionPane.showInputDialog(jButton3, "How many NEURODE(s) in this <<INPUT>> LAYER?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (inNodes == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numInNodes = java.lang.Integer.parseInt(inNodes); int y = 0; do { Element node = new Element("NEURODE"); node.setAttribute( new Attribute("N_ID", "IN" + String.valueOf(x + 1) + String.valueOf(y + 1))); node.setAttribute(new Attribute("ACTIVE", "-1")); node.setAttribute(new Attribute("ACTIVITY", "0.0")); node.setAttribute(new Attribute("BIAS", "0.0")); node.setAttribute(new Attribute("CNAME", "Input node#" + String.valueOf(y + 1))); node.setAttribute(new Attribute("NNET_V4", "0.0")); Element inSynapse = new Element("SYNAPSE"); inSynapse.setAttribute(new Attribute("WEIGHT", "1.00")); inSynapse.setAttribute(new Attribute("ORG_NEURODE", "INPUT")); node.addContent(inSynapse); inLayer.addContent(node); y++; } while (y < numInNodes); subnet.addContent(inLayer); x++; } while (x < numInLayers); String hidden_layers = JOptionPane.showInputDialog(jButton3, "How many <<HIDDEN>> LAYERS(s) in this subnet?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (hidden_layers == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numHLayers = java.lang.Integer.parseInt(hidden_layers); int z = 0; do { Element hLayer = new Element("LAYER"); hLayer.setAttribute(new Attribute("LAYER_NAME", "HIDDEN")); String transferFunc = JOptionPane.showInputDialog(jButton3, "Which transfer function for this LAYER? 1(hyberbolic tangent) or 2(logarithmic sigmoid)", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (transferFunc == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } hLayer.setAttribute(new Attribute("TRANSFER_FUNCTION", transferFunc)); String hNodes = JOptionPane.showInputDialog(jButton3, "How many NEURODE(s) in this <<HIDDEN>> LAYER?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (hNodes == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numhNodes = java.lang.Integer.parseInt(hNodes); int a = 0; do { Random rnd = new Random(); Element node = new Element("NEURODE"); node.setAttribute( new Attribute("N_ID", "N" + String.valueOf(z + 1) + String.valueOf(a + 1))); node.setAttribute(new Attribute("ACTIVE", "-1")); node.setAttribute(new Attribute("ACTIVITY", "0.0")); node.setAttribute(new Attribute("BIAS", getRandomValue(rnd, low, high, decpl))); node.setAttribute(new Attribute("CNAME", "Hidden node#" + String.valueOf(a + 1))); node.setAttribute(new Attribute("NNET_V4", "0.0")); hLayer.addContent(node); a++; } while (a < numhNodes); subnet.addContent(hLayer); z++; } while (z < numHLayers); String output_layers = JOptionPane.showInputDialog(jButton3, "How many <<OUTPUT>> LAYERS(s) in this subnet?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (hidden_layers == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numOLayers = java.lang.Integer.parseInt(output_layers); int b = 0; do { Element oLayer = new Element("LAYER"); oLayer.setAttribute(new Attribute("LAYER_NAME", "OUTPUT")); String transferFunc = JOptionPane.showInputDialog(jButton3, "Which transfer function for this LAYER? 1(hyberbolic tangent) or 2(logarithmic sigmoid)", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (transferFunc == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } oLayer.setAttribute(new Attribute("TRANSFER_FUNCTION", transferFunc)); String oNodes = JOptionPane.showInputDialog(jButton3, "How many NEURODE(s) in this <<OUTPUT>> LAYER?", "ANNeML Wizard", JOptionPane.QUESTION_MESSAGE); if (oNodes == " ") { JOptionPane.showMessageDialog(null, "An input value must be entered."); } int numoNodes = java.lang.Integer.parseInt(oNodes); int d = 0; do { Random rnd = new Random(); Element node = new Element("NEURODE"); node.setAttribute( new Attribute("N_ID", "ON" + String.valueOf(b + 1) + String.valueOf(d + 1))); node.setAttribute(new Attribute("ACTIVE", "-1")); node.setAttribute(new Attribute("ACTIVITY", "0.0")); node.setAttribute(new Attribute("BIAS", getRandomValue(rnd, low, high, decpl))); node.setAttribute(new Attribute("CNAME", "Output node#" + String.valueOf(d + 1))); node.setAttribute(new Attribute("NNET_V4", "0.0")); oLayer.addContent(node); d++; } while (d < numoNodes); subnet.addContent(oLayer); b++; } while (b < numOLayers); doc.getRootElement().addContent(subnet); i++; } while (i < numSubs); //generate fully interconnected SYNAPSE(s) for all NEURODE(s) within each SUBNET java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(doc); Iterator itSubslist = subnets.iterator(); do { Element currentSnet = (Element) itSubslist.next(); String snetName = currentSnet.getAttributeValue("SNET_NAME"); //System.out.println(snetName); java.util.List Hnodes = XPath .newInstance("//SUBNET[@SNET_NAME='" + snetName + "']/LAYER[@LAYER_NAME='HIDDEN']/NEURODE") .selectNodes(doc); Iterator itHNodelist = Hnodes.iterator(); do { Element node = (Element) itHNodelist.next(); //System.out.println(node.getAttributeValue("N_ID")); java.util.List Inodes = XPath .newInstance( "//SUBNET[@SNET_NAME='" + snetName + "']/LAYER[@LAYER_NAME='INPUT']/NEURODE") .selectNodes(doc); Iterator itNodelist = Inodes.iterator(); do { Element currentNode = (Element) itNodelist.next(); //System.out.println(currentNode.getAttributeValue("N_ID")); Element hSynapse = new Element("SYNAPSE"); Random rnd = new Random(); hSynapse.setAttribute(new Attribute("WEIGHT", getRandomValue(rnd, low, high, decpl))); hSynapse.setAttribute(new Attribute("ORG_NEURODE", currentNode.getAttributeValue("N_ID"))); node.addContent(hSynapse); } while (itNodelist.hasNext()); } while (itHNodelist.hasNext()); java.util.List Onodes = XPath .newInstance("//SUBNET[@SNET_NAME='" + snetName + "']/LAYER[@LAYER_NAME='OUTPUT']/NEURODE") .selectNodes(doc); Iterator itONodelist = Onodes.iterator(); do { Element node = (Element) itONodelist.next(); //System.out.println(node.getAttributeValue("N_ID")); java.util.List hnodes = XPath .newInstance( "//SUBNET[@SNET_NAME='" + snetName + "']/LAYER[@LAYER_NAME='HIDDEN']/NEURODE") .selectNodes(doc); Iterator itNodelist = hnodes.iterator(); do { Element currentNode = (Element) itNodelist.next(); //System.out.println(currentNode.getAttributeValue("N_ID")); Element hSynapse = new Element("SYNAPSE"); Random rnd = new Random(); hSynapse.setAttribute(new Attribute("WEIGHT", getRandomValue(rnd, low, high, decpl))); hSynapse.setAttribute(new Attribute("ORG_NEURODE", currentNode.getAttributeValue("N_ID"))); node.addContent(hSynapse); } while (itNodelist.hasNext()); } while (itONodelist.hasNext()); } while (itSubslist.hasNext()); // new XMLOutputter().output(doc, System.out); XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(doc, System.out); xmlOutput.output(doc, new FileWriter(nnetName + ".xml")); System.out.println("File Saved!"); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:Content.java
public void showPlaylist(String playlistName) { if (playlistName.equals("Library")) { setRightClick(true);/*from w w w .j av a2s . c o m*/ } else { setRightClick(false); } if (nowPlayingInfo != null) { try { nowPlayingInfo.setVisible(false); remove(nowPlayingInfo); } catch (Exception e) { } } currentPlaylist = playlistName; eventEnabled = false; int count = model.getRowCount(); for (int n = 0; n < count; n++) { model.removeRow(0); } if (playlistName.equals("Now Playing")) { playlist.setVisible(false); if (mediaPlayer != null) { try { String loc = mediaPlayer.getMedia().getSource(); for (int i = 0; i < Library.getLib().size(); i++) { if (("file:///" + ((Element) Library.getLib().get(i)).getChildText("url")).equals(loc)) { Element el = ((Element) Library.getLib().get(i)); nowPlayingSong = new JLabel(el.getChildText("name")); nowPlayingArtist = new JLabel(el.getChildText("artist")); nowPlayingAlbum = new JLabel(el.getChildText("album")); nowPlayingInfo = new JPanel(); nowPlayingInfo.setLayout(new BoxLayout(nowPlayingInfo, BoxLayout.PAGE_AXIS)); nowPlayingInfo.add(nowPlayingSong); nowPlayingInfo.add(nowPlayingArtist); nowPlayingInfo.add(nowPlayingAlbum); nowPlayingInfo.setVisible(true); add(nowPlayingInfo, BorderLayout.CENTER); break; } } } catch (Exception e) { } } } else if (playlistName.equals("Library")) { playlist.setVisible(true); List lib = Library.getLib(); for (int i = 0; i < lib.size(); i++) { Element song = (Element) lib.get(i); Vector<String> row = new Vector<String>(); row.add(song.getChildText("name")); row.add(song.getChildText("artist")); row.add(song.getChildText("album")); model.addRow(row); } } else { playlist.setVisible(true); List list = Library.getList(); for (int i = 0; i < list.size(); i++) { Element node = (Element) list.get(i); if (node.getAttributeValue("id") == playlistName) { List children = node.getChildren(); for (int j = 0; j < children.size(); j++) { Element entry = (Element) children.get(j); String entryNum = entry.getText(); List lib = Library.getLib(); for (int k = 0; k < lib.size(); k++) { if (((Element) lib.get(k)).getAttributeValue("id").equals(entryNum)) { Element song = (Element) lib.get(k); Vector<String> row = new Vector<String>(); row.add(song.getChildText("name")); row.add(song.getChildText("artist")); row.add(song.getChildText("album")); model.addRow(row); } } } } } playlist.revalidate(); revalidate(); eventEnabled = true; } }
From source file:Content.java
public void playSelected() { if (playlist.getSelectedRow() == -1) { try {/*from w w w .java 2s . c o m*/ playlist.setRowSelectionInterval(0, 0); } catch (Exception e) { return; } } if (currentPlaylist.equals("Library")) { if (mediaPlayer != null) { mediaPlayer.stop(); } try { List lib = Library.getLib(); Element child = (Element) lib.get(playlist.getSelectedRow()); if (child.getChildText("url").indexOf("http://") != -1) { Desktop.getDesktop().browse(new URI(child.getChildText("url"))); return; } if (child.getChildText("url").toLowerCase().indexOf("youtube") != -1) { Desktop.getDesktop().browse(new URI(child.getChildText("url"))); return; } if (child.getChildText("url").toLowerCase().indexOf(".com") != -1) { Desktop.getDesktop().browse(new URI(child.getChildText("url"))); return; } String loc = "file:///" + child.getChildText("url"); Media media = new Media(loc); mediaPlayer = new MediaPlayer(media); nowPlayingIndex = playlist.getSelectedRow(); mediaPlayer.play(); mediaPlayer.setOnEndOfMedia(new Runnable() { public void run() { playNext(); } }); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error playing media - please check the song location"); } } else { if (mediaPlayer != null) { mediaPlayer.stop(); } List list = Library.getList(); for (int i = 0; i < list.size(); i++) { Element node = (Element) list.get(i); if (node.getAttributeValue("id").equals(currentPlaylist)) { Element elem = (Element) node.getChildren().get(playlist.getSelectedRow()); String entryNum = elem.getText(); try { if (mediaPlayer != null) { mediaPlayer.stop(); } for (int j = 0; j < Library.getLib().size(); j++) { Element current = (Element) Library.getLib().get(j); if (current.getAttributeValue("id").equals(entryNum)) { if (current.getChildText("url").indexOf("http://") != -1) { Desktop.getDesktop().browse(new URI(current.getChildText("url"))); return; } if (current.getChildText("url").toLowerCase().indexOf("youtube") != -1) { Desktop.getDesktop().browse(new URI(current.getChildText("url"))); return; } if (current.getChildText("url").toLowerCase().indexOf(".com") != -1) { Desktop.getDesktop().browse(new URI(current.getChildText("url"))); return; } String loc = "file:///" + current.getChildText("url"); Media media = new Media(loc); mediaPlayer = new MediaPlayer(media); mediaPlayer.play(); nowPlayingIndex = playlist.getSelectedRow(); mediaPlayer.setOnEndOfMedia(new Runnable() { public void run() { playNext(); } }); } } } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error playing media - please check the song location"); } } } } }
From source file:Erudite_gui.java
License:Apache License
public void loadFile(String pathname, String filename) { jLabel6.setEnabled(true);//w w w . ja v a 2 s .co m jLabel7.setEnabled(true); jButton3.setEnabled(true); jButton4.setEnabled(true); jCheckBox1.setSelected(false); jCheckBox1.setEnabled(true); jEditorPane1.setEnabled(true); DefaultTableModel tblmodel = (DefaultTableModel) jTable2.getModel(); tblmodel.setRowCount(0); try { // Build & creat the document with SAX, use XML schema validation URL path = ClassLoader.getSystemResource("ANNeML.xsd"); if (path.getFile() == null) { jLabel2.setForeground(Color.RED); jLabel2.setText("error loading XML schema"); } else { //File argylexsd = new File(path.toURI()); //XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(argylexsd); XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory("ANNeML.xsd"); //***for .jar deployment SAXBuilder builder = new SAXBuilder(schemafac); Erudite_gui.NNetMap = builder.build(pathname); JDOMToTreeModelAdapter model = new JDOMToTreeModelAdapter(Erudite_gui.NNetMap); XMLTreeCellRenderer renderer = new XMLTreeCellRenderer(); jTree1.setCellRenderer(renderer); jTree1.setModel(model); java.util.List subnets = XPath.newInstance("//SUBNET").selectNodes(Erudite_gui.NNetMap); java.util.List layers = XPath.newInstance("//LAYER").selectNodes(Erudite_gui.NNetMap); java.util.List inputNeurodes = XPath.newInstance("//NEURODE[SYNAPSE/@ORG_NEURODE='INPUT']") .selectNodes(Erudite_gui.NNetMap); java.util.List hiddenNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='HIDDEN']/NEURODE") .selectNodes(Erudite_gui.NNetMap); java.util.List outputNeurodes = XPath.newInstance("//LAYER[@LAYER_NAME='OUTPUT']/NEURODE") .selectNodes(Erudite_gui.NNetMap); Color colr = new Color(0, 153, 255); jLabel2.setForeground(colr); jLabel2.setText("Valid ANNeML file."); HTMLEditorKit kit = (HTMLEditorKit) jEditorPane1.getEditorKit(); HTMLDocument doc = (HTMLDocument) jEditorPane1.getDocument(); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + filename + " loaded...</b>", 0, 0, null); jLabel3.setText("Subnet(s): " + subnets.size() + " Layers: " + layers.size() + " Inputs: " + inputNeurodes.size() + " Hidden: " + hiddenNeurodes.size() + " Outputs: " + outputNeurodes.size()); jLabel7.setText(java.lang.String.valueOf(inputNeurodes.size())); Erudite_gui.inputNID = new String[inputNeurodes.size()]; Erudite_gui.inputCNAME = new String[inputNeurodes.size()]; Erudite_gui.outputNID = new String[outputNeurodes.size()]; Erudite_gui.outputCNAME = new String[outputNeurodes.size()]; int i = 0; for (Iterator it = inputNeurodes.iterator(); it.hasNext();) { Element InputNode = (Element) it.next(); Erudite_gui.inputNID[i] = InputNode.getAttributeValue("N_ID"); Erudite_gui.inputCNAME[i] = InputNode.getAttributeValue("CNAME"); tblmodel.addRow( new String[] { null, Erudite_gui.inputNID[i] + " '" + inputCNAME[i] + "' ", null }); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + inputNID[i] + "</b> " + inputCNAME[i] + "<br>", 0, 0, null); i++; } int y = 0; for (Iterator it = outputNeurodes.iterator(); it.hasNext();) { Element OutputNode = (Element) it.next(); Erudite_gui.outputCNAME[y] = OutputNode.getAttributeValue("CNAME"); Erudite_gui.outputNID[y] = OutputNode.getAttributeValue("N_ID"); kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "<b>" + outputNID[y] + "</b> " + outputCNAME[y] + "<br>", 0, 0, null); y++; } kit.insertHTML(doc, jEditorPane1.getCaretPosition(), "Ready for input processing or training...<br><br>", 0, 0, null); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(jPanel1, "There was an error parsing the file.\n" + e.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } }