20 package net.sf.gridarta.gui.dialog.gameobjectattributes;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Container;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.event.FocusListener;
30 import java.text.DecimalFormat;
31 import java.text.NumberFormat;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.regex.Pattern;
36 import javax.swing.BorderFactory;
37 import javax.swing.Box;
38 import javax.swing.DefaultComboBoxModel;
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JComponent;
44 import javax.swing.JFormattedTextField;
45 import javax.swing.JLabel;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTabbedPane;
49 import javax.swing.JTextArea;
50 import javax.swing.JTextField;
51 import javax.swing.filechooser.FileFilter;
52 import javax.swing.text.DefaultFormatterFactory;
53 import javax.swing.text.NumberFormatter;
105 import org.jetbrains.annotations.NotNull;
106 import org.jetbrains.annotations.Nullable;
125 private static final Color
INT_COLOR =
new Color(74, 70, 156);
255 private final Collection<DialogAttribute<G, A, R, ?>>
dialogAttributes =
new ArrayList<>();
276 private void adjustTooltip(@Nullable
final JComponent component, @NotNull
final ArchetypeAttribute attribute) {
277 @NotNull
final String desc = attribute.getDescription();
278 if (component !=
null && !desc.isEmpty()) {
279 final StringBuilder sb =
new StringBuilder(
"<html>");
283 component.setToolTipText(sb.toString());
289 final String attributeName = archetypeAttribute.getArchetypeAttributeName();
292 adjustTooltip(input, archetypeAttribute);
293 final JLabel cLabel =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
294 adjustTooltip(cLabel, archetypeAttribute);
300 final JTextArea input =
new JTextArea();
303 if (bitmask ==
null) {
304 final JLabel row =
new JLabel(
"Error: Undefined Bitmask");
308 final JButton label =
new JButton(
new MaskChangeAL<>(archetypeAttribute.getAttributeName() +
":", tmpAttribute));
309 adjustTooltip(label, archetypeAttribute);
310 input.setBackground(
parent.getBackground());
311 input.setEditable(
false);
312 input.setBorder(BorderFactory.createLineBorder(Color.gray));
314 adjustTooltip(input, archetypeAttribute);
322 final JCheckBox input =
new JCheckBox(archetypeAttribute.getAttributeName(),
attributes.
getAttributeInt(archetypeAttribute.getArchetypeAttributeName()) == 1);
323 adjustTooltip(input, archetypeAttribute);
330 final boolean defaultValue;
331 if (archetypeAttribute.getTrueValue().equals(
"0")) {
332 defaultValue = attributeString.isEmpty() || attributeString.equals(
"0");
334 defaultValue = attributeString.equals(archetypeAttribute.getTrueValue());
336 final JCheckBox input =
new JCheckBox(archetypeAttribute.getAttributeName(), defaultValue);
337 adjustTooltip(input, archetypeAttribute);
343 final String attributeName = archetypeAttribute.getArchetypeAttributeName();
346 adjustTooltip(input, archetypeAttribute);
347 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
":");
348 adjustTooltip(label, archetypeAttribute);
354 throw new AssertionError();
359 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
360 adjustTooltip(label, archetypeAttribute);
363 final DecimalFormat format =
new DecimalFormat(
"#0.0#");
364 format.setMaximumFractionDigits(10);
365 format.setGroupingUsed(
false);
366 final NumberFormatter formatter =
new NumberFormatter(format);
367 formatter.setValueClass(Double.class);
368 final DefaultFormatterFactory factory =
new DefaultFormatterFactory(formatter);
370 final JFormattedTextField input =
new JFormattedTextField(factory, value);
371 input.setColumns(fieldLength);
372 adjustTooltip(input, archetypeAttribute);
378 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
379 adjustTooltip(label, archetypeAttribute);
382 final NumberFormat format = NumberFormat.getIntegerInstance();
383 format.setGroupingUsed(
false);
384 final NumberFormatter formatter =
new NumberFormatter(format);
385 final DefaultFormatterFactory factory =
new DefaultFormatterFactory(formatter);
387 final JFormattedTextField input =
new JFormattedTextField(factory, value);
388 input.setColumns(fieldLength);
389 adjustTooltip(input, archetypeAttribute);
395 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
396 adjustTooltip(label, archetypeAttribute);
399 adjustTooltip(input, archetypeAttribute);
405 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
406 adjustTooltip(label, archetypeAttribute);
408 final JComponent component;
409 final JComboBox<?> input;
413 input =
new JComboBox<>();
414 component =
new JLabel(
"Error: Undefined List");
419 adjustTooltip(input, archetypeAttribute);
425 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
426 adjustTooltip(label, archetypeAttribute);
430 final JComponent component1;
431 @Nullable
final JComboBox<?> input1;
435 input1 =
new JComboBox<>();
436 component1 =
new JLabel(
"Error: Undefined List");
438 input1 =
buildArrayBox(list1, value & 0x0F, archetypeAttribute.getAttributeName());
442 final JComponent component2;
443 @Nullable
final JComboBox<?> input2;
447 input2 =
new JComboBox<>();
448 component2 =
new JLabel(
"Error: Undefined List");
450 input2 =
buildArrayBox(list2, value >> 4, archetypeAttribute.getAttributeName());
454 adjustTooltip(input1, archetypeAttribute);
455 adjustTooltip(input2, archetypeAttribute);
456 final JComponent component =
new JPanel(
new GridBagLayout());
457 final GridBagConstraints gbc =
new GridBagConstraints();
459 gbc.fill = GridBagConstraints.HORIZONTAL;
460 component.add(component1, gbc);
461 component.add(component2, gbc);
462 adjustTooltip(component, archetypeAttribute);
468 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
469 adjustTooltip(label, archetypeAttribute);
472 final NumberFormat format = NumberFormat.getIntegerInstance();
473 format.setGroupingUsed(
false);
474 final NumberFormatter formatter =
new NumberFormatter(format);
475 final DefaultFormatterFactory factory =
new DefaultFormatterFactory(formatter);
477 final JFormattedTextField input =
new JFormattedTextField(factory, value);
478 input.setColumns(fieldLength);
479 adjustTooltip(input, archetypeAttribute);
488 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
489 adjustTooltip(label, archetypeAttribute);
491 adjustTooltip(tilePanel, archetypeAttribute);
497 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
498 adjustTooltip(label, archetypeAttribute);
501 adjustTooltip(tilePanel, archetypeAttribute);
507 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
508 adjustTooltip(label, archetypeAttribute);
511 adjustTooltip(input, archetypeAttribute);
519 adjustTooltip(input, archetypeAttribute);
520 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
521 adjustTooltip(label, archetypeAttribute);
528 if (archetypeAttribute.getArchetypeAttributeName().equals(
"msg") &&
attributes instanceof
GameObject) {
536 input.
setText(text ==
null ?
"" : text);
538 input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0));
539 adjustTooltip(input, archetypeAttribute);
546 if (treasureName.trim().isEmpty() || treasureName.trim().equalsIgnoreCase(
"none")) {
550 adjustTooltip(input, archetypeAttribute);
551 input.setEditable(
false);
554 adjustTooltip(label, archetypeAttribute);
560 final JLabel label =
new JLabel(archetypeAttribute.getAttributeName() +
": ");
561 adjustTooltip(label, archetypeAttribute);
564 adjustTooltip(input, archetypeAttribute);
592 public AttributesPaneBuilder(@NotNull
final Attributes attributes, @NotNull
final Component
parent, @NotNull
final ArchetypeTypeSet archetypeTypeSet, @NotNull
final CFTreasureListTree treasureListTree, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final AnimationObjects animationObjects, @NotNull
final ProjectSettings projectSettings, @NotNull
final FileFilter
mapFileFilter, @NotNull
final FileFilter
scriptFileFilter, @NotNull
final FaceObjects faceObjects, @NotNull
final Spells<
GameObjectSpell<G, A, R>>
gameObjectSpells, @NotNull
final Spells<NumberSpell> numberSpells,
final int undefinedSpellIndex, @NotNull
final TreasureTree treasureTree, @NotNull
final ImageIcon
noFaceSquareIcon, @NotNull
final ImageIcon
unknownSquareIcon, @NotNull
final TextAreaDefaults textAreaDefaults) {
643 final String sectionName = archetypeAttributeSection.getSectionName();
645 if (sectionName.length() <= 1) {
648 title = sectionName.substring(0, 1).toUpperCase() + sectionName.substring(1);
655 tabbedPane.setSelectedIndex(sectionId > 0 ? 0 : -1);
667 private Component
makeAttributePanel(@NotNull
final Iterable<ArchetypeAttribute> archetypeAttributeSection) {
668 int matchingAttributes = 0;
669 boolean hasBitmask =
false;
675 matchingAttributes++;
682 if (matchingAttributes == 0) {
687 final JPanel panel =
new JPanel(
new GridBagLayout());
688 final Insets gbcInsets =
new Insets(2, 2, 2, 2);
690 final GridBagConstraints gbc =
new GridBagConstraints();
691 gbc.insets = gbcInsets;
692 gbc.fill = GridBagConstraints.HORIZONTAL;
693 final Object labelGbc = gbc.clone();
695 gbc.gridwidth = GridBagConstraints.REMAINDER;
696 final Object compGbc = gbc.clone();
697 gbc.anchor = GridBagConstraints.WEST;
698 final Object rowGbc = gbc.clone();
699 gbc.fill = GridBagConstraints.BOTH;
702 final Object glueGbc = gbc.clone();
704 boolean hasGlue =
false;
711 assert tmpGuiInfo !=
null;
718 hasGlue |= tmpGuiInfo.
getGlue() !=
null;
724 panel.add(Box.createGlue(), glueGbc);
726 final JScrollPane panelReturn =
new JScrollPane(panel);
727 panelReturn.getVerticalScrollBar().setUnitIncrement(8);
737 private void addElement(@NotNull
final Container container, @Nullable
final Component component, @NotNull
final Object constraints) {
738 if (component !=
null) {
739 container.add(component, constraints);
753 private static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> JComboBox<?>
buildInvSpellBox(@NotNull
final Spells<
GameObjectSpell<G, A, R>>
gameObjectSpells, @NotNull
final Attributes attributes,
final boolean isOptionalSpell, @NotNull
final String attributeName) {
755 throw new IllegalArgumentException(
"attributes class must extend BaseObject: " +
attributes.getClass().getName());
758 final int selectedIndex;
759 @Nullable
final String title;
763 title = isOptionalSpell ? null :
"<none>";
768 title =
"<multiple>";
773 final String invObjectArchetypeName = invObject.getArchetype().getArchetypeName();
775 @Nullable String tmpTitle =
"<customized spell>";
777 if (invObjectArchetypeName.equals(spellObject.getArchetypeName())) {
778 tmpTitle = invObject.
isDefaultGameObject() ? null : spellObject.getName() +
" <customized>";
783 selectedIndex = tmpTitle ==
null ? index :
gameObjectSpells.size() + (isOptionalSpell ? 1 : 0);
788 final DefaultComboBoxModel<String> model =
new DefaultComboBoxModel<>();
790 model.addElement(spell.getName());
792 if (isOptionalSpell) {
793 model.addElement(
"<none>");
796 model.addElement(title);
798 final JComboBox<?> comboBox =
new JComboBox<>(model);
799 comboBox.setSelectedIndex(selectedIndex);
800 comboBox.setMaximumRowCount(10);
802 comboBox.setName(attributeName);
815 final String[] array =
new String[listData.size()];
816 boolean hasSelection =
false;
817 int selectedIndex = 0;
818 for (
int i = 0; i < array.length; i++) {
819 array[i] = listData.get(i).getSecond();
820 if (!hasSelection && listData.get(i).getFirst() == value) {
825 final JComboBox<?> comboBox =
new JComboBox<>(array);
826 comboBox.setSelectedIndex(selectedIndex);
827 comboBox.setMaximumRowCount(10);
829 comboBox.setName(attributeName);
846 if (spellNumber < 0 || spellNumber >=
numberSpells.size()) {
850 final int selectedIndex;
857 final DefaultComboBoxModel<String> model =
new DefaultComboBoxModel<>();
858 model.addElement(
"<none>");
860 model.addElement(spell.getName());
862 final JComboBox<?> comboBox =
new JComboBox<>(model);
863 comboBox.setSelectedIndex(selectedIndex);
864 comboBox.setMaximumRowCount(10);
866 comboBox.setName(archetypeAttribute.getAttributeName());