/** * Returns the value of the component * * @param nLineInd index of the line in the file. */ protected String getValue(int nLineInd) { JComponent comp = null; String strValue = null; // Get the component corresponding to the line of the file from the list. if (nLineInd < m_aListComp.size()) { comp = (JComponent) m_aListComp.get(nLineInd); } if (comp == null) return strValue; // Get the value of the component if (comp instanceof JTextField) strValue = ((JTextField) comp).getText(); else if (comp instanceof JCheckBox) strValue = ((JCheckBox) comp).isSelected() ? "yes" : "no"; else if (comp instanceof JComboBox) strValue = (String) ((JComboBox) comp).getSelectedItem(); // if the value is of the form: $home, then parse the value /*if (strValue.indexOf('$') >= 0) { String strNewValue = WFileUtil.parseValue(strValue, new HashMap()); if (strNewValue != null && strNewValue.trim().length() > 0) strValue = strNewValue; }*/ return strValue; }
private void attachOrphanRoadsToNearestPath(List<Path> paths) { findOrphanRoads(); ArrayList<Road> orRoads = new ArrayList<Road>(); orRoads.addAll(orphanRoads); while (!orphanRoads.isEmpty()) { for (Road road : orRoads) { boolean isAdded = false; for (Road connectedRoad : roadHelper.getConnectedRoads(road.getID())) { EntityID rPathId = roadHelper.getPathId(connectedRoad.getID()); if (rPathId != null) { isAdded = true; addToPath(road, rPathId, paths); orphanRoads.remove(road); break; } } if (!isAdded) { Path nearestPath = getNearestPath(road, paths); if (nearestPath != null) { adding(road, nearestPath); orphanRoads.remove(road); } } } if (orphanRoads.size() == orRoads.size()) break; orRoads.clear(); orRoads.addAll(orphanRoads); } }
/** * Get Accessible Goals * * @param ctx context * @return array of goals */ public static MGoal[] getGoals(Ctx ctx) { ArrayList<MGoal> list = new ArrayList<MGoal>(); String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo"; sql = MRole.getDefault(ctx, false) .addAccessSQL(sql, "PA_Goal", false, true); // RW to restrict Access PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, (Trx) null); rs = pstmt.executeQuery(); while (rs.next()) { MGoal goal = new MGoal(ctx, rs, null); goal.updateGoal(false); list.add(goal); } } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } finally { DB.closeStatement(pstmt); DB.closeResultSet(rs); } MGoal[] retValue = new MGoal[list.size()]; list.toArray(retValue); return retValue; } // getGoals
private void updateVpInfo() { String key; String vps; for (int j = 0; j < keys.size(); j++) { key = (String) keys.get(j); vps = (String) vpInfo.get(j); if (vps == null || vps.length() <= 0 || vps.equals("all")) { for (int i = 0; i < nviews; i++) { tp_paneInfo[i].put(key, "yes"); } } else { for (int i = 0; i < nviews; i++) tp_paneInfo[i].put(key, "no"); StringTokenizer tok = new StringTokenizer(vps, " ,\n"); while (tok.hasMoreTokens()) { int vp = Integer.valueOf(tok.nextToken()).intValue(); vp--; if (vp >= 0 && vp < nviews) { tp_paneInfo[vp].remove(key); tp_paneInfo[vp].put(key, "yes"); } } } } }
public void switchLayout(int newId, boolean bLayout) { if (layoutId == newId) return; if (newId >= nviews) updateVpInfo(newId + 1); if (bSwitching) { return; } bSwitching = true; int oldId = layoutId; vpId = newId; layoutId = newId; recordCurrentLayout(); VpLayoutInfo vInfo = Util.getViewArea().getLayoutInfo(oldId); if (vInfo != null) { // save current layout info vInfo.tp_selectedTab = tp_selectedTab; vInfo.setVerticalTabName(selectedTabName); // copyCurrentLayout(vInfo); } vInfo = Util.getViewArea().getLayoutInfo(newId); putHsLayout(oldId); if (bLayout) getHsLayout(vpId); for (int i = 0; i < toolList.size(); i++) ((VToolPanel) toolList.get(i)).switchLayout(newId, bLayout); if (bLayout) setCurrentLayout(); /* if(comparePanelLayout(oldId, newId)) { setCurrentLayout(); } if ((vInfo != null) && vInfo.bAvailable && compareCurrentLayout(vInfo)) { setCurrentLayout(vInfo); } for(int i=0; i< toolList.size(); i++) ((VToolPanel) toolList.get(i)).switchLayout(newId); */ // setViewPort(newId); if (bLayout) setCurrentLayout(vInfo); updateValue(); if (bLayout) { if (pinPanel.isOpen()) { if (!pinPanel.isVisible()) pinPanel.setVisible(true); } else pinPanel.setVisible(false); } validate(); repaint(); bSwitching = false; }
private static List<XmlElementDescriptor> computeRequiredSubTags(XmlElementsGroup group) { if (group.getMinOccurs() < 1) return Collections.emptyList(); switch (group.getGroupType()) { case LEAF: XmlElementDescriptor descriptor = group.getLeafDescriptor(); return descriptor == null ? Collections.<XmlElementDescriptor>emptyList() : Collections.singletonList(descriptor); case CHOICE: LinkedHashSet<XmlElementDescriptor> set = null; for (XmlElementsGroup subGroup : group.getSubGroups()) { List<XmlElementDescriptor> descriptors = computeRequiredSubTags(subGroup); if (set == null) { set = new LinkedHashSet<XmlElementDescriptor>(descriptors); } else { set.retainAll(descriptors); } } if (set == null || set.isEmpty()) { return Collections.singletonList(null); // placeholder for smart completion } return new ArrayList<XmlElementDescriptor>(set); default: ArrayList<XmlElementDescriptor> list = new ArrayList<XmlElementDescriptor>(); for (XmlElementsGroup subGroup : group.getSubGroups()) { list.addAll(computeRequiredSubTags(subGroup)); } return list; } }
public boolean moveValid(Square candidateSquare) { if (piece == 0) { setListForKing(); } if (piece == 1) { setListForQueen(); } if (piece == 2) { moveList.clear(); setListForRook(); } if (piece == 3) { setListForKnight(); } if (piece == 4) { setListForBishop(); } if (piece == 5) { setListForPawn(); } if (moveList.contains(candidateSquare.getPosition())) { return true; } return false; }
public synchronized int size() { combine(); if (blocks.size() == 0) return 0; return blocks.get(0).length; }
private List<InjInfo> getSelectedInjections() { final ArrayList<InjInfo> toRemove = new ArrayList<InjInfo>(); for (int row : myInjectionsTable.getSelectedRows()) { toRemove.add(myInjectionsTable.getItems().get(myInjectionsTable.convertRowIndexToModel(row))); } return toRemove; }
public TestType1CFont(InputStream is) throws IOException { super(); setPreferredSize(new Dimension(800, 800)); addKeyListener(this); BufferedInputStream bis = new BufferedInputStream(is); int count = 0; ArrayList<byte[]> al = new ArrayList<byte[]>(); byte b[] = new byte[32000]; int len; while ((len = bis.read(b, 0, b.length)) >= 0) { byte[] c = new byte[len]; System.arraycopy(b, 0, c, 0, len); al.add(c); count += len; b = new byte[32000]; } data = new byte[count]; len = 0; for (int i = 0; i < al.size(); i++) { byte from[] = al.get(i); System.arraycopy(from, 0, data, len, from.length); len += from.length; } pos = 0; // printData(); parse(); // TODO: free up (set to null) unused structures (data, subrs, stack) }
/** Pastes Items from the Clipboard on the Board */ public void paste() { ComponentSelection clipboardContent = (ComponentSelection) tbe.getClipboard().getContents(this); if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(ComponentSelection.itemFlavor))) { Object[] tempItems = null; try { tempItems = board.cloneItems(clipboardContent.getTransferData(ComponentSelection.itemFlavor)); } catch (UnsupportedFlavorException e1) { e1.printStackTrace(); } ItemComponent[] items = new ItemComponent[tempItems.length]; for (int i = 0; i < tempItems.length; i++) { items[i] = (ItemComponent) tempItems[i]; } PasteCommand del = new PasteCommand(items); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(del); tbe.addCommands(actCommands); board.addItem(items); } }
private void createPainToTree3true( final DefaultTreeModel treeModel, DefaultMutableTreeNode root, Collection paintCollection) { ArrayList a = (ArrayList) paintCollection; Iterator i = a.iterator(); Person p = null; Person parent = null; DefaultMutableTreeNode parentNode = root; DefaultMutableTreeNode newNode; while (i.hasNext()) { p = (Person) i.next(); int ves, ves2; if (parent != null) { parent = (Person) parentNode.getUserObject(); ves = comparePerson(p, (Person) parentNode.getUserObject()); ves2 = comparePersonAsString(p, (Person) parentNode.getUserObject()) + 1; System.out.println("ves = " + ves + " ves2= " + ves2); switch (ves) { case 0: { parentNode = root; parent = null; break; } case 1: { } } } newNode = new DefaultMutableTreeNode(p); parentNode.add(newNode); parent = p; parentNode = newNode; } }
/* -------------------------------------------------------------*/ private void objectCollision(ArrayList movingObjects) { for (int i = 0; i < movingObjects.size(); i++) { // make sure not testing if collided with yourself :P if (((SpaceObject) movingObjects.get(i)).getObjCount() != objectNum) { SpaceObject object = (SpaceObject) movingObjects.get(i); // find distance vector between two objects int x = pos_x - object.getXPos(); int y = pos_y - object.getYPos(); double distance = Math.sqrt(x * x + y * y); // has it collided with the object? if (distance < (radius + object.getRadius())) { // has it collided with a BULLET (or MISSILE)? if (object.isBullet()) { // do nothing } // is it another SPACESHIP? (INSTANT DEATH) else if (object.isSpaceShip()) { // do nothing } // collided with anything else (e.g PLANET): (INSTANT DEATH) else { collision.play(); kill(movingObjects); // object has died } } } } // end for loop }
/* -------------------------------------------------------------*/ private void gravityEffect(ArrayList movingObjects) { // find effect of gravity on this objects from all other objects for (int i = 0; i < movingObjects.size(); i++) { // reset variables double add_vx = 0.0; double add_vy = 0.0; SpaceObject object = (SpaceObject) movingObjects.get(i); if (object.getObjCount() != objectNum && // ignore yourself (distance = 0!) !object.isBullet() && // ignore bullets !object.isSpaceShip()) // ignore spaceships { // find distance vector between planet and ball int x = pos_x - object.getXPos(); int y = pos_y - object.getYPos(); double distance = Math.sqrt(x * x + y * y); // find effect of planet on velocity double add_vec = (SpaceObject.G * k * object.getMass() * ballMass) / (distance * distance); add_vx = -(x / distance) * add_vec; add_vy = -(y / distance) * add_vec; // add objects speeds onto spaceship speed (clip speed if too large) x_speed += add_vx; y_speed += add_vy; } } }
public void updatePickups() { for (int i = 0; i < pickupList.size(); i++) { if (pickupList.get(i).pickedUp) pickupList.remove(i); } // end for while (pickupList.size() < startNumPickups) pickupList.add(new Pickup(frameWidth, frameHeight)); } // end updatePickups
public void totalExport() { File expf = new File("export"); if (expf.exists()) rmrf(expf); expf.mkdirs(); for (int sto = 0; sto < storeLocs.size(); sto++) { try { String sl = storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-"); File estore = new File(expf, sl); estore.mkdir(); File log = new File(estore, LIBRARY_NAME); PrintWriter pw = new PrintWriter(log); for (int i = 0; i < store.getRowCount(); i++) if (store.curStore(i) == sto) { File enc = store.locate(i); File dec = sec.prepareMainFile(enc, estore, false); pw.println(dec.getName()); pw.println(store.getValueAt(i, Storage.COL_DATE)); pw.println(store.getValueAt(i, Storage.COL_TAGS)); synchronized (jobs) { jobs.addLast(expJob(enc, dec)); } } pw.close(); } catch (IOException exc) { exc.printStackTrace(); JOptionPane.showMessageDialog(frm, "Exporting Failed"); return; } } JOptionPane.showMessageDialog(frm, "Exporting to:\n " + expf.getAbsolutePath()); }
public void draw(Graphics g, ImagesLoader imLoad) { for (int i = 0; i < pickupList.size(); i++) { Pickup p = pickupList.get(i); BufferedImage img = imLoad.getImage(p.type); g.drawImage(img, (int) p.x, (int) p.y, null); } // end for } // end draw
public ArrayList<CellTagPair> findMarkupTags() { Pattern tagPattern = Pattern.compile("\\{(.+?)\\}"); ArrayList<CellTagPair> result = new ArrayList<CellTagPair>(); int width = getWidth(); int height = getHeight(); for (int y = 0; y < height; y++) { for (int x = 0; x < width - 3; x++) { Cell cell = new Cell(x, y); char c = get(cell); if (c == '{') { String rowPart = rows.get(y).substring(x); Matcher matcher = tagPattern.matcher(rowPart); if (matcher.find()) { String tagName = matcher.group(1); if (markupTags.contains(tagName)) { if (DEBUG) System.out.println("found tag " + tagName + " at " + x + ", " + y); result.add(new CellTagPair(new Cell(x, y), tagName)); } } } } } return result; }
public ArrayList<String> getMoveList() { moveList.clear(); if (piece == 0) { setListForKing(); } if (piece == 1) { setListForQueen(); } if (piece == 2) { moveList.clear(); squareList.clear(); setListForRook(); } if (piece == 3) { setListForKnight(); } if (piece == 4) { setListForBishop(); } if (piece == 5) { setAttacksForPawn(); } return moveList; }
/** Flashes the visual bell. This class has no other public API. */ public void flash() { if (GuiUtilities.isMacOs()) { // Mac OS has a system-wide "visual bell" that looks much better than ours. // You can turn this on in the Universal Access preference pane, by checking "Flash the screen // when an alert sound occurs". // We can take advantage of Apple's hard work if the user has this turned on by "actually" // ringing the bell. // This doesn't change our "no noise pollution" policy, if you ignore the very unlikely race // condition. ArrayList<String> result = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>(); int status = ProcessUtilities.backQuote( null, new String[] { "defaults", "-currentHost", "read", "Apple Global Domain", "com.apple.sound.beep.flash" }, result, errors); if (status == 0 && errors.size() == 0 && result.size() == 1 && result.get(0).equals("1")) { Toolkit.getDefaultToolkit().beep(); return; } } setBellVisibility(true); timer.restart(); }
/** * Returns all editors. * * @return editors */ EditorArea[] editors() { final ArrayList<EditorArea> edits = new ArrayList<EditorArea>(); for (final Component c : tabs.getComponents()) { if (c instanceof EditorArea) edits.add((EditorArea) c); } return edits.toArray(new EditorArea[edits.size()]); }
/** * Remove a child Widget from this container. * * @param index the index of the Widget to remove */ public void remove(int index) { Widget w = child.get(index).widget; getComponent().remove(w.getComponent()); child.remove(index); removeAsParent(w); invalidateSize(); }
public void putHsLayout(int id) { Hashtable hs = sshare.userInfo(); if (hs == null) return; String key, name; JComponent obj; PushpinIF pobj; for (int i = 0; i < keys.size(); i++) { key = (String) keys.get(i); obj = (JComponent) panes.get(key); if (obj != null && (obj instanceof PushpinIF)) { pobj = (PushpinIF) obj; name = "tabTool." + id + "." + pobj.getName() + "."; hs.put(name + "refY", new Float(pobj.getRefY())); hs.put(name + "refX", new Float(pobj.getRefX())); hs.put(name + "refH", new Float(pobj.getRefH())); key = "open"; if (pobj.isHide()) key = "hide"; else if (pobj.isClose()) key = "close"; hs.put(name + "status", key); } } /* name = "tabTool."+id+".TabPanel."; key = pinPanel.getLastName(); if (key != null) hs.put(name+"lastName", key); key = "open"; if (pinPanel.isHide()) key = "hide"; else if (pinPanel.isClose()) key = "close"; hs.put(name+"status", key); */ }
@NotNull public EditorWindow[] getOrderedWindows() { final ArrayList<EditorWindow> res = new ArrayList<EditorWindow>(); // Collector for windows in tree ordering: class Inner { final void collect(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; collect((JPanel) splitter.getFirstComponent()); collect((JPanel) splitter.getSecondComponent()); } else if (comp instanceof JPanel || comp instanceof JBTabs) { final EditorWindow window = findWindowWith(comp); if (window != null) { res.add(window); } } } } // get root component and traverse splitters tree: if (getComponentCount() != 0) { final Component comp = getComponent(0); LOG.assertTrue(comp instanceof JPanel); final JPanel panel = (JPanel) comp; if (panel.getComponentCount() != 0) { new Inner().collect(panel); } } LOG.assertTrue(res.size() == myWindows.size()); return res.toArray(new EditorWindow[res.size()]); }
public void addProgress(@NotNull ProgressIndicatorEx original, @NotNull TaskInfo info) { synchronized (myOriginals) { final boolean veryFirst = !hasProgressIndicators(); myOriginals.add(original); myInfos.add(info); final InlineProgressIndicator expanded = createInlineDelegate(info, original, false); final InlineProgressIndicator compact = createInlineDelegate(info, original, true); myPopup.addIndicator(expanded); myProgressIcon.resume(); if (veryFirst && !myPopup.isShowing()) { buildInInlineIndicator(compact); } else { buildInProcessCount(); if (myInfos.size() > 1 && Registry.is("ide.windowSystem.autoShowProcessPopup")) { openProcessPopup(false); } } runQuery(); } }
public void bringToFront(Figure figure) { if (children.remove(figure)) { children.add(figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
/** * Get Restriction Lines * * @param reload reload data * @return array of lines */ public MGoalRestriction[] getRestrictions(boolean reload) { if (m_restrictions != null && !reload) return m_restrictions; ArrayList<MGoalRestriction> list = new ArrayList<MGoalRestriction>(); // String sql = "SELECT * FROM PA_GoalRestriction " + "WHERE PA_Goal_ID=? AND IsActive='Y' " + "ORDER BY Org_ID, C_BPartner_ID, M_Product_ID"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_Trx()); pstmt.setInt(1, getPA_Goal_ID()); rs = pstmt.executeQuery(); while (rs.next()) list.add(new MGoalRestriction(getCtx(), rs, get_Trx())); } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { DB.closeStatement(pstmt); DB.closeResultSet(rs); } // m_restrictions = new MGoalRestriction[list.size()]; list.toArray(m_restrictions); return m_restrictions; } // getRestrictions
public void sendToBack(Figure figure) { if (children.remove(figure)) { children.add(0, figure); needsSorting = true; fireAreaInvalidated(figure.getDrawingArea()); } }
public void createBuildings() { bList = new ArrayList<Building>(); // resource bList.add(new Building("Gold Mine", 3, 3, 960, 7)); bList.add(new Building("Elixir Collector", 3, 3, 960, 7)); // bList.add(new Building("Dark Elixir Drill", 3, 3, 1160, 3)); bList.add(new Building("Gold Storage", 3, 3, 2100, 4)); bList.add(new Building("Elixir Storage", 3, 3, 2100, 4)); // bList.add(new Building("Dark Elixir Storage", 3, 3, 3200, 1)); // bList.add(new Building("Builder Hut", 2, 2, 250, 5)); // army bList.add(new Building("Army Camp", 5, 5, 500, 4)); bList.add(new Building("Barracks", 3, 3, 860, 4)); // bList.add(new Building("Dark Barracks", 3, 3, 900, 2)); // bList.add(new Building("Laboratory", 4, 4, 950, 1)); // bList.add(new Building("Spell Factory", 3, 3, 615, 1)); // bList.add(new Building("Barbarian King Altar", 3, 3, 250, 1)); // bList.add(new Building("Dark Spell Factory", 3, 3, 750, 1)); // bList.add(new Building("Archer Queen Altar", 3, 3, 250, 1)); // other bList.add(new Building("Town Hall", 4, 4, 5500, 1)); bList.add(new Building("Clan Castle", 3, 3, 3400, 1)); // defense bList.add(new Building("Archer Tower", 3, 3, 1050, 7)); bList.add(new Building("Cannon", 3, 3, 1260, 6)); bList.add(new Building("Wall", 1, 1, 7000, 275)); // bList.add(new Building("Air Sweeper", 2, 2, 1000, 2)); // bList.add(new Building("Cannon", 3, 3, 1260, 6)); // bList.add(new Building("Cannon", 3, 3, 1260, 6)); }
/** * When the user has to specify file names, he can use wildcards (*, ?). This methods handles the * usage of these wildcards. * * @param path The path were to search * @param s Wilcards * @param sort Set to true will sort file names * @return An array of String which contains all files matching <code>s</code> in current * directory. */ public static String[] getWildCardMatches(String path, String s, boolean sort) { if (s == null) return null; String files[]; String filesThatMatch[]; String args = new String(s.trim()); ArrayList filesThatMatchVector = new ArrayList(); if (path == null) path = getUserDirectory(); files = (new File(path)).list(); if (files == null) return null; for (int i = 0; i < files.length; i++) { if (match(args, files[i])) { File temp = new File(getUserDirectory(), files[i]); filesThatMatchVector.add(new String(temp.getName())); } } Object[] o = filesThatMatchVector.toArray(); filesThatMatch = new String[o.length]; for (int i = 0; i < o.length; i++) filesThatMatch[i] = o[i].toString(); o = null; filesThatMatchVector = null; if (sort) Arrays.sort(filesThatMatch); return filesThatMatch; }