List of usage examples for javax.swing GroupLayout setAutoCreateGaps
public void setAutoCreateGaps(boolean autoCreatePadding)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("GroupLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); GroupLayout groupLayout = new GroupLayout(contentPane); groupLayout.setAutoCreateGaps(true); groupLayout.setAutoCreateContainerGaps(true); contentPane.setLayout(groupLayout);//from ww w.j a v a 2 s . c om JButton b1 = new JButton("Button 1"); JButton b2 = new JButton("Button Second"); JButton b3 = new JButton("3"); JButton b4 = new JButton("4"); groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(LEADING).addComponent(b1).addComponent(b3)) .addGroup(groupLayout.createParallelGroup(TRAILING).addComponent(b2).addComponent(b4))); groupLayout.setVerticalGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b1).addComponent(b2)) .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b3).addComponent(b4))); frame.pack(); frame.setVisible(true); }
From source file:org.xapagy.ui.tempdyn.tdVisualizationGenerator.java
/** * Generate a vertical list of JFreeCharts * //w ww . ja v a2 s . c om * @param labels * - the labels for the values * @param index * - the index * @param values * @return */ public static String generateJFreeChart(List<String> labels, List<Double> index, List<List<Double>> values) { JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); for (int i = 0; i != labels.size(); i++) { XYSeries xys = new XYSeries(labels.get(i)); for (int j = 0; j != index.size(); j++) { xys.add(index.get(j), values.get(i).get(j)); } XYSeriesCollection xysc = new XYSeriesCollection(xys); JFreeChart chart = ChartFactory.createXYLineChart(labels.get(i), "Time", "Focus", xysc, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14)); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); } JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); return null; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Graphs the evolution of the links of all types (PRED, SUCC, SUMMARY, * CONTEXT etc) between two Vis./* w ww.j a v a 2s. c om*/ * * @param fromVi * @param toVi * @param tdb * @param agent * @param index * - a list of time points which will be plotted on the x axis */ public static void graphLinksBetweenVis(tdComponent fromVi, tdComponent toVi, tdDataBase tdb, Agent agent, List<Double> index) { String label = "Links between " + fromVi.getIdentifier() + " and " + toVi.getIdentifier(); // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // add a series for each link type for (String linkName : agent.getLinks().getLinkTypeNames()) { XYSeries linkSeries = new XYSeries(linkName); xysc.addSeries(linkSeries); // now fill in the series with values for (Double time : index) { double dtime = time; double linkValue = tdb.getLinkValue(fromVi.getIdentifier(), toVi.getIdentifier(), linkName, time); linkSeries.add(dtime, linkValue); } } // // ok, now let us create a graph // JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); JFreeChart chart = ChartFactory.createXYLineChart(label, "Time", "Value", xysc, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Generates the graph which plots the three choice scores (independent, * dependent and mood) for the evolution of a choice in time. * /*from ww w. j av a 2s . c o m*/ * @param tdc * - encompasses the selected choice * @param database * - the database of values collected * @param agent * @param index * - a list of time points which will be plotted on the x axis * @param choiceRange * - the y axis will be [0, choiceRange] */ public static void graphChoiceEvolution(tdComponent tdc, tdDataBase database, Agent agent, List<Double> index, double choiceRange) { String label = PpChoice.ppConcise(tdc.getChoice(), agent); // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); // focus and memory xysc.addSeries(new XYSeries("ChoiceScoreIndependent")); xysc.addSeries(new XYSeries("ChoiceScoreDependent")); xysc.addSeries(new XYSeries("ChoiceScoreMood")); // Fill in the values for (Double time : index) { double dtime = time; double valueChoiceScoreIndependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreIndependent").add(dtime, valueChoiceScoreIndependent); double valueChoiceScoreDependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreDependent").add(dtime, valueChoiceScoreDependent); double valueChoiceScoreMood = database.getChoiceScoreDependent(tdc.getIdentifier(), time); xysc.getSeries("ChoiceScoreMood").add(dtime, valueChoiceScoreMood); } // // ok, now let us create a graph // JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); // // the graph with the focus and the memory // XYSeriesCollection xysFM = new XYSeriesCollection(); xysFM.addSeries(xysc.getSeries("ChoiceScoreIndependent")); xysFM.addSeries(xysc.getSeries("ChoiceScoreDependent")); xysFM.addSeries(xysc.getSeries("ChoiceScoreMood")); JFreeChart chart = ChartFactory.createXYLineChart(label + " - Choice", "Time", "Value", xysFM, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * This function generates a frame into which a number of graphs are * arranged horizontally. Each graph describes the time series values for a * given in-focus object. We have: the focus (with all the energy colors - * salience / energy), the memory (with all the energy colors - salience / * energy), and a list of shadows (with all the energy colors - salience / * energy).//from w w w . j av a 2 s.c om * * @param tdc * @param database * @param agent * @param index * - the index of time values * @param isInstance * - true for instances * @param shadowComponents * - how many components will we enter in the graph * @param shadowRange * - the range of the y plot on the shadows - needs to be unique. * * */ public static void graphFMSComposite(tdComponent tdc, tdDataBase database, Agent agent, List<Double> index, int shadowComponents, double shadowRange, GraphEvolutionDescriptor ged) { String label = tdc.getLastPrettyPrint(); // FIXME: this is a tiny bit iffy: we are getting the shadows based on a // certain energy color String ecx = EnergyColors.SHI_GENERIC; List<String> shadowList = database.getShadowComponents(tdc.getIdentifier(), ecx, shadowComponents); // // ok, now let us create a graph // JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); // // the graph with the focus values // if (ged.graphFocusEnergy || ged.graphFocusSalience) { JFreeChart chart = chartFocusEvolution(tdc, label, database, agent, index, ged); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); } // // the graph with the memory values // if (ged.graphMemoryEnergy || ged.graphMemorySalience) { JFreeChart chart = chartMemoryEvolution(tdc, label, database, agent, index, ged); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); } // // the graphs with the shadow components // if (ged.graphShadowEnergy || ged.graphShadowSalience) { for (String sh : shadowList) { JFreeChart chart = chartShadowEvolution(tdc, sh, database, agent, index, shadowRange, ged); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); } } JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Graphs which plots the evolution of all the links from a given VI. If the * linkType is not null, it filters based on that, otherwise, it plots all * the link types//from w w w .j a v a 2 s. c om * * @param fromVi * @param linkType * @param tdb * @param agent * @param index */ public static void graphLinksFromAVi(tdComponent fromVi, String linkType, tdDataBase tdb, Agent agent, List<Double> index) { String label; if (linkType != null) { label = "Links of type " + linkType + " from " + fromVi.getIdentifier(); } else { label = "Links of all types from " + fromVi.getIdentifier(); } // create a general purpose xy collection for jfreechart XYSeriesCollection xysc = new XYSeriesCollection(); List<tdComponent> linkedVis = tdb.getFocusVis(); List<String> types = new ArrayList<>(); if (linkType != null) { types.add(linkType); } else { types.addAll(agent.getLinks().getLinkTypeNames()); } // add a series for each VI - if not null for (tdComponent toVi : linkedVis) { for (String linkName : types) { boolean addDecision = false; String id; if (linkType != null) { id = toVi.getIdentifier() + "-" + toVi.getLastPrettyPrint(); } else { id = linkName + " to " + toVi.getIdentifier() + "-" + toVi.getLastPrettyPrint(); } XYSeries linkSeries = new XYSeries(id); // now fill in the series with values for (Double time : index) { double dtime = time; double linkValue = tdb.getLinkValue(fromVi.getIdentifier(), toVi.getIdentifier(), linkName, time); if (linkValue != 0.0) { addDecision = true; } linkSeries.add(dtime, linkValue); } if (addDecision) { xysc.addSeries(linkSeries); } } } // // ok, now let us create a graph // JPanel panel = new JPanel(); // create a layout GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); SequentialGroup sgv = layout.createSequentialGroup(); layout.setVerticalGroup(sgv); ParallelGroup pgh = layout.createParallelGroup(); layout.setHorizontalGroup(pgh); JFreeChart chart = ChartFactory.createXYLineChart(label, "Time", "Value", xysc, PlotOrientation.VERTICAL, true, false, false); GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful); ChartPanel cp = new ChartPanel(chart); sgv.addComponent(cp); pgh.addComponent(cp); JFrame frame = new JFrame(); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
private JPanel create() { JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);/*from w w w .j a v a2 s .c o m*/ layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); GroupLayout.ParallelGroup parallel = layout.createParallelGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(parallel)); GroupLayout.SequentialGroup sequential = layout.createSequentialGroup(); layout.setVerticalGroup(sequential); for (int i = 0; i < NUM; i++) { labels[i] = new JLabel(String.valueOf(i + 1), JLabel.RIGHT); fields[i] = new JTextField(String.valueOf("" + (i + 1))); labels[i].setLabelFor(fields[i]); parallel.addGroup(layout.createSequentialGroup().addComponent(labels[i]).addComponent(fields[i])); sequential.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(labels[i]) .addComponent(fields[i])); layout.linkSize(SwingConstants.HORIZONTAL, labels[i], labels[0]); } return panel; }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); Container pane = getContentPane(); GroupLayout gl = new GroupLayout(pane); pane.setLayout(gl);// ww w . j av a 2 s . c o m gl.setAutoCreateGaps(true); gl.setAutoCreateContainerGaps(true); JButton btn = new JButton("Switch"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 1; i < 9; i++) { labels[i].setVisible(!labels[i].isVisible()); } } }); gl.setHonorsVisibility(false); SequentialGroup seqGroup = gl.createSequentialGroup(); gl.setHorizontalGroup(seqGroup); seqGroup.addComponent(btn); seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10); for (int i = 0; i < 10; i++) { seqGroup.addComponent(labels[i]); seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10); } ParallelGroup parGroup = gl.createParallelGroup(); gl.setVerticalGroup(parGroup); parGroup.addComponent(btn); for (int i = 0; i < 10; i++) { parGroup.addComponent(labels[i]); } pack(); }
From source file:layout.Find.java
public Find() { JLabel label = new JLabel("Find What:"); ;//from w w w . j av a 2 s . c om JTextField textField = new JTextField(); JCheckBox caseCheckBox = new JCheckBox("Match Case"); JCheckBox wrapCheckBox = new JCheckBox("Wrap Around"); JCheckBox wholeCheckBox = new JCheckBox("Whole Words"); JCheckBox backCheckBox = new JCheckBox("Search Backwards"); JButton findButton = new JButton("Find"); JButton cancelButton = new JButton("Cancel"); // remove redundant default border of check boxes - they would hinder // correct spacing and aligning (maybe not needed on some look and feels) caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label) .addGroup(layout.createParallelGroup(LEADING).addComponent(textField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING).addComponent(caseCheckBox) .addComponent(wholeCheckBox)) .addGroup(layout.createParallelGroup(LEADING).addComponent(wrapCheckBox) .addComponent(backCheckBox)))) .addGroup(layout.createParallelGroup(LEADING).addComponent(findButton).addComponent(cancelButton))); layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(label).addComponent(textField) .addComponent(findButton)) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(caseCheckBox) .addComponent(wrapCheckBox)) .addGroup(layout.createParallelGroup(BASELINE).addComponent(wholeCheckBox) .addComponent(backCheckBox))) .addComponent(cancelButton))); setTitle("Find"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }
From source file:lookandfeel.SynthDialog.java
public SynthDialog() { JLabel label = new JLabel("Find What:"); ;/* w ww. j a va 2s . c om*/ JTextField textField = new JTextField(); JCheckBox caseCheckBox = new JCheckBox("Match Case"); JCheckBox wrapCheckBox = new JCheckBox("Wrap Around"); JCheckBox wholeCheckBox = new JCheckBox("Whole Words"); JCheckBox backCheckBox = new JCheckBox("Search Backwards"); JButton findButton = new JButton("Find"); JButton cancelButton = new JButton("Cancel"); // remove redundant default border of check boxes - they would hinder // correct spacing and aligning (maybe not needed on some look and feels) caseCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wrapCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); wholeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); backCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label) .addGroup(layout.createParallelGroup(LEADING).addComponent(textField) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(LEADING).addComponent(caseCheckBox) .addComponent(wholeCheckBox)) .addGroup(layout.createParallelGroup(LEADING).addComponent(wrapCheckBox) .addComponent(backCheckBox)))) .addGroup(layout.createParallelGroup(LEADING).addComponent(findButton).addComponent(cancelButton))); layout.linkSize(SwingConstants.HORIZONTAL, findButton, cancelButton); layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(label).addComponent(textField) .addComponent(findButton)) .addGroup(layout.createParallelGroup(LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(BASELINE).addComponent(caseCheckBox) .addComponent(wrapCheckBox)) .addGroup(layout.createParallelGroup(BASELINE).addComponent(wholeCheckBox) .addComponent(backCheckBox))) .addComponent(cancelButton))); setTitle("Find"); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }