/** * Asks current editor to refresh its state in accordance with the arrangement rule shown at the * given row. * * @param row row index of the rule which match condition should be edited (if defined); <code> * '-1'</code> as an indication that no settings should be active */ public void reset(int row) { // Reset state. myRow = row; myFocusRequestor = myDefaultFocusRequestor; mySkipStateChange = true; try { for (ArrangementUiComponent component : myComponents.values()) { component.reset(); } } finally { mySkipStateChange = false; } ArrangementMatchingRulesModel model = myControl.getModel(); if (row < 0 || row >= model.getSize()) { myRow = -1; return; } Object element = model.getElementAt(row); ArrangementSettingsToken orderType = element instanceof ArrangementMatchRule ? ((ArrangementMatchRule) element).getOrderType() : null; final ArrangementMatchCondition condition; final Map<ArrangementSettingsToken, Object> conditionTokens; if (element instanceof EmptyArrangementRuleComponent) { // We need to disable conditions which are not applicable for empty rules (e.g. we don't want // to enable 'volatile' condition // for java rearranger if no 'field' condition is selected. condition = null; conditionTokens = ContainerUtilRt.newHashMap(); } else if (!(element instanceof StdArrangementMatchRule)) { return; } else { condition = ((StdArrangementMatchRule) element).getMatcher().getCondition(); conditionTokens = ArrangementUtil.extractTokens(condition); } mySkipStateChange = true; try { for (ArrangementUiComponent component : myComponents.values()) { ArrangementSettingsToken token = component.getToken(); if (token != null && (token.equals(orderType) || mySettingsManager.isEnabled(token, condition))) { component.setEnabled(true); component.setSelected(conditionTokens.containsKey(token)); Object value = conditionTokens.get(token); if (value != null) { component.setData(value); } } } refreshConditions(); } finally { mySkipStateChange = false; } }
public void checkLineMarkers( @NotNull Collection<LineMarkerInfo> markerInfos, @NotNull String text) { String fileName = myFile == null ? "" : myFile.getName() + ": "; String failMessage = ""; for (LineMarkerInfo info : markerInfos) { if (!containsLineMarker(info, myLineMarkerInfos.values())) { if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Extra line marker highlighted " + rangeString(text, info.startOffset, info.endOffset) + ": '" + info.getLineMarkerTooltip() + "'"; } } for (LineMarkerInfo expectedLineMarker : myLineMarkerInfos.values()) { if (!markerInfos.isEmpty() && !containsLineMarker(expectedLineMarker, markerInfos)) { if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Line marker was not highlighted " + rangeString(text, expectedLineMarker.startOffset, expectedLineMarker.endOffset) + ": '" + expectedLineMarker.getLineMarkerTooltip() + "'"; } } if (!failMessage.isEmpty()) Assert.fail(failMessage); }
public ActionCallback restoreLastUiState() { final ActionCallback result = new ActionCallback(myPlaceInGrid2Cell.values().size()); for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) { cell.restoreLastUiState().notifyWhenDone(result); } return result; }
@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; }
private Collection<FrameworkSupportNodeBase> createNodes( List<FrameworkSupportInModuleProvider> providers, Set<String> associated, final Set<String> preselected) { Map<String, FrameworkSupportNode> nodes = new HashMap<String, FrameworkSupportNode>(); Map<FrameworkGroup<?>, FrameworkGroupNode> groups = new HashMap<FrameworkGroup<?>, FrameworkGroupNode>(); List<FrameworkSupportNodeBase> roots = new ArrayList<FrameworkSupportNodeBase>(); Map<String, FrameworkSupportNodeBase> associatedNodes = new LinkedHashMap<String, FrameworkSupportNodeBase>(); for (FrameworkSupportInModuleProvider provider : providers) { createNode(provider, nodes, groups, roots, providers, associated, associatedNodes); } FrameworkSupportNodeBase.sortByName( roots, new Comparator<FrameworkSupportNodeBase>() { @Override public int compare(FrameworkSupportNodeBase o1, FrameworkSupportNodeBase o2) { return Comparing.compare( preselected.contains(o2.getId()), preselected.contains(o1.getId())); } }); myRoots = roots; return associatedNodes.values(); }
@Override public void run() { try { if (Fecs.getApplicationContext() == null) return; Long currentTime = System.currentTimeMillis(); double deltaTime = (currentTime - lastUpdateTime) * 0.001; if (getEngineState() == STATE_START) { // last bit is 1 = started int s = getCircumstanceState() - 1; // 0 is null state(error) if (s >= CircumstanceType.values().length || s < 0) throw new Exception("unstable state value with " + String.valueOf(s)); Circumstance.get(CircumstanceType.values()[s]) .setParameter("currentTime", currentTime) .setParameter("deltaTime", deltaTime) .trigger(); for (Cabin cabin : cabins.values()) updateCabin(cabin, deltaTime); } lastUpdateTime = currentTime; draw(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { try { Thread.sleep(1); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } SwingUtilities.invokeLater(this); } }
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 List<SwitchTarget> getTargets(boolean onlyVisible) { Collection<GridCellImpl> cells = myPlaceInGrid2Cell.values(); ArrayList<SwitchTarget> result = new ArrayList<SwitchTarget>(); for (GridCellImpl each : cells) { result.addAll(each.getTargets(onlyVisible)); } return result; }
private void releaseAllEditors() { for (final Editor editor : myEditors.values()) { if (!editor.isDisposed()) { EditorFactory.getInstance().releaseEditor(editor); } } myEditors.clear(); }
public void checkResult(Collection<HighlightInfo> infos, String text, @Nullable String filePath) { if (filePath == null) { VirtualFile virtualFile = myFile == null ? null : myFile.getVirtualFile(); filePath = virtualFile == null ? null : virtualFile.getUserData(VfsTestUtil.TEST_DATA_FILE_PATH); } String fileName = myFile == null ? "" : myFile.getName() + ": "; String failMessage = ""; for (HighlightInfo info : reverseCollection(infos)) { if (!expectedInfosContainsInfo(info) && !myIgnoreExtraHighlighting) { final int startOffset = info.startOffset; final int endOffset = info.endOffset; String s = text.substring(startOffset, endOffset); String desc = info.getDescription(); if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Extra " + rangeString(text, startOffset, endOffset) + " :'" + s + "'" + (desc == null ? "" : " (" + desc + ")") + " [" + info.type + "]"; } } final Collection<ExpectedHighlightingSet> expectedHighlights = myHighlightingTypes.values(); for (ExpectedHighlightingSet highlightingSet : reverseCollection(expectedHighlights)) { final Set<HighlightInfo> expInfos = highlightingSet.infos; for (HighlightInfo expectedInfo : expInfos) { if (!infosContainsExpectedInfo(infos, expectedInfo) && highlightingSet.enabled) { final int startOffset = expectedInfo.startOffset; final int endOffset = expectedInfo.endOffset; String s = text.substring(startOffset, endOffset); String desc = expectedInfo.getDescription(); if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Missing " + rangeString(text, startOffset, endOffset) + " :'" + s + "'" + (desc == null ? "" : " (" + desc + ")"); } } } if (!failMessage.isEmpty()) { compareTexts(infos, text, failMessage + "\n", filePath); } }
public void updateCabin(Cabin cabin, double deltaTime) { if (deltaTime > 0.2) return; if (cabin.isOn()) { switch (cabin.getState()) { case MOVE: double vector = cabin.getVector(); int vectorUnit = (int) (vector / Math.abs(vector)); double motor = motorOutput * earthGravity * deltaTime; // Nm/s (weight) -> kgfm if (motor <= gravity) { logger.debug("motor is too weak or gravity is too strong."); motor = gravity; } Floor target = cabin.getTarget(); double leftVector = target.getPosition() - cabin.getPosition(); int leftVectorUnit = (int) (leftVector / Math.abs(leftVector)); double accel = motor / mass(cabin) * leftVectorUnit; if (Math.abs(cabin.getVelocity()) > 1) accel *= Math.abs(vector * 0.5) < Math.abs(leftVector) ? 1 : -1; // brake on half point if (Double.isNaN(accel)) { accel = vectorUnit; } // logger.debug(String.format("%f -> %f (%f) : %f",cabin.getPosition(), // target.getPosition(),vector,accel)); // logger.debug(String.format("%s->%d, %f, %f, // %f",cabin.getName(),target.getNum(),accel,leftVector,vector*0.5)); updateCabin(cabin, accel, deltaTime); if (Math.abs(leftVector) < CABIN_MOVE_THRESHOLD) { // arrive cabin.setPosition(target.getPosition()); cabin.stop(); // cabin.getQueue().remove(target); logger.debug(String.format("%s->%d done", cabin.getName(), target.getNum())); } break; case STOP: logger.info("cabin({}) arrived", cabin.getName()); for (Floor floor : floors.values()) { if (cabin.getPosition() == floor.getPosition()) { logger.debug("on {}", floor); Iterator<Passenger> it = cabin.getPassengers().iterator(); while (it.hasNext()) { Passenger p = it.next(); if (p.getDest().equals(floor.getNum())) { p.setState(Passenger.State.NO_WAIT); it.remove(); floor.getPassengers().add(p); } } cabin.getQueue().remove(floor); } } if (cabin.getQueue().size() > 0) cabin.move(); // to next queued floor break; } } }
public boolean updateGridUI() { for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) { cell.setHideTabs(myContents.size() == 1); } final Content onlyContent = myContents.get(0); return onlyContent.getSearchComponent() != null; }
@NotNull protected Action[] createActions() { for (Configurable conf : myEnvToConfMap.values()) { if (conf.getHelpTopic() != null) { return new Action[] {getOKAction(), getCancelAction(), getHelpAction()}; } } return super.createActions(); }
public void processAddToUi(boolean restoreProportions) { if (restoreProportions) { for (final GridCellImpl cell : myPlaceInGrid2Cell.values()) { cell.restoreProportions(); } } updateSelection(true); }
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); } }
@NotNull private Set<NewColorAndFontPanel> getPanels() { Set<NewColorAndFontPanel> result = new HashSet<NewColorAndFontPanel>(); for (InnerSearchableConfigurable configurable : mySubPanelFactories.values()) { NewColorAndFontPanel panel = configurable.getSubPanelIfInitialized(); if (panel != null) { result.add(panel); } } return result; }
public boolean isModified() { if (myModuleModel.isChanged()) { return true; } for (ModuleEditor moduleEditor : myModuleEditors.values()) { if (moduleEditor.isModified()) { return true; } } return myModified || myFacetsConfigurator.isModified(); }
@Nullable public NewColorAndFontPanel findPage(String pageName) { if (mySubPanelFactories == null) { buildConfigurables(); } for (InnerSearchableConfigurable configurable : mySubPanelFactories.values()) { if (configurable.getDisplayName().equals(pageName)) { return configurable.createPanel(); } } return null; }
/** * This function re-computes the total number of hours for the selected period. It is ran every * time the user edits a text field specifying the number of hours for a particular top-level * project. Percentage labels are also updated. */ private void recomputeTotal() { double total = 0; for (Row row : rows.values()) { try { row.hours = Double.parseDouble(row.hoursTF.getText()); total += row.hours; row.hoursTF.setForeground(normalColour); } catch (NumberFormatException e) { row.hoursTF.setForeground(errorColour); totalLabel.setText("ERROR"); totalLabel.setForeground(errorColour); return; } } totalLabel.setText(decimalFormat.format(total)); totalLabel.setForeground(normalColour); for (Row row : rows.values()) { String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total); row.percentL.setText("(" + percentS + "%)"); } pack(); }
@Nullable public SwitchTarget getCellFor(Component c) { Component eachParent = c; while (eachParent != null) { for (GridCellImpl eachCell : myContent2Cell.values()) { if (eachCell.contains(eachParent)) { return eachCell.getTargetForSelection(); } } eachParent = eachParent.getParent(); } return null; }
private boolean expectedInfosContainsInfo(HighlightInfo info) { if (info.getTextAttributes(null, null) == TextAttributes.ERASE_MARKER) return true; final Collection<ExpectedHighlightingSet> expectedHighlights = myHighlightingTypes.values(); for (ExpectedHighlightingSet highlightingSet : expectedHighlights) { if (highlightingSet.severity != info.getSeverity()) continue; if (!highlightingSet.enabled) return true; final Set<HighlightInfo> infos = highlightingSet.infos; for (HighlightInfo expectedInfo : infos) { if (infoEquals(expectedInfo, info)) { return true; } } } return false; }
/** * Disable conditions not applicable at the current context (e.g. disable 'synchronized' if no * 'method' is selected). */ private void refreshConditions() { Pair<ArrangementMatchCondition, ArrangementSettingsToken> pair = buildCondition(); ArrangementMatchCondition condition = pair == null ? null : pair.first; for (ArrangementUiComponent component : myComponents.values()) { ArrangementSettingsToken token = component.getToken(); if (token == null) { continue; } boolean enabled = mySettingsManager.isEnabled(token, condition); component.setEnabled(enabled); if (!enabled) { component.setSelected(false); } } }
protected void doOKAction() { for (Configurable configurable : myEnvToConfMap.values()) { try { configurable.apply(); } catch (CancelledConfigurationException e) { return; } catch (ConfigurationException e) { Messages.showErrorDialog( myProject, VcsBundle.message("messge.text.cannot.save.settings", e.getLocalizedMessage()), getRealTitle()); return; } } super.doOKAction(); }
protected void doHelpAction() { String helpTopic = null; final Collection<Configurable> v = myEnvToConfMap.values(); final Configurable[] configurables = v.toArray(new Configurable[v.size()]); if (myMainPanel instanceof JTabbedPane) { final int tabIndex = ((JTabbedPane) myMainPanel).getSelectedIndex(); if (tabIndex >= 0 && tabIndex < configurables.length) { helpTopic = configurables[tabIndex].getHelpTopic(); } } else { helpTopic = configurables[0].getHelpTopic(); } if (helpTopic != null) { HelpManager.getInstance().invokeHelp(helpTopic); } else { super.doHelpAction(); } }
@NotNull @Override public Configurable[] buildConfigurables() { myDisposeCompleted = false; initAll(); List<ColorAndFontPanelFactory> panelFactories = createPanelFactories(); List<Configurable> result = new ArrayList<Configurable>(); mySubPanelFactories = new LinkedHashMap<ColorAndFontPanelFactory, InnerSearchableConfigurable>( panelFactories.size()); for (ColorAndFontPanelFactory panelFactory : panelFactories) { mySubPanelFactories.put(panelFactory, new InnerSearchableConfigurable(panelFactory)); } result.addAll(new ArrayList<SearchableConfigurable>(mySubPanelFactories.values())); return result.toArray(new Configurable[result.size()]); }
private void layoutHorizontal(final JPanel panel) { for (JSlider slider : mySliders.values()) { slider.setOrientation(SwingConstants.HORIZONTAL); slider.setPreferredSize(new Dimension(200, 40)); panel.add( slider, new GridBagConstraints( 0, 1, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0)); } }
@CalledInAwt public void updateData(@NotNull Map<Integer, LastRevision> revisions) { myRevisions = revisions; Date newestDate = null; int maxDateLength = 0; for (LastRevision revision : myRevisions.values()) { Date date = revision.getDate(); if (newestDate == null || date.after(newestDate)) { newestDate = date; } int length = DateFormatUtil.formatPrettyDate(date).length(); if (length > maxDateLength) { maxDateLength = length; } } myNewestDate = newestDate; myMaxDateLength = maxDateLength; }
private void onMouseClicked(@NotNull MouseEvent e) { if (myRow < 0) { return; } Point locationOnScreen = e.getLocationOnScreen(); for (ArrangementUiComponent component : myComponents.values()) { Rectangle screenBounds = component.getScreenBounds(); if (screenBounds == null || !screenBounds.contains(locationOnScreen)) { continue; } if (component.isEnabled()) { if (component.isSelected()) { removeCondition(component); } else { addCondition(component); } } apply(); return; } }
private boolean buildTree() { InspectionProfile profile = myInspectionProfile; boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY; myGroups.clear(); final Map<String, Tools> tools = myGlobalInspectionContext.getTools(); boolean resultsFound = false; for (Tools currentTools : tools.values()) { InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool(); final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName()); for (ScopeToolState state : myProvider.getTools(currentTools)) { InspectionToolWrapper toolWrapper = state.getTool(); if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) { addTool( toolWrapper, ((InspectionProfileImpl) profile) .getErrorLevel(key, state.getScope(myProject), myProject), isGroupedBySeverity); resultsFound = true; } } } return resultsFound; }
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; }