protected void stitchNeighbors(Set<Sector> neighbors, GeoPoint center) { assert gatedAssertion( neighbors.size() == 6 || neighbors.size() == 5 && countDistinctGlobalSectors(neighbors) == 5); if (!sector.equals(neighbors.iterator().next())) { return; } Map<GeoPoint, GeoPoint> nextPoints = new HashMap<GeoPoint, GeoPoint>(); Sector second = null; for (Sector s : neighbors) { char vertex = s.getVertex(center); Sector.Triangle cornerTriangle = s.getCornerTriangle(vertex); GeoPoint[] geoPoints = cornerTriangle.getPoints(vertex); nextPoints.put(geoPoints[1], geoPoints[2]); if (second == null && countShared(s.points, sector.points) == 1) { second = s; } } assert gatedAssertion(second != null); if (second != null) { GeoPoint[] acre = new GeoPoint[nextPoints.size()]; GeoPoint point = nextPoints.values().iterator().next(); for (int idx = 0; idx < nextPoints.size(); idx++) { assert !Arrays.asList(acre).contains(point); acre[idx] = point; point = nextPoints.get(point); assert gatedAssertion(point != null); if (point == null) { return; } } Sector[] others = new Sector[neighbors.size() - 2]; int idx = 0; for (Sector s : neighbors) { if (s != sector && s != second) { others[idx++] = s; } } Acre newAcre = new Acre(1, sector, second, Arrays.asList(others), center, acre); CartographicElementView cartographicElementView = getFor(subdivisions); for (Sector s : neighbors) { char vertex = s.getVertex(center); assert vertex == 'A' || vertex == 'B' || vertex == 'C'; Edge e = Edge.values()[vertex - 'A']; List<Acre> vertexAcre = cartographicElementView.get( s.getSharedAcres(), CartographicElementView.Position.Vertex, e, false); assert vertexAcre.size() == 1; assert vertexAcre.get(0) == null; vertexAcre.set(0, newAcre); } consume(newAcre); } }
private Color getThreadBlockColor(BumpThread bt) { if (bt == null) return Color.BLACK; synchronized (thread_colors) { Color c = thread_colors.get(bt); if (c == null) { double v; int ct = thread_colors.size(); if (ct == 0) v = 0; else if (ct == 1) v = 1; else { v = 0.5; int p0 = ct - 1; int p1 = 1; for (int p = p0; p > 1; p /= 2) { v /= 2.0; p0 -= p1; p1 *= 2; } if ((p0 & 1) == 0) p0 = 2 * p1 - p0 + 1; v = v * p0; } float h = (float) (v * 0.8); float s = 0.7f; float b = 1.0f; int rgb = Color.HSBtoRGB(h, s, b); rgb |= 0xc0000000; c = new Color(rgb, true); thread_colors.put(bt, c); } return c; } }
public List<String> find() throws IOException { // Set<String> g1 = new HashSet<String>(Arrays.asList("HRAS", "NRAS", "KRAS")); // Set<String> g2 = new HashSet<String>(Arrays.asList("BRAF")); Set<String> g1 = new HashSet<String>(Arrays.asList("HRAS")); Set<String> g2 = new HashSet<String>(Arrays.asList("NRAS", "KRAS")); Map<String, Double> pvals = calcDifferencePvals(g1, g2); System.out.println("pvals.size() = " + pvals.size()); List<String> list = FDR.select(pvals, null, fdrThr); System.out.println("result size = " + list.size()); Map<String, Boolean> dirs = getChangeDirections(list, g1, g2); int up = 0; int dw = 0; for (String gene : dirs.keySet()) { Boolean d = dirs.get(gene); if (d) up++; else dw++; } System.out.println("up = " + up); System.out.println("dw = " + dw); return list; }
private synchronized void startAnimation( JComponent component, Part part, State startState, State endState, long millis) { boolean isForwardAndReverse = false; if (endState == State.DEFAULTED) { isForwardAndReverse = true; } Map<Part, AnimationState> map = animationStateMap.get(component); if (millis <= 0) { if (map != null) { map.remove(part); if (map.size() == 0) { animationStateMap.remove(component); } } return; } if (map == null) { map = new EnumMap<Part, AnimationState>(Part.class); animationStateMap.put(component, map); } map.put(part, new AnimationState(startState, millis, isForwardAndReverse)); if (!timer.isRunning()) { timer.start(); } }
public UpdateOrStatusOptionsDialog(Project project, Map<Configurable, AbstractVcs> confs) { super(project); setTitle(getRealTitle()); myProject = project; if (confs.size() == 1) { myMainPanel = new JPanel(new BorderLayout()); final Configurable configurable = confs.keySet().iterator().next(); addComponent(confs.get(configurable), configurable, BorderLayout.CENTER); myMainPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); } else { myMainPanel = new JBTabbedPane(); final ArrayList<AbstractVcs> vcses = new ArrayList<>(confs.values()); Collections.sort( vcses, new Comparator<AbstractVcs>() { public int compare(final AbstractVcs o1, final AbstractVcs o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); Map<AbstractVcs, Configurable> vcsToConfigurable = revertMap(confs); for (AbstractVcs vcs : vcses) { addComponent(vcs, vcsToConfigurable.get(vcs), vcs.getDisplayName()); } } init(); }
public synchronized void actionPerformed(ActionEvent e) { java.util.List<JComponent> componentsToRemove = null; java.util.List<Part> partsToRemove = null; for (JComponent component : animationStateMap.keySet()) { component.repaint(); if (partsToRemove != null) { partsToRemove.clear(); } Map<Part, AnimationState> map = animationStateMap.get(component); if (!component.isShowing() || map == null || map.size() == 0) { if (componentsToRemove == null) { componentsToRemove = new ArrayList<JComponent>(); } componentsToRemove.add(component); continue; } for (Part part : map.keySet()) { if (map.get(part).isDone()) { if (partsToRemove == null) { partsToRemove = new ArrayList<Part>(); } partsToRemove.add(part); } } if (partsToRemove != null) { if (partsToRemove.size() == map.size()) { // animation is done for the component if (componentsToRemove == null) { componentsToRemove = new ArrayList<JComponent>(); } componentsToRemove.add(component); } else { for (Part part : partsToRemove) { map.remove(part); } } } } if (componentsToRemove != null) { for (JComponent component : componentsToRemove) { animationStateMap.remove(component); } } if (animationStateMap.size() == 0) { timer.stop(); } }
/** * \ Draw saved State (color dots on panel) on WhiteBoard * * @param outstream * @throws IOException */ public void writeState(OutputStream outstream) throws IOException { if (state == null) return; synchronized (state) { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(outstream)); // DataOutputStream dos=new DataOutputStream(outstream); dos.writeInt(state.size()); for (Map.Entry<Point, Color> entry : state.entrySet()) { Point point = entry.getKey(); Color col = entry.getValue(); dos.writeInt(point.x); dos.writeInt(point.x); dos.writeInt(col.getRGB()); } dos.flush(); System.out.println("wrote " + state.size() + " elements"); } }
private double[] toDoubleArray(Map<String, Double> map) { double[] d = new double[map.size()]; int i = 0; for (String key : map.keySet()) { d[i++] = map.get(key); } return d; }
/** Добавляет новую покупку. Обновляет данные о частоте использования типов. */ public void addPayObject(PayObject payObject) { if (payObjects.size() != 0 && frequencyUsePayType.size() == 0) updateAllFrequencyUse(); payObjects.add(payObject); updateFrequencyUse(payObject); ApplicationService.writeData(); MonitoringMoney.mainFrame.updateData(); }
public Animation() { String[] keys = {"no Animator found"}; if (tryDir(".")) // || tryDir("BLM305") || tryDir("CSE470")) keys = map.keySet().toArray(keys); System.out.println(map.size() + " classes loaded"); menu = new JComboBox(keys); pan.setLayout(new BorderLayout(GAP, GAP - 4)); pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP)); pan.setBackground(COLOR); last = new JPanel(); last.setPreferredSize(DIM); pan.add(last, "Center"); ref.setFont(NORM); ref.setEditable(false); ref.setColumns(35); ref.setDragEnabled(true); pan.add(ref, "North"); pan.add(bottomPanel(), "South"); pan.setToolTipText("A collective project for BLM320"); menu.setToolTipText("Animator classes"); who.setToolTipText("author()"); ref.setToolTipText("description()"); Closer ear = new Closer(); menu.addActionListener(ear); stop.addActionListener(ear); frm.addWindowListener(ear); if (map.size() > 0) setItem(0); frm.setContentPane(pan); frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frm.setLocation(scaled(120), scaled(90)); frm.pack(); // setSize() is called here frm.setVisible(true); start(); }
@NotNull private List<HighlightSeverity> getDefaultOrder() { Collection<SeverityBasedTextAttributes> values = myMap.values(); List<HighlightSeverity> order = new ArrayList<HighlightSeverity>(STANDARD_SEVERITIES.size() + values.size()); for (HighlightInfoType type : STANDARD_SEVERITIES.values()) { order.add(type.getSeverity(null)); } for (SeverityBasedTextAttributes attributes : values) { order.add(attributes.getSeverity()); } ContainerUtil.sort(order); return order; }
/** * Read State (color dots) from input stream * * @param instream * @throws IOException */ public void readState(InputStream instream) throws IOException { DataInputStream in = new DataInputStream(new BufferedInputStream(instream)); Map<Point, Color> new_state = new LinkedHashMap<Point, Color>(); int num = in.readInt(); for (int i = 0; i < num; i++) { Point point = new Point(in.readInt(), in.readInt()); Color col = new Color(in.readInt()); new_state.put(point, col); } synchronized (state) { state.clear(); state.putAll(new_state); System.out.println("read " + state.size() + " elements"); createOffscreenImage(true); } }
boolean tryDir(String d) { ClassLoader L = getClass().getClassLoader(); File p = new File(d, PACKAGE); System.out.println("Try " + p); if (!p.exists() || !p.isDirectory()) return false; for (File f : p.listFiles()) { String s = f.getName(); if (!s.endsWith(".class")) continue; String name = s.substring(0, s.length() - 6); try { Class<?> c = L.loadClass(PACKAGE + "." + name); if (!Animator.class.isAssignableFrom(c)) continue; Animator a = (Animator) c.newInstance(); a.container().setPreferredSize(DIM); map.put(name, a); System.out.println(" " + name); // ClassNotFoundException InstantiationException IllegalAccessException } catch (Exception e) { continue; } } return map.size() > 0; }
private boolean doRemoveModule(@NotNull ModuleEditor selectedEditor) { String question; if (myModuleEditors.size() == 1) { question = ProjectBundle.message("module.remove.last.confirmation"); } else { question = ProjectBundle.message("module.remove.confirmation", selectedEditor.getModule().getName()); } int result = Messages.showYesNoDialog( myProject, question, ProjectBundle.message("module.remove.confirmation.title"), Messages.getQuestionIcon()); if (result != Messages.YES) { return false; } // do remove myModuleEditors.remove(selectedEditor.getModule()); // destroyProcess removed module final Module moduleToRemove = selectedEditor.getModule(); // remove all dependencies on the module that is about to be removed List<ModifiableRootModel> modifiableRootModels = new ArrayList<ModifiableRootModel>(); for (final ModuleEditor moduleEditor : myModuleEditors.values()) { final ModifiableRootModel modifiableRootModel = moduleEditor.getModifiableRootModelProxy(); modifiableRootModels.add(modifiableRootModel); } // destroyProcess editor ModuleDeleteProvider.removeModule(moduleToRemove, null, modifiableRootModels, myModuleModel); processModuleCountChanged(); Disposer.dispose(selectedEditor); return true; }
public VisualizationPanel(List<String> metricNames, final Map<Project, Double[]> results) { Map<String, IVisualization> vis = VisualizationsRegistry.visualizations; int numVis = vis.size(); setLayout(new GridLayout(2 + numVis, 1)); this.metricNames = metricNames; this.results = results; metricNameComboBox = new JComboBox(); for (String name : metricNames) { metricNameComboBox.addItem(name); } add(metricNameComboBox); for (final String visName : vis.keySet()) { JButton btn = new JButton(visName); btn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { showVis(visName); } }); add(btn); } JButton boxPlotCombined = new JButton("box and whisker combined"); boxPlotCombined.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { showCombined("box and whisker"); } }); add(boxPlotCombined); }
public HectorComponent(@NotNull PsiFile file) { super(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); myFile = file; mySliders = new HashMap<Language, JSlider>(); final Project project = myFile.getProject(); final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final VirtualFile virtualFile = myFile.getContainingFile().getVirtualFile(); LOG.assertTrue(virtualFile != null); final boolean notInLibrary = !fileIndex.isInLibrarySource(virtualFile) && !fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInContent(virtualFile); final FileViewProvider viewProvider = myFile.getViewProvider(); List<Language> languages = new ArrayList<Language>(viewProvider.getLanguages()); Collections.sort(languages, PsiUtilBase.LANGUAGE_COMPARATOR); for (Language language : languages) { @SuppressWarnings("UseOfObsoleteCollectionType") final Hashtable<Integer, JLabel> sliderLabels = new Hashtable<Integer, JLabel>(); sliderLabels.put(1, new JLabel(EditorBundle.message("hector.none.slider.label"))); sliderLabels.put(2, new JLabel(EditorBundle.message("hector.syntax.slider.label"))); if (notInLibrary) { sliderLabels.put(3, new JLabel(EditorBundle.message("hector.inspections.slider.label"))); } final JSlider slider = new JSlider(SwingConstants.VERTICAL, 1, notInLibrary ? 3 : 2, 1); if (UIUtil.isUnderGTKLookAndFeel()) { // default GTK+ slider UI is way too ugly slider.putClientProperty("Slider.paintThumbArrowShape", true); slider.setUI(new BasicSliderUI(slider)); } slider.setLabelTable(sliderLabels); UIUtil.setSliderIsFilled(slider, true); slider.setPaintLabels(true); slider.setSnapToTicks(true); slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int value = slider.getValue(); for (Enumeration<Integer> enumeration = sliderLabels.keys(); enumeration.hasMoreElements(); ) { Integer key = enumeration.nextElement(); sliderLabels .get(key) .setForeground( key.intValue() <= value ? UIUtil.getLabelForeground() : UIUtil.getLabelDisabledForeground()); } } }); final PsiFile psiRoot = viewProvider.getPsi(language); assert psiRoot != null : "No root in " + viewProvider + " for " + language; slider.setValue( getValue( HighlightLevelUtil.shouldHighlight(psiRoot), HighlightLevelUtil.shouldInspect(psiRoot))); mySliders.put(language, slider); } GridBagConstraints gc = new GridBagConstraints( 0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0); JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(IdeBorderFactory.createTitledBorder(myTitle, false)); final boolean addLabel = mySliders.size() > 1; if (addLabel) { layoutVertical(panel); } else { layoutHorizontal(panel); } gc.gridx = 0; gc.gridy = 0; gc.weighty = 1.0; gc.fill = GridBagConstraints.BOTH; add(panel, gc); gc.gridy = GridBagConstraints.RELATIVE; gc.weighty = 0; final HyperlinkLabel configurator = new HyperlinkLabel("Configure inspections"); gc.insets.right = 5; gc.insets.bottom = 10; gc.weightx = 0; gc.fill = GridBagConstraints.NONE; gc.anchor = GridBagConstraints.EAST; add(configurator, gc); configurator.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { final JBPopup hector = getOldHector(); if (hector != null) { hector.cancel(); } if (!DaemonCodeAnalyzer.getInstance(myFile.getProject()) .isHighlightingAvailable(myFile)) return; final Project project = myFile.getProject(); final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project); assert errorsConfigurable != null; ShowSettingsUtil.getInstance().editConfigurable(project, errorsConfigurable); } }); gc.anchor = GridBagConstraints.WEST; gc.weightx = 1.0; gc.insets.right = 0; gc.fill = GridBagConstraints.HORIZONTAL; myAdditionalPanels = new ArrayList<HectorComponentPanel>(); for (HectorComponentPanelsProvider provider : Extensions.getExtensions(HectorComponentPanelsProvider.EP_NAME, project)) { final HectorComponentPanel componentPanel = provider.createConfigurable(file); if (componentPanel != null) { myAdditionalPanels.add(componentPanel); add(componentPanel.createComponent(), gc); componentPanel.reset(); } } }
@Override public int getUsagesCount() { return myUsageNodes.size(); }
public void apply() throws ConfigurationException { // validate content and source roots final Map<VirtualFile, String> contentRootToModuleNameMap = new HashMap<VirtualFile, String>(); final Map<VirtualFile, VirtualFile> srcRootsToContentRootMap = new HashMap<VirtualFile, VirtualFile>(); for (final ModuleEditor moduleEditor : myModuleEditors.values()) { final ModifiableRootModel rootModel = moduleEditor.getModifiableRootModel(); final ContentEntry[] contents = rootModel.getContentEntries(); for (ContentEntry contentEntry : contents) { final VirtualFile contentRoot = contentEntry.getFile(); if (contentRoot == null) { continue; } final String moduleName = moduleEditor.getName(); final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName); if (previousName != null && !previousName.equals(moduleName)) { throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.duplicate.content.error", contentRoot.getPresentableUrl(), previousName, moduleName)); } for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) { final VirtualFile anotherContentRoot = srcRootsToContentRootMap.put(srcRoot, contentRoot); if (anotherContentRoot != null) { final String problematicModule; final String correctModule; if (VfsUtilCore.isAncestor(anotherContentRoot, contentRoot, true)) { problematicModule = contentRootToModuleNameMap.get(anotherContentRoot); correctModule = contentRootToModuleNameMap.get(contentRoot); } else { problematicModule = contentRootToModuleNameMap.get(contentRoot); correctModule = contentRootToModuleNameMap.get(anotherContentRoot); } throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.duplicate.source.root.error", problematicModule, srcRoot.getPresentableUrl(), correctModule)); } } } } // additional validation: directories marked as src roots must belong to the same module as // their corresponding content root for (Map.Entry<VirtualFile, VirtualFile> entry : srcRootsToContentRootMap.entrySet()) { final VirtualFile srcRoot = entry.getKey(); final VirtualFile correspondingContent = entry.getValue(); final String expectedModuleName = contentRootToModuleNameMap.get(correspondingContent); for (VirtualFile candidateContent = srcRoot; candidateContent != null && !candidateContent.equals(correspondingContent); candidateContent = candidateContent.getParent()) { final String moduleName = contentRootToModuleNameMap.get(candidateContent); if (moduleName != null && !moduleName.equals(expectedModuleName)) { throw new ConfigurationException( ProjectBundle.message( "module.paths.validation.source.root.belongs.to.another.module.error", srcRoot.getPresentableUrl(), expectedModuleName, moduleName)); } } } final List<ModifiableRootModel> models = new ArrayList<ModifiableRootModel>(myModuleEditors.size()); for (ModuleEditor moduleEditor : myModuleEditors.values()) { moduleEditor.canApply(); } final Map<Sdk, Sdk> modifiedToOriginalMap = new HashMap<Sdk, Sdk>(); final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(myProject).getProjectJdksModel(); for (Map.Entry<Sdk, Sdk> entry : projectJdksModel.getProjectSdks().entrySet()) { modifiedToOriginalMap.put(entry.getValue(), entry.getKey()); } final Ref<ConfigurationException> exceptionRef = Ref.create(); DumbService.getInstance(myProject) .allowStartingDumbModeInside( DumbModePermission.MAY_START_BACKGROUND, new Runnable() { public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { @Override public void run() { try { for (final ModuleEditor moduleEditor : myModuleEditors.values()) { final ModifiableRootModel model = moduleEditor.apply(); if (model != null) { if (!model.isSdkInherited()) { // make sure the sdk is set to original SDK stored in the JDK // Table final Sdk modelSdk = model.getSdk(); if (modelSdk != null) { final Sdk original = modifiedToOriginalMap.get(modelSdk); if (original != null) { model.setSdk(original); } } } models.add(model); } } myFacetsConfigurator.applyEditors(); } catch (ConfigurationException e) { exceptionRef.set(e); return; } try { final ModifiableRootModel[] rootModels = models.toArray(new ModifiableRootModel[models.size()]); ModifiableModelCommitter.multiCommit(rootModels, myModuleModel); myModuleModelCommitted = true; myFacetsConfigurator.commitFacets(); } finally { ModuleStructureConfigurable.getInstance(myProject) .getFacetEditorFacade() .clearMaps(false); myFacetsConfigurator = createFacetsConfigurator(); myModuleModel = ModuleManager.getInstance(myProject).getModifiableModel(); myModuleModelCommitted = false; } } }); } }); if (!exceptionRef.isNull()) { throw exceptionRef.get(); } myModified = false; }