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

Property sheet trait improvement #13691

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 18 additions & 6 deletions vassal-app/src/main/java/VASSAL/counters/PropertySheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,13 @@ private static class Ed implements PieceEditor {
private final JButton colorCtrl;
private final JTable propertyTable;
private final JComboBox commitCtrl;
private final String previousState;

static final String[] COLUMN_NAMES = {Resources.getString("Editor.PropertySheet.name"), Resources.getString("Editor.PropertySheet.type")};
static final String[] COLUMN_NAMES = {Resources.getString("Editor.PropertySheet.name"), Resources.getString("Editor.PropertySheet.type"), Resources.getString("Editor.PropertySheet.state")};
static final String[] DEFAULT_ROW = {Resources.getString("Editor.PropertySheet.new_property"), Resources.getString("Editor.PropertySheet.text")};

public Ed(PropertySheet propertySheet) {
previousState = propertySheet.state;
m_panel = new PropertyPanel();
descCtrl = m_panel.addStringCtrl(Resources.getString("Editor.description_label"), propertySheet.description, "Editor.description_hint");
menuNameCtrl = m_panel.addStringCtrl(Resources.getString("Editor.menu_command"), propertySheet.menuName, "Editor.menu_command_hint");
Expand All @@ -952,18 +954,21 @@ protected void AddCreateRow(DefaultTableModel data) {

protected String[][] getTableData(String definition) {
final SequenceEncoder.Decoder decoder = new SequenceEncoder.Decoder(definition, DEF_DELIMITOR);
final SequenceEncoder.Decoder stateDecoder = new SequenceEncoder.Decoder(previousState, STATE_DELIMITOR);

int numRows = !definition.equals("") && decoder.hasMoreTokens() ? 1 : 0;
for (int iDef = -1; (iDef = definition.indexOf(DEF_DELIMITOR, iDef + 1)) >= 0;) {
++numRows;
}

final String[][] rows = new String[numRows][2];
final String[][] rows = new String[numRows][3];

for (int iRow = 0; decoder.hasMoreTokens() && iRow < numRows; ++iRow) {
final String token = decoder.nextToken();
final String stateToken = stateDecoder.nextToken();
rows[iRow][0] = token.substring(1);
rows[iRow][1] = TYPE_VALUES[token.charAt(0) - '0'];
rows[iRow][2] = stateToken;
}

return rows;
Expand Down Expand Up @@ -1030,13 +1035,20 @@ public String getType() {
return ID + typeEncoder.getValue();
}

/** returns a default value-string for the given definition */
/** Returns the current state */
@Override
public String getState() {
final StringBuilder buf = new StringBuilder();
buf.append(
String.valueOf(STATE_DELIMITOR).repeat(Math.max(0, propertyTable.getRowCount())));

for (int i = 0; i < propertyTable.getRowCount(); i++) {
if (i > 0) {
buf.append(STATE_DELIMITOR);
}
final String value = (String) propertyTable.getValueAt(i, 2);
if (value == null || value.isEmpty()) {
continue;
}
buf.append(value);
}
return buf.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ Editor.PropertySheet.delete_row=Delete Row
Editor.PropertySheet.property_sheet_item=Property Sheet item
Editor.PropertySheet.name=Name
Editor.PropertySheet.type=Type
Editor.PropertySheet.State=State
Editor.PropertySheet.new_property=*new property*
Editor.PropertySheet.text=Text
Editor.PropertySheet.commit_on=Commit changes on
Expand Down