Skip to content

Commit

Permalink
Merge pull request #910 from kkarakas/i_395_update_for_settings_edit_…
Browse files Browse the repository at this point in the history
…scoring_properties

i_395 scoring properties settings now on main page
  • Loading branch information
johnbrvc authored Jan 27, 2024
2 parents be8ca61 + f9a0c94 commit 857d022
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 65 deletions.
88 changes: 23 additions & 65 deletions src/edu/csus/ecs/pc2/ui/ContestInformationPane.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (C) 1989-2019 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics2D;
Expand Down Expand Up @@ -47,7 +46,6 @@
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import edu.csus.ecs.pc2.core.CommandVariableReplacer;
import edu.csus.ecs.pc2.core.IInternalController;
import edu.csus.ecs.pc2.core.model.ContestInformation;
Expand Down Expand Up @@ -153,8 +151,6 @@ public class ContestInformationPane extends JPanePlugin {

private JTextField textfieldMaxOutputSizeInK = null;

private JButton scoringPropertiesButton = null;

private Properties savedScoringProperties = null; // @jve:decl-index=0:

private Properties changedScoringProperties = null;
Expand Down Expand Up @@ -184,6 +180,8 @@ public class ContestInformationPane extends JPanePlugin {
private JPanel judgesDefaultAnswerPane;

private JPanel judgingOptionsPane;

private ScoringPropertiesPane scoringPropertiesPane;

private JPanel teamSettingsPane;

Expand Down Expand Up @@ -501,9 +499,9 @@ private JPanel getJudgingSettingsPane() {
judgeSettingsPane = new JPanel();

judgeSettingsPane.setAlignmentX(LEFT_ALIGNMENT);
judgeSettingsPane.setMaximumSize(new Dimension(750, 250));
judgeSettingsPane.setMinimumSize(new Dimension(750, 250));
judgeSettingsPane.setPreferredSize(new Dimension(750,250));
judgeSettingsPane.setMaximumSize(new Dimension(800, 425));
judgeSettingsPane.setMinimumSize(new Dimension(800, 425));
judgeSettingsPane.setPreferredSize(new Dimension(800,375));

if (showPaneOutlines) {

Expand All @@ -527,8 +525,9 @@ private JPanel getJudgingSettingsPane() {

judgeSettingsPane.add(getJudgingOptionsPane(),LEFT_ALIGNMENT);

judgeSettingsPane.add(getScoringPropertiesPane(),LEFT_ALIGNMENT);

judgeSettingsPane.add(Box.createHorizontalStrut(20));
judgeSettingsPane.add(getScoringPropertiesButton(),LEFT_ALIGNMENT);

}
return judgeSettingsPane;
Expand Down Expand Up @@ -703,7 +702,19 @@ private JPanel getTeamInformationDisplaySettingsPane() {
}
return teamInformationDisplaySettingsPane;
}
private JPanel getScoringPropertiesPane() {
if (scoringPropertiesPane == null) {
scoringPropertiesPane = new ScoringPropertiesPane(getUpdateButton(),getCancelButton());

scoringPropertiesPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Scoring Properties",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));

}
return scoringPropertiesPane;
}


private JPanel getJudgingOptionsPane() {
if (judgingOptionsPane == null) {

Expand Down Expand Up @@ -994,7 +1005,7 @@ protected ContestInformation getFromFields() {
newContestInformation.setAutoStartContest(savedContestInformation.isAutoStartContest());
}

newContestInformation.setScoringProperties(changedScoringProperties);
newContestInformation.setScoringProperties(scoringPropertiesPane.getProperties());

newContestInformation.setFreezeTime(contestFreezeLengthTextField.getText());

Expand Down Expand Up @@ -1074,6 +1085,7 @@ public void run() {

getUnfreezeScoreboardButton().setSelected(contestInformation.isUnfrozen());
setContestInformation(contestInformation);
((ScoringPropertiesPane) getScoringPropertiesPane()).setProperties(changedScoringProperties);
setEnableButtons(false);
}

Expand Down Expand Up @@ -1316,7 +1328,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
*/
private JTextField getJudgesDefaultAnswerTextField() {
if (judgesDefaultAnswerTextField == null) {
judgesDefaultAnswerTextField = new JTextField(40);
judgesDefaultAnswerTextField = new JTextField(50);
judgesDefaultAnswerTextField.setText("");
// judgesDefaultAnswerTextField.setSize(new Dimension(280, 29));
// judgesDefaultAnswerTextField.setLocation(new Point(208, 214));
Expand Down Expand Up @@ -1443,60 +1455,6 @@ public void actionPerformed(ActionEvent e) {
return allowMultipleTeamLoginsCheckbox ;
}

/**
* This method initializes scoringPropertiesButton
*
* @return javax.swing.JButton
*/
private JButton getScoringPropertiesButton() {
if (scoringPropertiesButton == null) {

scoringPropertiesButton = new JButton();
scoringPropertiesButton.setHorizontalAlignment(SwingConstants.LEFT);
scoringPropertiesButton.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

scoringPropertiesButton.setAlignmentX(LEFT_ALIGNMENT);
scoringPropertiesButton.setToolTipText("Edit Scoring Properties");
scoringPropertiesButton.setMnemonic(KeyEvent.VK_S);
scoringPropertiesButton.setText("Edit Scoring Properties");
scoringPropertiesButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
showContestPropertiesEditor();
}
});
}
return scoringPropertiesButton;
}

protected void showContestPropertiesEditor() {

PropertiesEditFrame propertiesEditFrame = new PropertiesEditFrame();
propertiesEditFrame.setTitle("Edit Scoring Properties");
propertiesEditFrame.setProperties(changedScoringProperties, new UpdateScoreProperties());
propertiesEditFrame.setVisible(true);
}

/**
* Update the edited properties.
*
* @author [email protected]
* @version $Id$
*/

// $HeadURL$
protected class UpdateScoreProperties implements IPropertyUpdater {

public void updateProperties(Properties properties) {
changedScoringProperties = properties;
enableUpdateButton();
}
}

/**
* This method initializes ccsTestModeCheckbox
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getCcsTestModeCheckbox() {
if (ccsTestModeCheckbox == null) {

Expand Down
24 changes: 24 additions & 0 deletions src/edu/csus/ecs/pc2/ui/MCLB.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,31 @@ public void run() {
public void autoSizeAllColumns() {
autoSizeAllColumns(this);
}
/**
* Sets column size
* @param columnNum index of a column from left to right (0-indexed)
* @param length in pixels
*/
public void setColumnSize(int columnNum,int length) {
final MCLB theBox = this;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
theBox.getColumnInfo(columnNum).setWidth(length);
}
});
}

public void setResizable (boolean resizable) {
final MCLB theBox = this;

SwingUtilities.invokeLater(new Runnable() {
public void run() {
for (int i = 0; i < theBox.getColumnCount(); i++) {
theBox.getColumnInfo(i).setResizable(resizable);
}
}
});
}
/**
* Set sorter for column in listbox.
*
Expand Down
178 changes: 178 additions & 0 deletions src/edu/csus/ecs/pc2/ui/ScoringPropertiesPane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.security.InvalidParameterException;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import com.ibm.webrunner.j2mclb.util.HeapSorter;
/**
* ScoringPropertiesPane is a inner pane for ContestInformationPane
* Allows editing Scoring Properties for admin.
* @author [email protected]
*
*/
public class ScoringPropertiesPane extends JPanel {


private static final long serialVersionUID = 147946474651407431L;

private MCLB propertyListBox = null;

private Properties originalProperties = new Properties(); // @jve:decl-index=0:

private IPropertyUpdater propertyUpdater = null;

private JButton updateButton;

private JButton cancelButton;

private int lengthOfColumns;

public ScoringPropertiesPane(JButton updateButtona,JButton cancelButtona) {
super();
updateButton = updateButtona;
cancelButton = cancelButtona;

initialize();
}

private void initialize() {
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(350, 200));
this.add(getPropertyListBox(), BorderLayout.CENTER);
lengthOfColumns = 167;


}

protected void updateProperties(Properties properties) {
propertyUpdater.updateProperties(properties);
propertyListBox.removeAllRows();

}

private MCLB getPropertyListBox() {
if (propertyListBox == null) {
propertyListBox = new MCLB();

propertyListBox.setMultipleSelections(true);

Object[] cols = { "Property", "Value" };

propertyListBox.addColumns(cols);

HeapSorter sorter = new HeapSorter();
propertyListBox.setColumnSorter(1, sorter, 1);

propertyListBox.setColumnSize(0,lengthOfColumns);
propertyListBox.setColumnSize(1,lengthOfColumns);
propertyListBox.setResizable(false);

propertyListBox.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
enableButtons();
}
});
}
return propertyListBox;
}

public boolean propertiesChanged() {
return !originalProperties.equals(getProperties());
}

public void setProperties(final Properties properties) {

if (properties == null){
throw new InvalidParameterException("Properties are null");
}

SwingUtilities.invokeLater(new Runnable() {
public void run() {
originalProperties = properties;
refreshProperties();
}
});
}

protected void refreshProperties() {

propertyListBox.removeAllRows();

Set<Object> set = originalProperties.keySet();

String[] keys = (String[]) set.toArray(new String[set.size()]);

Arrays.sort(keys);
for (String key : keys) {

Object[] objects = new Object[2];
objects[0] = key;
objects[1] = createJTextField((String) originalProperties.get(key), false);
propertyListBox.addRow(objects);
}

propertyListBox.setColumnSize(0,lengthOfColumns);
propertyListBox.setColumnSize(1,lengthOfColumns);

enableButtons();
}

/**
* Reads properties from user input.
* @return
*/
public Properties getProperties() {

Properties fieldProps = new Properties();

for (int i = 0; i < propertyListBox.getRowCount(); i++) {
Object[] objects = propertyListBox.getRow(i);
JTextField field = (JTextField) objects[1];
fieldProps.put(objects[0], field.getText());
}

return fieldProps;
}

private JTextField createJTextField(String text, boolean passwordField) {
JTextField textField = new JTextField();
textField.setText(text);
textField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent e) {
enableButtons();
}
});
return textField;
}

public IPropertyUpdater getPropertyUpdater() {
return propertyUpdater;
}

public void setPropertyUpdater(IPropertyUpdater propertyUpdater) {
this.propertyUpdater = propertyUpdater;
}

protected void enableButtons() {
boolean changed = propertiesChanged();

if (changed) {
updateButton.setEnabled(true);
cancelButton.setEnabled(true);
}
else {
updateButton.setEnabled(false);
cancelButton.setEnabled(false);
}
}
}

0 comments on commit 857d022

Please sign in to comment.