mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Added a kinda console to display messages coming from network
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14080,6 +14080,7 @@ src/main/java/forge/gui/CardDetailPanel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/CardListViewer.java -text
|
||||
src/main/java/forge/gui/CardPicturePanel.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/DualListBox.java -text
|
||||
src/main/java/forge/gui/FNetOverlay.java -text
|
||||
src/main/java/forge/gui/ForgeAction.java svneol=native#text/plain
|
||||
src/main/java/forge/gui/GuiChoose.java -text
|
||||
src/main/java/forge/gui/GuiDialog.java -text
|
||||
|
||||
108
src/main/java/forge/gui/FNetOverlay.java
Normal file
108
src/main/java/forge/gui/FNetOverlay.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextArea;
|
||||
import forge.gui.toolbox.FTextField;
|
||||
import forge.gui.toolbox.SmartScroller;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public enum FNetOverlay {
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final JPanel pnl = new OverlayPanel();
|
||||
/** @return {@link javax.swing.JPanel} */
|
||||
public JPanel getPanel() {
|
||||
return this.pnl;
|
||||
}
|
||||
|
||||
private final JTextArea txtLog = new FTextArea();
|
||||
private final FTextField txtInput = new FTextField.Builder().maxLength(60).build();
|
||||
|
||||
private boolean minimized = false;
|
||||
private int height = 120;
|
||||
private int width = 400;
|
||||
|
||||
private final int minimizedHeight = 30;
|
||||
|
||||
/**
|
||||
* Semi-transparent overlay panel. Should be used with layered panes.
|
||||
*/
|
||||
private FNetOverlay() {
|
||||
pnl.setOpaque(false);
|
||||
pnl.setVisible(false);
|
||||
pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
|
||||
pnl.setBorder(BorderFactory.createLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS)));
|
||||
|
||||
pnl.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap"));
|
||||
// pnl.add(new FLabel.Builder().text("Loading new game...").fontSize(22).build(), "h 40px!, align center");
|
||||
|
||||
// Block all input events below the overlay
|
||||
pnl.addMouseListener(new MouseAdapter() { });
|
||||
pnl.addMouseMotionListener(new MouseMotionAdapter() { });
|
||||
pnl.addKeyListener(new KeyAdapter() { });
|
||||
|
||||
txtLog.setOpaque(true);
|
||||
txtLog.setFocusable(true);
|
||||
txtLog.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
|
||||
txtLog.setText("console is here\nconsole is here\nconsole is here\nconsole is here\nconsole is here\nconsole is here\nconsole is here\nconsole is here");
|
||||
|
||||
JScrollPane _operationLogScroller = new JScrollPane(txtLog);
|
||||
_operationLogScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
_operationLogScroller.setBorder(null);
|
||||
new SmartScroller(_operationLogScroller);
|
||||
pnl.add(_operationLogScroller, "pushx, hmin 24, growy, growx, gap 2px 2px 2px 0");
|
||||
|
||||
pnl.add(txtInput, "pushx, growx, h 26px!, gap 0 0 2px 0");
|
||||
}
|
||||
|
||||
private class OverlayPanel extends JPanel {
|
||||
private static final long serialVersionUID = -5056220798272120558L;
|
||||
|
||||
/**
|
||||
* For some reason, the alpha channel background doesn't work properly on
|
||||
* Windows 7, so the paintComponent override is required for a
|
||||
* semi-transparent overlay.
|
||||
*
|
||||
* @param g
|
||||
*   Graphics object
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(this.getBackground());
|
||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param mainBounds
|
||||
*/
|
||||
public void containerResized(Rectangle mainBounds) {
|
||||
int w = Math.max(width, (int)(mainBounds.width * 0.25f));
|
||||
int x = mainBounds.width - w;
|
||||
int y = mainBounds.height - height;
|
||||
getPanel().setBounds(x, y, w, height);
|
||||
getPanel().validate();
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
txtLog.append(message);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package forge.gui.framework;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
@@ -18,6 +19,7 @@ import java.util.Set;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import forge.gui.FNetOverlay;
|
||||
import forge.gui.toolbox.FOverlay;
|
||||
import forge.view.FView;
|
||||
|
||||
@@ -114,7 +116,10 @@ public final class SResizingUtil {
|
||||
final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent();
|
||||
final JPanel pnlInsets = FView.SINGLETON_INSTANCE.getPnlInsets();
|
||||
|
||||
FOverlay.SINGLETON_INSTANCE.getPanel().setBounds(FView.SINGLETON_INSTANCE.getFrame().getContentPane().getBounds());
|
||||
Rectangle mainBounds = FView.SINGLETON_INSTANCE.getFrame().getContentPane().getBounds();
|
||||
FOverlay.SINGLETON_INSTANCE.getPanel().setBounds(mainBounds);
|
||||
FNetOverlay.SINGLETON_INSTANCE.containerResized(mainBounds);
|
||||
|
||||
pnlInsets.setBounds(FView.SINGLETON_INSTANCE.getFrame().getContentPane().getBounds());
|
||||
pnlInsets.validate();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.gui.home;
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.gui.FNetOverlay;
|
||||
import forge.gui.deckeditor.CDeckEditorUI;
|
||||
import forge.gui.deckeditor.controllers.CEditorConstructed;
|
||||
import forge.gui.framework.EDocID;
|
||||
@@ -81,6 +82,8 @@ public enum CHomeUI implements ICDoc {
|
||||
FControl.SINGLETON_INSTANCE.getServer().listen();
|
||||
VHomeUI.SINGLETON_INSTANCE.getLblStopServer().setEnabled(true);
|
||||
VHomeUI.SINGLETON_INSTANCE.getLblStartServer().setEnabled(false);
|
||||
|
||||
FNetOverlay.SINGLETON_INSTANCE.getPanel().setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -90,6 +93,8 @@ public enum CHomeUI implements ICDoc {
|
||||
FControl.SINGLETON_INSTANCE.getServer().stop();
|
||||
VHomeUI.SINGLETON_INSTANCE.getLblStopServer().setEnabled(false);
|
||||
VHomeUI.SINGLETON_INSTANCE.getLblStartServer().setEnabled(true);
|
||||
|
||||
FNetOverlay.SINGLETON_INSTANCE.getPanel().setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.google.common.collect.Lists;
|
||||
import forge.Singletons;
|
||||
import forge.control.FControl;
|
||||
import forge.control.RestartUtil;
|
||||
import forge.gui.FNetOverlay;
|
||||
import forge.gui.ImportDialog;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.deckeditor.VDeckEditorUI;
|
||||
@@ -107,6 +108,7 @@ public enum FView {
|
||||
// has a null layout, so new components will be W0 x H0 pixels - gotcha!
|
||||
// FControl has a method called "sizeComponents" which will fix this.
|
||||
lpnDocument.add(TargetingOverlay.SINGLETON_INSTANCE.getPanel(), TARGETING_LAYER);
|
||||
lpnDocument.add(FNetOverlay.SINGLETON_INSTANCE.getPanel(), TARGETING_LAYER);
|
||||
|
||||
pnlInsets.add(pnlContent, BorderLayout.CENTER);
|
||||
pnlInsets.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE));
|
||||
|
||||
Reference in New Issue
Block a user