Skip to content

Commit

Permalink
Merge pull request #4653 from bubblobill/UI_Text_Token_Props_Tooltips
Browse files Browse the repository at this point in the history
Reworked Token Type/Properties Editor tab
  • Loading branch information
cwisniew authored Jan 21, 2024
2 parents b29054f + 239285b commit eb34a2a
Show file tree
Hide file tree
Showing 8 changed files with 618 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public JTextField getTextField(String name) {
return (JTextField) getComponent(name);
}

public Collection<Component> getAllCompoments() {
public Collection<Component> getAllComponents() {
if (componentMap == null) {
createComponentMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void actionPerformed(ActionEvent e) {
private void initTokenPropertiesDialog(AbeillePanel panel) {
tokenPropertiesPanel = new TokenPropertiesManagementPanel();
panel.replaceComponent("propertiesPanel", "tokenPropertiesPanel", tokenPropertiesPanel);
tokenPropertiesPanel.prettify();
}

public JTextField getNewServerTextField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import net.rptools.CaseInsensitiveHashMap;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.swing.AbeillePanel;
Expand All @@ -35,9 +36,11 @@
import net.rptools.maptool.model.sheet.stats.StatSheetLocation;
import net.rptools.maptool.model.sheet.stats.StatSheetManager;
import net.rptools.maptool.model.sheet.stats.StatSheetProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class TokenPropertiesManagementPanel extends AbeillePanel<CampaignProperties> {

private static final Logger log = LogManager.getLogger(TokenPropertiesManagementPanel.class);
private Map<String, List<TokenProperty>> tokenTypeMap;
private final Map<String, StatSheetProperties> tokenTypeStatSheetMap = new HashMap<>();
private String editingType;
Expand Down Expand Up @@ -104,6 +107,10 @@ public JButton getTypeDeleteButton() {
return (JButton) getComponent("typeDeleteButton");
}

public JButton getTypeDuplicateButton() {
return (JButton) getComponent("typeDuplicateButton");
}

public JButton getPropertyMoveUpButton() {
return (JButton) getComponent("propertyMoveUpButton");
}
Expand Down Expand Up @@ -136,10 +143,22 @@ public JButton getTypeSetAsDefault() {
return (JButton) getComponent("typeDefaultButton");
}

public JButton getHelpButton() {
return (JButton) getComponent("helpButton");
}

public JPanel getDescriptionContainer() {
return (JPanel) getComponent("descriptionContainer");
}

public TokenPropertiesTableModel getTokenPropertiesTableModel() {
return (TokenPropertiesTableModel) getTokenPropertiesTable().getModel();
}

public JScrollPane getTableScrollPane() {
return (JScrollPane) getComponent("tokenPropertiesTableScrollPane");
}

public void initTypeAddButton() {
getTypeAddButton()
.addActionListener(
Expand Down Expand Up @@ -284,6 +303,41 @@ public void initPropertyDeleteButton() {
button.setEnabled(false);
}

public void initTypeDuplicateButton() {
var button = getTypeDuplicateButton();
button.addActionListener(
e ->
EventQueue.invokeLater(
() -> {
log.info("Type Duplicate - button action");
var propertyType = (String) getTokenTypeList().getSelectedValue();
if (propertyType != null) {
String newName = propertyType + "@";
tokenTypeMap.put(newName, tokenTypeMap.get(propertyType));
updateTypeList();
getTokenTypeList().setSelectedValue(newName, true);
button.setEnabled(true);
}
}));
button.setEnabled(false);
}

public void initDescriptionContainer() {
getDescriptionContainer().setVisible(false);
}

public void initHelpButton() {
var button = getHelpButton();
button.addActionListener(
e ->
EventQueue.invokeLater(
() -> {
JPanel helpText = getDescriptionContainer();
helpText.setVisible(!helpText.isVisible());
}));
button.setEnabled(true);
}

public void initPropertyTable() {
var propertyTable = getTokenPropertiesTable();
propertyTable.setModel(new TokenPropertiesTableModel());
Expand All @@ -309,9 +363,6 @@ public void initPropertyTable() {
getTokenPropertiesTable().getSelectedRow()
< getTokenPropertiesTable().getRowCount() - 1);
});
propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
propertyTable.getColumnModel().getColumn(0).setPreferredWidth(80);
propertyTable.getColumnModel().getColumn(2).setPreferredWidth(100);
}

public void initTokenTypeName() {
Expand Down Expand Up @@ -365,13 +416,15 @@ public void initTypeList() {
reset();
getPropertyAddButton().setEnabled(false);
getTypeDeleteButton().setEnabled(false);
getTypeDuplicateButton().setEnabled(false);
getTokenTypeName().setEditable(false);
getStatSheetComboBox().setEnabled(false);
getStatSheetLocationComboBox().setEnabled(false);
getTypeSetAsDefault().setEnabled(false);
} else {
bind((String) getTokenTypeList().getSelectedValue());
getPropertyAddButton().setEnabled(true);
getTypeDuplicateButton().setEnabled(true);
getTokenTypeName().setEditable(true);
// Can't delete the default property
if (propertyType.equals(defaultPropertyType)) {
Expand Down Expand Up @@ -612,6 +665,118 @@ private List<TokenProperty> parseTokenProperties(String propertyText)
return propertyList;
}

public void prettify() {

/* fix text areas to look like labels
* dig down to the appropriate container level
* then set the backgrounds to transparent
*/
JPanel jPanel = (JPanel) super.getComponent("descriptionContainer");
List<Component> jPanels =
Arrays.stream(jPanel.getComponents()).filter(c -> c instanceof JPanel).toList();

Color transparent = new Color(0, 0, 0, 1);
for (Component panel : jPanels) {
JPanel jp = (JPanel) panel;
Component[] components = jp.getComponents();
Arrays.stream(components).toList().forEach(c -> c.setBackground(transparent));
}

JTable propertyTable = getTokenPropertiesTable();
/* prettify - take cell background colour and adjust the luminance for cell contrast.
change the hue and saturation for the grid line colour
*/
Color bg, bgSmall, gridColour;
bg = propertyTable.getTableHeader().getComponent(0).getBackground(); // get background colour
float[] hsbComponents = new float[3];
Color.RGBtoHSB(bg.getRed(), bg.getGreen(), bg.getBlue(), hsbComponents); // convert to HSB

boolean lighten = hsbComponents[2] < 0.5f; // to determine direction of change
hsbComponents[2] =
lighten
? hsbComponents[2] + 0.015f
: hsbComponents[2] - 0.025f; // small change in brilliance
bgSmall = new Color(Color.HSBtoRGB(hsbComponents[0], hsbComponents[1], hsbComponents[2]));

hsbComponents[2] =
lighten
? hsbComponents[2] + 0.04f
: hsbComponents[2] - 0.02f; // bigger change in brilliance
bg = new Color(Color.HSBtoRGB(hsbComponents[0], hsbComponents[1], hsbComponents[2]));

hsbComponents[0] =
hsbComponents[0] < 0.5
? hsbComponents[0] + 0.5f
: hsbComponents[0] - 0.5f; // change hue 180 degrees
hsbComponents[1] =
hsbComponents[1] < 0.25
? hsbComponents[1] + 0.25f // increase saturation if it is low
: hsbComponents[1];
gridColour = new Color(Color.HSBtoRGB(hsbComponents[0], hsbComponents[1], hsbComponents[2]));

DefaultTableCellRenderer cellRenderer =
new DefaultTableCellRenderer(); // cell renderer for contrasting cells
cellRenderer.setBackground(bgSmall);
cellRenderer.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

DefaultTableCellRenderer headerRenderer =
new DefaultTableCellRenderer(); // cell renderer for contrasting headings
headerRenderer.setBackground(bg);
headerRenderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
headerRenderer.setVerticalAlignment(SwingConstants.TOP);

DefaultTableCellRenderer headerRenderer2 = new DefaultTableCellRenderer();
headerRenderer2.setVerticalAlignment(SwingConstants.TOP);
headerRenderer2.setHorizontalAlignment(SwingConstants.CENTER);

DefaultTableCellRenderer rowHeaderRenderer =
new DefaultTableCellRenderer(); // cell renderer for contrasting headings
headerRenderer.setBackground(bg);
headerRenderer.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);

propertyTable.setGridColor(gridColour);
propertyTable.setIntercellSpacing(new Dimension(2, 2));
propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
propertyTable.setShowHorizontalLines(true);
propertyTable.getTableHeader().setResizingAllowed(true);
propertyTable.setFillsViewportHeight(true);

for (int i = 0; i < propertyTable.getColumnCount(); i++) {

switch (i) { // set column shading
case 0, 2, 4, 6 -> propertyTable
.getColumnModel()
.getColumn(i)
.setHeaderRenderer(headerRenderer);
case 1, 3 -> {
propertyTable.getColumnModel().getColumn(i).setCellRenderer(cellRenderer);
propertyTable.getColumnModel().getColumn(i).setHeaderRenderer(headerRenderer2);
}
}

switch (i) { // set column sizes
case 0, 2, 3 -> {
propertyTable.getColumnModel().getColumn(i).setMinWidth(60);
propertyTable.getColumnModel().getColumn(i).setPreferredWidth(80);
}
case 1 -> {
propertyTable.getColumnModel().getColumn(i).setMinWidth(45);
propertyTable.getColumnModel().getColumn(i).setMaxWidth(100);
propertyTable.getColumnModel().getColumn(i).setPreferredWidth(55);
}
case 4, 5, 6 -> {
propertyTable.getColumnModel().getColumn(i).setMinWidth(50);
propertyTable.getColumnModel().getColumn(i).setMaxWidth(80);
propertyTable.getColumnModel().getColumn(i).setPreferredWidth(50);
}
}
}
Font hFont = propertyTable.getTableHeader().getComponent(0).getFont();
Dimension headerDim = propertyTable.getTableHeader().getSize();
headerDim.height = (int) (hFont.getSize() * 3.41);
propertyTable.getTableHeader().setPreferredSize(headerDim);
}

private class TypeListModel extends AbstractListModel {
public Object getElementAt(int index) {
List<String> names = new ArrayList<String>(tokenTypeMap.keySet());
Expand Down
Loading

0 comments on commit eb34a2a

Please sign in to comment.