Search in sources :

Example 1 with ColorProperty

use of games.strategy.engine.data.properties.ColorProperty in project triplea by triplea-game.

the class GameParser method parseEditableProperty.

private void parseEditableProperty(final Element property, final String name, final String defaultValue) throws GameParseException {
    // what type
    final List<Node> children = getNonTextNodes(property);
    if (children.size() != 1) {
        throw newGameParseException("Editable properties must have exactly 1 child specifying the type. Number of children found:" + children.size() + " for node:" + property.getNodeName());
    }
    final Element child = (Element) children.get(0);
    final String childName = child.getNodeName();
    final IEditableProperty editableProperty;
    if (childName.equals("boolean")) {
        editableProperty = new BooleanProperty(name, null, Boolean.valueOf(defaultValue));
    } else if (childName.equals("file")) {
        editableProperty = new FileProperty(name, null, defaultValue);
    } else if (childName.equals("list") || childName.equals("combo")) {
        final StringTokenizer tokenizer = new StringTokenizer(child.getAttribute("values"), ",");
        final Collection<String> values = new ArrayList<>();
        while (tokenizer.hasMoreElements()) {
            values.add(tokenizer.nextToken());
        }
        editableProperty = new ComboProperty<>(name, null, defaultValue, values);
    } else if (childName.equals("number")) {
        final int max = Integer.valueOf(child.getAttribute("max"));
        final int min = Integer.valueOf(child.getAttribute("min"));
        final int def = Integer.valueOf(defaultValue);
        editableProperty = new NumberProperty(name, null, max, min, def);
    } else if (childName.equals("color")) {
        // Parse the value as a hexidecimal number
        final int def = Integer.valueOf(defaultValue, 16);
        editableProperty = new ColorProperty(name, null, def);
    } else if (childName.equals("string")) {
        editableProperty = new StringProperty(name, null, defaultValue);
    } else {
        throw newGameParseException("Unrecognized property type:" + childName);
    }
    data.getProperties().addEditableProperty(editableProperty);
}
Also used : BooleanProperty(games.strategy.engine.data.properties.BooleanProperty) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) StringProperty(games.strategy.engine.data.properties.StringProperty) IEditableProperty(games.strategy.engine.data.properties.IEditableProperty) StringTokenizer(java.util.StringTokenizer) FileProperty(games.strategy.engine.data.properties.FileProperty) NumberProperty(games.strategy.engine.data.properties.NumberProperty) ColorProperty(games.strategy.engine.data.properties.ColorProperty)

Example 2 with ColorProperty

use of games.strategy.engine.data.properties.ColorProperty 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

ColorProperty (games.strategy.engine.data.properties.ColorProperty)2 IEditableProperty (games.strategy.engine.data.properties.IEditableProperty)2 NumberProperty (games.strategy.engine.data.properties.NumberProperty)2 ArrayList (java.util.ArrayList)2 BooleanProperty (games.strategy.engine.data.properties.BooleanProperty)1 FileProperty (games.strategy.engine.data.properties.FileProperty)1 PropertiesUi (games.strategy.engine.data.properties.PropertiesUi)1 StringProperty (games.strategy.engine.data.properties.StringProperty)1 SwingAction (games.strategy.ui.SwingAction)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Font (java.awt.Font)1 StringTokenizer (java.util.StringTokenizer)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1