// This method is called when a request has been made to close a client connection public synchronized void disconnectClient(ClientConnection clientConnection) { // Ensures this connection exists (a necessary check when this is being called from outside of a // clientConnection) if (clientConnection != null && clientConnection.isConnected() && clientSocketList.get(clientSocketList.indexOf(clientConnection)) != null) { // Send the client a message telling it to close its socket clientConnection.xmitMessage(ClientConnection.QUIT); // Then close that socket...the user really doesn't have a choice. We're just asking to be // nice. clientSocketList.get(clientSocketList.indexOf(clientConnection)).closeSocket(); parent.updateStatusBox( clientSocketList.indexOf(clientConnection) + " " + "Forcing disconnection of client " + clientConnection.id + " on port " + port + "..."); } else { // If this thread is NOT connected, it may be stuck, so let's send an interrupt to wake it up clientThreadList.get(clientSocketList.indexOf(clientConnection)).interrupt(); parent.updateStatusBox("Closing listen socket on port " + port + "..."); } }
/** Find the row in the table for a given message id */ public int findRow(SOAPMonitorData soap) { int row = -1; if (filter_data != null) { row = filter_data.indexOf(soap); } else { row = data.indexOf(soap); } return row; }
// This method is called when a client has disconnected from the server and its thread is about to // end // It just presents a status message and removes the given client and thread from our lists public synchronized void clientThreadEnding(ClientConnection clientConnection) { parent.updateStatusBox( clientSocketList.indexOf(clientConnection) + " " + "Client " + clientConnection.id + " disconnected, removing from connection pool"); clientThreadList.remove(clientSocketList.indexOf(clientConnection)); clientSocketList.remove(clientSocketList.indexOf(clientConnection)); numClients--; parent.updateStatusBox("There are " + numClients + " clients connected"); }
public void changeDictionary(String strLanguage) { // Change dictionary MonitorDictionary.setCurrentLanguage(strLanguage); DefaultDictionary.setCurrentLanguage(strLanguage); ErrorDictionary.setCurrentLanguage(strLanguage); // Update UI updateLanguage(); WindowManager.updateLanguage(); int iIndex = mvtLanguage.indexOf(strLanguage); if (iIndex >= 0) { JRadioButtonMenuItem mnu = (JRadioButtonMenuItem) mvtLanguageItem.elementAt(iIndex); mnu.setSelected(true); } // Store config Hashtable prt = null; try { prt = Global.loadHashtable(Global.FILE_CONFIG); } catch (Exception e) { prt = new Hashtable(); } prt.put("Language", strLanguage); try { Global.storeHashtable(prt, Global.FILE_CONFIG); } catch (Exception e) { } }
/** Replaces a figure in the drawing without removing it from the drawing. */ public synchronized void replace(Figure figure, Figure replacement) { int index = fFigures.indexOf(figure); if (index != -1) { replacement.addToContainer(this); // will invalidate figure figure.changed(); fFigures.setElementAt(replacement, index); } }
/** * Sets the current editor to the specified editor, loads the current entry, and makes sure that * it is visible to the user. * * @param makeCurrent the editor to select. */ protected void setCurrentEditor(PluggableEditor makeCurrent) { currentEditor = makeCurrent; if (currentEditor != null && currentEditor.getDataSink() != null) currentEditor.getDataSink().displayEntry(entry, dataSource); int index = activeEditors.indexOf(makeCurrent); if (index == -1) { clearPluggableEditors(); addEditor(makeCurrent); setSelectedIndex(activeEditors.indexOf(makeCurrent)); } else if (index != getSelectedIndex()) { setSelectedIndex(index); } }
/** Update a message */ public void updateData(SOAPMonitorData soap) { int row; if (filter_data == null) { // No filter, so just fire table updated row = data.indexOf(soap); if (row != -1) { fireTableRowsUpdated(row, row); } } else { // Check if the row was being displayed row = filter_data.indexOf(soap); if (row == -1) { // Row was not displayed, so check for if it // now needs to be displayed if (filterMatch(soap)) { int index = -1; row = data.indexOf(soap) + 1; while ((row < data.size()) && (index == -1)) { index = filter_data.indexOf(data.elementAt(row)); if (index != -1) { // Insert at this location filter_data.add(index, soap); } row++; } if (index == -1) { // Insert at end index = filter_data.size(); filter_data.addElement(soap); } fireTableRowsInserted(index, index); } } else { // Row was displayed, so check if it needs to // be updated or removed if (filterMatch(soap)) { fireTableRowsUpdated(row, row); } else { filter_data.remove(soap); fireTableRowsDeleted(row, row); } } } }
public void DelChild (CGNode n) throws NoSuchElementException { int idx = childs.indexOf (n); if (idx == -1) throw new NoSuchElementException (); else { childs.removeElementAt (idx); arrows.removeElementAt (idx); } }
// Once a client is connected to the server, their connection object is handed off to this method // for handling public synchronized void clientConnected(Socket socket) { // Create a ClientConnection to contain this new client, pass off the socket, and start the new // thread ClientConnection clientConnection = new ClientConnection(this, socket, idCounter); Thread clientSocketThread = new Thread(clientConnection); clientSocketThread.start(); // Add this connection to our socket and thread lists so we can keep track of who is alive clientSocketList.add(clientConnection); clientThreadList.add(clientSocketList.indexOf(clientConnection), clientSocketThread); numClients++; // numClients just keeps track of how many clients are connected idCounter++; // idCounter NEVER decrements, so we will never have two clientConnections trying // to occupy // the same space in the vector // Let the server status box know that someone has connected parent.updateStatusBox("Client " + clientConnection.id + " has connected on port " + port); parent.updateStatusBox("There are " + numClients + " clients connected\n"); }
public void doIt() { Selection curSel; Fig newFig = null; int offset = 1; String dir = (String) getArg(DIR); if (DIR_PREV.equals(dir)) offset = -1; Editor ce = Globals.curEditor(); SelectionManager sm = ce.getSelectionManager(); Vector diagramContents = ce.getLayerManager().getContents(); int diagramSize = diagramContents.size(); int newIndex = diagramSize + 1; if (sm.size() == 0) newIndex = 0; else if (sm.size() == 1) { Fig curFig; curSel = (Selection) sm.selections().firstElement(); curFig = (Fig) curSel.getContent(); int curIndex = diagramContents.indexOf(curFig); newIndex = (curIndex + offset + diagramSize) % diagramSize; } if (diagramSize > newIndex) newFig = (Fig) diagramContents.elementAt(newIndex); if (newFig != null) ce.getSelectionManager().select(newFig); }
/** This method returns the distribution HTML code as a string */ private String outputClustering(HTMLFile f, Collection<Cluster> allClusters, int maxSize) { int[] distribution = new int[maxSize + 1]; int max = 0; for (int i = 0; i <= maxSize; i++) distribution[i] = 0; // Now output the clustering: f.println("<TABLE CELLPADDING=2 CELLSPACING=2>"); f.println( "<TR><TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Cluster_number") + "<TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Size") + "<TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Threshold") + "<TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Cluster_members") + "<TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Most_frequent_words") + "</TR>"); Iterator<Cluster> clusterI = allClusters.iterator(); for (int i = 1; clusterI.hasNext(); i++) { Cluster cluster = clusterI.next(); if (max < ++distribution[cluster.size()]) max = distribution[cluster.size()]; // no singleton clusters if (cluster.size() == 1) continue; f.print( "<TR><TD ALIGN=center BGCOLOR=#8080ff>" + i + "<TD ALIGN=center BGCOLOR=#c0c0ff>" + cluster.size() + "<TD ALIGN=center BGCOLOR=#c0c0ff>" + cluster.getSimilarity() + "<TD ALIGN=left BGCOLOR=#c0c0ff>"); // sort names TreeSet<Submission> sortedSubmissions = new TreeSet<Submission>(); for (int x = 0; x < cluster.size(); x++) { sortedSubmissions.add(submissions.elementAt(cluster.getSubmissionAt(x))); } for (Iterator<Submission> iter = sortedSubmissions.iterator(); iter.hasNext(); ) { Submission sub = iter.next(); int index = submissions.indexOf(sub); f.print("<A HREF=\"submission" + index + ".html\">" + sub.name + "</A>"); if (iter.hasNext()) f.print(", "); neededSubmissions.add(sub); // write files for these. } if (this.program.get_language() instanceof jplag.text.Language) { f.println( "<TD ALIGN=left BGCOLOR=#c0c0ff>" + ThemeGenerator.generateThemes( sortedSubmissions, this.program.get_themewords(), true, this.program)); } else { f.println("<TD ALIGN=left BGCOLOR=#c0c0ff>-"); } f.println("</TR>"); } f.println("</TABLE>\n<P>\n"); f.println("<H5>" + msg.getString("Clusters.Distribution_of_cluster_size") + ":</H5>"); String text; text = "<TABLE CELLPADDING=1 CELLSPACING=1>\n"; text += "<TR><TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Cluster_size") + "<TH ALIGN=center BGCOLOR=#8080ff>" + msg.getString("Clusters.Number_of_clusters") + "<TH ALIGN=center BGCOLOR=#8080ff>.</TR>\n"; for (int i = 0; i <= maxSize; i++) { if (distribution[i] == 0) continue; text += "<TR><TD ALIGN=center BGCOLOR=#c0c0ff>" + i + "<TD ALIGN=right BGCOLOR=#c0c0ff>" + distribution[i] + "<TD BGCOLOR=#c0c0ff>\n"; for (int j = (distribution[i] * barLength / max); j > 0; j--) text += ("#"); if (distribution[i] * barLength / max == 0) { if (distribution[i] == 0) text += ("."); else text += ("#"); } text += ("</TR>\n"); } text += ("</TABLE>\n"); f.print(text); return text; }