use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.
the class ControlPanelBase method update.
/**
* Validates UI input and updates config objects
*/
public void update() {
LoadConfigReport report = validateInput();
if (report.isErrorFree()) {
try {
fillConfigFromInput();
chat.repaint();
} catch (Exception ex) {
ChatWindow.popup.handleProblem("Unexpected Error: " + ex.toString(), ex);
}
} else {
ChatWindow.popup.handleProblem(report);
}
}
use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.
the class ControlPanelMessage method build.
@Override
protected void build() {
usernamesBox = new JCheckBox("Show Usernames");
joinMessagesBox = new JCheckBox("Show Joins");
timestampsBox = new JCheckBox("Show Timestamps");
timeFormatInput = new LabeledInput(null, 9);
timeFormatUpdateButton = new JButton("Update Time Format");
queueSizeSlider = new LabeledSlider("Message Queue Size", "messages", ConfigMessage.MIN_QUEUE_SIZE, ConfigMessage.MAX_QUEUE_SIZE);
final String maxSpeedLabel = "MAX";
messageSpeedSlider = new LabeledSlider("Message Speed", "char/sec", ConfigMessage.MIN_MESSAGE_SPEED, ConfigMessage.MAX_MESSAGE_SPEED, maxSpeedLabel.length()) {
private static final long serialVersionUID = 1L;
@Override
public String getValueString() {
if (getValue() == slider.getMaximum()) {
return maxSpeedLabel;
} else {
return super.getValueString();
}
}
};
final String minExpirationLabel = "NEVER";
expirationTimeSlider = new LabeledSlider("Hide Messages After ", "sec", ConfigMessage.MIN_MESSAGE_EXPIRATION, ConfigMessage.MAX_MESSAGE_EXPIRATION, minExpirationLabel.length()) {
private static final long serialVersionUID = 1L;
@Override
protected String getUnitLabelStr() {
if (getValue() == slider.getMinimum()) {
return padValue("", super.getUnitLabelStr().length());
} else {
return super.getUnitLabelStr();
}
}
@Override
public String getValueString() {
if (getValue() == slider.getMinimum()) {
return minExpirationLabel;
} else {
return super.getValueString();
}
}
};
JLabel hideLabel = new JLabel("When No Messages Are Displayed: ");
hideEmptyBorder = new JCheckBox("Hide Border");
hideEmptyBackground = new JCheckBox("Hide Background");
caseTypeDropdown = new JComboBox<UsernameCaseResolutionType>(UsernameCaseResolutionType.values());
specifyCaseBox = new JCheckBox("Permit users to specify their own username case in posts");
messageCasingDropdown = new JComboBox<MessageCasing>(MessageCasing.values());
DocumentListener docListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
toggleEnableds();
}
@Override
public void removeUpdate(DocumentEvent e) {
toggleEnableds();
}
@Override
public void changedUpdate(DocumentEvent e) {
toggleEnableds();
}
};
timeFormatInput.addDocumentListener(docListener);
caseTypeDropdown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
UsernameCaseResolutionType type = (UsernameCaseResolutionType) caseTypeDropdown.getSelectedItem();
boolean changed = config.getCaseResolutionType() != type;
config.setCaseResolutionType(type);
if (changed) {
chatWindow.clearUsernameCases();
}
}
});
messageCasingDropdown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
config.setMessageCasing((MessageCasing) messageCasingDropdown.getSelectedItem());
chat.repaint();
}
});
ActionListener boxListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JCheckBox source = (JCheckBox) e.getSource();
if (usernamesBox.equals(source)) {
config.setShowUsernames(source.isSelected());
} else if (joinMessagesBox.equals(source)) {
config.setJoinMessages(source.isSelected());
} else if (timestampsBox.equals(source)) {
config.setShowTimestamps(source.isSelected());
toggleEnableds();
} else if (specifyCaseBox.equals(source)) {
config.setSpecifyCaseAllowed(specifyCaseBox.isSelected());
chatWindow.clearUsernameCases();
} else if (hideEmptyBorder.equals(source)) {
config.setHideEmptyBorder(hideEmptyBorder.isSelected());
} else if (hideEmptyBackground.equals(source)) {
config.setHideEmptyBackground(hideEmptyBackground.isSelected());
}
chat.repaint();
}
};
usernamesBox.addActionListener(boxListener);
joinMessagesBox.addActionListener(boxListener);
timestampsBox.addActionListener(boxListener);
specifyCaseBox.addActionListener(boxListener);
hideEmptyBorder.addActionListener(boxListener);
hideEmptyBackground.addActionListener(boxListener);
timeFormatUpdateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LoadConfigReport report = new LoadConfigReport();
config.validateTimeFormat(report, timeFormatInput.getText());
if (report.isErrorFree()) {
config.setTimeFormat(timeFormatInput.getText());
toggleEnableds();
chat.repaint();
} else {
ChatWindow.popup.handleProblem(report);
}
}
});
ChangeListener cl = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
if (queueSizeSlider.getSlider().equals(source)) {
config.setQueueSize(queueSizeSlider.getValue());
} else if (messageSpeedSlider.getSlider().equals(source)) {
config.setMessageSpeed(messageSpeedSlider.getValue(), chat.getMessageProgressor());
} else if (expirationTimeSlider.getSlider().equals(source)) {
config.setExpirationTime(expirationTimeSlider.getValue(), chat.getMessageExpirer());
chat.repaint();
}
}
}
};
messageSpeedSlider.addChangeListener(cl);
expirationTimeSlider.addChangeListener(cl);
queueSizeSlider.addChangeListener(cl);
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.NORTH;
gbc.fill = GridBagConstraints.NONE;
JPanel topOptions = new JPanel(new GridBagLayout());
topOptions.setBorder(new TitledBorder(baseBorder, "Message Format Options", TitledBorder.CENTER, TitledBorder.TOP));
JPanel optionsA = new JPanel(new GridBagLayout());
JPanel optionsB = new JPanel(new GridBagLayout());
GridBagConstraints tfGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
JPanel timeFormatPanel = new JPanel(new GridBagLayout());
timeFormatPanel.add(timeFormatInput, tfGbc);
tfGbc.gridx++;
timeFormatPanel.add(timeFormatUpdateButton, tfGbc);
GridBagConstraints aGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
optionsA.add(usernamesBox, aGbc);
aGbc.gridx++;
aGbc.anchor = GridBagConstraints.NORTH;
optionsA.add(timestampsBox, aGbc);
aGbc.gridy++;
aGbc.gridx = 0;
aGbc.anchor = GridBagConstraints.WEST;
optionsA.add(joinMessagesBox, aGbc);
aGbc.gridx++;
aGbc.anchor = GridBagConstraints.EAST;
optionsA.add(timeFormatPanel, aGbc);
GridBagConstraints bGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, DEFAULT_INSETS, 0, 0);
bGbc.gridwidth = 3;
optionsB.add(queueSizeSlider, bGbc);
bGbc.gridy++;
optionsB.add(messageSpeedSlider, bGbc);
bGbc.gridy++;
bGbc.fill = GridBagConstraints.HORIZONTAL;
optionsB.add(expirationTimeSlider, bGbc);
bGbc.gridy++;
bGbc.fill = GridBagConstraints.NONE;
bGbc.weightx = 0.333;
bGbc.gridwidth = 1;
bGbc.anchor = GridBagConstraints.EAST;
optionsB.add(hideLabel, bGbc);
bGbc.gridx++;
bGbc.anchor = GridBagConstraints.CENTER;
optionsB.add(hideEmptyBorder, bGbc);
bGbc.gridx++;
bGbc.anchor = GridBagConstraints.WEST;
optionsB.add(hideEmptyBackground, bGbc);
bGbc.gridx = 0;
bGbc.gridwidth = 3;
bGbc.gridy++;
bGbc.anchor = GridBagConstraints.CENTER;
bGbc.weightx = 1.0;
GridBagConstraints topOpGbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, DEFAULT_INSETS, 0, 0);
topOpGbc.anchor = GridBagConstraints.SOUTH;
topOptions.add(optionsA, topOpGbc);
topOpGbc.gridy++;
topOpGbc.anchor = GridBagConstraints.NORTH;
topOptions.add(optionsB, topOpGbc);
topOpGbc.gridy++;
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
add(topOptions, gbc);
gbc.gridy++;
JPanel usernameOptions = new JPanel(new GridLayout(3, 1));
usernameOptions.setBorder(new TitledBorder(baseBorder, "Username Options", TitledBorder.CENTER, TitledBorder.TOP));
usernameOptions.add(new JLabel("Default Method for Handling Username Casing"));
usernameOptions.add(caseTypeDropdown);
usernameOptions.add(specifyCaseBox);
JPanel casingOptions = new JPanel();
casingOptions.setBorder(new TitledBorder(baseBorder, "Message Casing Options", TitledBorder.CENTER, TitledBorder.TOP));
casingOptions.add(new JLabel("Force uppercase or lowercase: "));
casingOptions.add(messageCasingDropdown);
add(usernameOptions, gbc);
gbc.gridy++;
add(casingOptions, gbc);
gbc.gridy++;
// Filler panel
gbc.gridy++;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(new JPanel(), gbc);
gbc.gridy++;
}
use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.
the class ControlWindow method open.
private void open() {
boolean okayToProceed = fProps.checkForUnsavedProps(this, this);
if (okayToProceed) {
int result = opener.showOpenDialog(me);
if (result == JFileChooser.APPROVE_OPTION) {
try {
LoadConfigReport report = fProps.loadFile(opener.getSelectedFile());
if (report.isProblem()) {
throw new Exception("Configuration file open error");
}
controlTabs.refreshUiFromConfig(fProps);
chatWindow.getChatPanel().repaint();
} catch (Exception ex) {
final String errorMsg = "Unable to open file " + (opener.getSelectedFile() == null ? "null" : opener.getSelectedFile().getName());
logger.error(errorMsg, ex);
ChatWindow.popup.handleProblem(errorMsg);
}
}
}
}
use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.
the class FontificatorProperties method loadFile.
/**
* Load configuration from the specified file
*
* @param file
* @return report
* @throws Exception
*/
public LoadConfigReport loadFile(File file) throws Exception {
logger.trace("Loading file " + file.getAbsolutePath());
InputStream is = new FileInputStream(file);
LoadConfigReport report = loadFile(is, file.getAbsolutePath(), false);
is.close();
return report;
}
use of com.glitchcog.fontificator.config.loadreport.LoadConfigReport in project ChatGameFontificator by GlitchCog.
the class FontificatorProperties method loadFile.
/**
* Load configuration from the file indicated by the specified filename, or a preset file contained in the classpath
* resource directory
*
* @param filename
* @return report
* @throws Exception
*/
public LoadConfigReport loadFile(String filename) throws Exception {
if (filename.startsWith(ConfigFont.INTERNAL_FILE_PREFIX)) {
final String plainFilename = filename.substring(ConfigFont.INTERNAL_FILE_PREFIX.length());
if (getClass().getClassLoader().getResource(plainFilename) == null) {
LoadConfigReport report = new LoadConfigReport();
final String errorMsg = "Preset theme " + plainFilename + " not found";
ChatWindow.popup.handleProblem(errorMsg);
report.addError(errorMsg, LoadConfigErrorType.FILE_NOT_FOUND);
return report;
}
InputStream is = getClass().getClassLoader().getResourceAsStream(plainFilename);
LoadConfigReport report = loadFile(is, filename, true);
if (report.isErrorFree()) {
// This is a temporary copy, not to be saved to the last saved file for loading next time, but to avoid
// having to not save when switching between presets
this.lastSavedCopy = getCopy();
}
is.close();
return report;
} else {
return loadFile(new File(filename));
}
}
Aggregations