Example #1
0
 /**
  * カラムの非表示設定を行う.
  *
  * @param col 対象カラム番号
  * @param hide true:表示 false:非表示
  */
 public void setColumnHide(int col, boolean hide) {
   TableColumn tc = getColumnModel().getColumn(convertColumnIndexToView(col));
   int[] setting = new int[4];
   setting[0] = tc.getWidth();
   setting[1] = tc.getPreferredWidth();
   setting[2] = tc.getMinWidth();
   setting[3] = tc.getMaxWidth();
   if (hide) {
     if ((setting[0] == 0) && (setting[1] == 0) && (setting[2] == 0) && (setting[3] == 0)) {
       int[] baseSetting = columnSizeSetting.get(col);
       // setMaxWidthを実行する順番が大事
       tc.setMaxWidth(baseSetting[3]);
       tc.setMinWidth(baseSetting[2]);
       tc.setPreferredWidth(baseSetting[1]);
       tc.setWidth(baseSetting[0]);
     }
   } else {
     if ((setting[0] != 0) || (setting[1] != 0) || (setting[2] != 0) || (setting[3] != 0)) {
       columnSizeSetting.put(col, setting);
       // setMaxWidthを実行する順番が大事
       tc.setWidth(0);
       tc.setPreferredWidth(0);
       tc.setMinWidth(0);
       tc.setMaxWidth(0);
     }
   }
 }
Example #2
0
 private void setColumnWidths() {
   if (!initialised) {
     return;
   }
   TableColumn checkCol = getColumnModel().getColumn(0);
   TableColumn descCol = getColumnModel().getColumn(1);
   TableColumn actCol = getColumnModel().getColumn(2);
   checkCol.setMinWidth(35);
   checkCol.setMaxWidth(35);
   checkCol.setWidth(30);
   int descWidth = getFontMetrics(getFont()).stringWidth(DESC_WIDTH_TEXT);
   descCol.setMinWidth(descWidth);
   descCol.setWidth(descWidth); // no maximum set, so it will stretch...
   actCol.setMinWidth(50);
   actCol.setMaxWidth(55);
   actCol.setWidth(55);
   /* and for advanced mode: */
   if (getColumnModel().getColumnCount() > 3) {
     descCol.setMinWidth(descWidth / 2);
     TableColumn prioCol = getColumnModel().getColumn(3);
     prioCol.setMinWidth(45);
     prioCol.setMaxWidth(50);
     prioCol.setWidth(50);
   }
 }
  private void initTableVisualProperties(JTable table) {

    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setIntercellSpacing(new java.awt.Dimension(0, 0));
    // set the color of the table's JViewport
    table.getParent().setBackground(table.getBackground());

    // we'll get the parents width so we can use that to set the column sizes.
    double pw = table.getParent().getParent().getPreferredSize().getWidth();

    // #88174 - Need horizontal scrollbar for library names
    // ugly but I didn't find a better way how to do it
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setMinWidth(226);
    column.setWidth(((int) pw / 2) - 1);
    column.setPreferredWidth(((int) pw / 2) - 1);
    column.setMinWidth(75);
    column = table.getColumnModel().getColumn(1);
    column.setMinWidth(226);
    column.setWidth(((int) pw / 2) - 1);
    column.setPreferredWidth(((int) pw / 2) - 1);
    column.setMinWidth(75);
    this.addComponentListener(new TableColumnSizeComponentAdapter(table));
  }
 private boolean setColumnPreferredSize() {
   boolean sizeCalculated = false;
   Font tableFont = UIManager.getFont("Table.font");
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == GraphTableModel.ROOT_COLUMN) { // thin stripe, or root name, or nothing
       setRootColumnSize(column);
     } else if (i
         == GraphTableModel.COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i == GraphTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int maxWidth = 0;
       for (int row = 0; row < maxRowsToCheck; row++) {
         String value = getModel().getValueAt(row, i).toString();
         maxWidth = Math.max(getFontMetrics(tableFont).stringWidth(value), maxWidth);
         if (!value.isEmpty()) sizeCalculated = true;
       }
       column.setMinWidth(
           Math.min(maxWidth + UIUtil.DEFAULT_HGAP, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == GraphTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
   return sizeCalculated;
 }
Example #5
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
 public void componentResized(ComponentEvent evt) {
   double pw = table.getParent().getParent().getSize().getWidth();
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   TableColumn column = table.getColumnModel().getColumn(0);
   column.setWidth(((int) pw / 2) - 1);
   column.setPreferredWidth(((int) pw / 2) - 1);
   column = table.getColumnModel().getColumn(1);
   column.setWidth(((int) pw / 2) - 1);
   column.setPreferredWidth(((int) pw / 2) - 1);
 }
  private void fnHideColumn() {
    TableColumnModel tcm = this.tablePanel.getColumnModel();
    Object[] selected = this.cbList.getCheckBoxListSelectedValues();
    for (int i = 0; i < tcm.getColumnCount(); i++) {
      TableColumn tc = tcm.getColumn(i);
      String value = tc.getHeaderValue().toString();
      boolean matched = false;
      for (int j = 0; j < selected.length; j++) {
        if (value.equalsIgnoreCase(selected[j].toString())) {
          matched = true;
          break;
        }
      }
      if (!matched) {
        tc.setMinWidth(0);
        tc.setMaxWidth(0);
      } else {
        int width = this.model.getColumnWidth(value);
        tc.setMinWidth(width);

        tc.setWidth(width);
        tc.setPreferredWidth(width);
      }
    }
  }
Example #8
0
 /**
  * auto fit table columns width
  *
  * @version 1.0
  * @author dinglinhui
  */
 public void FitTableColumns(JTable myTable) {
   JTableHeader header = myTable.getTableHeader();
   int rowCount = myTable.getRowCount();
   Enumeration columns = myTable.getColumnModel().getColumns();
   while (columns.hasMoreElements()) {
     TableColumn column = (TableColumn) columns.nextElement();
     int col = header.getColumnModel().getColumnIndex(column.getIdentifier());
     int width =
         (int)
             myTable
                 .getTableHeader()
                 .getDefaultRenderer()
                 .getTableCellRendererComponent(
                     myTable, column.getIdentifier(), false, false, -1, col)
                 .getPreferredSize()
                 .getWidth();
     for (int row = 0; row < rowCount; row++) {
       int preferedWidth =
           (int)
               myTable
                   .getCellRenderer(row, col)
                   .getTableCellRendererComponent(
                       myTable, myTable.getValueAt(row, col), false, false, row, col)
                   .getPreferredSize()
                   .getWidth();
       width = Math.max(width, preferedWidth);
     }
     header.setResizingColumn(column); // 此行很重要
     column.setWidth(width + myTable.getIntercellSpacing().width);
   }
 }
Example #9
0
  private void initTabla() {
    tblHerramientas.setRowHeight(TABLA_DEFAULT_ALTO);
    DefaultTableModel modelo = (DefaultTableModel) tblHerramientas.getModel();

    // Ancho de Columnas
    int anchoColumna = 0;
    TableColumnModel modeloColumna = tblHerramientas.getColumnModel();
    TableColumn columnaTabla;
    for (int i = 0; i < tblHerramientas.getColumnCount(); i++) {
      columnaTabla = modeloColumna.getColumn(i);
      switch (i) {
        case TABLA_HERRAMIENTAS_COLUMNA_ESTADO:
          anchoColumna = 100;
          break;
        case TABLA_HERRAMIENTAS_COLUMNA_NOMBRE:
          anchoColumna = 350;
          break;
        case TABLA_HERRAMIENTAS_COLUMNA_HORAS:
          anchoColumna = 50;
          break;
      }
      columnaTabla.setPreferredWidth(anchoColumna);
      columnaTabla.setWidth(anchoColumna);
    }
  }
  /** function that creates History table */
  private void prepareUI() {
    for (int i = 0; i < 8; i++) {
      TableColumn column = tblTransactions.getColumnModel().getColumn(i);
      column.setHeaderRenderer(new PlainTableHeaderRenderer());
      if (i == 1 || i == 2) {
        column.setWidth(250);
        column.setMinWidth(250);
        column.setPreferredWidth(250);
      }
    }
    tblTransactions.getTableHeader().setFont(Fonts.DEFAULT_HEADING_FONT);
    tblTransactions.getTableHeader().setForeground(Color.BLACK);
    tblTransactions.getTableHeader().setBackground(Colors.TABLE_HEADER_BG_COLOR);
    tblTransactions.getTableHeader().setOpaque(true);

    scrollPane.setColumnHeader(
        new JViewport() {
          @Override
          public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.height = 25;
            return d;
          }
        });
    scrollPane.getHorizontalScrollBar().setUI(new XScrollbarUI());
    scrollPane.getVerticalScrollBar().setUI(new XScrollbarUI());
    tblTransactions.setRowHeight(25);
    tblTransactions.setDefaultRenderer(Object.class, new PlainTabelCellRenderer());
  }
  public static void pack(JTable table) {

    if (!table.isShowing() || table.getColumnCount() == 0) return;

    int width[] = new int[table.getColumnCount()];
    int total = 0;
    for (int col = 0; col < width.length; col++) {
      width[col] = preferredWidth(table, col);
      total += width[col];
    }

    int extra = table.getVisibleRect().width - total;
    if (extra > 0) {

      int bonus = extra / table.getColumnCount();
      for (int i = 0; i < width.length; i++) {
        width[i] += bonus;
      }
      extra -= bonus * table.getColumnCount();

      width[width.length - 1] += extra;
    }

    TableColumnModel columnModel = table.getColumnModel();
    for (int col = 0; col < width.length; col++) {
      TableColumn tableColumn = columnModel.getColumn(col);
      table.getTableHeader().setResizingColumn(tableColumn);
      tableColumn.setWidth(width[col]);
    }
  }
  private void removeDefaultColumn(Outline o) {
    TableColumn nodeColumn = o.getColumnModel().getColumn(0);
    nodeColumn.setHeaderValue("");
    nodeColumn.setWidth(1);
    nodeColumn.setMaxWidth(1);
    nodeColumn.setMinWidth(1);
    //        o.getColumnModel().removeColumn(nodeColumn);

  }
  /**
   * This method restores the width of the specified column to its previous width.
   *
   * @param column The column to restore.
   */
  private void restoreColumn(int column) {
    TableColumn tableColumn = table.getColumnModel().getColumn(column);
    Integer width = columnSizes.get(tableColumn);

    if (width != null) {
      table.getTableHeader().setResizingColumn(tableColumn);
      tableColumn.setWidth(width.intValue());
    }
  }
Example #14
0
 /** Initializes the table. */
 protected void init() {
   refreshTimer.setRepeats(false);
   refreshTimer.setCoalesce(true);
   setModel(rowModel);
   setColumnSelectionAllowed(true);
   setGridColor(Color.blue);
   setSelectionBackground(LIGHT_BLUE);
   setSelectionForeground(Color.red); // foreground color for selected cells
   setColumnModel(new DataTableColumnModel());
   setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
   setColumnSelectionAllowed(true);
   rowModel.addTableModelListener(
       new TableModelListener() {
         public void tableChanged(TableModelEvent e) {
           // forward the table model event to property change listeners
           DataRowTable.this.firePropertyChange("cell", null, e); // $NON-NLS-1$
         }
       });
   setDefaultRenderer(Object.class, cellRenderer);
   getTableHeader().setForeground(Color.blue); // set text color
   getTableHeader().setReorderingAllowed(true);
   getTableHeader().setDefaultRenderer(new HeaderRenderer());
   setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   int width = 24;
   String name;
   TableColumn column;
   if (getColumnCount() > 0) {
     // set width of column 0 (row index)
     name = getColumnName(0);
     column = getColumn(name);
     column.setMinWidth(width);
     column.setMaxWidth(2 * width);
     column.setWidth(width);
   }
   // set width of other columns
   width = 60;
   for (int i = 1, n = getColumnCount(); i < n; i++) {
     name = getColumnName(i);
     column = getColumn(name);
     column.setMinWidth(width);
     column.setMaxWidth(3 * width);
     column.setWidth(width);
   }
 }
Example #15
0
 /**
  * Sets the <code>TableColumn</code>'s maximum width to <code>maxWidth</code> or, if <code>
  * maxWidth</code> is less than the minimum width, to the minimum width.
  *
  * <p>If the value of the <code>width</code> or <code>preferredWidth</code> property is more than
  * the new maximum width, this method sets that property to the new maximum width.
  *
  * @param maxWidth the new maximum width
  * @see #getMaxWidth
  * @see #setPreferredWidth
  * @see #setMinWidth
  */
 @BeanProperty(description = "The maximum width of the column.")
 public void setMaxWidth(int maxWidth) {
   int old = this.maxWidth;
   this.maxWidth = Math.max(minWidth, maxWidth);
   if (width > this.maxWidth) {
     setWidth(this.maxWidth);
   }
   if (preferredWidth > this.maxWidth) {
     setPreferredWidth(this.maxWidth);
   }
   firePropertyChange("maxWidth", old, this.maxWidth);
 }
 /** Refresh the cell widths in the table. */
 public void refreshCellWidths() {
   // set width of columns
   for (int i = 0; i < getColumnCount(); i++) {
     String name = getColumnName(i);
     TableColumn statColumn = getColumn(name);
     name = dataTable.getColumnName(i);
     TableColumn dataColumn = dataTable.getColumn(name);
     statColumn.setMaxWidth(dataColumn.getWidth());
     statColumn.setMinWidth(dataColumn.getWidth());
     statColumn.setWidth(dataColumn.getWidth());
   }
 }
Example #17
0
  /**
   * Die absoulte Breite einer Spalte festlegen.
   *
   * @param iColumnIndex der Index der Spalte
   * @param iColumnWidth die absolute Breite der Spalte
   */
  protected void setColumnWidth(int iColumnIndex, int iColumnWidth) {
    if (iColumnWidth == 0) {
      setColumnWidthToZero(iColumnIndex);
      return;
    }

    TableColumn tc = table.getColumnModel().getColumn(iColumnIndex);
    tc.setMinWidth(Helper.getBreiteInPixel(QueryParameters.FLR_BREITE_MINIMUM));
    //		tc.setMaxWidth(iColumnWidth);
    //		tc.setMinWidth(iColumnWidth);
    tc.setPreferredWidth(iColumnWidth);
    tc.setWidth(iColumnWidth);
  }
 public static void configureTableColumns(JTable table, ITableColumnViewSettings[] settings) {
   TableColumnModel columnModel = table.getColumnModel();
   for (int columnIndex = 0; columnIndex < settings.length; columnIndex++) {
     TableColumn tableColumn = columnModel.getColumn(columnIndex);
     ITableColumnViewSettings view = settings[columnIndex];
     tableColumn.setCellEditor(view.getEditor());
     if (view.getRenderer() != null) {
       tableColumn.setCellRenderer(view.getRenderer());
     }
     tableColumn.setPreferredWidth(view.getPreferredWidth());
     tableColumn.setWidth(view.getPreferredWidth());
   }
 }
Example #19
0
  /**
   * Resizes the <code>TableColumn</code> to fit the width of its header cell. This method does
   * nothing if the header renderer is <code>null</code> (the default case). Otherwise, it sets the
   * minimum, maximum and preferred widths of this column to the widths of the minimum, maximum and
   * preferred sizes of the Component delivered by the header renderer. The transient "width"
   * property of this TableColumn is also set to the preferred width. Note this method is not used
   * internally by the table package.
   *
   * @see #setPreferredWidth
   */
  public void sizeWidthToFit() {
    if (headerRenderer == null) {
      return;
    }
    Component c =
        headerRenderer.getTableCellRendererComponent(null, getHeaderValue(), false, false, 0, 0);

    setMinWidth(c.getMinimumSize().width);
    setMaxWidth(c.getMaximumSize().width);
    setPreferredWidth(c.getPreferredSize().width);

    setWidth(getPreferredWidth());
  }
Example #20
0
  private void init() {
    getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setShowGrid(false);
    setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    TableColumn column = getColumnModel().getColumn(0);
    int checkBoxWidth = new JCheckBox().getPreferredSize().width;
    column.setPreferredWidth(checkBoxWidth);
    column.setMinWidth(checkBoxWidth);
    column.setWidth(checkBoxWidth);
    column.setMaxWidth(checkBoxWidth);
    column.setResizable(false);

    setTableHeader(null);
  }
  /*
   *  Update the TableColumn with the newly calculated width
   */
  private void updateTableColumn(int column, int width) {
    final TableColumn tableColumn = table.getColumnModel().getColumn(column);

    if (!tableColumn.getResizable()) return;

    width += spacing;

    //  Don't shrink the column width

    if (isOnlyAdjustLarger) {
      width = Math.max(width, tableColumn.getPreferredWidth());
    }

    columnSizes.put(tableColumn, new Integer(tableColumn.getWidth()));
    table.getTableHeader().setResizingColumn(tableColumn);
    tableColumn.setWidth(width);
  }
  public ButtonTable(Dimension buttonSize, final JButton... buttons) {
    // setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    JTable table = new JTable();
    table.setTableHeader(null);
    // table.setFillsViewportHeight(true);
    setViewportView(table);

    table.setModel(
        new AbstractTableModel() {

          @Override
          public Object getValueAt(int rowIndex, int columnIndex) {
            return null;
          }

          @Override
          public int getRowCount() {
            return buttons.length;
          }

          @Override
          public int getColumnCount() {
            return 1;
          }

          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
          }
        });

    // set all to left align... looks better
    for (JButton button : buttons) {
      button.setHorizontalAlignment(SwingConstants.LEFT);
    }

    CustomTableItemRenderer<JButton> renderer = new CustomTableItemRenderer(buttons);
    TableColumn buttonCol = table.getColumnModel().getColumn(0);
    buttonCol.setCellEditor(renderer);
    buttonCol.setCellRenderer(renderer);
    buttonCol.setWidth(buttonSize.width);
    table.setRowHeight(buttonSize.height);
    setPreferredSize(
        new Dimension(buttonSize.width + 6, table.getRowHeight() * table.getRowCount() + 10));
  }
  /**
   * Updates the column header component in the scroll pane. This depends on the current results
   * view and whether the sponsored results are visible.
   */
  private void syncColumnHeader() {
    Component resultHeader = resultsContainer.getScrollPaneHeader();
    if (resultHeader == null) {
      // If no headers, use nothing special.
      scrollPane.setColumnHeaderView(null);
    } else if (!sponsoredResultsPanel.isVisible()) {
      // If sponsored results aren't visible, just use the actual header.
      scrollPane.setColumnHeaderView(resultHeader);
    } else {
      // Otherwise, create a combined panel that has both sponsored results & header.
      JXPanel headerPanel = new JXPanel();
      // Make sure this syncs with the layout for the results & sponsored results!
      headerPanel.setLayout(new MigLayout("hidemode 3, gap 0, insets 0", "[]", "[grow][]"));
      headerPanel.add(resultHeader, "grow, push, alignx left, aligny top");

      DefaultTableColumnModel model = new DefaultTableColumnModel();
      TableColumn column = new TableColumn();
      model.addColumn(column);
      JTableHeader header = new JTableHeader(model);
      header.setDefaultRenderer(new TableCellHeaderRenderer());
      header.setReorderingAllowed(false);
      header.setResizingAllowed(false);
      header.setTable(new JXTable(0, 1));

      int width = sponsoredResultsPanel.getPreferredSize().width;
      int height = resultHeader.getPreferredSize().height;
      column.setWidth(width);
      Dimension dimension = new Dimension(width, height);
      header.setPreferredSize(dimension);
      header.setMaximumSize(dimension);
      header.setMinimumSize(dimension);

      headerPanel.add(header, "aligny top, alignx right");
      scrollPane.setColumnHeaderView(headerPanel);
    }

    scrollPane.validate();

    // Resize and repaint table header.  This eliminates visual issues due
    // to a change in the table format, which can result in an incorrect
    // header height or header flickering when a category is selected.
    if (resultHeader instanceof JTableHeader) {
      ((JTableHeader) resultHeader).resizeAndRepaint();
    }
  }
  private static int calcMaxWidth(JTable table) {
    int colsNum = table.getColumnModel().getColumnCount();

    int totalWidth = 0;
    for (int col = 0; col < colsNum - 1; col++) {
      TableColumn column = table.getColumnModel().getColumn(col);
      int preferred = column.getPreferredWidth();
      int width = Math.max(preferred, columnMaxWidth(table, col));
      totalWidth += width;
      column.setMinWidth(width);
      column.setMaxWidth(width);
      column.setWidth(width);
      column.setPreferredWidth(width);
    }

    totalWidth += columnMaxWidth(table, colsNum - 1);

    return totalWidth;
  }
Example #25
0
  private void strechShareWithRestColumns(int[] columnWidths) {
    if (columnWidths == null) return;
    List<TableColumn> columnsToStrech = new ArrayList<TableColumn>();
    int alreadyDefinedSize = 0;
    for (int i = 1; i < columnWidths.length - 1; i++) {
      TableColumn tc = table.getColumnModel().getColumn(i);
      if (columnWidths[i] == -1 && tc.getMaxWidth() > 0) columnsToStrech.add(tc);
      else alreadyDefinedSize += tc.getPreferredWidth();
    }

    if (columnsToStrech.size() == 0) return;

    int sharedTotal = table.getColumnModel().getTotalColumnWidth() - alreadyDefinedSize;
    for (TableColumn tc : columnsToStrech) {
      int newSize = sharedTotal / columnsToStrech.size();
      tc.setPreferredWidth(newSize);
      tc.setWidth(newSize);
    }
  }
Example #26
0
  protected void setResultsData() {
    getTable().setModel(getTableModel());
    int maxScoreColWidth = 0;

    for (int x = 0; x < getTableModel().getColumnCount(); x++) {
      if (x != 1) {
        getTable()
            .getColumnModel()
            .getColumn(x)
            .setCellRenderer(new ResultsTableCellRenderer(false));
      }
      TableColumn column = getTable().getColumnModel().getColumn(x);
      Component comp;

      column.setHeaderRenderer(new ResultsTableCellRenderer(true));
      comp =
          column
              .getHeaderRenderer()
              .getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
      int width = comp.getPreferredSize().width;

      for (int y = 0; y < getTableModel().getRowCount(); y++) {
        comp =
            getTable()
                .getDefaultRenderer(getTableModel().getColumnClass(x))
                .getTableCellRendererComponent(
                    getTable(), getTableModel().getValueAt(y, x), false, false, 0, x);
        if (comp.getPreferredSize().width > width) {
          width = comp.getPreferredSize().width;
        }
      }
      TableColumn col = getTable().getColumnModel().getColumn(x);

      col.setPreferredWidth(width);
      col.setMinWidth(width);
      col.setWidth(width);

      if (x >= 3 && width > maxScoreColWidth) {
        maxScoreColWidth = width;
      }
    }
  }
  public void setWidth(int width) {
    // int oldMax = getMaxWidth();
    // int oldMin = getMinWidth();
    // try {
    // setMaxWidth(Integer.MAX_VALUE);
    // setMinWidth(0);

    // int now = getWidth();

    // if ("Column: Name".equals(this.toString()) && width == 10) {
    // System.out.println("w " + this + " " + now + "->" + width);
    // }
    // if ("Column: Name".equals(this.toString()) && width == 386) {
    // System.out.println("w " + this + " " + now + "->" + width);
    // }
    super.setWidth(width);
    if (width != getWidth() && extColumn.getModel().isColumnVisible(extColumn.getIndex())) {

      org.appwork.utils.logging2.extmanager.LoggerFactory.getDefaultLogger()
          .severe(
              "Bad Column Implementation: "
                  + extColumn.getModel().getClass().getName()
                  + "/"
                  + extColumn.getName()
                  + " Min: "
                  + super.getMinWidth()
                  + " Max: "
                  + super.getMaxWidth());
    }
    // if (getModelIndex() == 8) {
    // System.out.println("w-->" + getWidth());
    // }
    // } finally {
    // setMaxWidth(oldMax);
    // setMinWidth(oldMin);
    // }

  }
Example #28
0
package com.l2fprod.common.swing.table;
  @Override
  public void propertyChange(PropertyChangeEvent event) {
    System.out.println("ktos mnie zawolal: " + event);
    tabbedPane.removeAll();

    if (event.getNewValue() instanceof XmlDocument) {
      final XmlDocument xmlDocument = (XmlDocument) event.getNewValue();

      JPanel generalPanel = new JPanel();

      GridBagLayout gridBagLayout = new GridBagLayout();
      generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
      generalPanel.setLayout(gridBagLayout);

      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.anchor = GridBagConstraints.LINE_START;
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Root element name: "), c);

      final JTextField rootElementName =
          new JTextField(
              xmlDocument.getRootElement() != null ? xmlDocument.getRootElement().getName() : "");
      rootElementName.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.getRootElement().setName(rootElementName.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(rootElementName, c);

      c.gridx = 0;
      c.gridy = 1;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Encoding: "), c);

      final JTextField encoding =
          new JTextField(xmlDocument.getEncoding() != null ? xmlDocument.getEncoding() : "");
      encoding.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.setEncoding(encoding.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 1;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(encoding, c);

      c.gridx = 0;
      c.gridy = 2;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Version: "), c);

      final JTextField version =
          new JTextField(xmlDocument.getVersion() != null ? xmlDocument.getVersion() : "");
      version.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlDocument.setVersion(version.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 2;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(version, c);

      c.gridx = 0;
      c.gridy = 3;
      c.gridwidth = 1;
      c.weighty = 1;
      generalPanel.add(new JPanel(), c);

      tabbedPane.addTab("General", null, generalPanel, "General options");

    } else if (event.getNewValue() instanceof XmlTag) {
      final XmlTag xmlTag = (XmlTag) event.getNewValue();
      JPanel generalPanel = new JPanel();

      GridBagLayout gridBagLayout = new GridBagLayout();
      generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
      generalPanel.setLayout(gridBagLayout);

      GridBagConstraints c = new GridBagConstraints();
      c.fill = GridBagConstraints.HORIZONTAL;
      c.anchor = GridBagConstraints.LINE_START;
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(new JLabel("Tag name: "), c);

      final JTextField tagName = new JTextField(xmlTag.getName());
      tagName.addFocusListener(
          new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {}

            @Override
            public void focusLost(FocusEvent e) {
              xmlTag.setName(tagName.getText());
            }
          });

      c.gridx = 1;
      c.gridy = 0;
      c.weightx = 1;
      c.weighty = 0.3;
      generalPanel.add(tagName, c);

      c.gridx = 0;
      c.gridy = 1;
      c.gridwidth = 2;
      c.weighty = 1;
      generalPanel.add(new JPanel(), c);

      tabbedPane.addTab("General", null, generalPanel, "General options");

      AttributesModel attributesModel = new AttributesModel(xmlTag);

      JTable attributesTable = new JTable(attributesModel);
      TableColumn columnName = attributesTable.getColumn("Name");
      columnName.setWidth(140);
      TableColumn columnValue = attributesTable.getColumn("Value");
      columnValue.setWidth(140);
      JPanel attrPanel = new JPanel(new BorderLayout());
      attrPanel.add(attributesTable.getTableHeader(), BorderLayout.PAGE_START);
      JScrollPane scrollPane = new JScrollPane(attributesTable);
      attrPanel.add(scrollPane, BorderLayout.CENTER);

      Schema schema = xmlTag.getSchema();
      String path = xmlTag.getPath();

      AvailableAttributesFinder aaf = new AvailableAttributesFinder(schema.getContent());
      Map<String, Boolean> availableAttributes = aaf.getAvailableAttributesForNode(path);

      attributesTable.addMouseListener(
          new AttributeTableClickListener(
              attributesTable, true, xmlTag.getSchemaType(), availableAttributes));
      scrollPane.addMouseListener(
          new AttributeTableClickListener(
              attributesTable, false, xmlTag.getSchemaType(), availableAttributes));

      tabbedPane.addTab("Attributes", null, attrPanel, "Attributes of this element");
      String text = ((XmlTag) event.getNewValue()).toString(0);

      JPanel textPanel = new JPanel();
      textPanel.setLayout(new GridLayout(0, 1));
      JTextArea textArea = new JTextArea(text);
      textArea.setEditable(false);
      textPanel.add(textArea);

      tabbedPane.addTab("Text", null, textPanel, "The text in the element");
    } else if (event.getNewValue() instanceof mxCell && ((mxCell) event.getNewValue()).isEdge()) {
      mxCell cell = (mxCell) event.getNewValue();
      mxICell source = cell.getSource();
      mxICell target = cell.getTarget();
      if (source != null
          && target != null
          && source.getParent() != null
          && target.getParent() != null) {
        XmlTag sourceTag = (XmlTag) source.getParent().getValue();
        XmlTag targetTag = (XmlTag) target.getParent().getValue();

        System.out.println(sourceTag + " -> " + targetTag);

        JPanel generalPanel = new JPanel();

        GridBagLayout gridBagLayout = new GridBagLayout();
        generalPanel.setAlignmentY(Component.TOP_ALIGNMENT);
        generalPanel.setLayout(gridBagLayout);

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.anchor = GridBagConstraints.LINE_START;
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(new JLabel("Source tag name: "), c);

        final JTextField sourceTagName =
            new JTextField(sourceTag.getName() != null ? sourceTag.getName() : "");
        sourceTagName.setEditable(false);

        c.gridx = 1;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(sourceTagName, c);

        c.gridx = 0;
        c.gridy = 1;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(new JLabel("Target tag name: "), c);

        final JTextField targetTagName =
            new JTextField(targetTag.getName() != null ? targetTag.getName() : "");
        targetTagName.setEditable(false);

        c.gridx = 1;
        c.gridy = 1;
        c.weightx = 1;
        c.weighty = 0.3;
        generalPanel.add(targetTagName, c);

        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 1;
        c.weighty = 1;
        generalPanel.add(new JPanel(), c);

        tabbedPane.addTab("General", null, generalPanel, "General options");
      }
    }
  }
Example #30
0
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {

    scroll1 = new javax.swing.JScrollPane();
    table = new javax.swing.JTable();
    btnAdd =
        new JButton(
            new AddRemoveRowAction(
                "",
                ImageFetcher.createIcon("openicon.png"),
                "Add New Row",
                new Integer(KeyEvent.VK_A)));
    btnRem =
        new JButton(
            new AddRemoveRowAction(
                "",
                ImageFetcher.createIcon("closeicon.png"),
                "Remove Last Row",
                new Integer(KeyEvent.VK_D)));
    scroll2 = new javax.swing.JScrollPane();
    pnlRows = new javax.swing.JPanel();

    addComponentListener(
        new java.awt.event.ComponentAdapter() {

          @Override
          public void componentResized(java.awt.event.ComponentEvent evt) {
            doRefresh(evt);
          }
        });

    scroll1.setBackground(new java.awt.Color(0, 0, 0));
    scroll1.setHorizontalScrollBarPolicy(
        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

    table.setModel(createCustomTable());
    tblHeader = table.getTableHeader();
    columnTotal = table.getModel().getColumnCount();
    tblHeader.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent me) {
            arrangeRows();
            validate();
          }
        });

    int i = 0;
    Enumeration enumCol = table.getColumnModel().getColumns();
    int prefwidth[] = columnsWidth();
    while (enumCol.hasMoreElements()) {
      TableColumn col = (TableColumn) enumCol.nextElement();
      col.setPreferredWidth(prefwidth[i]);
      if (i != 0) col.setWidth(DEF_MIN_WIDTH);
      else col.setWidth(MIN_MIN_WIDTH);
      i++;
    }
    scroll1.setViewportView(table);

    scroll2.setBorder(null);

    javax.swing.GroupLayout pnlRowsLayout = new javax.swing.GroupLayout(pnlRows);
    pnlRows.setLayout(pnlRowsLayout);
    pnlRowsLayout.setHorizontalGroup(
        pnlRowsLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 320, Short.MAX_VALUE));
    pnlRowsLayout.setVerticalGroup(
        pnlRowsLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 159, Short.MAX_VALUE));

    scroll2.setViewportView(pnlRows);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addComponent(
                        btnAdd,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        25,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, 0)
                    .addComponent(
                        btnRem,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        25,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(270, Short.MAX_VALUE))
            .addComponent(scroll1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
            .addComponent(scroll2, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(
                                btnRem,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE)
                            .addComponent(
                                btnAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
                    .addGap(0, 0, 0)
                    .addComponent(
                        scroll1,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        24,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, 0)
                    .addComponent(
                        scroll2, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)));
  } // </editor-fold>