-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1045 from johnbrvc/i_1043_ScoringPropertySheetGUI
i_1043 Fix GUI so you can see Scoring Properties
- Loading branch information
Showing
2 changed files
with
53 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau. | ||
// Copyright (C) 1989-2025 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau. | ||
package edu.csus.ecs.pc2.ui; | ||
|
||
import java.awt.BorderLayout; | ||
|
@@ -14,52 +14,50 @@ | |
import javax.swing.SwingUtilities; | ||
|
||
import com.ibm.webrunner.j2mclb.util.HeapSorter; | ||
import com.ibm.webrunner.j2mclb.util.StringComparator; | ||
/** | ||
* 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 static final long serialVersionUID = 147946474651407431L; | ||
private static final int PROPERTY_COL_WIDTH = 170; | ||
private static final int VALUE_COL_WIDTH = 500; | ||
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.setPreferredSize(new Dimension(PROPERTY_COL_WIDTH + VALUE_COL_WIDTH + 8, 200)); | ||
this.setMinimumSize(new Dimension(PROPERTY_COL_WIDTH + VALUE_COL_WIDTH + 8, 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(); | ||
|
@@ -71,46 +69,49 @@ private MCLB getPropertyListBox() { | |
propertyListBox.addColumns(cols); | ||
|
||
HeapSorter sorter = new HeapSorter(); | ||
propertyListBox.setColumnSorter(1, sorter, 1); | ||
sorter.setComparator(new StringComparator()); | ||
propertyListBox.setColumnSorter(0, sorter, 1); | ||
|
||
propertyListBox.setColumnSize(0,lengthOfColumns); | ||
propertyListBox.setColumnSize(1,lengthOfColumns); | ||
propertyListBox.setColumnSize(0,PROPERTY_COL_WIDTH); | ||
propertyListBox.setColumnSize(1,VALUE_COL_WIDTH); | ||
propertyListBox.setResizable(false); | ||
|
||
propertyListBox.addKeyListener(new java.awt.event.KeyAdapter() { | ||
@Override | ||
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() { | ||
@Override | ||
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()]); | ||
String[] keys = set.toArray(new String[set.size()]); | ||
|
||
Arrays.sort(keys); | ||
for (String key : keys) { | ||
|
@@ -120,13 +121,13 @@ protected void refreshProperties() { | |
objects[1] = createJTextField((String) originalProperties.get(key), false); | ||
propertyListBox.addRow(objects); | ||
} | ||
propertyListBox.setColumnSize(0,lengthOfColumns); | ||
propertyListBox.setColumnSize(1,lengthOfColumns); | ||
|
||
propertyListBox.setColumnSize(0,PROPERTY_COL_WIDTH); | ||
propertyListBox.setColumnSize(1,VALUE_COL_WIDTH); | ||
|
||
enableButtons(); | ||
} | ||
|
||
/** | ||
* Reads properties from user input. | ||
* @return | ||
|
@@ -143,26 +144,27 @@ public Properties getProperties() { | |
|
||
return fieldProps; | ||
} | ||
|
||
private JTextField createJTextField(String text, boolean passwordField) { | ||
JTextField textField = new JTextField(); | ||
textField.setText(text); | ||
textField.addKeyListener(new java.awt.event.KeyAdapter() { | ||
@Override | ||
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(); | ||
|
||
|