List of usage examples for com.jgoodies.forms.layout FormLayout getColumnCount
public int getColumnCount()
From source file:com.intellij.uiDesigner.compiler.FormLayoutUtils.java
License:Apache License
public static String getEncodedColumnSpecs(final FormLayout formLayout) { StringBuffer result = new StringBuffer(); for (int i = 1; i <= formLayout.getColumnCount(); i++) { if (result.length() > 0) { result.append(","); }/*from w w w . j av a2s .c o m*/ result.append(getEncodedSpec(formLayout.getColumnSpec(i))); } return result.toString(); }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
@Override public void writeLayout(final XmlWriter writer, final RadContainer radContainer) { FormLayout layout = (FormLayout) radContainer.getLayout(); for (int i = 1; i <= layout.getRowCount(); i++) { RowSpec rowSpec = layout.getRowSpec(i); writer.startElement(UIFormXmlConstants.ELEMENT_ROWSPEC); try {/*from ww w. jav a 2s . co m*/ writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VALUE, FormLayoutUtils.getEncodedSpec(rowSpec)); } finally { writer.endElement(); } } for (int i = 1; i <= layout.getColumnCount(); i++) { ColumnSpec columnSpec = layout.getColumnSpec(i); writer.startElement(UIFormXmlConstants.ELEMENT_COLSPEC); try { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VALUE, FormLayoutUtils.getEncodedSpec(columnSpec)); } finally { writer.endElement(); } } writeGroups(writer, UIFormXmlConstants.ELEMENT_ROWGROUP, layout.getRowGroups()); writeGroups(writer, UIFormXmlConstants.ELEMENT_COLGROUP, layout.getColumnGroups()); }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
@NotNull @Override//from w w w . ja v a2s.c o m public ComponentDropLocation getDropLocation(@NotNull RadContainer container, @Nullable final Point location) { FormLayout formLayout = getFormLayout(container); if (formLayout.getRowCount() == 0 || formLayout.getColumnCount() == 0) { if (location != null) { Rectangle rc = new Rectangle(new Point(), container.getDelegee().getSize()); return new FormFirstComponentInsertLocation(container, location, rc); } } final FormLayout.LayoutInfo layoutInfo = formLayout.getLayoutInfo(container.getDelegee()); if (location != null && location.x > layoutInfo.getWidth()) { int row = findCell(layoutInfo.rowOrigins, location.y); if (row == -1) { return NoDropLocation.INSTANCE; } return new GridInsertLocation(container, row, getGridColumnCount(container) - 1, GridInsertMode.ColumnAfter); } if (location != null && location.y > layoutInfo.getHeight()) { int column = findCell(layoutInfo.columnOrigins, location.x); if (column == -1) { return NoDropLocation.INSTANCE; } return new GridInsertLocation(container, getGridRowCount(container) - 1, column, GridInsertMode.RowAfter); } if (container.getGridRowCount() == 1 && container.getGridColumnCount() == 1 && getComponentAtGrid(container, 0, 0) == null) { final Rectangle rc = getGridCellRangeRect(container, 0, 0, 0, 0); if (location == null) { return new FormFirstComponentInsertLocation(container, rc, 0, 0); } return new FormFirstComponentInsertLocation(container, location, rc); } return super.getDropLocation(container, location); }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
private static void insertOrAppendColumn(final FormLayout formLayout, final int index, final ColumnSpec columnSpec) { if (index == formLayout.getColumnCount() + 1) { formLayout.appendColumn(columnSpec); } else {/*from www. j av a 2 s . com*/ formLayout.insertColumn(index, columnSpec); } }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
@Override public int deleteGridCells(final RadContainer grid, final int cellIndex, final boolean isRow) { int result = 1; FormLayout formLayout = (FormLayout) grid.getLayout(); adjustDeletedCellOrigins(grid, cellIndex, isRow); if (isRow) {/* w ww.ja v a 2 s. c o m*/ int[][] groupIndices = formLayout.getRowGroups(); groupIndices = removeDeletedCell(groupIndices, cellIndex + 1); formLayout.setRowGroups(groupIndices); formLayout.removeRow(cellIndex + 1); updateGridConstraintsFromCellConstraints(grid); if (formLayout.getRowCount() > 0 && formLayout.getRowCount() % 2 == 0) { int gapRowIndex = (cellIndex >= grid.getGridRowCount()) ? cellIndex - 1 : cellIndex; if (GridChangeUtil.isRowEmpty(grid, gapRowIndex)) { formLayout.removeRow(gapRowIndex + 1); updateGridConstraintsFromCellConstraints(grid); result++; } } } else { int[][] groupIndices = formLayout.getColumnGroups(); groupIndices = removeDeletedCell(groupIndices, cellIndex + 1); formLayout.setColumnGroups(groupIndices); formLayout.removeColumn(cellIndex + 1); updateGridConstraintsFromCellConstraints(grid); if (formLayout.getColumnCount() > 0 && formLayout.getColumnCount() % 2 == 0) { int gapColumnIndex = (cellIndex >= grid.getGridColumnCount()) ? cellIndex - 1 : cellIndex; if (GridChangeUtil.isColumnEmpty(grid, gapColumnIndex)) { formLayout.removeColumn(gapColumnIndex + 1); updateGridConstraintsFromCellConstraints(grid); result++; } } } return result; }
From source file:com.jeta.swingbuilder.codegen.builder.PanelWriter.java
License:Open Source License
public MethodWriter createPanel(DeclarationManager decl_mgr, FormMemento fm) { decl_mgr.addImport("javax.swing.JPanel"); decl_mgr.addImport("com.jgoodies.forms.layout.CellConstraints"); decl_mgr.addImport("com.jgoodies.forms.layout.FormLayout"); PropertiesMemento pm = fm.getPropertiesMemento(); MethodWriter method_writer = new MethodWriter(decl_mgr, null, getSuggestedMethodName(pm.getComponentName())); BeanWriter form_bean_writer = new BeanWriter(method_writer, pm); method_writer.setReturnResult(form_bean_writer); LocalVariableDeclaration layout = new LocalVariableDeclaration(method_writer, com.jgoodies.forms.layout.FormLayout.class); layout.addParameter(new StringExpression(fm.getColumnSpecs())); layout.addParameter(new StringExpression(fm.getRowSpecs())); /** we need this to get the row/column count */ FormLayout formlayout = new FormLayout(FormSpecAdapter.fixupSpecs(fm.getColumnSpecs()), FormSpecAdapter.fixupSpecs(fm.getRowSpecs())); method_writer.addStatements(form_bean_writer.getStatements()); method_writer.addStatement(layout);// w ww .jav a2 s.c o m /** set the column and row groups */ setGroups(method_writer, layout.getVariable(), fm, true); setGroups(method_writer, layout.getVariable(), fm, false); LocalVariableDeclaration ccvar = new LocalVariableDeclaration(method_writer, com.jgoodies.forms.layout.CellConstraints.class, "cc"); method_writer.addStatement(ccvar); /** add the panel declaration/ctor to the method */ MethodStatement ss = new MethodStatement(form_bean_writer.getBeanVariable(), "setLayout"); ss.addParameter(new BasicExpression(layout.getVariable())); method_writer.addStatement(ss); decl_mgr.addMethod(method_writer); /** puts a newline between beans */ method_writer.addStatement(new BasicStatement("")); HashMap row_cache = new HashMap(); HashMap col_cache = new HashMap(); Iterator iter = fm.iterator(); while (iter.hasNext()) { ComponentMemento cm = (ComponentMemento) iter.next(); CellConstraintsMemento ccm = cm.getCellConstraintsMemento(); CellConstraints cc = ccm.createCellConstraints(); try { if (cm instanceof FormMemento) { FormMemento cfm = (FormMemento) cm; MethodWriter subpanel = createPanel(method_writer, cfm); method_writer.addStatement(createAddComponentStatement(form_bean_writer.getBeanVariable(), subpanel.getMethodName() + "()", ccvar.getVariable(), cc)); } else if (cm instanceof BeanMemento) { BeanMemento bm = (BeanMemento) cm; Integer icol = new Integer(cc.gridX); Integer irow = new Integer(cc.gridY); if (bm.getBeanClass() == null) { /** found an empty component */ if (col_cache.get(icol) == null) col_cache.put(icol, new FillMarker(bm, formlayout.getColumnSpec(icol.intValue()))); if (row_cache.get(irow) == null) row_cache.put(irow, new FillMarker(bm, formlayout.getRowSpec(irow.intValue()))); } else if (bm.getProperties() != null) { String beanclass = bm.getBeanClass(); if (beanclass.indexOf("GridView") > 0 || beanclass.indexOf("JETALabel") > 0 || decl_mgr.isIncludeNonStandard() || beanclass.indexOf("com.jeta") < 0) { BeanWriter bw = new BeanWriter(method_writer, bm.getProperties()); method_writer.addStatements(bw.getStatements()); method_writer .addStatement(createAddComponentStatement(form_bean_writer.getBeanVariable(), bw.getResultVariable(), ccvar.getVariable(), cc)); /** puts a newline between beans */ method_writer.addStatement(new BasicStatement("")); if (icol.intValue() == 1) row_cache.put(irow, new FillMarker(bm, formlayout.getRowSpec(irow.intValue()))); if (irow.intValue() == 1) col_cache.put(icol, new FillMarker(bm, formlayout.getColumnSpec(icol.intValue()))); } } } else { assert (false); } } catch (Exception e) { } } MethodStatement addseps = new MethodStatement("addFillComponents"); addseps.addParameter(form_bean_writer.getBeanVariable()); addseps.addParameter(createFillArray(col_cache, formlayout.getColumnCount())); addseps.addParameter(createFillArray(row_cache, formlayout.getRowCount())); method_writer.addStatement(addseps); return method_writer; }
From source file:jgnash.ui.budget.BudgetOverviewPanel.java
License:Open Source License
void updateSparkLines() { Runnable r = new Runnable() { @Override/*w ww . ja v a 2 s.c o m*/ public void run() { final List<AccountGroup> groups = new ArrayList<>(budgetPanel.getAccountGroups()); final List<Icon> icons = new ArrayList<>(); for (AccountGroup group : groups) { icons.add(budgetPanel.getSparkLineIcon(group)); } EventQueue.invokeLater(new Runnable() { @Override public void run() { FormLayout layout = (FormLayout) sparklinePanel.getLayout(); // remove all components and columns sparklinePanel.removeAll(); int columnCount = layout.getColumnCount(); for (int i = columnCount; i >= 1; i--) { layout.removeColumn(i); } // create components and columns and add if (icons.size() > 0) { layout.appendColumn(ColumnSpec.decode("d")); sparklinePanel.add(getLabel(groups.get(0), icons.get(0)), CC.xy(1, 1)); for (int i = 1; i < icons.size(); i++) { layout.appendColumn(ColumnSpec.decode("2dlu")); layout.appendColumn(ColumnSpec.decode("d")); sparklinePanel.add(getLabel(groups.get(i), icons.get(i)), CC.xy(i * 2 + 1, 1)); } } // force the complete panel to update so icons show invalidate(); validate(); } }); } }; updateIconExecutor.execute(r); }
From source file:loci.ome.notes.editor.TemplateEditor.java
License:Open Source License
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("new")) { icons = new Hashtable[0]; fields = new Hashtable[0]; tabPane.removeAll();/* w w w . j av a 2 s. c o m*/ repaint(); } else if (cmd.equals("open")) { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return f.getAbsolutePath().endsWith(".template") || f.isDirectory(); } public String getDescription() { return "OME Notes Templates"; } }; chooser.setFileFilter(filter); int status = chooser.showOpenDialog(this); if (status == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getAbsolutePath(); try { Template t = new Template(file); TemplateTab[] tabs = t.getTabs(); for (int i = 0; i < tabs.length; i++) { int rows = tabs[i].getRows(); int cols = tabs[i].getColumns(); if (cols == 0) cols = 1; if (rows == 0) rows = 1; addTab(tabs[i].getName(), rows, cols); tabPane.setSelectedIndex(i); for (int j = 0; j < tabs[i].getNumFields(); j++) { TemplateField f = tabs[i].getField(j); int x = f.getRow(); int y = f.getColumn(); if (x == -1) x = 1; if (y == -1) y = j + 1; Point p = new Point(x, y); DraggableIcon icon = (DraggableIcon) icons[i].get(p); icon.label = new JLabel(f.getName()); JPanel panel = new JPanel(); panel.add(f.getComponent()); icon.setPanel(panel); } } } catch (Exception exc) { error("Failed to parse template", exc); } tabPane.setSelectedIndex(0); } } else if (cmd.equals("save")) { // build up the template from the components TemplateTab[] tabs = new TemplateTab[tabPane.getTabCount()]; for (int i = 0; i < tabs.length; i++) { tabs[i] = new TemplateTab(); tabs[i].setName(tabPane.getTitleAt(i)); JComponent c = (JComponent) tabPane.getComponentAt(i); FormLayout layout = (FormLayout) c.getLayout(); tabs[i].setRows(layout.getRowCount()); tabs[i].setColumns(layout.getColumnCount()); Object[] keys = icons[i].keySet().toArray(); for (int j = 0; j < keys.length; j++) { Point p = (Point) keys[j]; DraggableIcon icon = (DraggableIcon) icons[i].get(p); TemplateField f = (TemplateField) fields[i].get(p); if (icon.image != null) { Component[] components = icon.image.getComponents(); JLabel label = icon.label; JComponent component = (JComponent) components[0]; f.setComponent(component); for (int k = 0; k < COMPONENTS.length; k++) { if (component.getClass().equals(COMPONENTS[k])) { f.setType(COMPONENT_TYPES[k]); break; } } f.setRow(p.y); f.setColumn(p.x); f.setDefaultValue(TemplateTools.getComponentValue(component)); tabs[i].addField(f); } } } Template t = new Template(tabs, null); // prompt for filename to save to if (currentFile == null) { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return true; } public String getDescription() { return "All files"; } }; chooser.setFileFilter(filter); int status = chooser.showSaveDialog(this); if (status == JFileChooser.APPROVE_OPTION) { currentFile = chooser.getSelectedFile().getAbsolutePath(); if (currentFile == null) return; } } try { t.save(currentFile); } catch (IOException io) { error("Failed to save template", io); } } else if (cmd.equals("quit")) dispose(); else if (cmd.equals("add row")) addRow(); else if (cmd.equals("add col")) addColumn(); else if (cmd.equals("prompt tab")) { // prompt for tab name JPopupMenu menu = new JPopupMenu(); newTabName = new JTextField(); newTabName.setPreferredSize(new Dimension(200, 25)); menu.add(newTabName); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("new tab"); menu.add(b); JComponent s = (JComponent) e.getSource(); menu.show(s, s.getX(), s.getY()); newTabName.grabFocus(); } else if (cmd.equals("new tab")) { newTabName.getParent().setVisible(false); addTab(newTabName.getText(), 2, 2); } else if (cmd.equals("setName")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); String text = ((JTextField) menu.getComponents()[0]).getText(); Point p = new Point(icon.gridx, icon.gridy); int ndx = tabPane.getSelectedIndex(); TemplateField f = (TemplateField) fields[ndx].get(p); f.setName(text); f.setNameMap(null); // set the name if (icon.label != null) icon.remove(icon.label); icon.remove(icon.image); icon.label = new JLabel(text); icon.add(icon.label); icon.add(icon.image); icon.getParent().repaint(); } else if (cmd.equals("changeName")) { // prompt for new field name JPopupMenu menu = new JPopupMenu(); JTextField field = new JTextField(); field.setPreferredSize(new Dimension(200, 25)); menu.add(field); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("setName"); menu.add(b); menu.show(lastMenuComponent, lastMenuX, lastMenuY); field.grabFocus(); } else if (cmd.equals("nameMap")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); MappingWindow w = new MappingWindow(this, true); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("map")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); MappingWindow w = new MappingWindow(this, false); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("repeat")) { JMenuItem item = (JMenuItem) e.getSource(); DraggableIcon icon = (DraggableIcon) ((JPopupMenu) item.getParent()).getInvoker(); TemplateField f = getField(icon); if (item.getText().equals("Repeat this field")) { item.setText("Don't repeat this field"); f.setRepeated(true); } else { item.setText("Repeat this field"); f.setRepeated(false); } } else if (cmd.equals("removeField")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); int idx = tabPane.getSelectedIndex(); Object[] keys = icons[idx].keySet().toArray(); for (int i = 0; i < keys.length; i++) { if (icons[idx].get(keys[i]).equals(icon)) { icons[idx].remove(keys[i]); fields[idx].remove(keys[i]); break; } } icon.remove(icon.label); icon.remove(icon.image); tabPane.repaint(); } else if (cmd.startsWith("removeRow")) { int row = Integer.parseInt(cmd.substring(cmd.indexOf(":") + 1)); JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); menu.setVisible(false); JPanel pane = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) pane.getLayout(); int rows = layout.getRowCount(); int cols = layout.getColumnCount(); int idx = tabPane.getSelectedIndex(); for (int i = 0; i < cols; i++) { pane.remove((JComponent) icons[idx].get(new Point(i + 1, row + 1))); } rekey(row, -1); layout.removeRow(row + 1); tabPane.repaint(); } else if (cmd.startsWith("removeColumn")) { int col = Integer.parseInt(cmd.substring(cmd.indexOf(":") + 1)); JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); menu.setVisible(false); JPanel pane = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) pane.getLayout(); int rows = layout.getRowCount(); int cols = layout.getColumnCount(); int idx = tabPane.getSelectedIndex(); for (int i = 0; i < rows; i++) { pane.remove((JComponent) icons[idx].get(new Point(col + 1, i + 1))); } rekey(-1, col); layout.removeColumn(col + 1); tabPane.repaint(); } else if (cmd.equals("removeTab")) { int ndx = tabPane.getSelectedIndex(); tabPane.remove(ndx); Hashtable[] h = new Hashtable[icons.length - 1]; Hashtable[] f = new Hashtable[fields.length - 1]; System.arraycopy(icons, 0, h, 0, ndx); System.arraycopy(icons, ndx + 1, h, ndx, h.length - ndx); System.arraycopy(fields, 0, f, 0, ndx); System.arraycopy(fields, ndx + 1, f, ndx, f.length - ndx); icons = h; fields = f; } else if (cmd.equals("specifyChoices")) { JMenuItem item = (JMenuItem) e.getSource(); DraggableIcon icon = (DraggableIcon) ((JPopupMenu) item.getParent()).getInvoker(); TemplateField f = getField(icon); EnumWindow w = new EnumWindow(this, f.getEnums()); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("setThumbSource")) { JPopupMenu menu = new JPopupMenu(); ButtonGroup g = new ButtonGroup(); JRadioButton dataset = new JRadioButton("Use thumbnail from dataset"); dataset.setSelected(true); g.add(dataset); JRadioButton file = new JRadioButton("Use thumbnail from file:"); g.add(file); menu.add(dataset); menu.add(file); JTextField field = new JTextField(); field.setPreferredSize(new Dimension(200, 25)); menu.add(field); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("applyThumbSource"); menu.add(b); menu.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("applyThumbSource")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); Component[] c = menu.getComponents(); JRadioButton dataset = (JRadioButton) c[0]; String text = null; if (!dataset.isSelected()) { JTextField t = (JTextField) c[2]; text = t.getText(); getField(icon).setValueMap(text); } menu.setVisible(false); if (text != null) { try { BufferedImageReader reader = new BufferedImageReader(); reader.setId(text); BufferedImage thumb = reader.openThumbImage(0); JLabel label = (JLabel) icon.image.getComponents()[0]; label.setIcon(new ImageIcon(thumb)); reader.close(); } catch (FormatException exc) { error("Failed to open thumbnail (" + text + ")", exc); } catch (IOException exc) { error("Failed to open thumbnail (" + text + ")", exc); } } } else if (cmd.equals("ok")) { // this event came from an instance of EnumWindow JPanel parent = (JPanel) ((JButton) e.getSource()).getParent(); EnumWindow menu = (EnumWindow) parent.getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); TemplateField f = getField(icon); menu.setVisible(false); String[] options = menu.getOptions(); f.setEnums(options); JComboBox box = (JComboBox) icon.image.getComponents()[0]; for (int i = 0; i < options.length; i++) box.addItem(options[i]); repaint(); } else if (cmd.equals("chooseMapping")) { // this event came from an instance of MappingWindow JTabbedPane parent = (JTabbedPane) ((JButton) e.getSource()).getParent(); MappingWindow menu = (MappingWindow) parent.getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); TemplateField f = getField(icon); String omexmlMap = null; if (menu.nameMap) f.setNameMap(omexmlMap); else f.setValueMap(omexmlMap); menu.setVisible(false); } }
From source file:loci.ome.notes.editor.TemplateEditor.java
License:Open Source License
/** Add a new column to the current tab. */ private void addRow() { JPanel selected = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) selected.getLayout(); layout.appendRow(new RowSpec("pref:grow")); int ndx = tabPane.getSelectedIndex(); for (int i = 0; i < layout.getColumnCount(); i++) { addIcon(selected, layout.getRowCount() - 1, i, ndx); }/*from ww w. j a v a 2s . c o m*/ tabPane.repaint(); }
From source file:loci.ome.notes.editor.TemplateEditor.java
License:Open Source License
/** Add a new row to the current tab. */ private void addColumn() { JPanel selected = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) selected.getLayout(); layout.appendColumn(new ColumnSpec("pref:grow")); int ndx = tabPane.getSelectedIndex(); for (int i = 0; i < layout.getRowCount(); i++) { addIcon(selected, i, layout.getColumnCount() - 1, ndx); }// w ww .j a va 2 s . c o m tabPane.repaint(); }