mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Remove UI class since most methods are never called, the rest may be moved to classes that use them
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14530,7 +14530,6 @@ src/main/java/forge/view/arcane/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/view/arcane/util/Animation.java svneol=native#text/plain
|
||||
src/main/java/forge/view/arcane/util/CardPanelMouseListener.java svneol=native#text/plain
|
||||
src/main/java/forge/view/arcane/util/GlowText.java svneol=native#text/plain
|
||||
src/main/java/forge/view/arcane/util/UI.java svneol=native#text/plain
|
||||
src/main/java/forge/view/arcane/util/package-info.java svneol=native#text/plain
|
||||
src/main/java/forge/view/package-info.java svneol=native#text/plain
|
||||
src/main/resources/proxy-template.ftl -text
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.view.arcane.util.UI;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -167,11 +166,11 @@ public class CardFaceSymbols {
|
||||
* @param w an int
|
||||
* @param h and int
|
||||
*/
|
||||
public static void draw(final Graphics g, String s, int x, final int y, final int w, final int h) {
|
||||
public static void drawOther(final Graphics g, String s, int x, final int y, final int w, final int h) {
|
||||
if (s.length() == 0) {
|
||||
return;
|
||||
}
|
||||
s = UI.getDisplayManaCost(s);
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(s, " ");
|
||||
while (tok.hasMoreTokens()) {
|
||||
String symbol = tok.nextToken();
|
||||
|
||||
@@ -415,7 +415,7 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
if (this.getCard() != null && this.getGameCard().getFoil() > 0) {
|
||||
final String fl = String.format("foil%02d", this.getCard().getFoil());
|
||||
final int z = Math.round(this.cardWidth * CardPanel.BLACK_BORDER_SIZE);
|
||||
CardFaceSymbols.draw(g, fl, this.cardXOffset + z, this.cardYOffset + z, this.cardWidth - (2 * z),
|
||||
CardFaceSymbols.drawOther(g, fl, this.cardXOffset + z, this.cardYOffset + z, this.cardWidth - (2 * z),
|
||||
this.cardHeight - (2 * z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
package forge.view.arcane;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,7 +35,6 @@ import forge.Card;
|
||||
import forge.Constant;
|
||||
import forge.gui.match.CMatchUI;
|
||||
import forge.view.arcane.util.CardPanelMouseListener;
|
||||
import forge.view.arcane.util.UI;
|
||||
|
||||
/**
|
||||
* Manages mouse events and common functionality for CardPanel containing
|
||||
@@ -296,7 +297,7 @@ public abstract class CardPanelContainer extends JPanel {
|
||||
* a {@link forge.view.arcane.CardPanel} object.
|
||||
*/
|
||||
public final void removeCardPanel(final CardPanel fromPanel) {
|
||||
UI.invokeAndWait(new Runnable() {
|
||||
CardPanelContainer.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (CardPanelContainer.this.getMouseDragPanel() != null) {
|
||||
@@ -321,7 +322,7 @@ public abstract class CardPanelContainer extends JPanel {
|
||||
* </p>
|
||||
*/
|
||||
public final void clear() {
|
||||
UI.invokeAndWait(new Runnable() {
|
||||
CardPanelContainer.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CardPanelContainer.this.getCardPanels().clear();
|
||||
@@ -623,4 +624,25 @@ public abstract class CardPanelContainer extends JPanel {
|
||||
public void setMouseDragPanel(final CardPanel mouseDragPanel0) {
|
||||
this.mouseDragPanel = mouseDragPanel0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* invokeAndWait.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable
|
||||
* a {@link java.lang.Runnable} object.
|
||||
*/
|
||||
public static void invokeAndWait(final Runnable runnable) {
|
||||
if (EventQueue.isDispatchThread()) {
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
EventQueue.invokeAndWait(runnable);
|
||||
} catch (InterruptedException ex) {
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +140,18 @@ public abstract class Animation {
|
||||
protected void end() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* invokeLater.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable
|
||||
* a {@link java.lang.Runnable} object.
|
||||
*/
|
||||
public static void invokeLater(final Runnable runnable) {
|
||||
EventQueue.invokeLater(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses averaging of the time between the past few frames to provide smooth
|
||||
* animation.
|
||||
@@ -248,7 +260,7 @@ public abstract class Animation {
|
||||
public static void moveCardToPlay(final int startX, final int startY, final int startWidth, final int endX,
|
||||
final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder,
|
||||
final JLayeredPane layeredPane, final int speed) {
|
||||
UI.invokeLater(new Runnable() {
|
||||
Animation.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
|
||||
@@ -343,7 +355,7 @@ public abstract class Animation {
|
||||
public static void moveCard(final int startX, final int startY, final int startWidth, final int endX,
|
||||
final int endY, final int endWidth, final CardPanel animationPanel, final CardPanel placeholder,
|
||||
final JLayeredPane layeredPane, final int speed) {
|
||||
UI.invokeLater(new Runnable() {
|
||||
Animation.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
|
||||
@@ -397,10 +409,7 @@ public abstract class Animation {
|
||||
* a {@link forge.view.arcane.CardPanel} object.
|
||||
*/
|
||||
public static void moveCard(final CardPanel placeholder) {
|
||||
UI.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
Animation.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (placeholder != null) {
|
||||
@@ -411,8 +420,6 @@ public abstract class Animation {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -1,326 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.view.arcane.util;
|
||||
|
||||
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 java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
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;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
/**
|
||||
* UI utility functions.
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UI {
|
||||
/** Constant <code>imageCache</code>. */
|
||||
private static ConcurrentMap<URI, Image> imageCache = new MapMaker().softValues().makeMap();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getToggleButton.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link javax.swing.JToggleButton} object.
|
||||
*/
|
||||
public static JToggleButton getToggleButton() {
|
||||
JToggleButton button = new JToggleButton();
|
||||
button.setMargin(new Insets(2, 4, 2, 4));
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getButton.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link javax.swing.JButton} object.
|
||||
*/
|
||||
public static JButton getButton() {
|
||||
JButton button = new JButton();
|
||||
button.setMargin(new Insets(2, 4, 2, 4));
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setTitle.
|
||||
* </p>
|
||||
*
|
||||
* @param panel
|
||||
* a {@link javax.swing.JPanel} object.
|
||||
* @param title
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public static void setTitle(final JPanel panel, final String title) {
|
||||
Border border = panel.getBorder();
|
||||
if (border instanceof TitledBorder) {
|
||||
((TitledBorder) panel.getBorder()).setTitle(title);
|
||||
panel.repaint();
|
||||
} else {
|
||||
panel.setBorder(BorderFactory.createTitledBorder(title));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getFileURL.
|
||||
* </p>
|
||||
*
|
||||
* @param path
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.net.URL} object.
|
||||
*/
|
||||
public static URL getFileURL(final String path) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return file.toURI().toURL();
|
||||
} catch (MalformedURLException ignored) {
|
||||
}
|
||||
}
|
||||
return UI.class.getResource(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImageIcon.
|
||||
* </p>
|
||||
*
|
||||
* @param path
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link javax.swing.ImageIcon} object.
|
||||
*/
|
||||
public static ImageIcon getImageIcon(final String path) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
try {
|
||||
stream = UI.class.getResourceAsStream(path);
|
||||
if (stream == null && new File(path).exists()) {
|
||||
stream = new FileInputStream(path);
|
||||
}
|
||||
if (stream == null) {
|
||||
throw new RuntimeException("Image not found: " + path);
|
||||
}
|
||||
byte[] data = new byte[stream.available()];
|
||||
stream.read(data);
|
||||
return new ImageIcon(data);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Error reading image: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setHTMLEditorKit.
|
||||
* </p>
|
||||
*
|
||||
* @param editorPane
|
||||
* a {@link javax.swing.JEditorPane} object.
|
||||
*/
|
||||
public static void setHTMLEditorKit(final JEditorPane editorPane) {
|
||||
editorPane.getDocument().putProperty("imageCache", imageCache); // Read
|
||||
// internally
|
||||
// by
|
||||
// ImageView,
|
||||
// but
|
||||
// never
|
||||
// written.
|
||||
// Extend all this shit to cache images.
|
||||
editorPane.setEditorKit(new HTMLEditorKit() {
|
||||
private static final long serialVersionUID = -562969765076450440L;
|
||||
|
||||
@Override
|
||||
public ViewFactory getViewFactory() {
|
||||
return new HTMLFactory() {
|
||||
@Override
|
||||
public View create(final Element elem) {
|
||||
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
|
||||
if (o instanceof HTML.Tag) {
|
||||
HTML.Tag kind = (HTML.Tag) o;
|
||||
if (kind == HTML.Tag.IMG) {
|
||||
return new ImageView(elem) {
|
||||
@Override
|
||||
public URL getImageURL() {
|
||||
URL url = super.getImageURL();
|
||||
// Put an image into the cache to be
|
||||
// read by other ImageView methods.
|
||||
if (url != null && imageCache.get(url) == null) {
|
||||
try {
|
||||
imageCache.put(url.toURI(), Toolkit.getDefaultToolkit()
|
||||
.createImage(url));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return super.create(elem);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setVerticalScrollingView.
|
||||
* </p>
|
||||
*
|
||||
* @param scrollPane
|
||||
* a {@link javax.swing.JScrollPane} object.
|
||||
* @param view
|
||||
* a {@link java.awt.Component} object.
|
||||
*/
|
||||
public static void setVerticalScrollingView(final JScrollPane scrollPane, final Component view) {
|
||||
final JViewport viewport = new JViewport();
|
||||
viewport.setLayout(new ViewportLayout() {
|
||||
private static final long serialVersionUID = -4436977380450713628L;
|
||||
|
||||
@Override
|
||||
public void layoutContainer(final Container parent) {
|
||||
viewport.setViewPosition(new Point(0, 0));
|
||||
Dimension viewportSize = viewport.getSize();
|
||||
int width = viewportSize.width;
|
||||
int height = Math.max(view.getPreferredSize().height, viewportSize.height);
|
||||
viewport.setViewSize(new Dimension(width, height));
|
||||
}
|
||||
});
|
||||
viewport.setView(view);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setViewport(viewport);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDisplayManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @param manaCost
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getDisplayManaCost(String manaCost) {
|
||||
manaCost = manaCost.replace("/", "");
|
||||
manaCost = manaCost.replace("X 0", "X");
|
||||
// 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) {
|
||||
manaCost = manaCost.substring(pipePosition + 3);
|
||||
}
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* invokeLater.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable
|
||||
* a {@link java.lang.Runnable} object.
|
||||
*/
|
||||
public static void invokeLater(final Runnable runnable) {
|
||||
EventQueue.invokeLater(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* invokeAndWait.
|
||||
* </p>
|
||||
*
|
||||
* @param runnable
|
||||
* a {@link java.lang.Runnable} object.
|
||||
*/
|
||||
public static void invokeAndWait(final Runnable runnable) {
|
||||
if (EventQueue.isDispatchThread()) {
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
EventQueue.invokeAndWait(runnable);
|
||||
} catch (InterruptedException ex) {
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setDefaultFont.
|
||||
* </p>
|
||||
*
|
||||
* @param font
|
||||
* a {@link java.awt.Font} object.
|
||||
*/
|
||||
public static void setDefaultFont(final Font font) {
|
||||
for (Object key : Collections.list(UIManager.getDefaults().keys())) {
|
||||
Object value = UIManager.get(key);
|
||||
if (value instanceof javax.swing.plaf.FontUIResource) {
|
||||
UIManager.put(key, font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user