List of usage examples for org.apache.commons.lang ArrayUtils indexOf
public static int indexOf(boolean[] array, boolean valueToFind)
Finds the index of the given value in the array.
From source file:net.sf.firemox.tools.Configuration.java
/** * Add a property to the list./*from w w w .j a va 2 s . c o m*/ * * @param property * @param pItem */ public static void addRecentProperty(String property, String pItem) { String item = pItem.replace(",", "\\,"); String[] previous = getArray(property); getConfiguration().clearProperty(property); getConfiguration().setProperty(property + "(0)", item); int index = ArrayUtils.indexOf(previous, item); if (index >= 0) { for (int i = 0; i < index; i++) { getConfiguration().setProperty(property + "(" + i + 1 + ")", previous[i]); } for (int i = index + 1; i < previous.length; i++) { getConfiguration().setProperty(property + "(" + i + ")", previous[i]); } } else { final int maxSize; if (previous.length > MAX_RECENT_SIZE) maxSize = MAX_RECENT_SIZE; else maxSize = previous.length; for (int i = 0; i < maxSize; i++) { getConfiguration().setProperty(property + "(" + i + 1 + ")", previous[i]); } } }
From source file:com.jaspersoft.studio.book.gallery.controls.render.DraggableGroupRenderer.java
/** * Pain the feedback on the gallery item if it is position is provided trought the dropTargetEffect * field/*from w w w . j a v a2 s .c om*/ * * @param graphicContext graphic context to pain the feedback on the gallery item */ protected void paintDropTargetEffect(GC graphicContext) { if (dropTargetEffect != null && dropTargetEffect.isValid()) { int oldStroke = graphicContext.getLineWidth(); graphicContext.setLineWidth(2); GalleryItem elementGroups = dropTargetEffect.getItem().getParentItem(); int index = ArrayUtils.indexOf(elementGroups.getItems(), dropTargetEffect.getItem()); Rectangle itemBounds = dropTargetEffect.getItem().getBounds(); if (dropTargetEffect.isPlacedAfter()) { if (index == (elementGroups.getItemCount() - 1)) { // it's the last element, draw the line after it int xAxis = itemBounds.x + itemBounds.width; graphicContext.drawLine(xAxis, itemBounds.y, xAxis, itemBounds.y + itemBounds.height); } else { // place the line in the middle between the element and the next one GalleryItem nextItem = elementGroups.getItem(index + 1); Rectangle nextItemBounds = nextItem.getBounds(); if (nextItemBounds.y != itemBounds.y) { // the element are on two different levels int xAxis = itemBounds.x + itemBounds.width; graphicContext.drawLine(xAxis, itemBounds.y, xAxis, itemBounds.y + itemBounds.height); } else { DraggableGalleryItemRenderer itemRender = (DraggableGalleryItemRenderer) gallery .getItemRenderer(); Rectangle image1Bounds = itemRender.imagesBounds.get(dropTargetEffect.getItem()); Rectangle image2Bounds = itemRender.imagesBounds.get(nextItem); int mX = image1Bounds.x + image1Bounds.width; int mWidth = image2Bounds.x - mX; int drawLineX = mX + mWidth / 2 - graphicContext.getLineWidth() / 2; graphicContext.drawLine(drawLineX, itemBounds.y, drawLineX, itemBounds.y + itemBounds.height); } } } else { if (index == 0) { // it's the first element, draw the line before it graphicContext.drawLine(itemBounds.x, itemBounds.y, itemBounds.x, itemBounds.y + itemBounds.height); } else { // place the line in the middle between the element and the previous one GalleryItem previousItem = elementGroups.getItem(index - 1); Rectangle previousItemBounds = previousItem.getBounds(); if (previousItemBounds.y != itemBounds.y) { // the element are on two different levels graphicContext.drawLine(itemBounds.x, itemBounds.y, itemBounds.x, itemBounds.y + itemBounds.height); } else { DraggableGalleryItemRenderer itemRender = (DraggableGalleryItemRenderer) gallery .getItemRenderer(); Rectangle image1Bounds = itemRender.imagesBounds.get(previousItem); Rectangle image2Bounds = itemRender.imagesBounds.get(dropTargetEffect.getItem()); int mX = image1Bounds.x + image1Bounds.width; int mWidth = image2Bounds.x - mX; int drawLineX = mX + mWidth / 2 - graphicContext.getLineWidth() / 2; graphicContext.drawLine(drawLineX, itemBounds.y, drawLineX, itemBounds.y + itemBounds.height); } } } graphicContext.setLineWidth(oldStroke); } }
From source file:com.pureinfo.srm.view.function.ShowProductsSelectorFunctionHandler.java
/** * @see com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase#perform(java.lang.Object[], * com.pureinfo.dolphinview.context.model.IDVContext) *//*from w w w .j a v a2 s . com*/ public Object perform(Object[] _args, IDVContext _context) throws PureException { SRMUser user = (SRMUser) _context.getObject(); if (user == null) return ""; IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); // List products = mgr.getMyProduct(user.getId()); String sWorks = user.getWorks(); int[] arrIds = MyViewFunctionHelper.split(sWorks); //return MyViewFunctionHelper.makeDolphinObjectSelectorOption(products, // "id", "productName", listProIds); StringBuffer sbuff = new StringBuffer(); try { Product product; int nId; Date publishDate; for (Iterator iter = products.iterator(); iter.hasNext();) { product = (Product) iter.next(); nId = product.getId(); sbuff.append("<OPTION value=\"").append(nId).append('"'); if (arrIds != null && ArrayUtils.indexOf(arrIds, nId) >= 0) { sbuff.append(" SELECTED"); } sbuff.append('>').append(product.getProductName()); sbuff.append(" [").append(product.getPublisher()).append(']'); publishDate = product.getPublishDate(); if (publishDate != null) { sbuff.append(' ').append(ForceConstants.DATE_FORMAT.format(publishDate)); } sbuff.append("</OPTION>"); } return sbuff.toString(); } finally { sbuff.setLength(0); } }
From source file:com.jaspersoft.studio.property.section.widgets.SPReadCombo.java
public void setItems(String[] items) { setRefreshing(true);/*from w w w. j a v a2s.c o m*/ String currentSelection = combo.getText(); if (ArrayUtils.contains(items, currentSelection)) { combo.setItems(items); combo.select(ArrayUtils.indexOf(items, currentSelection)); setRefreshing(false); } else { setRefreshing(false); combo.setItems(items); combo.select(0); } }
From source file:ch.ralscha.extdirectspring.util.MethodInfoCache.java
/** * Put a method into the MethodCache./*from w ww . ja v a 2s . co m*/ * * @param beanName the name of the bean * @param clazz the class of the bean * @param method the method * @param context the Spring application context */ public void put(String beanName, Class<?> clazz, Method method, ApplicationContext context) { MethodInfo info = new MethodInfo(clazz, context, beanName, method); // START: add by chiknin String group = info.getGroup(); String clrValue = null; Controller contAnn = AnnotationUtils.findAnnotation(clazz, Controller.class); if (contAnn != null) { clrValue = contAnn.value(); } else { Component compAnn = AnnotationUtils.findAnnotation(clazz, Component.class); clrValue = compAnn.value(); } if (StringUtil.isBlank(clrValue)) { clrValue = StringUtil.uncapitalize(clazz.getSimpleName()); } if (StringUtil.isNotBlank(group)) { if (ArrayUtils.indexOf(group.split(","), clrValue) == -1) { group = clrValue + "," + group; } } else { group = clrValue; } ReflectUtil.setFieldValue(info, "group", group); cache.put(new Key(beanName, method.getName()), info); }
From source file:jp.sourceforge.tmdmaker.ui.views.properties.DiagramPropertySource.java
@Override public Object getPropertyValue(Object id) { if (id.equals(NAME)) { return diagram.getName() != null ? diagram.getName() : ""; } else if (id.equals(DATABASE_NAME)) { return ArrayUtils.indexOf(dataBaseList, diagram.getDatabaseName()); } else if (id.equals(DESCRIPTION)) { return diagram.getDescription() != null ? diagram.getDescription() : ""; }//from ww w . j a v a 2s.co m return null; }
From source file:gda.device.detector.countertimer.TfgScalerWithLogValues.java
/** * When set to true ln(I0/It) and ln(I0/Iref) will be added to the output columns * /* w ww. j a va 2 s. c o m*/ * @param outputLogValues * The outputLogValues to set. */ public void setOutputLogValues(boolean outputLogValues) { this.outputLogValues = outputLogValues; // adjust the extraNmaes and outputFormat arrays if (!configured) { return; } if (outputLogValues) { if (!ArrayUtils.contains(extraNames, LNI0IT_LABEL)) { extraNames = (String[]) ArrayUtils.add(extraNames, LNI0IT_LABEL); outputFormat = (String[]) ArrayUtils.add(outputFormat, "%.5f"); } if (!ArrayUtils.contains(extraNames, LNITIREF_LABEL)) { extraNames = (String[]) ArrayUtils.add(extraNames, LNITIREF_LABEL); outputFormat = (String[]) ArrayUtils.add(outputFormat, "%.5f"); } } else { int numInputs = inputNames.length; if (ArrayUtils.contains(extraNames, LNI0IT_LABEL)) { int index = ArrayUtils.indexOf(extraNames, LNI0IT_LABEL); extraNames = (String[]) ArrayUtils.remove(extraNames, index); outputFormat = (String[]) ArrayUtils.remove(outputFormat, index + numInputs); } if (ArrayUtils.contains(extraNames, LNITIREF_LABEL)) { int index = ArrayUtils.indexOf(extraNames, LNITIREF_LABEL); extraNames = (String[]) ArrayUtils.remove(extraNames, index); outputFormat = (String[]) ArrayUtils.remove(outputFormat, index + numInputs); } } }
From source file:net.mumie.coursecreator.graph.cells.MainComponentConstants.java
/** * returns if a category belongs to a Element * @param cat//from w w w . j a v a 2 s . c o m * @return true category is a elementCategory * false category is no elementCategory */ public static boolean isElementCategory(int cat) { int lower = ArrayUtils.indexOf(categories, CAT_DEFINITION); int upper = ArrayUtils.indexOf(categories, CAT_ALGORITHM); return (cat >= lower && cat <= upper); }
From source file:captureplugin.drivers.defaultdriver.configpanels.ChannelTableModel.java
/** * Updates the List of Channels/*from ww w . j av a 2 s . co m*/ */ private void updateChannels() { PluginManager pl = Plugin.getPluginManager(); if (pl == null) { return; } TreeMap<Channel, String> channels = mData.getChannels(); final Channel[] channelArray = pl.getSubscribedChannels(); for (Channel channel : channelArray) { if (!channels.containsKey(channel)) { channels.put(channel, ""); } } mData.setChannels(channels); mChannelRows = new ArrayList<Channel>(mData.getChannels().keySet()); Collections.sort(mChannelRows, new Comparator<Channel>() { public int compare(Channel a, Channel b) { return ArrayUtils.indexOf(channelArray, a) - ArrayUtils.indexOf(channelArray, b); } }); }
From source file:at.tuwien.ifs.commons.gui.controls.MultiOptionToggleButton.java
public MultiOptionToggleButton(final ImageIcon[] icons, final String[] buttonTexts, final String tooltip, final MultiOptionToggleListener listener) { super(icons[0]); this.setToolTipText(tooltip); this.addActionListener(new ActionListener() { @Override//www . j ava 2s .c o m public void actionPerformed(ActionEvent e) { menu.show(MultiOptionToggleButton.this, 0, MultiOptionToggleButton.this.getHeight()); // highlight current selection final Component[] components = menu.getComponents(); for (Component c : components) { c.setBackground(null); } menu.getComponent(selectedIndex).setBackground(Color.GRAY); } }); for (int i = 0; i < buttonTexts.length; i++) { JMenuItem jMenuItem = new JMenuItem(buttonTexts[i], icons[i]); jMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { listener.performAction(e.getActionCommand()); selectedIndex = ArrayUtils.indexOf(buttonTexts, e.getActionCommand()); setIcon(icons[selectedIndex]); } }); menu.add(jMenuItem); } JMenuBar menuBar = new JMenuBar(); menuBar.setBorderPainted(false); menuBar.add(menu); }