List of usage examples for java.awt Component getPreferredSize
public Dimension getPreferredSize()
From source file:it.iit.genomics.cru.igb.bundles.mi.view.MITable.java
public MITable(MITableModel model, IgbService service, final MIQuery query) { super(model); this.query = query; igbLogger = IGBLogger.getInstance(query.getLabel()); this.igbService = service; this.SymSelectionListener = new MouseListener() { @SuppressWarnings("unchecked") @Override/*from w ww . j a va 2 s. c o m*/ public void mouseClicked(MouseEvent e) { if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1) { if (getSelectedRow() >= 0) { int modelRow = convertRowIndexToModel(getSelectedRow()); MIResult interaction = ((MITableModel) getModel()).getResult(modelRow); structuresPanel.setCurrentInteraction(interaction); } MITable table = (MITable) e.getComponent(); int modelRow = convertRowIndexToModel(table.getSelectedRow()); int column = table.getSelectedColumn(); if (e.getClickCount() == 1) { if (column == MITableModel.TRACK_COLUMN) { Object value = table.getValueAt(table.getSelectedRow(), column); if (value instanceof JButton) { MIResult result = ((MITableModel) table.getModel()).getResult(modelRow); TypeContainerAnnot interactorTrack = result.createTrack(); igbService.addTrack(interactorTrack, interactorTrack.getID()); igbService.getSeqMapView().updatePanel(); for (TierGlyph t : igbService.getAllTierGlyphs()) { if (TierGlyph.TierType.ANNOTATION.equals(t.getTierType()) && (t.getAnnotStyle().getTrackName().equals(interactorTrack.getID()))) { SimpleTrackStyle style = new SimpleTrackStyle(interactorTrack.getID(), false) { @Override public boolean drawCollapseControl() { return false; } }; t.getAnnotStyle().copyPropertiesFrom(style); t.getAnnotStyle().setColorProvider(new RGB()); interactorTrack.setProperty(TrackLineParser.ITEM_RGB, "on"); } } igbService.getSeqMapView().updatePanel(); ((JButton) value).setText(interactorTrack.getID()); ((JButton) value).setEnabled(false); updateUI(); } } } else { // symmetry: zoom-in if (column == MITableModel.SYMS1_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor1(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries1(); zoomToSym(syms); } } else if (column == MITableModel.SYMS2_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor2(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries2(); zoomToSym(syms); } } // Protein: link to uniprot if (column == MITableModel.INTERACTOR1_COLUMN || column == MITableModel.INTERACTOR2_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String id; String taxid; MoleculeEntry interactor; if (column == MITableModel.INTERACTOR1_COLUMN) { interactor = miResult.getInteractor1(); } else { interactor = miResult.getInteractor2(); } taxid = interactor.getTaxid(); String query; String anchor = ""; switch (taxid) { case MoleculeEntry.TAXID_DNA: case MoleculeEntry.TAXID_RNA: if (miResult.getInteractionStructures().isEmpty()) { return; } query = "http://www.pdb.org/pdb/explore/explore.do?structureId=" + miResult.getInteractionStructures().iterator().next().getStructureID(); break; case MoleculeEntry.TAXID_LIGAND: if (miResult.getInteractionStructures().isEmpty()) { return; } query = DrugBankMapper.getInstance().isDrug(interactor.getGeneName()) ? DrugBankMapper.getInstance().getDrugBankLink(interactor.getGeneName()) : "http://www.ebi.ac.uk/pdbe-srv/pdbechem/chemicalCompound/show/" + interactor.getGeneName(); break; case MoleculeEntry.TAXID_MODIFICATION: query = "http://www.uniprot.org/uniprot/" + miResult.getInteractor1().getUniprotAc(); anchor = "#ptm_processing"; break; default: id = interactor.getUniprotAc(); query = "http://www.uniprot.org/uniprot/" + id; break; } try { URI uri = new URI(URIUtil.encodeQuery(query) + anchor); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website."); return; } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website: " + query); } } // interaction type: link to psicquic if (column == MITableModel.INTERACTION_TYPE_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String queryURL; String idA = miResult.getInteractor1().getUniprotAc(); String idB = miResult.getInteractor2().getUniprotAc(); if (null == miResult.getPsicquicUrl()) { // from the structure database if (query.searchDSysMap()) { queryURL = "http://http://dsysmap.irbbarcelona.org/results.php?type=proteins&neigh=2&value=" + idA + "," + idB; } else if (query.searchInteractome3D()) { try { queryURL = "http://interactome3d.irbbarcelona.org/interaction.php?ids=" + idA + ";" + idB + "&dataset=" + it.iit.genomics.cru.bridges.interactome3d.ws.Utils .getDataset(query.getTaxid()); } catch (Interactome3DException e3d) { // it will never happend: if the taxid was not known by // I3D, we wouldn't have an interaction return; } } else { return; } } else { if (false == idA.equals(idB)) { queryURL = miResult.getPsicquicUrl() + "query/id:" + miResult.getInteractor1().getUniprotAc() + "* AND id:" + miResult.getInteractor2().getUniprotAc() + "*"; } else { queryURL = miResult.getPsicquicUrl() + "query/idA:" + miResult.getInteractor1().getUniprotAc() + "* AND idB:" + miResult.getInteractor2().getUniprotAc() + "*"; } } try { URI uri = new URI(URIUtil.encodeQuery(queryURL)); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server."); } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server: " + queryURL); } } } } } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; TableRowSorter<MITableModel> sorter = new MITableRowSorter(model); setRowSorter(sorter); sorter.setRowFilter(evidenceRowFilter()); model.fireTableDataChanged(); this.getTableHeader().setReorderingAllowed(false); TableCellRenderer rend = getTableHeader().getDefaultRenderer(); TableColumnModel tcm = getColumnModel(); for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(j); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, j); tc.setPreferredWidth(c.getPreferredSize().width); } TableCellRenderer buttonRenderer = new JTableButtonRenderer(); getColumn(model.getColumnName(MITableModel.TRACK_COLUMN)).setCellRenderer(buttonRenderer); getColumn(model.getColumnName(MITableModel.SYMS1_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.SYMS2_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR1_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR2_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTION_TYPE_COLUMN)) .setCellRenderer(new EvidenceRenderer()); getColumn(model.getColumnName(MITableModel.STRUCTURES_COLUMN)).setCellRenderer(new StructuresRenderer()); setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); int smallWidth = 75; int mediumWidth = 120; int largeWidth = 200; getColumnModel().getColumn(MITableModel.TRACK_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMaxWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setPreferredWidth(smallWidth); addMouseListener(SymSelectionListener); getSelectionModel().addListSelectionListener(new RowSelectionListener()); }
From source file:dataviewer.DataViewer.java
private void renderData(DefaultTableModel model) { tb_data.setVisible(false);//from w w w .j a va2 s . co m tb_data.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 == 0 ? Color.WHITE : new Color(240, 240, 240)); if (table.isCellSelected(row, column)) { c.setBackground(new Color(200, 0, 0)); c.setForeground(Color.white); } else if (table.isRowSelected(row)) { c.setBackground(new Color(0, 0, 200)); c.setForeground(Color.white); } else { c.setForeground(Color.black); } return c; } }); tb_data.setGridColor(new Color(220, 220, 220)); tb_data.setShowVerticalLines(true); tb_data.setModel(model); for (int i = 0; i < model.getColumnCount(); ++i) { if (model.getColumnName(i).equals("_N_")) { TableRowSorter trs = new TableRowSorter(model); trs.setComparator(i, new IntComparator()); tb_data.setRowSorter(trs); } } for (int j = 0; j < tb_data.getColumnCount(); j++) { int width = 0; TableColumn col = tb_data.getColumnModel().getColumn(j); TableCellRenderer renderer = tb_data.getTableHeader().getDefaultRenderer(); Component comp = renderer.getTableCellRendererComponent(tb_data, col.getHeaderValue(), false, false, 0, 0); width = Math.max(comp.getPreferredSize().width, width); for (int i = 0; i < tb_data.getRowCount(); i++) { renderer = tb_data.getCellRenderer(i, j); comp = tb_data.prepareRenderer(renderer, i, j); width = Math.max(comp.getPreferredSize().width, width); } tb_data.getColumnModel().getColumn(j).setPreferredWidth(width + 20); } tb_data.setVisible(true); }
From source file:TileLayout.java
private void align(Dimension cont, Object cons[], Component comp) { int align = 0; Insets insets = null;//from w w w . ja v a 2 s.c o m Rectangle tile = null, fixd = null; if (cons != null) { for (int i = 0; i < cons.length; i++) { // gather constraints if (cons[i] != null) { if (cons[i] instanceof Rectangle) fixd = (Rectangle) cons[i]; else if (cons[i] instanceof Insets) insets = (Insets) cons[i]; else if (cons[i] instanceof Integer) align = ((Integer) cons[i]).intValue(); else if (cons[i] instanceof Component) tile = ((Component) cons[i]).getBounds(); } } } if (tile == null) tile = new Rectangle(cont); Rectangle pref = new Rectangle(tile.getLocation(), comp.getPreferredSize()); // perform component positioning: if ((align & 0x004000) != 0) pref.width = fixd.width; else if ((align & 0x008000) != 0) pref.width = (tile.width * fixd.width + 500) / 1000; else if ((align & 0x010000) != 0) pref.width = tile.width; if ((align & 0x080000) != 0) pref.height = fixd.height; else if ((align & 0x100000) != 0) pref.height = (tile.height * fixd.height + 500) / 1000; else if ((align & 0x200000) != 0) pref.height = tile.height; if ((align & 0x000001) != 0) pref.x -= pref.width; else if ((align & 0x000002) != 0) pref.x += (tile.width - pref.width >> 1); else if ((align & 0x000004) != 0) pref.x += tile.width - pref.width; else if ((align & 0x000008) != 0) pref.x += tile.width; else if ((align & 0x000010) != 0) pref.x += fixd.x; else if ((align & 0x000020) != 0) pref.x += (tile.width * fixd.x + 500) / 1000; if ((align & 0x000040) != 0) pref.y -= pref.height; else if ((align & 0x000080) != 0) pref.y += (tile.height - pref.height >> 1); else if ((align & 0x000100) != 0) pref.y += tile.height - pref.height; else if ((align & 0x000200) != 0) pref.y += tile.height; else if ((align & 0x000400) != 0) pref.y += fixd.y; else if ((align & 0x000800) != 0) pref.y += (tile.height * fixd.y + 500) / 1000; if ((align & 0x001000) != 0) pref.setBounds(0, pref.y, pref.x + pref.width, pref.height); else if ((align & 0x002000) != 0) pref.width = cont.width - pref.x; if ((align & 0x020000) != 0) pref.setBounds(pref.x, 0, pref.width, pref.y + pref.height); else if ((align & 0x040000) != 0) pref.height = cont.height - pref.y; if (insets != null) { // apply insets, if any: pref.x += insets.left; pref.y += insets.top; pref.width -= insets.left + insets.right; pref.height -= insets.top + insets.bottom; } // Note: this can cause surprising results, so use it, if you dare. :-) // Honour component minimum size: Dimension d = comp.getMinimumSize(); if (pref.width < d.width) pref.width = d.width; if (pref.height < d.height) pref.height = d.height; comp.setBounds(pref); // now the tile is set! }
From source file:FormatLayout.java
/** * Returns the preferred size of the component using this layout manager. * * @param parent the parent.//from w w w. j a v a 2 s . com * * @return the preferred size of the component. */ public Dimension preferredLayoutSize(final Container parent) { Component c0, c1, c2, c3, c4, c5; synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); int componentIndex = 0; final int rowCount = this.rowHeights.length; for (int i = 0; i < this.columnWidths.length; i++) { this.columnWidths[i] = 0; } this.columns1and2Width = 0; this.columns4and5Width = 0; this.columns1to4Width = 0; this.columns1to5Width = 0; this.columns0to5Width = 0; this.totalHeight = 0; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { final int format = this.rowFormats[rowIndex % this.rowFormats.length]; switch (format) { case FormatLayout.C: c0 = parent.getComponent(componentIndex); updateC(rowIndex, c0.getPreferredSize()); componentIndex = componentIndex + 1; break; case FormatLayout.LC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize()); componentIndex = componentIndex + 2; break; case FormatLayout.LCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize()); componentIndex = componentIndex + 3; break; case FormatLayout.LCLC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize()); componentIndex = componentIndex + 4; break; case FormatLayout.LCBLC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize()); componentIndex = componentIndex + 5; break; case FormatLayout.LCLCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize()); componentIndex = componentIndex + 5; break; case FormatLayout.LCBLCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); c5 = parent.getComponent(componentIndex + 5); updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize()); componentIndex = componentIndex + 6; break; } } complete(); return new Dimension(this.totalWidth + insets.left + insets.right, this.totalHeight + (rowCount - 1) * this.rowGap + insets.top + insets.bottom); } }
From source file:FormatLayout.java
/** * Performs the layout of the container. * * @param parent the parent.//from ww w.j av a 2 s. com */ public void layoutContainer(final Container parent) { Component c0, c1, c2, c3, c4, c5; synchronized (parent.getTreeLock()) { final Insets insets = parent.getInsets(); int componentIndex = 0; final int rowCount = this.rowHeights.length; for (int i = 0; i < this.columnWidths.length; i++) { this.columnWidths[i] = 0; } this.columns1and2Width = 0; this.columns4and5Width = 0; this.columns1to4Width = 0; this.columns1to5Width = 0; this.columns0to5Width = parent.getBounds().width - insets.left - insets.right; this.totalHeight = 0; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { final int format = this.rowFormats[rowIndex % this.rowFormats.length]; switch (format) { case FormatLayout.C: c0 = parent.getComponent(componentIndex); updateC(rowIndex, c0.getPreferredSize()); componentIndex = componentIndex + 1; break; case FormatLayout.LC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize()); componentIndex = componentIndex + 2; break; case FormatLayout.LCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize()); componentIndex = componentIndex + 3; break; case FormatLayout.LCLC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize()); componentIndex = componentIndex + 4; break; case FormatLayout.LCBLC: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize()); componentIndex = componentIndex + 5; break; case FormatLayout.LCLCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize()); componentIndex = componentIndex + 5; break; case FormatLayout.LCBLCB: c0 = parent.getComponent(componentIndex); c1 = parent.getComponent(componentIndex + 1); c2 = parent.getComponent(componentIndex + 2); c3 = parent.getComponent(componentIndex + 3); c4 = parent.getComponent(componentIndex + 4); c5 = parent.getComponent(componentIndex + 5); updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize()); componentIndex = componentIndex + 6; break; } } complete(); componentIndex = 0; int rowY = insets.top; final int[] rowX = new int[6]; rowX[0] = insets.left; rowX[1] = rowX[0] + this.columnWidths[0] + this.columnGaps[0]; rowX[2] = rowX[1] + this.columnWidths[1] + this.columnGaps[1]; rowX[3] = rowX[2] + this.columnWidths[2] + this.columnGaps[2]; rowX[4] = rowX[3] + this.columnWidths[3] + this.columnGaps[3]; rowX[5] = rowX[4] + this.columnWidths[4] + this.columnGaps[4]; final int w1to2 = this.columnWidths[1] + this.columnGaps[1] + this.columnWidths[2]; final int w4to5 = this.columnWidths[4] + this.columnGaps[4] + this.columnWidths[5]; final int w1to4 = w1to2 + this.columnGaps[2] + this.columnWidths[3] + this.columnGaps[3] + this.columnWidths[4]; final int w1to5 = w1to4 + this.columnGaps[4] + this.columnWidths[5]; final int w0to5 = w1to5 + this.columnWidths[0] + this.columnGaps[0]; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { final int format = this.rowFormats[rowIndex % this.rowFormats.length]; switch (format) { case FormatLayout.C: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY, w0to5, c0.getPreferredSize().height); componentIndex = componentIndex + 1; break; case FormatLayout.LC: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, w1to5, c1.getPreferredSize().height); componentIndex = componentIndex + 2; break; case FormatLayout.LCB: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, w1to4, c1.getPreferredSize().height); c2 = parent.getComponent(componentIndex + 2); c2.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2, this.columnWidths[5], c2.getPreferredSize().height); componentIndex = componentIndex + 3; break; case FormatLayout.LCLC: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, w1to2, c1.getPreferredSize().height); c2 = parent.getComponent(componentIndex + 2); c2.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2, this.columnWidths[3], c2.getPreferredSize().height); c3 = parent.getComponent(componentIndex + 3); c3.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2, w4to5, c3.getPreferredSize().height); componentIndex = componentIndex + 4; break; case FormatLayout.LCBLC: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, this.columnWidths[1], c1.getPreferredSize().height); c2 = parent.getComponent(componentIndex + 2); c2.setBounds(rowX[2], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2, this.columnWidths[2], c2.getPreferredSize().height); c3 = parent.getComponent(componentIndex + 3); c3.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2, this.columnWidths[3], c3.getPreferredSize().height); c4 = parent.getComponent(componentIndex + 4); c4.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2, w4to5, c4.getPreferredSize().height); componentIndex = componentIndex + 5; break; case FormatLayout.LCLCB: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, w1to2, c1.getPreferredSize().height); c2 = parent.getComponent(componentIndex + 2); c2.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2, this.columnWidths[3], c2.getPreferredSize().height); c3 = parent.getComponent(componentIndex + 3); c3.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2, this.columnWidths[4], c3.getPreferredSize().height); c4 = parent.getComponent(componentIndex + 4); c4.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2, this.columnWidths[5], c4.getPreferredSize().height); componentIndex = componentIndex + 5; break; case FormatLayout.LCBLCB: c0 = parent.getComponent(componentIndex); c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2, this.columnWidths[0], c0.getPreferredSize().height); c1 = parent.getComponent(componentIndex + 1); c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2, this.columnWidths[1], c1.getPreferredSize().height); c2 = parent.getComponent(componentIndex + 2); c2.setBounds(rowX[2], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2, this.columnWidths[2], c2.getPreferredSize().height); c3 = parent.getComponent(componentIndex + 3); c3.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2, this.columnWidths[3], c3.getPreferredSize().height); c4 = parent.getComponent(componentIndex + 4); c4.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2, this.columnWidths[4], c4.getPreferredSize().height); c5 = parent.getComponent(componentIndex + 5); c5.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c5.getPreferredSize().height) / 2, this.columnWidths[5], c5.getPreferredSize().height); componentIndex = componentIndex + 6; break; } rowY = rowY + this.rowHeights[rowIndex] + this.rowGap; } } }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
/** * This method is called from within the constructor to initialize the form * components.//from w ww .j a va 2 s . c om */ private void initComponents() { // Lee: for aesthetics and Linux won't display window controls on an untitled window. final String version = CopiedFromOtherJars.getVersion(); setTitle(CopiedFromOtherJars.getText("msg.title.mainWindow", version)); //$NON-NLS-1$ if (jbPathText == null) jbPathText = CopiedFromOtherJars.getText("msg.info.setJavaVersion"); //$NON-NLS-1$ if (jbMTJarText == null) jbMTJarText = CopiedFromOtherJars.getText("msg.info.selectMapToolJar"); //$NON-NLS-1$ if (mapToolJarName == null) mapToolJarName = CopiedFromOtherJars.getText("msg.info.selectMapToolJar"); //$NON-NLS-1$ final Container cp = getContentPane(); cp.setLayout(new BorderLayout()); final JPanel basicPanel = buildBasicPanel(); final JPanel langPanel = buildLanguagePanel(); final JPanel advancedPanel = buildAdvancedPanel(); final JPanel tsPanel = buildTroubleshootingPanel(); mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.basic"), basicPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.language"), langPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.advanced"), advancedPanel); //$NON-NLS-1$ mtlOptions.addTab(CopiedFromOtherJars.getText("msg.tab.troubleshoot"), tsPanel); //$NON-NLS-1$ cp.add(mtlOptions, BorderLayout.CENTER); cp.add(jtfCommand, BorderLayout.SOUTH); // Lee: user must register MT executable jbLaunch.setEnabled( !mapToolJarName.equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.selectMapToolJar"))); //$NON-NLS-1$ jbLaunch.setText(CopiedFromOtherJars.getText("msg.info.launchMapTool")); //$NON-NLS-1$ jbLaunch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { try { jbLaunchActionPerformed(evt); } catch (final IOException e) { e.printStackTrace(); } } }); jtfCommand.setEditable(false); jtfCommand.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); jtfCommand.setText(CopiedFromOtherJars.getText("msg.info.cmdLineShownHere")); //$NON-NLS-1$ jtfCommand.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { jtfCommand.selectAll(); } @Override public void focusLost(FocusEvent arg0) { jtfCommand.setCaretPosition(0); } }); jcbKeepOpen.setSelected(false); jcbKeepOpen.setText(CopiedFromOtherJars.getText("msg.info.keepLauncherOpen")); //$NON-NLS-1$ jcbKeepOpen.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.keepLauncherOpen")); //$NON-NLS-1$ final JPanel lowerPanel = new JPanel(); lowerPanel.setLayout(new GridLayout(3, 1)); lowerPanel.setBorder(new LineBorder(Color.BLACK)); lowerPanel.add(jbLaunch); lowerPanel.add(jcbKeepOpen); lowerPanel.add(jtfCommand); cp.add(lowerPanel, BorderLayout.SOUTH); mtlOptions.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final JTabbedPane source = (JTabbedPane) e.getSource(); final String tabName = source.getTitleAt(source.getSelectedIndex()); if (jbLaunch.isEnabled()) { jbLaunch.requestFocusInWindow(); } else { if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.basic"))) { //$NON-NLS-1$ jbMTJar.requestFocusInWindow(); } else if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.language"))) { //$NON-NLS-1$ // This should work as long as there's at least one language in the list. langGroup.getElements().nextElement().requestFocusInWindow(); } else if (tabName.equals(CopiedFromOtherJars.getText("msg.tab.advanced"))) { //$NON-NLS-1$ jcbConsole.requestFocusInWindow(); jtfArgs.setText(extraArgs); } else { jcbEnableAssertions.requestFocusInWindow(); } } } }); Dimension d = new Dimension(advancedPanel.getPreferredSize().width, 25); jtfArgs.setPreferredSize(d); // mtlOptions.setPreferredSize(new Dimension(350, getPreferredSize().height)); d.width = -1; d.height = -1; JLabel tabLabel = null; int tabs = mtlOptions.getTabCount(); while (tabs-- > 0) { Component tab = mtlOptions.getTabComponentAt(tabs); if (tab == null) { if (tabLabel == null) tabLabel = new JLabel(); tabLabel.setText(mtlOptions.getTitleAt(tabs)); tab = tabLabel; } Dimension dim = tab.getPreferredSize(); d.width = Math.max(dim.width, d.width); d.height = Math.max(dim.height, d.height); } // Set width to width of largest tab * number of tabs, then add 20%. d.width = d.width * 120 / 100 * mtlOptions.getTabCount(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setIconImage(icon.getImage()); // To prevent the tabs from wrapping or scrolling setMinimumSize(new Dimension(d.width, getSize().height)); pack(); setResizable(true); }
From source file:TableLayout.java
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); measureComponents(parent);/*from w w w .j a v a2s . c om*/ int width = parent.getSize().width - (insets.left + insets.right); int height = parent.getSize().height - (insets.top + insets.bottom); // System.out.println("Resize "+width+","+height); // Decide whether to base our scaling on minimum or preferred sizes, or // a mixture of both, separately for width and height scaling. // This weighting also tells us how much of the hgap/vgap to use. double widthWeighting = 0.0; if (width >= PrefWidth || PrefWidth == MinWidth) widthWeighting = 1.0; else if (width <= MinWidth) { widthWeighting = 0.0; width = MinWidth; } else widthWeighting = (double) (width - MinWidth) / (double) (PrefWidth - MinWidth); double heightWeighting = 0.0; if (height >= PrefHeight || PrefHeight == MinHeight) heightWeighting = 1.0; else if (height <= MinHeight) { heightWeighting = 0.0; height = MinHeight; } else heightWeighting = (double) (height - MinHeight) / (double) (PrefHeight - MinHeight); // calculate scale factors to scale components to size of container, based // on weighted combination of minimum and preferred sizes double minWidthScale = (1.0 - widthWeighting) * width / MinWidth; //double prefWidthScale = widthWeighting * (width-hgap*(ncols+1))/(PrefWidth-hgap*(ncols+1)); double minHeightScale = (1.0 - heightWeighting) * height / MinHeight; double prefHeightScale = heightWeighting * (height - vgap * (nrows + 1)) / (PrefHeight - vgap * (nrows + 1)); // only get the full amount of gap if we're working to preferred size int vGap = (int) (vgap * heightWeighting); int hGap = (int) (hgap * widthWeighting); int y = insets.top + vGap; for (int c = 0; c < ncols; ++c) weight[c] = prefWidth[c]; for (int r = 0; r < nrows; ++r) { int x = insets.left + hGap; int rowHeight = (int) (minHeight[r] * minHeightScale + prefHeight[r] * prefHeightScale); // Column padding can vary from row to row, so we need several // passes through the columns for each row: // First, work out the weighting that deterimines how we distribute column padding for (int c = 0; c < ncols; ++c) { Component comp = components[c][r]; if (comp != null) { TableOption option = (TableOption) options.get(comp); if (option == null) option = defaultOption; if (option.weight >= 0) weight[c] = option.weight; else if (option.weight == -1) weight[c] = prefWidth[c]; } } int totalWeight = 0; for (int c = 0; c < ncols; ++c) totalWeight += weight[c]; int horizSurplus = width - hgap * (ncols + 1) - PrefWidth; // Then work out column sizes, essentially preferred size + share of padding for (int c = 0; c < ncols; ++c) { columnWidth[c] = (int) (minWidthScale * minWidth[c] + widthWeighting * prefWidth[c]); if (horizSurplus > 0 && totalWeight > 0) columnWidth[c] += (int) (widthWeighting * horizSurplus * weight[c] / totalWeight); } // Only now do we know enough to position all the columns within this row... for (int c = 0; c < ncols; ++c) { Component comp = components[c][r]; if (comp != null) { TableOption option = (TableOption) options.get(comp); if (option == null) option = defaultOption; // cell size may be bigger than row/column size due to spanning int cellHeight = rowHeight; int cellWidth = columnWidth[c]; for (int i = 1; i < option.colSpan; ++i) cellWidth += columnWidth[c + i]; for (int i = 1; i < option.rowSpan; ++i) cellHeight += (int) (minHeight[r + i] * minHeightScale + prefHeight[r + i] * prefHeightScale + vGap); Dimension d = new Dimension(comp.getPreferredSize()); if (d.width > cellWidth || option.horizontal == TableOption.FILL) d.width = cellWidth; if (d.height > cellHeight || option.vertical == TableOption.FILL) d.height = cellHeight; int yoff = 0; if (option.vertical == TableOption.BOTTOM) yoff = cellHeight - d.height; else if (option.vertical == TableOption.CENTRE) yoff = (cellHeight - d.height) / 2; int xoff = 0; if (option.horizontal == TableOption.RIGHT) xoff = cellWidth - d.width; else if (option.horizontal == TableOption.CENTRE) xoff = (cellWidth - d.width) / 2; // System.out.println(" "+comp.getClass().getName()+" at ("+x+"+"+xoff+","+y+"+"+yoff+"), size "+d.width+","+d.height); comp.setBounds(x + xoff, y + yoff, d.width, d.height); } x += columnWidth[c] + hGap; } y += rowHeight + vGap; } }
From source file:com.vgi.mafscaling.LogView.java
private void loadLogFile() { fileChooser.setMultiSelectionEnabled(false); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;/*from w w w . j a v a2 s . c o m*/ // close log player if (logPlayWindow != null) disposeLogView(); // process log file File file = fileChooser.getSelectedFile(); Properties prop = new Properties(); prop.put("delimiter", ","); prop.put("firstRowHasColumnNames", "true"); setCursor(new Cursor(Cursor.WAIT_CURSOR)); logDataTable.filter(null); filterText.setText(""); try { for (int i = 0; i < logDataTable.getColumnCount(); ++i) logDataTable.getTableHeader().removeMouseListener( ((CheckboxHeaderRenderer) logDataTable.getColumn(i).getHeaderRenderer()) .getMouseListener()); logDataTable.refresh(file.toURI().toURL(), prop); Column col; String colName; String lcColName; String val; CheckboxHeaderRenderer renderer; Component comp; XYSeries series; xAxisColumn.removeAllItems(); yAxisColumn.removeAllItems(); plotsColumn.removeAllItems(); xAxisColumn.addItem(""); yAxisColumn.addItem(""); plotsColumn.setText(""); plot3d.removeAllPlots(); rpmDataset.removeAllSeries(); dataset.removeAllSeries(); xyMarker.clearLabels(true); rpmCol = -1; displCount = 0; selectionCombo.removeAllItems(); listModel.removeAllElements(); JTableHeader tableHeader = logDataTable.getTableHeader(); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { col = logDataTable.getColumn(i); renderer = new CheckboxHeaderRenderer(i + 1, tableHeader); col.setHeaderRenderer(renderer); colName = col.getHeaderValue().toString(); xAxisColumn.addItem(colName); yAxisColumn.addItem(colName); plotsColumn.addItem(colName); comp = renderer.getTableCellRendererComponent(logDataTable.getTable(), colName, false, false, 0, 0); col.setPreferredWidth(comp.getPreferredSize().width + 4); series = new XYSeries(colName); series.setDescription(colName); lcColName = colName.toLowerCase(); dataset.addSeries(series); plotRenderer.setSeriesShapesVisible(i, false); plotRenderer.setSeriesVisible(i, false); selectionCombo.addItem(colName); listModel.addElement(new JLabel(colName, renderer.getCheckIcon(), JLabel.LEFT)); if (rpmDataset.getSeriesCount() == 0 && (lcColName.matches(".*rpm.*") || lcColName.matches(".*eng.*speed.*"))) { rpmDataset.addSeries(series); rpmPlotRenderer.setSeriesShapesVisible(0, false); rpmPlotRenderer.setSeriesVisible(0, false); rpmCol = i; } for (int j = 0; j < logDataTable.getRowCount(); ++j) { try { val = (String) logDataTable.getValueAt(j, i); series.add(j, Double.valueOf(val), false); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Invalid numeric value in column " + colName + ", row " + (j + 1), "Invalid value", JOptionPane.ERROR_MESSAGE); return; } } series.fireSeriesChanged(); } if (logDataTable.getControlPanel().getComponentCount() > 7) logDataTable.getControlPanel().remove(7); logDataTable.getControlPanel().add(new JLabel(" [" + file.getName() + "]")); initColors(); } catch (Exception ex) { ex.printStackTrace(); logger.error(ex); } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
/** * Returns the preferred height of a row. * The result is equal to the tallest cell in the row. * * @param rowIndex row index//from w w w .jav a 2 s . c om * @return row height */ public int getPreferredRowHeight(int rowIndex) { // Get the current default height for all rows int height = impl.getRowHeight(); // Determine highest cell in the row for (int c = 0; c < impl.getColumnCount(); c++) { TableCellRenderer renderer = impl.getCellRenderer(rowIndex, c); Component comp = impl.prepareRenderer(renderer, rowIndex, c); int componentHeight = comp.getPreferredSize().height; height = Math.max(height, componentHeight); } return height; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param table/* www .ja v a 2s.c o m*/ * @param model * @return */ public static JTable autoResizeColWidth(final JTable table, final DefaultTableModel model) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setModel(model); int margin = 5; DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); int preferredWidthTotal = 0; int renderedWidthTotal = 0; int[] colWidths = new int[table.getColumnCount()]; for (int i = 0; i < table.getColumnCount(); i++) { int vColIndex = i; TableColumn col = colModel.getColumn(vColIndex); int width = 0; // Get width of column header TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { renderer = table.getTableHeader().getDefaultRenderer(); } Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0); width = comp.getPreferredSize().width; // Get maximum width of column data for (int r = 0; r < table.getRowCount(); r++) { renderer = table.getCellRenderer(r, vColIndex); comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex); width = Math.max(width, comp.getPreferredSize().width); } // Add margin width += 2 * margin; preferredWidthTotal += col.getPreferredWidth(); colWidths[i] = width; renderedWidthTotal += width; } if (renderedWidthTotal > preferredWidthTotal) { for (int i = 0; i < table.getColumnCount(); i++) { colModel.getColumn(i).setPreferredWidth(colWidths[i]); } } ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.LEFT); // table.setAutoCreateRowSorter(true); table.getTableHeader().setReorderingAllowed(false); return table; }