diff --git a/.gitattributes b/.gitattributes index 5f19988d661..8cdf4fd3192 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/main/java/forge/gui/toolbox/CardFaceSymbols.java b/src/main/java/forge/gui/toolbox/CardFaceSymbols.java index fa4ba43a539..a2e05e06e9f 100644 --- a/src/main/java/forge/gui/toolbox/CardFaceSymbols.java +++ b/src/main/java/forge/gui/toolbox/CardFaceSymbols.java @@ -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; /** *
@@ -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(); diff --git a/src/main/java/forge/view/arcane/CardPanel.java b/src/main/java/forge/view/arcane/CardPanel.java index 83e6c53fcad..cbbbe3dcb32 100644 --- a/src/main/java/forge/view/arcane/CardPanel.java +++ b/src/main/java/forge/view/arcane/CardPanel.java @@ -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)); } } diff --git a/src/main/java/forge/view/arcane/CardPanelContainer.java b/src/main/java/forge/view/arcane/CardPanelContainer.java index f08d46d8c34..340ee24c277 100644 --- a/src/main/java/forge/view/arcane/CardPanelContainer.java +++ b/src/main/java/forge/view/arcane/CardPanelContainer.java @@ -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 { *
*/ 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; } + + /** + *+ * invokeAndWait. + *
+ * + * @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); + } + } } diff --git a/src/main/java/forge/view/arcane/util/Animation.java b/src/main/java/forge/view/arcane/util/Animation.java index 933c50f5b46..75a28688315 100644 --- a/src/main/java/forge/view/arcane/util/Animation.java +++ b/src/main/java/forge/view/arcane/util/Animation.java @@ -140,6 +140,18 @@ public abstract class Animation { protected void end() { } + /** + *+ * invokeLater. + *
+ * + * @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,19 +409,14 @@ public abstract class Animation { * a {@link forge.view.arcane.CardPanel} object. */ public static void moveCard(final CardPanel placeholder) { - UI.invokeLater(new Runnable() { + Animation.invokeLater(new Runnable() { @Override public void run() { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - if (placeholder != null) { - placeholder.setDisplayEnabled(true); - // placeholder.setImage(imagePanel); - placeholder.setCard(placeholder.getGameCard()); - } - } - }); + if (placeholder != null) { + placeholder.setDisplayEnabled(true); + // placeholder.setImage(imagePanel); + placeholder.setCard(placeholder.getGameCard()); + } } }); } diff --git a/src/main/java/forge/view/arcane/util/UI.java b/src/main/java/forge/view/arcane/util/UI.java deleted file mode 100644 index 83c01378127..00000000000 --- a/src/main/java/forge/view/arcane/util/UI.java +++ /dev/null @@ -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, seeimageCache. */
- private static ConcurrentMap- * getToggleButton. - *
- * - * @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; - } - - /** - *- * getButton. - *
- * - * @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; - } - - /** - *- * setTitle. - *
- * - * @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)); - } - } - - /** - *- * getFileURL. - *
- * - * @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); - } - - /** - *- * getImageIcon. - *
- * - * @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); - } - } - - /** - *- * setHTMLEditorKit. - *
- * - * @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); - } - }; - } - }); - } - - /** - *- * setVerticalScrollingView. - *
- * - * @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); - } - - /** - *- * getDisplayManaCost. - *
- * - * @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; - } - - /** - *- * invokeLater. - *
- * - * @param runnable - * a {@link java.lang.Runnable} object. - */ - public static void invokeLater(final Runnable runnable) { - EventQueue.invokeLater(runnable); - } - - /** - *- * invokeAndWait. - *
- * - * @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); - } - } - - /** - *- * setDefaultFont. - *
- * - * @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); - } - } - } -}