List of usage examples for javax.swing JOptionPane showInputDialog
public static String showInputDialog(Component parentComponent, Object message) throws HeadlessException
parentComponent
. From source file:com.cch.aj.entryrecorder.frame.HomeJFrame.java
private void btnSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSettingsActionPerformed String login = JOptionPane.showInputDialog(this, "Please enter 'UserName/Password'"); if (login != null && (login.equals("aj") || login.equals("admin/ajpro123"))) { SettingsJFrame sf = AppContext.getApplicationContext().getBean("SettingsJFrame", SettingsJFrame.class); sf.setVisible(true);// w w w . jav a 2 s . c om } }
From source file:coolmap.application.widget.impl.WidgetUserGroup.java
private void initPopup() { JPopupMenu popup = new JPopupMenu(); table.setComponentPopupMenu(popup);/*from w w w. j ava2s . c o m*/ JMenuItem item = new JMenuItem("Rename"); popup.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<String> groupNames = getSelectedGroups(); if (groupNames.isEmpty()) { return; } String returnVal = JOptionPane.showInputDialog(CoolMapMaster.getCMainFrame(), "Please provide a new name:"); if (returnVal == null || returnVal.length() == 0) { returnVal = "Untitled"; } int counter = 0; String newName; for (String groupName : groupNames) { if (counter == 0) { newName = returnVal; } else { newName = returnVal + "_" + counter; } //new name must not exist int subCounter = 0; String name = newName; while (nodeGroups.containsKey(name)) { subCounter++; name = newName + "_" + subCounter; } newName = name; Color c = nodeColor.get(groupName); Set<VNode> nodes = new HashSet(nodeGroups.get(groupName)); nodeColor.remove(groupName); nodeGroups.removeAll(groupName); nodeColor.put(newName, c); nodeGroups.putAll(newName, nodes); // System.out.println(newName + " " + c + " " + nodes); counter++; } updateTable(); } }); //////////////////////////////////////////////////////////////////////// //remove operations item = new JMenuItem("Remove"); popup.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<String> groupNames = getSelectedGroups(); for (String group : groupNames) { nodeColor.remove(group); nodeGroups.removeAll(group); } updateTable(); } }); //add separarator popup.addSeparator(); JMenu insertRow = new JMenu("Add selected to row"); popup.add(insertRow); JMenu insertColumn = new JMenu("Add selected to column"); popup.add(insertColumn); item = new JMenuItem("prepend", UI.getImageIcon("prependRow")); insertRow.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { insertRow(0); } }); item = new JMenuItem("prepend", UI.getImageIcon("prependColumn")); insertColumn.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { insertColumn(0); } }); item = new JMenuItem("insert", UI.getImageIcon("insertRow")); item.setToolTipText("Insert selected groups to the selected region in the active coolmap view"); insertRow.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject(); if (obj == null) { return; } int index = 0; ArrayList selectedRows = obj.getCoolMapView().getSelectedRows(); if (!selectedRows.isEmpty()) { index = ((Range<Integer>) selectedRows.iterator().next()).lowerEndpoint(); } insertRow(index); } }); item = new JMenuItem("insert", UI.getImageIcon("insertColumn")); item.setToolTipText("Insert selected groups to the selected region in the active coolmap view"); insertColumn.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject(); if (obj == null) { return; } int index = 0; ArrayList selectedColumns = obj.getCoolMapView().getSelectedColumns(); if (!selectedColumns.isEmpty()) { index = ((Range<Integer>) selectedColumns.iterator().next()).lowerEndpoint(); } insertColumn(index); } }); item = new JMenuItem("append", UI.getImageIcon("appendRow")); insertRow.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (CoolMapMaster.getActiveCoolMapObject() == null) { return; } insertRow(CoolMapMaster.getActiveCoolMapObject().getViewNumRows()); } }); item = new JMenuItem("append", UI.getImageIcon("appendColumn")); insertColumn.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (CoolMapMaster.getActiveCoolMapObject() == null) { return; } insertColumn(CoolMapMaster.getActiveCoolMapObject().getViewNumColumns()); } }); item = new JMenuItem("replace", UI.getImageIcon("replaceRow")); insertRow.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { replaceRow(); } }); item = new JMenuItem("replace", UI.getImageIcon("replaceColumn")); insertColumn.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { replaceColumn(); } }); }
From source file:io.github.jeddict.relation.mapper.widget.table.RelationTableWidget.java
private void convertToJoinColumn() { DBRelationTable relationTable = this.getBaseElementSpec(); relationTable.getAttribute().getJoinTable().clear(); if (relationTable.getAttribute() instanceof OneToMany) { String joinColumnName = JOptionPane.showInputDialog( (Component) RelationTableWidget.this.getModelerScene().getModelerPanelTopComponent(), "Please enter join column name (required) :"); ((JoinColumnHandler) relationTable.getAttribute()).getJoinColumn().clear(); JoinColumn joinColumn = new JoinColumn(); joinColumn.setName(joinColumnName); ((JoinColumnHandler) relationTable.getAttribute()).addJoinColumn(joinColumn); }//from w ww. j a va 2s . c om }
From source file:net.sf.jabref.importer.fetcher.MedlineFetcher.java
@Override public boolean processQuery(String query, ImportInspector iIDialog, OutputPrinter frameOP) { shouldContinue = true;//from w w w . j av a 2 s . c o m String cleanQuery = query.trim().replace(';', ','); if (cleanQuery.matches("\\d+[,\\d+]*")) { frameOP.setStatus(Localization.lang("Fetching Medline by id...")); List<BibEntry> bibs = fetchMedline(cleanQuery, frameOP); if (bibs.isEmpty()) { frameOP.showMessage(Localization.lang("No references found")); } for (BibEntry entry : bibs) { iIDialog.addEntry(entry); } return true; } if (!query.isEmpty()) { frameOP.setStatus(Localization.lang("Fetching Medline by term...")); String searchTerm = toSearchTerm(query); // get the ids from entrez SearchResult result = getIds(searchTerm, 0, 1); if (result.count == 0) { frameOP.showMessage(Localization.lang("No references found")); return false; } int numberToFetch = result.count; if (numberToFetch > MedlineFetcher.PACING) { while (true) { String strCount = JOptionPane.showInputDialog( Localization.lang("References found") + ": " + numberToFetch + " " + Localization.lang("Number of references to fetch?"), Integer.toString(numberToFetch)); if (strCount == null) { frameOP.setStatus(Localization.lang("%0 import canceled", "Medline")); return false; } try { numberToFetch = Integer.parseInt(strCount.trim()); break; } catch (NumberFormatException ex) { frameOP.showMessage(Localization.lang("Please enter a valid number")); } } } for (int i = 0; i < numberToFetch; i += MedlineFetcher.PACING) { if (!shouldContinue) { break; } int noToFetch = Math.min(MedlineFetcher.PACING, numberToFetch - i); // get the ids from entrez result = getIds(searchTerm, i, noToFetch); List<BibEntry> bibs = fetchMedline(result.ids, frameOP); for (BibEntry entry : bibs) { iIDialog.addEntry(entry); } iIDialog.setProgress(i + noToFetch, numberToFetch); } return true; } frameOP.showMessage( Localization.lang("Please enter a comma separated list of Medline IDs (numbers) or search terms."), Localization.lang("Input error"), JOptionPane.ERROR_MESSAGE); return false; }
From source file:playground.sergioo.capacitiesChanger2012.gui.NetworkPanel.java
@Override public void mouseClicked(MouseEvent e) { double[] p = getWorld(e.getX(), e.getY()); if (e.getClickCount() == 2) { if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON1) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]); Link link = ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager() .getSelectedLink();/* w w w . j a v a2 s . c o m*/ try { link.setCapacity( Double.parseDouble(JOptionPane.showInputDialog("New capacity", link.getCapacity()))); } catch (Exception e2) { } ((SimpleSelectionNetworkPainter) getActiveLayer().getPainter()).calculateMinMax(); window.refreshLabel(Labels.LINK); } else if (e.getButton() == MouseEvent.BUTTON3) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]); Link link = ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager() .getSelectedLink(); try { link.setFreespeed( Double.parseDouble(JOptionPane.showInputDialog("New free speed", link.getFreespeed()))); } catch (Exception e2) { } ((SimpleSelectionNetworkPainter) getActiveLayer().getPainter()).calculateMinMax(); window.refreshLabel(Labels.LINK); } } else { if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON1) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectLink(p[0], p[1]); window.refreshLabel(Labels.LINK); } else if (window.getOption().equals(Options.SELECT_LINK) && e.getButton() == MouseEvent.BUTTON3) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().unselectLink(); window.refreshLabel(Labels.LINK); } else if (window.getOption().equals(Options.SELECT_NODE) && e.getButton() == MouseEvent.BUTTON1) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().selectNode(p[0], p[1]); window.refreshLabel(Labels.NODE); } else if (window.getOption().equals(Options.SELECT_NODE) && e.getButton() == MouseEvent.BUTTON3) { ((NetworkPainter) getActiveLayer().getPainter()).getNetworkPainterManager().unselectNode(); window.refreshLabel(Labels.NODE); } else if (window.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON1) camera.zoomIn(p[0], p[1]); else if (window.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON3) camera.zoomOut(p[0], p[1]); } repaint(); }
From source file:client.gui.ButtonPanel.java
@Override public void actionPerformed(final ActionEvent event) { if (GlobalVariables.connected) { if (event.getSource() == exchangeCards) { try { final JSONArray toSend = new JSONArray(); toSend.put(new JSONObject().put("action", "exchange_cards")); for (int i = 0; i < GlobalVariables.hand.length; i++) { if (!(GlobalVariables.chosen[i])) { continue; }//from ww w . j a v a 2 s .c o m toSend.put(new JSONObject().put("suit", GlobalVariables.hand[i].getSuit()).put("rank", GlobalVariables.hand[i].getRank())); } GlobalVariables.chosen = new boolean[] { false, false, false, false }; GlobalVariables.out.println(toSend); System.out.println("[DEBUG] " + toSend); } catch (JSONException e) { e.printStackTrace(); } } else if (event.getSource() == startGame) { try { final JSONArray toSend = new JSONArray(); toSend.put(new JSONObject().put("action", "start_game")); GlobalVariables.out.println(toSend); System.out.println("[DEBUG] " + toSend); } catch (JSONException e) { e.printStackTrace(); } } else if (event.getSource() == smallBlind) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "small_blind")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == bigBlind) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "big_blind")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == call) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "call")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == raise) { int raise; try { raise = Integer.parseInt(JOptionPane.showInputDialog(this, "Type your bet:")); } catch (NumberFormatException e) { new MyDialog("This isn't a number").setVisible(true); return; } final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "raise")); toSend.put(new JSONObject().put("bet", raise)); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == bet) { int bet; try { bet = Integer.parseInt(JOptionPane.showInputDialog(this, "Type your bet:")); } catch (NumberFormatException e) { new MyDialog("This isn't a number").setVisible(true); return; } final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "bet")); toSend.put(new JSONObject().put("bet", bet)); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == check) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "check")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == fold) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "fold")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == allIn) { final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "all-in")); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } else if (event.getSource() == liveBlind) { int raise; try { raise = Integer.parseInt(JOptionPane.showInputDialog(this, "Type your bet:")); } catch (NumberFormatException e) { new MyDialog("This isn't a number").setVisible(true); return; } final JSONArray toSend = new JSONArray(); try { toSend.put(new JSONObject().put("action", "live_blind")); toSend.put(new JSONObject().put("bet", raise)); } catch (JSONException e) { e.printStackTrace(); } GlobalVariables.out.println(toSend); } hideAll(); // GlobalVariables.panel.repaint(); } }
From source file:net.sf.jabref.importer.fetcher.JSTORFetcher2.java
private String getCitationsFromUrl(String urlQuery, List<String> ids, int count, String[] numberOfRefs, ImportInspector dialog, OutputPrinter status) throws IOException { URL url = new URL(urlQuery); URLDownload ud = new URLDownload(url); String cont = ud.downloadToString(); String entirePage = cont;//from ww w . ja v a 2s. c om String pageEntire = cont; int countOfRefs = 0; int refsRequested; if (count == 1) { // Readin the numberofhits (only once) Matcher mn = JSTORFetcher2.numberofhits.matcher(pageEntire); if (mn.find()) { //System.out.println("JSTORFetcher2 getCitationsFromUrl numberofhits=" + mn.group(1)); numberOfRefs[0] = mn.group(1); countOfRefs = Integer.valueOf(numberOfRefs[0]); //System.out.println("JSTORFetcher2 getCitationsFromUrl numberofrefs[0]=" + Integer.valueOf(numberOfRefs[0])); } else { //System.out.println("JSTORFetcher2 getCitationsFromUrl cant find numberofhits="); numberOfRefs[0] = "0"; } while (true) { String strCount = JOptionPane.showInputDialog( Localization.lang("References found") + ": " + countOfRefs + " " + Localization.lang("Number of references to fetch?"), Integer.toString(countOfRefs)); if (strCount == null) { status.setStatus(Localization.lang("JSTOR import cancelled")); return JSTORFetcher2.CANCELLED; } try { numberOfRefs[1] = strCount.trim(); refsRequested = Integer.parseInt(numberOfRefs[1]); break; } catch (RuntimeException ex) { status.showMessage(Localization.lang("Please enter a valid number")); } } } countOfRefs = Integer.valueOf(numberOfRefs[0]); refsRequested = Integer.valueOf(numberOfRefs[1]); Matcher m = JSTORFetcher2.idPattern.matcher(cont); if (m.find() && ((ids.size() + 1) <= refsRequested)) { do { ids.add(m.group(1)); cont = cont.substring(m.end()); m = JSTORFetcher2.idPattern.matcher(cont); } while (m.find() && ((ids.size() + 1) <= refsRequested)); } else if (entirePage.contains(JSTORFetcher2.noAccessIndicator)) { noAccessFound = true; return null; } else { return null; } m = JSTORFetcher2.nextPagePattern.matcher(entirePage); if (m.find()) { return JSTORFetcher2.JSTOR_URL + m.group(1); } else { return null; } }
From source file:MetaFramework.Bayesian.java
/** * Computes the bayesian statistics for enrichment for all the relevant pathways and it prints the results to a * file./* w w w .ja v a2 s . c o m*/ * * @param bicluster Bicluster for which the enrichment analysis will be done * @param engine Engine/Parser with the geneToPathway and pathToGene hashsets. * @param dataset Dataset from which biclusters are computed * @param colChoice Column on which differentiation will be done. -1 Means diff expressed genes will be computed over columns */ public void compute(Bicluster bicluster, AbstractPathwayAnalysis<E, T, G> engine, Dataset dataset, int colChoice) throws Exception { // Idea is to compute Bayesian statistics for the given gene list/cluster and term ArrayList<String> geneNames = new ArrayList<String>(); // System.out.println(bicluster.getGenes().length); for (int i = 0; i < bicluster.getGenes().length; i++) { geneNames.add(dataset.getGeneName(bicluster.getGenes()[i])); } // System.out.println(geneNames.size()); Set<String> allPathways = getAllPath(geneNames, engine); ArrayList<String> diffGenes = new ArrayList<String>(); if (colChoice == -1) { // Diff expression diffGenes = calculateDiff(bicluster, colChoice, dataset, -1.0); // Threshold does not matter here // System.out.println("Number of differentially expressed genes : " + diffGenes.size()); } else { // Column based differentiation // Make sure it is binary (0/1 or false/true) // And 1 basically means differentiated String threshold = Double.toString(Double.MAX_VALUE); if (!checkForBinary(dataset, colChoice)) { // If not binary, then ask for a threshold (smaller -> notDiff, higher -> Diff) threshold = JOptionPane.showInputDialog(null, "Column values are not binary! Please input a threshold for differentiation:"); } // Now that we know the threshold, we should be fine diffGenes = calculateDiff(bicluster, colChoice, dataset, Double.parseDouble(threshold)); } // System.out.println("Some debug results : "); // System.out.println("Number of diff genes : " + diffGenes.size()); // for (String dTm : diffGenes) // System.out.println("Diff gene : " + dTm); Set<String> notDiffGenes = MatrixFunctions.setDifference(geneNames, new HashSet<String>(diffGenes)); // System.out.println("Amount of pathways : " + allPathways); // if (diffGenes.size() != 0) // { // System.out.println(notDiffGenes.size()); // } for (String tmp : allPathways) { G pathTmp = pathClass.newInstance(); pathTmp.setInteractions(null); pathTmp.setId(0); pathTmp.setMolList(null); pathTmp.setName(tmp); ArrayList<E> molecules = engine.getPathToGene().get(pathTmp); ArrayList<String> genesInPathway = new ArrayList<String>(); for (E mol : molecules) genesInPathway.add(mol.getName()); int nMin = (int) (1); // At least 20 percent of input genes should be part of the pathway int xMin = 1; // Let's say at least 1 gene should be diff expressed Set<String> genesInOther = new HashSet<String>(); // Getting all the genes from other pathways. for (String tmp2 : allPathways) { if (!tmp.equalsIgnoreCase(tmp2)) { G pathTmp2 = pathClass.newInstance(); pathTmp2.setInteractions(null); pathTmp2.setId(0); pathTmp2.setMolList(null); pathTmp2.setName(tmp2); ArrayList<E> mols = engine.getPathToGene().get(pathTmp2); ArrayList<String> molNames = new ArrayList<String>(); for (Molecule molT : mols) molNames.add(molT.getName()); genesInOther.addAll(molNames); } } Set<String> genesOnlyPathway = MatrixFunctions.setDifference(genesInPathway, genesInOther); Set<String> genesNotPathway = MatrixFunctions.setDifference(genesInOther, genesInPathway); // Computation of relevant terms int x1OnlyPathway = MatrixFunctions.intersection(genesOnlyPathway, diffGenes).size(); // x1OnlyPathway = 0; int x0OnlyPathway = MatrixFunctions.intersection(genesOnlyPathway, notDiffGenes).size(); // x0OnlyPathway = 0; int nOnlyPath = genesOnlyPathway.size(); // nOnlyPath = 0; int x1PathAnd = MatrixFunctions.intersection(genesInPathway, diffGenes).size() - x1OnlyPathway; // x1PathAnd = 4; int x0PathAnd = MatrixFunctions.intersection(genesInPathway, notDiffGenes).size() - x0OnlyPathway; // x0PathAnd = 2; int nAnd = MatrixFunctions.setDifference(genesInPathway, genesOnlyPathway).size(); // nAnd = 6; int x1NoPathway = MatrixFunctions.intersection(genesNotPathway, diffGenes).size(); // x1NoPathway = 380; int x0NoPathway = MatrixFunctions.intersection(genesNotPathway, notDiffGenes).size(); // x0NoPathway = 3590; int nNoPath = genesNotPathway.size(); // nNoPath = 380 + 3590; double gHat = GScore(x1OnlyPathway, x1PathAnd, x1NoPathway, x0OnlyPathway, x0PathAnd, x0NoPathway); // if (gHat != 0) // System.out.println("Ghat is : " + gHat); int x1Path = x1OnlyPathway + x1PathAnd; // System.out.println("Genes in Pathways : " + genesInPathway.size() + " , x1Path : " + x1Path); if (!(genesInPathway.size() < nMin) && !(x1Path < xMin) && !(gHat <= 0)) { // System.out.println("Not skipping"); double[] gObs = new double[nSim]; // Do not skip the loop, still continue if (genesInPathway.size() > (x1OnlyPathway + x0OnlyPathway + x1PathAnd + x0PathAnd)) { ArrayList<Double> X1onlyPath = RPosterior(nSim, x1OnlyPathway, x1OnlyPathway + x0OnlyPathway, nOnlyPath); double[] X0onlyPath = MatrixFunctions.constantMinusVector(nOnlyPath, X1onlyPath); ArrayList<Double> X1andPath = RPosterior(nSim, x1PathAnd, x1PathAnd + x0PathAnd, nAnd); double[] X0andPath = MatrixFunctions.constantMinusVector(nAnd, X1andPath); ArrayList<Double> X1noPath = RPosterior(nSim, x1NoPathway, x1NoPathway + x0NoPathway, nNoPath); double[] X0noPath = MatrixFunctions.constantMinusVector(nNoPath, X1noPath); // gObs will be used for the comparison vs simulation results gObs = GScoreMatrix(X1onlyPath, X1andPath, X1noPath, X0onlyPath, X0andPath, X0noPath); // System.out.println("For debug"); } else { double X1onlyPath = x1OnlyPathway; double X0onlyPath = nOnlyPath - X1onlyPath; double X1andPath = x1OnlyPathway; double X0andPath = nAnd - X1andPath; double X1noPath = x1NoPathway; double X0noPath = nNoPath - X1noPath; for (int k = 0; k < nSim; k++) gObs[k] = gHat; } double[] gRand = new double[nSim]; // Random simulations loop. // NOTE: As you will see in the comments in the loop, some of the variables actually should be replaced // in case there is an existence of knowledge about observability of certain genes for (int j = 0; j < nSim; j++) { // Simulation loop int n = Math.min(poisson(diffGenes.size()), geneNames.size()); // 2nd argument is actually number of observed genes Set<String> diffRandom = new HashSet<String>(); Random random = new Random(); for (int i = 0; i < n; i++) { diffRandom.add(geneNames.get(random.nextInt(geneNames.size()))); } Set<String> notDiffRandom = MatrixFunctions.setDifference(geneNames, diffRandom); int x1OnlyPathR = MatrixFunctions.intersection(genesOnlyPathway, diffRandom).size(); int x0OnlyPathR = MatrixFunctions.intersection(genesOnlyPathway, notDiffRandom).size(); int nOnlyPathR = genesOnlyPathway.size(); int x1AndPathR = MatrixFunctions.intersection(genesInPathway, diffRandom).size() - x1OnlyPathR; int x0AndPathR = MatrixFunctions.intersection(genesInPathway, notDiffRandom).size() - x0OnlyPathR; int nPathAndR = MatrixFunctions.setDifference(genesInPathway, genesOnlyPathway).size(); int x1NoPathR = MatrixFunctions.intersection(genesNotPathway, diffRandom).size(); int x0NoPathR = MatrixFunctions.intersection(genesNotPathway, notDiffRandom).size(); int nNoPathR = genesNotPathway.size(); ArrayList<Double> X1onlyPathR = RPosterior(1, x1OnlyPathR, x1OnlyPathR + x0OnlyPathR, nOnlyPathR); double[] X0onlyPathR = new double[X1onlyPathR.size()]; for (int k = 0; k < X0onlyPathR.length; k++) { X0onlyPathR[k] = nOnlyPathR - X1onlyPathR.get(k); } ArrayList<Double> X1andPathR = RPosterior(1, x1AndPathR, x1AndPathR + x0AndPathR, nPathAndR); double[] X0andPathR = new double[X1andPathR.size()]; for (int k = 0; k < X0andPathR.length; k++) { X0andPathR[k] = nPathAndR - X1andPathR.get(k); } ArrayList<Double> X1noPathR = RPosterior(1, x1NoPathR, x1NoPathR + x0NoPathR, nNoPathR); double[] X0noPathR = new double[X1noPathR.size()]; for (int k = 0; k < X1noPathR.size(); k++) { X0noPathR[k] = nNoPathR - X1noPathR.get(k); } gRand[j] = GScoreMatrix(X1onlyPathR, X1andPathR, X1noPathR, X0onlyPathR, X0andPathR, X0noPathR)[0]; } // Simulations are done, so let's start comparing the results int cnt = 0; for (int j = 0; j < nSim; j++) if (gRand[j] >= gObs[j]) cnt++; outFile.println("Results for : " + tmp); double result = (cnt + 0.0) / (nSim + 0.0); // 0.0 is needed to push for the double division if (result <= 0.05) outFile.println("Pathway with name : " + tmp + " has p-value of : " + result); // computing error bars double errorLeft = Math.min(quantile(gObs, 0.05), gHat); double errorRight = Math.max(quantile(gObs, 0.95), gHat); outFile.println("G hat : " + gHat); outFile.println("Errorbar : [" + errorLeft + ", " + errorRight + "]"); outFile.println("There were " + bicluster.getGenes().length + " genes. " + diffGenes.size() + " were diff expressed. Pathway has " + genesInPathway.size() + " genes"); outFile.println( "From the diff expressed genes, " + (x1PathAnd + x1OnlyPathway) + " were in the pathway"); } else { outFile.println("Results for : " + tmp); outFile.println("GHat : " + gHat); outFile.println("There were " + bicluster.getGenes().length + " genes. " + diffGenes.size() + " were diff expressed. Pathway has " + genesInPathway.size() + " genes"); outFile.println( "From the diff expressed genes, " + (x1PathAnd + x1OnlyPathway) + " were in the pathway"); } outFile.println("-------------------------------"); } }
From source file:com.raceup.fsae.test.TesterGui.java
/** * Creates new edit menu//w w w . jav a 2s. co m * * @return edit menu */ private JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); // file menu JMenuItem item = new JMenuItem("Test submissions seconds wait"); item.addActionListener(e -> { String userInput = JOptionPane.showInputDialog("Test submissions seconds wait", SECONDS_WAIT_BETWEEN_SUBMISSIONS); SECONDS_WAIT_BETWEEN_SUBMISSIONS = Integer.parseInt(userInput); // update }); menu.add(item); return menu; }
From source file:net.sf.jabref.external.ExternalFilePanel.java
public void downLoadFile(final String fieldName, final FieldEditor fieldEditor, final Component parent) { final String res = JOptionPane.showInputDialog(parent, Localization.lang("Enter URL to download")); if ((res == null) || res.trim().isEmpty()) { return;//from w w w . j av a 2 s . com } /* * If this panel belongs in an entry editor, note which entry is * currently shown: */ final BibEntry targetEntry; if (entryEditor != null) { targetEntry = entryEditor.getEntry(); } else { targetEntry = entry; } JabRefExecutorService.INSTANCE.execute(new Runnable() { public String getPlannedFileName(String result) { String suffix = off.getSuffix(result); if (suffix == null) { suffix = '.' + fieldName.toLowerCase(); } String plannedName; if (getKey() != null) { plannedName = getKey() + suffix; } else { plannedName = JOptionPane.showInputDialog(parent, Localization.lang("BibTeX key not set. Enter a name for the downloaded file")); if ((plannedName != null) && !off.accept(plannedName)) { plannedName += suffix; } } /* * [ 1548875 ] download pdf produces unsupported filename * * http://sourceforge.net/tracker/index.php?func=detail&aid=1548875&group_id=92314&atid=600306 * */ if (OS.WINDOWS) { plannedName = plannedName.replaceAll("\\?|\\*|\\<|\\>|\\||\\\"|\\:|\\.$|\\[|\\]", ""); } else if (OS.OS_X) { plannedName = plannedName.replaceAll(":", ""); } return plannedName; } @Override public void run() { String originalText = fieldEditor.getText(); fieldEditor.setEnabled(false); boolean updateEditor = true; try { fieldEditor.setText(Localization.lang("Downloading...")); output(Localization.lang("Downloading...")); String plannedName = getPlannedFileName(res); // Find the default directory for this field type: String[] dirs = metaData.getFileDirectory(fieldName); String directory = null; // Look for the first one in the list that exists: for (String dir : dirs) { if (new File(dir).exists()) { directory = dir; break; } } if (directory == null) { if (dirs.length > 0) { JOptionPane.showMessageDialog(parent, Localization.lang("Could not find directory for %0-files: %1", fieldName, dirs[0]), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(parent, Localization.lang("No directory defined for %0-files", fieldName), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); } return; } File file = new File(new File(directory), plannedName); URL url = new URL(res); try { MonitoredURLDownload.buildMonitoredDownload(parent, url).downloadToFile(file); } catch (IOException e2) { JOptionPane.showMessageDialog(parent, Localization.lang("Invalid URL") + ": " + e2.getMessage(), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Error while downloading " + url, e2); return; } output(Localization.lang("Download completed")); String textToSet = file.getPath(); if (textToSet.startsWith(directory)) { // Construct path relative to pdf base dir textToSet = textToSet.substring(directory.length(), textToSet.length()); // Remove leading path separator if (textToSet.startsWith(File.separator)) { textToSet = textToSet.substring(File.separator.length()); } } /* * Check if we should update the editor text field, or * update the target entry directly: */ if ((entryEditor == null) || (entryEditor.getEntry() != targetEntry)) { /* * Editor has probably changed to show a different * entry. So we must update the target entry directly * and not set the text of the editor. */ targetEntry.setField(fieldName, textToSet); fieldEditor.setText(textToSet); fieldEditor.setEnabled(true); updateEditor = false; } else { /* * Need to set the fieldEditor first before running * updateField-Action, because otherwise we might get a * race condition. * * (Hopefully a) Fix for: [ 1545601 ] downloading pdf * corrupts pdf field text * * http://sourceforge.net/tracker/index.php?func=detail&aid=1545601&group_id=92314&atid=600306 */ fieldEditor.setText(textToSet); fieldEditor.setEnabled(true); updateEditor = false; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { entryEditor.updateField(fieldEditor); } }); } } catch (MalformedURLException e1) { JOptionPane.showMessageDialog(parent, Localization.lang("Invalid URL"), Localization.lang("Download file"), JOptionPane.ERROR_MESSAGE); } finally { // If stuff goes wrong along the road, put back original // value if (updateEditor) { fieldEditor.setText(originalText); fieldEditor.setEnabled(true); } } } }); }