Skip to content

Commit

Permalink
remove dead code, clean imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pyckle authored and Andrew Pikler committed Jun 13, 2024
1 parent 711b5aa commit ec61eeb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.github.pyckle.oref.integration.caching.OrefApiCachingService;
import com.github.pyckle.oref.integration.config.OrefConfig;
import com.github.pyckle.oref.integration.datetime.OrefDateTimeUtils;
import com.github.pyckle.oref.integration.dto.Alert;
import com.github.pyckle.oref.integration.dto.AlertHistory;
import com.github.pyckle.oref.integration.dto.HistoryEventWithParsedDates;
import org.slf4j.Logger;
Expand All @@ -20,9 +19,7 @@
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* This manages all alerts from all APIs and ensures they're stitched together correctly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
import java.time.LocalDateTime;
import java.util.List;

/**
* A class which can describe an alert received from any of Oref's REST APIs
*
* @param alertSource the source API of the alert
* @param receivedTimestamp the timestamp when this alert was received
* @param remoteTimestamp the timestamp the server specified for this alert. May fallback to local time if parsing fails
* @param isDrill whether this alert is a drill. See {@link com.github.pyckle.oref.alerts.categories.AlertCategories#isDrill(String)}
* @param category the category of this alert in Hebrew
* @param translatedCategory the category of this alert translated to the local language
* @param locations the translated alerted areas
* @param locationsHeb the alerted areas in Hebrew
*/
public record AlertDetails(
AlertSource alertSource,
Instant receivedTimestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.github.pyckle.oref.alerts.categories.AlertCategories;
import com.github.pyckle.oref.alerts.categories.dto.AlertCategory;
import com.github.pyckle.oref.integration.activealerts.ActiveAlert;
import com.github.pyckle.oref.integration.activealerts.AlertsRolloverStorage;
import com.github.pyckle.oref.integration.activealerts.FileTimeToInstantUtil;
import com.github.pyckle.oref.integration.caching.OrefApiCachingService;
import com.github.pyckle.oref.integration.config.OrefConfig;
import com.github.pyckle.oref.integration.datetime.OrefDateTimeUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import com.github.pyckle.oref.integration.activealerts.AlertsRolloverStorage;
import com.github.pyckle.oref.integration.config.OrefApiUris;
import com.github.pyckle.oref.integration.config.OrefConfig;
import com.github.pyckle.oref.integration.translationstores.CategoryDescriptionStore;
import com.github.pyckle.oref.integration.translationstores.DistrictStore;
import com.github.pyckle.oref.integration.dto.Alert;
import com.github.pyckle.oref.integration.dto.AlertHistory;
import com.github.pyckle.oref.integration.dto.Category;
import com.github.pyckle.oref.integration.dto.District;
import com.github.pyckle.oref.integration.dto.HistoryEventWithParsedDates;
import com.github.pyckle.oref.integration.dto.LeftoverAlertDescription;
import com.github.pyckle.oref.integration.translationstores.CategoryDescriptionStore;
import com.github.pyckle.oref.integration.translationstores.DistrictStore;
import com.google.gson.reflect.TypeToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Objects;

/**
* A service that stores caching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@

import com.github.pyckle.oref.alerts.AlertsManager;
import com.github.pyckle.oref.alerts.details.AlertDetails;
import com.github.pyckle.oref.integration.activealerts.ActiveAlert;
import com.github.pyckle.oref.integration.activealerts.AlertTimestamps;
import com.github.pyckle.oref.integration.caching.AlertStatus;
import com.github.pyckle.oref.integration.caching.CachedApiResult;
import com.github.pyckle.oref.integration.caching.OrefApiCachingService;
import com.github.pyckle.oref.integration.config.OrefConfig;
import com.github.pyckle.oref.integration.datetime.OrefDateTimeUtils;
import com.github.pyckle.oref.integration.translationstores.DistrictStore;
import com.github.pyckle.oref.integration.dto.HistoryEventWithParsedDates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class PekudeiOrefView {
private static final Logger logger = LoggerFactory.getLogger(PekudeiOrefView.class);
Expand All @@ -49,6 +41,11 @@ public PekudeiOrefView(OrefConfig orefConfig) {
panel.setOpaque(false);
}

private static int getWidthInPx(String text, Graphics g, Font f) {
FontMetrics fontMetrics = g.getFontMetrics(f);
return fontMetrics.stringWidth(text);
}

public JPanel getPanel() {
return panel;
}
Expand Down Expand Up @@ -126,7 +123,7 @@ private void rewriteAlerts(LocalDateTime activeAlertThreshold) {
for (String loc : alertDetails.locations()) {
activeAlertsDrawn |= isActive;
String newGroupedLocs = groupedLocs + (groupedLocs.isEmpty() ? "" : ", ") + loc;
boolean nextLocFits = maxAlertWidth >= ResizeUtils.getWidthInPx(newGroupedLocs, this.panel.getGraphics(), f);
boolean nextLocFits = maxAlertWidth >= getWidthInPx(newGroupedLocs, this.panel.getGraphics(), f);
if (nextLocFits) {
groupedLocs = newGroupedLocs;
} else {
Expand Down Expand Up @@ -164,10 +161,10 @@ private static String getGroupedAlertTitle(AlertDetails alertDetails) {
}

private int maxGroupedAlertTitle(List<AlertDetails> alertDetails, Font f) {
int ret = ResizeUtils.getWidthInPx(getAlertUpdatedStr(), this.panel.getGraphics(), f);
int ret = getWidthInPx(getAlertUpdatedStr(), this.panel.getGraphics(), f);
for (var alertDetail : alertDetails) {
ret = Math.max(ret, ResizeUtils.getWidthInPx(getGroupedAlertTitle(alertDetail), this.panel.getGraphics(), f));
ret = Math.max(ret, ResizeUtils.getWidthInPx(getDateLabel(alertDetail), this.panel.getGraphics(), f));
ret = Math.max(ret, getWidthInPx(getGroupedAlertTitle(alertDetail), this.panel.getGraphics(), f));
ret = Math.max(ret, getWidthInPx(getDateLabel(alertDetail), this.panel.getGraphics(), f));
}
return ret + 16; // add pixels so text doesn't sit on each other
}
Expand Down Expand Up @@ -201,41 +198,10 @@ public void triggerResize(int width, int height) {
rewriteAlerts(getActiveAlertThreshold());
}

private void internalTriggerResize(int numUsedCols, int maxNumRows) {
if (this.infoLabels.isEmpty() || this.infoLabels.get(0).getText().isEmpty()) {
return;
}

final int maxLabelWidth = this.maxWidth / numUsedCols;
final int maxLabelHeight = this.maxHeight / maxNumRows;
Font newFont = findBiggestPossibleFont(maxLabelWidth, maxLabelHeight);
setNewFont(newFont.getSize());
this.panel.revalidate();
this.panel.repaint();
}

private static LocalDateTime getActiveAlertThreshold() {
return LocalDateTime.now().minusSeconds(180);
}

private Font findBiggestPossibleFont(int maxLabelWidth, int maxLabelHeight) {
Font newFont = infoLabels.get(0).getFont();
int maxFontSize = Integer.MAX_VALUE;
for (JLabel l : infoLabels) {
Font bestFontForRow = ResizeUtils.findBestFontSize(panel.getGraphics(), l.getFont(), l.getText(),
maxLabelWidth, maxLabelHeight, maxFontSize);
if (bestFontForRow.getSize() < maxFontSize) {
newFont = bestFontForRow;
maxFontSize = newFont.getSize();
}
}
return newFont;
}

private void setNewFont(int fontSize) {
infoLabels.forEach(l -> l.setFont(ResizeUtils.cloneFont(l.getFont(), fontSize)));
}

private void addNextCellToPanel(GridPlaceTracker tracker, boolean isBold, Color color, String message) {
GridBagConstraints gc = new GridBagConstraints();
JLabel label = createLabel(orefConfig.getMinFontSize(), color, isBold);
Expand Down Expand Up @@ -301,13 +267,5 @@ public int getRow() {
public int getCol() {
return orefConfig.isRightToLeft() ? maxNumCols - col : col;
}

public int numColsUsed() {
return Math.max(1, row > 0 ? col + 1 : col);
}

public int getRowsUsed() {
return Math.max(1, rowsUsed);
}
}
}
}

This file was deleted.

0 comments on commit ec61eeb

Please sign in to comment.