/** * 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); }
/** * _more_ * * @return _more_ */ private JComponent doMakeContents() { chartTop = new JPanel(new BorderLayout()); chartLeft = new JPanel(new BorderLayout()); JComponent chartComp = GuiUtils.leftCenter(chartLeft, GuiUtils.topCenter(chartTop, getChart().getContents())); return chartComp; }
/** * This method checks if the current server is valid. If it is valid then it checks if there is * authentication required * * @return true if the server exists and can be accessed */ protected boolean canAccessServer() { // Try reading the public.serv file to see if we need a username/proj JTextField projFld = null; JTextField userFld = null; JComponent contents = null; JLabel label = null; boolean firstTime = true; while (true) { int status = checkIfServerIsOk(); if (status == STATUS_OK) { break; } if (status == STATUS_ERROR) { setState(STATE_UNCONNECTED); return false; } if (projFld == null) { projFld = new JTextField("", 10); userFld = new JTextField("", 10); GuiUtils.tmpInsets = GuiUtils.INSETS_5; contents = GuiUtils.doLayout( new Component[] { GuiUtils.rLabel("User ID:"), userFld, GuiUtils.rLabel("Project #:"), projFld, }, 2, GuiUtils.WT_N, GuiUtils.WT_N); label = new JLabel(" "); contents = GuiUtils.topCenter(label, contents); contents = GuiUtils.inset(contents, 5); } String lbl = (firstTime ? "The server: " + getServer() + " requires a user ID & project number for access" : "Authentication for server: " + getServer() + " failed. Please try again"); label.setText(lbl); if (!GuiUtils.showOkCancelDialog(null, "ADDE Project/User name", contents, null)) { setState(STATE_UNCONNECTED); return false; } firstTime = false; String userName = userFld.getText().trim(); String project = projFld.getText().trim(); if ((userName.length() > 0) && (project.length() > 0)) { passwords.put(getServer(), new String[] {userName, project}); } } return true; }
/** Export a list of user selected projections */ public void doExport() { List projections = getProjections(); Vector<String> projectionNames = new Vector<>(projections.size()); for (int i = 0; i < projections.size(); i++) { ProjectionImpl projection = (ProjectionImpl) projections.get(i); projectionNames.add(projection.getName()); } JList<String> jlist = new JList<>(projectionNames); JPanel contents = GuiUtils.topCenter( GuiUtils.cLabel("Please select the projections you want to export"), GuiUtils.makeScrollPane(jlist, 200, 400)); if (!GuiUtils.showOkCancelDialog(null, "Export Projections", contents, null)) { return; } int[] indices = jlist.getSelectedIndices(); if ((indices == null) || (indices.length == 0)) { return; } List<ProjectionImpl> selected = new ArrayList<>(indices.length); for (int i = 0; i < indices.length; i++) { selected.add((ProjectionImpl) projections.get(indices[i])); } String xml = (new XmlEncoder()).toXml(selected); String filename = FileManager.getWriteFile(FileManager.FILTER_XML, FileManager.SUFFIX_XML); if (filename == null) { return; } try { IOUtil.writeFile(filename, xml); } catch (Exception exc) { LogUtil.logException("Writing projection file: " + filename, exc); } }
/** * Make the gui for the field selector * * @return gui for field selector */ protected JComponent doMakeContents() { GuiUtils.tmpInsets = GuiUtils.INSETS_5; comp = GuiUtils.doLayout(comps, 2, GuiUtils.WT_N, GuiUtils.WT_N); if (dataSelection != null) { Object prop; prop = dataSelection.getProperty(PROP_GRID_X); if (prop != null) { gridXFld.setText("" + prop); // If we have a data selection property then turn of cbx useDefaultCbx.setSelected(false); } prop = dataSelection.getProperty(PROP_GRID_Y); if (prop != null) { gridYFld.setText("" + prop); } prop = dataSelection.getProperty(PROP_GRID_UNIT); if (prop != null) { gridUnitCmbx.setSelectedItem(TwoFacedObject.findId(prop, tfos)); } prop = dataSelection.getProperty(PROP_GRID_NUMPASSES); if (prop != null) { numGridPassesFld.setText("" + prop); } prop = dataSelection.getProperty(PROP_GRID_GAIN); if (prop != null) { gainComp.setValue(((Number) prop).floatValue()); } prop = dataSelection.getProperty(PROP_GRID_SEARCH_RADIUS); if (prop != null) { searchComp.setValue(((Number) prop).floatValue()); } } checkEnable(); return GuiUtils.topCenter(GuiUtils.right(useDefaultCbx), GuiUtils.topLeft(comp)); }
/** Just creates an empty XmlTree */ private void makeXmlTree() { if (imageDefaults == null) { imageDefaults = getImageDefaults(); } xmlTree = new XmlTree(imageDefaultsRoot, true, "") { public void doClick(XmlTree theTree, XmlTree.XmlTreeNode node, Element element) { Element clicked = xmlTree.getSelectedElement(); String lastTag = clicked.getTagName(); if ("folder".equals(lastTag)) { lastCat = clicked; lastClicked = null; setStatus("Please enter a name for the new parameter set"); newSetBtn.setEnabled(true); } else { lastCat = clicked.getParentNode(); lastClicked = clicked; } } public void doRightClick( XmlTree theTree, XmlTree.XmlTreeNode node, Element element, MouseEvent event) { JPopupMenu popup = new JPopupMenu(); if (makePopupMenu(theTree, element, popup)) { popup.show((Component) event.getSource(), event.getX(), event.getY()); } } }; List tagList = new ArrayList(); tagList.add(TAG_FOLDER); tagList.add(TAG_DEFAULT); xmlTree.addTagsToProcess(tagList); xmlTree.defineLabelAttr(TAG_FOLDER, ATTR_NAME); addToContents(GuiUtils.inset(GuiUtils.topCenter(new JPanel(), xmlTree.getScroller()), 5)); return; }
/** Just creates an empty XmlTree */ private void makeBlankTree() { XmlTree blankTree = new XmlTree(null, true, ""); addToContents(GuiUtils.inset(GuiUtils.topCenter(new JPanel(), blankTree.getScroller()), 5)); }
/** * Create a new ProjectionManager. * * @param parent JFrame (application) or JApplet (applet) * @param projections list of initial projections * @param makeDialog true to make this a dialog * @param helpId help id if dialog * @param maps List of MapData */ public ProjectionManager( RootPaneContainer parent, List projections, boolean makeDialog, String helpId, List maps) { this.helpId = helpId; this.maps = maps; this.parent = parent; // manage NewProjectionListeners lm = new ListenerManager( "java.beans.PropertyChangeListener", "java.beans.PropertyChangeEvent", "propertyChange"); // here's where the map will be drawn: but cant be changed/edited npViewControl = new NPController(); if (maps == null) { maps = getDefaultMaps(); // we use the system default } for (int mapIdx = 0; mapIdx < maps.size(); mapIdx++) { MapData mapData = (MapData) maps.get(mapIdx); if (mapData.getVisible()) { npViewControl.addMap(mapData.getSource(), mapData.getColor()); } } mapViewPanel = npViewControl.getNavigatedPanel(); mapViewPanel.setPreferredSize(new Dimension(250, 250)); mapViewPanel.setToolTipText("Shows the default zoom of the current projection"); mapViewPanel.setChangeable(false); if ((projections == null) || (projections.size() == 0)) { projections = makeDefaultProjections(); } // the actual list is a JTable subclass projTable = new JTableProjection(this, projections); JComponent listContents = new JScrollPane(projTable); JComponent buttons = GuiUtils.hbox( GuiUtils.makeButton("Edit", this, "doEdit"), GuiUtils.makeButton("New", this, "doNew"), GuiUtils.makeButton("Export", this, "doExport"), GuiUtils.makeButton("Delete", this, "doDelete")); mapLabel = new JLabel(" "); JComponent leftPanel = GuiUtils.inset(GuiUtils.topCenter(mapLabel, mapViewPanel), 5); JComponent rightPanel = GuiUtils.topCenter(buttons, listContents); rightPanel = GuiUtils.inset(rightPanel, 5); contents = GuiUtils.inset(GuiUtils.hbox(leftPanel, rightPanel), 5); // default current and working projection if (null != (current = projTable.getSelected())) { setWorkingProjection(current); projTable.setCurrentProjection(current); mapLabel.setText(current.getName()); } /* listen for new working Projections from projTable */ projTable.addNewProjectionListener( new NewProjectionListener() { public void actionPerformed(NewProjectionEvent e) { if (e.getProjection() != null) { setWorkingProjection(e.getProjection()); } } }); eventsOK = true; // put it together in the viewDialog if (makeDialog) { Container buttPanel = GuiUtils.makeApplyOkHelpCancelButtons(this); contents = GuiUtils.centerBottom(contents, buttPanel); viewDialog = GuiUtils.createDialog(GuiUtils.getApplicationTitle() + "Projection Manager", false); viewDialog.getContentPane().add(contents); viewDialog.pack(); ucar.unidata.util.Msg.translateTree(viewDialog); viewDialog.setLocation(100, 100); } }
/** * Create me * * @param persistenceManager A reference to the persistence manager in case we need it * @param label The label to use in the dialog title */ public LoadBundleDialog(IdvPersistenceManager persistenceManager, String label) { dialogTitle = label; label = null; this.persistenceManager = persistenceManager; msgLabel1 = new JLabel(" "); msgLabel1.setMinimumSize(new Dimension(250, 20)); msgLabel1.setPreferredSize(new Dimension(250, 20)); msgLabel2 = new JLabel(" "); msgLabel2.setMinimumSize(new Dimension(250, 20)); msgLabel2.setPreferredSize(new Dimension(250, 20)); progressBar = new RovingProgress(); progressBar.start(); progressBar.setBorder(BorderFactory.createLineBorder(Color.gray)); JLabel waitLbl = new JLabel(IdvWindow.getWaitIcon()); ActionListener buttonListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { removeItems = true; // removeItems = ae.getActionCommand().equals(CMD_CANCELANDREMOVE); okToRun = false; setMessage("Cancelling load. Please wait..."); Misc.runInABit( 2000, new Runnable() { public void run() { dispose(); } }); } }; // String[] cmds = { CMD_CANCELANDREMOVE, GuiUtils.CMD_CANCEL }; String[] cmds = {GuiUtils.CMD_CANCEL}; // String[] tts = { "Press to cancel and remove any loaded items", // "Press to cancel" }; String[] tts = {"Press to cancel and remove loaded items"}; JPanel buttonPanel = GuiUtils.makeButtons(buttonListener, cmds, cmds, tts, null); GuiUtils.tmpInsets = GuiUtils.INSETS_2; JComponent labelComp = GuiUtils.doLayout( new Component[] { new JLabel("Status:"), msgLabel1, waitLbl, GuiUtils.filler(), msgLabel2, GuiUtils.filler() }, 3, GuiUtils.WT_NYN, GuiUtils.WT_N); contents = GuiUtils.inset(labelComp, 5); if (label != null) { contents = GuiUtils.topCenter(GuiUtils.cLabel("Loading: " + label), contents); } // contents = GuiUtils.vbox(contents, // GuiUtils.inset(progressBar, 5), // buttonPanel); contents = GuiUtils.vbox(contents, buttonPanel); }
/** * Edit row * * @param paramInfo param info * @param removeOnCancel Should remove param info if user presses cancel_ * @return ok */ public boolean editRow(ParamInfo paramInfo, boolean removeOnCancel) { List comps = new ArrayList(); ParamField nameFld = new ParamField(null, true); nameFld.setText(paramInfo.getName()); JPanel topPanel = GuiUtils.hbox(GuiUtils.lLabel("Parameter: "), nameFld); topPanel = GuiUtils.inset(topPanel, 5); comps.add(GuiUtils.inset(new JLabel("Defined"), new Insets(5, 0, 0, 0))); comps.add(GuiUtils.filler()); comps.add(GuiUtils.filler()); final JLabel ctPreviewLbl = new JLabel(""); final JLabel ctLbl = new JLabel(""); if (paramInfo.hasColorTableName()) { ctLbl.setText(paramInfo.getColorTableName()); ColorTable ct = getIdv().getColorTableManager().getColorTable(paramInfo.getColorTableName()); if (ct != null) { ctPreviewLbl.setIcon(ColorTableCanvas.getIcon(ct)); } else { ctPreviewLbl.setIcon(null); } } String cbxLabel = ""; final ArrayList menus = new ArrayList(); getIdv() .getColorTableManager() .makeColorTableMenu( new ObjectListener(null) { public void actionPerformed(ActionEvent ae, Object data) { ctLbl.setText(data.toString()); ColorTable ct = getIdv().getColorTableManager().getColorTable(ctLbl.getText()); if (ct != null) { ctPreviewLbl.setIcon(ColorTableCanvas.getIcon(ct)); } else { ctPreviewLbl.setIcon(null); } } }, menus); JCheckBox ctUseCbx = new JCheckBox(cbxLabel, paramInfo.hasColorTableName()); final JButton ctPopup = new JButton("Change"); ctPopup.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { GuiUtils.showPopupMenu(menus, ctPopup); } }); addEditComponents( comps, "Color Table:", ctUseCbx, GuiUtils.hbox(ctPopup, GuiUtils.vbox(ctLbl, ctPreviewLbl), 5)); JCheckBox rangeUseCbx = new JCheckBox(cbxLabel, paramInfo.hasRange()); JTextField minFld = new JTextField("" + paramInfo.getMin(), 4); JTextField maxFld = new JTextField("" + paramInfo.getMax(), 4); JPanel rangePanel = GuiUtils.hbox(minFld, maxFld, 5); addEditComponents(comps, "Range:", rangeUseCbx, rangePanel); JCheckBox unitUseCbx = new JCheckBox(cbxLabel, paramInfo.hasDisplayUnit()); String unitLabel = ""; Unit unit = null; if (paramInfo.hasDisplayUnit()) { unit = paramInfo.getDisplayUnit(); } JComboBox unitFld = getIdv().getDisplayConventions().makeUnitBox(unit, null); // JTextField unitFld = new JTextField(unitLabel, 15); addEditComponents(comps, "Unit:", unitUseCbx, unitFld); ContourInfo ci = paramInfo.getContourInfo(); JCheckBox contourUseCbx = new JCheckBox(cbxLabel, ci != null); if (ci == null) { ci = new ContourInfo(); } ContourInfoDialog contDialog = new ContourInfoDialog("Edit Contour Defaults", false, null, false); contDialog.setState(ci); addEditComponents(comps, "Contour:", contourUseCbx, contDialog.getContents()); GuiUtils.tmpInsets = new Insets(5, 5, 5, 5); JComponent contents = GuiUtils.doLayout(comps, 3, GuiUtils.WT_NNY, GuiUtils.WT_N); contents = GuiUtils.topCenter(topPanel, contents); contents = GuiUtils.inset(contents, 5); while (true) { if (!GuiUtils.showOkCancelDialog(null, "Parameter Defaults", contents, null)) { if (removeOnCancel) { myParamInfos.remove(paramInfo); tableChanged(); } return false; } String what = ""; try { if (contourUseCbx.isSelected()) { what = "setting contour defaults"; contDialog.doApply(); ci.set(contDialog.getInfo()); paramInfo.setContourInfo(ci); } else { paramInfo.clearContourInfo(); } if (unitUseCbx.isSelected()) { what = "setting display unit"; Object selected = unitFld.getSelectedItem(); String unitName = TwoFacedObject.getIdString(selected); if ((unitName == null) || unitName.trim().equals("")) { paramInfo.setDisplayUnit(null); } else { paramInfo.setDisplayUnit(ucar.visad.Util.parseUnit(unitName)); } } else { paramInfo.setDisplayUnit(null); } if (ctUseCbx.isSelected()) { paramInfo.setColorTableName(ctLbl.getText()); } else { paramInfo.clearColorTableName(); } if (rangeUseCbx.isSelected()) { what = "setting range"; paramInfo.setRange( new Range(Misc.parseNumber(minFld.getText()), Misc.parseNumber(maxFld.getText()))); } else { paramInfo.clearRange(); } paramInfo.setName(nameFld.getText().trim()); break; } catch (Exception exc) { errorMsg("An error occurred " + what + "\n " + exc.getMessage()); // exc.printStackTrace(); } } repaint(); saveData(); return true; }
private void showSaveDialog() { if (saveWindow == null) { saveWindow = GuiUtils.createFrame("Save Image Parameter Set"); } if (statusComp == null) { statusLabel = new JLabel(); statusComp = GuiUtils.inset(statusLabel, 2); statusComp.setBackground(new Color(255, 255, 204)); statusLabel.setOpaque(true); statusLabel.setBackground(new Color(255, 255, 204)); } JPanel statusPanel = GuiUtils.inset( GuiUtils.top( GuiUtils.vbox( new JLabel(" "), GuiUtils.hbox(GuiUtils.rLabel("Status: "), statusComp), new JLabel(" "))), 6); JPanel sPanel = GuiUtils.topCenter(statusPanel, GuiUtils.filler()); List newComps = new ArrayList(); final JTextField newName = new JTextField(20); newName.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { setStatus("Click New Folder or New ParameterSet button"); newCompName = newName.getText().trim(); } }); newComps.add(newName); newComps.add(GuiUtils.filler()); newFolderBtn = new JButton("New Folder"); newFolderBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { newFolder = newName.getText().trim(); if (newFolder.length() == 0) { newComponentError("folder"); return; } Element exists = XmlUtil.findElement(imageDefaultsRoot, "folder", ATTR_NAME, newFolder); if (!(exists == null)) { if (!GuiUtils.askYesNo( "Verify Replace Folder", "Do you want to replace the folder " + "\"" + newFolder + "\"?" + "\nNOTE: All parameter sets it contains will be deleted.")) return; imageDefaultsRoot.removeChild(exists); } newName.setText(""); Node newEle = makeNewFolder(); makeXmlTree(); xmlTree.selectElement((Element) newEle); lastCat = newEle; lastClicked = null; newSetBtn.setEnabled(true); setStatus("Please enter a name for the new parameter set"); } }); newComps.add(newFolderBtn); newComps.add(GuiUtils.filler()); newName.setEnabled(true); newFolderBtn.setEnabled(true); newSetBtn = new JButton("New Parameter Set"); newSetBtn.setActionCommand(CMD_NEWPARASET); newSetBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { newCompName = newName.getText().trim(); if (newCompName.length() == 0) { newComponentError("parameter set"); return; } newName.setText(""); Element newEle = saveParameterSet(); if (newEle == null) return; xmlTree.selectElement(newEle); lastClicked = newEle; } }); newComps.add(newSetBtn); newSetBtn.setEnabled(false); JPanel newPanel = GuiUtils.top(GuiUtils.left(GuiUtils.hbox(newComps))); JPanel topPanel = GuiUtils.topCenter(sPanel, newPanel); treePanel = new JPanel(); treePanel.setLayout(new BorderLayout()); makeXmlTree(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { String cmd = event.getActionCommand(); if (cmd.equals(GuiUtils.CMD_CANCEL)) { if (lastClicked != null) { removeNode(lastClicked); lastClicked = null; } saveWindow.setVisible(false); saveWindow = null; } else { saveWindow.setVisible(false); saveWindow = null; } } }; JPanel bottom = GuiUtils.inset(GuiUtils.makeApplyCancelButtons(listener), 5); contents = GuiUtils.topCenterBottom(topPanel, treePanel, bottom); saveWindow.getContentPane().add(contents); saveWindow.pack(); saveWindow.setLocation(200, 200); saveWindow.setVisible(true); GuiUtils.toFront(saveWindow); setStatus("Please select a folder from tree, or create a new folder"); }