Esempio n. 1
0
  public HexTable(ViewerHexTableModel model) {
    super(model);
    this.model = model;
    enableEvents(AWTEvent.KEY_EVENT_MASK);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    setShowGrid(false);
    setIntercellSpacing(ZERO_DIMENSION);
    alternateCellColor = getBackground();
    offsetColor = getForeground();
    asciiDumpColor = getForeground();

    setCellSelectionEnabled(true);
    setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    setDefaultEditor(Object.class, cellEditor);
    setDefaultRenderer(Object.class, cellRenderer);

    for (int i = getColumnModel().getColumnCount() - 1; i >= 0; i--) {
      TableColumn col = getColumnModel().getColumn(i);
      col.setHeaderRenderer(headerRenderer);
    }
    getTableHeader().setReorderingAllowed(false);
    setShowGrid(false);

    setFont(getFont());
  }
  // Initialize JTable
  private void initTable() {
    DialogTableModel tblModel = new DialogTableModel(students);
    studentsTbl.setModel(tblModel);

    studentsTbl.setAutoCreateRowSorter(true);
    studentsTbl.setRowSelectionAllowed(true);
    studentsTbl.getRowSorter().toggleSortOrder(1);
    studentsTbl.setGridColor(Color.gray);
    studentsTbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    studentsTbl.setRowHeight(22);

    TableColumn tc = studentsTbl.getColumnModel().getColumn(0);
    tc.setCellEditor(studentsTbl.getDefaultEditor(Boolean.class));
    tc.setCellRenderer(studentsTbl.getDefaultRenderer(Boolean.class));
    tc.setHeaderRenderer(
        new CheckBoxTableHeader(
            new ItemListener() {
              @Override
              public void itemStateChanged(ItemEvent e) {
                Object source = e.getSource();
                if (source instanceof AbstractButton == false) {
                  return;
                }
                boolean checked = e.getStateChange() == ItemEvent.SELECTED;
                for (int x = 0, y = studentsTbl.getRowCount(); x < y; x++) {
                  studentsTbl.setValueAt(new Boolean(checked), x, 0);
                }
              }
            }));
  }
  /** 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 TableCellRenderFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new PlanetTableModel();
    JTable table = new JTable(model);
    table.setRowSelectionAllowed(false);

    // set up renderers and editors

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());

    JComboBox<Integer> moonCombo = new JComboBox<>();
    for (int i = 0; i <= 20; i++) moonCombo.addItem(i);

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
    moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
    moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
    moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif")));

    // show table

    table.setRowHeight(100);
    add(new JScrollPane(table), BorderLayout.CENTER);
  }
  private void createArchiveTreeTable() {

    List l = ivcn.localFindAll();
    treeTable = new JXTreeTable(studyList);
    treeTable.setHorizontalScrollEnabled(true);
    treeTable.setRootVisible(false);
    treeTable.setShowsRootHandles(true);
    treeTable.setShowHorizontalLines(true);
    treeTable.setShowVerticalLines(true);
    treeTable.setColumnMargin(1);
    treeTable.setColumnControlVisible(false);
    treeTable.setRolloverEnabled(true);
    treeTable.setScrollsOnExpand(true);
    treeTable.setTreeCellRenderer(new TreeTableCellRenderer());
    treeTable.setAutoCreateColumnsFromModel(false);
    treeTable.setColumnFactory(
        new ColumnFactory() {
          public void configureColumnWidths(JXTable table, TableColumnExt columnExt) {}
        });
    // treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    ListSelectionModel lsm = treeTable.getSelectionModel();
    lsm.addListSelectionListener(this);

    CompoundHighlighter cp = new CompoundHighlighter();
    cp.addHighlighter(new AlternateRowHighlighter(ROW_COLOR1, ROW_COLOR2, Color.white));
    cp.addHighlighter(new HierarchicalColumnHighlighter(COL_COLOR1, Color.white));

    treeTable.setHighlighters(cp);
    for (int i = 0; i < ARCHIVE_COLUMN_WIDTH.length; i++) {
      TableColumn column = treeTable.getColumnModel().getColumn(i);
      column.setPreferredWidth(ARCHIVE_COLUMN_WIDTH[i]);
      column.setHeaderRenderer(new TableHeaderRenderer(Color.black));
    }
  }
Esempio n. 6
0
  private HeaderCellRenderer getHeaderRenderer(int idx) {
    TableColumn tc = data.getColumnModel().getColumn(idx);
    if (tc.getHeaderRenderer() != null) return (HeaderCellRenderer) tc.getHeaderRenderer();

    HeaderCellRenderer hcr = new HeaderCellRenderer();
    tc.setHeaderRenderer(hcr);

    return hcr;
  }
Esempio n. 7
0
  /** Method setSortRenderer */
  private void setSortRenderer() {
    final TableCellRenderer sortRenderer = new SortRenderer((RowTableModel) getModel());
    // TableCellRenderer rowRenderer = new RowRenderer();
    final TableColumnModel model = getColumnModel();
    final int colCount = model.getColumnCount();

    for (int i = 0; i < colCount; i++) {
      TableColumn tc = model.getColumn(i);
      tc.setHeaderRenderer(sortRenderer);
    }
  }
 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));
     }
   }
 }
Esempio n. 9
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;
      }
    }
  }
    /*
     * (non-Javadoc)
     *
     * @see javax.swing.JTable#createDefaultColumnsFromModel()
     */
    public void createDefaultColumnsFromModel() {
      TableModel m = getModel();
      if (m != null) {
        // Remove any current columns
        TableColumnModel cm = getColumnModel();
        while (cm.getColumnCount() > 0) {
          cm.removeColumn(cm.getColumn(0));
        }

        // Create new columns from the data model info
        for (int i = 0; i < m.getColumnCount(); i++) {
          TableColumn newColumn = new TableColumn(i);

          // Special renderer for supporting selection of a particular
          // column header
          newColumn.setHeaderRenderer(new DefaultTableSelectableCellRenderer());
          addColumn(newColumn);
        }
      }
    }
Esempio n. 11
0
  /**
   * *******************************************************************************
   *
   * @param directoryTree
   */
  protected DirectoryTable(DirectoryTree directoryTree, String fileExtension) {
    super(new DirectoryTableModel(directoryTree, fileExtension));

    setShowGrid(false);
    setRowSelectionAllowed(false);
    setColumnSelectionAllowed(false);
    setCellSelectionEnabled(true);
    getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    setBackground(UIManager.getColor("pmdTableBackground"));
    setRowHeight(20);
    setSelectionBackground(Color.blue);
    setSelectionForeground(Color.white);
    getSelectionModel().addListSelectionListener(new ListSelectionHandler());

    TableColumnModel columnModel = getColumnModel();
    JTableHeader tableHeader = getTableHeader();

    columnModel.setColumnMargin(2);
    tableHeader.addMouseListener(new TableHeaderMouseListener());

    //
    // Create the column renderers.
    //
    ColumnHeaderRenderer headerRenderer;
    DefaultTableCellRenderer cellRenderer;
    TableColumn column;

    //
    // Create renderers for the file name column.
    //
    column = columnModel.getColumn(DirectoryTableModel.FILE_NAME_COLUMN);
    headerRenderer = new ColumnHeaderRenderer();
    cellRenderer = new DefaultTableCellRenderer();

    cellRenderer.setIcon(UIManager.getIcon("document"));
    headerRenderer.setHorizontalAlignment(JLabel.LEFT);
    column.setHeaderRenderer(headerRenderer);
    cellRenderer.setHorizontalAlignment(JLabel.LEFT);
    column.setCellRenderer(cellRenderer);

    //
    // Create a cell renderer for the file size column.
    //
    column = columnModel.getColumn(DirectoryTableModel.FILE_SIZE_COLUMN);
    headerRenderer = new ColumnHeaderRenderer();
    cellRenderer = new DefaultTableCellRenderer();

    headerRenderer.setHorizontalAlignment(JLabel.RIGHT);
    column.setHeaderRenderer(headerRenderer);
    cellRenderer.setHorizontalAlignment(JLabel.RIGHT);
    column.setCellRenderer(cellRenderer);

    //
    // Create a cell renderer for the file last modified date column.
    //
    column = columnModel.getColumn(DirectoryTableModel.FILE_LAST_MODIFIED_COLUMN);
    headerRenderer = new ColumnHeaderRenderer();
    cellRenderer = new DefaultTableCellRenderer();

    headerRenderer.setHorizontalAlignment(JLabel.LEFT);
    column.setHeaderRenderer(headerRenderer);
    cellRenderer.setHorizontalAlignment(JLabel.LEFT);
    column.setCellRenderer(cellRenderer);

    //
    // Listeners
    //
    ListenerList.addListener((DirectoryTableEventListener) new DirectoryTableEventHandler());
  }
Esempio n. 12
0
  public LibraryApp() {
    super("Ambient Library");

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    bookTable_.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    contentPane_.setBorder(new EmptyBorder(10, 5, 10, 5));
    contentPane_.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane_);

    contentPane_.add(bookTableScrollPane_);

    contentPane_.add(keywordPanel_, BorderLayout.SOUTH);
    keywordPanel_.setBorder(new EmptyBorder(5, 0, 0, 0));
    keywordPanel_.setLayout(new BorderLayout(5, 0));
    keywordPanel_.add(keywordField_);
    keywordPanel_.add(keywordLabel_, BorderLayout.WEST);

    // bookTable_.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    bookTable_.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    bookTable_.setDefaultRenderer(String.class, bookTableCellRenderer_);
    bookTable_.setDefaultRenderer(Icon.class, statusCellRenderer_);
    bookTable_.setDefaultRenderer(ImageIcon.class, statusCellRenderer_);
    bookTable_.setCellSelectionEnabled(false);
    bookTable_.setRowSelectionAllowed(true);
    bookTable_.setSelectionBackground(Color.blue);

    JMenuItem addReviewMenuItem = new JMenuItem(ADD_REVIEW_CMD);
    JMenuItem clearReviewsMenuItem = new JMenuItem(CLR_REVIEW_CMD);
    JMenuItem editKeywordsMenuItem = new JMenuItem(EDIT_KEYWS_CMD);
    addReviewMenuItem.addActionListener(new AddReviewActionAdapter(this));
    clearReviewsMenuItem.addActionListener(new ClearReviewsActionAdapter(this));
    editKeywordsMenuItem.addActionListener(new EditKeywordsActionAdapter(this));
    popupMenu_.add(addReviewMenuItem);
    popupMenu_.add(clearReviewsMenuItem);
    popupMenu_.add(editKeywordsMenuItem);

    MouseListener popupListener = new PopupListener();
    bookTable_.addMouseListener(popupListener);

    TableColumn statusColumn = bookTable_.getColumnModel().getColumn(0);
    statusColumn.setMaxWidth(40);
    statusColumn.setMaxWidth(40);
    statusColumn.setPreferredWidth(40);

    TableColumn ratingColumn = bookTable_.getColumnModel().getColumn(3);
    ratingColumn.setMaxWidth(60);
    ratingColumn.setMaxWidth(60);
    ratingColumn.setPreferredWidth(60);

    TableColumn favorColumn = bookTable_.getColumnModel().getColumn(4);
    favorColumn.setMaxWidth(60);
    favorColumn.setMaxWidth(60);
    favorColumn.setPreferredWidth(60);

    sorter_ = new TableRowSorter<BookTableModel>(bookTableModel_);
    bookTable_.setRowSorter(sorter_);
    sorter_.setSortsOnUpdates(true);

    ImageIcon starIcon = new ImageIcon(LibraryApp.class.getResource("../icons/flatstar.png"));
    JLabel ratingLabel = new JLabel("", starIcon, JLabel.CENTER);
    TableCellRenderer ratingRenderer = new HeaderRenderer();
    ratingColumn.setHeaderRenderer(ratingRenderer);
    ratingColumn.setHeaderValue(ratingLabel);

    ImageIcon heartIcon = new ImageIcon(LibraryApp.class.getResource("../icons/flatheart.png"));
    JLabel favorLabel = new JLabel("", heartIcon, JLabel.CENTER);
    TableCellRenderer favorRenderer = new HeaderRenderer();
    favorColumn.setHeaderRenderer(favorRenderer);
    favorColumn.setHeaderValue(favorLabel);

    keywordLabel_.setIcon(heartIcon);
    keywordField_.addActionListener(new KeywordActionListener());
    keywordField_.getDocument().addDocumentListener(new KeywordDocumentListener());
    keywordField_.getDocument().putProperty("name", "Keyword Field");

    keywordField_.setText("a,e,i,o,u,y");

    this.pack();
    this.setVisible(true);
  }
  private JPanel createDirectoryPanel() {

    dirTreeTable = new JXTreeTable(new FileSystemModel());
    dirTreeTable.setHorizontalScrollEnabled(true);
    dirTreeTable.setRootVisible(false);
    dirTreeTable.setShowsRootHandles(true);
    dirTreeTable.setShowHorizontalLines(true);
    dirTreeTable.setShowVerticalLines(true);
    dirTreeTable.setColumnMargin(1);
    dirTreeTable.setColumnControlVisible(false);
    dirTreeTable.setRolloverEnabled(true);
    dirTreeTable.setScrollsOnExpand(true);
    dirTreeTable.setTreeCellRenderer(new TreeTableCellRenderer());
    dirTreeTable.setAutoCreateColumnsFromModel(false);
    // dirTreeTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    ListSelectionModel lsm = dirTreeTable.getSelectionModel();
    lsm.addListSelectionListener(this);

    CompoundHighlighter cp = new CompoundHighlighter();
    cp.addHighlighter(
        new AlternateRowHighlighter(new Color(20, 30, 45), new Color(0, 10, 25), Color.white));
    cp.addHighlighter(new HierarchicalColumnHighlighter(new Color(40, 50, 65), Color.white));

    dirTreeTable.setHighlighters(cp);
    for (int i = 0; i < DIRECTORY_COLUMN_WIDTH.length; i++) {
      TableColumn column = dirTreeTable.getColumnModel().getColumn(i);
      column.setPreferredWidth(DIRECTORY_COLUMN_WIDTH[i]);
      column.setHeaderRenderer(new TableHeaderRenderer(Color.black));
    }

    JScrollPane treeTableScrollPane =
        new JScrollPane(
            dirTreeTable,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    treeTableScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    treeTableScrollPane.setPreferredSize(new Dimension(807, 450));
    JLabel directoryLabel = new JLabel("File explorer");
    JSeparator separator1 = new JSeparator();
    separator1.setPreferredSize(new Dimension(785, 5));

    FormLayout fl =
        new FormLayout(
            "pref,2dlu,pref,10px,pref,2dlu,pref,5px,pref,2dlu,pref,5px,pref,2dlu,pref,pref:grow",
            "pref,5px,pref,2dlu,pref,2px,pref");
    CellConstraints cc = new CellConstraints();

    JPanel dirOptionPanel = new JPanel(fl);
    JLabel dirOptionsLabel = new JLabel("File explorer options");
    JSeparator separator2 = new JSeparator();
    separator2.setPreferredSize(new Dimension(300, 5));
    JLabel openAsLabel = new JLabel("Open as", JLabel.TRAILING);

    JLabel rawFileLabel = new JLabel("Raw file parameters");
    JSeparator separator3 = new JSeparator();
    separator3.setPreferredSize(new Dimension(380, 5));

    imageWidthLabel.setEnabled(false);
    imageHeightLabel.setEnabled(false);
    bitsAllocatedLabel.setEnabled(false);
    bitsStoredLabel.setEnabled(false);
    fileOffsetLabel.setEnabled(false);
    numImagesLabel.setEnabled(false);

    imageWidthTextField.setEnabled(false);
    imageHeightTextField.setEnabled(false);
    bitsAllocatedTextField.setEnabled(false);
    bitsStoredTextField.setEnabled(false);
    fileOffsetTextField.setEnabled(false);
    numImagesTextField.setEnabled(false);
    openAsComboBox.addActionListener(this);

    dirOptionPanel.add(dirOptionsLabel, cc.xywh(1, 1, 3, 1));
    dirOptionPanel.add(separator2, cc.xywh(1, 3, 3, 1));
    dirOptionPanel.add(openAsLabel, cc.xy(1, 5));
    dirOptionPanel.add(openAsComboBox, cc.xy(3, 5));
    dirOptionPanel.add(recurseCheckBox, cc.xy(3, 7));

    dirOptionPanel.add(rawFileLabel, cc.xywh(5, 1, 11, 1));
    dirOptionPanel.add(separator3, cc.xywh(5, 3, 12, 1));
    dirOptionPanel.add(imageWidthLabel, cc.xy(5, 5));
    dirOptionPanel.add(imageWidthTextField, cc.xy(7, 5));
    dirOptionPanel.add(imageHeightLabel, cc.xy(5, 7));
    dirOptionPanel.add(imageHeightTextField, cc.xy(7, 7));
    dirOptionPanel.add(bitsAllocatedLabel, cc.xy(9, 5));
    dirOptionPanel.add(bitsAllocatedTextField, cc.xy(11, 5));
    dirOptionPanel.add(bitsStoredLabel, cc.xy(9, 7));
    dirOptionPanel.add(bitsStoredTextField, cc.xy(11, 7));
    dirOptionPanel.add(fileOffsetLabel, cc.xy(13, 5));
    dirOptionPanel.add(fileOffsetTextField, cc.xy(15, 5));
    dirOptionPanel.add(numImagesLabel, cc.xy(13, 7));
    dirOptionPanel.add(numImagesTextField, cc.xy(15, 7));

    openDirButton.setEnabled(false);
    closeDirButton.setSelected(true);
    SpringLayout buttonLayout = new SpringLayout();
    JPanel buttonPanel = new JPanel(buttonLayout);
    buttonPanel.setOpaque(false);
    buttonPanel.add(openDirButton);
    buttonPanel.add(closeDirButton);
    buttonLayout.putConstraint(
        SpringLayout.NORTH, openDirButton, 0, SpringLayout.NORTH, buttonPanel);
    buttonLayout.putConstraint(SpringLayout.WEST, openDirButton, 0, SpringLayout.WEST, buttonPanel);
    buttonLayout.putConstraint(
        SpringLayout.NORTH, closeDirButton, 0, SpringLayout.NORTH, buttonPanel);
    buttonLayout.putConstraint(
        SpringLayout.WEST, closeDirButton, 5, SpringLayout.EAST, openDirButton);
    buttonLayout.putConstraint(
        SpringLayout.EAST, buttonPanel, 0, SpringLayout.EAST, closeDirButton);
    buttonLayout.putConstraint(
        SpringLayout.SOUTH, buttonPanel, 0, SpringLayout.SOUTH, closeDirButton);

    SpringLayout layout = new SpringLayout();
    JPanel dirPanel = new JPanel(layout);
    dirPanel.add(dirOptionPanel);
    dirPanel.add(directoryLabel);
    dirPanel.add(separator1);
    dirPanel.add(treeTableScrollPane);
    dirPanel.add(buttonPanel);

    layout.putConstraint(SpringLayout.NORTH, dirOptionPanel, 0, SpringLayout.NORTH, dirPanel);
    layout.putConstraint(SpringLayout.WEST, dirOptionPanel, 0, SpringLayout.WEST, dirPanel);
    layout.putConstraint(SpringLayout.NORTH, directoryLabel, 0, SpringLayout.SOUTH, dirOptionPanel);
    layout.putConstraint(SpringLayout.WEST, directoryLabel, 0, SpringLayout.WEST, dirPanel);
    layout.putConstraint(SpringLayout.NORTH, separator1, 5, SpringLayout.SOUTH, directoryLabel);
    layout.putConstraint(SpringLayout.WEST, separator1, 0, SpringLayout.WEST, dirPanel);
    layout.putConstraint(
        SpringLayout.NORTH, treeTableScrollPane, 5, SpringLayout.SOUTH, separator1);
    layout.putConstraint(SpringLayout.WEST, treeTableScrollPane, 0, SpringLayout.WEST, dirPanel);
    layout.putConstraint(
        SpringLayout.NORTH, buttonPanel, 5, SpringLayout.SOUTH, treeTableScrollPane);
    layout.putConstraint(SpringLayout.EAST, buttonPanel, 0, SpringLayout.EAST, dirPanel);
    layout.putConstraint(SpringLayout.EAST, dirPanel, 5, SpringLayout.EAST, separator1);
    layout.putConstraint(SpringLayout.SOUTH, dirPanel, 0, SpringLayout.SOUTH, buttonPanel);
    return dirPanel;
  }
  private void initComponents() {
    jbAdd =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass().getResource(res.getString("JPolicyInformation.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JPolicyInformation.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JPolicyInformation.jbAdd.mnemonic").charAt(0));

    jbAdd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              addPressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jbEdit =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass().getResource(res.getString("JPolicyInformation.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JPolicyInformation.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JPolicyInformation.jbEdit.mnemonic").charAt(0));

    jbEdit.setEnabled(false);

    jbEdit.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              editPressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jbRemove =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass()
                            .getResource(res.getString("JPolicyInformation.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JPolicyInformation.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JPolicyInformation.jbRemove.mnemonic").charAt(0));

    jbRemove.setEnabled(false);

    jbRemove.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              removePressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jpPolicyInformationButtons = new JPanel();
    jpPolicyInformationButtons.setLayout(
        new BoxLayout(jpPolicyInformationButtons, BoxLayout.Y_AXIS));
    jpPolicyInformationButtons.add(Box.createVerticalGlue());
    jpPolicyInformationButtons.add(jbAdd);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbEdit);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbRemove);
    jpPolicyInformationButtons.add(Box.createVerticalGlue());

    PolicyInformationTableModel policyInformationTableModel = new PolicyInformationTableModel();
    jtPolicyInformation = new JKseTable(policyInformationTableModel);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyInformationTableModel);
    sorter.setComparator(0, new PolicyInformationTableModel.PolicyInformationComparator());
    jtPolicyInformation.setRowSorter(sorter);

    jtPolicyInformation.setShowGrid(false);
    jtPolicyInformation.setRowMargin(0);
    jtPolicyInformation.getColumnModel().setColumnMargin(0);
    jtPolicyInformation.getTableHeader().setReorderingAllowed(false);
    jtPolicyInformation.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtPolicyInformation.setRowHeight(Math.max(18, jtPolicyInformation.getRowHeight()));

    for (int i = 0; i < jtPolicyInformation.getColumnCount(); i++) {
      TableColumn column = jtPolicyInformation.getColumnModel().getColumn(i);
      column.setHeaderRenderer(
          new PolicyInformationTableHeadRend(
              jtPolicyInformation.getTableHeader().getDefaultRenderer()));
      column.setCellRenderer(new PolicyInformationTableCellRend());
    }

    ListSelectionModel selectionModel = jtPolicyInformation.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
              updateButtonControls();
            }
          }
        });

    jtPolicyInformation.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            maybeEditPolicyInformation(evt);
          }
        });

    jtPolicyInformation.addKeyListener(
        new KeyAdapter() {
          boolean deleteLastPressed = false;

          @Override
          public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
              deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
          }

          @Override
          public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs()
                && deleteLastPressed
                && evt.getKeyCode() == KeyEvent.VK_DELETE) {
              try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                deleteLastPressed = false;
                removeSelectedPolicyInformation();
              } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
              }
            }
          }

          @Override
          public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
              try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                removeSelectedPolicyInformation();
              } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
              }
            }
          }
        });

    jspPolicyInformation =
        PlatformUtil.createScrollPane(
            jtPolicyInformation,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspPolicyInformation.getViewport().setBackground(jtPolicyInformation.getBackground());

    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(250, 150));
    add(jspPolicyInformation, BorderLayout.CENTER);
    add(jpPolicyInformationButtons, BorderLayout.EAST);

    populate();
  }
Esempio n. 15
0
  /**
   * Constructor.
   *
   * @param m TreeTableModelSorted m
   */
  public JTreeTableSorted(TreeTableModelSorted m, boolean allowSortColChange) {

    this.model = m;
    this.useThreads = model.useThreads();
    this.treeSort = model.isTreeSort();

    // create the ui
    table = new JTreeTable(model);
    setLayout(new BorderLayout());
    scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);

    // table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    // table.setFont( table.getFont().deriveFont( Font.BOLD));

    // now set the header renderers
    TableColumnModel tcm = table.getColumnModel();
    int ncolwt = useThreads ? table.getColumnCount() - 1 : table.getColumnCount();
    for (int i = 0; i < ncolwt; i++) {
      TableColumn tc = tcm.getColumn(i);
      tc.setHeaderRenderer(new SortedHeaderRenderer(model.getColumnName(i), i));
    }
    if (useThreads) {
      threadCol = ncolwt;
      threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
      tcm.getColumn(threadCol).setHeaderRenderer(threadHeaderRenderer);
    }

    // popupMenu
    popupMenu = new ucar.nc2.ui.widget.PopupMenu(table.getTableHeader(), "Visible");
    int ncols = model.getColumnCount();
    acts = new PopupAction[ncols];
    for (int i = 0; i < ncols; i++) {
      acts[i] = new PopupAction(model.getColumnName(i));
      popupMenu.addActionCheckBox(model.getColumnName(i), acts[i], true);
    }

    // listen for list selection
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting() && lm.hasListeners() && (listSelectionEvent == null)) {
                  listSelectionEvent = e;
                  if (debugEvent) System.out.println(" JTreeTableSorted message selected = " + e);
                  SwingUtilities.invokeLater(
                      new Runnable() { // gotta do this after the dust settles

                        public void run() {
                          lm.sendEvent(listSelectionEvent);
                          listSelectionEvent = null; // dont like this
                        }
                      }); // new Runnable
                }
              }
            }); // new ListSelectionListener

    // listen for mouse clicks on the column header
    allowSortColChangeMouseListener =
        new MyMouseAdapter() {
          public void click(MouseEvent e) {
            TableColumnModel tcm2 = table.getColumnModel();
            int colIdx = tcm2.getColumnIndexAtX(e.getX());
            int colNo = table.convertColumnIndexToModel(colIdx);

            // keep track of selection
            selectedRow = getSelectedRow();
            if (debug) System.out.println("----selectedRow = " + selectedRow);

            if (colNo == threadCol) { // toggle threads
              threadHeaderRenderer.setOn(!threadHeaderRenderer.isOn);
              model.setThreadsOn(threadHeaderRenderer.isOn);
              model.sort();
            } else {
              boolean reverse = model.sort(colNo);
              setSortCol(colNo, reverse);
            }

            table.fireDataChanged();
            invokeSetPath();
          }
        };
    allowSortColChange(allowSortColChange);

    // event manager for ListSelection
    lm =
        new ListenerManager(
            "javax.swing.event.ListSelectionListener",
            "javax.swing.event.ListSelectionEvent",
            "valueChanged");

    // default sort
    setSortCol(model.getSortCol(), model.getReverse());
  }
Esempio n. 16
0
  /**
   * Set the state from the last saved in the PreferencesExt.
   *
   * @param store ok if null or empty
   */
  public void restoreState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();

    // stored column order
    int[] modelIndex = (int[]) store.getBean("ColumnOrder", null);

    if ((modelIndex != null) && (modelIndex.length == ncols)) { // what about invisible ??

      // make invisible any not stored
      boolean[] visible = new boolean[ncols];
      for (int i = 0; i < modelIndex.length; i++)
        if (modelIndex[i] < ncols) visible[modelIndex[i]] = true;

      // modify popup menu
      for (int i = 0; i < ncols; i++)
        if (!visible[i]) {
          // System.out.println( colName[i]+" hide "+i);
          acts[i].hideColumn();
          acts[i].putValue(BAMutil.STATE, new Boolean(false));
        }

      // now set the header order
      TableColumnModel tcm = table.getColumnModel();
      int n = Math.min(modelIndex.length, table.getColumnCount());
      for (int i = 0; i < n; i++) {
        TableColumn tc = tcm.getColumn(i);
        tc.setModelIndex(modelIndex[i]);
        String name = model.getColumnName(modelIndex[i]);
        tc.setHeaderValue(name);
        tc.setIdentifier(name);
        if (useThreads && (modelIndex[i] == threadCol)) {
          threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
          tc.setHeaderRenderer(threadHeaderRenderer);
        } else tc.setHeaderRenderer(new SortedHeaderRenderer(name, modelIndex[i]));
      }
    }

    // set the column widths
    Object colWidths = store.getBean("ColumnWidths", null);
    if (colWidths == null) return;
    int[] size = (int[]) colWidths;

    if (size != null) setColumnWidths(size);
    if (debug) {
      System.out.println(" read widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }

    boolean isThreadsOn = store.getBoolean("isThreadsOn", false);
    if (useThreads) {
      model.setThreadsOn(isThreadsOn);
      threadHeaderRenderer.setOn(isThreadsOn);
    }

    int colNo = store.getInt("SortOnCol", 0);
    boolean reverse = store.getBoolean("SortReverse", false);
    model.setSortCol(colNo);
    model.setReverse(reverse);
    setSortCol(colNo, reverse);

    model.sort();
    table.fireDataChanged();
  }
Esempio n. 17
0
  /**
   * Descripción de Método
   *
   * @param aPanel
   * @param mTab
   * @param table
   * @return
   */
  private int setupVTable(APanel aPanel, MTab mTab, VTable table) {
    if (!mTab.isDisplayed()) {
      return 0;
    }

    int size = mTab.getFieldCount();

    for (int i = 0; i < size; i++) {
      TableColumn tc = getTableColumn(table, i);
      MField mField = mTab.getField(i);

      //

      if (mField.getColumnName().equals(tc.getIdentifier().toString())) {
        if (mField.getDisplayType() == DisplayType.RowID) {
          tc.setCellRenderer(new VRowIDRenderer(false));
          tc.setCellEditor(new VRowIDEditor(false));
          tc.setHeaderValue("");
          tc.setMaxWidth(2);
        } else {

          // need to set CellEditor explicitly as default editor based on class causes problem
          // (YesNo-> Boolean)
          if (mField.isDisplayed() && mField.isDisplayedInGrid()) {
            tc.setCellRenderer(new VCellRenderer(mField));

            VCellEditor ce = new VCellEditor(mField, this);

            tc.setCellEditor(ce);

            //

            tc.setHeaderValue(mField.getHeader());
            // tc.setPreferredWidth( Math.min( mField.getDisplayLength(),30 )); original, Modificado
            // por ConSerTi
            tc.setPreferredWidth(mField.getDisplayLength());
            tc.setMinWidth(1);

            tc.setHeaderRenderer(new VHeaderRenderer(mField.getDisplayType()));

            // Enable Button actions in grid

            if (mField.getDisplayType() == DisplayType.Button) {
              VEditor button = ce.getEditor();

              if ((button != null) && (aPanel != null)) {
                ((JButton) button).addActionListener(aPanel);
              }
            }
          } else // column not displayed
          {
            tc.setHeaderValue(null);
            tc.setMinWidth(0);
            tc.setMaxWidth(0);
            tc.setPreferredWidth(0);
          }
        }

        // System.out.println ("TableColumnID " + tc.getIdentifier ()
        // + "  Renderer=" + tc.getCellRenderer ()
        // + mField.getHeader ());
        // Modificado Por ConSerTi, para permitir campos de longuitud menor de 30
        tc.setMinWidth(10);
      } // found field
      else {
        log.log(
            Level.SEVERE,
            "TableColumn "
                + tc.getIdentifier()
                + " <> MField "
                + mField.getColumnName()
                + mField.getHeader());
      }
    } // for all fields

    table.createSortRenderers();

    return size;
  } // setupVTable