use of com.glitchcog.fontificator.gui.controls.panel.model.DropdownLabel in project ChatGameFontificator by GlitchCog.
the class ControlPanelFont method build.
@Override
protected void build() {
sliderListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (fontScaleSlider.getSlider().equals(source)) {
config.setFontScale(fontScaleSlider.getScaledValue());
fontScaleSlider.setValueTextColor(((int) config.getFontScale() == config.getFontScale()) ? SCALE_EVEN : SCALE_UNEVEN);
} else if (borderScaleSlider.getSlider().equals(source)) {
config.setBorderScale(borderScaleSlider.getScaledValue());
borderScaleSlider.setValueTextColor(((int) config.getBorderScale() == config.getBorderScale()) ? SCALE_EVEN : SCALE_UNEVEN);
} else if (borderInsetXSlider.getSlider().equals(source)) {
config.setBorderInsetX(borderInsetXSlider.getValue());
} else if (borderInsetYSlider.getSlider().equals(source)) {
config.setBorderInsetY(borderInsetYSlider.getValue());
} else if (spaceWidthSlider.getSlider().equals(source)) {
config.setSpaceWidth(spaceWidthSlider.getValue());
} else if (baselineOffsetSlider.getSlider().equals(source)) {
config.setBaselineOffset(baselineOffsetSlider.getValue());
} else if (lineSpacingSlider.getSlider().equals(source)) {
config.setLineSpacing(lineSpacingSlider.getValue());
} else if (charSpacingSlider.getSlider().equals(source)) {
config.setCharSpacing(charSpacingSlider.getValue());
}
chat.repaint();
}
};
ActionListener fontAl = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
DropdownLabel key = new DropdownLabel(source.getText());
if (CUSTOM_KEY.equals(key)) {
int selectionResult = fontPngPicker.showDialog(ControlWindow.me, "Select Font PNG");
if (selectionResult == JFileChooser.APPROVE_OPTION) {
fontFilenameInput.setText(fontPngPicker.getSelectedFile().getAbsolutePath());
fontPresetDropdown.setSelectedText(fontPngPicker.getSelectedFile().getName());
}
} else {
fontFilenameInput.setText(PRESET_FONT_FILE_MAP.get(key).getFontFilename());
fontTypeCheckbox.setSelected(FontType.VARIABLE_WIDTH.equals(PRESET_FONT_FILE_MAP.get(key).getDefaultType()));
spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
}
updateFontOrBorder(true);
}
};
ActionListener borderAl = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
DropdownLabel key = new DropdownLabel(source.getText());
if (CUSTOM_KEY.equals(key)) {
int selectionResult = borderPngPicker.showDialog(ControlWindow.me, "Select Border PNG");
if (selectionResult == JFileChooser.APPROVE_OPTION) {
borderFilenameInput.setText(borderPngPicker.getSelectedFile().getAbsolutePath());
borderPresetDropdown.setSelectedText(borderPngPicker.getSelectedFile().getName());
}
} else {
DropdownBorder border = PRESET_BORDER_FILE_MAP.get(key);
borderFilenameInput.setText(border.getBorderFilename());
colorPanel.setBorderColor(border.getDefaultTint());
}
updateFontOrBorder(false);
}
};
fontTypeListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
config.setFontType(fontTypeCheckbox.isSelected() ? FontType.VARIABLE_WIDTH : FontType.FIXED_WIDTH);
spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
updateFontOrBorder(true);
}
};
extendedCharBox = new JCheckBox("Display Extended Characters");
extendedCharBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean ecbSelected = extendedCharBox.isSelected();
config.setExtendedCharEnabled(ecbSelected);
unknownCharPopupButton.setEnabled(!ecbSelected);
unknownCharLabel.setEnabled(!ecbSelected);
chat.repaint();
}
});
unknownCharLabel = new JLabel("");
charPicker = new CharacterPicker(ControlWindow.me, fProps.getFontConfig(), unknownCharLabel, chat);
Map<String, List<String>> fontMenuMap = getMenuMapFromPresets(PRESET_FONT_FILE_MAP.keySet());
fontMenuMap.put(CUSTOM_KEY.getLabel(), null);
Map<String, List<String>> borderMenuMap = getMenuMapFromPresets(PRESET_BORDER_FILE_MAP.keySet());
borderMenuMap.put(CUSTOM_KEY.getLabel(), null);
fontTypeCheckbox = new JCheckBox("Variable Width Characters");
fontFilenameInput = new LabeledInput("Font Filename", 32);
fontPresetDropdown = new ComboMenuBar(fontMenuMap, fontAl);
borderFilenameInput = new LabeledInput("Border Filename", 32);
borderPresetDropdown = new ComboMenuBar(borderMenuMap, borderAl);
gridWidthInput = new LabeledInput("Grid Width", 4);
gridHeightInput = new LabeledInput("Grid Height", 4);
fontScaleSlider = new LabeledSlider("Font Scale", "x", ConfigFont.MIN_FONT_SCALE, ConfigFont.MAX_FONT_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
borderScaleSlider = new LabeledSlider("Border Scale", "x", ConfigFont.MIN_BORDER_SCALE, ConfigFont.MAX_BORDER_SCALE, ConfigFont.FONT_BORDER_SCALE_GRANULARITY);
borderInsetXSlider = new LabeledSlider("X", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
borderInsetYSlider = new LabeledSlider("Y", "pixels", ConfigFont.MIN_BORDER_INSET, ConfigFont.MAX_BORDER_INSET);
characterKeyInput = new LabeledInput("Character Key", 32);
spaceWidthSlider = new LabeledSlider("Space Width", "%", ConfigFont.MIN_SPACE_WIDTH, ConfigFont.MAX_SPACE_WIDTH);
baselineOffsetSlider = new LabeledSlider("Baseline Height Offset", "pixels", ConfigFont.MIN_BASELINE_OFFSET, ConfigFont.MAX_BASELINE_OFFSET);
lineSpacingSlider = new LabeledSlider("Line Spacing", "pixels", ConfigFont.MIN_LINE_SPACING, ConfigFont.MAX_LINE_SPACING);
charSpacingSlider = new LabeledSlider("Char Spacing", "pixels", ConfigFont.MIN_CHAR_SPACING, ConfigFont.MAX_LINE_SPACING);
unknownCharPopupButton = new JButton("Select Missing Character");
unknownCharPopupButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
charPicker.setVisible(true);
}
});
fontFilenameInput.setEnabled(false);
borderFilenameInput.setEnabled(false);
fontScaleSlider.addChangeListener(sliderListener);
borderScaleSlider.addChangeListener(sliderListener);
borderInsetXSlider.addChangeListener(sliderListener);
borderInsetYSlider.addChangeListener(sliderListener);
spaceWidthSlider.addChangeListener(sliderListener);
baselineOffsetSlider.addChangeListener(sliderListener);
lineSpacingSlider.addChangeListener(sliderListener);
charSpacingSlider.addChangeListener(sliderListener);
JPanel fontPanel = new JPanel(new GridBagLayout());
JPanel borderPanel = new JPanel(new GridBagLayout());
JPanel unknownPanel = new JPanel(new GridBagLayout());
fontPanel.setBorder(new TitledBorder(baseBorder, "Font"));
borderPanel.setBorder(new TitledBorder(baseBorder, "Border"));
unknownPanel.setBorder(new TitledBorder(baseBorder, "Extended and Unicode Characters"));
GridBagConstraints fontGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
GridBagConstraints borderGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
GridBagConstraints unknownGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
// Fields are still used and stored in properties files when saved, but the values are either fixed or meant to
// be filled by other components
// add(fontFilenameInput);
// add(borderFilenameInput);
// add(gridWidthInput);
// add(gridHeightInput);
// add(characterKeyInput);
fontPanel.add(fontPresetDropdown, fontGbc);
fontGbc.gridx++;
// This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
// height in the layout
fontPanel.add(fontScaleSlider, fontGbc);
fontGbc.gridwidth = 2;
fontGbc.gridx = 0;
fontGbc.gridy++;
fontPanel.add(lineSpacingSlider, fontGbc);
fontGbc.gridy++;
fontPanel.add(charSpacingSlider, fontGbc);
fontGbc.gridy++;
JPanel variableWidthPanel = new JPanel(new GridBagLayout());
GridBagConstraints vwpGbc = getGbc();
vwpGbc.anchor = GridBagConstraints.EAST;
vwpGbc.weightx = 0.0;
vwpGbc.fill = GridBagConstraints.NONE;
variableWidthPanel.add(fontTypeCheckbox, vwpGbc);
vwpGbc.anchor = GridBagConstraints.WEST;
vwpGbc.weightx = 1.0;
vwpGbc.fill = GridBagConstraints.HORIZONTAL;
vwpGbc.gridx++;
variableWidthPanel.add(spaceWidthSlider, vwpGbc);
fontPanel.add(variableWidthPanel, fontGbc);
fontGbc.gridy++;
fontPanel.add(baselineOffsetSlider, fontGbc);
fontGbc.gridy++;
borderPanel.add(borderPresetDropdown, borderGbc);
borderGbc.gridx++;
// This slider being on the same row as the preset dropdown keeps the combo menu bar from collapsing to no
// height in the layout
borderPanel.add(borderScaleSlider, borderGbc);
borderGbc.gridwidth = 2;
borderGbc.gridx = 0;
borderGbc.gridy++;
borderGbc.anchor = GridBagConstraints.CENTER;
borderPanel.add(new JLabel("Font Insets Off Border"), borderGbc);
borderGbc.gridy++;
borderPanel.add(borderInsetXSlider, borderGbc);
borderGbc.gridy++;
borderPanel.add(borderInsetYSlider, borderGbc);
borderGbc.gridy++;
unknownPanel.add(extendedCharBox, unknownGbc);
unknownGbc.gridx++;
unknownPanel.add(unknownCharPopupButton, unknownGbc);
unknownGbc.gridx++;
unknownPanel.add(unknownCharLabel, unknownGbc);
unknownGbc.gridx++;
JPanel everything = new JPanel(new GridBagLayout());
GridBagConstraints eGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 10, 10);
everything.add(fontPanel, eGbc);
eGbc.gridy++;
everything.add(borderPanel, eGbc);
eGbc.gridy++;
everything.add(unknownPanel, eGbc);
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.CENTER;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
add(everything, gbc);
// Filler panel
gbc.gridy++;
gbc.weighty = 1.0;
gbc.anchor = GridBagConstraints.SOUTH;
add(new JPanel(), gbc);
}
use of com.glitchcog.fontificator.gui.controls.panel.model.DropdownLabel in project ChatGameFontificator by GlitchCog.
the class ControlPanelFont method getMenuMapFromPresets.
/**
* Turns a list of keys with a single pipe deliminating the parent menu from the menu item into a map that can be a
* parameter to create a ComboMenuBar
*
* @param keys
* @return
*/
private Map<String, List<String>> getMenuMapFromPresets(Collection<DropdownLabel> keys) {
Map<String, List<String>> menuMap = new LinkedHashMap<String, List<String>>();
for (DropdownLabel key : keys) {
final String menu = key.getGroup();
final String item = key.getLabel();
List<String> items = menuMap.get(menu);
if (items == null) {
items = new ArrayList<String>();
menuMap.put(menu, items);
}
items.add(item);
}
return menuMap;
}
use of com.glitchcog.fontificator.gui.controls.panel.model.DropdownLabel in project ChatGameFontificator by GlitchCog.
the class ControlPanelFont method fillInputFromConfig.
@Override
protected void fillInputFromConfig() {
borderFilenameInput.setText(config.getBorderFilename());
fontFilenameInput.setText(config.getFontFilename());
gridWidthInput.setText(Integer.toString(config.getGridWidth()));
gridHeightInput.setText(Integer.toString(config.getGridHeight()));
fontScaleSlider.setScaledValue(config.getFontScale());
borderScaleSlider.setScaledValue(config.getBorderScale());
borderInsetXSlider.setValue(config.getBorderInsetX());
borderInsetYSlider.setValue(config.getBorderInsetY());
characterKeyInput.setText(config.getCharacterKey());
extendedCharBox.setSelected(config.isExtendedCharEnabled());
charPicker.setSelectedChar(config.getUnknownChar());
spaceWidthSlider.setValue(config.getSpaceWidth());
baselineOffsetSlider.setValue(config.getBaselineOffset());
lineSpacingSlider.setValue(config.getLineSpacing());
charSpacingSlider.setValue(config.getCharSpacing());
fontTypeCheckbox.setSelected(FontType.VARIABLE_WIDTH.equals(config.getFontType()));
spaceWidthSlider.setEnabled(fontTypeCheckbox.isSelected());
final boolean ecbSelected = extendedCharBox.isSelected();
unknownCharPopupButton.setEnabled(!ecbSelected);
unknownCharLabel.setEnabled(!ecbSelected);
boolean found;
found = false;
for (Map.Entry<DropdownLabel, DropdownFont> entry : PRESET_FONT_FILE_MAP.entrySet()) {
if (entry.getValue() != null && config.getFontFilename().equals(entry.getValue().getFontFilename())) {
found = true;
fontPresetDropdown.setSelectedText(entry.getKey().getLabel());
}
}
if (!found) {
String filename = new File(fontFilenameInput.getText()).getName();
fontPresetDropdown.setSelectedText(filename);
}
found = false;
for (Map.Entry<DropdownLabel, DropdownBorder> entry : PRESET_BORDER_FILE_MAP.entrySet()) {
if (entry.getValue() != null && config.getBorderFilename().equals(entry.getValue().getBorderFilename())) {
found = true;
borderPresetDropdown.setSelectedText(entry.getKey().getLabel());
}
}
if (!found) {
String filename = new File(borderFilenameInput.getText()).getName();
borderPresetDropdown.setSelectedText(filename);
}
// Although the font was already updated from the listener attached the the fontTypeDropdown, it should be done
// here to make it official. If the font and border aren't updated, they could be out of sync with the input
// filled from config on preset loads, and it shouldn't be the responsibility of actionlisteners attached to UI
// components to update the display
updateFontOrBorder(true);
// Also, the border must be updated here too.
updateFontOrBorder(false);
}
Aggregations