/** * Compute a logical, reasonably efficient join on the specified tables. See project description * for hints on how this should be implemented. * * @param stats Statistics for each table involved in the join, referenced by base table names, * not alias * @param filterSelectivities Selectivities of the filter predicates on each table in the join, * referenced by table alias (if no alias, the base table name) * @param explain Indicates whether your code should explain its query plan or simply execute it * @return A Vector<LogicalJoinNode> that stores joins in the left-deep order in which they should * be executed. * @throws ParsingException when stats or filter selectivities is missing a table in the join, or * or when another internal error occurs */ public Vector<LogicalJoinNode> orderJoins( HashMap<String, TableStats> stats, HashMap<String, Double> filterSelectivities, boolean explain) throws ParsingException { // See the project writeup for some hints as to how this function // should work. // some code goes here PlanCache pc = new PlanCache(); for (int i = 1; i <= joins.size(); i++) { Set<Set<LogicalJoinNode>> subsets = enumerateSubsets(joins, i); for (Set<LogicalJoinNode> subset : subsets) { CostCard best = new CostCard(); best.cost = Double.MAX_VALUE; for (LogicalJoinNode node : subset) { CostCard subCard = computeCostAndCardOfSubplan(stats, filterSelectivities, node, subset, best.cost, pc); if (subCard != null) { if (subCard.cost < best.cost) best = subCard; pc.addPlan(subset, best.cost, best.card, best.plan); } } } } if (explain) printJoins(joins, pc, stats, filterSelectivities); HashSet<LogicalJoinNode> joinSet = new HashSet<LogicalJoinNode>(); for (int i = 0; i < joins.size(); i++) { joinSet.add(joins.get(i)); } Vector<LogicalJoinNode> order = pc.getOrder(joinSet); if (order != null) return order; return joins; }
@Override public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(100); } catch (Exception e) { // TODO: handle exception } // 判断每一粒子弹和每一辆敌人的坦克都是否有重合(击中) for (int i = 0; i < hero.bombs.size(); i++) { // 取出每个子弹 Bomb myBomb = hero.bombs.get(i); // 子弹必须得存活才有判断的意义 if (myBomb.isLive) { for (int j = 0; j < ets.size(); j++) { // 取出每辆坦克 EnemyTank et = ets.get(j); if (et.isLive) { this.isHit(myBomb, et); } } } } this.repaint(); } }
public int submit() { String newName = produktgruppeFormular.nameField.getText(); if (isProdGrAlreadyKnown(newName)) { // not allowed: changing name to one that is already registered in DB JOptionPane.showMessageDialog( this, "Fehler: Produktgruppe '" + newName + "' bereits vorhanden!", "Info", JOptionPane.INFORMATION_MESSAGE); produktgruppeFormular.nameField.setText(""); return 0; } Integer parentProdGrID = produktgruppeFormular.parentProdGrIDs.get( produktgruppeFormular.parentProdGrBox.getSelectedIndex()); Vector<Integer> idsNew = produktgruppeFormular.idsOfNewProdGr(parentProdGrID); Integer topID = idsNew.get(0); Integer subID = idsNew.get(1); Integer subsubID = idsNew.get(2); Integer mwstID = produktgruppeFormular.mwstIDs.get(produktgruppeFormular.mwstBox.getSelectedIndex()); Integer pfandID = produktgruppeFormular.pfandIDs.get(produktgruppeFormular.pfandBox.getSelectedIndex()); return insertNewProdGr(topID, subID, subsubID, newName, mwstID, pfandID); }
/** * Establishes combo box editor for 'from onramp' column. * * @param clmn */ private void setUpToOnrampColumn() { JComboBox combo = new JComboBox(); Vector<AbstractNetworkElement> nes = ((AbstractControllerComplex) controller).getMyMonitor().getSuccessors(); for (int i = 0; i < nes.size(); i++) if ((nes.get(i).getType() & TypesHWC.MASK_LINK) > 0) combo.addItem(nes.get(i)); TableColumn clmn = zonetab.getColumnModel().getColumn(3); clmn.setCellEditor(new DefaultCellEditor(combo)); clmn.setCellRenderer(new DefaultTableCellRenderer()); return; }
/** * Show a dialog for printing the current drawing. * * @param fff the parent frame which will be used for dialogs and message boxes. * @param CCr the CircuitPanel containing the drawing to be exported. */ public void printDrawing(JFrame fff, CircuitPanel CCr) { cc = CCr; DialogPrint dp = new DialogPrint(fff); dp.setMirror(printMirror); dp.setFit(printFitToPage); dp.setBW(printBlackWhite); dp.setLandscape(printLandscape); dp.setVisible(true); // Get some information about the printing options. printMirror = dp.getMirror(); printFitToPage = dp.getFit(); printLandscape = dp.getLandscape(); printBlackWhite = dp.getBW(); Vector<LayerDesc> ol = cc.dmp.getLayers(); if (dp.shouldPrint()) { if (printBlackWhite) { Vector<LayerDesc> v = new Vector<LayerDesc>(); // Here we create an alternative array of layers in // which all colors are pitch black. This may be // useful for PCB's. for (int i = 0; i < LayerDesc.MAX_LAYERS; ++i) v.add( new LayerDesc( new ColorSwing(Color.black), ((LayerDesc) ol.get(i)).getVisible(), "B/W", ((LayerDesc) ol.get(i)).getAlpha())); cc.dmp.setLayers(v); } PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); // Set the correct printing orientation. if (printLandscape) { aset.add(OrientationRequested.LANDSCAPE); } else { aset.add(OrientationRequested.PORTRAIT); } job.print(aset); } catch (PrinterException ex) { // The job did not successfully complete JOptionPane.showMessageDialog(fff, Globals.messages.getString("Print_uncomplete")); } } cc.dmp.setLayers(ol); } }
@SuppressWarnings("unchecked") private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) { toggle(false); JFileChooser fc = new JFileChooser(); String path = FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv"; fc.setSelectedFile(new File(path)); fc.showSaveDialog(this); File target = fc.getSelectedFile(); int row = model.getRowCount(); try { boolean written; try (FileOutputStream fos = new FileOutputStream(target)) { while (--row > -1) { Vector v = (Vector) model.getDataVector().get(row); for (int i = 0; i < v.size(); i++) { if (v.get(i).toString().contains(",")) { v.set(i, ST.format("\"<%1>\"", v.get(i))); } } String line = ST.format("<%1:{ x |, <x>}>", v).substring(2); fos.write(line.getBytes(CHARSET)); fos.write(Character.LINE_SEPARATOR); } written = true; } if (written) { LogEmitter.factory .get() .emit( this, Core.ALERT.INFO, ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath())); } else { LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } } catch (FileNotFoundException ex) { Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex); LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } catch (IOException ex) { Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex); LogEmitter.factory .get() .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath())); } toggle(true); }
public void paint(Graphics g) { super.paint(g); // 画出我的坦克 g.fillRect(0, 0, 400, 300); // 确定区域为400 300 背景为黑色值 // 使用画坦克方法画出坦克 this.drawTank(hero.getX(), hero.getY(), g, hero.getDirect(), 0); // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { this.drawTank(ets.get(i).getX(), ets.get(i).getY(), g, ets.get(i).getDirect(), 1); } }
public void nick_name(String msg) { try { String name = msg.substring(13); this.setName(name); Vector v = father.onlineList; boolean isRepeatedName = false; int size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); if (tempSat.getName().equals(name)) { isRepeatedName = true; break; } } if (isRepeatedName == true) { dout.writeUTF("<#NAME_REPEATED#>"); din.close(); dout.close(); sc.close(); flag = false; } else { v.add(this); father.refreshList(); String nickListMsg = ""; StringBuilder nickListMsgSb = new StringBuilder(); size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); nickListMsgSb.append("!"); nickListMsgSb.append(tempSat.getName()); } nickListMsgSb.append("<#NICK_LIST#>"); nickListMsg = nickListMsgSb.toString(); Vector tempv = father.onlineList; size = tempv.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF(nickListMsg); if (tempSat != this) { tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is now online...."); } } } } catch (IOException e) { e.printStackTrace(); } }
public void setValueAt(Object value, int row, int col) { if (rowData.size() > row && row >= 0) { Object[] data = (Object[]) rowData.get(row); data[col] = value; } fireTableCellUpdated(row, col); }
private void moveUpAndDownPage(boolean _up) { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page == null) return; if (_up) { if (index == 0) return; pageList.removeElementAt(index); pageList.insertElementAt(page, index - 1); tabbedPanel.removeTabAt(index); tabbedPanel.insertTab( page.isActive() ? page.getName() : page.getName() + " (D)", null, page.getComponent(), tooltip, index - 1); } else { if (index == (pageList.size() - 1)) return; pageList.removeElementAt(index); pageList.insertElementAt(page, index + 1); tabbedPanel.removeTabAt(index); tabbedPanel.insertTab( page.isActive() ? page.getName() : page.getName() + " (D)", null, page.getComponent(), tooltip, index + 1); } tabbedPanel.setSelectedComponent(page.getComponent()); changed = true; }
public void paintComponent(Graphics g) { g.setColor(new Color(96, 96, 96)); image.paintIcon(this, g, 1, 1); FontMetrics fm = g.getFontMetrics(); String[] args = {jEdit.getVersion()}; String version = jEdit.getProperty("about.version", args); g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5); g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM); int height = fm.getHeight(); int firstLine = scrollPosition / height; int firstLineOffset = height - scrollPosition % height; int lines = (getHeight() - TOP - BOTTOM) / height; int y = firstLineOffset; for (int i = 0; i <= lines; i++) { if (i + firstLine >= 0 && i + firstLine < text.size()) { String line = (String) text.get(i + firstLine); g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y); } y += fm.getHeight(); } }
// 重写paint方法 public void paint(Graphics g) { super.paint(g); // float lineWidth = 3.0f; // ((Graphics2D)g).setStroke(new BasicStroke(lineWidth)); // 将坦克的活动区域填充为默认黑色 g.fillRect(0, 0, 800, 600); this.drawTank(hero.getX(), hero.getY(), g, hero.getDirection(), 1); for (int i = 0; i < hero.bombs.size(); i++) { Bomb myBomb = hero.bombs.get(i); // 画出一颗子弹 if (myBomb != null && myBomb.isLive == true) { // float lineWidth = 2.0f; // ((Graphics2D) g).setStroke(new BasicStroke(lineWidth));//设置线条为粗线 g.draw3DRect(myBomb.x, myBomb.y, 2, 2, true); } if (myBomb.isLive == false) { hero.bombs.remove(myBomb); } } // 画出爆炸 for (int i = 0; i < baozhas.size(); i++) { BaoZha bz = baozhas.get(i); System.out.println("baozhas.size()= " + baozhas.size()); if (bz.life > 5) { g.drawImage(image3, bz.x, bz.y, 30, 30, this); } else if (bz.life > 3) { g.drawImage(image2, bz.x, bz.y, 30, 30, this); } else { g.drawImage(image1, bz.x, bz.y, 30, 30, this); } bz.liftDown(); if (bz.life == 0) { baozhas.remove(bz); } } // 画出敌人的坦克 for (int i = 0; i < ets.size(); i++) { EnemyTank et = ets.get(i); if (et.isLive) { this.drawTank(et.getX(), et.getY(), g, et.getDirection(), 0); } } }
/** * Find the table in the plan, and return the cost and cardinality of the intermediate joined * table during the execution */ private CostCard getCostCard( Vector<LogicalJoinNode> plan, Vector<Integer> planCardinalities, Vector<Double> planCosts, String table) { for (int i = plan.size() - 1; i >= 0; i--) { LogicalJoinNode j = plan.get(i); if (j.t1Alias.equals(table) || (j.t2Alias != null && j.t2Alias.equals(table))) { CostCard c = new CostCard(); c.card = planCardinalities.get(i); c.cost = planCosts.get(i); return c; } } return null; }
/** * Not all editors are capable of displaying new entries. This whips through and removes all * editors that can't. */ private void trimNonNewEntryEditors() { int size = activeEditors.size(); for (int i = size - 1; i >= 0; i--) { if (((DataSink) activeEditors.get(i)).canCreateEntry() == false) { remove(i); } } suggestTableEditor(); // use table editor as default for new entries... }
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ public boolean yaEsta(String nombre) { boolean siOno = false; for (int a = 0; a < vectorJugadores.size(); a++) { if (nombre.equals(vectorJugadores.get(a))) { siOno = true; break; } } return siOno; }
private void renameCurrentPage(String _name) { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; _name = getUniqueName(_name); // Gonzalo 070128 tabbedPanel.setTitleAt(index, _name); Editor page = pageList.get(index); page.setName(_name); if (!page.isActive()) tabbedPanel.setTitleAt(index, page.getName() + " (D)"); changed = true; }
public void run() { if (telephony == null) return; Call createdCall = null; if (contacts != null) { Contact contact = (Contact) contacts.get(0); // NOTE: The multi user call is not yet implemented! // We just get the first contact and create a call for him. try { createdCall = telephony.createCall(contact); } catch (OperationFailedException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(contact.getDisplayName()).setState(e.getMessage()); removeCallPanelWait(callPanel); } // If the call is successfully created we set the created // Call instance to the already existing CallPanel and we // add this call to the active calls. if (createdCall != null) { callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL); activeCalls.put(createdCall, callPanel); } } else { try { createdCall = telephony.createCall(stringContact); } catch (ParseException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(stringContact).setState(e.getMessage()); removeCallPanelWait(callPanel); } catch (OperationFailedException e) { logger.error("The call could not be created: " + e); callPanel.getParticipantPanel(stringContact).setState(e.getMessage()); removeCallPanelWait(callPanel); } // If the call is successfully created we set the created // Call instance to the already existing CallPanel and we // add this call to the active calls. if (createdCall != null) { callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL); activeCalls.put(createdCall, callPanel); } } }
public Object getValueAt(int rowIndex, int columnIndex) { if (timeList != null) { if (rowIndex < timeList.size()) { JCTimeObject ctObj = (JCTimeObject) timeList.get(rowIndex); if (columnIndex == 0) { return ctObj.toString(); } } } return null; }
protected void fireChangeListeners() { if (changeListeners == null) return; for (int a = 0; a < changeListeners.size(); a++) { ChangeListener l = (ChangeListener) changeListeners.get(a); try { l.stateChanged(new ChangeEvent(this)); } catch (RuntimeException e) { e.printStackTrace(); } } }
private void copyPage() { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page == null) return; addPage( typeOfPage(page), this.getUniqueName(page.getName()), page.saveStringBuffer().toString(), true); changed = true; }
/** If a purpose written pluggable editor is available, switch to that, */ public boolean suggestPluggableEditor() { for (int i = activeEditors.size() - 1; i >= 0; i--) { // try to set to the first 'user written' pluggable editor // that can be found... PluggableEditor ed = (PluggableEditor) activeEditors.get(i); if ((ed != templateDisplay) && (ed != tableDisplay)) { setCurrentEditor(ed); return true; } } return false; }
public void client_leave(String msg) { try { Vector tempv = father.onlineList; tempv.remove(this); int size = tempv.size(); String nl = "<#NICK_LIST#>"; for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF("<#MSG#>" + this.getName() + "is offline...."); nl = nl + "|" + tempSat.getName(); } for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) tempv.get(i); tempSat.dout.writeUTF(nl); } this.flag = false; father.refreshList(); } catch (IOException e) { e.printStackTrace(); } }
private void toggleCurrentPage() { int index = tabbedPanel.getSelectedIndex(); if (index < 0) return; Editor page = pageList.get(index); if (page.isActive()) { page.setActive(false); tabbedPanel.setTitleAt(index, page.getName() + " (D)"); } else { page.setActive(true); tabbedPanel.setTitleAt(index, page.getName()); } changed = true; ejs.getModelEditor().getVariablesEditor().updateControlValues(false); }
/** * This can be used to register Swing components that may be used by sub editors to affect the * outside environment. */ public void registerComponents( JMenuBar menu, JToolBar buttons, JTree tree, JPopupMenu treeMenu, JFrame jxplorer) { registerMenu = menu; registerButtons = buttons; registerTree = tree; registerTreeMenu = treeMenu; registerJX = jxplorer; // reset the sub editors as well. for (int i = 0; i < activeEditors.size(); i++) { ((PluggableEditor) activeEditors.get(i)) .registerComponents(menu, buttons, tree, treeMenu, jxplorer); } }
public void surrender(String msg) { try { String name = msg.substring(10); Vector v = father.onlineList; int size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); if (tempSat.getName().equals(name)) { tempSat.dout.writeUTF(msg); break; } } } catch (IOException e) { e.printStackTrace(); } }
public Object getValueAt(int rowIndex, int columnIndex) { SkeletonProperty sp = (SkeletonProperty) m_props.get(rowIndex); switch (columnIndex) { case 0: return sp.getIdName(); case 1: return sp.getLabel(); case 2: return sp.getDescription(); case 3: return sp.getType(); case 4: return sp.getValue(); default: return ""; } }
public void challenge(String msg) { try { String name1 = this.getName(); String name2 = msg.substring(13); Vector v = father.onlineList; int size = v.size(); for (int i = 0; i < size; i++) { ServerAgentThread tempSat = (ServerAgentThread) v.get(i); if (tempSat.getName().equals(name2)) { tempSat.dout.writeUTF("<#CHALLENGE#>" + name1); break; } } } catch (IOException e) { e.printStackTrace(); } }
public Surface getSurfaceUnderVivaeObject(VivaeObject actor) { Vector<Surface> surfacesActorIsOn = new Vector<Surface>(); Surface srfc = null; for (Surface surface : surfaces) { srfc = surface; Area actArea = actor.getArea(); actArea.intersect(srfc.getArea()); if (!actArea.isEmpty()) { surfacesActorIsOn.add(srfc); } } if (surfacesActorIsOn.isEmpty()) { return null; } srfc = surfacesActorIsOn.get(surfacesActorIsOn.size() - 1); return srfc; }
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { SkeletonProperty sp = (SkeletonProperty) m_props.get(rowIndex); switch (columnIndex) { case 0: sp.setIdName(aValue.toString()); break; case 1: sp.setLabel(aValue.toString()); break; case 2: sp.setDescription(aValue.toString()); break; case 3: sp.setType(aValue.toString()); break; case 4: sp.setValue(aValue.toString()); break; } }
public synchronized Object getValueAt(int row, int col) { Node node = nodes.get(row); switch (col) { case 0: return node.getNodeID(); case 1: return node.getCurrState(); case 2: return node.getTailBlockID(); case 3: return node.getHeadBlockID(); case 4: return node.getLocalTime(); case 5: return node.getGlobalTime(); case 6: return node.getIsTimeSynchronized(); case 7: return new LastRequestCellRendererClass(); default: return "UNKNOWN"; } }