@FXML void loadSelectedPlaylist() { Playlist p = (Playlist) playlistsView.getSelectionModel().getSelectedItem(); if (p == null) return; tracksView.setPlaceholder(offlinePlaceHolder); Platform.runLater( () -> { List<Track> tracks = p.getTracks(); tracksView.getItems().clear(); for (int i = tracks.size() - 1; i >= 0; i--) { tracksView.getItems().add(tracks.get(i)); } if (findTrack) { Platform.runLater( () -> { tracksView.getSelectionModel().select(currentTrack); tracksView.scrollTo(currentTrack); tracksView.requestFocus(); findTrack = false; }); } else { if (tracksView.getItems().size() > 0) { tracksView.scrollTo(0); } } }); }
/** * Read stream into array of strings. * * @param inputStream The InputStream for the file. */ protected void openInputStream(InputStream inputStream) { String textLine; // Collect input lines in an array list. List<String> lines = ListFactory.createNewList(); BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new UnicodeReader(inputStream, textFileEncoding)); while ((textLine = bufferedReader.readLine()) != null) { lines.add(textLine); } textFileLoaded = true; } catch (IOException e) { } finally { try { if (bufferedReader != null) bufferedReader.close(); } catch (Exception e) { } } // Convert array list to array of strings. textFileLines = new String[lines.size()]; for (int i = 0; i < lines.size(); i++) { textFileLines[i] = lines.get(i); } }
public static EventHandler<ActionEvent> getBrowseHandler( FXController controller, TextField filePath) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Select a file to upload..."); return e -> { if (AESCTR.secretKey == null) { new Alert(Alert.AlertType.INFORMATION, "Please generate or choose a key", ButtonType.OK) .showAndWait(); return; } selectedFiles = fileChooser.showOpenMultipleDialog(null); if (selectedFiles != null) { controller.writeLog("Selected files: "); StringBuilder sb = new StringBuilder(1024); for (int i = 0; i < selectedFiles.size(); i++) { if (i == selectedFiles.size() - 1) { sb.append(selectedFiles.get(i).getAbsolutePath()); } else { sb.append(selectedFiles.get(i).getAbsolutePath() + ", "); } controller.writeLog(selectedFiles.get(i).getName()); } filePath.setText(sb.toString()); } }; }
private static String buildAllMethodNamesString( String allMethodNames, List<MethodEntry> parents) { StringBuffer allMN = new StringBuffer(120); allMN.append(allMethodNames); if (allMN.length() > 0) { allMN.append("."); } if (parents.size() > 1) { allMN.append("["); } { boolean first = true; for (MethodEntry entry : parents) { if (!first) { allMN.append(","); } first = false; allMN.append(((PsiMethod) entry.myEnd).getName()); } } if (parents.size() > 1) { allMN.append("]"); } return allMN.toString(); }
@Override protected void render(ColoredTreeCellRenderer renderer) { SimpleTextAttributes rootAttributes; SimpleTextAttributes branchAttributes; if (remoteName != null && commits.size() != 0 && remoteCommits != 0 || currentBranch == null) { rootAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES.derive( SimpleTextAttributes.STYLE_BOLD, null, null, null); branchAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; } else if (remoteName == null || commits.size() == 0) { rootAttributes = SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES; branchAttributes = SimpleTextAttributes.GRAYED_ATTRIBUTES; } else { branchAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES; rootAttributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; } renderer.append(root.getPresentableUrl(), rootAttributes); if (currentBranch != null) { renderer.append(" [" + currentBranch, branchAttributes); if (remoteName != null) { renderer.append(" -> " + remoteName + "#" + remoteBranch, branchAttributes); } renderer.append("]", branchAttributes); } }
// masuda$ // ChartEventListener @Override public void propertyChange(PropertyChangeEvent pce) { if (tableModel == null) { return; } ChartEventModel evt = (ChartEventModel) pce.getNewValue(); int sRow = -1; long ptPk = evt.getPtPk(); List<PatientModel> list = tableModel.getDataProvider(); // minagawa^ // ChartEventModel.EVENT eventType = evt.getEventType(); int eventType = evt.getEventType(); // minagawa$ switch (eventType) { case ChartEventModel.PVT_STATE: for (int row = 0; row < list.size(); ++row) { PatientModel pm = list.get(row); if (ptPk == pm.getId()) { sRow = row; pm.setOwnerUUID(evt.getOwnerUUID()); break; } } break; case ChartEventModel.PM_MERGE: for (int row = 0; row < list.size(); ++row) { PatientModel pm = list.get(row); if (ptPk == pm.getId()) { sRow = row; // pm = msg.getPatientModel(); list.set(row, evt.getPatientModel()); break; } } break; case ChartEventModel.PVT_MERGE: for (int row = 0; row < list.size(); ++row) { PatientModel pm = list.get(row); if (ptPk == pm.getId()) { sRow = row; // pm = msg.getPatientVisitModel().getPatientModel(); list.set(row, evt.getPatientVisitModel().getPatientModel()); break; } } break; default: break; } if (sRow != -1) { tableModel.fireTableRowsUpdated(sRow, sRow); } }
public int compareTo(VersionNumber oth) { for (int i = 0; i < Math.min(digits.size(), oth.digits.size()); i++) { if (!digits.get(i).equals(oth.digits.get(i))) return oth.digits.get(i) - digits.get(i); } // All digits equal so far, and only one of the numbers has more digits. // The one with digits remaining is the newest one: return oth.digits.size() - digits.size(); }
/** Gets the GUI component for this pane. */ public JComponent getGUI() { if (cwp == null) { Object object = mWhiteBoard.get("device_definition"); Object ctx_obj = mWhiteBoard.get("context"); if (null != object && object instanceof ConfigDefinition && null != ctx_obj && ctx_obj instanceof ConfigContext) { mConfigContext = (ConfigContext) ctx_obj; ConfigDefinition def = (ConfigDefinition) object; String token = def.getToken(); // Create a temporary list of ConfigDefinitions to pass to factory. java.util.List def_list = new ArrayList(); def_list.add(def); // Initialize a ConfigElementFactory with the needed // ConfigDefinition. And create a new ConfigElement. ConfigElementFactory temp_factory = new ConfigElementFactory(def_list); mConfigElement = temp_factory.create("New " + token, def); List list = CustomEditorRegistry.findEditors(token); Color start_color = new Color(160, 160, 180); Object color = UIManager.get("window"); if (null != color && color instanceof Color) { start_color = (Color) color; } else { System.out.println("Could not get the desktop color from the UIManager."); } // XXX:This will be used after making findEditors -> findEditor // if(null != editor) if (null == list || list.size() == 0) { System.out.println("No CustomEditors registered for token: " + token); JScrollPane scroll_pane = new JScrollPane(); PropertySheet element_prop_sheet = PropertySheetFactory.instance() .makeSheet(mConfigContext, mConfigElement, start_color); scroll_pane.getViewport().removeAll(); scroll_pane.getViewport().add(element_prop_sheet, null); cwp = scroll_pane; } else if (null != list && list.size() > 0) { CustomEditor editor = (CustomEditor) list.get(0); cwp = (JComponent) editor.getPanel(); editor.setConfig(mConfigContext, mConfigElement); } } } // cwp.init(mWhiteBoard); return cwp; }
public String toString() { return "MethodEntry " + myEnd.toString() + "; calls " + myCalledMethods.size() + ", called by " + myCalledByMethods.size() + ", nParameters=" + nParameters; }
void addToPlaylist(List<File> files, Playlist p) { if (interfaceDisabled) return; new Thread( () -> { setInterfaceDisabled(true); int total = files.size(); AtomicInteger current = new AtomicInteger(0); Cache.pushToPlaylist( files, p, (Track t) -> { Platform.runLater( () -> { infoLabel.setText( String.format( res.getString("processed"), current.incrementAndGet(), total, t.getTitle())); if (p == getSelectedPlaylist()) { tracksView.getItems().remove(t); tracksView.getItems().add(0, t); } }); }); setInterfaceDisabled(false); }) .start(); if (p == getSelectedPlaylist()) { Platform.runLater( () -> { loadSelectedPlaylist(); }); } }
@NotNull private XmlAttribute[] calculateAttributes(final Map<String, String> attributesValueMap) { final List<XmlAttribute> result = new ArrayList<XmlAttribute>(10); processChildren( new PsiElementProcessor() { public boolean execute(@NotNull PsiElement element) { if (element instanceof XmlAttribute) { XmlAttribute attribute = (XmlAttribute) element; result.add(attribute); cacheOneAttributeValue(attribute.getName(), attribute.getValue(), attributesValueMap); myHaveNamespaceDeclarations = myHaveNamespaceDeclarations || attribute.isNamespaceDeclaration(); } else if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_TAG_END) { return false; } return true; } }); if (result.isEmpty()) { return XmlAttribute.EMPTY_ARRAY; } else { return ContainerUtil.toArray(result, new XmlAttribute[result.size()]); } }
private void hideNestedTable(int level) { int n = nestedTableList.size(); for (int i = n - 1; i >= level; i--) { NestedTable ntable = nestedTableList.get(i); ntable.hide(); } }
@NotNull public static PsiMethod[] findMethodsByName( @NotNull PsiClass aClass, String name, boolean checkBases) { List<PsiMember> methods = findByMap(aClass, name, checkBases, MemberType.METHOD); //noinspection SuspiciousToArrayCall return methods.toArray(new PsiMethod[methods.size()]); }
@NotNull public PsiReference[] getReferences() { ProgressManager.checkCanceled(); final ASTNode startTagName = XmlChildRole.START_TAG_NAME_FINDER.findChild(this); if (startTagName == null) return PsiReference.EMPTY_ARRAY; final ASTNode endTagName = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(this); List<PsiReference> refs = new ArrayList<PsiReference>(); String prefix = getNamespacePrefix(); TagNameReference startTagRef = TagNameReference.createTagNameReference(this, startTagName, true); refs.add(startTagRef); if (prefix.length() > 0) { refs.add(createPrefixReference(startTagName, prefix, startTagRef)); } if (endTagName != null) { TagNameReference endTagRef = TagNameReference.createTagNameReference(this, endTagName, false); refs.add(endTagRef); prefix = XmlUtil.findPrefixByQualifiedName(endTagName.getText()); if (StringUtil.isNotEmpty(prefix)) { refs.add(createPrefixReference(endTagName, prefix, endTagRef)); } } // ArrayList.addAll() makes a clone of the collection //noinspection ManualArrayToCollectionCopy for (PsiReference ref : ReferenceProvidersRegistry.getReferencesFromProviders(this, XmlTag.class)) { refs.add(ref); } return ContainerUtil.toArray(refs, new PsiReference[refs.size()]); }
public void moveDown(int index) { if (index < data.size() - 1) { TileScript event = data.remove(index); data.add(index + 1, event); fireContentsChanged(this, index, index + 1); } }
@NotNull public static String buildStringToFindForIndicesFromRegExp( @NotNull String stringToFind, @NotNull Project project) { if (!Registry.is("idea.regexp.search.uses.indices")) return ""; final AccessToken accessToken = ReadAction.start(); try { final List<PsiElement> topLevelRegExpChars = getTopLevelRegExpChars("a", project); if (topLevelRegExpChars.size() != 1) return ""; // leave only top level regExpChars return StringUtil.join( getTopLevelRegExpChars(stringToFind, project), new Function<PsiElement, String>() { final Class regExpCharPsiClass = topLevelRegExpChars.get(0).getClass(); @Override public String fun(PsiElement element) { return regExpCharPsiClass.isInstance(element) ? element.getText() : " "; } }, ""); } finally { accessToken.finish(); } }
@Nullable private LocalQuickFix[] createNPEFixes( PsiExpression qualifier, PsiExpression expression, boolean onTheFly) { if (qualifier == null || expression == null) return null; if (qualifier instanceof PsiMethodCallExpression) return null; if (qualifier instanceof PsiLiteralExpression && ((PsiLiteralExpression) qualifier).getValue() == null) return null; try { final List<LocalQuickFix> fixes = new SmartList<LocalQuickFix>(); if (PsiUtil.getLanguageLevel(qualifier).isAtLeast(LanguageLevel.JDK_1_4)) { final Project project = qualifier.getProject(); final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory(); final PsiBinaryExpression binary = (PsiBinaryExpression) elementFactory.createExpressionFromText("a != null", null); binary.getLOperand().replace(qualifier); fixes.add(new AddAssertStatementFix(binary)); } addSurroundWithIfFix(qualifier, fixes, onTheFly); if (ReplaceWithTernaryOperatorFix.isAvailable(qualifier, expression)) { fixes.add(new ReplaceWithTernaryOperatorFix(qualifier)); } return fixes.toArray(new LocalQuickFix[fixes.size()]); } catch (IncorrectOperationException e) { LOG.error(e); return null; } }
/*-------------------------------------------------------------------------*/ public FoeTypeSelection(int dirtyFlag) { this.dirtyFlag = dirtyFlag; List<String> foeTypesList = new ArrayList<String>(Database.getInstance().getFoeTypes().keySet()); Collections.sort(foeTypesList); int max = foeTypesList.size(); checkBoxes = new HashMap<String, JCheckBox>(); JPanel panel = new JPanel(new GridLayout(max / 2 + 2, 2, 3, 3)); selectAll = new JButton("Select All"); selectAll.addActionListener(this); selectNone = new JButton("Select None"); selectNone.addActionListener(this); panel.add(selectAll); panel.add(selectNone); for (String s : foeTypesList) { JCheckBox cb = new JCheckBox(s); checkBoxes.put(s, cb); cb.addActionListener(this); panel.add(cb); } JScrollPane scroller = new JScrollPane(panel); this.add(scroller); }
@Override protected ValidationInfo doValidate() { final String resourceName = getResourceName(); final Module selectedModule = getModule(); final List<String> directoryNames = getDirNames(); final String fileName = getFileName(); if (resourceName.length() == 0) { return new ValidationInfo("specify resource name", myNameField); } else if (!AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) { return new ValidationInfo(resourceName + " is not correct resource name", myNameField); } else if (fileName.length() == 0) { return new ValidationInfo("specify file name", myFileNameCombo); } else if (selectedModule == null) { return new ValidationInfo("specify module", myModuleCombo); } else if (directoryNames.size() == 0) { return new ValidationInfo("choose directories", myDirectoriesList); } final ValidationInfo info = checkIfResourceAlreadyExists( selectedModule, resourceName, myResourceType, directoryNames, fileName); if (info != null) { return info; } return null; }
@NotNull public <T> T[] findChildrenByClass(Class<T> aClass) { List<T> result = new ArrayList<T>(); for (PsiElement child : getChildren()) { if (aClass.isInstance(child)) result.add((T) child); } return result.toArray((T[]) Array.newInstance(aClass, result.size())); }
private static AttachingConnector getAttachingConnectorFor(String transport) { List acs = Bootstrap.virtualMachineManager().attachingConnectors(); AttachingConnector ac; int i, k = acs.size(); for (i = 0; i < k; i++) if ((ac = (AttachingConnector) acs.get(i)).transport().name().equals(transport)) return ac; return null; }
/*-------------------------------------------------------------------------*/ public void refresh(List<TileScript> scripts, Zone zone) { this.scripts = scripts; this.zone = zone; if (scripts != null) { this.setText(scripts.size() + " scripts"); } }
public BitSet getCharContainingIndexSet(char[] nameChars) { BitSet sets = new BitSet(sources.size()); sets.set(0, sources.size()); for (char c : nameChars) { c = Character.toLowerCase(c); BitSet charSet = index.get(c); if (charSet == null) { sets.clear(); break; } else { sets.and(charSet); if (sets.isEmpty()) { break; } } } return sets; }
protected void control(List nodes) { if (nodes.size() <= 1) return; Collections.sort(nodes, new YComparator()); // double d = Y_max - Y_min; // d = d / (nodes.size() - 1); // Note: X, Y are at node centers for (int i = 1; i < nodes.size(); i++) { ((NodeView) nodes.get(i)) .setYPosition( ((NodeView) nodes.get(i - 1)).getYPosition() + ((NodeView) nodes.get(i - 1)).getHeight() * 0.5 + ((NodeView) nodes.get(i)).getHeight() * 0.5); ((NodeView) nodes.get(i)).setXPosition(((NodeView) nodes.get(i - 1)).getXPosition()); } }
public void setUpList() { List substances = system.getSubstances(); int nSubs = substances.size(); // substances.length; Substance s; for (int i = 0; i < nSubs; i++) { s = (Substance) (substances.get(i)); substanceNames.addElement(s.getName()); } }
private static int getItemToSelect( LookupImpl lookup, List<LookupElement> items, boolean onExplicitAction, @Nullable LookupElement mostRelevant) { if (items.isEmpty() || lookup.getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED) { return 0; } if (lookup.isSelectionTouched() || !onExplicitAction) { final LookupElement lastSelection = lookup.getCurrentItem(); int old = ContainerUtil.indexOfIdentity(items, lastSelection); if (old >= 0) { return old; } Object selectedValue = ((LookupImpl) lookup).getList().getSelectedValue(); if (selectedValue instanceof EmptyLookupItem && ((EmptyLookupItem) selectedValue).isLoading()) { int index = ((LookupImpl) lookup).getList().getSelectedIndex(); if (index >= 0 && index < items.size()) { return index; } } for (int i = 0; i < items.size(); i++) { String invariant = PRESENTATION_INVARIANT.get(items.get(i)); if (invariant != null && invariant.equals(PRESENTATION_INVARIANT.get(lastSelection))) { return i; } } } String selectedText = lookup.getEditor().getSelectionModel().getSelectedText(); for (int i = 0; i < items.size(); i++) { LookupElement item = items.get(i); if (isPrefixItem(lookup, item, true) && !isLiveTemplate(item) || item.getLookupString().equals(selectedText)) { return i; } } return Math.max(0, ContainerUtil.indexOfIdentity(items, mostRelevant)); }
void playRandom() { List<Track> tracks = tracksView.getItems(); Random random = new Random(); int size = tracks.size(); int r = random.nextInt(size - 1); tracksView.getSelectionModel().select(r); tracksView.scrollTo(tracksView.getSelectionModel().getSelectedIndex()); Track nextTrack = (Track) tracksView.getSelectionModel().getSelectedItem(); playTrack(nextTrack); }
public void showColorButtons() { Color colors[] = {Color.RED, Color.BLACK, Color.WHITE, Color.GREEN, Color.YELLOW, Color.BLUE}; Insets in = this.getInsets(); this.input = new JTextField(); this.add(this.input); this.input.setBounds(100 + in.left, 36 + in.top, 200, 30); int arrayAmount = numberOfPlayersButtons.size(); for (int i = 0; i < numberOfPlayersButtons.size(); i++) { this.remove(numberOfPlayersButtons.get(i)); } numberOfPlayersButtons = null; arrayAmount = this.maxPlayersAmount; for (int i = 0; i < arrayAmount; i++) { JButton tempButton = new JButton(); colorButtons.add(tempButton); tempButton.setBackground(colors[i]); tempButton.setBorderPainted(false); tempButton.setOpaque(true); tempButton.setBounds(65 + i * 45 + in.left, 81 + in.top, 25, 25); tempButton.addActionListener(this.listener); this.add(tempButton); } Dimension size; size = label.getPreferredSize(); label.setBounds(65, 5 + in.top, size.width + 48, size.height); label.setText("Jogador 1, informe a sua cor e o seu nome:"); this.repaint(); }
@Override public void writeExternal(Element parentNode) throws WriteExternalException { for (int i = 0; i < myPatterns.size(); i++) { String pattern = myPatterns.get(i); String name = myNames.get(i); @NonNls Element element = new Element("pair"); parentNode.addContent(element); element.setAttribute("type", pattern); element.setAttribute("name", name); } }
@Nullable public static ValidationInfo checkIfResourceAlreadyExists( @NotNull Module selectedModule, @NotNull String resourceName, @NotNull ResourceType resourceType, @NotNull List<String> dirNames, @NotNull String fileName) { if (resourceName.length() == 0 || dirNames.size() == 0 || fileName.length() == 0) { return null; } final AndroidFacet facet = AndroidFacet.getInstance(selectedModule); final VirtualFile resourceDir = facet != null ? AndroidRootUtil.getResourceDir(facet) : null; if (resourceDir == null) { return null; } for (String directoryName : dirNames) { final VirtualFile resourceSubdir = resourceDir.findChild(directoryName); if (resourceSubdir == null) { continue; } final VirtualFile resFile = resourceSubdir.findChild(fileName); if (resFile == null) { continue; } if (resFile.getFileType() != StdFileTypes.XML) { return new ValidationInfo( "File " + FileUtil.toSystemDependentName(resFile.getPath()) + " is not XML file"); } final Resources resources = AndroidUtils.loadDomElement(selectedModule, resFile, Resources.class); if (resources == null) { return new ValidationInfo( AndroidBundle.message( "not.resource.file.error", FileUtil.toSystemDependentName(resFile.getPath()))); } for (ResourceElement element : AndroidResourceUtil.getValueResourcesFromElement(resourceType.getName(), resources)) { if (resourceName.equals(element.getName().getValue())) { return new ValidationInfo( "resource '" + resourceName + "' already exists in " + FileUtil.toSystemDependentName(resFile.getPath())); } } } return null; }