MCPcopy Create free account
hub / github.com/FabricMC/Matcher / setCellStyle

Method setCellStyle

src/main/java/matcher/gui/MatchPaneSrc.java:255–314  ·  view source on GitHub ↗
(Cell<?> cell, Matchable<?> item)

Source from the content-addressed store, hash-verified

253 }
254
255 private void setCellStyle(Cell<?> cell, Matchable<?> item) {
256 CellStyleClass styleClass = null;
257
258 if (!gui.isUseDiffColors()) {
259 if (!item.hasPotentialMatch()) {
260 styleClass = CellStyleClass.NO_MATCH;
261 } else if (item.getMatch() == null) {
262 styleClass = CellStyleClass.LOW_MATCH_SIMILARITY;
263 } else if (!item.isFullyMatched(false)) { // TODO: change recursive to true once arg+var matching is further implemented
264 styleClass = CellStyleClass.MODERATE_MATCH_SIMILARITY;
265 } else {
266 styleClass = CellStyleClass.HIGH_MATCH_SIMILARITY;
267 }
268 } else {
269 final float epsilon = 1e-5f; // float rounding error
270 float similarity = item.getSimilarity();
271
272 if (similarity < epsilon) {
273 styleClass = CellStyleClass.LOW_MATCH_SIMILARITY;
274 } else if (similarity > 1 - epsilon) {
275 styleClass = CellStyleClass.HIGH_MATCH_SIMILARITY;
276 } else {
277 cell.setTextFill(null);
278 if (lowSimilarityCellTextColor == null || highSimilarityCellTextColor == null) return;
279
280 similarity = Math.round((similarity / diffColorStepAlignment)) * diffColorStepAlignment;
281 int similarityAsInt = (int) (similarity * 100);
282 Color textColor;
283
284 switch (Config.getTheme().getDiffColorInterpolationMode()) {
285 case RGB:
286 textColor = similarityToColorRgb.get(similarityAsInt);
287
288 if (textColor == null) {
289 textColor = interpolateRgb(lowSimilarityCellTextColor, highSimilarityCellTextColor, similarity);
290 similarityToColorRgb.put(similarityAsInt, textColor);
291 }
292
293 break;
294 case HSB:
295 textColor = similarityToColorHsb.get(similarityAsInt);
296
297 if (textColor == null) {
298 textColor = interpolateHsb(lowSimilarityCellTextColor, highSimilarityCellTextColor, similarity);
299 similarityToColorHsb.put(similarityAsInt, textColor);
300 }
301
302 break;
303 default:
304 throw new UnsupportedOperationException("Unsupported color interpolation mode!");
305 }
306
307 assert textColor != null;
308 cell.setTextFill(textColor);
309 }
310 }
311
312 cell.getStyleClass().removeAll(CellStyleClass.cssNames);

Callers 2

setCustomStyleMethod · 0.80
setCustomStyleMethod · 0.80

Calls 10

getThemeMethod · 0.95
interpolateRgbMethod · 0.95
interpolateHsbMethod · 0.95
isUseDiffColorsMethod · 0.80
hasPotentialMatchMethod · 0.65
getMatchMethod · 0.65
isFullyMatchedMethod · 0.65
getSimilarityMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected