Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the toolbar separators #3974

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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