TrustGrapher
r52
A playabale simulator for modelling trust between agents
|
00001 00002 package cu.trustGrapher.loading; 00003 00004 import cu.trustGrapher.TrustGrapher; 00005 import java.io.File; 00006 import javax.swing.border.TitledBorder; 00007 00008 import java.util.ArrayList; 00009 import java.util.List; 00010 import aohara.utilities.*; 00011 00017 public class AlgorithmLoader extends javax.swing.JFrame { 00018 00019 public static final int MAX_GRAPHS = 13, MAX_VISIBLE = 6; 00020 public static final String GRAPH = "graph", CLASS = "class"; 00021 public static final String LOG_PATH = "logPath", CLASS_PATH = "classPath", PROPERTY_PATH = "propertyPath"; 00022 protected PropertyManager config; 00023 protected TrustGrapher trustGrapher; 00024 private List<GraphConfig> graphConfigs; 00025 00027 00032 public AlgorithmLoader(TrustGrapher trustGrapher, PropertyManager config) { 00033 this.trustGrapher = trustGrapher; 00034 this.config = config; 00035 initComponents(); 00036 } 00037 00039 00046 private Integer getNewKey(String type) { 00047 for (int i = 0; i < config.keySet().size() + 1; i++) { 00048 if (!config.containsKey(type + i)) { 00049 return i; 00050 } 00051 } 00052 return null; 00053 } 00054 00058 private int getBaseIndex() { 00059 return Integer.parseInt(((String) baseField.getSelectedItem()).split("-")[0]); 00060 } 00061 00065 private GraphConfig getSelectedGraph() { 00066 String temp = ((String) graphList.getSelectedValue()).split("-")[0]; 00067 return getGraphConfig(Integer.parseInt(temp)); 00068 } 00069 00073 public List<GraphConfig> getGraphConfigs() { 00074 return graphConfigs; 00075 } 00076 00084 private GraphConfig getGraphConfig(int index) { 00085 for (GraphConfig graphConfig : graphConfigs) { 00086 if (index == graphConfig.getIndex()) { 00087 return graphConfig; 00088 } 00089 } 00090 return null; 00091 } 00092 00097 private Object[] getGraphDisplayNames() { 00098 ArrayList<String> names = new ArrayList<String>(MAX_GRAPHS); 00099 for (GraphConfig graphConfig : graphConfigs) { 00100 names.add(graphConfig.getDisplayName()); 00101 } 00102 return names.toArray(); 00103 } 00104 00108 private boolean hasRepGraph() { 00109 for (GraphConfig graphConfig : graphConfigs) { 00110 if (graphConfig != null) { 00111 if (graphConfig.isReputationGraph()) { 00112 return true; 00113 } 00114 } 00115 } 00116 return false; 00117 } 00118 00122 public int getVisibleGraphCount() { 00123 int count = 0; 00124 for (GraphConfig graphConfig : graphConfigs) { 00125 if (graphConfig.isDisplayed()) { 00126 count++; 00127 } 00128 } 00129 return count; 00130 } 00131 00133 00138 private boolean addGraphConfig(GraphConfig graphConfig) { 00139 if (graphConfigs.size() >= MAX_GRAPHS) { 00140 ChatterBox.alert("Cannot have more than " + MAX_GRAPHS + " graphs at one time."); 00141 return false; 00142 } 00143 graphConfigs.add(graphConfig); 00144 return true; 00145 } 00146 00154 private boolean addNewGraph(int index, int classIndex) { 00155 String classPath = (classIndex != -1) ? config.getProperty(CLASS + classIndex) : null; 00156 GraphConfig graphConfig = new GraphConfig(index, false, -1, classIndex, classPath, null); 00157 if (graphConfig.isTrustGraph() && !hasRepGraph()) { 00158 ChatterBox.alert("There must be an existing Reputation Graph\nbefore you can add a Trust Graph."); 00159 return false; 00160 } 00161 return addGraphConfig(graphConfig); 00162 } 00163 00168 private void updateFields() { 00169 GraphConfig graph = getSelectedGraph(); 00170 if (graph != null) { //If a graph is selected 00171 ((TitledBorder) graphPanel.getBorder()).setTitle(graph.getDisplayName()); 00172 displayField.setSelected(graph.isDisplayed()); //Set the Display JCheckBox 00173 00174 propertiesField.setText(graph.getProperties() != null ? graph.getProperties().getName() : ""); //Set the properties file 00175 //If the feedbackHistory is selected, disable the properties buttons 00176 choosePropertiesButton.setEnabled(graph.isFeedbackGraph() ? false : true); 00177 removePropertyButton.setEnabled(graph.isFeedbackGraph() ? false : true); 00178 00179 //Set the Base List 00180 baseField.setEnabled(false); 00181 baseField.removeAllItems(); 00182 if (graph.isFeedbackGraph()) { //If the graphs is the feedbackHistory 00183 baseField.addItem(GraphConfig.NO_BASE); 00184 baseField.setSelectedIndex(0); 00185 } else if (graph.isReputationGraph()) { //if the graphs is a reputation graph 00186 baseField.addItem(getGraphConfig(0).getDisplayName()); 00187 baseField.setSelectedIndex(0); 00188 } else { //Otherwise, it must use be a trust graph 00189 for (GraphConfig a : graphConfigs) { //Add All reputation graphs to the base list 00190 if (a.isReputationGraph()) { 00191 baseField.addItem(a.getDisplayName()); 00192 if (graph.getBaseIndex() != -1) { 00193 if (graph.getBaseIndex() == a.getIndex()) { //If the current graph listens to this graph, select it 00194 baseField.setSelectedItem(a.getDisplayName()); 00195 } 00196 } 00197 } 00198 } 00199 } 00200 if (((String) baseField.getSelectedItem()).equals(GraphConfig.NO_BASE)) { 00201 graph.setBase(-1); 00202 } else { 00203 graph.setBase(getBaseIndex()); 00204 } 00205 //If the selected graph uses a trust algorithm, enable the base field 00206 baseField.setEnabled(graph.isTrustGraph() ? true : false); 00207 00208 //Set the class list 00209 classList.removeAllItems(); 00210 for (int i = 0; i < config.keySet().size(); i++) { 00211 if (config.containsKey(CLASS + i)) { 00212 classList.addItem(formatClassName(i, config.getProperty(CLASS + i))); 00213 } 00214 } 00215 config.setProperty(graph.getKey(), graph.toString()); 00216 } 00217 } 00218 00223 public void start() { 00224 graphConfigs = new ArrayList<GraphConfig>(); 00225 config.loadPropertyFile(); 00226 00227 if (!config.containsKey(GRAPH + 0)) { //If the feedbackHistory graph does not exist in the properties, add it 00228 addNewGraph(0, -1); 00229 } 00230 //Add the graphs from the properties files to the GraphConfig list 00231 for (int i = 0; i <= config.keySet().size(); i++) { 00232 if (config.containsKey(GRAPH + i)) { 00233 String[] property = config.getProperty(GRAPH + i).split(","); 00234 int baseIndex = -1; 00235 int classIndex = -1; 00236 try { 00237 baseIndex = Integer.parseInt(property[1]); 00238 } catch (NumberFormatException ex) { 00239 } 00240 try { 00241 classIndex = Integer.parseInt(property[2]); 00242 } catch (NumberFormatException ex) { 00243 } 00244 String classPath = (classIndex == -1) ? null : config.getProperty(CLASS + classIndex); 00245 //Graph property format display base classIndex classPath properties 00246 addGraphConfig( new GraphConfig(i, Boolean.parseBoolean(property[0]), baseIndex, classIndex, classPath, new File(property[3]))); 00247 } 00248 } 00249 00250 //Set the log to the last one loaded 00251 String logPath = config.getProperty(LOG_PATH); 00252 if (logPath != null) { 00253 pathField.setText(logPath); 00254 } 00255 graphList.setListData(getGraphDisplayNames()); //Set the graphList names 00256 graphList.setSelectedIndex(0); 00257 updateFields(); 00258 setVisible(true); 00259 } 00260 00262 00268 public static void run(TrustGrapher trustGrapher, PropertyManager properties) { 00269 AlgorithmLoader algorithmLoader = new AlgorithmLoader(trustGrapher, properties); 00270 algorithmLoader.start(); 00271 } 00272 00279 public static String formatClassName(int index, String path) { 00280 //if it is a .jar, the name appears after the last '.' 00281 //Otherwise, it is a .class, and the name will appear after the last '/' 00282 char startChar = path.contains(".jar") ? '.' : '/'; 00283 return "class" + index + "-" + path.substring(path.lastIndexOf(startChar) + 1).replace(".class", ""); 00284 } 00285 00287 00292 @SuppressWarnings("unchecked") 00293 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 00294 private void initComponents() { 00295 00296 okButton = new javax.swing.JButton(); 00297 cancelButton = new javax.swing.JButton(); 00298 applyButton = new javax.swing.JButton(); 00299 helpButton = new javax.swing.JButton(); 00300 javax.swing.JPanel algorithmListPanel = new javax.swing.JPanel(); 00301 jScrollPane1 = new javax.swing.JScrollPane(); 00302 graphList = new javax.swing.JList(); 00303 addButton = new javax.swing.JButton(); 00304 removeButton = new javax.swing.JButton(); 00305 graphPanel = new javax.swing.JPanel(); 00306 displayField = new javax.swing.JCheckBox(); 00307 javax.swing.JLabel jLabel2 = new javax.swing.JLabel(); 00308 baseField = new javax.swing.JComboBox(); 00309 javax.swing.JLabel jLabel3 = new javax.swing.JLabel(); 00310 javax.swing.JLabel jLabel5 = new javax.swing.JLabel(); 00311 jPanel1 = new javax.swing.JPanel(); 00312 propertiesField = new javax.swing.JTextField(); 00313 choosePropertiesButton = new javax.swing.JButton(); 00314 removePropertyButton = new javax.swing.JButton(); 00315 javax.swing.JPanel jPanel2 = new javax.swing.JPanel(); 00316 javax.swing.JLabel jLabel6 = new javax.swing.JLabel(); 00317 pathField = new javax.swing.JTextField(); 00318 loadButton = new javax.swing.JButton(); 00319 javax.swing.JLabel jLabel7 = new javax.swing.JLabel(); 00320 classList = new javax.swing.JComboBox(); 00321 addClassButton = new javax.swing.JButton(); 00322 removeClassButton = new javax.swing.JButton(); 00323 00324 setTitle("Algorithm Configuration"); 00325 setBackground(new java.awt.Color(39, 31, 24)); 00326 setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); 00327 setForeground(new java.awt.Color(254, 254, 254)); 00328 setResizable(false); 00329 00330 okButton.setText("OK"); 00331 okButton.addActionListener(new java.awt.event.ActionListener() { 00332 public void actionPerformed(java.awt.event.ActionEvent evt) { 00333 okButtonActionPerformed(evt); 00334 } 00335 }); 00336 00337 cancelButton.setText("Cancel"); 00338 cancelButton.addActionListener(new java.awt.event.ActionListener() { 00339 public void actionPerformed(java.awt.event.ActionEvent evt) { 00340 cancelButtonActionPerformed(evt); 00341 } 00342 }); 00343 00344 applyButton.setText("Apply"); 00345 applyButton.addActionListener(new java.awt.event.ActionListener() { 00346 public void actionPerformed(java.awt.event.ActionEvent evt) { 00347 applyButtonActionPerformed(evt); 00348 } 00349 }); 00350 00351 helpButton.setText("Help"); 00352 helpButton.addActionListener(new java.awt.event.ActionListener() { 00353 public void actionPerformed(java.awt.event.ActionEvent evt) { 00354 helpButtonActionPerformed(evt); 00355 } 00356 }); 00357 00358 algorithmListPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Graph List", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14))); // NOI18N 00359 00360 graphList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 00361 graphList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { 00362 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 00363 graphListValueChanged(evt); 00364 } 00365 }); 00366 jScrollPane1.setViewportView(graphList); 00367 00368 addButton.setText("Add"); 00369 addButton.addActionListener(new java.awt.event.ActionListener() { 00370 public void actionPerformed(java.awt.event.ActionEvent evt) { 00371 addButtonActionPerformed(evt); 00372 } 00373 }); 00374 00375 removeButton.setText("Remove"); 00376 removeButton.addActionListener(new java.awt.event.ActionListener() { 00377 public void actionPerformed(java.awt.event.ActionEvent evt) { 00378 removeButtonActionPerformed(evt); 00379 } 00380 }); 00381 00382 javax.swing.GroupLayout algorithmListPanelLayout = new javax.swing.GroupLayout(algorithmListPanel); 00383 algorithmListPanel.setLayout(algorithmListPanelLayout); 00384 algorithmListPanelLayout.setHorizontalGroup( 00385 algorithmListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00386 .addGroup(algorithmListPanelLayout.createSequentialGroup() 00387 .addContainerGap() 00388 .addGroup(algorithmListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00389 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE) 00390 .addGroup(algorithmListPanelLayout.createSequentialGroup() 00391 .addComponent(addButton) 00392 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE) 00393 .addComponent(removeButton))) 00394 .addContainerGap()) 00395 ); 00396 algorithmListPanelLayout.setVerticalGroup( 00397 algorithmListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00398 .addGroup(algorithmListPanelLayout.createSequentialGroup() 00399 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE) 00400 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 00401 .addGroup(algorithmListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00402 .addComponent(addButton) 00403 .addComponent(removeButton)) 00404 .addContainerGap(17, Short.MAX_VALUE)) 00405 ); 00406 00407 graphPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Graph", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14))); // NOI18N 00408 00409 displayField.setText("Display Graph"); 00410 displayField.addActionListener(new java.awt.event.ActionListener() { 00411 public void actionPerformed(java.awt.event.ActionEvent evt) { 00412 displayFieldActionPerformed(evt); 00413 } 00414 }); 00415 00416 jLabel2.setBackground(new java.awt.Color(52, 52, 52)); 00417 jLabel2.setText("Listens to:"); 00418 00419 baseField.addActionListener(new java.awt.event.ActionListener() { 00420 public void actionPerformed(java.awt.event.ActionEvent evt) { 00421 baseFieldActionPerformed(evt); 00422 } 00423 }); 00424 00425 jLabel3.setText("Maximum 12 algorithms at any time."); 00426 00427 jLabel5.setText("Maximum 6 graphs displayed at any time."); 00428 00429 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Algorithm Properties")); 00430 00431 propertiesField.setEditable(false); 00432 00433 choosePropertiesButton.setText("Choose"); 00434 choosePropertiesButton.addActionListener(new java.awt.event.ActionListener() { 00435 public void actionPerformed(java.awt.event.ActionEvent evt) { 00436 choosePropertiesButtonActionPerformed(evt); 00437 } 00438 }); 00439 00440 removePropertyButton.setText("Remove"); 00441 removePropertyButton.addActionListener(new java.awt.event.ActionListener() { 00442 public void actionPerformed(java.awt.event.ActionEvent evt) { 00443 removePropertyButtonActionPerformed(evt); 00444 } 00445 }); 00446 00447 javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); 00448 jPanel1.setLayout(jPanel1Layout); 00449 jPanel1Layout.setHorizontalGroup( 00450 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00451 .addGroup(jPanel1Layout.createSequentialGroup() 00452 .addContainerGap() 00453 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00454 .addComponent(propertiesField, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE) 00455 .addGroup(jPanel1Layout.createSequentialGroup() 00456 .addGap(51, 51, 51) 00457 .addComponent(choosePropertiesButton) 00458 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00459 .addComponent(removePropertyButton))) 00460 .addContainerGap()) 00461 ); 00462 jPanel1Layout.setVerticalGroup( 00463 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00464 .addGroup(jPanel1Layout.createSequentialGroup() 00465 .addComponent(propertiesField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00466 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00467 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00468 .addComponent(removePropertyButton) 00469 .addComponent(choosePropertiesButton)) 00470 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 00471 ); 00472 00473 javax.swing.GroupLayout graphPanelLayout = new javax.swing.GroupLayout(graphPanel); 00474 graphPanel.setLayout(graphPanelLayout); 00475 graphPanelLayout.setHorizontalGroup( 00476 graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00477 .addGroup(graphPanelLayout.createSequentialGroup() 00478 .addContainerGap() 00479 .addGroup(graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00480 .addComponent(displayField) 00481 .addGroup(graphPanelLayout.createSequentialGroup() 00482 .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 00483 .addGap(303, 303, 303)) 00484 .addGroup(graphPanelLayout.createSequentialGroup() 00485 .addComponent(jLabel3) 00486 .addContainerGap(50, Short.MAX_VALUE)) 00487 .addGroup(graphPanelLayout.createSequentialGroup() 00488 .addGroup(graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) 00489 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, graphPanelLayout.createSequentialGroup() 00490 .addComponent(jLabel2) 00491 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00492 .addComponent(baseField, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 00493 .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 00494 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) 00495 ); 00496 graphPanelLayout.setVerticalGroup( 00497 graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00498 .addGroup(graphPanelLayout.createSequentialGroup() 00499 .addComponent(displayField) 00500 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 00501 .addGroup(graphPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00502 .addComponent(jLabel2) 00503 .addComponent(baseField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) 00504 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 00505 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00506 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE) 00507 .addComponent(jLabel3) 00508 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 00509 .addComponent(jLabel5) 00510 .addContainerGap()) 00511 ); 00512 00513 jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("")); 00514 00515 jLabel6.setText("Feedback Log:"); 00516 00517 pathField.setEditable(false); 00518 00519 loadButton.setText("Choose Log"); 00520 loadButton.addActionListener(new java.awt.event.ActionListener() { 00521 public void actionPerformed(java.awt.event.ActionEvent evt) { 00522 loadButtonActionPerformed(evt); 00523 } 00524 }); 00525 00526 jLabel7.setText("Algorithms:"); 00527 00528 classList.setMaximumSize(new java.awt.Dimension(41, 28)); 00529 00530 addClassButton.setText("Add"); 00531 addClassButton.addActionListener(new java.awt.event.ActionListener() { 00532 public void actionPerformed(java.awt.event.ActionEvent evt) { 00533 addClassButtonActionPerformed(evt); 00534 } 00535 }); 00536 00537 removeClassButton.setText("Remove"); 00538 removeClassButton.addActionListener(new java.awt.event.ActionListener() { 00539 public void actionPerformed(java.awt.event.ActionEvent evt) { 00540 removeClassButtonActionPerformed(evt); 00541 } 00542 }); 00543 00544 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); 00545 jPanel2.setLayout(jPanel2Layout); 00546 jPanel2Layout.setHorizontalGroup( 00547 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00548 .addGroup(jPanel2Layout.createSequentialGroup() 00549 .addContainerGap() 00550 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00551 .addGroup(jPanel2Layout.createSequentialGroup() 00552 .addComponent(jLabel7) 00553 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00554 .addComponent(classList, 0, 246, Short.MAX_VALUE) 00555 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00556 .addComponent(addClassButton) 00557 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00558 .addComponent(removeClassButton)) 00559 .addGroup(jPanel2Layout.createSequentialGroup() 00560 .addComponent(jLabel6) 00561 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00562 .addComponent(pathField, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) 00563 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00564 .addComponent(loadButton))) 00565 .addContainerGap()) 00566 ); 00567 jPanel2Layout.setVerticalGroup( 00568 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00569 .addGroup(jPanel2Layout.createSequentialGroup() 00570 .addContainerGap() 00571 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00572 .addComponent(jLabel6) 00573 .addComponent(pathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00574 .addComponent(loadButton)) 00575 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00576 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00577 .addComponent(jLabel7) 00578 .addComponent(classList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00579 .addComponent(removeClassButton) 00580 .addComponent(addClassButton)) 00581 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 00582 ); 00583 00584 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 00585 getContentPane().setLayout(layout); 00586 layout.setHorizontalGroup( 00587 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00588 .addGroup(layout.createSequentialGroup() 00589 .addContainerGap() 00590 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00591 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 00592 .addGroup(layout.createSequentialGroup() 00593 .addComponent(helpButton) 00594 .addGap(185, 185, 185) 00595 .addComponent(applyButton) 00596 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00597 .addComponent(okButton) 00598 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00599 .addComponent(cancelButton)) 00600 .addGroup(layout.createSequentialGroup() 00601 .addComponent(algorithmListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00602 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00603 .addComponent(graphPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE))) 00604 .addContainerGap()) 00605 ); 00606 layout.setVerticalGroup( 00607 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 00608 .addGroup(layout.createSequentialGroup() 00609 .addContainerGap() 00610 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 00611 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00612 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 00613 .addComponent(graphPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 00614 .addComponent(algorithmListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 00615 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 00616 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 00617 .addComponent(helpButton) 00618 .addComponent(okButton) 00619 .addComponent(cancelButton) 00620 .addComponent(applyButton)) 00621 .addContainerGap()) 00622 ); 00623 00624 pack(); 00625 }// </editor-fold>//GEN-END:initComponents 00626 00627 private void graphListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_graphListValueChanged 00628 if (graphList.getSelectedIndex() != -1) { 00629 updateFields(); 00630 } 00631 }//GEN-LAST:event_graphListValueChanged 00632 00633 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed 00634 //Generate array of graph types to load 00635 ArrayList<String> classPaths = new ArrayList<String>(); 00636 for (int i = 0; i <= MAX_GRAPHS; i++) { 00637 if (config.containsKey(CLASS + i)) { 00638 classPaths.add(formatClassName(i, config.getProperty(CLASS + i))); 00639 } 00640 } 00641 //Ask which type of graph to add 00642 if (graphConfigs.size() < MAX_GRAPHS) { 00643 String selectedClassName = ChatterBox.selectionPane("Question", "Which graph type would you like to load?", classPaths.toArray()); 00644 if (selectedClassName != null) { 00645 int newKey = getNewKey(GRAPH); 00646 addNewGraph(newKey, classPaths.indexOf((Object) selectedClassName)); 00647 config.setProperty(GRAPH + newKey, getGraphConfig(newKey).toString()); 00648 00649 //Add the info to the loader and window 00650 graphList.setListData(getGraphDisplayNames()); 00651 graphList.setSelectedIndex(graphList.getLastVisibleIndex()); 00652 } 00653 } 00654 }//GEN-LAST:event_addButtonActionPerformed 00655 00656 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed 00657 int index = getSelectedGraph().getIndex(); 00658 if (index == 0) { 00659 ChatterBox.alert("You cannot remove the FeedbackHistory."); 00660 } else if (index != -1) { 00661 //Check if this graph is being used by another 00662 for (GraphConfig graphConfig : graphConfigs) { 00663 if (graphConfig.getBaseIndex() != -1) { 00664 if (graphConfig.getBaseIndex() == index) { 00665 ChatterBox.alert("You cannot remove a graph that is used by another."); 00666 return; 00667 } 00668 } 00669 } 00670 00671 config.remove(GRAPH + index); //Remove the GraphConfig from the proeprties 00672 for (int i = 0; i < graphConfigs.size(); i++) { //remove the GraphConfig from the list 00673 if (index == graphConfigs.get(i).getIndex()) { 00674 graphConfigs.remove(graphConfigs.get(i)); 00675 } 00676 } 00677 graphList.setListData(getGraphDisplayNames()); //reset the graph list 00678 graphList.setSelectedIndex(graphList.getLastVisibleIndex()); 00679 } 00680 }//GEN-LAST:event_removeButtonActionPerformed 00681 00682 private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed 00683 config.save(); 00684 }//GEN-LAST:event_applyButtonActionPerformed 00685 00686 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed 00687 config.save(); 00688 dispose(); 00689 if (getVisibleGraphCount() > 0) { 00690 trustGrapher.algorithmsLoaded(graphConfigs); 00691 } else { 00692 ChatterBox.alert("No graphs are displayed, so no action was done."); 00693 } 00694 }//GEN-LAST:event_okButtonActionPerformed 00695 00696 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed 00697 dispose(); 00698 }//GEN-LAST:event_cancelButtonActionPerformed 00699 00700 private void displayFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayFieldActionPerformed 00701 if (graphList.getSelectedIndex() != -1 && isVisible()) { 00702 if (displayField.isSelected()) { 00703 if (getVisibleGraphCount() >= MAX_VISIBLE) { 00704 displayField.setSelected(false); 00705 ChatterBox.alert("You cannot have more than " + MAX_VISIBLE + " visible graphs at one time."); 00706 } else { 00707 GraphConfig graphConfig = getSelectedGraph(); 00708 graphConfig.setDisplay(displayField.isSelected()); 00709 config.setProperty(graphConfig.getKey(), graphConfig.toString()); 00710 } 00711 } 00712 } 00713 }//GEN-LAST:event_displayFieldActionPerformed 00714 00715 private void baseFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_baseFieldActionPerformed 00716 //This is called when the selected graph's base is changed from the options window 00717 if (baseField.isEnabled() && baseField.getSelectedIndex() != -1 && isVisible()) { 00718 GraphConfig graphConfig = getSelectedGraph(); 00719 graphConfig.setBase(getBaseIndex()); 00720 config.setProperty(graphConfig.getKey(), graphConfig.toString()); 00721 } 00722 }//GEN-LAST:event_baseFieldActionPerformed 00723 00724 private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed 00725 //This is called when the choose log button is pressed 00726 00727 //See if there is a property containing the path of the last log file loaded 00728 File lastPath = config.containsKey(LOG_PATH) ? new File(config.getProperty(LOG_PATH)).getParentFile() : null; 00729 00730 //Open a JFileChoose asking the user to choose a new log file 00731 File logFile = BitStylus.chooseFile("Choose a log file to load", lastPath, new String[]{"arff"}); 00732 if (logFile != null) { 00733 pathField.setText(logFile.getPath()); 00734 config.setProperty(LOG_PATH, logFile.getPath()); 00735 } 00736 }//GEN-LAST:event_loadButtonActionPerformed 00737 00738 private void addClassButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClassButtonActionPerformed 00739 //This is called when the Add Class Button is pressed 00740 00741 //See if there is a property containg the path of the last class file loaded 00742 File directory = config.containsKey(CLASS_PATH) ? new File(config.getProperty(CLASS_PATH)) : null; 00743 //Open a JFileChoose asking the user to choose a class file to add 00744 File file = BitStylus.chooseFile("Choose an algorithm to load", directory, new String[]{CLASS, "jar"}); 00745 Object o = (file != null) ? GraphConfig.newAlgorithm(file.getPath()) : null; //Load the object 00746 if (o != null) { 00747 config.setProperty(CLASS_PATH, file.getParent()); //Save the path of the class file that was loaded 00748 String path = file.getPath().endsWith(".jar") ? file.getPath() + "!" + o.getClass().getName() : file.getPath(); 00749 config.setProperty(CLASS + getNewKey(CLASS), path); 00750 updateFields(); 00751 classList.setSelectedIndex(classList.getItemCount() - 1); 00752 } 00753 }//GEN-LAST:event_addClassButtonActionPerformed 00754 00755 private void removeClassButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeClassButtonActionPerformed 00756 //This is called when the remove class button is called 00757 if (classList.getSelectedItem() == null) { 00758 return; 00759 } 00760 int index = Integer.parseInt(((String) classList.getSelectedItem()).split("-")[0].replace(CLASS, "")); 00761 00762 //see if any graphs depend on this class. If so, the class cannot be deleted 00763 for (GraphConfig graphCOnfig : graphConfigs) { 00764 if (graphCOnfig.getClassFile() != null) { 00765 if (graphCOnfig.getClassFile().getPath().equals(config.getProperty(CLASS + index))) { 00766 ChatterBox.alert("This class cannot be removed since it has graphs that depend on it."); 00767 return; 00768 } 00769 } 00770 } 00771 if (ChatterBox.yesNoDialog("Are you sure you want to remove " + classList.getSelectedItem() + "?")) { 00772 if (!config.remove(CLASS + index)) { 00773 ChatterBox.alert("The property was not removed!"); 00774 } 00775 classList.removeItemAt(classList.getSelectedIndex()); 00776 updateFields(); 00777 } 00778 }//GEN-LAST:event_removeClassButtonActionPerformed 00779 00780 private void choosePropertiesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choosePropertiesButtonActionPerformed 00781 //This is called when the Choose Properties button is pressed 00782 00783 //See if there is a property containing the path of the last properties file loaded 00784 File lastPath = config.containsKey(PROPERTY_PATH) ? new File(config.getProperty(PROPERTY_PATH)) : null; 00785 File propertyFile = BitStylus.chooseFile("Choose a properties file to load", lastPath, new String[]{"properties"}); 00786 if (propertyFile != null) { 00787 propertiesField.setText(propertyFile.getName()); 00788 config.setProperty(PROPERTY_PATH, propertyFile.getPath()); 00789 GraphConfig graphConfig = getSelectedGraph(); 00790 graphConfig.setProperties(propertyFile); 00791 config.setProperty(graphConfig.getKey(), graphConfig.toString()); 00792 } 00793 }//GEN-LAST:event_choosePropertiesButtonActionPerformed 00794 00795 private void removePropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePropertyButtonActionPerformed 00796 propertiesField.setText(""); 00797 getSelectedGraph().setProperties(null); 00798 }//GEN-LAST:event_removePropertyButtonActionPerformed 00799 00800 private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed 00801 String message = "To use this configuration window:\n\n" 00802 + "You must first add a class path to the algorithms combo box.\nClick the 'Add' Button next to it to do so.\n\n" 00803 + "Then you can add a graph to the simulator with the 'Add' Button below the 'Graph list'.\n" 00804 + "You can only add graphs that have had their class path added already.\n\n" 00805 + "You can then select an individual graphs from the list and change its' properties in the panel to the right.\n" 00806 + "The 'Listens to' combo box means that the currently selected graph's algorithm will listen to that graph"; 00807 ChatterBox.alert(message); 00808 }//GEN-LAST:event_helpButtonActionPerformed 00809 // Variables declaration - do not modify//GEN-BEGIN:variables 00810 private javax.swing.JButton addButton; 00811 private javax.swing.JButton addClassButton; 00812 private javax.swing.JButton applyButton; 00813 private javax.swing.JComboBox baseField; 00814 private javax.swing.JButton cancelButton; 00815 private javax.swing.JButton choosePropertiesButton; 00816 private javax.swing.JComboBox classList; 00817 private javax.swing.JCheckBox displayField; 00818 private javax.swing.JList graphList; 00819 private javax.swing.JPanel graphPanel; 00820 private javax.swing.JButton helpButton; 00821 private javax.swing.JPanel jPanel1; 00822 private javax.swing.JScrollPane jScrollPane1; 00823 private javax.swing.JButton loadButton; 00824 private javax.swing.JButton okButton; 00825 private javax.swing.JTextField pathField; 00826 private javax.swing.JTextField propertiesField; 00827 private javax.swing.JButton removeButton; 00828 private javax.swing.JButton removeClassButton; 00829 private javax.swing.JButton removePropertyButton; 00830 // End of variables declaration//GEN-END:variables 00831 } 00833