Esempio n. 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));
  }
Esempio n. 2
0
  public SimpleTable() {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    final String[] names = {"First Name", "Last Name", "Id"};
    final Object[][] data = {
      {"Mark", "Andrews", new Integer(1)},
      {"Tom", "Ball", new Integer(2)},
      {"Alan", "Chung", new Integer(3)},
    };

    TableModel dataModel =
        new AbstractTableModel() {
          public int getColumnCount() {
            return names.length;
          }

          public int getRowCount() {
            return data.length;
          }

          public Object getValueAt(int row, int col) {
            return data[row][col];
          }

          public String getColumnName(int column) {
            return names[column];
          }

          public Class getColumnClass(int col) {
            return getValueAt(0, col).getClass();
          }

          public void setValueAt(Object aValue, int row, int column) {
            data[row][column] = aValue;
          }
        };

    aTable = new JTable(dataModel);

    ListSelectionModel listMod = aTable.getSelectionModel();
    listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listMod.addListSelectionListener(this);

    JScrollPane scrollpane = new JScrollPane(aTable);
    scrollpane.setPreferredSize(new Dimension(300, 300));
    frame.getContentPane().add(scrollpane);
    frame.pack();
    frame.setVisible(true);

    aTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              System.out.println(" double click");
            }
          }
        });
  }
  /** Initializes the table. */
  protected void init() {
    dataTable
        .getColumnModel()
        .addColumnModelListener(
            new TableColumnModelListener() {
              public void columnAdded(TableColumnModelEvent e) {
                /** empty block */
              }

              public void columnRemoved(TableColumnModelEvent e) {
                /** empty block */
              }

              public void columnSelectionChanged(ListSelectionEvent e) {
                /** empty block */
              }

              public void columnMarginChanged(ChangeEvent e) {
                refreshTable();
              }

              public void columnMoved(TableColumnModelEvent e) {
                refreshTable();
              }
            });
    // assemble statistics data array
    Dataset workingData = dataTable.getWorkingData();
    double[] xstats = getStatistics(workingData.getXPoints());
    double[] ystats = getStatistics(workingData.getValidYPoints());
    if (statsData == null) {
      statsData = new Object[xstats.length][0];
    }
    for (int i = 0; i < xstats.length; i++) {
      String label = ToolsRes.getString("Table.Entry.Count"); // $NON-NLS-1$
      if (i == 5) {
        statsData[i] =
            new Object[] {label, new Integer((int) xstats[i]), new Integer((int) ystats[i])};
      } else {
        switch (i) {
          case 0:
            label = ToolsRes.getString("Table.Entry.Max");
            break; //$NON-NLS-1$
          case 1:
            label = ToolsRes.getString("Table.Entry.Min");
            break; //$NON-NLS-1$
          case 2:
            label = ToolsRes.getString("Table.Entry.Mean");
            break; //$NON-NLS-1$
          case 3:
            label = ToolsRes.getString("Table.Entry.StandardDev");
            break; //$NON-NLS-1$
          case 4:
            label = ToolsRes.getString("Table.Entry.StandardError"); // $NON-NLS-1$
        }
        statsData[i] = new Object[] {label, new Double(xstats[i]), new Double(ystats[i])};
      }
    }
    // set and configure table model and header
    setModel(tableModel);
    setGridColor(Color.blue);
    setEnabled(false);
    setTableHeader(null); // no table header
    labelRenderer = new LabelRenderer();
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    setDefaultRenderer(Double.class, new ScientificRenderer(3));
    ListSelectionModel selectionModel = dataTable.getSelectionModel();
    selectionModel.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            Dataset workingData = dataTable.getWorkingData();
            double[] xstats = getStatistics(workingData.getXPoints());
            double[] ystats = getStatistics(workingData.getValidYPoints());
            int i = 0;
            for (; i < xstats.length - 1; i++) {
              statsData[i][1] = new Double(xstats[i]);
              statsData[i][2] = new Double(ystats[i]);
            }
            statsData[i][1] = new Integer((int) xstats[i]);
            statsData[i][2] = new Integer((int) ystats[i]);
            refreshTable();
          }
        });
    refreshCellWidths();
  }
  public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = {"one", "two", "three", "four", "five", "six", "seven"};
    String[] columnNames = {"French", "Spanish", "Italian"};
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = {
      "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION"
    };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);
    comboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
              listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
              listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
              listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
          }
        });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    // Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane =
        new JScrollPane(
            output,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    // topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    // XXX: next line needed if bottomHalf is a scroll pane:
    // bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
  }