/*
   * Update radio button names in the same order as the table
   */
  private void updateControlPanel() {
    schedule.removeAll();
    noneButton.setName(""); // Name holds schedule id for the selected radio button
    noneButton.setSelected(true);
    commentTextArea.setText(""); // no text for the noneButton
    enableButtons(false);
    schedule.add(noneButton);
    schGroup.add(noneButton);

    for (int i = trainsScheduleModel.getFixedColumn();
        i < trainsScheduleModel.getColumnCount();
        i++) {
      log.debug("Column name: {}", trainsScheduleTable.getColumnName(i));
      TrainSchedule ts =
          trainScheduleManager.getScheduleByName(trainsScheduleTable.getColumnName(i));
      if (ts != null) {
        JRadioButton b = new JRadioButton();
        b.setText(ts.getName());
        b.setName(ts.getId());
        schedule.add(b);
        schGroup.add(b);
        addRadioButtonAction(b);
        if (b.getName().equals(trainManager.getTrainScheduleActiveId())) {
          b.setSelected(true);
          enableButtons(true);
          // update comment field
          commentTextArea.setText(ts.getComment());
        }
      }
    }
    schedule.revalidate();
  }
  /**
   * Exports the given table to the given text file.
   *
   * @param fileName Name of the file
   * @param table Table to export
   * @throws IOException Thrown if an error occurs while writing to the file.
   */
  public void export(String fileName, JTable table) throws IOException {
    BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));

    // Export selected rows
    int[] rows = table.getSelectedRows();

    // Export entire table if there is no selection
    if (rows == null || rows.length < 1) {
      rows = new int[table.getRowCount()];
      for (int i = 0; i < rows.length; i++) {
        rows[i] = i;
      }
    }

    // Write headers
    for (int col = 0; col < table.getColumnCount(); col++) {
      bw.write(LINE_COMMENT);
      bw.write(table.getColumnName(col));
      if (col != table.getColumnCount()) bw.write(COL_DELIMITER);
    }
    bw.write(ROW_DELIMITER);

    // Write table content
    for (int row : rows) {
      for (int col = 0; col < table.getColumnCount(); col++) {
        Object o = table.getValueAt(row, col);
        if (o != null) bw.write(o.toString());
        if (col != table.getColumnCount()) bw.write(COL_DELIMITER);
      }
      bw.write(ROW_DELIMITER);
    }

    bw.close();
  }
Example #3
0
  private Vector<String> getColumnNames() {
    Vector<String> columnNames = new Vector<String>();

    for (int i = 0; i < jTable1.getColumnCount(); i++) columnNames.add(jTable1.getColumnName(i));

    return columnNames;
  }
 private int buscarColumna(String busColumna, javax.swing.JTable tablaAbuscar) {
   int busCol = 0;
   for (int i = 0; i < tablaAbuscar.getColumnCount(); i++) {
     if (tablaAbuscar.getColumnName(i).equals(busColumna)) busCol = i;
   }
   return busCol;
 }
Example #5
0
  void saveTableFile() {
    java.io.File file = tableFileChooser.getSelectedFile();
    try {
      FileWriter fwriter = new FileWriter(file);
      BufferedWriter bwriter = new BufferedWriter(fwriter);

      for (int j = 0; j < table.getColumnCount(); j++) {
        String xml = "";
        xml += table.getColumnName(j);
        bwriter.write(xml);
        bwriter.write('\t');
      }
      bwriter.newLine();

      for (int i = 0; i < table.getRowCount(); i++) {
        // xml+= "<row number = '" + i + "'>\n";
        for (int j = 0; j < table.getColumnCount(); j++) {
          String xml = "";
          xml += table.getValueAt(i, j);
          bwriter.write(xml);
          bwriter.write('\t');
        }
        // xml += "\n";
        bwriter.newLine();
      }

      // fwriter.write(xml);
      // fwriter.close();

      bwriter.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
Example #6
0
 public void actionPerformed(ActionEvent e) {
   Object value = getValue(NAME);
   if (value == MNEMONIC) {
     JComponent c = (JComponent) e.getSource();
     c.requestFocusInWindow();
     value = getValue(MNEMONIC);
     if (value != null) {
       JComboBox combo = (JComboBox) c;
       combo.setSelectedItem(value);
     }
   } else if (value == EDIT) {
     JTable table = (JTable) e.getSource();
     int row = table.getSelectionModel().getLeadSelectionIndex();
     if (row < 0 || row >= table.getRowCount()) return;
     int col = UITableModel.VALUE_COLUMN_INDEX;
     table.editCellAt(row, table.convertColumnIndexToView(col));
   } else if (value == SORT) {
     value = getValue(SORT);
     JTable table = (JTable) e.getSource();
     for (int col = table.getColumnCount(); --col >= 0; ) {
       if (value.equals(table.getColumnName(col))) {
         table.getRowSorter().toggleSortOrder(table.convertColumnIndexToModel(col));
         break;
       }
     }
   } else if (value == CLOSE) {
     SwingUtilities.getWindowAncestor((Component) e.getSource()).dispose();
   }
 }
Example #7
0
  /**
   * CONSTRUCTOR This would be the ideal constructor, but there are issues with the initcomponents
   * in Analyster so the tab must be initialized first then the table can be added
   *
   * @param table
   */
  public Tab(JTable table) {
    tableName = "";
    this.table = table;
    totalRecords = 0;
    recordsShown = 0;
    filter = new TableFilter(table);
    ColumnPopupMenu = new ColumnPopupMenu(filter);

    // store the column names for the table
    for (int i = 0; i < table.getColumnCount(); i++) tableColNames[i] = table.getColumnName(i);
  }
Example #8
0
  public static TableColumn getTableColumn(JTable table, int columnIndex) {
    if (table == null) {
      throw new NullPointerException();
    }

    String columnName = table.getColumnName(columnIndex);
    if (columnName == null) {
      return null;
    }

    TableColumn column = table.getColumn(columnName);

    return column;
  }
Example #9
0
 private static void registerSortMnemonics(JTable t) {
   for (int col = t.getColumnCount(); --col >= 0; ) {
     String name = t.getColumnName(col);
     int idx = name.indexOf('\u0332');
     if (idx > 0) {
       int mnemonic = (int) Character.toUpperCase(name.charAt(idx - 1));
       Actions act = new Actions(Actions.SORT);
       act.putValue(Actions.SORT, name);
       t.getInputMap(JComponent.WHEN_FOCUSED)
           .put(KeyStroke.getKeyStroke(mnemonic, InputEvent.ALT_DOWN_MASK), act);
       t.getActionMap().put(act, act);
     }
   }
 }
 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();
 }
Example #11
0
  ClauseOrder(QueryClauses clauses) {
    super(new GridLayout(1, 2));

    this.clauses = clauses;

    DefaultPanel pnl;
    JToolBar bar;
    JScrollPane scroll;

    DefaultTableModel model =
        new DefaultTableModel(0, 2) {
          public boolean isCellEditable(int row, int column) {
            return column == 0;
          }
        };

    this.add(pnl = new DefaultPanel());
    pnl.setCenterComponent(
        scroll = new JScrollPane(availableExpressions = new JList(new DefaultListModel())));
    pnl.setEastComponent(bar = new JToolBar(JToolBar.VERTICAL));
    bar.add(createButton("put >", PUT));
    bar.add(createButton("< push", PUSH));
    bar.setFloatable(false);

    this.add(pnl = new DefaultPanel());
    pnl.setCenterComponent(scroll = new JScrollPane(selectedExpressions = new JTable(model)));
    pnl.setEastComponent(bar = new JToolBar(JToolBar.VERTICAL));
    bar.add(createButton("up", UP));
    bar.add(createButton("down", DOWN));
    bar.setFloatable(false);
    scroll.getViewport().setBackground(selectedExpressions.getBackground());

    TableColumn tableColumn = selectedExpressions.getColumn(selectedExpressions.getColumnName(0));
    tableColumn.setCellEditor(new CheckBoxCellRenderer());
    tableColumn.setCellRenderer(new CheckBoxCellRenderer());
    tableColumn.setPreferredWidth(15);
    tableColumn.setMaxWidth(15);
    tableColumn.setResizable(false);

    selectedExpressions.setIntercellSpacing(new Dimension(0, 0));
    selectedExpressions.setShowGrid(false);
    selectedExpressions.setColumnSelectionAllowed(false);
    selectedExpressions.setDefaultRenderer(Boolean.class, new CheckBoxCellRenderer());
    selectedExpressions.getTableHeader().setPreferredSize(new Dimension(0, 0));
    selectedExpressions.getTableHeader().setVisible(false);
  }
 @Override
 public void mouseClicked(MouseEvent e) {
   int col = table.columnAtPoint(new Point(e.getX(), e.getY()));
   String header = table.getColumnName(col);
   if (columnHeader.contains(header)) {
     int row = table.rowAtPoint(new Point(e.getX(), e.getY()));
     TableModel tableModel = table.getModel();
     Object val =
         tableModel.getValueAt(
             table.convertRowIndexToModel(row), table.convertColumnIndexToModel(col));
     if (val != null) {
       String text = val.toString();
       textDialog.setText(text);
       textDialog.setVisible(true);
     }
   }
 }
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   JLabel c =
       (JLabel)
           super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   if (table.getRowSorter().convertRowIndexToModel(row) == currentActor.getDefaultAttack()) {
     MiscUtil.setLabelBold(c);
   }
   // Check parsing: at some point may want to create 'ParsingComponent' which has label and
   // textfield versions
   AttackTableModel.columns col = AttackTableModel.columns.valueOf(table.getColumnName(column));
   if (col == columns.Damage
       && !ParsingFieldParserFactory.DamageParser().parseIsValid(c.getText()))
     c.setForeground(Color.red);
   else c.setForeground(Color.black);
   return c;
 }
  private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger() && table.isEnabled()) {
      currentPoint = new Point(e.getX(), e.getY());
      curCol = table.columnAtPoint(currentPoint);
      curRow = table.rowAtPoint(currentPoint);

      if (curRow < 0 || curRow >= table.getRowCount()) {
        return;
      }
      // translate table index to model index
      int mcol = table.getColumn(table.getColumnName(curCol)).getModelIndex();
      logger.debug("curRow, mcol" + curRow + " " + mcol);

      // .. create popup menu...
      JPopupMenu contextMenu = createContextMenu(curRow, mcol);

      // ... and show it
      if (contextMenu != null && contextMenu.getComponentCount() > 0) {
        contextMenu.show(table, currentPoint.x, currentPoint.y);
      }
    }
  }
  /**
   * Exports currently selected table to file
   *
   * @param tabbedPane - Currently loaded tabbedPane
   */
  public void exportCSVToFile(JTabbedPane tabbedPane) {

    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select where you'd like to save the CSV file");
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    String tabName = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
    chooser.setSelectedFile(new File(tabName.replaceAll("/", "-")));
    chooser.setAcceptAllFileFilterUsed(true);

    // If user chooses valid directory then saves CSV there
    if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
      String filepath = chooser.getSelectedFile() + ".csv";
      try {
        // Uses a file choo
        FileWriter writer = new FileWriter(filepath);
        JScrollPane currentScrollPane =
            (JScrollPane) tabbedPane.getComponentAt(tabbedPane.getSelectedIndex());
        JViewport viewport = currentScrollPane.getViewport();
        JTable currentTable = (JTable) viewport.getView();

        // Goes through column headings and adds to CSV file
        for (int i = 0; i < currentTable.getColumnCount(); i++) {
          writer.write(currentTable.getColumnName(i) + ",");
        }
        writer.write("\n");
        // Goes through rows and adds to CSV file
        for (int i = 0; i < currentTable.getRowCount(); i++) {
          for (int j = 0; j < currentTable.getColumnCount(); j++) {
            writer.write(currentTable.getValueAt(i, j).toString() + ",");
          }
          writer.write("\n");
        }
        writer.close();
        JOptionPane.showMessageDialog(null, "Table data successfully exported as CSV file");
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
 public static void makeFace(JTable table) {
   try {
     DefaultTableCellRenderer tcr =
         new DefaultTableCellRenderer() {
           public Component getTableCellRendererComponent(
               JTable table,
               Object value,
               boolean isSelected,
               boolean hasFocus,
               int row,
               int column) {
             if (row % 2 == 0) setBackground(Color.white); // 设置奇数行底色
             else if (row % 2 == 1) setBackground(new Color(206, 231, 255)); // 设置偶数行底色
             return super.getTableCellRendererComponent(
                 table, value, isSelected, hasFocus, row, column);
           }
         };
     for (int i = 0; i < table.getColumnCount(); i++) {
       table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
  @Override
  public JComponent createComponent() {
    myPanel =
        new JPanel(new GridBagLayout()) {
          @Override
          public Dimension getPreferredSize() {
            return new Dimension(-1, 400);
          }
        };

    myExtPanel =
        new AddEditRemovePanel<NameLocationPair>(
            new ExtUrlsTableModel(),
            myPairs,
            XmlBundle.message("label.edit.external.resource.configure.external.resources")) {
          @Override
          protected NameLocationPair addItem() {
            return addExtLocation();
          }

          @Override
          protected boolean removeItem(NameLocationPair o) {
            setModified(true);
            return true;
          }

          @Override
          protected NameLocationPair editItem(NameLocationPair o) {
            return editExtLocation(o);
          }
        };
    myExtPanel.getTable().setShowColumns(true);

    myExtPanel.setRenderer(1, new PathRenderer());

    JTable table = myExtPanel.getTable();
    if (myProject != null) {
      TableColumn column = table.getColumn(table.getColumnName(2));
      column.setMaxWidth(50);
      column.setCellEditor(JBTable.createBooleanEditor());
    }

    table
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                setModified(true);
              }
            });
    myIgnorePanel =
        new AddEditRemovePanel<String>(
            new IgnoredUrlsModel(),
            myIgnoredUrls,
            XmlBundle.message("label.edit.external.resource.configure.ignored.resources")) {
          @Override
          protected String addItem() {
            return addIgnoreLocation();
          }

          @Override
          protected boolean removeItem(String o) {
            setModified(true);
            return true;
          }

          @Override
          protected String editItem(String o) {
            return editIgnoreLocation(o);
          }
        };

    myPanel.add(
        myExtPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myPanel.add(
        myIgnorePanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    myExtPanel.setData(myPairs);
    myIgnorePanel.setData(myIgnoredUrls);

    myExtPanel.getEmptyText().setText(XmlBundle.message("no.external.resources"));
    myIgnorePanel.getEmptyText().setText(XmlBundle.message("no.ignored.resources"));

    return myPanel;
  }
Example #18
0
 public void setTableColNames(JTable table) {
   tableColNames = new String[table.getColumnCount()];
   for (int i = 0; i < table.getColumnCount(); i++) tableColNames[i] = table.getColumnName(i);
 }
  /**
   * Returns a html representation of the construction protocol.
   *
   * @param imgBase64 : image file to be included
   */
  public String getHTML(String imgBase64) {
    StringBuilder sb = new StringBuilder();

    boolean icon_column;

    // Let's be W3C compliant:
    sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n");
    sb.append("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
    sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">");
    sb.append("<head>\n");
    sb.append("<title>");
    sb.append(StringUtil.toHTMLString(GeoGebraConstants.APPLICATION_NAME));
    sb.append(" - ");
    sb.append(app.getPlain("ConstructionProtocol"));
    sb.append("</title>\n");
    sb.append("<meta keywords = \"");
    sb.append(StringUtil.toHTMLString(GeoGebraConstants.APPLICATION_NAME));
    sb.append(" export\">");

    sb.append(
        "<style type=\"text/css\"><!--body { font-family:Arial,Helvetica,sans-serif; margin-left:40px }--></style>");

    sb.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");
    sb.append("</head>\n");

    sb.append("<body>\n");

    // header with title
    Construction cons = kernel.getConstruction();
    String title = cons.getTitle();
    if (!title.equals("")) {
      sb.append("<h1>");
      sb.append(StringUtil.toHTMLString(title));
      sb.append("</h1>\n");
    }

    // header with author and date
    String author = cons.getAuthor();
    String date = cons.getDate();
    String line = null;
    if (!author.equals("")) {
      line = author;
    }
    if (!date.equals("")) {
      if (line == null) line = date;
      else line = line + " - " + date;
    }
    if (line != null) {
      sb.append("<h3>");
      sb.append(StringUtil.toHTMLString(line));
      sb.append("</h3>\n");
    }

    // include image file
    if (imgBase64 != null) {
      sb.append("<p>\n");
      sb.append("<img src=\"data:image/png;base64,");
      sb.append(imgBase64);
      sb.append("\" alt=\"");
      sb.append(StringUtil.toHTMLString(GeoGebraConstants.APPLICATION_NAME));
      sb.append(' ');
      sb.append(StringUtil.toHTMLString(app.getPlain("DrawingPad")));
      sb.append("\" border=\"1\">\n");
      sb.append("</p>\n");
    }

    // table
    sb.append("<table border=\"1\">\n");

    // table headers
    sb.append("<tr>\n");
    TableColumnModel colModel = table.getColumnModel();
    int nColumns = colModel.getColumnCount();

    for (int nCol = 0; nCol < nColumns; nCol++) {
      // toolbar icon will only be inserted on request

      icon_column = table.getColumnName(nCol).equals("ToolbarIcon");
      if ((icon_column && addIcons) || !icon_column) {
        TableColumn tk = colModel.getColumn(nCol);
        title = (String) tk.getIdentifier();
        sb.append("<th>");
        sb.append(StringUtil.toHTMLString(title));
        sb.append("</th>\n");
      }
    }
    sb.append("</tr>\n");

    // table rows
    int endRow = table.getRowCount();
    for (int nRow = 0; nRow < endRow; nRow++) {
      sb.append("<tr  valign=\"baseline\">\n");
      for (int nCol = 0; nCol < nColumns; nCol++) {

        // toolbar icon will only be inserted on request
        icon_column = table.getColumnName(nCol).equals("ToolbarIcon");
        if ((icon_column && addIcons) || !icon_column) {
          int col = table.getColumnModel().getColumn(nCol).getModelIndex();
          String str =
              StringUtil.toHTMLString(
                  ((ConstructionTableData) data).getPlainHTMLAt(nRow, col), false);
          sb.append("<td>");
          if (str.equals("")) sb.append("&nbsp;"); // space
          else {
            Color color = ((ConstructionTableData) data).getColorAt(nRow, col);
            if (color != Color.black) {
              sb.append("<span style=\"color:#");
              sb.append(StringUtil.toHexString(new org.geogebra.desktop.awt.GColorD(color)));
              sb.append("\">");
              sb.append(str);
              sb.append("</span>");
            } else sb.append(str);
          }
          sb.append("</td>\n");
        }
      }
      sb.append("</tr>\n");
    }

    sb.append("</table>\n");

    // footer
    sb.append(((GuiManagerD) app.getGuiManager()).getCreatedWithHTML(false));

    // append base64 string so that file can be reloaded with File -> Open
    sb.append(
        "\n<!-- Base64 string so that this file can be opened in GeoGebra with File -> Open -->");
    sb.append("\n<applet style=\"display:none\">");
    sb.append("\n<param name=\"ggbBase64\" value=\"");
    appendBase64((AppD) app, sb);
    sb.append("\">\n<applet>");

    sb.append("\n</body>");
    sb.append("\n</html>");

    return sb.toString();
  }