Exemple #1
0
  /**
   * Constructs a ClutoTree diaplay which is initialized with tableModel as the data model, and the
   * given selection model.
   *
   * @param clutoSolution The clustering solution
   * @param tableContext The context which manages views and selections.
   * @param tableModel the data model for the parallel coordinate display
   */
  public ClutoTree(ClutoSolution clutoSolution, TableContext tableContext, TableModel tableModel) {
    ctx = tableContext;
    tm = tableModel;
    lsm = ctx.getRowSelectionModel(tm);

    // labelModel
    int ncol = tm.getColumnCount();
    for (int i = 0; i < ncol; i++) {
      labelModel.addElement(tm.getColumnName(i));
    }

    setLayout(new BorderLayout());
    btnP = new JToolBar();
    add(btnP, BorderLayout.NORTH);
    labelChoice.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              labelColumn = 0;
              String ln = (String) e.getItem();
              if (ln != null) {
                for (int c = 0; c < tm.getColumnCount(); c++) {
                  if (ln.equals(tm.getColumnName(c))) {
                    labelColumn = c;
                    break;
                  }
                }
              }
              graph.invalidate();
              validate();
              repaint();
            }
          }
        });
    btnP.add(labelChoice);

    graph = new SimpleGraph();
    graph.getGraphDisplay().setOpaque(true);
    graph.getGraphDisplay().setBackground(Color.white);
    graph.getGraphDisplay().setGridColor(new Color(220, 220, 220));
    graph.showGrid(false);
    graph.showAxis(BorderLayout.WEST, false);
    graph.showAxis(BorderLayout.EAST, true);
    graph.getAxisDisplay(BorderLayout.EAST).setZoomable(true);
    graph.getAxisDisplay(BorderLayout.EAST).setAxisLabeler(labeler);
    ((LinearAxis) graph.getYAxis()).setTickIncrement(-1.);
    graph.getAxisDisplay(BorderLayout.SOUTH).setZoomable(true);
    gs = new GraphSegments();
    gs.setColor(Color.blue);
    idxSelColor = new IndexSelectColor(Color.cyan, null, new DefaultListSelectionModel());
    gs.setIndexedColor(idxSelColor);
    graph.addGraphItem(gs);
    graph.getGraphDisplay().addMouseListener(ma);

    add(graph);
    if (lsm != null) {
      lsm.addListSelectionListener(selListener);
    }
    display(makeTree(clutoSolution));
  }
    private Object getValueWithoutWebEditorsFormat(int row, int column) {
      Object r = original.getValueAt(row, column);

      if (r instanceof Boolean) {
        if (((Boolean) r).booleanValue()) return XavaResources.getString(locale, "yes");
        return XavaResources.getString(locale, "no");
      }
      if (withValidValues) {
        MetaProperty p = getMetaProperty(column);
        if (p.hasValidValues()) {
          return p.getValidValueLabel(locale, original.getValueAt(row, column));
        }
      }

      if (r instanceof java.util.Date) {
        MetaProperty p =
            getMetaProperty(column); // In order to use the type declared by the developer
        // and not the one returned by JDBC or the JPA engine
        if (java.sql.Time.class.isAssignableFrom(p.getType())) {
          return DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(r);
        }
        if (java.sql.Timestamp.class.isAssignableFrom(p.getType())) {
          DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
          return dateFormat.format(r);
        }
        return DateFormat.getDateInstance(DateFormat.SHORT, locale).format(r);
      }

      if (r instanceof BigDecimal) {
        return formatBigDecimal(r, locale);
      }

      return r;
    }
Exemple #3
0
 private boolean noProperContent() {
   return model == null
       || model.getRowCount() <= 0
       || model.getColCount() <= 0
       || colWidth == null
       || colWidth.length <= 0;
 }
 /** Overrides <code>JComponent</code>'s <code>getToolTipText</code> */
 public String getToolTipText(MouseEvent e) {
   String tip = null;
   java.awt.Point p = e.getPoint();
   int rowIndex = rowAtPoint(p);
   // int colIndex = columnAtPoint(p);
   // int realColumnIndex = convertColumnIndexToModel(colIndex);
   TableModel model = getModel();
   tip = (String) model.getValueAt(rowIndex, 1);
   return tip;
 }
  //
  //  Implement the PropertyChangeListener
  //
  public void propertyChange(PropertyChangeEvent e) {
    //  When the TableModel changes we need to update the listeners
    //  and column widths

    if ("model".equals(e.getPropertyName())) {
      TableModel model = (TableModel) e.getOldValue();
      model.removeTableModelListener(this);

      model = (TableModel) e.getNewValue();
      model.addTableModelListener(this);
      adjustColumns();
    }
  }
Exemple #6
0
 @Override
 public boolean onKeyboardEvent(KeyboardEvent event) {
   if (event == null) throw new NullPointerException("event may not be null");
   if (!event.isSpecial() || event.isModified()) return false;
   switch (event.getSpecial()) {
     case ARROW_DOWN:
       return onArrowDown(event, false);
     case ARROW_UP:
       return onArrowUp(event, false);
     case ARROW_RIGHT:
       return onArrowRight(event);
     case ARROW_LEFT:
       return onArrowLeft(event);
     case ALTERNATIVE_ARROW_DOWN:
       return onArrowDown(event, true);
     case ALTERNATIVE_ARROW_UP:
       return onArrowUp(event, true);
       // FIXME:case KeyboardEvent.ALTERNATIVE_ARROW_RIGHT:
       // FIXME:case KeyboardEvent.ALTERNATIVE_ARROW_LEFT:
     case HOME:
       return onHome(event);
     case END:
       return onEnd(event);
     case ALTERNATIVE_HOME:
       return onLineHome(event);
     case ALTERNATIVE_END:
       return onLineEnd(event);
     case PAGE_DOWN:
       return onPageDown(event, false);
     case PAGE_UP:
       return onPageUp(event, false);
     case ALTERNATIVE_PAGE_DOWN:
       return onPageDown(event, true);
     case ALTERNATIVE_PAGE_UP:
       return onPageUp(event, true);
     case ENTER:
       if (noProperContent()
           || clickHandler == null
           || hotPointY < 0
           || hotPointY >= model.getRowCount()
           || getColUnderPos(hotPointX) < 0) return false;
       return clickHandler.onClick(
           model,
           getColUnderPos(hotPointX),
           hotPointY,
           model.getCell(getColUnderPos(hotPointX), hotPointY));
     default:
       return false;
   }
 }
 private int[] getWidths(TableModel tableModel) {
   int[] widths = new int[tableModel.getColumnCount()];
   for (int r = 0;
       r < Math.min(tableModel.getRowCount(), 500);
       r++) { // 500 is not for performance, but for using only a sample of data with huge table
     for (int c = 0; c < tableModel.getColumnCount(); c++) {
       Object o = tableModel.getValueAt(r, c);
       if (o instanceof String) {
         String s = ((String) o).trim();
         if (s.length() > widths[c]) widths[c] = s.length();
       }
     }
   }
   return widths;
 }
Exemple #8
0
 private boolean onEnd(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   hotPointY = count;
   onNewHotPointY(false);
   return true;
 }
 private Object getValueWithWebEditorsFormat(int row, int column) {
   Object r = original.getValueAt(row, column);
   MetaProperty metaProperty = getMetaProperty(column);
   String result = WebEditors.format(this.request, metaProperty, r, null, "", true);
   if (isHtml(result)) { // this avoids that the report shows html content
     result = WebEditors.format(this.request, metaProperty, r, null, "", false);
   }
   return result;
 }
Exemple #10
0
 private void onNewHotPointY(boolean briefIntroduction) {
   final int count = model.getRowCount();
   hotPointX = hotPointY < count ? initialHotPointX : 0;
   cellShift = 0;
   environment.onAreaNewHotPoint(this);
   if (hotPointY < count)
     appearance.introduceRow(model, hotPointY, briefIntroduction ? INTRODUCTION_BRIEF : 0);
   else environment.hint(Hints.EMPTY_LINE);
 }
Exemple #11
0
 private boolean onArrowDown(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY >= count) {
     environment.hint(Hints.TABLE_NO_ROWS_BELOW);
     return true;
   }
   ++hotPointY;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Exemple #12
0
 protected Comparator getComparator(int column) {
   Class columnType = tableModel.getColumnClass(column);
   Comparator comparator = (Comparator) columnComparators.get(columnType);
   if (comparator != null) {
     return comparator;
   }
   if (Comparable.class.isAssignableFrom(columnType)) {
     return COMPARABLE_COMAPRATOR;
   }
   return LEXICAL_COMPARATOR;
 }
  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);
    }
  }
Exemple #14
0
 private boolean onArrowUp(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY <= 0) {
     environment.hint(Hints.TABLE_NO_ROWS_ABOVE);
     return true;
   }
   --hotPointY;
   if (hotPointY >= count) hotPointY = count - 1;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Exemple #15
0
 private boolean onPageDown(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY >= count) {
     environment.hint(Hints.TABLE_NO_ROWS_BELOW);
     return true;
   }
   hotPointY += environment.getAreaVisibleHeight(this);
   if (hotPointY >= count) hotPointY = count;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Exemple #16
0
 /**
  * Return a label for the given point on the graph axis
  *
  * @param value the value on the graph
  * @return the label for the given value
  */
 private String getLeafLabel(double value) {
   String label = Double.toString(value);
   try {
     int v = (int) value;
     int r = idxMap.getSrc(v);
     if (r < 0 || r >= tm.getRowCount()) {
       return "";
     }
     if (labelColumn >= 0 && labelColumn < tm.getColumnCount()) {
       Object o = tm.getValueAt(r, labelColumn);
       return o != null ? o.toString() : "";
     }
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   try {
     label = Integer.toString((int) value);
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   return label;
 }
Exemple #17
0
 public void refresh(boolean refreshModel) {
   if (model == null) {
     colWidth = null;
     cellShift = 0;
     hotPointX = 0;
     hotPointY = 0;
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return;
   }
   if (refreshModel) model.refresh();
   final int colCount = model.getColCount();
   final int rowCount = model.getRowCount();
   if (colCount <= 0 || rowCount <= 0) {
     colWidth = null;
     cellShift = 0;
     hotPointX = 0;
     hotPointY = 0;
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return;
   }
   initialHotPointX = appearance.getInitialHotPointX(model);
   colWidth = new int[colCount];
   int totalWidth = initialHotPointX;
   for (int i = 0; i < colCount; ++i) {
     final int width = appearance.getColWidth(model, i);
     colWidth[i] = width >= 1 ? width : 1;
     totalWidth += (colWidth[i] + 1);
   }
   if (hotPointY > rowCount) hotPointY = rowCount;
   if (hotPointY < rowCount && hotPointX >= totalWidth)
     hotPointX =
         totalWidth - 1; // totalWidth may not be zero as always we have at least one column here;
   if (hotPointY == rowCount) hotPointX = 0;
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
 }
Exemple #18
0
  private Row[] getViewToModel() {
    if (viewToModel == null) {
      int tableModelRowCount = tableModel.getRowCount();
      viewToModel = new Row[tableModelRowCount];
      for (int row = 0; row < tableModelRowCount; row++) {
        viewToModel[row] = new Row(row);
      }

      if (isSorting()) {
        Arrays.sort(viewToModel);
      }
    }
    return viewToModel;
  }
Exemple #19
0
 /**
  * Display the tree rooted at node tn in the graph as a dendogram.
  *
  * @param tn the root node of the tree to display
  */
 private void display(TreeNode tn) {
   double[] segs = dendogram(tn);
   double distance = 10.;
   if (tn instanceof Cluster) {
     distance = ((Cluster) tn).getSimilarity();
   } else {
     distance = ((DefaultMutableTreeNode) tn).getDepth();
   }
   gs.setData(segs, GraphDataModel.FORMAT_XY);
   graph.getXAxis().setMin(distance);
   graph.getXAxis().setMax(0.);
   graph.getYAxis().setMin(tm.getRowCount() - .5);
   graph.getYAxis().setMax(-.5);
   repaint();
 }
Exemple #20
0
 @Override
 public String getLine(int index) {
   if (noProperContent())
     return index <= 0 ? environment.staticStr(LangStatic.TABLE_NO_CONTENT) : "";
   if (index < 0 || index >= model.getRowCount()) return "";
   final int currentCol = getColUnderPos(hotPointX);
   String line = getStringOfLen(appearance.getRowPrefix(model, index), initialHotPointX, "", "");
   if (index != hotPointY || currentCol < 0) {
     for (int i = 0; i < model.getColCount(); ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
     return line;
   }
   if (currentCol > 0)
     for (int i = 0; i < currentCol; ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
   String currentColText = appearance.getCellText(model, currentCol, index);
   if (cellShift > 0 && cellShift < currentColText.length())
     currentColText = currentColText.substring(cellShift);
   line += getStringOfLen(currentColText, colWidth[currentCol], ">", " ");
   if (currentCol + 1 < colWidth.length)
     for (int i = currentCol + 1; i < colWidth.length; ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
   return line;
 }
Exemple #21
0
 private boolean onArrowLeft(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY < 0 || hotPointY >= count) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   if (hotPointX < initialHotPointX) hotPointX = initialHotPointX;
   if (getColUnderPos(hotPointX) < 0) hotPointX = initialHotPointX;
   final int currentCol = getColUnderPos(hotPointX);
   final int currentColWidth = colWidth[currentCol];
   final int colStartPos = getColStartPos(currentCol);
   final TableCell c =
       new TableCell(
           hotPointX - colStartPos,
           cellShift,
           currentColWidth,
           appearance.getCellText(model, currentCol, hotPointY));
   if (!c.movePrev()) {
     if (currentCol <= 0) {
       environment.hint(Hints.TABLE_BEGIN_OF_ROW);
       return true;
     }
     final String prevColText = appearance.getCellText(model, currentCol - 1, hotPointY);
     final int prevColWidth = colWidth[currentCol - 1];
     final int prevColStartPos = getColStartPos(currentCol - 1);
     if (prevColText.length() > prevColWidth) {
       hotPointX = prevColStartPos + prevColWidth;
       cellShift = prevColText.length() - prevColWidth;
     } else {
       cellShift = 0;
       hotPointX = prevColStartPos + prevColText.length();
     }
     environment.hint(Hints.TABLE_END_OF_COL);
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   cellShift = c.shift;
   hotPointX = c.pos + colStartPos;
   if (c.pos == c.width) // Should never happen;
   environment.hint(Hints.TABLE_END_OF_COL);
   else environment.sayLetter(c.line.charAt(c.pos + c.shift));
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
   return true;
 }
Exemple #22
0
 private boolean onArrowRight(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY < 0 || hotPointY >= count) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   // Checking that hot point not before proper line begin;
   if (hotPointX < initialHotPointX) hotPointX = initialHotPointX;
   if (getColUnderPos(hotPointX) < 0) hotPointX = initialHotPointX;
   final int currentCol = getColUnderPos(hotPointX);
   final int currentColWidth = colWidth[currentCol];
   final int colStartPos = getColStartPos(currentCol);
   final int nextColStartPos = colStartPos + colWidth[currentCol] + 1;
   final TableCell c =
       new TableCell(
           hotPointX - colStartPos,
           cellShift,
           currentColWidth,
           appearance.getCellText(model, currentCol, hotPointY));
   if (!c.moveNext()) {
     if (currentCol + 1 >= colWidth.length) {
       environment.hint(Hints.TABLE_END_OF_ROW);
       return true;
     }
     cellShift = 0;
     hotPointX = nextColStartPos;
     final String nextColText = appearance.getCellText(model, currentCol + 1, hotPointY);
     if (!nextColText.isEmpty()) environment.sayLetter(nextColText.charAt(0));
     else
       environment.hint(
           currentCol + 2 < colWidth.length ? Hints.TABLE_END_OF_COL : Hints.TABLE_END_OF_ROW);
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   cellShift = c.shift;
   hotPointX = c.pos + colStartPos;
   if (c.pos + c.shift >= c.line.length())
     environment.hint(
         currentCol + 1 < colWidth.length ? Hints.TABLE_END_OF_COL : Hints.TABLE_END_OF_ROW);
   else environment.sayLetter(c.line.charAt(c.pos + c.shift));
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
   return true;
 }
  public void calculaSumas() {
    try {
      TableModel tm = this.tablaPrincipal.getModel();
      int tamTabla = tm.getRowCount();
      double costo, cantidad, totalFila, sumaTotal;
      sumaTotal = 0.0;

      for (int i = 0; i < tamTabla; i++) {
        if (tm.getValueAt(i, 2) != null && tm.getValueAt(i, 3) != null) {
          costo = Double.valueOf(String.valueOf(tm.getValueAt(i, 2)));
          cantidad = Double.valueOf(String.valueOf(tm.getValueAt(i, 3)));
          totalFila = costo * cantidad;

          tm.setValueAt(totalFila, i, 4);
          sumaTotal += totalFila;
        }
      }

      txtSumaTotal.setText(String.valueOf(sumaTotal));
    } catch (Exception e) {
      Dialogos.lanzarAlerta("Cantidades invalidas, puede que algun numero este mal escrito");
    }
  }
  @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();
  }
 public int getColumnCount() {
   return columnCountLimit == null ? original.getColumnCount() : columnCountLimit;
 }
 public Class getColumnClass(int c) {
   return original.getColumnClass(c);
 }
 public boolean isCellEditable(int row, int column) {
   return original.isCellEditable(row, column);
 }
Exemple #28
0
 @Override
 public int getLineCount() {
   if (noProperContent()) return 2;
   return model.getRowCount() + 1;
 }
Exemple #29
0
 public Object getSelectedRow() {
   final int index = getSelectedRowIndex();
   if (index < 0) return null;
   return model.getRow(index);
 }
Exemple #30
0
 public int getSelectedRowIndex() {
   return hotPointY < model.getRowCount() ? hotPointY : -1;
 }