📄 bootgui.java
字号:
it.hasMoreElements(); ) {
PropertyType prop = (PropertyType) it.nextElement();
String name = prop.getName();
String type = prop.getType();
String defaultVal = prop.getDefaultValue();
boolean found = false;
for (int i = 0; (i < size) &&!found; i++) {
JPanel singlePanel = (JPanel) propertyPanel.getComponent(i);
JLabel label = (JLabel) singlePanel.getComponent(0);
if (name.equalsIgnoreCase(label.getText())) {
found = true;
if (type.equalsIgnoreCase(PropertyType.COMBO_TYPE)) {
//JComboBox
JComboBox box =
(JComboBox) singlePanel.getComponent(1);
out.setProperty(name.toLowerCase(),
box.getSelectedItem().toString());
}
else if (type.equalsIgnoreCase(PropertyType.BOOLEAN_TYPE)) {
//JCheckBox
JCheckBox box =
(JCheckBox) singlePanel.getComponent(1);
out.setProperty(name.toLowerCase(),
(new Boolean(box.isSelected()))
.toString());
} else {
//JTextField
JTextField textField =
(JTextField) singlePanel.getComponent(1);
String text = textField.getText();
//if the user not specificy a value the default one is saved.
if (text.length() == 0) {
text = defaultVal;
}
out.setProperty(name.toLowerCase(), text);
}
}
}
}
//System.out.println("extract from GUI: ");
//out.list(System.out);
return out;
}
/**
* Compare two property collections.
*/
boolean compareProperties(BasicProperties p1,
BasicProperties p2) {
Enumeration keys = p1.keys();
boolean modified = false;
while (keys.hasMoreElements() &&!modified) {
String k1 = (String) keys.nextElement();
String v1 = p1.getProperty(k1);
String v2 = p2.getProperty(k1);
if (v1 == null) {
modified = (v2 != null);
} else {
modified = !(v1.equalsIgnoreCase(v2));
}
}
return modified;
}
/**
* Update the gui when a new file is opened.
* For every property it sets in the vector of property the value read in the file
* or if it is absent the default value.
*/
void updateProperties() {
int size = propertyPanel.getComponentCount();
for (Enumeration it = propertiesVector.elements();
it.hasMoreElements(); ) {
PropertyType prop = (PropertyType) it.nextElement();
String name = prop.getName();
String type = prop.getType();
String newValue = prop.getDefaultValue();
boolean found = false;
for (int i = 0; (i < size) &&!found; i++) {
JPanel singlePanel = (JPanel) propertyPanel.getComponent(i);
JLabel label = (JLabel) singlePanel.getComponent(0);
if (name.equalsIgnoreCase(label.getText())) {
found = true;
if (type.equalsIgnoreCase(PropertyType.BOOLEAN_TYPE)) {
//JCheckBox
JCheckBox box = (JCheckBox) singlePanel.getComponent(1);
box.setSelected(newValue.equalsIgnoreCase("true"));
} else {
//JTextField
JTextField textField = (JTextField) singlePanel.getComponent(1);
textField.setText(newValue);
}
}
}
}
}
/**
* Show the gui in the center of the screen
*/
void ShowCorrect() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension mySize = getPreferredSize();
int x = (screenSize.width - mySize.width) / 2;
int y = (screenSize.height - mySize.height) / 2;
setBounds(x, y, mySize.width, mySize.height);
setResizable(true);
pack();
setVisible(true);
toFront();
}
/**
* Read the properties from file and update the vector of properties.
*/
void loadPropertiesFromFile(String fileName)
throws FileNotFoundException, IOException {
BasicProperties p = readPropertiesFromFile(fileName);
// update the properties in the vector of properties
// for every property set the value read in the file and set the command line value to null.
Enumeration e = p.keys();
while (e.hasMoreElements()) {
boolean found = false;
String name = (String) e.nextElement();
Enumeration it = propertiesVector.elements();
while (it.hasMoreElements() &&!found) {
PropertyType pt = (PropertyType) it.nextElement();
if (pt.getName().equalsIgnoreCase(name)) {
found = true;
pt.setDefaultValue(p.getProperty(name));
}
}
}
}
/**
* Read the properties from a specific file.
*/
BasicProperties readPropertiesFromFile(String fileName)
throws FileNotFoundException, IOException {
BasicProperties p = new ExpandedProperties();
FileInputStream in = new FileInputStream(fileName);
p.load(in);
in.close();
return p;
}
/**
* Verify if the file written by the user has the right extension. (Used in the save action)
*/
boolean hasExtension(String fileName) {
String ext = null;
boolean out = false;
int i = fileName.lastIndexOf('.');
if ((i > 0) && (i < fileName.length() - 1)) {
ext = fileName.substring(i + 1);
}
if (ext != null) {
if (ext.equalsIgnoreCase("conf")) {
out = true;
}
}
return out;
}
/**
* Returns a list of PropertyType used by the BootGUI to initialize the GUI.
*/
Vector createPropertyVector(BasicProperties theProperties) {
Vector pv = new Vector();
String[] loginEnum = {"Simple", "Unix", "NT", "Kerberos"};
pv.add(new PropertyType(BootProfileImpl.LOGIN_KEY,
PropertyType.COMBO_TYPE,
loginEnum,
theProperties.getProperty(BootProfileImpl.LOGIN_KEY),
"User Authentication context",
false));
pv.add(new PropertyType(BootProfileImpl.MAIN_HOST,
PropertyType.STRING_TYPE,
theProperties.getProperty(BootProfileImpl.MAIN_HOST),
"Host Name of the main-container",
false));
pv.add(new PropertyType(BootProfileImpl.GUI_KEY,
PropertyType.BOOLEAN_TYPE,
new Boolean(theProperties.getBooleanProperty(BootProfileImpl.GUI_KEY, false)).toString(),
"Select to launch the RMA Gui",
false));
pv.add(new PropertyType(BootProfileImpl.MAIN_PORT,
PropertyType.STRING_TYPE,
new Integer(theProperties.getIntProperty(BootProfileImpl.MAIN_PORT,
BootProfileImpl.DEFAULT_PORT)).toString(),
"Port Number of the main-container",
false));
pv.add(new PropertyType(BootProfileImpl.NAME_KEY,
PropertyType.STRING_TYPE,
theProperties.getProperty(BootProfileImpl.NAME_KEY),
"The symbolic plaform name",
false));
pv.add(new PropertyType(BootProfileImpl.CONTAINER_KEY,
PropertyType.BOOLEAN_TYPE,
new Boolean(theProperties.getBooleanProperty(BootProfileImpl.CONTAINER_KEY, false)).toString(),
"Select to launch an agent-container",
false));
pv.add(new PropertyType(BootProfileImpl.MTP_KEY,
PropertyType.STRING_TYPE,
theProperties.getProperty(BootProfileImpl.MTP_KEY),
"List of MTPs to activate",
false));
pv.add(new PropertyType(BootProfileImpl.NOMTP_KEY,
PropertyType.BOOLEAN_TYPE,
new Boolean(theProperties.getBooleanProperty(BootProfileImpl.NOMTP_KEY, false)).toString(),
"Disable all external MTPs on this container",
false));
pv.add(new PropertyType(BootProfileImpl.ACLCODEC_KEY,
PropertyType.STRING_TYPE,
theProperties.getProperty(BootProfileImpl.ACLCODEC_KEY),
"List of ACLCodec to install",
false));
pv.add(new PropertyType(BootProfileImpl.AGENTS,
PropertyType.STRING_TYPE,
theProperties.getProperty(BootProfileImpl.AGENTS),
"Agents to launch",
false));
pv.add(new PropertyType(BootProfileImpl.NOMOBILITY_KEY,
PropertyType.BOOLEAN_TYPE,
new Boolean(theProperties.getBooleanProperty(BootProfileImpl.NOMOBILITY_KEY,false)).toString(),
"Disable Mobility",
false));
return pv;
}
/**
* A JPanel for a single property.
*/
class singlePanel extends JPanel {
singlePanel() {
super();
}
JPanel newSinglePanel(PropertyType property) {
JPanel mainP = new JPanel(new FlowLayout(FlowLayout.LEFT));
Border etched = BorderFactory.createEtchedBorder(Color.white,
Color.gray);
String name = property.getName();
JLabel nameLabel = new JLabel(name.toUpperCase());
nameLabel.setPreferredSize(new Dimension(80, 26));
nameLabel.setMaximumSize(new Dimension(80, 26));
nameLabel.setMinimumSize(new Dimension(80, 26));
mainP.add(nameLabel);
String type = property.getType();
JComboBox valueCombo;
JCheckBox valueBox;
JTextField valueText;
// if the property has a command line value than it is used
// otherwise is used the default value
String value = property.getDefaultValue();
if (type.equalsIgnoreCase(PropertyType.COMBO_TYPE)) {
valueCombo = new JComboBox(property.getComboValues());
valueCombo.setSelectedIndex(0);
valueCombo.setToolTipText(property.getToolTip());
mainP.add(valueCombo);
} else if (type.equalsIgnoreCase(PropertyType.BOOLEAN_TYPE)) {
valueBox = new JCheckBox();
valueBox.setSelected((new Boolean(value)).booleanValue());
valueBox.setToolTipText(property.getToolTip());
mainP.add(valueBox);
} else {
valueText = new JTextField();
valueText.setBorder(etched);
if (type.equalsIgnoreCase(PropertyType.INTEGER_TYPE)) {
valueText.setPreferredSize(new Dimension(100, 26));
valueText.setMaximumSize(new Dimension(100,26));
} else {
valueText.setPreferredSize(new Dimension(600, 26));
}
valueText.setMinimumSize(new Dimension(50, 26));
valueText.setText(value);
valueText.setToolTipText(property.getToolTip());
mainP.add(valueText);
}
return mainP;
}
}
/**
* Extends FileFilter in order to show only files with extension ".conf".
*/
class myFileFilter extends FileFilter {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String ext = getExtension(f);
if (ext != null) {
if (ext.equals(EXTENSION)) {
return true;
} else {
return false;
}
}
return false;
}
public String getDescription() {
return "Configuration file (*." + EXTENSION + ")";
}
String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if ((i > 0) && (i < s.length() - 1)) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -