List of usage examples for java.awt List add
public void add(String item)
From source file:Main.java
public static void main(String[] args) { Frame f = new Frame("FlowLayout demo"); f.setLayout(new FlowLayout()); f.add(new Button("Red")); f.add(new Button("Blue")); f.add(new Button("White")); List list = new List(); for (int i = 0; i < args.length; i++) { list.add(args[i]); }/*from w w w. j av a 2 s.c o m*/ f.add(list); f.add(new Checkbox("Pick me", true)); f.add(new Label("Enter name here:")); f.add(new TextField(20)); f.pack(); f.setVisible(true); }
From source file:Main.java
public static java.util.List<Component> getAllComponents(final Container container) { Component[] comps = container.getComponents(); java.util.List<Component> compList = new ArrayList<>(); for (Component comp : comps) { compList.add(comp); if (comp instanceof Container) { compList.addAll(getAllComponents((Container) comp)); }//from w w w .java 2s. co m } return compList; }
From source file:Main.java
public static java.util.List<Component> getComponents(Container container, String classString) { java.util.List<Component> list = new ArrayList<>(); for (Component component : getAllComponents(container)) { if (component.getClass().toString().endsWith(classString)) { list.add(component); }/* ww w. j a v a2 s . c o m*/ } return list; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java
public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx, final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller, final java.util.Collection<String> attrs) throws Exception { final Instances dataSetWithTheGap = new Instances(pdataSet); for (int i = position; i < position + gapsize; i++) dataSetWithTheGap.instance(i).setMissing(attr); int[] arr = new int[] { attr.index(), dateIdx }; for (final String sss : attrs) { arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() }); }/* w w w . j av a 2 s . c o m*/ Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap, arr); filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0, filteredDsWithTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithTheGap.numInstances() - 1)); final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap); final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds); Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr); filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0, filteredDsWithoutTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithoutTheGap.numInstances() - 1)); diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes()); for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) { diff.instance(i).setValue(diff.numAttributes() - 1, filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name()))); } //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final java.util.List<String> toRemove = new java.util.ArrayList<String>(); for (int j = 0; j < diff.numAttributes(); j++) { final String consideredAttrName = diff.attribute(j).name(); if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name())) toRemove.add(consideredAttrName); } diff.setClassIndex(-1); for (final String ssss : toRemove) diff.deleteAttributeAt(diff.attribute(ssss).index()); //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false, WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null); final XYPlot xyp = (XYPlot) cp.getChart().getPlot(); xyp.getDomainAxis().setLabel(""); xyp.getRangeAxis().setLabel(""); final Marker gapBeginMarker = new ValueMarker( dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx)); gapBeginMarker.setPaint(Color.RED); gapBeginMarker.setLabel("Gap begin"); gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker); final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx)); gapEndMarker.setPaint(Color.RED); gapEndMarker.setLabel("Gap end"); gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); cp.getChart().getXYPlot().addDomainMarker(gapEndMarker); addExportPopupMenu(diff, cp); return cp; }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithScatterPlot.java
/** * Create a scatterplot with the logs of the values passed in * @param xValues// www . j a v a2s . co m * @param yValues * @param dataSetName * @return */ public static PanelWithScatterPlot createPlotForLogValues(java.util.List<? extends Number> xValues, java.util.List<? extends Number> yValues, String dataSetName) { java.util.List<Double> xValuesLog = new ArrayList<Double>(); java.util.List<Double> yValuesLog = new ArrayList<Double>(); for (int i = 0; i < xValues.size(); i++) { xValuesLog.add(Math.log(xValues.get(i).doubleValue())); yValuesLog.add(Math.log(yValues.get(i).doubleValue())); } return new PanelWithScatterPlot(xValuesLog, yValuesLog, dataSetName); }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
public static ChartPanel buildChartPanelForNominalAttribute(final Instances ds, final Attribute attr, final int dateIdx) { final TaskSeriesCollection localTaskSeriesCollection = new TaskSeriesCollection(); final java.util.List<String> names = new ArrayList<String>(); final Set<String> present = WekaDataStatsUtil.getPresentValuesForNominalAttribute(ds, attr.index()); for (final String pr : present) { names.add(pr); localTaskSeriesCollection.add(new TaskSeries(pr)); }//from w ww. ja v a 2s. c o m final Calendar cal = Calendar.getInstance(); try { for (final double[] dd : WekaTimeSeriesUtil.split(ds, attr.index())) { cal.setTimeInMillis((long) dd[0]); final Date start = cal.getTime(); cal.setTimeInMillis((long) dd[1]); final Date end = cal.getTime(); final String sd = ds.instance((int) dd[2]).stringValue(attr); localTaskSeriesCollection.getSeries(sd).add(new Task("T", start, end)); } } catch (Exception e) { e.printStackTrace(); } final XYTaskDataset localXYTaskDataset = new XYTaskDataset(localTaskSeriesCollection); localXYTaskDataset.setTransposed(true); localXYTaskDataset.setSeriesWidth(0.6D); final DateAxis localDateAxis = new DateAxis(DATE_TIME_LABEL); final SymbolAxis localSymbolAxis = new SymbolAxis("", names.toArray(new String[names.size()])); localSymbolAxis.setGridBandsVisible(false); final XYBarRenderer localXYBarRenderer = new XYBarRenderer(); localXYBarRenderer.setUseYInterval(true); localXYBarRenderer.setShadowVisible(false); final XYPlot localXYPlot = new XYPlot(localXYTaskDataset, localDateAxis, localSymbolAxis, localXYBarRenderer); final CombinedDomainXYPlot localCombinedDomainXYPlot = new CombinedDomainXYPlot( new DateAxis(DATE_TIME_LABEL)); localCombinedDomainXYPlot.add(localXYPlot); final JFreeChart localJFreeChart = new JFreeChart("", localCombinedDomainXYPlot); localJFreeChart.setBackgroundPaint(Color.white); final ChartPanel cp = new ChartPanel(localJFreeChart, true); cp.setBorder(new TitledBorder(attr.name())); return cp; }
From source file:com.aw.swing.mvp.JDialogView.java
private void setupIcons(JDialog dialog) { java.util.List list = new ArrayList(); list.add(imageIcon.getImage()); list.add(imageIconBig.getImage());// w w w .j a va 2 s . c o m dialog.setIconImages(list); }
From source file:Sampler.java
private void createUI() { setFont(new Font("Serif", Font.PLAIN, 12)); setLayout(new BorderLayout()); // Set our location to the left of the image frame. setSize(200, 350);//w w w . ja v a 2 s . c o m Point pt = mImageFrame.getLocation(); setLocation(pt.x - getSize().width, pt.y); final Checkbox accumulateCheckbox = new Checkbox("Accumulate", false); final Label statusLabel = new Label(""); // Make a sorted list of the operators. Enumeration e = mOps.keys(); Vector names = new Vector(); while (e.hasMoreElements()) names.addElement(e.nextElement()); Collections.sort(names); final java.awt.List list = new java.awt.List(); for (int i = 0; i < names.size(); i++) list.add((String) names.elementAt(i)); add(list, BorderLayout.CENTER); // When an item is selected, do the corresponding transformation. list.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() != ItemEvent.SELECTED) return; String key = list.getSelectedItem(); BufferedImageOp op = (BufferedImageOp) mOps.get(key); BufferedImage source = mSplitImageComponent.getSecondImage(); boolean accumulate = accumulateCheckbox.getState(); if (source == null || accumulate == false) source = mSplitImageComponent.getImage(); String previous = mImageFrame.getTitle() + " + "; if (accumulate == false) previous = ""; mImageFrame.setTitle(previous + key); statusLabel.setText("Performing " + key + "..."); list.setEnabled(false); accumulateCheckbox.setEnabled(false); BufferedImage destination = op.filter(source, null); mSplitImageComponent.setSecondImage(destination); mSplitImageComponent.setSize(mSplitImageComponent.getPreferredSize()); mImageFrame.setSize(mImageFrame.getPreferredSize()); list.setEnabled(true); accumulateCheckbox.setEnabled(true); statusLabel.setText("Performing " + key + "...done."); } }); Button loadButton = new Button("Load..."); loadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { FileDialog fd = new FileDialog(Sampler.this); fd.show(); if (fd.getFile() == null) return; String path = fd.getDirectory() + fd.getFile(); mSplitImageComponent.setImage(path); mSplitImageComponent.setSecondImage(null); // Utilities.sizeContainerToComponent(mImageFrame, // mSplitImageComponent); mImageFrame.validate(); mImageFrame.repaint(); } }); Panel bottom = new Panel(new GridLayout(2, 1)); Panel topBottom = new Panel(); topBottom.add(accumulateCheckbox); topBottom.add(loadButton); bottom.add(topBottom); bottom.add(statusLabel); add(bottom, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { mImageFrame.dispose(); dispose(); System.exit(0); } }); }
From source file:com.kbot2.scriptable.methods.wrappers.Interface.java
public Interface[] getChildren() { if (inter != null) { java.util.List<Interface> out = new LinkedList<Interface>(); IComponent[] interfaces = inter.getChildren(); if (interfaces == null) return null; for (IComponent child : interfaces) { if (child == null) continue; out.add(new Interface(botEnv, child, this, parrentInterfaceGroup)); }// w w w . ja v a 2 s.c o m return out.toArray(new Interface[1]); } return null; }
From source file:com.jhash.oimadmin.ui.UIJavaCompile.java
@Override public void initializeComponent() { logger.debug("Initializing {}", this); this.outputDirectory = configuration.getWorkArea() + Config.VAL_WORK_AREA_CLASSES + File.separator + System.currentTimeMillis(); logger.debug("Compile output directory {}", outputDirectory); File templateDirectory = new File(configuration.getWorkArea() + File.separator + Config.VAL_WORK_AREA_CONF + File.separator + "templates"); logger.debug("Trying to validate template directory {} exists and is directory", templateDirectory); if (templateDirectory.exists() && templateDirectory.isDirectory()) { logger.debug("Trying to list files in directory"); String[] listOfFile = templateDirectory.list(new FilenameFilter() { @Override/*from w w w.j a va 2s.c om*/ public boolean accept(File dir, String name) { logger.trace("Validating file {}", name); if (name.startsWith(templatePrefix)) { logger.trace("File {} begins with prefix", name); return true; } return false; } }); java.util.List<String> fixedListOfFile = new ArrayList<>(); logger.debug("Extract class name and display name from file names {}", listOfFile); for (String fileName : listOfFile) { String fileSuffix = fileName.replaceAll(templatePrefix, ""); logger.trace("Adding class {} to list", fileSuffix); fixedListOfFile.add(fileSuffix); } if (fixedListOfFile != null && fixedListOfFile.size() > 0) { logger.debug("Creating combo-box with values {}", fixedListOfFile); sourceCodeSelector = new JComboBox<String>(fixedListOfFile.toArray(new String[0])); sourceCodeSelector.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.debug("Event {} triggered on combo box {}", e, sourceCodeSelector); String sourceCodeSelected = (String) sourceCodeSelector.getSelectedItem(); if (sourceCodeSelector != null) { logger.debug("Trying to read file for selected source code {}", sourceCodeSelected); String readData = Utils.readFile(templatePrefix + sourceCodeSelected, templateDirectory.getAbsolutePath()); sourceCode.setText(readData); classNameText.setText(sourceCodeSelected); } } }); sourceCodeSelector.setSelectedIndex(0); } } compileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { logger.debug("Triggered action {} on {}", e, compileButton); compile(); logger.debug("Completed action {} on {}", e, compileButton); } catch (Exception exception) { displayMessage("Compilation failed", "Failed to compile", exception); } } }); javaCompileUI = buildCodePanel(); }