private void makeActionsToolbars() { navToolbarAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { Boolean state = (Boolean) getValue(BAMutil.STATE); if (state.booleanValue()) toolPanel.add(navToolbar); else toolPanel.remove(navToolbar); } }; BAMutil.setActionProperties( navToolbarAction, "MagnifyPlus", "show Navigate toolbar", true, 'M', 0); navToolbarAction.putValue( BAMutil.STATE, new Boolean(store.getBoolean("navToolbarAction", true))); moveToolbarAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { Boolean state = (Boolean) getValue(BAMutil.STATE); if (state.booleanValue()) toolPanel.add(moveToolbar); else toolPanel.remove(moveToolbar); } }; BAMutil.setActionProperties(moveToolbarAction, "Up", "show Move toolbar", true, 'M', 0); moveToolbarAction.putValue( BAMutil.STATE, new Boolean(store.getBoolean("moveToolbarAction", true))); }
public CloseOperationState canCloseElement() { // if this is not the last cloned xml editor component, closing is OK if (!mDataObject.getEditorSupport().isModified() || !CasaDataEditorSupport.isLastView(multiViewObserver.getTopComponent())) { return CloseOperationState.STATE_OK; } AbstractAction save = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { // save changes try { mDataObject.getEditorSupport().saveDocument(); mDataObject.setModified(false); } catch (IOException ex) { } } }; save.putValue( Action.LONG_DESCRIPTION, NbBundle.getMessage( DataObject.class, "MSG_SaveFile", // NOI18N mDataObject.getPrimaryFile().getNameExt())); return MultiViewFactory.createUnsafeCloseState( "ID_CASA_CLOSING", // NOI18N save, MultiViewFactory.NOOP_CLOSE_ACTION); // return a placeholder state - to be sure our CloseHandler is called /*return MultiViewFactory.createUnsafeCloseState( "ID_TEXT_CLOSING", // dummy ID // NOI18N MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION);*/ }
@Override @NotNull protected Action[] createActions() { final AbstractAction checkNowAction = new AbstractAction("Check Now") { @Override public void actionPerformed(@Nullable ActionEvent e) { ProgressManager.getInstance() .run( new Task.Modal(null, "Checking plugins repository...", true) { boolean result; Exception ex; @Override public void run(@NotNull ProgressIndicator indicator) { try { result = UpdateChecker.checkPluginsHost( correctRepositoryRule(getTextField().getText()), new THashMap<PluginId, PluginDownloader>(), true, indicator); } catch (Exception e1) { ex = e1; } } @Override public void onSuccess() { if (ex != null) { showErrorDialog(myField, "Connection failed: " + ex.getMessage()); } else if (result) { showInfoMessage( myField, "Plugins repository was successfully checked", "Check Plugins Repository"); } else { showErrorDialog( myField, "Plugin descriptions contain some errors. Please, check idea.log for details."); } } }); } }; myField .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { checkNowAction.setEnabled(!StringUtil.isEmptyOrSpaces(myField.getText())); } }); checkNowAction.setEnabled(!StringUtil.isEmptyOrSpaces(myField.getText())); return ArrayUtil.append(super.createActions(), checkNowAction); }
/** Invokes the request on a remote object using an outbound XML stream. */ public Object invoke(Method method, String url, Object[] args, HandlerChainInvoker handlerChain) throws IOException, XMLStreamException, MalformedURLException, JAXBException, Throwable { AbstractAction action = _actionMethods.get(method); if (action != null) return action.invoke(url, args, handlerChain); else if ("toString".equals(method.getName())) return "SoapStub[" + (_api != null ? _api.getName() : "") + "]"; else throw new RuntimeException(L.l("not a web method: {0}", method.getName())); }
private void initParameters() { super.putValue(Action.NAME, "Generar Aproximación lineal"); // ImageIcon imageIcon = new ImageIcon( // new ImageIcon("icons/integrate-icon.png").getImage().getScaledInstance(30, 30, // Image.SCALE_SMOOTH)); // Image smallIcon = imageIcon.getImage().getScaledInstance(25, 25, Image.SCALE_SMOOTH); // super.putValue(Action.SMALL_ICON, new ImageIcon(smallIcon)); // super.putValue(Action.LARGE_ICON_KEY, imageIcon); super.putValue( Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK)); super.putValue( Action.SHORT_DESCRIPTION, "Genera una aproximación lineal para los puntos dados"); }
// set all menu items related to debugging enabled, all else disabled; // for insert, remove and fetch: continue, step // additionally for scripts: next and sometimes cancel private void enableDebug(boolean isScript, boolean enableCancel) { setAllEnabled(false); debugMenu.setEnabled(true); stepAction.setEnabled(true); cancelAction.setEnabled(enableCancel); nextAction.setEnabled(isScript); contAction.setEnabled(true); breakpointsItem.setEnabled(true); treeStatsMenu.setEnabled(true); utilItem.setEnabled(true); predSzItem.setEnabled(true); slotCntItem.setEnabled(true); }
/** @param move For add: if true, remove from all previous groups */ private AbstractAction getAction( GroupTreeNode node, BibtexEntry[] selection, boolean add, boolean move) { AbstractAction action = add ? new AddToGroupAction(node, move, panel) : new RemoveFromGroupAction(node, panel); AbstractGroup group = node.getGroup(); if (!move) { action.setEnabled( add ? group.supportsAdd() && !group.containsAll(selection) : group.supportsRemove() && group.containsAny(selection)); } else { action.setEnabled(group.supportsAdd()); } return action; }
public void writeSchema(XMLStreamWriter out) throws XMLStreamException, JAXBException { out.writeStartElement("xsd", "schema", W3C_XML_SCHEMA_NS_URI); out.writeAttribute("version", "1.0"); out.writeAttribute("targetNamespace", _namespace); out.writeNamespace(TARGET_NAMESPACE_PREFIX, _namespace); _context.generateSchemaWithoutHeader(out); for (AbstractAction action : _actionNames.values()) action.writeSchema(out, _namespace, _context); out.writeEndElement(); // schema out.flush(); }
// enable all menu items/menus for operations that require // a Gist to work on, excluding the debugging functions private void enableIndexOpened() { DbgOutput.println(1, "enableIndexOpened()"); setAllEnabled(true); // debugging operations only during operations stepAction.setEnabled(false); stopAction.setEnabled(false); cancelAction.setEnabled(false); nextAction.setEnabled(false); contAction.setEnabled(false); // no profile opened completeAnalysisItem.setEnabled(false); wkldStatsItem.setEnabled(false); splitStatsItem.setEnabled(false); penaltyStatsItem.setEnabled(false); }
// enable/disable all menu items/actions private void setAllEnabled(boolean enabled) { DbgOutput.println(2, "enabled: " + enabled); fileMenu.setEnabled(enabled); newItem.setEnabled(enabled); openItem.setEnabled(enabled); closeItem.setEnabled(enabled); // dumpItem.setEnabled(enabled); flushItem.setEnabled(enabled); optionsItem.setEnabled(enabled); settingsItem.setEnabled(enabled); debugMenu.setEnabled(enabled); stepAction.setEnabled(enabled); stopAction.setEnabled(enabled); cancelAction.setEnabled(enabled); nextAction.setEnabled(enabled); contAction.setEnabled(enabled); breakpointsItem.setEnabled(enabled); opsMenu.setEnabled(enabled); insertItem.setEnabled(enabled); deleteItem.setEnabled(enabled); searchItem.setEnabled(enabled); executeItem.setEnabled(enabled); treeStatsMenu.setEnabled(enabled); utilItem.setEnabled(enabled); predSzItem.setEnabled(enabled); slotCntItem.setEnabled(enabled); analysisMenu.setEnabled(enabled); newAnalysisItem.setEnabled(enabled); openAnalysisItem.setEnabled(enabled); completeAnalysisItem.setEnabled(enabled); wkldStatsItem.setEnabled(enabled); splitStatsItem.setEnabled(enabled); penaltyStatsItem.setEnabled(enabled); // these are never disabled windowsMenu.setEnabled(true); showCmdsItem.setEnabled(true); showResultsItem.setEnabled(true); showTraceItem.setEnabled(true); tileItem.setEnabled(true); }
/** save all data in the PersistentStore */ public void storePersistentData() { store.putInt("vertSplit", splitDraw.getDividerLocation()); store.putBoolean( "navToolbarAction", ((Boolean) navToolbarAction.getValue(BAMutil.STATE)).booleanValue()); store.putBoolean( "moveToolbarAction", ((Boolean) moveToolbarAction.getValue(BAMutil.STATE)).booleanValue()); if (projManager != null) projManager.storePersistentData(); /* if (csManager != null) csManager.storePersistentData(); if (sysConfigDialog != null) sysConfigDialog.storePersistentData(); */ dsTable.save(); dsTable.getPrefs().putBeanObject("DialogBounds", dsDialog.getBounds()); store.put(GEOTIFF_FILECHOOSER_DEFAULTDIR, geotiffFileChooser.getCurrentDirectory()); controller.storePersistentData(); }
/** @param move For add: if true, remove from previous groups */ private void insertNodes( JMenu menu, GroupTreeNode node, BibtexEntry[] selection, boolean add, boolean move) { final AbstractAction action = getAction(node, selection, add, move); if (node.getChildCount() == 0) { JMenuItem menuItem = new JMenuItem(action); setGroupFontAndIcon(menuItem, node.getGroup()); menu.add(menuItem); if (action.isEnabled()) { menu.setEnabled(true); } return; } JMenu submenu; if (node.getGroup() instanceof AllEntriesGroup) { for (int i = 0; i < node.getChildCount(); ++i) { insertNodes(menu, (GroupTreeNode) node.getChildAt(i), selection, add, move); } } else { submenu = new JMenu('[' + node.getGroup().getName() + ']'); setGroupFontAndIcon(submenu, node.getGroup()); // setEnabled(true) is done above/below if at least one menu // entry (item or submenu) is enabled submenu.setEnabled(action.isEnabled()); JMenuItem menuItem = new JMenuItem(action); setGroupFontAndIcon(menuItem, node.getGroup()); submenu.add(menuItem); submenu.add(new Separator()); for (int i = 0; i < node.getChildCount(); ++i) { insertNodes(submenu, (GroupTreeNode) node.getChildAt(i), selection, add, move); } menu.add(submenu); if (submenu.isEnabled()) { menu.setEnabled(true); } } }
public void putValue(String key, Object newValue) { super.putValue(key, newValue); if (key == Actions.SELECTED_KEY) { if (palette != null) { AbstractOSXApplication application = getApplication(); boolean b = (Boolean) newValue; if (b) { application.addPalette(palette); palette.setVisible(true); } else { application.removePalette(palette); palette.setVisible(false); } } } }
/** * Avalia a condição <code>boolean</code> para processar ou não a ação. * * @throws <code>IllegalArgumentException</code> caso não tenha ação e/ou condição <code>boolean * </code> vinculada. */ @Override protected void action() { if (action == null) { throw new IllegalArgumentException( "Indique a Ação que deve ser executada, utilize o método addAction."); } if (expression == null) { throw new IllegalArgumentException( "Indique a expressão condicional da Ação, utilize o método addConditional."); } if (expression.conditional()) { action.actionPerformed(); } }
void setSelected(boolean b) { selected = b; showGridTableAction.setEnabled(b); showNcMLAction.setEnabled(b); showNcMLAction.setEnabled(b); showNetcdfDatasetAction.setEnabled(b); showGridDatasetInfoAction.setEnabled(b); // showNetcdfXMLAction.setEnabled( b); navToolbarAction.setEnabled(b); moveToolbarAction.setEnabled(b); controller.showGridAction.setEnabled(b); controller.showContoursAction.setEnabled(b); controller.showContourLabelsAction.setEnabled(b); redrawAction.setEnabled(b); minmaxHorizAction.setEnabled(b); minmaxLogAction.setEnabled(b); minmaxHoldAction.setEnabled(b); fieldLoopAction.setEnabled(b); levelLoopAction.setEnabled(b); timeLoopAction.setEnabled(b); panz.setEnabledActions(b); }
/** * To be accurate, all of the actions must have been added before this method is run for the first * time. */ public void generateWSDL() throws IOException, XMLStreamException, JAXBException { if (_wsdlGenerated) return; // We write to DOM so that we can pretty print it. Since this only // happens once, it's not too much of a burden. DOMResult result = new DOMResult(); XMLOutputFactory factory = getXMLOutputFactory(); XMLStreamWriter out = factory.createXMLStreamWriter(result); out.writeStartDocument("UTF-8", "1.0"); // <definitions> out.setDefaultNamespace(WSDL_NAMESPACE); out.writeStartElement(WSDL_NAMESPACE, "definitions"); out.writeAttribute("targetNamespace", _namespace); out.writeAttribute("name", _serviceName); out.writeNamespace(TARGET_NAMESPACE_PREFIX, _namespace); out.writeNamespace("soap", _soapNamespaceURI); // <types> out.writeStartElement(WSDL_NAMESPACE, "types"); if (_separateSchema) { out.writeStartElement(W3C_XML_SCHEMA_NS_URI, "schema"); out.writeEmptyElement(W3C_XML_SCHEMA_NS_URI, "import"); out.writeAttribute("namespace", _namespace); out.writeAttribute("schemaLocation", _serviceName + "_schema1.xsd"); out.writeEndElement(); // schema } else writeSchema(out); out.writeEndElement(); // types // <messages> for (AbstractAction action : _actionNames.values()) action.writeWSDLMessages(out, _soapNamespaceURI); // <portType> out.writeStartElement(WSDL_NAMESPACE, "portType"); out.writeAttribute("name", _portType); for (AbstractAction action : _actionNames.values()) action.writeWSDLOperation(out, _soapNamespaceURI); out.writeEndElement(); // portType // <binding> out.writeStartElement(WSDL_NAMESPACE, "binding"); out.writeAttribute("name", _portName + "Binding"); out.writeAttribute("type", TARGET_NAMESPACE_PREFIX + ':' + _portType); out.writeEmptyElement(_soapNamespaceURI, "binding"); out.writeAttribute("transport", _soapTransport); out.writeAttribute("style", _soapStyle); for (AbstractAction action : _actionNames.values()) action.writeWSDLBindingOperation(out, _soapNamespaceURI); out.writeEndElement(); // binding // <service> out.writeStartElement(WSDL_NAMESPACE, "service"); out.writeAttribute("name", _serviceName); out.writeStartElement(WSDL_NAMESPACE, "port"); out.writeAttribute("name", _portName); out.writeAttribute("binding", TARGET_NAMESPACE_PREFIX + ':' + _portName + "Binding"); out.writeEmptyElement(_soapNamespaceURI, "address"); out.writeAttribute("location", _wsdlLocation); out.writeEndElement(); // port out.writeEndElement(); // service out.writeEndElement(); // definitions _wsdlBuffer = new CharArrayWriter(); XmlPrinter printer = new XmlPrinter(_wsdlBuffer); printer.setPrintDeclaration(true); printer.setStandalone("true"); printer.printPrettyXml(result.getNode()); _wsdlGenerated = true; }
private int invoke( Object service, XMLStreamReader in, XMLStreamWriter out, List<Attachment> attachments) throws IOException, XMLStreamException, Throwable { in.nextTag(); // XXX Namespace in.require(XMLStreamReader.START_ELEMENT, null, "Envelope"); in.nextTag(); XMLStreamReader header = null; if ("Header".equals(in.getName().getLocalPart())) { in.nextTag(); XMLOutputFactory outputFactory = getXMLOutputFactory(); CharArrayWriter writer = new CharArrayWriter(); StreamResult result = new StreamResult(writer); XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(result); StaxUtil.copyReaderToWriter(in, xmlWriter); CharArrayReader reader = new CharArrayReader(writer.toCharArray()); XMLInputFactory inputFactory = getXMLInputFactory(); header = inputFactory.createXMLStreamReader(reader); in.nextTag(); } // XXX Namespace? in.require(XMLStreamReader.START_ELEMENT, null, "Body"); in.nextTag(); String actionName = in.getName().getLocalPart(); // services/1318: special corner case where no method name is given // May happen with Document BARE methods w/no arguments if ("Body".equals(actionName) && in.getEventType() == in.END_ELEMENT) actionName = ""; out.writeStartDocument("UTF-8", "1.0"); out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Envelope", SOAP_ENVELOPE); out.writeNamespace(SOAP_ENVELOPE_PREFIX, SOAP_ENVELOPE); // out.writeNamespace("xsi", XMLNS_XSI); out.writeNamespace("xsd", XMLNS_XSD); AbstractAction action = _actionNames.get(actionName); // XXX: exceptions<->faults int responseCode = 500; if (action != null) responseCode = action.invoke(service, header, in, out, attachments); else { // skip the unknown action while (in.getEventType() != in.END_ELEMENT || !"Body".equals(in.getName().getLocalPart())) in.nextTag(); writeClientFault(out); } // XXX Namespace? in.require(XMLStreamReader.END_ELEMENT, null, "Body"); in.nextTag(); in.require(XMLStreamReader.END_ELEMENT, null, "Envelope"); out.writeEndElement(); // Envelope out.flush(); return responseCode; }
public void addAction(Method method, AbstractAction action) { if (log.isLoggable(Level.FINER)) log.finer("Adding " + action + " to " + this); _actionNames.put(action.getInputName(), action); _actionMethods.put(method, action); }
public void putValue(String key, Object newValue) { super.putValue(key, newValue); if (EXPAND_ICON.equals(key) || COLLAPSE_ICON.equals(key)) { updateIcon(); } }
private void makeUI(int defaultHeight) { datasetNameLabel = new JLabel(); /* gridPP = new PrefPanel("GridView", (PreferencesExt) store.node("GridViewPrefs")); gridUrlIF = gridPP.addTextComboField("url", "Gridded Data URL", null, 10, false); gridPP.addButton( BAMutil.makeButtconFromAction( chooseLocalDatasetAction )); gridPP.finish(true, BorderLayout.EAST); gridPP.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { InvDatasetImpl ds = new InvDatasetImpl( gridUrlIF.getText(), thredds.catalog.DataType.GRID, ServiceType.NETCDF); setDataset( ds); } }); */ // top tool panel toolPanel = new JPanel(); toolPanel.setBorder(new EtchedBorder()); toolPanel.setLayout(new MFlowLayout(FlowLayout.LEFT, 0, 0)); // menus JMenu dataMenu = new JMenu("Dataset"); dataMenu.setMnemonic('D'); configMenu = new JMenu("Configure"); configMenu.setMnemonic('C'); JMenu toolMenu = new JMenu("Controls"); toolMenu.setMnemonic('T'); addActionsToMenus(dataMenu, configMenu, toolMenu); JMenuBar menuBar = new JMenuBar(); menuBar.add(dataMenu); menuBar.add(configMenu); menuBar.add(toolMenu); toolPanel.add(menuBar); // field choosers fieldPanel = new JPanel(); fieldPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); toolPanel.add(fieldPanel); // stride toolPanel.add(controller.strideSpinner); // buttcons BAMutil.addActionToContainer(toolPanel, controller.drawHorizAction); BAMutil.addActionToContainer(toolPanel, controller.drawVertAction); mapBeanMenu = MapBean.makeMapSelectButton(); toolPanel.add(mapBeanMenu.getParentComponent()); // the Navigated panel and its toolbars panz.setLayout(new FlowLayout()); navToolbar = panz.getNavToolBar(); moveToolbar = panz.getMoveToolBar(); if (((Boolean) navToolbarAction.getValue(BAMutil.STATE)).booleanValue()) toolPanel.add(navToolbar); if (((Boolean) moveToolbarAction.getValue(BAMutil.STATE)).booleanValue()) toolPanel.add(moveToolbar); BAMutil.addActionToContainer(toolPanel, panz.setReferenceAction); BAMutil.addActionToContainer(toolPanel, controller.dataProjectionAction); BAMutil.addActionToContainer(toolPanel, controller.showGridAction); BAMutil.addActionToContainer(toolPanel, controller.showContoursAction); BAMutil.addActionToContainer(toolPanel, controller.showContourLabelsAction); BAMutil.addActionToContainer(toolPanel, redrawAction); // vertical split vertPanel = new VertPanel(); splitDraw = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panz, vertPanel); int divLoc = store.getInt("vertSplit", 2 * defaultHeight / 3); splitDraw.setDividerLocation(divLoc); drawingPanel = new JPanel(new BorderLayout()); // filled later // status panel JPanel statusPanel = new JPanel(new BorderLayout()); statusPanel.setBorder(new EtchedBorder()); positionLabel = new JLabel("position"); positionLabel.setToolTipText("position at cursor"); dataValueLabel = new JLabel("data value", SwingConstants.CENTER); dataValueLabel.setToolTipText("data value (double click on grid)"); statusPanel.add(positionLabel, BorderLayout.WEST); statusPanel.add(dataValueLabel, BorderLayout.CENTER); panz.setPositionLabel(positionLabel); // colorscale panel colorScalePanel = new ColorScale.Panel(this, controller.getColorScale()); csDataMinMax = new JComboBox(GridRenderer.MinMaxType.values()); csDataMinMax.setToolTipText("ColorScale Min/Max setting"); csDataMinMax.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { controller.setDataMinMaxType((GridRenderer.MinMaxType) csDataMinMax.getSelectedItem()); } }); JPanel westPanel = new JPanel(new BorderLayout()); westPanel.add(colorScalePanel, BorderLayout.CENTER); westPanel.add(csDataMinMax, BorderLayout.NORTH); // lay it out JPanel northPanel = new JPanel(); // northPanel.setLayout( new BoxLayout(northPanel, BoxLayout.Y_AXIS)); northPanel.setLayout(new BorderLayout()); northPanel.add(datasetNameLabel, BorderLayout.NORTH); northPanel.add(toolPanel, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(northPanel, BorderLayout.NORTH); add(statusPanel, BorderLayout.SOUTH); add(westPanel, BorderLayout.WEST); add(drawingPanel, BorderLayout.CENTER); setDrawHorizAndVert(controller.drawHorizOn, controller.drawVertOn); }
public NcmlEditor(JPanel buttPanel, PreferencesExt prefs) { this.prefs = prefs; fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager")); AbstractAction coordAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { addCoords = (Boolean) getValue(BAMutil.STATE); String tooltip = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF"; coordButt.setToolTipText(tooltip); } }; addCoords = prefs.getBoolean("coordState", false); String tooltip2 = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF"; BAMutil.setActionProperties(coordAction, "addCoords", tooltip2, true, 'C', -1); coordAction.putValue(BAMutil.STATE, Boolean.valueOf(addCoords)); coordButt = BAMutil.addActionToContainer(buttPanel, coordAction); protoChooser = new ComboBox((PreferencesExt) prefs.node("protoChooser")); addProtoChoices(); buttPanel.add(protoChooser); protoChooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String ptype = (String) protoChooser.getSelectedItem(); String proto = protoMap.get(ptype); if (proto != null) { editor.setText(proto); } } }); editor = new JEditorPane(); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit(false); // Set the wrapping style. kit.setWrapStyleWord(true); editor.setEditorKit(kit); // Set the font style. editor.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Set the tab size editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, 2); // Enable auto indentation. editor.getDocument().putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, true); // Enable tag completion. editor.getDocument().putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, true); // Initialise the folding kit.setFolding(true); // Set a style kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, Color.RED, Font.BOLD); // Put the editor in a panel that will force it to resize, when a different view is choosen. ScrollableEditorPanel editorPanel = new ScrollableEditorPanel(editor); JScrollPane scroller = new JScrollPane(editorPanel); // Add the number margin as a Row Header View scroller.setRowHeaderView(new LineNumberMargin(editor)); AbstractAction wrapAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { XMLEditorKit kit = (XMLEditorKit) editor.getEditorKit(); kit.setLineWrappingEnabled(!kit.isLineWrapping()); editor.updateUI(); } }; BAMutil.setActionProperties(wrapAction, "Wrap", "Toggle Wrapping", false, 'W', -1); BAMutil.addActionToContainer(buttPanel, wrapAction); AbstractAction saveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { String location = (ds == null) ? ncmlLocation : ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); String filename = fileChooser.chooseFilenameToSave(location + ".ncml"); if (filename == null) return; if (doSaveNcml(editor.getText(), filename)) ncmlLocation = filename; } }; BAMutil.setActionProperties(saveAction, "Save", "Save NcML", false, 'S', -1); BAMutil.addActionToContainer(buttPanel, saveAction); AbstractAction netcdfAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (outChooser == null) { outChooser = new NetcdfOutputChooser((Frame) null); outChooser.addPropertyChangeListener( "OK", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { writeNetcdf((NetcdfOutputChooser.Data) evt.getNewValue()); } }); } String location = (ds == null) ? ncmlLocation : ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); outChooser.setOutputFilename(location); outChooser.setVisible(true); } }; BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF file", false, 'N', -1); BAMutil.addActionToContainer(buttPanel, netcdfAction); AbstractAction transAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doTransform(editor.getText()); } }; BAMutil.setActionProperties( transAction, "Import", "read textArea through NcMLReader\n write NcML back out via resulting dataset", false, 'T', -1); BAMutil.addActionToContainer(buttPanel, transAction); AbstractButton compareButton = BAMutil.makeButtcon("Select", "Check NcML", false); compareButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Formatter f = new Formatter(); checkNcml(f); infoTA.setText(f.toString()); infoTA.gotoTop(); infoWindow.show(); } }); buttPanel.add(compareButton); setLayout(new BorderLayout()); add(scroller, BorderLayout.CENTER); // the info window infoTA = new TextHistoryPane(); infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA); infoWindow.setBounds( (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300))); }
// set all menu items except for "stop" to disabled private void enableStop() { setAllEnabled(false); debugMenu.setEnabled(true); stopAction.setEnabled(true); }
public BufrMessageViewer(final PreferencesExt prefs, JPanel buttPanel) { this.prefs = prefs; AbstractAction useReaderAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { Boolean state = (Boolean) getValue(BAMutil.STATE); doRead = state.booleanValue(); } }; BAMutil.setActionProperties(useReaderAction, "addCoords", "read data", true, 'C', -1); useReaderAction.putValue(BAMutil.STATE, new Boolean(doRead)); BAMutil.addActionToContainer(buttPanel, useReaderAction); AbstractAction seperateWindowAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { Boolean state = (Boolean) getValue(BAMutil.STATE); seperateWindow = state.booleanValue(); } }; BAMutil.setActionProperties( seperateWindowAction, "addCoords", "seperate DDS window", true, 'C', -1); seperateWindowAction.putValue(BAMutil.STATE, new Boolean(seperateWindow)); BAMutil.addActionToContainer(buttPanel, seperateWindowAction); messageTable = new BeanTableSorted( MessageBean.class, (PreferencesExt) prefs.node("GridRecordBean"), false); messageTable.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ddsTable.setBeans(new ArrayList()); obsTable.setBeans(new ArrayList()); MessageBean mb = (MessageBean) messageTable.getSelectedBean(); java.util.List<DdsBean> beanList = new ArrayList<DdsBean>(); try { setDataDescriptors(beanList, mb.m.getRootDataDescriptor(), 0); setObs(mb.m); } catch (IOException e1) { JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage()); e1 .printStackTrace(); // To change body of catch statement use File | Settings | // File Templates. } ddsTable.setBeans(beanList); } }); obsTable = new BeanTableSorted(ObsBean.class, (PreferencesExt) prefs.node("ObsBean"), false); obsTable.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ObsBean csb = (ObsBean) obsTable.getSelectedBean(); } }); ddsTable = new BeanTableSorted(DdsBean.class, (PreferencesExt) prefs.node("DdsBean"), false); ddsTable.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { DdsBean csb = (DdsBean) ddsTable.getSelectedBean(); } }); thredds.ui.PopupMenu varPopup = new thredds.ui.PopupMenu(messageTable.getJTable(), "Options"); varPopup.addAction( "Show DDS", new AbstractAction() { public void actionPerformed(ActionEvent e) { MessageBean vb = (MessageBean) messageTable.getSelectedBean(); if (!seperateWindow) infoTA.clear(); Formatter f = new Formatter(); try { if (!vb.m.isTablesComplete()) { f.format(" MISSING DATA DESCRIPTORS= "); vb.m.showMissingFields(f); f.format("%n%n"); } vb.m.dump(f); } catch (IOException e1) { JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage()); e1 .printStackTrace(); // To change body of catch statement use File | Settings | // File Templates. } if (seperateWindow) { TextHistoryPane ta = new TextHistoryPane(); IndependentWindow info = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), ta); info.setBounds( (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300))); ta.appendLine(f.toString()); ta.gotoTop(); info.show(); } else { infoTA.appendLine(f.toString()); infoTA.gotoTop(); infoWindow.show(); } } }); varPopup.addAction( "Data Table", new AbstractAction() { public void actionPerformed(ActionEvent e) { MessageBean mb = (MessageBean) messageTable.getSelectedBean(); try { NetcdfDataset ncd = getBufrMessageAsDataset(mb.m); Variable v = ncd.findVariable(BufrIosp.obsRecord); if ((v != null) && (v instanceof Structure)) { if (dataTable == null) makeDataTable(); dataTable.setStructure((Structure) v); dataWindow.show(); } } catch (Exception ex) { JOptionPane.showMessageDialog(BufrMessageViewer.this, ex.getMessage()); ex.printStackTrace(); } } }); varPopup.addAction( "Bit Count", new AbstractAction() { public void actionPerformed(ActionEvent e) { MessageBean mb = (MessageBean) messageTable.getSelectedBean(); Message m = mb.m; Formatter out = new Formatter(); try { infoTA2.clear(); if (!m.dds.isCompressed()) { MessageUncompressedDataReader reader = new MessageUncompressedDataReader(); reader.readData(null, m, raf, null, false, out); } else { MessageCompressedDataReader reader = new MessageCompressedDataReader(); reader.readData(null, m, raf, null, out); } int nbitsGiven = 8 * (m.dataSection.getDataLength() - 4); DataDescriptor root = m.getRootDataDescriptor(); out.format( "Message nobs=%d compressed=%s vlen=%s countBits= %d givenBits=%d %n", m.getNumberDatasets(), m.dds.isCompressed(), root.isVarLength(), m.getCountedDataBits(), nbitsGiven); out.format(" countBits= %d givenBits=%d %n", m.getCountedDataBits(), nbitsGiven); out.format( " countBytes= %d dataSize=%d %n", m.getCountedDataBytes(), m.dataSection.getDataLength()); out.format("%n"); infoTA2.appendLine(out.toString()); } catch (Exception ex) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ex.printStackTrace(new PrintStream(bos)); infoTA2.appendLine(out.toString()); infoTA2.appendLine(bos.toString()); } infoTA2.gotoTop(); infoWindow2.show(); } }); varPopup.addAction( "Write Message", new AbstractAction() { public void actionPerformed(ActionEvent e) { MessageBean mb = (MessageBean) messageTable.getSelectedBean(); try { String defloc; String header = mb.m.getHeader(); if (header != null) { header = header.split(" ")[0]; } if (header == null) { defloc = (raf.getLocation() == null) ? "." : raf.getLocation(); int pos = defloc.lastIndexOf("."); if (pos > 0) defloc = defloc.substring(0, pos); } else defloc = header; if (fileChooser == null) fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager")); String filename = fileChooser.chooseFilenameToSave(defloc + ".bufr"); if (filename == null) return; File file = new File(filename); FileOutputStream fos = new FileOutputStream(file); WritableByteChannel wbc = fos.getChannel(); wbc.write(ByteBuffer.wrap(mb.m.getHeader().getBytes())); byte[] raw = scan.getMessageBytes(mb.m); wbc.write(ByteBuffer.wrap(raw)); wbc.close(); JOptionPane.showMessageDialog( BufrMessageViewer.this, filename + " successfully written"); } catch (Exception ex) { JOptionPane.showMessageDialog(BufrMessageViewer.this, "ERROR: " + ex.getMessage()); ex.printStackTrace(); } } }); varPopup.addAction( "Dump distinct DDS", new AbstractAction() { public void actionPerformed(ActionEvent e) { dumpDDS(); } }); varPopup.addAction( "Write all distinct messages", new AbstractAction() { public void actionPerformed(ActionEvent e) { writeAll(); } }); varPopup.addAction( "Show XML", new AbstractAction() { public void actionPerformed(ActionEvent e) { MessageBean mb = (MessageBean) messageTable.getSelectedBean(); Message m = mb.m; ByteArrayOutputStream out = new ByteArrayOutputStream(1000 * 100); try { infoTA.clear(); NetcdfDataset ncd = getBufrMessageAsDataset(mb.m); new Bufr2Xml(m, ncd, out, true); infoTA.setText(out.toString()); } catch (Exception ex) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ex.printStackTrace(new PrintStream(bos)); infoTA.appendLine(out.toString()); infoTA.appendLine(bos.toString()); } infoTA.gotoTop(); infoWindow.show(); } }); // the info window infoTA = new TextHistoryPane(); infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA); infoWindow.setBounds( (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300))); // the info window 2 infoTA2 = new TextHistoryPane(); infoWindow2 = new IndependentWindow("Extra Information-2", BAMutil.getImage("netcdfUI"), infoTA2); infoWindow2.setBounds( (Rectangle) prefs.getBean("InfoWindowBounds2", new Rectangle(300, 300, 500, 300))); split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, ddsTable, obsTable); split2.setDividerLocation(prefs.getInt("splitPos2", 800)); split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, messageTable, split2); split.setDividerLocation(prefs.getInt("splitPos", 500)); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); }
public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { super.firePropertyChange(propertyName, oldValue, newValue); }