Search in sources :

Example 1 with PropertiesUi

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);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) IOException(java.io.IOException) PropertiesUi(games.strategy.engine.data.properties.PropertiesUi) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty)

Example 2 with PropertiesUi

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
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) HashMap(java.util.HashMap) PropertiesUi(games.strategy.engine.data.properties.PropertiesUi) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty)

Example 3 with PropertiesUi

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);
}
Also used : PropertiesUi(games.strategy.engine.data.properties.PropertiesUi)

Example 4 with PropertiesUi

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);
    }
}
Also used : PropertiesUi(games.strategy.engine.data.properties.PropertiesUi)

Example 5 with PropertiesUi

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);
}
Also used : JPanel(javax.swing.JPanel) AbstractAction(javax.swing.AbstractAction) SwingAction(games.strategy.ui.SwingAction) Action(javax.swing.Action) Color(java.awt.Color) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) PropertiesUi(games.strategy.engine.data.properties.PropertiesUi) Font(java.awt.Font) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty) BorderLayout(java.awt.BorderLayout) NumberProperty(games.strategy.engine.data.properties.NumberProperty) ColorProperty(games.strategy.engine.data.properties.ColorProperty)

Aggregations

PropertiesUi (games.strategy.engine.data.properties.PropertiesUi)6 IEditableProperty (games.strategy.engine.data.properties.IEditableProperty)3 JDialog (javax.swing.JDialog)3 JOptionPane (javax.swing.JOptionPane)3 JScrollPane (javax.swing.JScrollPane)3 ColorProperty (games.strategy.engine.data.properties.ColorProperty)1 NumberProperty (games.strategy.engine.data.properties.NumberProperty)1 SwingAction (games.strategy.ui.SwingAction)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Font (java.awt.Font)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1