public void invertSelection() { int[] sel = this.list.getSelectedIndices(); int[] newSel = new int[listModel.getSize() - sel.length]; int idx = 0; int lastIdx = -1; for (int i : sel) { for (int i2 = lastIdx + 1; i2 < i; i2++) newSel[idx++] = i2; lastIdx = i; } for (int i2 = lastIdx + 1; i2 < listModel.getSize(); i2++) newSel[idx++] = i2; list.setSelectedIndices(newSel); }
void syncLists() { JList list = webPanels[1 - panelIndex].instanceList; DefaultListModel model1 = (DefaultListModel) instanceList.getModel(); DefaultListModel model2 = (DefaultListModel) list.getModel(); model2.clear(); int n = model1.getSize(); for (int i = 0; i < n; i++) model2.addElement(model1.get(i)); list.setSelectedIndices(new int[] {}); enableButtons(instanceList); webPanels[1 - panelIndex].enableButtons(list); }
private void speichern(Path saveName) { Properties prop = new Properties(); if (!quellListModel.isEmpty()) for (int i = 0; i < quellListModel.getSize(); i++) prop.setProperty( String.format("quellMenu%d", i), quellListModel.getElementAt(i).getValueMember().toString()); if (!zielListModel.isEmpty()) for (int i = 0; i < zielListModel.getSize(); i++) prop.setProperty( String.format("zielMenu%d", i), zielListModel.getElementAt(i).getValueMember().toString()); try { FileOutputStream out = new FileOutputStream(saveName.toString()); prop.store(out, null); out.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * Returns the rowCount attribute of the BPMsList object * * @return The rowCount value */ public int getRowCount() { return listModel.getSize(); }
private void subZListBoxEintrag() { if (zielJList.getSelectedIndex() < 0) return; else zielListModel.remove(zielJList.getSelectedIndex()); if (zielListModel.getSize() > 0) zielJList.setSelectedIndex(zielListModel.getSize() - 1); }
private void addZListBoxEintrag(Path zielOrdner) { if (zielOrdner == null) return; zielListModel.addElement(new ListItem(zielOrdner, zielOrdner.toString())); zielJList.setSelectedIndex(zielListModel.getSize() - 1); }
private void subQListBoxEintrag() { if (quellJList.getSelectedIndex() < 0) return; else quellListModel.remove(quellJList.getSelectedIndex()); if (quellListModel.getSize() > 0) quellJList.setSelectedIndex(quellListModel.getSize() - 1); }
private void addQListBoxEintrag(Path quellOrdner) { if (quellOrdner == null) return; quellListModel.addElement(new ListItem(quellOrdner, quellOrdner)); quellJList.setSelectedIndex(quellListModel.getSize() - 1); }
public boolean importData(JComponent c, Transferable t) { if (sourceIndices == null || !canImport(c, t.getTransferDataFlavors())) { return false; } JList target = null; ArrayList alist = null; try { target = (JList) c; if (hasLocalArrayListFlavor(t.getTransferDataFlavors())) { alist = (ArrayList) t.getTransferData(localArrayListFlavor); } else if (hasSerialArrayListFlavor(t.getTransferDataFlavors())) { alist = (ArrayList) t.getTransferData(serialArrayListFlavor); } else { return false; } } catch (UnsupportedFlavorException ufe) { System.out.println("importData: unsupported data flavor"); return false; } catch (IOException ioe) { System.out.println("importData: I/O exception"); return false; } //At this point we use the same code to retrieve the data //locally or serially. //We'll drop at the current selected index. int targetIndex = target.getSelectedIndex(); //Prevent the user from dropping data back on itself. //For example, if the user is moving items #4,#5,#6 and #7 and //attempts to insert the items after item #5, this would //be problematic when removing the original items. //This is interpreted as dropping the same data on itself //and has no effect. if (source.equals(target)) { //System.out.print("checking indices index TO: " + targetIndex + " FROM:"); //for (int i = 0; i < sourceIndices.length;i++) //System.out.print(" "+sourceIndices[i]); //System.out.println(""); if (targetIndex >= sourceIndices[0] && targetIndex <= sourceIndices[sourceIndices.length - 1]) { //System.out.println("setting indices null : " + targetIndex + " " + sourceIndices[0] + " " + sourceIndices[sourceIndices.length - 1]); sourceIndices = null; return true; } } DefaultListModel listModel = (DefaultListModel) target.getModel(); int max = listModel.getSize(); if (targetIndex < 0) { targetIndex = max; } else { if (sourceIndices[0] < targetIndex) targetIndex++; if (targetIndex > max) { targetIndex = max; } } addIndex = targetIndex; addCount = alist.size(); for (int i = 0; i < alist.size(); i++) { listModel.add(targetIndex++, objectOf(listModel, alist.get(i))); } return true; }
boolean fileWriter(File file, JList InstanceList) throws IOException { //returns true if successful. useAppletJS = JmolViewer.checkOption(viewer, "webMakerCreateJS"); // JOptionPane.showMessageDialog(null, "Creating directory for data..."); String datadirPath = file.getPath(); String datadirName = file.getName(); String fileName = null; if (datadirName.indexOf(".htm") > 0) { fileName = datadirName; datadirPath = file.getParent(); file = new File(datadirPath); datadirName = file.getName(); } else { fileName = datadirName + ".html"; } datadirPath = datadirPath.replace('\\', '/'); boolean made_datadir = (file.exists() && file.isDirectory() || file.mkdir()); DefaultListModel listModel = (DefaultListModel) InstanceList.getModel(); LogPanel.log(""); if (made_datadir) { LogPanel.log(GT._("Using directory {0}", datadirPath)); LogPanel.log(" " + GT._("adding JmolPopIn.js")); viewer.writeTextFile(datadirPath + "/JmolPopIn.js", WebExport.getResourceString(this, "JmolPopIn.js")); for (int i = 0; i < listModel.getSize(); i++) { JmolInstance thisInstance = (JmolInstance) (listModel.getElementAt(i)); String javaname = thisInstance.javaname; String script = thisInstance.script; LogPanel.log(" ...jmolApplet" + i); LogPanel.log(" ..." + GT._("adding {0}.png", javaname)); try { thisInstance.movepict(datadirPath); } catch (IOException IOe) { throw IOe; } String fileList = ""; fileList += addFileList(script, "/*file*/"); fileList += addFileList(script, "FILE0="); fileList += addFileList(script, "FILE1="); if (localAppletPath.getText().equals(".") || remoteAppletPath.getText().equals(".")) fileList += "Jmol.js\nJmolApplet.jar"; String[] filesToCopy = fileList.split("\n"); String[] copiedFileNames = new String[filesToCopy.length]; String f; int pt; for (int iFile = 0; iFile < filesToCopy.length; iFile++) { if ((pt = (f = filesToCopy[iFile]).indexOf("|")) >= 0) filesToCopy[iFile] = f.substring(0, pt); copiedFileNames[iFile] = copyBinaryFile(filesToCopy[iFile], datadirPath); } script = localizeFileReferences(script, filesToCopy, copiedFileNames); LogPanel.log(" ..." + GT._("adding {0}.spt", javaname)); viewer.writeTextFile(datadirPath + "/" + javaname + ".spt", script); } String html = WebExport.getResourceString(this, panelName + "_template"); html = fixHtml(html); appletInfoDivs = ""; StringBuffer appletDefs = new StringBuffer(); if (!useAppletJS) htmlAppletTemplate = WebExport.getResourceString(this, panelName + "_template2"); for (int i = 0; i < listModel.getSize(); i++) html = getAppletDefs(i, html, appletDefs, (JmolInstance) listModel .getElementAt(i)); html = TextFormat.simpleReplace(html, "@AUTHOR@", GT.escapeHTML(pageAuthorName .getText())); html = TextFormat.simpleReplace(html, "@TITLE@", GT.escapeHTML(webPageTitle.getText())); html = TextFormat.simpleReplace(html, "@REMOTEAPPLETPATH@", remoteAppletPath.getText()); html = TextFormat.simpleReplace(html, "@LOCALAPPLETPATH@", localAppletPath.getText()); html = TextFormat.simpleReplace(html, "@DATADIRNAME@", datadirName); if (appletInfoDivs.length() > 0) appletInfoDivs = "\n<div style='display:none'>\n" + appletInfoDivs + "\n</div>\n"; String str = appletDefs.toString(); if (useAppletJS) str = "<script type='text/javascript'>\n" + str + "\n</script>"; html = TextFormat.simpleReplace(html, "@APPLETINFO@", appletInfoDivs); html = TextFormat.simpleReplace(html, "@APPLETDEFS@", str); html = TextFormat.simpleReplace(html, "@CREATIONDATA@", GT.escapeHTML(WebExport .TimeStamp_WebLink())); html = TextFormat.simpleReplace(html, "@AUTHORDATA@", GT.escapeHTML(GT._("Based on template by A. Herráez as modified by J. Gutow"))); html = TextFormat.simpleReplace(html, "@LOGDATA@", "<pre>\n" + LogPanel.getText() + "\n</pre>\n"); LogPanel.log(" ..." + GT._("creating {0}", fileName)); viewer.writeTextFile(datadirPath + "/" + fileName, html); } else { IOException IOe = new IOException("Error creating directory: " + datadirPath); throw IOe; } LogPanel.log(""); return true; }
public void actionPerformed(ActionEvent e) { if (e.getSource() == remoteAppletPath) {//apparently no events are fired to reach this, maybe "enter" does it String path = remoteAppletPath.getText(); WebExport.setAppletPath(path, true); return; } if (e.getSource() == localAppletPath) {//apparently no events are fired to reach this, maybe "enter" does it String path = localAppletPath.getText(); WebExport.setAppletPath(path, false); return; } //Handle open button action. if (e.getSource() == addInstanceButton) { //make dialog to get name for instance //create an instance with this name. Each instance is just a container for a string with the Jmol state //which contains the full information on the file that is loaded and manipulations done. String label = (instanceList.getSelectedIndices().length != 1 ? "" : getInstanceName(-1)); String name = JOptionPane.showInputDialog( GT._("Give the occurrence of Jmol a name:"), label); if (name == null) return; //need to get the script... String script = viewer.getStateInfo(); if (script == null) { LogPanel.log("Error trying to get Jmol State within pop_in_Jmol."); } DefaultListModel listModel = (DefaultListModel) instanceList.getModel(); int width = 300; int height = 300; if (appletSizeSpinnerH != null) { width = ((SpinnerNumberModel) (appletSizeSpinnerW.getModel())) .getNumber().intValue(); height = ((SpinnerNumberModel) (appletSizeSpinnerH.getModel())) .getNumber().intValue(); } JmolInstance instance = new JmolInstance(viewer, name, script, width, height); if (instance == null) { LogPanel .log(GT._("Error creating new instance containing script(s) and image.")); } int i; for (i = instanceList.getModel().getSize(); --i >= 0;) if (getInstanceName(i).equals(instance.name)) break; if (i < 0) { i = listModel.getSize(); listModel.addElement(instance); LogPanel.log(GT._("added Instance {0}", instance.name)); } else { listModel.setElementAt(instance, i); LogPanel.log(GT._("updated Instance {0}", instance.name)); } instanceList.setSelectedIndex(i); syncLists(); return; } if (e.getSource() == deleteInstanceButton) { DefaultListModel listModel = (DefaultListModel) instanceList.getModel(); //find out which are selected and remove them. int[] todelete = instanceList.getSelectedIndices(); int nDeleted = 0; for (int i = 0; i < todelete.length; i++){ JmolInstance instance = (JmolInstance) listModel.get(todelete[i]); try { instance.delete(); } catch (IOException err) { LogPanel.log(err.getMessage()); } listModel.remove(todelete[i] - nDeleted++); } syncLists(); return; } if (e.getSource() == showInstanceButton) { DefaultListModel listModel = (DefaultListModel) instanceList.getModel(); //find out which are selected and remove them. int[] list = instanceList.getSelectedIndices(); if (list.length != 1) return; JmolInstance instance = (JmolInstance) listModel.get(list[0]); viewer.evalStringQuiet(")" + instance.script); //leading paren disabled history return; } if (e.getSource() == saveButton) { fc.setDialogTitle(GT._("Select a directory to create or an HTML file to save")); int returnVal = fc.showSaveDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) return; File file = fc.getSelectedFile(); boolean retVal = true; try { String path = remoteAppletPath.getText(); WebExport.setAppletPath(path, true); path = localAppletPath.getText(); WebExport.setAppletPath(path, false); String authorName = pageAuthorName.getText(); WebExport.setWebPageAuthor(authorName); retVal = fileWriter(file, instanceList); } catch (IOException IOe) { LogPanel.log(IOe.getMessage()); } if (!retVal) { LogPanel.log(GT._("Call to FileWriter unsuccessful.")); } } if (e.getSource() == helpButton){ HelpDialog webExportHelp = new HelpDialog(WebExport.getFrame(), WebExport.getHtmlResource(this, panelName + "_instructions")); webExportHelp.setVisible(true); webExportHelp.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } }
public void clientJoined(Message.ClientJoinMsg m) { Iterator i = clients.iterator(); while (i.hasNext()) { EditorClient ec = (EditorClient) i.next(); if (ec.isPresent()) { if (m.getName().equals(ec.getName())) { sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_NAME); return; } if (m.getColorCode() == ec.getColorCode()) { sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_COLOR); return; } } } // clientAccepted // mach... added ClientIPaddress + added server to EditorClient const EditorClient newClient = new EditorClient( this, nextClientId, m.getName(), m.getColorCode(), m.getKeyValue(), m.getClientIPaddress()); if (EditorServer_Debug) System.out.println( ">>> In EditorServer.clientJoined : client NAME is : *" + m.getName() + "* IPAddress : is : *" + m.getClientIPaddress() + "*"); clients.add(newClient); nextClientId++; clientsPanel.updateClientList(); // here... match Audio & Text client // iterate through list of audio client String audioClientIP = ""; int offset = -1; if (isAudioOptionSelected) { if (EditorServer_Debug) System.out.println("\n>>>In Client Accepted !!!"); for (int n = 0; n < plistModel.getSize(); n++) { audioClientIP = (plistModel.getElementAt(n)).toString(); offset = audioClientIP.indexOf('@'); audioClientIP = audioClientIP.substring(offset + 1); if (audioClientIP.equals(m.getClientIPaddress())) { System.out.println("MATCH found!!!" + m.getName() + "<>" + audioClientIP); // change ... plistModel.set(n, m.getName()); } } } // endif isAudioOptionSelected try { clientChannel.sendToOthers(client, new Data(newClient.getMessage())); sendDocumentState(nextClientId - 1); sendHighlightTypes(); sendHighlights(); } catch (Exception e) { System.err.println("EditorServer: clientJoined: error sending msg"); if (EditorServer_Debug) e.printStackTrace(); } }
@Override protected String getEnabledValue() { return Integer.toString(model.getSize()); }