コード例 #1
0
 private void setTableColumnWidths() {
   table.sizeColumnsToFit(JTable.AUTO_RESIZE_NEXT_COLUMN);
   TableColumn column = null;
   column = table.getColumnModel().getColumn(0);
   column.setMinWidth(KEY_COL_WIDTH);
   column.setPreferredWidth(KEY_COL_WIDTH);
   column = table.getColumnModel().getColumn(1);
   column.setPreferredWidth(VAL_COL_WIDTH);
 }
コード例 #2
0
 public void setModel(LogItemTableModel model) {
   this.model = model;
   logItemTable.setModel(model);
   logItemTable.getColumnModel().getColumn(0).setMinWidth(180);
   logItemTable.getColumnModel().getColumn(0).setMaxWidth(200);
   logItemTable.getColumnModel().getColumn(1).setMinWidth(50);
   logItemTable.getColumnModel().getColumn(1).setMaxWidth(80);
   logItemTable.setDefaultRenderer(Object.class, new LogEntryRenderer());
 }
コード例 #3
0
ファイル: prueba.java プロジェクト: whoeverxd/myrepo
  protected void setupTable(JTable table) {

    table.setFillsViewportHeight(true);
    table.getColumnModel().getColumn(2).setMaxWidth(150);
    table.getColumnModel().getColumn(1).setMaxWidth(150);
    table.getColumnModel().getColumn(0).setMaxWidth(150);
    //   table.getColumnModel().getColumn(0).setPreferredWidth(10);

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
  }
コード例 #4
0
  /**
   * This method implements the TableModelListener
   *
   * @param e The event to listen for.
   */
  @Override
  public void tableChanged(TableModelEvent e) {
    if (!isColumnDataIncluded) {
      return;
    }

    //  A cell has been updated

    if (e.getType() == TableModelEvent.UPDATE) {
      int column = table.convertColumnIndexToView(e.getColumn());

      //  Only need to worry about an increase in width for this cell

      if (isOnlyAdjustLarger) {
        int row = e.getFirstRow();
        TableColumn tableColumn = table.getColumnModel().getColumn(column);

        if (tableColumn.getResizable()) {
          int width = getCellDataWidth(row, column);
          updateTableColumn(column, width);
        }
      } //	Could be an increase of decrease so check all rows
      else {
        adjustColumn(column);
      }
    } //  The update affected more than one column so adjust all columns
    else {
      adjustColumns();
    }
  }
コード例 #5
0
 public void setMetricsResults(MetricDisplaySpecification displaySpecification, MetricsRun run) {
   final MetricCategory[] categories = MetricCategory.values();
   for (final MetricCategory category : categories) {
     final JTable table = tables.get(category);
     final String type = MetricsCategoryNameUtil.getShortNameForCategory(category);
     final MetricTableSpecification tableSpecification =
         displaySpecification.getSpecification(category);
     final MetricsResult results = run.getResultsForCategory(category);
     final MetricTableModel model = new MetricTableModel(results, type, tableSpecification);
     table.setModel(model);
     final Container tab = table.getParent().getParent();
     if (model.getRowCount() == 0) {
       tabbedPane.remove(tab);
       continue;
     }
     final String longName = MetricsCategoryNameUtil.getLongNameForCategory(category);
     tabbedPane.add(tab, longName);
     final MyColumnListener columnListener = new MyColumnListener(tableSpecification, table);
     final TableColumnModel columnModel = table.getColumnModel();
     columnModel.addColumnModelListener(columnListener);
     final int columnCount = columnModel.getColumnCount();
     for (int i = 0; i < columnCount; i++) {
       final TableColumn column = columnModel.getColumn(i);
       column.addPropertyChangeListener(columnListener);
     }
     setRenderers(table, type);
     setColumnWidths(table, tableSpecification);
   }
 }
コード例 #6
0
  public void adjustColumns() {
    TableColumnModel tcm = table.getColumnModel();

    for (int i = 0; i < tcm.getColumnCount(); i++) {
      adjustColumn(i);
    }
  }
コード例 #7
0
  /**
   * 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());
    }
  }
コード例 #8
0
  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;
  }
コード例 #9
0
  /*
   *  Adjust the width of the specified column in the table
   */
  public void adjustColumn(final int column) {
    TableColumn tableColumn = table.getColumnModel().getColumn(column);

    if (!tableColumn.getResizable()) return;

    int columnHeaderWidth = getColumnHeaderWidth(column);
    int columnDataWidth = getColumnDataWidth(column);
    int preferredWidth = Math.max(columnHeaderWidth, columnDataWidth);

    updateTableColumn(column, preferredWidth);
  }
コード例 #10
0
  @NotNull
  private static MyModel setTableModel(
      @NotNull JTable table,
      @NotNull UsageViewImpl usageView,
      @NotNull final List<UsageNode> data) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final int columnCount = calcColumnCount(data);
    MyModel model = table.getModel() instanceof MyModel ? (MyModel) table.getModel() : null;
    if (model == null || model.getColumnCount() != columnCount) {
      model = new MyModel(data, columnCount);
      table.setModel(model);

      ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView);
      for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
        TableColumn column = table.getColumnModel().getColumn(i);
        column.setCellRenderer(renderer);
      }
    }
    return model;
  }
コード例 #11
0
 /**
  * Establishes combo box editor for 'from onramp' column.
  *
  * @param clmn
  */
 private void setUpToOnrampColumn() {
   JComboBox combo = new JComboBox();
   Vector<AbstractNetworkElement> nes =
       ((AbstractControllerComplex) controller).getMyMonitor().getSuccessors();
   for (int i = 0; i < nes.size(); i++)
     if ((nes.get(i).getType() & TypesHWC.MASK_LINK) > 0) combo.addItem(nes.get(i));
   TableColumn clmn = zonetab.getColumnModel().getColumn(3);
   clmn.setCellEditor(new DefaultCellEditor(combo));
   clmn.setCellRenderer(new DefaultTableCellRenderer());
   return;
 }
コード例 #12
0
  private static int columnMaxWidth(@NotNull JTable table, int col) {
    TableColumn column = table.getColumnModel().getColumn(col);
    int width = 0;
    for (int row = 0; row < table.getRowCount(); row++) {
      Component component = table.prepareRenderer(column.getCellRenderer(), row, col);

      int rendererWidth = component.getPreferredSize().width;
      width = Math.max(width, rendererWidth + table.getIntercellSpacing().width);
    }
    return width;
  }
コード例 #13
0
    public static Image createImage(final JTable table, int column) {
      final int height =
          Math.max(20, Math.min(100, table.getSelectedRowCount() * table.getRowHeight()));
      final int width = table.getColumnModel().getColumn(column).getWidth();

      final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = (Graphics2D) image.getGraphics();

      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

      drawSelection(table, column, g2, width);
      return image;
    }
コード例 #14
0
 // Determines the width of each column in the table.
 protected void determineColumnWidth() {
   if (segmentTable.getColumnCount() == 2) {
     TableColumn column = null;
     for (int i = 0; i < 2; i++) {
       column = segmentTable.getColumnModel().getColumn(i);
       if (i == 0) {
         column.setPreferredWidth(30);
       } else {
         column.setPreferredWidth(100);
       }
     }
   }
 }
コード例 #15
0
  /*
   *  Calculated the width based on the column name
   */
  private int getColumnHeaderWidth(int column) {
    if (!isColumnHeaderIncluded) return 0;

    TableColumn tableColumn = table.getColumnModel().getColumn(column);
    Object value = tableColumn.getHeaderValue();
    TableCellRenderer renderer = tableColumn.getHeaderRenderer();

    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }

    Component c = renderer.getTableCellRendererComponent(table, value, false, false, -1, column);
    return c.getPreferredSize().width;
  }
コード例 #16
0
  public MainPanel() {
    super(new BorderLayout());

    table.setAutoCreateRowSorter(true);
    table.setSurrendersFocusOnKeystroke(true);
    table.setRowHeight(64);

    TableColumn c = table.getColumnModel().getColumn(1);
    c.setCellEditor(new TextAreaCellEditor());
    c.setCellRenderer(new TextAreaCellRenderer());

    add(new JScrollPane(table));
    setPreferredSize(new Dimension(320, 240));
  }
コード例 #17
0
 private void saveColumnSpecification() {
   final TableColumnModel columnModel = table.getColumnModel();
   final int numColumns = table.getColumnCount();
   final List<String> columns = new ArrayList<String>(numColumns);
   final List<Integer> columnWidths = new ArrayList<Integer>(numColumns);
   for (int i = 0; i < numColumns; i++) {
     final String columnName = table.getColumnName(i);
     columns.add(columnName);
     final TableColumn column = columnModel.getColumn(i);
     final int columnWidth = column.getWidth();
     columnWidths.add(Integer.valueOf(columnWidth));
   }
   tableSpecification.setColumnOrder(columns);
   tableSpecification.setColumnWidths(columnWidths);
   MetricsProfileRepository.getInstance().persistCurrentProfile();
 }
コード例 #18
0
  /*
   *  Calculate the width based on the widest cell renderer for the
   *  given column.
   */
  private int getColumnDataWidth(int column) {
    if (!isColumnDataIncluded) return 0;

    int preferredWidth = 0;
    int maxWidth = table.getColumnModel().getColumn(column).getMaxWidth();

    for (int row = 0; row < table.getRowCount(); row++) {
      preferredWidth = Math.max(preferredWidth, getCellDataWidth(row, column));

      //  We've exceeded the maximum width, no need to check other rows

      if (preferredWidth >= maxWidth) break;
    }

    return preferredWidth;
  }
コード例 #19
0
  /*
   *  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);
  }
コード例 #20
0
  /** Constructs a new MemorySegmentComponent. */
  public MemorySegmentComponent() {
    dataFormat = Format.DEC_FORMAT;
    listeners = new Vector();
    errorEventListeners = new Vector();
    highlightIndex = new Vector();
    segmentTable = new JTable(getTableModel());
    segmentTable.setDefaultRenderer(segmentTable.getColumnClass(0), getCellRenderer());
    startEnabling = -1;
    endEnabling = -1;

    JTextField tf = new JTextField();
    tf.setFont(Utilities.bigBoldValueFont);
    tf.setBorder(null);
    DefaultCellEditor editor = new DefaultCellEditor(tf);
    segmentTable.getColumnModel().getColumn(getColumnValue()).setCellEditor(editor);

    jbInit();
  }
コード例 #21
0
    public void mouseClicked(MouseEvent e) {
      TableColumnModel colModel = table.getColumnModel();
      int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
      int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();

      if (modelIndex < 0) return;
      if (sortCol == modelIndex) isSortAsc = !isSortAsc;
      else sortCol = modelIndex;

      for (int i = 0; i < colNames.length; i++) {
        TableColumn column = colModel.getColumn(i);
        column.setHeaderValue(getColumnName(column.getModelIndex()));
      }
      table.getTableHeader().repaint();

      Collections.sort(rowData, new MyComparator(isSortAsc));
      table.tableChanged(new TableModelEvent(MyTableModel.this));
      table.repaint();
    }
コード例 #22
0
  /** Initial method to populate the insuranceCompaniesTable */
  public void loadTable() {

    Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies();
    tableData = new InsuranceCompanyTableModel(data);
    insuranceCompaniesTable.setModel(tableData);
    insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50);
    insuranceCompaniesTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Check if db is empty and proceed with selecting only if the table is populated
    if (insuranceCompaniesTable.getRowCount() > 0) {
      // Set selected company according to selected row on load
      selectRow();
      int selectedCompanyId =
          Integer.valueOf(
              (String)
                  insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0));
    }
  }
コード例 #23
0
 private void maybeGrabSelection() {
   if (table.getSelectedRow() != -1) {
     // Grab selection
     ListSelectionModel rowSel = table.getSelectionModel();
     ListSelectionModel colSel = table.getColumnModel().getSelectionModel();
     if (!haveAnchor()) {
       //        System.err.println("Updating from table's selection");
       setSelection(
           rowSel.getAnchorSelectionIndex(), rowSel.getLeadSelectionIndex(),
           colSel.getAnchorSelectionIndex(), colSel.getLeadSelectionIndex());
     } else {
       //        System.err.println("Updating lead from table's selection");
       setSelection(
           getRowAnchor(), rowSel.getLeadSelectionIndex(),
           getColAnchor(), colSel.getLeadSelectionIndex());
     }
     //      printSelection();
   }
 }
コード例 #24
0
  private static void setColumnWidths(JTable table, MetricTableSpecification tableSpecification) {
    final TableModel model = table.getModel();
    final TableColumnModel columnModel = table.getColumnModel();

    final List<Integer> columnWidths = tableSpecification.getColumnWidths();
    final List<String> columnOrder = tableSpecification.getColumnOrder();
    if (columnWidths != null && !columnWidths.isEmpty()) {

      final int columnCount = model.getColumnCount();
      for (int i = 0; i < columnCount; i++) {
        final String columnName = model.getColumnName(i);
        final int index = columnOrder.indexOf(columnName);
        if (index != -1) {
          final Integer width = columnWidths.get(index);
          final TableColumn column = columnModel.getColumn(i);
          column.setPreferredWidth(width.intValue());
        }
      }
    } else {
      final Graphics graphics = table.getGraphics();
      final Font font = table.getFont();
      final FontMetrics fontMetrics = table.getFontMetrics(font);

      final int rowCount = model.getRowCount();
      int maxFirstColumnWidth = 100;
      for (int i = 0; i < rowCount; i++) {
        final String name = (String) model.getValueAt(i, 0);
        if (name != null) {
          final Rectangle2D stringBounds = fontMetrics.getStringBounds(name, graphics);
          final double stringWidth = stringBounds.getWidth();
          if (stringWidth > maxFirstColumnWidth) {
            maxFirstColumnWidth = (int) stringWidth;
          }
        }
      }

      final int allocatedFirstColumnWidth = Math.min(300, maxFirstColumnWidth + 5);
      final TableColumn column = columnModel.getColumn(0);
      column.setPreferredWidth(allocatedFirstColumnWidth);
    }
  }
コード例 #25
0
 private static void setRenderers(JTable table, String type) {
   final MetricTableModel model = (MetricTableModel) table.getModel();
   final MetricInstance[] metrics = model.getMetricsInstances();
   Arrays.sort(metrics, new MetricInstanceAbbreviationComparator());
   final TableColumnModel columnModel = table.getColumnModel();
   for (int i = 0; i < model.getColumnCount(); i++) {
     final String columnName = model.getColumnName(i);
     final TableColumn column = columnModel.getColumn(i);
     if (columnName.equals(type)) {
       column.setCellRenderer(new MetricCellRenderer(null));
       column.setHeaderRenderer(new HeaderRenderer(null, model, SwingConstants.LEFT));
     } else {
       final MetricInstance metricInstance = model.getMetricForColumn(i);
       final TableCellRenderer renderer = new MetricCellRenderer(metricInstance);
       column.setCellRenderer(renderer);
       final Metric metric = metricInstance.getMetric();
       final String displayName = metric.getDisplayName();
       column.setHeaderRenderer(new HeaderRenderer(displayName, model, SwingConstants.RIGHT));
     }
   }
 }
コード例 #26
0
 private JTable makeTable() {
   String empty = "";
   String[] columnNames = {"String", "Button"};
   Object[][] data = {{"AAA", empty}, {"CCC", empty}, {"BBB", empty}, {"ZZZ", empty}};
   DefaultTableModel model =
       new DefaultTableModel(data, columnNames) {
         @Override
         public Class<?> getColumnClass(int column) {
           return getValueAt(0, column).getClass();
         }
       };
   final JTable table = new JTable(model);
   table.setRowHeight(36);
   table.setAutoCreateRowSorter(true);
   // table.addMouseListener(new CellButtonsMouseListener());
   // ButtonsEditorRenderer er = new ButtonsEditorRenderer(table);
   TableColumn column = table.getColumnModel().getColumn(1);
   column.setCellRenderer(new ButtonsRenderer());
   column.setCellEditor(new ButtonsEditor(table));
   return table;
 }
コード例 #27
0
  @Override
  public void downloadBatch(DownloadBatch_Result result) {
    table = new JTable();

    tableModel = new TableModel(bState, result);

    table.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            cells = bState.cells;

            JTable target = (JTable) e.getSource();
            int row = target.getSelectedRow();
            int column = target.getSelectedColumn() - 1;
            for (ArrayList<Cell> cellRow : cells) {
              for (Cell cell : cellRow) {
                if (cell.record == row && cell.field == column) {
                  bState.setSelectedCell(cell);
                }
              }
            }
          }
        });
    table.addKeyListener(
        new KeyListener() {

          @Override
          public void keyTyped(KeyEvent e) {
            // TODO Auto-generated method stub

          }

          @Override
          public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

          }

          @Override
          public void keyReleased(KeyEvent e) {
            JTable target = (JTable) e.getSource();
            int row = target.getSelectedRow();
            int column = target.getSelectedColumn() - 1;
            if (e.getKeyCode() == KeyEvent.VK_TAB) {
              for (ArrayList<Cell> cellRow : cells) {
                for (Cell cell : cellRow) {
                  if (cell.record == row && cell.field == column) {
                    bState.setSelectedCell(cell);
                  }
                }
              }
            }
          }
        });
    table.setModel(tableModel);
    table.setRowHeight(20);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setCellSelectionEnabled(true);
    table.getTableHeader().setReorderingAllowed(false);

    TableColumnModel columnModel = table.getColumnModel();
    for (int i = 0; i < tableModel.getColumnCount(); ++i) {
      TableColumn column = columnModel.getColumn(i);
      column.setPreferredWidth(100);
    }
    for (int i = 0; i < tableModel.getColumnCount(); ++i) {
      TableColumn column = columnModel.getColumn(i);
      column.setCellRenderer(new CellRenderer());
      //			column.setCellEditor(new CellEditor());
    }

    BoxLayout box = new BoxLayout(this, BoxLayout.Y_AXIS);
    setLayout(box);
    add(table.getTableHeader());
    add(table);

    revalidate();
  }
コード例 #28
0
  public MessageStrategy() {

    JButton button = new JButton("刷新");
    button.addActionListener(new newListener());

    // 获取表格数据信息
    StrategyController controller = new StrategyController();
    int count = 0;
    ArrayList<DiscountStrategyVO> discounts = controller.getAllDiscounts();
    for (int t = 0; t < discounts.size(); t++) {
      int client = discounts.get(t).getRank();
      data[t][0] = discounts.get(t).getId();
      data[t][1] =
          "折扣:"
              + Double.toString(discounts.get(t).getDiscount())
              + "      "
              + "客户级别:"
              + Integer.toString(client);
      count++;
    }
    ArrayList<VoucherStrategyVO> vouchers = controller.getAllVouchers();
    for (int t = 0; t < vouchers.size(); t++) {
      int client = vouchers.get(t).getRank();
      data[count][0] = vouchers.get(t).getId();
      data[count][1] =
          "代金券:"
              + Double.toString(vouchers.get(t).getVoucher())
              + "      "
              + "客户级别:"
              + Integer.toString(client);
      count++;
    }
    ArrayList<CombinationStrategyVO> combinations = controller.getAllCombinations();
    for (int t = 0; t < combinations.size(); t++) {
      ArrayList<CombinationItemVO> comdities = combinations.get(t).getList();
      String comdity = "";
      for (int k = 0; k < comdities.size(); k++) {
        comdity =
            comdity
                + comdities.get(k).getCommodity()
                + ","
                + comdities.get(k).getModel()
                + ","
                + Integer.toString(comdities.get(k).getNumber())
                + ";";
      }
      data[count][0] = combinations.get(t).getId();
      data[count][1] =
          "组合商品:"
              + comdity
              + "     "
              + "原价:"
              + Double.toString(combinations.get(t).getInitialMoney())
              + "     "
              + "现价:"
              + Double.toString(combinations.get(t).getLaterMoney());
      count++;
    }
    ArrayList<GiftStrategyVO> giftClient = controller.getAllGifts();
    for (int t = 0; t < giftClient.size(); t++) {
      int client = giftClient.get(t).getRank();
      ArrayList<GiftItemVO> items = giftClient.get(t).getList();
      String giftItem = "";
      for (int k = 0; k < items.size(); k++) {
        giftItem =
            giftItem
                + items.get(k).getCommodity()
                + ","
                + items.get(k).getModel()
                + ","
                + Integer.toString(items.get(k).getNumber())
                + ";";
      }
      data[count][0] = giftClient.get(t).getId();
      data[count][1] = "客户级别:" + Integer.toString(client) + "     " + "赠品:" + giftItem;
      count++;
    }
    ArrayList<GiftBasedOnTotalMoneyVO> giftMoney = controller.getAllGBOTMs();
    for (int t = 0; t < giftMoney.size(); t++) {
      ArrayList<GBOTMItemVO> items = giftMoney.get(t).getList();
      String giftItem = "";
      for (int k = 0; k < items.size(); k++) {
        giftItem =
            giftItem
                + items.get(k).getCommodity()
                + ","
                + items.get(k).getModel()
                + ","
                + Integer.toString(items.get(k).getNumber())
                + ";";
      }
      data[count][0] = giftMoney.get(t).getId();
      data[count][1] =
          "价格下限:"
              + Double.toString(giftMoney.get(t).getLower())
              + "     "
              + "价格上限:"
              + Double.toString(giftMoney.get(t).getUpper())
              + "     "
              + "赠品:"
              + giftItem;
      count++;
    }
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);

    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(table);
    scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    table.getColumnModel().getColumn(1).setPreferredWidth(800);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    panel.setLayout(null);
    button.setBounds(330, 3, 65, 25);
    scroller.setBounds(0, 40, 410, 420);

    panel.add(button);
    panel.add(scroller);
  }
コード例 #29
0
ファイル: BodyPan.java プロジェクト: UlTMATE/Lookout
  public void setContent(String cat) {
    cat = cat.trim();
    selectAllCB.setVisible(false);
    selectAllCB.setSelected(false);
    deleteBut.setVisible(false);
    restoreBut.setVisible(false);
    refreshBut.setVisible(true);
    Object columns[] = null;
    int count = 0;
    switch (cat) {
      case "Inbox":
        columns = new Object[] {"", "From", "Date", "Subject", "Content"};
        count = Database.getCount("Inbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc");
        ;
        break;
      case "SentMail":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Sentmail");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc");
        break;
      case "Draft":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Draft");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc");
        break;
      case "Outbox":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Outbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc");
        break;
      case "Trash":
        //                restoreBut.setVisible(true);
        columns = new Object[] {"", "To/From", "Date", "Subject", "Content"};
        count = Database.getCount("Trash");
        workingSet =
            db.getData(
                "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc");
        break;
      default:
        System.out.println("in default case");
    }
    if (count > 0) {
      selectAllCB.setVisible(true);
      rows = new Object[count][];
      msgID = new int[count];
      try {
        workingSet.beforeFirst();
        for (int i = 0; i < count && workingSet.next(); i++) {
          msgID[i] = workingSet.getInt(1);
          rows[i] =
              new Object[] {
                false,
                workingSet.getString(2),
                workingSet.getDate(3),
                workingSet.getString(4),
                workingSet.getString(5)
              };
        }
      } catch (SQLException sqlExc) {
        JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE);
        sqlExc.printStackTrace();
      }

      tableModel = new MyDefaultTableModel(rows, columns);
      table = new JTable(tableModel);
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(this);
      table.getTableHeader().setOpaque(true);
      table.getTableHeader().setReorderingAllowed(false);
      //            table.getTableHeader().setBackground(Color.blue);
      table.getTableHeader().setForeground(Color.blue);
      //        table.setRowSelectionAllowed(false);
      //            table.setColumnSelectionAllowed(false);
      table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
      table.setRowHeight(20);
      table.setFillsViewportHeight(true);

      TableColumn column = null;
      for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
          column.setPreferredWidth(6);
        } else if (i == 3) {
          column.setPreferredWidth(250);
        } else if (i == 4) {
          column.setPreferredWidth(450);
        } else {
          column.setPreferredWidth(40);
        }
      }
      table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

      remove(contentPan);
      contentPan = new JScrollPane(table);
      contentPan.setBackground(Color.orange);
      contentPan.setOpaque(true);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      Home.home.homeFrame.setVisible(true);
    } else {
      JPanel centPan = new JPanel(new GridBagLayout());
      centPan.setBackground(new Color(52, 86, 70));
      JLabel label = new JLabel("No Messages In This Category");
      label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
      label.setForeground(Color.orange);
      centPan.add(label);
      remove(contentPan);
      contentPan = new JScrollPane(centPan);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      contentPan.repaint();
    }
  }
コード例 #30
0
  // {{{ InstallPanel constructor
  InstallPanel(PluginManager window, boolean updates) {
    super(new BorderLayout(12, 12));

    this.window = window;
    this.updates = updates;

    setBorder(new EmptyBorder(12, 12, 12, 12));

    final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split.setResizeWeight(0.75);
    /* Setup the table */
    table = new JTable(pluginModel = new PluginTableModel());
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setRowHeight(table.getRowHeight() + 2);
    table.setPreferredScrollableViewportSize(new Dimension(500, 200));
    table.setDefaultRenderer(
        Object.class,
        new TextRenderer((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class)));
    table.addFocusListener(new TableFocusHandler());
    InputMap tableInputMap = table.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap tableActionMap = table.getActionMap();
    tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabOutForward");
    tableActionMap.put("tabOutForward", new KeyboardAction(KeyboardCommand.TAB_OUT_FORWARD));
    tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK), "tabOutBack");
    tableActionMap.put("tabOutBack", new KeyboardAction(KeyboardCommand.TAB_OUT_BACK));
    tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "editPlugin");
    tableActionMap.put("editPlugin", new KeyboardAction(KeyboardCommand.EDIT_PLUGIN));
    tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "closePluginManager");
    tableActionMap.put(
        "closePluginManager", new KeyboardAction(KeyboardCommand.CLOSE_PLUGIN_MANAGER));

    TableColumn col1 = table.getColumnModel().getColumn(0);
    TableColumn col2 = table.getColumnModel().getColumn(1);
    TableColumn col3 = table.getColumnModel().getColumn(2);
    TableColumn col4 = table.getColumnModel().getColumn(3);
    TableColumn col5 = table.getColumnModel().getColumn(4);

    col1.setPreferredWidth(30);
    col1.setMinWidth(30);
    col1.setMaxWidth(30);
    col1.setResizable(false);

    col2.setPreferredWidth(180);
    col3.setPreferredWidth(130);
    col4.setPreferredWidth(70);
    col5.setPreferredWidth(70);

    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);
    header.addMouseListener(new HeaderMouseHandler());
    header.setDefaultRenderer(
        new HeaderRenderer((DefaultTableCellRenderer) header.getDefaultRenderer()));

    scrollpane = new JScrollPane(table);
    scrollpane.getViewport().setBackground(table.getBackground());
    split.setTopComponent(scrollpane);

    /* Create description */
    JScrollPane infoPane = new JScrollPane(infoBox = new PluginInfoBox());
    infoPane.setPreferredSize(new Dimension(500, 100));
    split.setBottomComponent(infoPane);

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            split.setDividerLocation(0.75);
          }
        });

    final JTextField searchField = new JTextField();
    searchField.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
              table.dispatchEvent(e);
              table.requestFocus();
            }
          }
        });
    searchField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              void update() {
                pluginModel.setFilterString(searchField.getText());
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                update();
              }

              @Override
              public void insertUpdate(DocumentEvent e) {
                update();
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                update();
              }
            });
    table.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            int i = table.getSelectedRow(), n = table.getModel().getRowCount();
            if (e.getKeyCode() == KeyEvent.VK_DOWN && i == (n - 1)
                || e.getKeyCode() == KeyEvent.VK_UP && i == 0) {
              searchField.requestFocus();
              searchField.selectAll();
            }
          }
        });
    Box filterBox = Box.createHorizontalBox();
    filterBox.add(new JLabel("Filter : "));
    filterBox.add(searchField);
    add(BorderLayout.NORTH, filterBox);
    add(BorderLayout.CENTER, split);

    /* Create buttons */
    Box buttons = new Box(BoxLayout.X_AXIS);

    buttons.add(new InstallButton());
    buttons.add(Box.createHorizontalStrut(12));
    buttons.add(new SelectallButton());
    buttons.add(chooseButton = new ChoosePluginSet());
    buttons.add(new ClearPluginSet());
    buttons.add(Box.createGlue());
    buttons.add(new SizeLabel());

    add(BorderLayout.SOUTH, buttons);
    String path = jEdit.getProperty(PluginManager.PROPERTY_PLUGINSET, "");
    if (!path.isEmpty()) {
      loadPluginSet(path);
    }
  } // }}}