use of games.strategy.engine.data.properties.PropertiesUi in project triplea by triplea-game.
the class ChangeGameOptionsClientAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
final byte[] oldBytes = serverRemote.getGameOptions();
if (oldBytes == null || oldBytes.length == 0) {
return;
}
try {
final List<IEditableProperty> properties = GameProperties.readEditableProperties(oldBytes);
final PropertiesUi pui = new PropertiesUi(properties, true);
final JScrollPane scroll = new JScrollPane(pui);
scroll.setBorder(null);
scroll.getViewport().setBorder(null);
final JOptionPane pane = new JOptionPane(scroll, JOptionPane.PLAIN_MESSAGE);
final String ok = "OK";
final String cancel = "Cancel";
pane.setOptions(new Object[] { ok, cancel });
final JDialog window = pane.createDialog(JOptionPane.getFrameForComponent(parent), "Map Options");
window.setVisible(true);
final Object buttonPressed = pane.getValue();
if (buttonPressed != null && !buttonPressed.equals(cancel)) {
// but it doesn't change the hosts, so we need to send it back to the host.
try {
serverRemote.changeToGameOptions(GameProperties.writeEditableProperties(properties));
} catch (final IOException ex) {
ClientLogger.logQuietly("Failed to write game properties", ex);
}
}
} catch (final IOException | ClassCastException ex) {
ClientLogger.logQuietly("Failed to read game properties", ex);
}
}
use of games.strategy.engine.data.properties.PropertiesUi in project triplea by triplea-game.
the class GameSelectorPanel method selectGameOptions.
private void selectGameOptions() {
// backup current game properties before showing dialog
final Map<String, Object> currentPropertiesMap = new HashMap<>();
for (final IEditableProperty property : model.getGameData().getProperties().getEditableProperties()) {
currentPropertiesMap.put(property.getName(), property.getValue());
}
final PropertiesUi panel = new PropertiesUi(model.getGameData().getProperties(), true);
final JScrollPane scroll = new JScrollPane(panel);
scroll.setBorder(null);
scroll.getViewport().setBorder(null);
final JOptionPane pane = new JOptionPane(scroll, JOptionPane.PLAIN_MESSAGE);
final String ok = "OK";
final String cancel = "Cancel";
final String makeDefault = "Make Default";
final String reset = "Reset";
pane.setOptions(new Object[] { ok, makeDefault, reset, cancel });
final JDialog window = pane.createDialog(JOptionPane.getFrameForComponent(this), "Map Options");
window.setVisible(true);
final Object buttonPressed = pane.getValue();
if (buttonPressed == null || buttonPressed.equals(cancel)) {
// restore properties, if cancel was pressed, or window was closed
for (final IEditableProperty property : model.getGameData().getProperties().getEditableProperties()) {
property.setValue(currentPropertiesMap.get(property.getName()));
}
} else if (buttonPressed.equals(reset)) {
if (!originalPropertiesMap.isEmpty()) {
// restore properties, if cancel was pressed, or window was closed
for (final IEditableProperty property : model.getGameData().getProperties().getEditableProperties()) {
property.setValue(originalPropertiesMap.get(property.getName()));
}
selectGameOptions();
}
} else if (buttonPressed.equals(makeDefault)) {
gamePropertiesCache.cacheGameProperties(model.getGameData());
} else {
// ok was clicked, and we have modified the properties already
}
}
use of games.strategy.engine.data.properties.PropertiesUi in project triplea by triplea-game.
the class MapPropertyWrapper method createPropertiesUi.
static Tuple<PropertiesUi, List<MapPropertyWrapper<?>>> createPropertiesUi(final Object object, final boolean editable) {
final List<MapPropertyWrapper<?>> properties = createProperties(object);
final PropertiesUi ui = new PropertiesUi(properties, editable);
return Tuple.of(ui, properties);
}
use of games.strategy.engine.data.properties.PropertiesUi in project triplea by triplea-game.
the class GameMenu method addGameOptionsMenu.
private void addGameOptionsMenu() {
if (!gameData.getProperties().getEditableProperties().isEmpty()) {
add(SwingAction.of("Map Options", e -> {
final PropertiesUi ui = new PropertiesUi(gameData.getProperties().getEditableProperties(), false);
JOptionPane.showMessageDialog(frame, ui, "Map Options", JOptionPane.PLAIN_MESSAGE);
})).setMnemonic(KeyEvent.VK_O);
}
}
use of games.strategy.engine.data.properties.PropertiesUi in project triplea by triplea-game.
the class ViewMenu method addMapFontAndColorEditorMenu.
private void addMapFontAndColorEditorMenu() {
final Action mapFontOptions = SwingAction.of("Edit Map Font and Color", e -> {
final List<IEditableProperty> properties = new ArrayList<>();
final NumberProperty fontsize = new NumberProperty("Font Size", null, 60, 0, MapImage.getPropertyMapFont().getSize());
final ColorProperty territoryNameColor = new ColorProperty("Territory Name and PU Color", null, MapImage.getPropertyTerritoryNameAndPuAndCommentColor());
final ColorProperty unitCountColor = new ColorProperty("Unit Count Color", null, MapImage.getPropertyUnitCountColor());
final ColorProperty factoryDamageColor = new ColorProperty("Factory Damage Color", null, MapImage.getPropertyUnitFactoryDamageColor());
final ColorProperty hitDamageColor = new ColorProperty("Hit Damage Color", null, MapImage.getPropertyUnitHitDamageColor());
properties.add(fontsize);
properties.add(territoryNameColor);
properties.add(unitCountColor);
properties.add(factoryDamageColor);
properties.add(hitDamageColor);
final PropertiesUi pui = new PropertiesUi(properties, true);
final JPanel ui = new JPanel();
ui.setLayout(new BorderLayout());
ui.add(pui, BorderLayout.CENTER);
ui.add(new JLabel("<html>Change the font and color of 'text' (not pictures) on the map. " + "<br /><em>(Some people encounter problems with the color picker, and this " + "<br />is a bug outside of triplea, located in the 'look and feel' that " + "<br />you are using. If you have an error come up, try switching to the " + "<br />basic 'look and feel', then setting the color, then switching back.)</em></html>"), BorderLayout.NORTH);
final Object[] options = { "Set Properties", "Reset To Default", "Cancel" };
final int result = JOptionPane.showOptionDialog(frame, ui, "Edit Map Font and Color", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, 2);
if (result == 1) {
MapImage.resetPropertyMapFont();
MapImage.resetPropertyTerritoryNameAndPuAndCommentColor();
MapImage.resetPropertyUnitCountColor();
MapImage.resetPropertyUnitFactoryDamageColor();
MapImage.resetPropertyUnitHitDamageColor();
frame.getMapPanel().resetMap();
} else if (result == 0) {
MapImage.setPropertyMapFont(new Font("Ariel", Font.BOLD, fontsize.getValue()));
MapImage.setPropertyTerritoryNameAndPuAndCommentColor((Color) territoryNameColor.getValue());
MapImage.setPropertyUnitCountColor((Color) unitCountColor.getValue());
MapImage.setPropertyUnitFactoryDamageColor((Color) factoryDamageColor.getValue());
MapImage.setPropertyUnitHitDamageColor((Color) hitDamageColor.getValue());
frame.getMapPanel().resetMap();
}
});
add(mapFontOptions).setMnemonic(KeyEvent.VK_C);
}
Aggregations