mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
refactor: removed some outdated GUI components and code
This commit is contained in:
parent
d016e4c4c3
commit
550e97e1e3
4 changed files with 29 additions and 182 deletions
|
|
@ -225,79 +225,6 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
action.actionPerformed(null);
|
||||
}
|
||||
|
||||
public static class ImageRenderer2 extends JEditorPane implements ListCellRenderer {
|
||||
|
||||
public final Map<String, String> cache = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(
|
||||
javax.swing.JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus
|
||||
) {
|
||||
|
||||
setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 6));
|
||||
|
||||
UI.setHTMLEditorKit(this);
|
||||
|
||||
setOpaque(false);
|
||||
setBackground(new Color(0, 0, 0, 0));
|
||||
|
||||
String text = value.toString();
|
||||
|
||||
if (cache.containsKey(text)) {
|
||||
text = cache.get(text);
|
||||
} else {
|
||||
StringBuilder buffer = getHtmlForText(isSelected, text);
|
||||
String rendered = buffer.toString();
|
||||
cache.put(text, rendered);
|
||||
text = rendered;
|
||||
}
|
||||
|
||||
final String finalText = text;
|
||||
// System.out.println(finalText);
|
||||
|
||||
ImageRenderer2.super.setText(finalText);
|
||||
setCaretPosition(0);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private StringBuilder getHtmlForText(boolean isSelected, String text) {
|
||||
int fontSize = 16;
|
||||
|
||||
String fontFamily = "arial";
|
||||
|
||||
final StringBuilder buffer = new StringBuilder(512);
|
||||
buffer.append("<html><body style='font-family:");
|
||||
buffer.append(fontFamily);
|
||||
buffer.append(";font-size:");
|
||||
buffer.append(fontSize);
|
||||
buffer.append("pt;margin:3px 3px 3px 3px;");
|
||||
if (isSelected) {
|
||||
buffer.append("color: #4093D0'>");
|
||||
} else {
|
||||
buffer.append("color: #FFFFFF'>");
|
||||
}
|
||||
buffer.append("<b>");
|
||||
|
||||
text = text.replaceAll("#([^#]+)#", "<i>$1</i>");
|
||||
text = text.replaceAll("\\s*//\\s*", "<hr width='50%'>");
|
||||
text = text.replace("\r\n", "<div style='font-size:5pt'></div>");
|
||||
//text += "<br>";
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
buffer.append(ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.DIALOG));
|
||||
}
|
||||
|
||||
buffer.append("</b></body></html>");
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ImageRenderer extends DefaultListCellRenderer {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
package mage.client.components.ext;
|
||||
|
||||
import org.mage.card.arcane.UI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class MageFloatPane extends JEditorPane {
|
||||
|
||||
public MageFloatPane() {
|
||||
UI.setHTMLEditorKit(this);
|
||||
setEditable(false);
|
||||
setBackground(Color.white);
|
||||
JButton jb = new JButton("Done");
|
||||
jb.setLocation(50, 50);
|
||||
jb.setSize(100, 50);
|
||||
add(jb);
|
||||
}
|
||||
|
||||
public void setCard(final String text) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
setText(text);
|
||||
setCaretPosition(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package mage.client.components.ext;
|
||||
|
||||
import mage.client.components.MageRoundPane;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author ayratn
|
||||
*/
|
||||
public final class TestMageFloatPane {
|
||||
|
||||
public static void main(String... args) {
|
||||
JFrame f = new JFrame();
|
||||
|
||||
f.setSize(600, 400);
|
||||
f.setVisible(true);
|
||||
|
||||
MageFloatPane fp = new MageFloatPane();
|
||||
fp.setCard("Card");
|
||||
|
||||
MageRoundPane popupContainer = new MageRoundPane();
|
||||
popupContainer.setLayout(null);
|
||||
|
||||
popupContainer.add(fp);
|
||||
//popupContainer.setVisible(false);
|
||||
popupContainer.setBounds(0, 0, 320 + 80, 201 + 80);
|
||||
|
||||
|
||||
JDialog floatOnParent = new JDialog(f, false);
|
||||
floatOnParent.setUndecorated(true);
|
||||
floatOnParent.getContentPane().add(popupContainer);
|
||||
|
||||
floatOnParent.setBounds(300, 100, 300, 200);
|
||||
floatOnParent.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,15 +2,17 @@ package org.mage.card.arcane;
|
|||
|
||||
import mage.utils.StreamUtils;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.text.Element;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.View;
|
||||
import javax.swing.text.ViewFactory;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.html.ImageView;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -24,46 +26,25 @@ import java.util.Objects;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JViewport;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.ViewportLayout;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.text.Element;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.View;
|
||||
import javax.swing.text.ViewFactory;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.html.ImageView;
|
||||
|
||||
/**
|
||||
* UI utility functions.
|
||||
*/
|
||||
public final class UI {
|
||||
private static final ConcurrentMap<URI, Image> imageCache = new ConcurrentHashMap<>();
|
||||
|
||||
public static JToggleButton getToggleButton () {
|
||||
public static JToggleButton getToggleButton() {
|
||||
JToggleButton button = new JToggleButton();
|
||||
button.setMargin(new Insets(2, 4, 2, 4));
|
||||
return button;
|
||||
}
|
||||
|
||||
public static JButton getButton () {
|
||||
public static JButton getButton() {
|
||||
JButton button = new JButton();
|
||||
button.setMargin(new Insets(2, 4, 2, 4));
|
||||
return button;
|
||||
}
|
||||
|
||||
public static void setTitle (JPanel panel, String title) {
|
||||
public static void setTitle(JPanel panel, String title) {
|
||||
Border border = panel.getBorder();
|
||||
if (border instanceof TitledBorder) {
|
||||
((TitledBorder) panel.getBorder()).setTitle(title);
|
||||
|
|
@ -73,7 +54,7 @@ public final class UI {
|
|||
}
|
||||
}
|
||||
|
||||
public static ImageIcon getImageIcon (String path) {
|
||||
public static ImageIcon getImageIcon(String path) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = UI.class.getResourceAsStream(path);
|
||||
|
|
@ -93,14 +74,17 @@ public final class UI {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setHTMLEditorKit (JEditorPane editorPane) {
|
||||
editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written.
|
||||
public static void setHTMLEditorKit(JEditorPane editorPane) {
|
||||
editorPane.setEditorKit(new HTMLEditorKit());
|
||||
if (true) return;
|
||||
|
||||
// TODO: wtf, is it used to display images by url?! Remove that code after few releases if no bug reports, 27.11.2023
|
||||
editorPane.getDocument().putProperty("imageCache", imageCache); // Read internally by ImageView, but never written.
|
||||
editorPane.setEditorKit(new HTMLEditorKit() {
|
||||
private static final long serialVersionUID = -54602188235105448L;
|
||||
|
||||
@Override
|
||||
public ViewFactory getViewFactory () {
|
||||
public ViewFactory getViewFactory() {
|
||||
return new HTMLFactory() {
|
||||
@Override
|
||||
public View create(Element elem) {
|
||||
|
|
@ -133,12 +117,13 @@ public final class UI {
|
|||
});
|
||||
}
|
||||
|
||||
public static void setVerticalScrollingView (JScrollPane scrollPane, final Component view) {
|
||||
public static void setVerticalScrollingView(JScrollPane scrollPane, final Component view) {
|
||||
final JViewport viewport = new JViewport();
|
||||
viewport.setLayout(new ViewportLayout() {
|
||||
private static final long serialVersionUID = 7701568740313788935L;
|
||||
|
||||
@Override
|
||||
public void layoutContainer (Container parent) {
|
||||
public void layoutContainer(Container parent) {
|
||||
viewport.setViewPosition(new Point(0, 0));
|
||||
Dimension viewportSize = viewport.getSize();
|
||||
int width = viewportSize.width;
|
||||
|
|
@ -151,7 +136,7 @@ public final class UI {
|
|||
scrollPane.setViewport(viewport);
|
||||
}
|
||||
|
||||
public static String getDisplayManaCost (String manaCost) {
|
||||
public static String getDisplayManaCost(String manaCost) {
|
||||
// A pipe in the cost means "process left of the pipe as the card color, but display right of the pipe as the cost".
|
||||
int pipePosition = manaCost.indexOf("{|}");
|
||||
if (pipePosition != -1) {
|
||||
|
|
@ -160,11 +145,11 @@ public final class UI {
|
|||
return manaCost;
|
||||
}
|
||||
|
||||
public static void invokeLater (Runnable runnable) {
|
||||
public static void invokeLater(Runnable runnable) {
|
||||
EventQueue.invokeLater(runnable);
|
||||
}
|
||||
|
||||
public static void invokeAndWait (Runnable runnable) {
|
||||
public static void invokeAndWait(Runnable runnable) {
|
||||
if (EventQueue.isDispatchThread()) {
|
||||
runnable.run();
|
||||
return;
|
||||
|
|
@ -177,7 +162,7 @@ public final class UI {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setSystemLookAndFeel () {
|
||||
public static void setSystemLookAndFeel() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -186,7 +171,7 @@ public final class UI {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setDefaultFont (Font font) {
|
||||
public static void setDefaultFont(Font font) {
|
||||
for (Object key : Collections.list(UIManager.getDefaults().keys())) {
|
||||
Object value = UIManager.get(key);
|
||||
if (value instanceof javax.swing.plaf.FontUIResource) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue