master
Lodici 2013-11-03 20:52:01 +00:00
parent 757f78ed90
commit ffde20b221
2 changed files with 134 additions and 16 deletions

View File

@ -27,10 +27,15 @@ import magic.ui.widget.ZoneBackgroundLabel;
import net.miginfocom.swing.MigLayout;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
@ -74,6 +79,7 @@ public final class GamePanel extends JPanel {
private final JPanel stackContainer;
private final JSplitPane splitter;
private final TexturedPanel splitterContainer;
private final boolean isLogAutosizeMode = true;
public GamePanel(
final MagicFrame frame,
@ -139,14 +145,35 @@ public final class GamePanel extends JPanel {
stackContainer = new JPanel(new MigLayout("insets 0, gap 0"));
stackContainer.setOpaque(false);
if (isLogAutosizeMode) {
splitter = null;
splitterContainer = new TexturedPanel();
splitterContainer.setLayout(new MigLayout("insets 0, gap 0, flowy"));
} else {
splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitter.setBorder(FontsAndBorders.BLACK_BORDER);
splitter.setOneTouchExpandable(false);
splitter.setContinuousLayout(true);
splitter.setResizeWeight(0.5);
splitter.setOpaque(false);
splitter.setOpaque(true);
splitter.setDividerSize(4);
splitter.setUI(new BasicSplitPaneUI() {
@SuppressWarnings("serial")
@Override
public BasicSplitPaneDivider createDefaultDivider() {
return new BasicSplitPaneDivider(this) {
@Override
public Border getBorder() {
return BorderFactory.createLineBorder(Color.RED, 2);
}
};
}
});
splitterContainer = new TexturedPanel();
splitterContainer.setLayout(new MigLayout("insets 0, gap 0"));
}
updateView();
@ -379,21 +406,29 @@ public final class GamePanel extends JPanel {
sb.append("insets ").append(spacing).append(",") // margins
.append("gap 0 ").append(spacing).append(",") // gapx [gapy]
.append("flowy,")
.append("").toString())); // debug
.append("debug").toString())); // debug
r = result.getBoundary(ResolutionProfileType.GameOpponentViewer);
lhsPanel.add(opponentViewer, "w 100%, h " + r.height + "px!");
stackContainer.add(imageStackViewer, "w 100%, pushy, bottom");
if (isLogAutosizeMode) {
splitterContainer.add(logBookViewer, "w 100%, h 20:100%, growy");
splitterContainer.add(stackContainer, "w 100%, h min(pref, " + splitterContainer.getHeight() / 2 + "):pref");
} else {
splitter.setTopComponent(logBookViewer);
splitter.setBottomComponent(stackContainer);
splitterContainer.add(splitter, "w 100%, h 100%");
}
lhsPanel.add(splitterContainer, "w 100%, h 100%");
r = result.getBoundary(ResolutionProfileType.GameDuelViewer);
lhsPanel.add(gameDuelViewer, "w 100%, h " + r.height + "px!");
r = result.getBoundary(ResolutionProfileType.GamePlayerViewer);
lhsPanel.add(playerViewer, "w 100%, h " + r.height + "px!");
add(lhsPanel, "w 100%, h 100%");
add(lhsPanel, "w 100%, h 500!");
add(rhsPanel, "w 100%, h 100%");
}

View File

@ -10,11 +10,15 @@ import magic.ui.widget.TitleBar;
import magic.ui.widget.ViewerScrollPane;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.ScrollPaneConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
@ -31,6 +35,9 @@ public class StackViewer extends JPanel implements ChoiceViewer {
private final Collection<StackButton> buttons;
private Rectangle setRectangle = new Rectangle();
private JComponent layoutContainer = null;
final TitleBar stackTitleBar;
public StackViewer(final ViewerInfo viewerInfo,final GameController controller,final boolean image) {
this.viewerInfo=viewerInfo;
@ -43,17 +50,26 @@ public class StackViewer extends JPanel implements ChoiceViewer {
setLayout(new BorderLayout());
final Theme theme = ThemeFactory.getInstance().getCurrentTheme();
final TitleBar stackTitleBar = new TitleBar("Stack");
stackTitleBar = new TitleBar("Stack");
stackTitleBar.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK));
stackTitleBar.setIcon(theme.getIcon(Theme.ICON_SMALL_STACK));
add(stackTitleBar, BorderLayout.SOUTH);
add(stackTitleBar, BorderLayout.NORTH);
viewerPane=new ViewerScrollPane();
add(viewerPane,BorderLayout.CENTER);
buttons=new ArrayList<StackButton>();
// addComponentListener(new ComponentAdapter() {
// @Override
// public void componentResized(ComponentEvent e) {
// super.componentResized(e);
// System.out.println("StackViewer Resized : " + getSize());
// }
// });
update();
}
@Override
@ -68,6 +84,7 @@ public class StackViewer extends JPanel implements ChoiceViewer {
}
public void update() {
System.out.print("StackViewer.update()");
final int maxWidth=getWidth()-40;
@ -93,10 +110,76 @@ public class StackViewer extends JPanel implements ChoiceViewer {
}
}
int stackHeight = getBounds().height;
System.out.print(" : contentHeight = " + stackHeight); // contentHeight);
showValidChoices(controller.getValidChoices());
viewerPane.switchContent();
repaint();
System.out.println();
if (getParent() != null && layoutContainer == null) {
layoutContainer = (JComponent)getParent().getParent();
System.out.println(layoutContainer.getClass().getName());
}
if (layoutContainer != null) {
if (layoutContainer.getClass().getName() == "javax.swing.JSplitPane") {
setSplitterPosition((JSplitPane)layoutContainer, stackHeight);
} else if (layoutContainer.getClass().getName() == "magic.ui.widget.TexturedPanel") {
System.out.println("Validating JPanel");
Dimension d = new Dimension(getBounds().width, getBounds().height + 1);
setPreferredSize(d);
//setMinimumSize(d); //new Dimension(d.width, stackTitleBar.getHeight() * 3));
setMaximumSize(d);
viewerPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
layoutContainer.validate();
}
}
// //updateSplitterComponent(getBounds().height);
// if (getParent() != null && splitter == null) {
// Component c = getParent().getParent();
// if (c.getClass().getName() == "javax.swing.JSplitPane") {
// splitter = (JSplitPane)getParent().getParent();
// }
// }
//
// if (splitter != null) {
// setSplitterPosition(stackHeight);
// } else {
//
// }
}
private void setSplitterPosition(JSplitPane splitter, int stackHeight) {
if (splitter != null) {
System.out.println("splitter.getDividerLocation() = " + splitter.getDividerLocation());
splitter.setDividerLocation(splitter.getHeight() - stackHeight - stackTitleBar.getHeight());
//splitter.validate();
}
}
// private void updateSplitterComponent(int stackHeight) {
// if (stackHeight > 0 && splitter == null) {
// Component p = getParent();
// while (p != null) {
// if (p.getClass().getName() == "javax.swing.JSplitPane") {
// //splitter = (JSplitPane)p;
// break;
// }
// }
// }
// if (splitter != null) {
//
//// } else {
//// throw new NullPointerException("Could not locate JSplitPane component.");
//// }
// }
// }
public boolean isEmpty() {