Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Prediction Breakdowns By Default #148

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/botdetector/BotDetectorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface BotDetectorConfig extends Config
String SHOW_FEEDBACK_TEXTBOX = "showFeedbackTextbox";
String SHOW_DISCORD_VERIFICATION_ERRORS = "showDiscordVerificationErrors";
String ANONYMOUS_UUID_KEY = "anonymousUUID";
String AUTO_SHOW_BREAKDOWN_PANEL_KEY = "autoShowBreakdownPanel";

int AUTO_SEND_MINIMUM_MINUTES = 5;
int AUTO_SEND_MAXIMUM_MINUTES = 360;
Expand Down Expand Up @@ -183,6 +184,15 @@ default PanelFontType panelFontType()
return PanelFontType.NORMAL;
}

@ConfigItem(
position = 5,
keyName = AUTO_SHOW_BREAKDOWN_PANEL_KEY,
name = "Auto Show Prediction Breakdown",
description = "Automatically shows the prediction breakdown panel when receiving a prediction.",
section = panelSection
)
default boolean autoShowBreakdownPanel() {return false;}

@ConfigItem(
position = 1,
keyName = ADD_PREDICT_OPTION_KEY,
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/botdetector/BotDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ private void onConfigChanged(ConfigChanged event)
case BotDetectorConfig.ONLY_SEND_AT_LOGOUT_KEY:
updateTimeToAutoSend();
break;
case BotDetectorConfig.AUTO_SHOW_BREAKDOWN_PANEL_KEY:
SwingUtilities.invokeLater(() -> panel.setPredictionBreakdownButtons());
break;
}
}

Expand Down
89 changes: 88 additions & 1 deletion src/main/java/com/botdetector/ui/BotDetectorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public enum WarningLabel
private JLabel predictionPlayerNameLabel;
private JLabel predictionTypeLabel;
private JLabel predictionConfidenceLabel;
private JButton showPredictionBreakdownButton;
private JButton hidePredictionBreakdownButton;

// Prediction Breakdown
private JLabel predictionBreakdownLabel;
Expand Down Expand Up @@ -705,6 +707,36 @@ private JPanel primaryPredictionPanel()
primaryPredictionPanel.add(predictionConfidenceLabel, c);
switchableFontComponents.add(predictionConfidenceLabel);


showPredictionBreakdownButton = new JButton("Show Breakdown");
showPredictionBreakdownButton.setToolTipText("<html>View the complete breakdown of the prediction for the selected account." +
"<br><span style='color:red'>NOTE:</span> We only utilize the primary prediction for our bot detection purposes.</html>");
showPredictionBreakdownButton.setForeground(HEADER_COLOR);
showPredictionBreakdownButton.setFont(SMALL_FONT);
showPredictionBreakdownButton.addActionListener(l -> setPredictionBreakdownPanel(true));
showPredictionBreakdownButton.setFocusable(false);
c.gridx = 0;
c.weightx = 0;
c.gridwidth = 2;
c.gridy++;
primaryPredictionPanel.add(showPredictionBreakdownButton, c);
setShowPredictionBreakdownButton(false);


hidePredictionBreakdownButton = new JButton("Hide Breakdown");
hidePredictionBreakdownButton.setToolTipText("<html>Close the prediction breakdown panel.</html>");
hidePredictionBreakdownButton.setForeground(HEADER_COLOR);
hidePredictionBreakdownButton.setFont(SMALL_FONT);
hidePredictionBreakdownButton.addActionListener(l -> setPredictionBreakdownPanel(false));
hidePredictionBreakdownButton.setFocusable(false);
c.gridx = 0;
c.weightx = 0;
c.gridwidth = 2;
c.gridy++;
primaryPredictionPanel.add(hidePredictionBreakdownButton, c);
setHidePredictionBreakdownButton(false);


return primaryPredictionPanel;
}

Expand Down Expand Up @@ -1039,6 +1071,59 @@ public void setFeedbackTextboxVisible(boolean visible)
feedbackTextScrollPane.setVisible(visible);
}

/**
* Sets the visibility of the button that shows the prediction breakdown panel.
* @param visible The visibility to apply on the show prediction breakdown panel button.
*/
public void setShowPredictionBreakdownButton(boolean visible)
{
showPredictionBreakdownButton.setVisible(visible);
}

/**
* Sets the visibility of the button that hide the prediction breakdown panel.
* @param visible The visibility to apply on the hide prediction breakdown panel button.
*/
public void setHidePredictionBreakdownButton(boolean visible)
{
hidePredictionBreakdownButton.setVisible(visible);
}

/**
* Sets visibility of prediction breakdown panel and shows appropriate show/hide button in the primary panel.
* @param visible The desired visibility state of the breakdown panel.
*/
private void setPredictionBreakdownPanel(boolean visible)
{
predictionBreakdownPanel.setVisible(visible);

setPredictionBreakdownButtons();

}

/**
* Sets visibility of the "Show Breakdown" and "Hide Breakdown" buttons in the Primary Prediction panel.
*/
public void setPredictionBreakdownButtons()
{
if(config.autoShowBreakdownPanel())
{
//If the user opted to auto show prediction breakdown then hide buttons.
setHidePredictionBreakdownButton(false);
setShowPredictionBreakdownButton(false);
}
else if(predictionBreakdownPanel.isVisible())
{
setHidePredictionBreakdownButton(true);
setShowPredictionBreakdownButton(false);
}
else
{
setHidePredictionBreakdownButton(false);
setShowPredictionBreakdownButton(true);
}
}

/**
* Forcibly hides the feedback panel.
*/
Expand Down Expand Up @@ -1112,7 +1197,7 @@ public void setPrediction(Prediction pred, PlayerSighting sighting)
else
{
predictionBreakdownLabel.setText(toPredictionBreakdownString(pred.getPredictionBreakdown()));
predictionBreakdownPanel.setVisible(true);
setPredictionBreakdownPanel(config.autoShowBreakdownPanel());

final String primaryLabel = pred.getPredictionLabel();

Expand Down Expand Up @@ -1191,6 +1276,8 @@ public void setPrediction(Prediction pred, PlayerSighting sighting)
predictionConfidenceLabel.setText(EMPTY_LABEL);
predictionBreakdownLabel.setText(EMPTY_LABEL);

setPredictionBreakdownPanel(false);
setShowPredictionBreakdownButton(false);
predictionBreakdownPanel.setVisible(false);
predictionFeedbackPanel.setVisible(false);
predictionFlaggingPanel.setVisible(false);
Expand Down