/** * Put a projection in the dialog for editing * * @param projClass projection class * @param proj projection */ private void putProjInDialog(ProjectionClass projClass, Projection proj) { // nameTF.setText (proj.getName().trim()); for (int i = 0; i < projClass.paramList.size(); i++) { ProjectionParam pp = (ProjectionParam) projClass.paramList.get(i); // fetch the value from the projection object Double value; try { if (debugBeans) { System.out.println("Projection putProjInDialog invoke reader on " + pp); } value = (Double) pp.reader.invoke(proj, VOIDOBJECTARG); if (debugBeans) { System.out.println("Projection putProjInDialog value " + value); } } catch (Exception ee) { System.err.println( "ProjectionManager: putProjInDialog failed " + " invoking read " + pp.name + " class " + projClass); continue; } String valstr = Format.d(value.doubleValue(), 5); pp.getTextField().setText(valstr); } }
/** * Set the projection from the dialog properties * * @param projClass projection class * @param proj projection */ private void setProjFromDialog(ProjectionClass projClass, ProjectionImpl proj) { proj.setName(nameTF.getText().trim()); for (int i = 0; i < projClass.paramList.size(); i++) { ProjectionParam pp = (ProjectionParam) projClass.paramList.get(i); // fetch the value from the projection object try { String valstr = pp.getTextField().getText(); Double valdub = new Double(valstr); Object[] args = {valdub}; if (debugBeans) { System.out.println("Projection setProjFromDialog invoke writer on " + pp); } pp.writer.invoke(proj, args); } catch (Exception ee) { System.err.println( "ProjectionManager: setProjParams failed " + " invoking write " + pp.name + " class " + projClass); continue; } } }
/** * Set the fields from the ProjectionClass * * @param projClass projection class to use */ private void setFieldsWithClassParams(ProjectionClass projClass) { // set the projection in the JComboBox String want = projClass.toString(); for (int i = 0; i < projClassCB.getItemCount(); i++) { ProjectionClass pc = (ProjectionClass) projClassCB.getItemAt(i); if (pc.toString().equals(want)) { projClassCB.setSelectedItem((Object) pc); break; } } // set the parameter fields paramPanel.removeAll(); paramPanel.setVisible(0 < projClass.paramList.size()); List widgets = new ArrayList(); for (int i = 0; i < projClass.paramList.size(); i++) { ProjectionParam pp = (ProjectionParam) projClass.paramList.get(i); // construct the label String name = pp.name; String text = ""; // Create a decent looking label for (int cIdx = 0; cIdx < name.length(); cIdx++) { char c = name.charAt(cIdx); if (cIdx == 0) { c = Character.toUpperCase(c); } else { if (Character.isUpperCase(c)) { text += " "; c = Character.toLowerCase(c); } } text += c; } widgets.add(GuiUtils.rLabel(text + ": ")); // text input field JTextField tf = new JTextField(); pp.setTextField(tf); tf.setColumns(12); widgets.add(tf); } GuiUtils.tmpInsets = new Insets(4, 4, 4, 4); JPanel widgetPanel = GuiUtils.doLayout(widgets, 2, GuiUtils.WT_N, GuiUtils.WT_N); paramPanel.add("North", widgetPanel); paramPanel.add("Center", GuiUtils.filler()); }