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

feat: Remove html usage #1777

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void setupRequirements()
coins = new ItemRequirement("Coins", ItemCollections.COINS, 5);
coins.setTooltip("10 if you buy a fishing rod from Jack");
fishingPass = new ItemRequirement("Fishing Pass", ItemID.FISHING_PASS);
fishingPass.setTooltip("<html>This can be obtained during the quest<br>If you lose this you can get another from Vestri.</html>");
fishingPass.setTooltip("This can be obtained during the quest\n\nIf you lose this you can get another from Vestri.");
garlic = new ItemRequirement("Garlic", ItemID.GARLIC);
garlic.setTooltip("This can be obtained during the quest.");
garlic.setHighlightInInventory(true);
Expand Down
28 changes: 12 additions & 16 deletions src/main/java/com/questhelper/panel/AssistLevelPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public AssistLevelPanel()
JPanel titlePanel = new FixedWidthPanel();
titlePanel.setLayout(new BorderLayout());

JLabel title = new JLabel();
title.setText("<html>Choose Assist Level</html>");
JTextArea title = JGenerator.makeJTextArea("Choose Assist Level");
title.setForeground(Color.WHITE);
title.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

Expand Down Expand Up @@ -99,13 +98,14 @@ private JPanel createMinimumAssistPanel(QuestHelper questHelper)
JPanel minAssistPanel = new JPanel();
minAssistPanel.setLayout(new BorderLayout());

JLabel title = new JLabel();
title.setText("<html>Minimum Assistance</html>");
JTextArea title = JGenerator.makeJTextArea();
title.setText("Minimum Assistance");
title.setForeground(Color.WHITE);
title.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

JLabel description = new JLabel();
description.setText("<html>This disables most overlay-based help, and hides puzzle solutions. This is a good option if you just want the sidebar with helpful information, as it will still track where you are in the quest, and show items needed.</html>");
JTextArea description = JGenerator.makeJTextArea();
description.setText("This disables most overlay-based help, and hides puzzle solutions. This is a good option if you just want the sidebar with helpful information, " +
"as it will still track where you are in the quest, and show items needed.");
description.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

JButton select = new JButton();
Expand Down Expand Up @@ -138,14 +138,12 @@ private JPanel createMediumAssistPanel(QuestHelper questHelper)
JPanel medAssistPanel = new JPanel();
medAssistPanel.setLayout(new BorderLayout());

JLabel title = new JLabel();
title.setText("<html>Medium Assistance</html>");
JTextArea title = JGenerator.makeJTextArea("Medium Assistance");
title.setForeground(Color.WHITE);
title.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

JLabel description = new JLabel();
description.setText(
"<html>This enables most overlay-based help, but hides puzzle solutions. This is a good option if you want to still have guidance, but still solve certain parts for yourself.</p></html>");
JTextArea description = JGenerator.makeJTextArea("This enables most overlay-based help, but hides puzzle solutions. " +
"This is a good option if you want to still have guidance, but still solve certain parts for yourself.");
description.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

JButton select = new JButton();
Expand Down Expand Up @@ -178,14 +176,12 @@ private JPanel createFullAssistPanel(QuestHelper questHelper)
JPanel fullAssistPanel = new JPanel();
fullAssistPanel.setLayout(new BorderLayout());

JLabel title = new JLabel();
title.setText("<html>Full Assistance</html>");
JTextArea title = JGenerator.makeJTextArea("Full Assistance");
title.setForeground(Color.WHITE);
title.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

JLabel description = new JLabel();
description.setText(
"<html>Gives you the full helper experience, highlighting objects & dialogue options, puzzler solvers, and with arrows so you know where to go.</html>");
JTextArea description = JGenerator.makeJTextArea("Gives you the full helper experience, highlighting objects & dialogue options, puzzler solvers, and " +
"with arrows so you know where to go.");
description.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

JButton select = new JButton();
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/com/questhelper/panel/JGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2024, Zoinkwiz <https://github.com/Zoinkwiz>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.questhelper.panel;

import javax.swing.*;
import javax.swing.border.EmptyBorder;

public class JGenerator
{
public static JLabel makeJLabel()
{
JLabel jLabel = new JLabel();
jLabel.putClientProperty("html.disable", Boolean.TRUE);
return jLabel;
}

public static JLabel makeJLabel(String text)
{
JLabel jLabel = new JLabel(text);
jLabel.putClientProperty("html.disable", Boolean.TRUE);
return jLabel;
}

public static JTextPane makeJTextPane()
{
JTextPane titlePane = new JTextPane();
titlePane.setEditable(false);
titlePane.setFocusable(false);
titlePane.setOpaque(false);

return titlePane;
}

public static JTextPane makeJTextPane(String text)
{
JTextPane titlePane = new JTextPane();
titlePane.setEditable(false);
titlePane.setFocusable(false);
titlePane.setOpaque(false);
titlePane.setText(text);

return titlePane;
}

public static JTextArea makeJTextArea()
{
JTextArea jTextArea = new JTextArea();
jTextArea.setLineWrap(true);
jTextArea.setWrapStyleWord(true);
jTextArea.setOpaque(false);
jTextArea.setEditable(false);
jTextArea.setFocusable(false);
jTextArea.setBackground(javax.swing.UIManager.getColor("Label.background"));
jTextArea.setBorder(new EmptyBorder(0, 0, 0, 0));

return jTextArea;
}

public static JTextArea makeJTextArea(String text)
{
JTextArea jTextArea = new JTextArea(text);
jTextArea.setLineWrap(true);
jTextArea.setWrapStyleWord(true);
jTextArea.setOpaque(false);
jTextArea.setEditable(false);
jTextArea.setFocusable(false);
jTextArea.setBackground(javax.swing.UIManager.getColor("Label.background"));
jTextArea.setBorder(new EmptyBorder(0, 0, 0, 0));

return jTextArea;
}
}
37 changes: 25 additions & 12 deletions src/main/java/com/questhelper/panel/QuestHelperPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
Expand Down Expand Up @@ -81,8 +80,7 @@ public class QuestHelperPanel extends PluginPanel
private final JPanel allDropdownSections = new JPanel();
private final JComboBox<Enum> filterDropdown, difficultyDropdown, orderDropdown;

private final JLabel skillExpandButton = new JLabel();

private final JButton skillExpandButton = new JButton();
private final IconTextField searchBar = new IconTextField();
private final FixedWidthPanel questListPanel = new FixedWidthPanel();
private final FixedWidthPanel questListWrapper = new FixedWidthPanel();
Expand Down Expand Up @@ -130,7 +128,7 @@ public QuestHelperPanel(QuestHelperPlugin questHelperPlugin, QuestManager questM
titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
titlePanel.setLayout(new BorderLayout());

JLabel title = new JLabel();
JTextArea title = JGenerator.makeJTextArea();
title.setText("Quest Helper");
title.setForeground(Color.WHITE);
titlePanel.add(title, BorderLayout.WEST);
Expand Down Expand Up @@ -250,10 +248,9 @@ public void mouseExited(java.awt.event.MouseEvent evt)

titlePanel.add(viewControls, BorderLayout.EAST);

JLabel questsCompletedLabel = new JLabel();
JTextArea questsCompletedLabel = JGenerator.makeJTextArea();
questsCompletedLabel.setForeground(Color.GRAY);
questsCompletedLabel.setText("<html><body style='text-align:left'>Please log in to see available quests" +
".</body></html>");
questsCompletedLabel.setText("Please log in to see available quests");

allQuestsCompletedPanel.setLayout(new BorderLayout());
allQuestsCompletedPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
Expand Down Expand Up @@ -317,12 +314,28 @@ public void changedUpdate(DocumentEvent e)
SkillFilterPanel skillFilterPanel = new SkillFilterPanel(questHelperPlugin.skillIconManager, questHelperPlugin.getConfigManager());
skillFilterPanel.setVisible(false);

JLabel filterName = new JLabel("Skill filtering");
JLabel filterName = JGenerator.makeJLabel("Skill filtering");
filterName.setForeground(Color.WHITE);
skillExpandButton.setForeground(Color.GRAY);
skillExpandButton.setIcon(COLLAPSED_ICON);
skillExpandButton.setHorizontalTextPosition(SwingConstants.LEFT);
skillExpandButton.setIconTextGap(10);
skillExpandButton.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent mouseEvent)
{
skillFilterPanel.setVisible(!skillFilterPanel.isVisible());
if (skillFilterPanel.isVisible())
{
skillExpandButton.setIcon(EXPANDED_ICON);
}
else
{
skillExpandButton.setIcon(COLLAPSED_ICON);
}
}
});

JPanel skillExpandBar = new JPanel();
skillExpandBar.setLayout(new BorderLayout());
Expand Down Expand Up @@ -427,7 +440,7 @@ private JComboBox<Enum> makeNewDropdown(Enum[] values, String key)
private JPanel makeDropdownPanel(JComboBox dropdown, String name)
{
// Filters
JLabel filterName = new JLabel(name);
JTextArea filterName = JGenerator.makeJTextArea(name);
filterName.setForeground(Color.WHITE);

JPanel filtersPanel = new JPanel();
Expand Down Expand Up @@ -542,15 +555,15 @@ public void refresh(List<QuestHelper> questHelpers, boolean loggedOut,
if (questSelectPanels.isEmpty() || !hasMoreQuests)
{
allQuestsCompletedPanel.removeAll();
JLabel noMatch = new JLabel();
JTextArea noMatch = JGenerator.makeJTextArea();
noMatch.setForeground(Color.GRAY);
if (loggedOut)
{
noMatch.setText("<html><body style='text-align:left'>Log in to see available quests</body></html>");
noMatch.setText("Log in to see available quests");
}
else
{
noMatch.setText("<html><body style='text-align:left'>No quests are available that match your current filters</body></html>");
noMatch.setText("No quests are available that match your current filters");
}
allQuestsCompletedPanel.add(noMatch);
}
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/com/questhelper/panel/QuestOverviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class QuestOverviewPanel extends JPanel

private final JPanel introPanel = new JPanel();

private final JLabel questNameLabel = new JLabel();
private final JLabel questNameLabel = JGenerator.makeJLabel();

private static final ImageIcon CLOSE_ICON = Icon.CLOSE.getIcon();

Expand Down Expand Up @@ -129,7 +129,6 @@ public QuestOverviewPanel(QuestHelperPlugin questHelperPlugin, QuestManager ques
actionsContainer.add(viewControls, BorderLayout.EAST);

questNameLabel.setForeground(Color.WHITE);
questNameLabel.setText("");
final JPanel leftTitleContainer = new JPanel(new BorderLayout(5, 0));
leftTitleContainer.setBackground(ColorScheme.DARKER_GRAY_COLOR);
leftTitleContainer.add(questNameLabel, BorderLayout.CENTER);
Expand All @@ -151,7 +150,7 @@ public QuestOverviewPanel(QuestHelperPlugin questHelperPlugin, QuestManager ques
configHeaderPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
configHeaderPanel.setLayout(new BorderLayout());
configHeaderPanel.setBorder(new EmptyBorder(5, 5, 5, 10));
JLabel configHeaderText = new JLabel();
JTextArea configHeaderText = JGenerator.makeJTextArea();
configHeaderText.setForeground(Color.WHITE);
configHeaderText.setText("Configuration:");
configHeaderText.setMinimumSize(new Dimension(1, configHeaderPanel.getPreferredSize().height));
Expand Down Expand Up @@ -241,7 +240,7 @@ private JComboBox<Enum> makeNewDropdown(Enum[] values, String key)
private JPanel makeDropdownPanel(JComboBox dropdown, String name)
{
// Filters
JLabel filterName = new JLabel(name);
JTextArea filterName = JGenerator.makeJTextArea(name);
filterName.setForeground(Color.WHITE);

JPanel filtersPanel = new JPanel();
Expand Down Expand Up @@ -322,7 +321,7 @@ public void updateSteps()
questStepPanelList.forEach(panel -> {
for (QuestStep step : panel.getSteps())
{
JLabel label = panel.getStepsLabels().get(step);
JTextPane label = panel.getStepsLabels().get(step);
if (label != null)
{
label.setText(panel.generateText(step));
Expand Down Expand Up @@ -395,7 +394,7 @@ public void setupQuestRequirements(QuestHelper quest)
configHeaderPanel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
configHeaderPanel.setLayout(new BorderLayout());
configHeaderPanel.setBorder(new EmptyBorder(5, 5, 5, 10));
JLabel configHeaderText = new JLabel();
JTextArea configHeaderText = JGenerator.makeJTextArea();
configHeaderText.setForeground(Color.WHITE);
configHeaderText.setText("Configuration:");
configHeaderText.setMinimumSize(new Dimension(1, configHeaderPanel.getPreferredSize().height));
Expand Down Expand Up @@ -528,7 +527,7 @@ else if (requirement instanceof QuestPointRequirement)

private void updateCombatRequirementsPanels(List<String> combatRequirementList)
{
JLabel combatLabel = new JLabel();
JTextArea combatLabel = JGenerator.makeJTextArea();
combatLabel.setForeground(Color.GRAY);
StringBuilder textCombat = new StringBuilder();
if (combatRequirementList == null)
Expand All @@ -537,13 +536,18 @@ private void updateCombatRequirementsPanels(List<String> combatRequirementList)
}
else
{
for (String combatRequirement : combatRequirementList)
var first = true;
for (var combatRequirement : combatRequirementList)
{
if (!first)
{
textCombat.append("\n");
}
textCombat.append(combatRequirement);
textCombat.append("<br>");
first = false;
}
}
combatLabel.setText("<html><body style = 'text-align:left'>" + textCombat + "</body></html>");
combatLabel.setText(textCombat.toString());

questCombatRequirementsListPanel.add(combatLabel);
}
Expand All @@ -558,8 +562,6 @@ private void updateExternalResourcesPanel(QuestHelper quest)
{
externalResourcesList = Collections.singletonList("https://oldschool.runescape.wiki/w/" + StringUtils.lowerCase(URLEncoder.encode(quest.getQuest().name(), StandardCharsets.UTF_8)));
}
JLabel externalResources = new JLabel();
externalResources.setForeground(Color.GRAY);
JButton wikiBtn = new JButton();

//Button constant properties
Expand Down Expand Up @@ -595,7 +597,6 @@ public void mouseExited(java.awt.event.MouseEvent evt)
}

questExternalResourcesList.removeAll();
questExternalResourcesList.add(externalResources);
questExternalResourcesList.add(wikiBtn, BorderLayout.EAST);
}

Expand All @@ -604,14 +605,19 @@ private void updateQuestNotes(List<String> notes)
if (notes != null)
{
var textNote = new StringBuilder();
for (String note : notes)
var first = true;
for (var note : notes)
{
if (!first)
{
textNote.append("\n\n");
}
textNote.append(note);
textNote.append("<br><br>");
first = false;
}
var overviewLabel = new JLabel();
var overviewLabel = JGenerator.makeJTextArea();
overviewLabel.setForeground(Color.GRAY);
overviewLabel.setText("<html><body style = 'text-align:left'>" + textNote + "</body></html>");
overviewLabel.setText(textNote.toString());

questNotesList.add(overviewLabel);
questNotesPanel.setVisible(true);
Expand Down
Loading
Loading