/** * Load in the {@link ucar.unidata.idv.ui.ParamInfo}-s defined in the xml from the given root * Element. Create a new JTable and add it into the GUI. * * @param root The xml root * @param i Which resource is this */ private void addList(Element root, int i) { List infos; boolean isWritable = resources.isWritableResource(i); if (root != null) { infos = createParamInfoList(root); } else { if (!isWritable) { return; } infos = new ArrayList(); } if (infos.size() == 0) { // infos.add(new ParamInfo("", null, null, null, null)); } ParamDefaultsTable table = new ParamDefaultsTable(infos, isWritable); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); String editableStr = ""; if (!isWritable) { editableStr = " (" + Msg.msg("non-editable") + ") "; } JLabel label = new JLabel( "<html>" + Msg.msg("Path: ${param1}", resources.get(i) + editableStr) + "</html>"); JPanel tablePanel = GuiUtils.topCenter(GuiUtils.inset(label, 4), new JScrollPane(table)); table.label = resources.getShortName(i); tableTabbedPane.add(resources.getShortName(i), tablePanel); myTables.add(table); }
/** * Copy the given ParamInfo object into the user's editable table * * @param i the param fino object to copy */ protected void copyToUsers(ParamInfo i) { ParamInfo copy = new ParamInfo(i); ParamDefaultsTable to = (ParamDefaultsTable) myTables.get(0); to.add(copy); tableTabbedPane.setSelectedIndex(0); to.editRow(copy, true); }
/** Export allthe param infos to the plugin manager */ public void exportToPlugin() { ParamDefaultsTable table = getCurrentTable(); List list = table.getParamInfoList(); if (list.size() == 0) { LogUtil.userMessage("No rows selected"); return; } getIdv().getPluginManager().addObject(list); }
/** * Get the list of resources * * @return the list of resources */ public List getResources() { List infos = new ArrayList(); for (int i = 0; i < myTables.size(); i++) { ParamDefaultsTable paramDefaultsTable = (ParamDefaultsTable) myTables.get(i); for (ParamInfo paramInfo : (List<ParamInfo>) paramDefaultsTable.getParamInfoList()) { infos.add( new ResourceViewer.ResourceWrapper( paramInfo, paramInfo.toString(), paramDefaultsTable.label, paramDefaultsTable.isEditable)); } } return infos; }
/** Import an xml param defaults file */ public void doImport() { try { String filename = FileManager.getReadFile(FileManager.FILTER_XML); if (filename == null) { return; } Element root = XmlUtil.getRoot(IOUtil.readContents(filename)); if (root == null) { return; } List infos = createParamInfoList(root); ParamDefaultsTable table = getCurrentTable(); table.getParamInfoList().addAll(infos); table.tableChanged(); saveData(); } catch (Exception exc) { LogUtil.printException(log_, "Error importing file", exc); } }
/** * Get the color table, range, etc, from the given display control and save them as the param * defaults for its data choice * * @param displayControl the display control to get state from */ public void saveDefaults(DisplayControlImpl displayControl) { try { List choices = displayControl.getMyDataChoices(); if (choices.size() != 1) { return; } DataChoice dc = (DataChoice) choices.get(0); String name = dc.getName(); String ctName = ((displayControl.getColorTable() != null) ? displayControl.getColorTable().getName() : null); ParamInfo newParamInfo = new ParamInfo( name, ctName, displayControl.getRange(), displayControl.getContourInfo(), displayControl.getDisplayUnit()); ParamDefaultsTable firstTable = getFirstTable(); if (!firstTable.editRow(newParamInfo, false)) { return; } ParamInfo origParamInfo = firstTable.findByName(dc.getName()); if (origParamInfo == null) { firstTable.addBeginning(newParamInfo); firstTable.getSelectionModel().setSelectionInterval(0, 0); } else { origParamInfo.initWith(newParamInfo); firstTable.tableChanged(); firstTable.selectParamInfo(origParamInfo); } saveData(); show(); GuiUtils.showComponentInTabs(firstTable); } catch (Exception exc) { LogUtil.printException(log_, "copying defaults", exc); } }