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))); }
private void addToolbarOption(String toolbarName, JToolBar toolbar, AbstractAction act) { boolean wantsToolbar = store.getBoolean(toolbarName, true); if (wantsToolbar) toolPanel.add(toolbar); }
/** * Set the state from the last saved in the PreferencesExt. * * @param store ok if null or empty */ public void restoreState(PreferencesExt store) { if (store == null) return; int ncols = table.getColumnCount(); // stored column order int[] modelIndex = (int[]) store.getBean("ColumnOrder", null); if ((modelIndex != null) && (modelIndex.length == ncols)) { // what about invisible ?? // make invisible any not stored boolean[] visible = new boolean[ncols]; for (int i = 0; i < modelIndex.length; i++) if (modelIndex[i] < ncols) visible[modelIndex[i]] = true; // modify popup menu for (int i = 0; i < ncols; i++) if (!visible[i]) { // System.out.println( colName[i]+" hide "+i); acts[i].hideColumn(); acts[i].putValue(BAMutil.STATE, new Boolean(false)); } // now set the header order TableColumnModel tcm = table.getColumnModel(); int n = Math.min(modelIndex.length, table.getColumnCount()); for (int i = 0; i < n; i++) { TableColumn tc = tcm.getColumn(i); tc.setModelIndex(modelIndex[i]); String name = model.getColumnName(modelIndex[i]); tc.setHeaderValue(name); tc.setIdentifier(name); if (useThreads && (modelIndex[i] == threadCol)) { threadHeaderRenderer = new ThreadHeaderRenderer(threadCol); tc.setHeaderRenderer(threadHeaderRenderer); } else tc.setHeaderRenderer(new SortedHeaderRenderer(name, modelIndex[i])); } } // set the column widths Object colWidths = store.getBean("ColumnWidths", null); if (colWidths == null) return; int[] size = (int[]) colWidths; if (size != null) setColumnWidths(size); if (debug) { System.out.println(" read widths = "); for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]); System.out.println(); } boolean isThreadsOn = store.getBoolean("isThreadsOn", false); if (useThreads) { model.setThreadsOn(isThreadsOn); threadHeaderRenderer.setOn(isThreadsOn); } int colNo = store.getInt("SortOnCol", 0); boolean reverse = store.getBoolean("SortReverse", false); model.setSortCol(colNo); model.setReverse(reverse); setSortCol(colNo, reverse); model.sort(); table.fireDataChanged(); }
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))); }