Skip to content

Commit

Permalink
Merge pull request #3974 from kwvanderlinde/feature/3893-visual-separ…
Browse files Browse the repository at this point in the history
…ation-in-toolbar
  • Loading branch information
cwisniew authored Apr 19, 2023
2 parents abefb6d + 379b732 commit 3b597dc
Showing 1 changed file with 29 additions and 64 deletions.
93 changes: 29 additions & 64 deletions src/main/java/net/rptools/maptool/client/ui/ToolbarPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Enumeration;
import java.util.Hashtable;
import javax.swing.*;
import javax.swing.plaf.basic.BasicToolBarUI;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.functions.MediaPlayerAdapter;
import net.rptools.maptool.client.swing.SwingUtil;
Expand Down Expand Up @@ -49,25 +48,25 @@ public class ToolbarPanel extends JToolBar {
private final JToggleButton templateButton;
private final JToggleButton fogButton;
private final JToggleButton topologyButton;
private final Component horizontalSpacer;
/**
* The last component prior to the option panel. This is used to find the index at which to
* reinsert the option panel when the fullscreen tools are hidden.
*/
private final Component optionPanelSeparator;

private final JPanel optionPanel;
private final Toolbox toolbox;
private final JButton mapselect;

public ToolbarPanel(Toolbox tbox) {
setRollover(true);
setFloatable(false);

add(Box.createHorizontalStrut(5));

toolbox = tbox;
optionPanel = new JPanel(new CardLayout());

final JSeparator vertSplit = new JSeparator(JSeparator.VERTICAL);
final Component vertSpacer = Box.createHorizontalStrut(10);

final JSeparator horizontalSplit = new JSeparator(JSeparator.HORIZONTAL);
horizontalSplit.setVisible(false);
horizontalSpacer = Box.createVerticalStrut(10);
horizontalSpacer.setVisible(false);

pointerGroupButton = createPointerGroupButton();
add(pointerGroupButton);
drawButton =
Expand Down Expand Up @@ -99,10 +98,7 @@ public ToolbarPanel(Toolbox tbox) {
I18N.getText("tools.topo.tooltip"));
add(topologyButton);

add(vertSplit);
add(horizontalSplit);
add(vertSpacer);
add(horizontalSpacer);
optionPanelSeparator = addSeparator(this, 21);

add(optionPanel);

Expand Down Expand Up @@ -133,9 +129,7 @@ public ToolbarPanel(Toolbox tbox) {
add(jslider);
// End slider

add(Box.createHorizontalStrut(10));
add(new JSeparator(JSeparator.VERTICAL));
add(Box.createHorizontalStrut(10));
addSeparator(this, 21);

// Jamz: Adding new Token Selection option buttons
// Default selected button created with reference to set selection true
Expand Down Expand Up @@ -166,9 +160,7 @@ public ToolbarPanel(Toolbox tbox) {
I18N.getText("tools.token.fow.npc.tooltip"),
TokenSelection.NPC));

add(Box.createHorizontalStrut(10));
add(new JSeparator(JSeparator.VERTICAL));
add(Box.createHorizontalStrut(10));
addSeparator(this, 21);

tokenSelectionButtonAll.setSelected(true);
// Jamz: End panel
Expand All @@ -177,23 +169,13 @@ public ToolbarPanel(Toolbox tbox) {
mapselect = createZoneSelectionButton();
add(mapselect);

add(Box.createHorizontalStrut(5));

// Non visible tools
tbox.createTool(GridTool.class);
tbox.createTool(BoardTool.class);
tbox.createTool(FacingTool.class);
tbox.createTool(StampTool.class);

addPropertyChangeListener(
"orientation",
evt -> {
int orientation = (Integer) evt.getNewValue();

horizontalSplit.setVisible(orientation == JToolBar.VERTICAL);
horizontalSpacer.setVisible(orientation == JToolBar.VERTICAL);

vertSplit.setVisible(orientation == JToolBar.HORIZONTAL);
vertSpacer.setVisible(orientation == JToolBar.HORIZONTAL);
});
}

public JPanel getOptionPanel() {
Expand Down Expand Up @@ -221,7 +203,7 @@ public JToggleButton getTopologyButton() {
}

public int getOptionsPanelIndex() {
return getComponentIndex(horizontalSpacer) + 1;
return getComponentIndex(optionPanelSeparator) + 1;
}

public JButton getMapselect() {
Expand Down Expand Up @@ -387,15 +369,27 @@ private OptionPanel createTopologyPanel() {
.add(HollowDiamondTopologyTool.class)
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_DIAMOND_HOLLOW));

// Add with space to separate mode button group from shape button group.
panel.add(Box.createHorizontalStrut(10));
// Add with separator to separate mode button group from shape button group.
addSeparator(panel, 11);

final var topologyModeSelectionPanel = new TopologyModeSelectionPanel();
panel.add(topologyModeSelectionPanel);

return panel;
}

private static Component addSeparator(JToolBar toolBar, final int size) {
final var sep =
new JToolBar.Separator() {
@Override
public Dimension getPreferredSize() {
return new Dimension(size, super.getPreferredSize().height);
}
};
toolBar.add(sep);
return sep;
}

private JToggleButton createButton(
final Icons icon, final Icons offIcon, final OptionPanel panel, String tooltip) {
final JToggleButton button = new JToggleButton();
Expand Down Expand Up @@ -465,29 +459,6 @@ private JToggleButton createTokenSelectionButton(
return button;
}

/**
* Return the current floating status of the ToolbarPanel.
*
* @return true if floating, false otherwise
*/
private boolean isFloating() {
return getUI() instanceof BasicToolBarUI && ((BasicToolBarUI) ui).isFloating();
}

/**
* Show or hide the ToolbarPanel, even if it is floating.
*
* @param visible should the ToolbarPanel be visible or not
*/
@Override
public void setVisible(boolean visible) {
if (isFloating()) {
SwingUtilities.getRoot(this).setVisible(visible);
} else {
super.setVisible(visible);
}
}

public void setTokenSelectionGroupEnabled(boolean enabled) {
Enumeration<AbstractButton> enumeration = tokenSelectionbuttonGroup.getElements();
while (enumeration.hasMoreElements()) {
Expand All @@ -506,9 +477,6 @@ public OptionPanel() {
setRollover(true);
setBorder(null);
setBorderPainted(false);

ToolbarPanel.this.addPropertyChangeListener(
"orientation", evt -> setOrientation((Integer) evt.getNewValue()));
}

public Tool add(Class<? extends Tool> toolClass) {
Expand Down Expand Up @@ -544,9 +512,6 @@ public SidePanel() {
setRollover(true);
setBorder(null);
setBorderPainted(false);

ToolbarPanel.this.addPropertyChangeListener(
"orientation", evt -> setOrientation((Integer) evt.getNewValue()));
}

public Tool add(Class<? extends Tool> toolClass) {
Expand Down

0 comments on commit 3b597dc

Please sign in to comment.